Ver código fonte

Init vertex buffer in constructor

the vertex buffer was initialized only when vertics data was set, and
was therefore undefined until then.
Now initializing it in the constructor.
Raanan Weber 10 anos atrás
pai
commit
95b6726f58
2 arquivos alterados com 7 adições e 6 exclusões
  1. 3 3
      src/Mesh/babylon.geometry.js
  2. 4 3
      src/Mesh/babylon.geometry.ts

+ 3 - 3
src/Mesh/babylon.geometry.js

@@ -9,12 +9,14 @@ var BABYLON;
         function Geometry(id, scene, vertexData, updatable, mesh) {
         function Geometry(id, scene, vertexData, updatable, mesh) {
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
             this._totalVertices = 0;
             this._totalVertices = 0;
-            this._indices = [];
             this._isDisposed = false;
             this._isDisposed = false;
             this.id = id;
             this.id = id;
             this._engine = scene.getEngine();
             this._engine = scene.getEngine();
             this._meshes = [];
             this._meshes = [];
             this._scene = scene;
             this._scene = scene;
+            //Init vertex buffer cache
+            this._vertexBuffers = {};
+            this._indices = [];
             // vertexData
             // vertexData
             if (vertexData) {
             if (vertexData) {
                 this.setAllVerticesData(vertexData, updatable);
                 this.setAllVerticesData(vertexData, updatable);
@@ -43,7 +45,6 @@ var BABYLON;
             this.notifyUpdate();
             this.notifyUpdate();
         };
         };
         Geometry.prototype.setVerticesData = function (kind, data, updatable, stride) {
         Geometry.prototype.setVerticesData = function (kind, data, updatable, stride) {
-            this._vertexBuffers = this._vertexBuffers || {};
             if (this._vertexBuffers[kind]) {
             if (this._vertexBuffers[kind]) {
                 this._vertexBuffers[kind].dispose();
                 this._vertexBuffers[kind].dispose();
             }
             }
@@ -634,4 +635,3 @@ var BABYLON;
         })(Primitives = Geometry.Primitives || (Geometry.Primitives = {}));
         })(Primitives = Geometry.Primitives || (Geometry.Primitives = {}));
     })(Geometry = BABYLON.Geometry || (BABYLON.Geometry = {}));
     })(Geometry = BABYLON.Geometry || (BABYLON.Geometry = {}));
 })(BABYLON || (BABYLON = {}));
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.geometry.js.map

+ 4 - 3
src/Mesh/babylon.geometry.ts

@@ -11,7 +11,7 @@
         private _engine: Engine;
         private _engine: Engine;
         private _meshes: Mesh[];
         private _meshes: Mesh[];
         private _totalVertices = 0;
         private _totalVertices = 0;
-        private _indices = [];
+        private _indices;
         private _vertexBuffers;
         private _vertexBuffers;
         private _isDisposed = false;
         private _isDisposed = false;
         public _delayInfo; //ANY
         public _delayInfo; //ANY
@@ -24,6 +24,9 @@
             this._engine = scene.getEngine();
             this._engine = scene.getEngine();
             this._meshes = [];
             this._meshes = [];
             this._scene = scene;
             this._scene = scene;
+			//Init vertex buffer cache
+			this._vertexBuffers = {};
+			this._indices = [];
 
 
             // vertexData
             // vertexData
             if (vertexData) {
             if (vertexData) {
@@ -59,8 +62,6 @@
         }
         }
 
 
         public setVerticesData(kind: string, data: number[] | Float32Array, updatable?: boolean, stride?: number): void {
         public setVerticesData(kind: string, data: number[] | Float32Array, updatable?: boolean, stride?: number): void {
-            this._vertexBuffers = this._vertexBuffers || {};
-
             if (this._vertexBuffers[kind]) {
             if (this._vertexBuffers[kind]) {
                 this._vertexBuffers[kind].dispose();
                 this._vertexBuffers[kind].dispose();
             }
             }