Jelajahi Sumber

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 tahun lalu
induk
melakukan
95b6726f58
2 mengubah file dengan 7 tambahan dan 6 penghapusan
  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) {
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NONE;
             this._totalVertices = 0;
-            this._indices = [];
             this._isDisposed = false;
             this.id = id;
             this._engine = scene.getEngine();
             this._meshes = [];
             this._scene = scene;
+            //Init vertex buffer cache
+            this._vertexBuffers = {};
+            this._indices = [];
             // vertexData
             if (vertexData) {
                 this.setAllVerticesData(vertexData, updatable);
@@ -43,7 +45,6 @@ var BABYLON;
             this.notifyUpdate();
         };
         Geometry.prototype.setVerticesData = function (kind, data, updatable, stride) {
-            this._vertexBuffers = this._vertexBuffers || {};
             if (this._vertexBuffers[kind]) {
                 this._vertexBuffers[kind].dispose();
             }
@@ -634,4 +635,3 @@ var BABYLON;
         })(Primitives = Geometry.Primitives || (Geometry.Primitives = {}));
     })(Geometry = BABYLON.Geometry || (BABYLON.Geometry = {}));
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.geometry.js.map

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

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