Browse Source

Fixed parameters order while loading primitives
Fixed indices while copying geometry
Added Mesh::makeGeometryUnique

Gwenaël Hagenmuller 11 years ago
parent
commit
3d3014c08b

+ 7 - 7
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -362,7 +362,7 @@ var BABYLON = BABYLON || {};
             return null; // null since geometry could be something else than a box...
         }
 
-        var box = new BABYLON.Geometry.Primitives.Box(parsedBox.id, scene.getEngine(), parsedBox.canBeRegenerated, parsedBox.size, null);
+        var box = new BABYLON.Geometry.Primitives.Box(parsedBox.id, scene.getEngine(), parsedBox.size, parsedBox.canBeRegenerated, null);
         BABYLON.Tags.AddTagsTo(box, parsedBox.tags);
 
         scene.pushGeometry(box, true);
@@ -375,7 +375,7 @@ var BABYLON = BABYLON || {};
             return null; // null since geometry could be something else than a sphere...
         }
 
-        var sphere = new BABYLON.Geometry.Primitives.Sphere(parsedSphere.id, scene.getEngine(), parsedSphere.canBeRegenerated, parsedSphere.segments, parsedSphere.diameter, null);
+        var sphere = new BABYLON.Geometry.Primitives.Sphere(parsedSphere.id, scene.getEngine(), parsedSphere.segments, parsedSphere.diameter, parsedSphere.canBeRegenerated, null);
         BABYLON.Tags.AddTagsTo(sphere, parsedSphere.tags);
 
         scene.pushGeometry(sphere, true);
@@ -388,7 +388,7 @@ var BABYLON = BABYLON || {};
             return null; // null since geometry could be something else than a cylinder...
         }
 
-        var cylinder = new BABYLON.Geometry.Primitives.Cylinder(parsedCylinder.id, scene.getEngine(), parsedCylinder.canBeRegenerated, parsedCylinder.height, parsedCylinder.diameterTop, parsedCylinder.diameterBottom, parsedCylinder.tessellation, null);
+        var cylinder = new BABYLON.Geometry.Primitives.Cylinder(parsedCylinder.id, scene.getEngine(), parsedCylinder.height, parsedCylinder.diameterTop, parsedCylinder.diameterBottom, parsedCylinder.tessellation, parsedCylinder.canBeRegenerated, null);
         BABYLON.Tags.AddTagsTo(cylinder, parsedCylinder.tags);
 
         scene.pushGeometry(cylinder, true);
@@ -401,7 +401,7 @@ var BABYLON = BABYLON || {};
             return null; // null since geometry could be something else than a torus...
         }
 
-        var torus = new BABYLON.Geometry.Primitives.Torus(parsedTorus.id, scene.getEngine(), parsedTorus.canBeRegenerated, parsedTorus.diameter, parsedTorus.thickness, parsedTorus.tessellation, null);
+        var torus = new BABYLON.Geometry.Primitives.Torus(parsedTorus.id, scene.getEngine(), parsedTorus.diameter, parsedTorus.thickness, parsedTorus.tessellation, parsedTorus.canBeRegenerated, null);
         BABYLON.Tags.AddTagsTo(torus, parsedTorus.tags);
 
         scene.pushGeometry(torus, true);
@@ -414,7 +414,7 @@ var BABYLON = BABYLON || {};
             return null; // null since geometry could be something else than a ground...
         }
 
-        var ground = new BABYLON.Geometry.Primitives.Ground(parsedGround.id, scene.getEngine(), parsedGround.canBeRegenerated, parsedGround.width, parsedGround.height, parsedGround.subdivisions, null);
+        var ground = new BABYLON.Geometry.Primitives.Ground(parsedGround.id, scene.getEngine(), parsedGround.width, parsedGround.height, parsedGround.subdivisions, parsedGround.canBeRegenerated, null);
         BABYLON.Tags.AddTagsTo(ground, parsedGround.tags);
 
         scene.pushGeometry(ground, true);
@@ -427,7 +427,7 @@ var BABYLON = BABYLON || {};
             return null; // null since geometry could be something else than a plane...
         }
 
-        var plane = new BABYLON.Geometry.Primitives.Plane(parsedPlane.id, scene.getEngine(), parsedPlane.canBeRegenerated, parsedPlane.size, null);
+        var plane = new BABYLON.Geometry.Primitives.Plane(parsedPlane.id, scene.getEngine(), parsedPlane.size, parsedPlane.canBeRegenerated, null);
         BABYLON.Tags.AddTagsTo(plane, parsedPlane.tags);
 
         scene.pushGeometry(plane, true);
@@ -440,7 +440,7 @@ var BABYLON = BABYLON || {};
             return null; // null since geometry could be something else than a torusKnot...
         }
 
