فهرست منبع

Added possibility to make the geometry unique for the mesh while updating vertices data

Gwenaël Hagenmuller 11 سال پیش
والد
کامیت
fef55f32e0

+ 3 - 1
Babylon/Mesh/babylon.geometry.js

@@ -230,6 +230,8 @@ var BABYLON;
             // must be done before setting vertexBuffers because of mesh._createGlobalSubMesh()
             mesh._geometry = this;
 
+            mesh.getScene().pushGeometry(this);
+
             meshes.push(mesh);
 
             if (this.isReady()) {
@@ -337,7 +339,7 @@ var BABYLON;
 
         Geometry.prototype.copy = function (id) {
             var vertexData = new BABYLON.VertexData();
-            vertexData.indices = this.getIndices();
+            vertexData.indices = this.getIndices(); // todo: clone
 
             var updatable = false;
             var stopChecking = false;

+ 3 - 1
Babylon/Mesh/babylon.geometry.ts

@@ -239,6 +239,8 @@
             // must be done before setting vertexBuffers because of mesh._createGlobalSubMesh()
             mesh._geometry = this;
 
+            mesh.getScene().pushGeometry(this);
+
             meshes.push(mesh);
 
             if (this.isReady()) {
@@ -347,7 +349,7 @@
 
         public copy(id: string): Geometry {
             var vertexData = new BABYLON.VertexData();
-            vertexData.indices = this.getIndices();
+            vertexData.indices = this.getIndices(); // todo: clone
 
             var updatable = false;
             var stopChecking = false;

+ 10 - 6
Babylon/Mesh/babylon.mesh.js

@@ -423,18 +423,23 @@ var BABYLON;
 
                 var scene = this.getScene();
 
-                this._geometry = new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene.getEngine(), vertexData, updatable, this);
-                scene.pushGeometry(this._geometry);
+                new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene.getEngine(), vertexData, updatable, this);
             } else {
                 this._geometry.setVerticesData(data, kind, updatable);
             }
         };
 
-        Mesh.prototype.updateVerticesData = function (kind, data, updateExtends) {
+        Mesh.prototype.updateVerticesData = function (kind, data, updateExtends, makeItUnique) {
             if (!this._geometry) {
                 return;
             }
-            this._geometry.updateVerticesData(kind, data, updateExtends);
+            if (!makeItUnique) {
+                this._geometry.updateVerticesData(kind, data, updateExtends);
+            } else {
+                var geometry = this._geometry.copy(BABYLON.Geometry.RandomId());
+                geometry.applyToMesh(this);
+                this.updateVerticesData(kind, data, updateExtends, false);
+            }
         };
 
         Mesh.prototype.setIndices = function (indices) {
@@ -444,8 +449,7 @@ var BABYLON;
 
                 var scene = this.getScene();
 
-                this._geometry = new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene.getEngine(), vertexData, false, this);
-                scene.pushGeometry(this._geometry);
+                new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene.getEngine(), vertexData, false, this);
             } else {
                 this._geometry.setIndices(indices);
             }

+ 11 - 6
Babylon/Mesh/babylon.mesh.ts

@@ -442,19 +442,25 @@
 
                 var scene = this.getScene();
 
-                this._geometry = new BABYLON.Geometry(Geometry.RandomId(), scene.getEngine(), vertexData, updatable, this);
-                scene.pushGeometry(this._geometry);
+                new BABYLON.Geometry(Geometry.RandomId(), scene.getEngine(), vertexData, updatable, this);
             }
             else {
                 this._geometry.setVerticesData(data, kind, updatable);
             }
         }
 
-        public updateVerticesData(kind: string, data: number[], updateExtends?: boolean): void {
+        public updateVerticesData(kind: string, data: number[], updateExtends?: boolean, makeItUnique?: boolean): void {
             if (!this._geometry) {
                 return;
             }
-            this._geometry.updateVerticesData(kind, data, updateExtends);
+            if (!makeItUnique) {
+                this._geometry.updateVerticesData(kind, data, updateExtends);
+            }
+            else {
+                var geometry = this._geometry.copy(Geometry.RandomId());
+                geometry.applyToMesh(this);
+                this.updateVerticesData(kind, data, updateExtends, false);
+            }
         }
 
         public setIndices(indices: number[]): void {
@@ -464,8 +470,7 @@
 
                 var scene = this.getScene();
 
-                this._geometry = new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene.getEngine(), vertexData, false, this);
-                scene.pushGeometry(this._geometry);
+                new BABYLON.Geometry(BABYLON.Geometry.RandomId(), scene.getEngine(), vertexData, false, this);
             }
             else {
                 this._geometry.setIndices(indices);

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 2 - 2
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/ourOwnBabylon.js