Browse Source

Merge remote-tracking branch 'zz85/master' into dev

Mr.doob 13 years ago
parent
commit
93562b3ca6
2 changed files with 43 additions and 1 deletions
  1. 12 1
      examples/webgl_geometries2.html
  2. 31 0
      src/extras/geometries/ParametricGeometries.js

+ 12 - 1
examples/webgl_geometries2.html

@@ -88,13 +88,24 @@
 				// }
 
 				console.log(THREE.ParametricGeometries);
-				var geo = new THREE.ParametricGeometry(20, 20, THREE.ParametricGeometries.klein);
+				var geo;
+
+
+				geo = new THREE.ParametricGeometry(20, 20, THREE.ParametricGeometries.klein);
 				object = THREE.SceneUtils.createMultiMaterialObject( geo, materials );
 				object.children[ 0 ].doubleSided = true;
 				object.position.set( 0, 0, 0 );
 				object.scale.multiplyScalar(10);
 				scene.add( object );
 
+
+				geo = new THREE.ParametricGeometry(20, 20, THREE.ParametricGeometries.mobius);
+				object = THREE.SceneUtils.createMultiMaterialObject( geo, materials );
+				// object.children[ 0 ].doubleSided = true;
+				object.position.set( 10, 0, 0 );
+				object.scale.multiplyScalar(100);
+				scene.add( object );
+
 				// var geo = new THREE.ParametricGeometry(10, 10, THREE.ParametricGeometries.plane(200, 200));
 				THREE.UVsDebug( geo );
 				document.body.appendChild( THREE.UVsDebug( geo ));

+ 31 - 0
src/extras/geometries/ParametricGeometries.js

@@ -154,7 +154,38 @@ THREE.ParametricGeometries = {
 
             return new THREE.Vector3(x, y, z);
         };
+    },
+
+    mobius: function(u, t) {
+
+        // flat mobius strip
+        // http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
+        // u = u - 0.5;
+        // var v = 2 * pi * t;
+
+        // var x, y, z;
+
+        // var a = 2;
+        // x = cos(v) * (a + u * cos(v/2));
+        // y = sin(v) * (a + u * cos(v/2));
+        // z = u * sin(v/2);
+        // return new THREE.Vector3(x, y, z);
+
+        // volumetric mobius strip
+        u *= pi;
+        t *= 2 * pi;
+
+        u = u * 2
+        var phi = u / 2
+        var major = 2.25, a = 0.125, b = 0.65;
+        var x, y, z;
+        x = a * cos(t) * cos(phi) - b * sin(t) * sin(phi);
+        z = a * cos(t) * sin(phi) + b * sin(t) * cos(phi);
+        y = (major + x) * sin(u);
+        x = (major + x) * cos(u);
+        return new THREE.Vector3(x, y, z);
     }
+
 };