Explorar el Código

small cleanup

Sukolsak Sakshuwong hace 3 años
padre
commit
ef9885411c

+ 64 - 64
src/extensions/geo-export/glb-exporter.ts

@@ -50,7 +50,7 @@ export class GlbExporter extends MeshExporter<GlbData> {
         return [ min, max ];
     }
 
-    async addMeshWithColors(vertices: Float32Array, normals: Float32Array, indices: Uint32Array | undefined, groups: Float32Array | Uint8Array, vertexCount: number, drawCount: number, values: BaseValues, instanceIndex: number, isGeoTexture: boolean, ctx: RuntimeContext) {
+    protected async addMeshWithColors(vertices: Float32Array, normals: Float32Array, indices: Uint32Array | undefined, groups: Float32Array | Uint8Array, vertexCount: number, drawCount: number, values: BaseValues, instanceIndex: number, isGeoTexture: boolean, ctx: RuntimeContext) {
         const t = Mat4();
         const n = Mat3();
         const tmpV = Vec3();
@@ -152,85 +152,85 @@ export class GlbExporter extends MeshExporter<GlbData> {
         const bufferViewOffset = this.bufferViews.length;
 
         this.bufferViews.push({
-            'buffer': 0,
-            'byteOffset': this.byteOffset,
-            'byteLength': vertexBuffer.byteLength,
-            'target': 34962 // ARRAY_BUFFER
+            buffer: 0,
+            byteOffset: this.byteOffset,
+            byteLength: vertexBuffer.byteLength,
+            target: 34962 // ARRAY_BUFFER
         });
         this.byteOffset += vertexBuffer.byteLength;
 
         this.bufferViews.push({
-            'buffer': 0,
-            'byteOffset': this.byteOffset,
-            'byteLength': normalBuffer.byteLength,
-            'target': 34962 // ARRAY_BUFFER
+            buffer: 0,
+            byteOffset: this.byteOffset,
+            byteLength: normalBuffer.byteLength,
+            target: 34962 // ARRAY_BUFFER
         });
         this.byteOffset += normalBuffer.byteLength;
 
         this.bufferViews.push({
-            'buffer': 0,
-            'byteOffset': this.byteOffset,
-            'byteLength': colorBuffer.byteLength,
-            'target': 34962 // ARRAY_BUFFER
+            buffer: 0,
+            byteOffset: this.byteOffset,
+            byteLength: colorBuffer.byteLength,
+            target: 34962 // ARRAY_BUFFER
         });
         this.byteOffset += colorBuffer.byteLength;
 
         this.bufferViews.push({
-            'buffer': 0,
-            'byteOffset': this.byteOffset,
-            'byteLength': indexBuffer.byteLength,
-            'target': 34963 // ELEMENT_ARRAY_BUFFER
+            buffer: 0,
+            byteOffset: this.byteOffset,
+            byteLength: indexBuffer.byteLength,
+            target: 34963 // ELEMENT_ARRAY_BUFFER
         });
         this.byteOffset += indexBuffer.byteLength;
 
         // accessors
         const accessorOffset = this.accessors.length;
         this.accessors.push({
-            'bufferView': bufferViewOffset,
-            'byteOffset': 0,
-            'componentType': 5126, // FLOAT
-            'count': vertexCount,
-            'type': 'VEC3',
-            'max': vertexMax,
-            'min': vertexMin
+            bufferView: bufferViewOffset,
+            byteOffset: 0,
+            componentType: 5126, // FLOAT
+            count: vertexCount,
+            type: 'VEC3',
+            max: vertexMax,
+            min: vertexMin
         });
         this.accessors.push({
-            'bufferView': bufferViewOffset + 1,
-            'byteOffset': 0,
-            'componentType': 5126, // FLOAT
-            'count': vertexCount,
-            'type': 'VEC3',
-            'max': normalMax,
-            'min': normalMin
+            bufferView: bufferViewOffset + 1,
+            byteOffset: 0,
+            componentType: 5126, // FLOAT
+            count: vertexCount,
+            type: 'VEC3',
+            max: normalMax,
+            min: normalMin
         });
         this.accessors.push({
-            'bufferView': bufferViewOffset + 2,
-            'byteOffset': 0,
-            'componentType': 5126, // FLOAT
-            'count': vertexCount,
-            'type': 'VEC4',
-            'max': [...colorMax, uAlpha],
-            'min': [...colorMin, uAlpha]
+            bufferView: bufferViewOffset + 2,
+            byteOffset: 0,
+            componentType: 5126, // FLOAT
+            count: vertexCount,
+            type: 'VEC4',
+            max: [...colorMax, uAlpha],
+            min: [...colorMin, uAlpha]
         });
         this.accessors.push({
-            'bufferView': bufferViewOffset + 3,
-            'byteOffset': 0,
-            'componentType': 5125, // UNSIGNED_INT
-            'count': drawCount,
-            'type': 'SCALAR',
-            'max': [ indexMax ],
-            'min': [ indexMin ]
+            bufferView: bufferViewOffset + 3,
+            byteOffset: 0,
+            componentType: 5125, // UNSIGNED_INT
+            count: drawCount,
+            type: 'SCALAR',
+            max: [ indexMax ],
+            min: [ indexMin ]
         });
 
         // primitive
         this.primitives.push({
-            'attributes': {
-                'POSITION': accessorOffset,
-                'NORMAL': accessorOffset + 1,
-                'COLOR_0': accessorOffset + 2,
+            attributes: {
+                POSITION: accessorOffset,
+                NORMAL: accessorOffset + 1,
+                COLOR_0: accessorOffset + 2,
             },
-            'indices': accessorOffset + 3,
-            'material': 0
+            indices: accessorOffset + 3,
+            material: 0
         });
     }
 
@@ -238,24 +238,24 @@ export class GlbExporter extends MeshExporter<GlbData> {
         const binaryBufferLength = this.byteOffset;
 
         const gltf = {
-            'asset': {
-                'version': '2.0'
+            asset: {
+                version: '2.0'
             },
-            'scenes': [{
-                'nodes': [ 0 ]
+            scenes: [{
+                nodes: [ 0 ]
             }],
-            'nodes': [{
-                'mesh': 0
+            nodes: [{
+                mesh: 0
             }],
-            'meshes': [{
-                'primitives': this.primitives
+            meshes: [{
+                primitives: this.primitives
             }],
-            'buffers': [{
-                'byteLength': binaryBufferLength,
+            buffers: [{
+                byteLength: binaryBufferLength,
             }],
-            'bufferViews': this.bufferViews,
-            'accessors': this.accessors,
-            'materials': [{}]
+            bufferViews: this.bufferViews,
+            accessors: this.accessors,
+            materials: [{}]
         };
 
         const createChunk = (chunkType: number, data: ArrayBuffer[], byteLength: number, padChar: number): [ArrayBuffer[], number] => {

+ 5 - 6
src/extensions/geo-export/stl-exporter.ts

@@ -28,13 +28,12 @@ export class StlExporter extends MeshExporter<StlData> {
     private triangleBuffers: ArrayBuffer[] = [];
     private triangleCount = 0;
 
-    async addMeshWithColors(vertices: Float32Array, normals: Float32Array, indices: Uint32Array | undefined, groups: Float32Array | Uint8Array, vertexCount: number, drawCount: number, values: BaseValues, instanceIndex: number, isGeoTexture: boolean, ctx: RuntimeContext) {
+    protected async addMeshWithColors(vertices: Float32Array, normals: Float32Array, indices: Uint32Array | undefined, groups: Float32Array | Uint8Array, vertexCount: number, drawCount: number, values: BaseValues, instanceIndex: number, isGeoTexture: boolean, ctx: RuntimeContext) {
         const t = Mat4();
         const tmpV = Vec3();
         const v1 = Vec3();
         const v2 = Vec3();
         const v3 = Vec3();
-        const n = Vec3();
         const stride = isGeoTexture ? 4 : 3;
 
         const aTransform = values.aTransform.ref.value;
@@ -60,12 +59,12 @@ export class StlExporter extends MeshExporter<StlData> {
             v3fromArray(v1, vertexArray, (isGeoTexture ? i : indices![i]) * 3);
             v3fromArray(v2, vertexArray, (isGeoTexture ? i + 1 : indices![i + 1]) * 3);
             v3fromArray(v3, vertexArray, (isGeoTexture ? i + 2 : indices![i + 2]) * 3);
-            v3triangleNormal(n, v1, v2, v3);
+            v3triangleNormal(tmpV, v1, v2, v3);
 
             const byteOffset = 50 * i;
-            dataView.setFloat32(byteOffset, n[0], true);
-            dataView.setFloat32(byteOffset + 4, n[1], true);
-            dataView.setFloat32(byteOffset + 8, n[2], true);
+            dataView.setFloat32(byteOffset, tmpV[0], true);
+            dataView.setFloat32(byteOffset + 4, tmpV[1], true);
+            dataView.setFloat32(byteOffset + 8, tmpV[2], true);
 
             dataView.setFloat32(byteOffset + 12, v1[0], true);
             dataView.setFloat32(byteOffset + 16, v1[1], true);