Browse Source

Merge pull request #759 from RaananW/fix-vertex-buffer

Init vertex buffer in constructor
Raanan Weber 10 years ago
parent
commit
467e9b0696
2 changed files with 7 additions and 6 deletions
  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();
             }