mirror of
https://github.com/LucasDower/ObjToSchematic.git
synced 2025-12-11 20:15:30 +01:00
Fixed getSections not returning a copy of the section, fixed copy on mesh
This commit is contained in:
parent
3729986623
commit
c51c4d900c
@ -1,4 +1,4 @@
|
||||
import { RGBA } from "./colour";
|
||||
import { RGBA, RGBAUtil } from "./colour";
|
||||
//import { Material, OtS_Util } from "./materials";
|
||||
import { OtS_Texture } from "./ots_texture";
|
||||
|
||||
@ -7,6 +7,41 @@ export type OtS_MeshSection = { name: string, positionData: Float32Array, normal
|
||||
| { type: 'colour', colourData: Float32Array }
|
||||
| { type: 'textured', texcoordData: Float32Array, texture: OtS_Texture });
|
||||
|
||||
export namespace OtS_MeshUtil {
|
||||
export function copySection(section: OtS_MeshSection): OtS_MeshSection {
|
||||
switch(section.type) {
|
||||
case 'solid':
|
||||
return {
|
||||
type: 'solid',
|
||||
name: section.name,
|
||||
indexData: section.indexData.slice(0),
|
||||
positionData: section.positionData.slice(0),
|
||||
normalData: section.normalData.slice(0),
|
||||
colour: RGBAUtil.copy(section.colour),
|
||||
};
|
||||
case 'colour':
|
||||
return {
|
||||
type: 'colour',
|
||||
name: section.name,
|
||||
indexData: section.indexData.slice(0),
|
||||
positionData: section.positionData.slice(0),
|
||||
normalData: section.normalData.slice(0),
|
||||
colourData: section.colourData.slice(0),
|
||||
};
|
||||
case 'textured':
|
||||
return {
|
||||
type: 'textured',
|
||||
name: section.name,
|
||||
indexData: section.indexData.slice(0),
|
||||
positionData: section.positionData.slice(0),
|
||||
normalData: section.normalData.slice(0),
|
||||
texcoordData: section.texcoordData.slice(0),
|
||||
texture: section.texture.copy(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
export class OtS_MaterialSlots {
|
||||
private _slots: Map<number, Material>;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Bounds } from './bounds';
|
||||
import { RGBA } from './colour';
|
||||
import { degreesToRadians } from './math';
|
||||
import { OtS_MeshSection } from './ots_materials';
|
||||
import { OtS_MeshSection, OtS_MeshUtil } from './ots_materials';
|
||||
import { OtS_Texture } from './ots_texture';
|
||||
import { UV } from "./util";
|
||||
import { ASSERT } from './util/error_util';
|
||||
@ -357,10 +357,10 @@ export class OtS_Mesh {
|
||||
public copy() {
|
||||
const clone = OtS_Mesh.create();
|
||||
|
||||
for (const section of this._sections) {
|
||||
this.getSectionData().forEach((section) => {
|
||||
const success = clone.addSection(section).ok;
|
||||
ASSERT(success);
|
||||
}
|
||||
})
|
||||
|
||||
return clone;
|
||||
}
|
||||
@ -391,9 +391,10 @@ export class OtS_Mesh {
|
||||
.reduce((total, count) => total + count, 0);
|
||||
}
|
||||
|
||||
// TODO: Return copy
|
||||
public getSectionData(): OtS_MeshSection[] {
|
||||
return this._sections;
|
||||
return this._sections.map((section) => {
|
||||
return OtS_MeshUtil.copySection(section);
|
||||
})
|
||||
}
|
||||
|
||||
public getSectionMetadata(): OtS_MeshSectionMetadata[] {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user