Browse Source

Added CircleGeometry to build and geometries example.

alteredq 13 years ago
parent
commit
d34478d5ca

+ 2 - 0
build/Three.js

@@ -649,6 +649,8 @@ w=e}}THREE.EventTarget.call(this);this.object=a;this.domElement=b!==void 0?b:doc
 s=s-a};this.rotateRight=function(a){a===void 0&&(a=f());s=s+a};this.rotateUp=function(a){a===void 0&&(a=f());q=q-a};this.rotateDown=function(a){a===void 0&&(a=f());q=q+a};this.zoomIn=function(a){a===void 0&&(a=Math.pow(0.95,i.userZoomSpeed));x=x/a};this.zoomOut=function(a){a===void 0&&(a=Math.pow(0.95,i.userZoomSpeed));x=x*a};this.update=function(){var a=this.object.position,b=a.clone().subSelf(this.center),c=Math.atan2(b.x,b.z),d=Math.atan2(Math.sqrt(b.x*b.x+b.z*b.z),b.y);this.autoRotate&&this.rotateLeft(f());
 var c=c+s,d=d+q,d=Math.max(1.0E-6,Math.min(Math.PI-1.0E-6,d)),e=b.length();b.x=e*Math.sin(d)*Math.sin(c);b.y=e*Math.cos(d);b.z=e*Math.sin(d)*Math.cos(c);b.multiplyScalar(x);a.copy(this.center).addSelf(b);this.object.lookAt(this.center);q=s=0;x=1;if(t.distanceTo(this.object.position)>0){this.dispatchEvent(z);t.copy(this.object.position)}};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},false);this.domElement.addEventListener("mousedown",function(a){if(i.userRotate){a.preventDefault();
 if(a.button===0||a.button===2){w=c;l.set(a.clientX,a.clientY)}else if(a.button===1){w=d;p.set(a.clientX,a.clientY)}document.addEventListener("mousemove",g,false);document.addEventListener("mouseup",h,false)}},false);this.domElement.addEventListener("mousewheel",function(a){i.userZoom&&(a.wheelDelta>0?i.zoomOut():i.zoomIn())},false)};
+THREE.CircleGeometry=function(a,b,c,d){THREE.Geometry.call(this);var a=a||50,c=c!==void 0?c:0,d=d!==void 0?d:Math.PI*2,b=b!==void 0?Math.max(3,b):8,e,f=[];e=new THREE.Vector3;var g=new THREE.UV(0.5,0.5);this.vertices.push(e);f.push(g);for(e=0;e<=b;e++){var h=new THREE.Vector3;h.x=a*Math.cos(c+e/b*d);h.y=a*Math.sin(c+e/b*d);this.vertices.push(h);f.push(new THREE.UV((h.x/a+1)/2,-(h.y/a+1)/2+1))}c=new THREE.Vector3(0,0,-1);for(e=1;e<=b;e++){this.faces.push(new THREE.Face3(e,e+1,0,[c,c,c]));this.faceVertexUvs[0].push([f[e],
+f[e+1],g])}this.computeCentroids();this.computeFaceNormals();this.boundingSphere={radius:a}};THREE.CircleGeometry.prototype=Object.create(THREE.Geometry.prototype);
 THREE.CubeGeometry=function(a,b,c,d,e,f,g,h){function i(a,b,c,g,h,i,l,m){var n,o=d||1,p=e||1,q=h/2,r=i/2,s=j.vertices.length;if(a==="x"&&b==="y"||a==="y"&&b==="x")n="z";else if(a==="x"&&b==="z"||a==="z"&&b==="x"){n="y";p=f||1}else if(a==="z"&&b==="y"||a==="y"&&b==="z"){n="x";o=f||1}var t=o+1,x=p+1,X=h/o,N=i/p,aa=new THREE.Vector3;aa[n]=l>0?1:-1;for(h=0;h<x;h++)for(i=0;i<t;i++){var ca=new THREE.Vector3;ca[a]=(i*X-q)*c;ca[b]=(h*N-r)*g;ca[n]=l;j.vertices.push(ca)}for(h=0;h<p;h++)for(i=0;i<o;i++){a=new THREE.Face4(i+
 t*h+s,i+t*(h+1)+s,i+1+t*(h+1)+s,i+1+t*h+s);a.normal.copy(aa);a.vertexNormals.push(aa.clone(),aa.clone(),aa.clone(),aa.clone());a.materialIndex=m;j.faces.push(a);j.faceVertexUvs[0].push([new THREE.UV(i/o,1-h/p),new THREE.UV(i/o,1-(h+1)/p),new THREE.UV((i+1)/o,1-(h+1)/p),new THREE.UV((i+1)/o,1-h/p)])}}THREE.Geometry.call(this);var j=this,l=a/2,m=b/2,n=c/2,p,r,o,q,s,x;if(g!==void 0){if(g instanceof Array)this.materials=g;else{this.materials=[];for(p=0;p<6;p++)this.materials.push(g)}p=0;q=1;r=2;s=3;o=
 4;x=5}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(h!=void 0)for(var t in h)this.sides[t]!==void 0&&(this.sides[t]=h[t]);this.sides.px&&i("z","y",-1,-1,c,b,l,p);this.sides.nx&&i("z","y",1,-1,c,b,-l,q);this.sides.py&&i("x","z",1,1,a,c,m,r);this.sides.ny&&i("x","z",1,-1,a,c,-m,s);this.sides.pz&&i("x","y",1,-1,a,b,n,o);this.sides.nz&&i("x","y",-1,-1,a,b,-n,x);this.computeCentroids();this.mergeVertices()};THREE.CubeGeometry.prototype=Object.create(THREE.Geometry.prototype);