-        var torusKnot = new BABYLON.Geometry.Primitives.TorusKnot(parsedTorusKnot.id, scene.getEngine(), parsedTorusKnot.canBeRegenerated, parsedTorusKnot.radius, parsedTorusKnot.tube, parsedTorusKnot.radialSegments, parsedTorusKnot.tubularSegments, parsedTorusKnot.p, parsedTorusKnot.q, null);
+        var torusKnot = new BABYLON.Geometry.Primitives.TorusKnot(parsedTorusKnot.id, scene.getEngine(), parsedTorusKnot.radius, parsedTorusKnot.tube, parsedTorusKnot.radialSegments, parsedTorusKnot.tubularSegments, parsedTorusKnot.p, parsedTorusKnot.q, parsedTorusKnot.canBeRegenerated, null);
         BABYLON.Tags.AddTagsTo(torusKnot, parsedTorusKnot.tags);
 
         scene.pushGeometry(torusKnot, true);

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

@@ -339,7 +339,13 @@ var BABYLON;
 
         Geometry.prototype.copy = function (id) {
             var vertexData = new BABYLON.VertexData();
-            vertexData.indices = this.getIndices(); // todo: clone
+
+            vertexData.indices = [];
+
+            var indices = this.getIndices();
+            for (var index = 0; index < indices.length; index++) {
+                vertexData.indices.push(indices[index]);
+            }
 
             var updatable = false;
             var stopChecking = false;

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

@@ -349,7 +349,13 @@
 
         public copy(id: string): Geometry {
             var vertexData = new BABYLON.VertexData();
-            vertexData.indices = this.getIndices(); // todo: clone
+
+            vertexData.indices = [];
+
+            var indices = this.getIndices();
+            for (var index = 0; index < indices.length; index++) {
+                vertexData.indices.push(indices[index]);
+            }
 
             var updatable = false;
             var stopChecking = false;

+ 16 - 9
Babylon/Mesh/babylon.mesh.js

@@ -271,15 +271,15 @@ var BABYLON;
         Mesh.prototype.refreshBoundingInfo = function () {
             var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
 
-            if (!data) {
-                return;
+            if (data) {
+                var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this.getTotalVertices());
+                this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
             }
 
-            var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this.getTotalVertices());
-            this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
-
-            for (var index = 0; index < this.subMeshes.length; index++) {
-                this.subMeshes[index].refreshBoundingInfo();
+            if (this.subMeshes) {
+                for (var index = 0; index < this.subMeshes.length; index++) {
+                    this.subMeshes[index].refreshBoundingInfo();
+                }
             }
 
             this._updateBoundingInfo();
@@ -436,12 +436,19 @@ var BABYLON;
             if (!makeItUnique) {
                 this._geometry.updateVerticesData(kind, data, updateExtends);
             } else {
-                var geometry = this._geometry.copy(BABYLON.Geometry.RandomId());
-                geometry.applyToMesh(this);
+                this.makeGeometryUnique();
                 this.updateVerticesData(kind, data, updateExtends, false);
             }
         };
 
+        Mesh.prototype.makeGeometryUnique = function () {
+            if (!this._geometry) {
+                return;
+            }
+            var geometry = this._geometry.copy(BABYLON.Geometry.RandomId());
+            geometry.applyToMesh(this);
+        };
+
         Mesh.prototype.setIndices = function (indices) {
             if (!this._geometry) {
                 var vertexData = new BABYLON.VertexData();

+ 16 - 9
Babylon/Mesh/babylon.mesh.ts

@@ -289,15 +289,15 @@
         public refreshBoundingInfo(): void {
             var data = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
 
-            if (!data) {
-                return;
+            if (data) {
+                var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this.getTotalVertices());
+                this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
             }
 
-            var extend = BABYLON.Tools.ExtractMinAndMax(data, 0, this.getTotalVertices());
-            this._boundingInfo = new BABYLON.BoundingInfo(extend.minimum, extend.maximum);
-
-            for (var index = 0; index < this.subMeshes.length; index++) {
-                this.subMeshes[index].refreshBoundingInfo();
+            if (this.subMeshes) {
+                for (var index = 0; index < this.subMeshes.length; index++) {
+                    this.subMeshes[index].refreshBoundingInfo();
+                }
             }
 
             this._updateBoundingInfo();
@@ -457,12 +457,19 @@
                 this._geometry.updateVerticesData(kind, data, updateExtends);
             }
             else {
-                var geometry = this._geometry.copy(Geometry.RandomId());
-                geometry.applyToMesh(this);
+                this.makeGeometryUnique();
                 this.updateVerticesData(kind, data, updateExtends, false);
             }
         }
 
+        public makeGeometryUnique() {
+            if (!this._geometry) {
+                return;
+            }
+            var geometry = this._geometry.copy(Geometry.RandomId());
+            geometry.applyToMesh(this);
+        }
+
         public setIndices(indices: number[]): void {
             if (!this._geometry) {
                 var vertexData = new BABYLON.VertexData();

File diff suppressed because it is too large
+ 2 - 2
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/ourOwnBabylon.js