Sfoglia il codice sorgente

Decimation process improvements

Raanan Weber 10 anni fa
parent
commit
8a91ae10fc

+ 10 - 4
Babylon/Mesh/babylon.meshSimplification.js

@@ -99,16 +99,22 @@ var BABYLON;
     })();
     BABYLON.DecimationTriangle = DecimationTriangle;
     var DecimationVertex = (function () {
-        function DecimationVertex(position, normal, uv, id) {
+        function DecimationVertex(position, normal, id) {
             this.position = position;
             this.normal = normal;
-            this.uv = uv;
             this.id = id;
             this.isBorder = true;
             this.q = new QuadraticMatrix();
             this.triangleCount = 0;
             this.triangleStart = 0;
+            this.referenceVertices = [];
         }
+        DecimationVertex.prototype.updatePosition = function (newPosition) {
+            this.position.copyFrom(newPosition);
+            this.referenceVertices.forEach(function (vertex) {
+                vertex.position.copyFrom(newPosition);
+            });
+        };
         return DecimationVertex;
     })();
     BABYLON.DecimationVertex = DecimationVertex;
@@ -277,7 +283,7 @@ var BABYLON;
                                 else if (v0.color)
                                     v0.color = color;
                                 v0.q = v1.q.add(v0.q);
-                                v0.position = p;
+                                v0.updatePosition(p);
                                 var tStart = _this.references.length;
                                 deletedTriangles = _this.updateTriangles(v0.id, v0, deleted0, deletedTriangles);
                                 deletedTriangles = _this.updateTriangles(v0.id, v1, deleted1, deletedTriangles);
@@ -334,7 +340,7 @@ var BABYLON;
             var submesh = mesh.subMeshes[submeshIndex];
             var vertexInit = function (i) {
                 var offset = i + submesh.verticesStart;
-                var vertex = new DecimationVertex(BABYLON.Vector3.FromArray(positionData, offset * 3), BABYLON.Vector3.FromArray(normalData, offset * 3), null, i);
+                var vertex = new DecimationVertex(BABYLON.Vector3.FromArray(positionData, offset * 3), BABYLON.Vector3.FromArray(normalData, offset * 3), i);
                 if (_this._mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
                     vertex.uv = BABYLON.Vector2.FromArray(uvs, offset * 2);
                 }

+ 16 - 3
Babylon/Mesh/babylon.meshSimplification.ts

@@ -144,14 +144,27 @@
         public triangleStart: number;
         public triangleCount: number;
 
+        public uv: Vector2
         //if color is present instead of uvs.
         public color: Color4;
 
-        constructor(public position: Vector3, public normal: Vector3, public uv: Vector2, public id) {
+        public referenceVertices: Array<DecimationVertex>;
+
+        
+
+        constructor(public position: Vector3, public normal: Vector3, public id) {
             this.isBorder = true;
             this.q = new QuadraticMatrix();
             this.triangleCount = 0;
             this.triangleStart = 0;
+            this.referenceVertices = [];
+        }
+
+        public updatePosition(newPosition: Vector3) {
+            this.position.copyFrom(newPosition);
+            this.referenceVertices.forEach(function (vertex) {
+                vertex.position.copyFrom(newPosition);
+            });
         }
     }
 
@@ -352,7 +365,7 @@
                                     v0.color = color;
                                 v0.q = v1.q.add(v0.q);
 
-                                v0.position = p;
+                                v0.updatePosition(p);
 
                                 var tStart = this.references.length;
 
@@ -413,7 +426,7 @@
 
             var vertexInit = (i) => {
                 var offset = i + submesh.verticesStart;
-                var vertex = new DecimationVertex(Vector3.FromArray(positionData, offset * 3), Vector3.FromArray(normalData, offset * 3), null, i);
+                var vertex = new DecimationVertex(Vector3.FromArray(positionData, offset * 3), Vector3.FromArray(normalData, offset * 3), i);
                 if (this._mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
                     vertex.uv = Vector2.FromArray(uvs, offset * 2);
                 } else if (this._mesh.isVerticesDataPresent(VertexBuffer.ColorKind)) {