+ 2 - 0
build/custom/ThreeExtras.js

@@ -186,6 +186,8 @@ r=e}}THREE.EventTarget.call(this);this.object=b;this.domElement=a!==void 0?a:doc
 s=s-a};this.rotateRight=function(a){a===void 0&&(a=f());s=s+a};this.rotateUp=function(a){a===void 0&&(a=f());p=p-a};this.rotateDown=function(a){a===void 0&&(a=f());p=p+a};this.zoomIn=function(a){a===void 0&&(a=Math.pow(0.95,i.userZoomSpeed));u=u/a};this.zoomOut=function(a){a===void 0&&(a=Math.pow(0.95,i.userZoomSpeed));u=u*a};this.update=function(){var a=this.object.position,b=a.clone().subSelf(this.center),c=Math.atan2(b.x,b.z),d=Math.atan2(Math.sqrt(b.x*b.x+b.z*b.z),b.y);this.autoRotate&&this.rotateLeft(f());
 var c=c+s,d=d+p,d=Math.max(1.0E-6,Math.min(Math.PI-1.0E-6,d)),e=b.length();b.x=e*Math.sin(d)*Math.sin(c);b.y=e*Math.cos(d);b.z=e*Math.sin(d)*Math.cos(c);b.multiplyScalar(u);a.copy(this.center).addSelf(b);this.object.lookAt(this.center);p=s=0;u=1;if(t.distanceTo(this.object.position)>0){this.dispatchEvent(v);t.copy(this.object.position)}};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},false);this.domElement.addEventListener("mousedown",function(a){if(i.userRotate){a.preventDefault();
 if(a.button===0||a.button===2){r=c;l.set(a.clientX,a.clientY)}else if(a.button===1){r=d;k.set(a.clientX,a.clientY)}document.addEventListener("mousemove",g,false);document.addEventListener("mouseup",h,false)}},false);this.domElement.addEventListener("mousewheel",function(a){i.userZoom&&(a.wheelDelta>0?i.zoomOut():i.zoomIn())},false)};
+THREE.CircleGeometry=function(b,a,c,d){THREE.Geometry.call(this);var b=b||50,c=c!==void 0?c:0,d=d!==void 0?d:Math.PI*2,a=a!==void 0?Math.max(3,a):8,e,f=[];e=new THREE.Vector3;var g=new THREE.UV(0.5,0.5);this.vertices.push(e);f.push(g);for(e=0;e<=a;e++){var h=new THREE.Vector3;h.x=b*Math.cos(c+e/a*d);h.y=b*Math.sin(c+e/a*d);this.vertices.push(h);f.push(new THREE.UV((h.x/b+1)/2,-(h.y/b+1)/2+1))}c=new THREE.Vector3(0,0,-1);for(e=1;e<=a;e++){this.faces.push(new THREE.Face3(e,e+1,0,[c,c,c]));this.faceVertexUvs[0].push([f[e],
+f[e+1],g])}this.computeCentroids();this.computeFaceNormals();this.boundingSphere={radius:b}};THREE.CircleGeometry.prototype=Object.create(THREE.Geometry.prototype);
 THREE.CubeGeometry=function(b,a,c,d,e,f,g,h){function i(a,b,c,g,h,i,k,m){var n,l=d||1,o=e||1,q=h/2,p=i/2,s=j.vertices.length;if(a==="x"&&b==="y"||a==="y"&&b==="x")n="z";else if(a==="x"&&b==="z"||a==="z"&&b==="x"){n="y";o=f||1}else if(a==="z"&&b==="y"||a==="y"&&b==="z"){n="x";l=f||1}var t=l+1,u=o+1,I=h/l,M=i/o,J=new THREE.Vector3;J[n]=k>0?1:-1;for(h=0;h<u;h++)for(i=0;i<t;i++){var N=new THREE.Vector3;N[a]=(i*I-q)*c;N[b]=(h*M-p)*g;N[n]=k;j.vertices.push(N)}for(h=0;h<o;h++)for(i=0;i<l;i++){a=new THREE.Face4(i+
 t*h+s,i+t*(h+1)+s,i+1+t*(h+1)+s,i+1+t*h+s);a.normal.copy(J);a.vertexNormals.push(J.clone(),J.clone(),J.clone(),J.clone());a.materialIndex=m;j.faces.push(a);j.faceVertexUvs[0].push([new THREE.UV(i/l,1-h/o),new THREE.UV(i/l,1-(h+1)/o),new THREE.UV((i+1)/l,1-(h+1)/o),new THREE.UV((i+1)/l,1-h/o)])}}THREE.Geometry.call(this);var j=this,l=b/2,m=a/2,n=c/2,k,o,q,p,s,u;if(g!==void 0){if(g instanceof Array)this.materials=g;else{this.materials=[];for(k=0;k<6;k++)this.materials.push(g)}k=0;p=1;o=2;s=3;q=4;u=
 5}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(h!=void 0)for(var t in h)this.sides[t]!==void 0&&(this.sides[t]=h[t]);this.sides.px&&i("z","y",-1,-1,c,a,l,k);this.sides.nx&&i("z","y",1,-1,c,a,-l,p);this.sides.py&&i("x","z",1,1,b,c,m,o);this.sides.ny&&i("x","z",1,-1,b,c,-m,s);this.sides.pz&&i("x","y",1,-1,b,a,n,q);this.sides.nz&&i("x","y",-1,-1,b,a,-n,u);this.computeCentroids();this.mergeVertices()};THREE.CubeGeometry.prototype=Object.create(THREE.Geometry.prototype);

