Ver Fonte

Testing if refactoring Parametric function to range from (0..1,0..1) instead of (0..pi, 0..2pi) is a good idea or not..

zz85 há 13 anos atrás
pai
commit
6d0800ed58

+ 33 - 7
src/extras/geometries/ParametricGeometries.js

@@ -29,15 +29,16 @@ THREE.TubeGeometry2 = function(path, segments, radius, segmentsRadius, closed, d
         normals = frames.normals,
         binormals = frames.binormals;
 
-    // proxy internals
-    this.tangents = tangents;
-    this.normals = normals;
-    this.binormals = binormals;
+        // proxy internals
+        this.tangents = tangents;
+        this.normals = normals;
+        this.binormals = binormals;
 
    
 
     var ParametricTube = function(u, v) {
-        u /= Math.PI;
+        v *= 2 * pi;
+        
         i = u * (numpoints - 1);
         i = Math.floor(i);
 
@@ -125,6 +126,9 @@ THREE.TorusKnotGeometry2.prototype.constructor = THREE.TorusKnotGeometry2;
 
 
 function klein(u, v) {
+    u *= pi;
+    v *= 2 * pi;
+
     u = u * 2;
     var x, y, z;
     if (u < pi) {
@@ -145,7 +149,9 @@ function klein(u, v) {
 THREE.SphereGeometry2 = function(size, x, y) {
 
     function sphere(u, v) {
-
+        u *= pi;
+        v *= 2 * pi;
+        
         var x = sin(u) * cos(v);
         var y = cos(u);
         var z = -sin(u) * sin(v);
@@ -158,4 +164,24 @@ THREE.SphereGeometry2 = function(size, x, y) {
 };
 
 THREE.SphereGeometry2.prototype = new THREE.Geometry();
-THREE.SphereGeometry2.prototype.constructor = THREE.SphereGeometry2;
+THREE.SphereGeometry2.prototype.constructor = THREE.SphereGeometry2;
+
+
+THREE.PlaneGeometry2 = function(width, depth, segmentsWidth, segmentsDepth) {
+
+    function plane(u, v) {
+        
+        console.log('u, v', u, v);
+        var x = u * width;
+        var y = 0; 
+        var z = v * depth;
+
+        return new THREE.Vector3(x, y, z);
+    }
+  
+    THREE.ParametricGeometry.call(this, segmentsWidth, segmentsDepth, plane);
+
+};
+
+THREE.PlaneGeometry2.prototype = new THREE.Geometry();
+THREE.PlaneGeometry2.prototype.constructor = THREE.PlaneGeometry2;

+ 2 - 3
src/extras/geometries/ParametricGeometry.js

@@ -11,15 +11,14 @@ THREE.ParametricGeometry = function(slices, stacks, func) {
     var verts = this.vertices,
         faces = this.faces,
         uvs = this.faceVertexUvs[0];
-    var pi = Math.PI;
 
     var i, il, theta, j, phi, p;
 
     for (i = 0; i <= slices; i++) {
-        theta = i * pi / slices;
+        theta = i / slices;
 
         for (j = 0; j < stacks; j++) {
-            phi = j * 2 * pi / stacks;
+            phi = j / stacks;
 
             p = func(theta, phi);
             verts.push(new THREE.Vertex(p));