Selaa lähdekoodia

PolygonMeshBuilder without the mesh

Allow PolygonMeshBuilder to generate a VertexData object instead of forcing the creation of a new mesh that requires a scene and a mesh that would then need to be disposed if the polygon is to be manually merged with another mesh.
Arthur Fiedler 6 vuotta sitten
vanhempi
commit
4a99273c59
1 muutettua tiedostoa jossa 23 lisäystä ja 4 poistoa
  1. 23 4
      src/Meshes/polygonMesh.ts

+ 23 - 4
src/Meshes/polygonMesh.ts

@@ -223,6 +223,25 @@ export class PolygonMeshBuilder {
      */
     build(updatable: boolean = false, depth: number = 0): Mesh {
         var result = new Mesh(this._name, this._scene);
+        
+        var vertexData = this.buildVertexData(depth);
+        
+        result.setVerticesData(VertexBuffer.PositionKind, vertexData.positions, updatable);
+        result.setVerticesData(VertexBuffer.NormalKind, vertexData.normals, updatable);
+        result.setVerticesData(VertexBuffer.UVKind, vertexData.uvs, updatable);
+        result.setIndices(vertexData.indices);
+
+        return result;
+    }
+    
+    /**
+     * Creates the polygon
+     * @param updatable If the mesh should be updatable
+     * @param depth The depth of the mesh created
+     * @returns the created mesh
+     */
+    buildVertexData(depth: number = 0): VertexData {
+        var result = new VertexData();
 
         var normals = new Array<number>();
         var positions = new Array<number>();
@@ -271,10 +290,10 @@ export class PolygonMeshBuilder {
             });
         }
 
-        result.setVerticesData(VertexBuffer.PositionKind, positions, updatable);
-        result.setVerticesData(VertexBuffer.NormalKind, normals, updatable);
-        result.setVerticesData(VertexBuffer.UVKind, uvs, updatable);
-        result.setIndices(indices);
+        result.indices = indices;
+        result.positions = positions;
+        result.normals = normals;
+        result.uvs = uvs;
 
         return result;
     }