+ 6 - 2
examples/webgl_geometries.html

@@ -41,7 +41,7 @@
 
 				scene = new THREE.Scene();
 
-				var light, object, materials;
+				var light, object, object2, materials;
 
 				scene.add( new THREE.AmbientLight( 0x404040 ) );
 
@@ -51,7 +51,7 @@
 
 				materials = [
 					new THREE.MeshLambertMaterial( { ambient: 0xbbbbbb, map: THREE.ImageUtils.loadTexture( 'textures/ash_uvgrid01.jpg' ), side: THREE.DoubleSide } ),
-					new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true, transparent: true, opacity: 0.1, doubleSided: true } )
+					new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true, transparent: true, opacity: 0.1, side: THREE.DoubleSide } )
 				];
 
 				materials[ 0 ].map.anisotropy = 16;
@@ -81,6 +81,10 @@
 				object.position.set( -200, 0, 0 );
 				scene.add( object );
 
+				object2 = THREE.SceneUtils.createMultiMaterialObject( new THREE.CircleGeometry( 50, 10, 0, Math.PI ), materials );
+				object2.rotation.x = Math.PI/2;
+				object.add( object2 );
+
 				object = THREE.SceneUtils.createMultiMaterialObject( new THREE.SphereGeometry( 75, 20, 10 ), materials );
 				object.position.set( 0, 0, 0 );
 				scene.add( object );

+ 5 - 5
src/extras/geometries/CircleGeometry.js

@@ -10,7 +10,7 @@ THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
 
     thetaStart = thetaStart !== undefined ? thetaStart : 0;
     thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
-    segments = segments !== undefined ? Math.max(3, segments) : 8;
+    segments = segments !== undefined ? Math.max( 3, segments ) : 8;
 
     var i, uvs = [],
     center = new THREE.Vector3(), centerUV = new THREE.UV( 0.5, 0.5 );
@@ -26,19 +26,19 @@ THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
         vertex.y = radius * Math.sin( thetaStart + i / segments * thetaLength );
 
         this.vertices.push( vertex );
-        uvs.push( new THREE.UV( ( vertex.x / radius + 1 ) / 2, - ( vertex.y / radius + 1 ) / 2 + 1) );
+        uvs.push( new THREE.UV( ( vertex.x / radius + 1 ) / 2, - ( vertex.y / radius + 1 ) / 2 + 1 ) );
 
     }
 
-    var n = new THREE.Vector3(0, 0, -1);
+    var n = new THREE.Vector3( 0, 0, -1 );
 
-    for ( i=1; i <= segments; i ++ ) {
+    for ( i = 1; i <= segments; i ++ ) {
 
         var v1 = i;
         var v2 = i + 1 ;
         var v3 = 0;
 
-        this.faces.push( new THREE.Face3( v1, v2, v3, [ n, n, n ]));
+        this.faces.push( new THREE.Face3( v1, v2, v3, [ n, n, n ] ) );
         this.faceVertexUvs[ 0 ].push( [ uvs[ i ], uvs[ i + 1 ], centerUV ] );
 
     }

+ 1 - 0
utils/files.json

@@ -101,6 +101,7 @@
 		"extras/controls/RollControls.js",
 		"extras/controls/TrackballControls.js",
 		"extras/controls/OrbitControls.js",
+		"extras/geometries/CircleGeometry.js",
 		"extras/geometries/CubeGeometry.js",
 		"extras/geometries/CylinderGeometry.js",
 		"extras/geometries/ExtrudeGeometry.js",