提交 825715b3 编写于 作者: A alteredq

Unflipped CubeGeometry.

上级 9a33d707
......@@ -625,8 +625,8 @@ t=t-a};this.rotateRight=function(a){a===void 0&&(a=f());t=t+a};this.rotateUp=fun
var c=c+t,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(u);a.copy(this.center).addSelf(b);this.object.lookAt(this.center);q=t=0;u=1;if(w.distanceTo(this.object.position)>0){this.dispatchEvent(x);w.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){s=c;l.set(a.clientX,a.clientY)}else if(a.button===1){s=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.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,r=h/2,q=i/2,t=k.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 u=o+1,j=p+1,w=h/o,L=i/p,S=new THREE.Vector3;S[n]=l>0?1:-1;for(h=0;h<j;h++)for(i=0;i<u;i++){var aa=new THREE.Vector3;aa[a]=(i*w-r)*c;aa[b]=(h*L-q)*g;aa[n]=l;k.vertices.push(aa)}for(h=0;h<p;h++)for(i=0;i<o;i++){a=new THREE.Face4(i+
u*h+t,i+u*(h+1)+t,i+1+u*(h+1)+t,i+1+u*h+t);a.normal.copy(S);a.vertexNormals.push(S.clone(),S.clone(),S.clone(),S.clone());a.materialIndex=m;k.faces.push(a);k.faceVertexUvs[0].push([new THREE.UV(i/o,h/p),new THREE.UV(i/o,(h+1)/p),new THREE.UV((i+1)/o,(h+1)/p),new THREE.UV((i+1)/o,h/p)])}}THREE.Geometry.call(this);var k=this,l=a/2,o=b/2,m=c/2,p,r,n,q,t,u;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;t=3;n=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 w in h)this.sides[w]!==void 0&&(this.sides[w]=h[w]);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,o,r);this.sides.ny&&i("x","z",1,-1,a,c,-o,t);this.sides.pz&&i("x","y",1,-1,a,b,m,n);this.sides.nz&&i("x","y",-1,-1,a,b,-m,u);this.computeCentroids();this.mergeVertices()};THREE.CubeGeometry.prototype=Object.create(THREE.Geometry.prototype);
u*h+t,i+u*(h+1)+t,i+1+u*(h+1)+t,i+1+u*h+t);a.normal.copy(S);a.vertexNormals.push(S.clone(),S.clone(),S.clone(),S.clone());a.materialIndex=m;k.faces.push(a);k.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 k=this,l=a/2,o=b/2,m=c/2,p,r,n,q,t,u;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;t=3;n=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 w in h)this.sides[w]!==void 0&&(this.sides[w]=h[w]);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,o,r);this.sides.ny&&i("x","z",1,-1,a,c,-o,t);this.sides.pz&&i("x","y",1,-1,a,b,m,n);this.sides.nz&&i("x","y",-1,-1,a,b,-m,u);this.computeCentroids();this.mergeVertices()};THREE.CubeGeometry.prototype=Object.create(THREE.Geometry.prototype);
THREE.CylinderGeometry=function(a,b,c,d,e,f){THREE.Geometry.call(this);var a=a!==void 0?a:20,b=b!==void 0?b:20,c=c!==void 0?c:100,g=c/2,d=d||8,e=e||1,h,i,k=[],l=[];for(i=0;i<=e;i++){var o=[],m=[],p=i/e,r=p*(b-a)+a;for(h=0;h<=d;h++){var n=h/d,q=new THREE.Vector3;q.x=r*Math.sin(n*Math.PI*2);q.y=-p*c+g;q.z=r*Math.cos(n*Math.PI*2);this.vertices.push(q);o.push(this.vertices.length-1);m.push(new THREE.UV(n,p))}k.push(o);l.push(m)}c=(b-a)/c;for(h=0;h<d;h++){if(a!==0){o=this.vertices[k[0][h]].clone();m=this.vertices[k[0][h+
1]].clone()}else{o=this.vertices[k[1][h]].clone();m=this.vertices[k[1][h+1]].clone()}o.setY(Math.sqrt(o.x*o.x+o.z*o.z)*c).normalize();m.setY(Math.sqrt(m.x*m.x+m.z*m.z)*c).normalize();for(i=0;i<e;i++){var p=k[i][h],r=k[i+1][h],n=k[i+1][h+1],q=k[i][h+1],t=o.clone(),u=o.clone(),w=m.clone(),s=m.clone(),x=l[i][h].clone(),F=l[i+1][h].clone(),C=l[i+1][h+1].clone(),z=l[i][h+1].clone();this.faces.push(new THREE.Face4(p,r,n,q,[t,u,w,s]));this.faceVertexUvs[0].push([x,F,C,z])}}if(!f&&a>0){this.vertices.push(new THREE.Vector3(0,
g,0));for(h=0;h<d;h++){p=k[0][h];r=k[0][h+1];n=this.vertices.length-1;t=new THREE.Vector3(0,1,0);u=new THREE.Vector3(0,1,0);w=new THREE.Vector3(0,1,0);x=l[0][h].clone();F=l[0][h+1].clone();C=new THREE.UV(F.u,0);this.faces.push(new THREE.Face3(p,r,n,[t,u,w]));this.faceVertexUvs[0].push([x,F,C])}}if(!f&&b>0){this.vertices.push(new THREE.Vector3(0,-g,0));for(h=0;h<d;h++){p=k[i][h+1];r=k[i][h];n=this.vertices.length-1;t=new THREE.Vector3(0,-1,0);u=new THREE.Vector3(0,-1,0);w=new THREE.Vector3(0,-1,0);
......
......@@ -180,8 +180,8 @@ s=s-a};this.rotateRight=function(a){a===void 0&&(a=f());s=s+a};this.rotateUp=fun
var c=c+s,d=d+r,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(t);a.copy(this.center).addSelf(b);this.object.lookAt(this.center);r=s=0;t=1;if(v.distanceTo(this.object.position)>0){this.dispatchEvent(x);v.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){p=c;l.set(a.clientX,a.clientY)}else if(a.button===1){p=d;m.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.CubeGeometry=function(b,a,c,d,e,f,g,h){function i(a,b,c,g,h,i,k,m){var l,n=d||1,o=e||1,q=h/2,r=i/2,s=j.vertices.length;if(a==="x"&&b==="y"||a==="y"&&b==="x")l="z";else if(a==="x"&&b==="z"||a==="z"&&b==="x"){l="y";o=f||1}else if(a==="z"&&b==="y"||a==="y"&&b==="z"){l="x";n=f||1}var t=n+1,v=o+1,I=h/n,M=i/o,J=new THREE.Vector3;J[l]=k>0?1:-1;for(h=0;h<v;h++)for(i=0;i<t;i++){var O=new THREE.Vector3;O[a]=(i*I-q)*c;O[b]=(h*M-r)*g;O[l]=k;j.vertices.push(O)}for(h=0;h<o;h++)for(i=0;i<n;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/n,h/o),new THREE.UV(i/n,(h+1)/o),new THREE.UV((i+1)/n,(h+1)/o),new THREE.UV((i+1)/n,h/o)])}}THREE.Geometry.call(this);var j=this,l=b/2,n=a/2,k=c/2,m,o,q,r,s,t;if(g!==void 0){if(g instanceof Array)this.materials=g;else{this.materials=[];for(m=0;m<6;m++)this.materials.push(g)}m=0;r=1;o=2;s=3;q=4;t=5}else this.materials=
[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(h!=void 0)for(var v in h)this.sides[v]!==void 0&&(this.sides[v]=h[v]);this.sides.px&&i("z","y",-1,-1,c,a,l,m);this.sides.nx&&i("z","y",1,-1,c,a,-l,r);this.sides.py&&i("x","z",1,1,b,c,n,o);this.sides.ny&&i("x","z",1,-1,b,c,-n,s);this.sides.pz&&i("x","y",1,-1,b,a,k,q);this.sides.nz&&i("x","y",-1,-1,b,a,-k,t);this.computeCentroids();this.mergeVertices()};THREE.CubeGeometry.prototype=Object.create(THREE.Geometry.prototype);
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/n,1-h/o),new THREE.UV(i/n,1-(h+1)/o),new THREE.UV((i+1)/n,1-(h+1)/o),new THREE.UV((i+1)/n,1-h/o)])}}THREE.Geometry.call(this);var j=this,l=b/2,n=a/2,k=c/2,m,o,q,r,s,t;if(g!==void 0){if(g instanceof Array)this.materials=g;else{this.materials=[];for(m=0;m<6;m++)this.materials.push(g)}m=0;r=1;o=2;s=3;q=4;t=
5}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(h!=void 0)for(var v in h)this.sides[v]!==void 0&&(this.sides[v]=h[v]);this.sides.px&&i("z","y",-1,-1,c,a,l,m);this.sides.nx&&i("z","y",1,-1,c,a,-l,r);this.sides.py&&i("x","z",1,1,b,c,n,o);this.sides.ny&&i("x","z",1,-1,b,c,-n,s);this.sides.pz&&i("x","y",1,-1,b,a,k,q);this.sides.nz&&i("x","y",-1,-1,b,a,-k,t);this.computeCentroids();this.mergeVertices()};THREE.CubeGeometry.prototype=Object.create(THREE.Geometry.prototype);
THREE.CylinderGeometry=function(b,a,c,d,e,f){THREE.Geometry.call(this);var b=b!==void 0?b:20,a=a!==void 0?a:20,c=c!==void 0?c:100,g=c/2,d=d||8,e=e||1,h,i,j=[],l=[];for(i=0;i<=e;i++){var n=[],k=[],m=i/e,o=m*(a-b)+b;for(h=0;h<=d;h++){var q=h/d,r=new THREE.Vector3;r.x=o*Math.sin(q*Math.PI*2);r.y=-m*c+g;r.z=o*Math.cos(q*Math.PI*2);this.vertices.push(r);n.push(this.vertices.length-1);k.push(new THREE.UV(q,m))}j.push(n);l.push(k)}c=(a-b)/c;for(h=0;h<d;h++){if(b!==0){n=this.vertices[j[0][h]].clone();k=this.vertices[j[0][h+
1]].clone()}else{n=this.vertices[j[1][h]].clone();k=this.vertices[j[1][h+1]].clone()}n.setY(Math.sqrt(n.x*n.x+n.z*n.z)*c).normalize();k.setY(Math.sqrt(k.x*k.x+k.z*k.z)*c).normalize();for(i=0;i<e;i++){var m=j[i][h],o=j[i+1][h],q=j[i+1][h+1],r=j[i][h+1],s=n.clone(),t=n.clone(),v=k.clone(),p=k.clone(),x=l[i][h].clone(),z=l[i+1][h].clone(),A=l[i+1][h+1].clone(),w=l[i][h+1].clone();this.faces.push(new THREE.Face4(m,o,q,r,[s,t,v,p]));this.faceVertexUvs[0].push([x,z,A,w])}}if(!f&&b>0){this.vertices.push(new THREE.Vector3(0,
g,0));for(h=0;h<d;h++){m=j[0][h];o=j[0][h+1];q=this.vertices.length-1;s=new THREE.Vector3(0,1,0);t=new THREE.Vector3(0,1,0);v=new THREE.Vector3(0,1,0);x=l[0][h].clone();z=l[0][h+1].clone();A=new THREE.UV(z.u,0);this.faces.push(new THREE.Face3(m,o,q,[s,t,v]));this.faceVertexUvs[0].push([x,z,A])}}if(!f&&a>0){this.vertices.push(new THREE.Vector3(0,-g,0));for(h=0;h<d;h++){m=j[i][h+1];o=j[i][h];q=this.vertices.length-1;s=new THREE.Vector3(0,-1,0);t=new THREE.Vector3(0,-1,0);v=new THREE.Vector3(0,-1,0);
......
......@@ -127,10 +127,10 @@ THREE.CubeGeometry = function ( width, height, depth, segmentsWidth, segmentsHei
scope.faces.push( face );
scope.faceVertexUvs[ 0 ].push( [
new THREE.UV( ix / gridX, iy / gridY ),
new THREE.UV( ix / gridX, ( iy + 1 ) / gridY ),
new THREE.UV( ( ix + 1 ) / gridX, ( iy + 1 ) / gridY ),
new THREE.UV( ( ix + 1 ) / gridX, iy / gridY )
new THREE.UV( ix / gridX, 1 - iy / gridY ),
new THREE.UV( ix / gridX, 1 - ( iy + 1 ) / gridY ),
new THREE.UV( ( ix + 1 ) / gridX, 1- ( iy + 1 ) / gridY ),
new THREE.UV( ( ix + 1 ) / gridX, 1 - iy / gridY )
] );
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册