Browse Source

Fixing torusKnot

David Catuhe 11 years ago
parent
commit
e9e75f28b5

+ 4 - 1
Babylon/Materials/babylon.shaderMaterial.js

@@ -27,6 +27,8 @@ var BABYLON = BABYLON || {};
         this._vectors3 = [];
         this._vectors4 = [];
         this._matrices = [];
+
+        this._cachedWorldViewMatrix = new BABYLON.Matrix();
     };
 
     BABYLON.ShaderMaterial.prototype = Object.create(BABYLON.Material.prototype);
@@ -139,7 +141,8 @@ var BABYLON = BABYLON || {};
         }
 
         if (this._options.uniforms.indexOf("worldView") !== -1) {
-            this._effect.setMatrix("worldView", world.multiply(this._scene.getViewMatrix()));
+            world.multiplyToRef(this._scene.getViewMatrix(), this._cachedWorldViewMatrix);
+            this._effect.setMatrix("worldView", this._cachedWorldViewMatrix);
         }
 
         if (this._options.uniforms.indexOf("projection") !== -1) {

+ 2 - 2
Babylon/Mesh/babylon.mesh.js

@@ -1149,9 +1149,9 @@ var BABYLON = BABYLON || {};
         return torus;
     };
 
-    BABYLON.Mesh.CreateTorusKnot = function (name, radius, tube, radialSegments, tubularSegments, scene, updatable) {
+    BABYLON.Mesh.CreateTorusKnot = function (name, radius, tube, radialSegments, tubularSegments, p, q, scene, updatable) {
         var torusKnot = new BABYLON.Mesh(name, scene);
-        var vertexData = BABYLON.VertexData.CreateTorusKnot(radius, tube, radialSegments, tubularSegments);
+        var vertexData = BABYLON.VertexData.CreateTorusKnot(radius, tube, radialSegments, tubularSegments, p, q);
 
         vertexData.applyToMesh(torusKnot, updatable);
 

+ 12 - 14
Babylon/Mesh/babylon.mesh.vertexData.js

@@ -7,7 +7,7 @@ var BABYLON = BABYLON || {};
     };
 
     // Methods
-    BABYLON.VertexData.prototype.applyToMesh = function(mesh, updatable) {
+    BABYLON.VertexData.prototype.applyToMesh = function (mesh, updatable) {
         if (this.positions) {
             mesh.setVerticesData(this.positions, BABYLON.VertexBuffer.PositionKind, updatable);
         }
@@ -185,7 +185,7 @@ var BABYLON = BABYLON || {};
         return result;
     };
 
-    BABYLON.VertexData.CreateBox = function(size) {
+    BABYLON.VertexData.CreateBox = function (size) {
         var normalsSource = [
             new BABYLON.Vector3(0, 0, 1),
             new BABYLON.Vector3(0, 0, -1),
@@ -628,32 +628,30 @@ var BABYLON = BABYLON || {};
             bitan.normalize();
             n.normalize();
 
-            for (var j = 0; j <= tubularSegments; j++) {
+            for (var j = 0; j < tubularSegments; j++) {
                 var modJ = j % tubularSegments;
                 var v = modJ / tubularSegments * 2 * Math.PI;
                 var cx = -tube * Math.cos(v);
                 var cy = tube * Math.sin(v);
 
-                var pos = new BABYLON.Vector3();
-                pos.x = p1.x + cx * n.x + cy * bitan.x;
-                pos.y = p1.y + cx * n.y + cy * bitan.y;
-                pos.z = p1.z + cx * n.z + cy * bitan.z;
-
-                positions.push(pos.x);
-                positions.push(pos.y);
-                positions.push(pos.z);
+                positions.push(p1.x + cx * n.x + cy * bitan.x);
+                positions.push(p1.y + cx * n.y + cy * bitan.y);
+                positions.push(p1.z + cx * n.z + cy * bitan.z);
 
                 uvs.push(i / radialSegments);
                 uvs.push(j / tubularSegments);
             }
         }
 
-        for (var i = 0; i <= radialSegments; i++) {
+        var max = radialSegments * tubularSegments - 1;
+
+        for (var i = 0; i < radialSegments; i++) {
             for (var j = 0; j < tubularSegments; j++) {
+                var jNext =  (j + 1) % tubularSegments;
                 var a = i * tubularSegments + j;
                 var b = (i + 1) * tubularSegments + j;
-                var c = (i + 1) * tubularSegments + j + 1;
-                var d = i * tubularSegments + j + 1;
+                var c = (i + 1) * tubularSegments + jNext;
+                var d = i * tubularSegments + jNext;
 
                 indices.push(a); indices.push(b); indices.push(d);
                 indices.push(b); indices.push(c); indices.push(d);

File diff suppressed because it is too large
+ 2 - 2
babylon.1.11.0-beta.js