浏览代码

Tweaked and renamed geometry extrude examples.

alteredq 13 年之前
父节点
当前提交
36338eeeef
共有 3 个文件被更改,包括 45 次插入31 次删除
  1. 7 7
      build/Three.js
  2. 7 7
      build/custom/ThreeExtras.js
  3. 31 17
      examples/webgl_geometry_extrude.html

+ 7 - 7
build/Three.js

@@ -507,13 +507,13 @@ z=new THREE.UV(t.u,1),this.faces.push(new THREE.Face3(c,o,p,[q,n,s])),this.faceV
 THREE.ExtrudeGeometry=function(a,b){if(typeof a!=="undefined"){THREE.Geometry.call(this);var a=a instanceof Array?a:[a],c,d=a.length,e;this.shapebb=a[d-1].getBoundingBox();for(c=0;c<d;c++)e=a[c],this.addShape(e,b);this.computeCentroids();this.computeFaceNormals()}};THREE.ExtrudeGeometry.prototype=new THREE.Geometry;THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;
 THREE.ExtrudeGeometry.prototype.addShape=function(a,b){function c(a,b,c){b||console.log("die");return b.clone().multiplyScalar(c).addSelf(a)}function d(a,b,c){var d=THREE.ExtrudeGeometry.__v1,e=THREE.ExtrudeGeometry.__v2,f=THREE.ExtrudeGeometry.__v3,g=THREE.ExtrudeGeometry.__v4,h=THREE.ExtrudeGeometry.__v5,i=THREE.ExtrudeGeometry.__v6;d.set(a.x-b.x,a.y-b.y);e.set(a.x-c.x,a.y-c.y);d=d.normalize();e=e.normalize();f.set(-d.y,d.x);g.set(e.y,-e.x);h.copy(a).addSelf(f);i.copy(a).addSelf(g);if(h.equals(i))return g.clone();
 h.copy(b).addSelf(f);i.copy(c).addSelf(g);f=d.dot(g);g=i.subSelf(h).dot(g);f===0&&(console.log("Either infinite or no solutions!"),g===0?console.log("Its finite solutions."):console.log("Too bad, no solutions."));g/=f;if(g<0)return b=Math.atan2(b.y-a.y,b.x-a.x),a=Math.atan2(c.y-a.y,c.x-a.x),b>a&&(a+=Math.PI*2),a=(b+a)/2,new THREE.Vector2(-Math.cos(a),-Math.sin(a));return d.multiplyScalar(g).addSelf(h).subSelf(a).clone()}function e(a){for(y=a.length;--y>=0;){Z=y;da=y-1;da<0&&(da=a.length-1);for(var b=
-0,c=m+j*2,b=0;b<c;b++){var d=R*b,e=R*(b+1),f=ba+Z+d,g=ba+Z+e,k=f,d=ba+da+d,e=ba+da+e,l=g;k+=G;d+=G;e+=G;l+=G;w.faces.push(new THREE.Face4(k,d,e,l,null,null,z));z&&(k=b/c,d=(b+1)/c,e=h+i*2,f=(w.vertices[f].position.z+i)/e,g=(w.vertices[g].position.z+i)/e,w.faceVertexUvs[0].push([new THREE.UV(f,k),new THREE.UV(g,k),new THREE.UV(g,d),new THREE.UV(f,d)]))}}}function f(a,b,c){w.vertices.push(new THREE.Vertex(new THREE.Vector3(a,b,c)))}function g(a,b,c){a+=G;b+=G;c+=G;w.faces.push(new THREE.Face3(a,b,c,
-null,null,t));if(t){var d=A.maxY,e=A.maxX,f=w.vertices[b].position.x,b=w.vertices[b].position.y,g=w.vertices[c].position.x,c=w.vertices[c].position.y;w.faceVertexUvs[0].push([new THREE.UV(w.vertices[a].position.x/e,w.vertices[a].position.y/d),new THREE.UV(f/e,b/d),new THREE.UV(g/e,c/d)])}}var h=b.amount!==void 0?b.amount:100,i=b.bevelThickness!==void 0?b.bevelThickness:6,k=b.bevelSize!==void 0?b.bevelSize:i-2,j=b.bevelSegments!==void 0?b.bevelSegments:3,o=b.bevelEnabled!==void 0?b.bevelEnabled:!0,
-p=b.curveSegments!==void 0?b.curveSegments:12,m=b.steps!==void 0?b.steps:1,q=b.bendPath,n=b.extrudePath,s,r=!1,u=b.useSpacedPoints!==void 0?b.useSpacedPoints:!1,t=b.material,z=b.extrudeMaterial,A=this.shapebb;if(n)s=n.getPoints(p),m=s.length,r=!0,o=!1;o||(k=i=j=0);var E,D,B,w=this,G=this.vertices.length;q&&a.addWrapPath(q);p=u?a.extractAllSpacedPoints(p):a.extractAllPoints(p);q=p.shape;p=p.holes;if(n=!THREE.Shape.Utils.isClockWise(q)){q=q.reverse();D=0;for(B=p.length;D<B;D++)E=p[D],THREE.Shape.Utils.isClockWise(E)&&
-(p[D]=E.reverse());n=!1}n=THREE.Shape.Utils.triangulateShape(q,p);u=q;D=0;for(B=p.length;D<B;D++)E=p[D],q=q.concat(E);var y,K,$,Q,Y,S,R=q.length,l=n.length,W=[];y=0;K=u.length;Z=K-1;for(da=y+1;y<K;y++,Z++,da++)Z===K&&(Z=0),da===K&&(da=0),W[y]=d(u[y],u[Z],u[da]);var v=[],X,L=W.concat();D=0;for(B=p.length;D<B;D++){E=p[D];X=[];y=0;K=E.length;Z=K-1;for(da=y+1;y<K;y++,Z++,da++)Z===K&&(Z=0),da===K&&(da=0),X[y]=d(E[y],E[Z],E[da]);v.push(X);L=L.concat(X)}for($=0;$<j;$++){Q=$/j;Y=i*(1-Q);Q=k*Math.sin(Q*Math.PI/
-2);y=0;for(K=u.length;y<K;y++)S=c(u[y],W[y],Q),f(S.x,S.y,-Y);D=0;for(B=p.length;D<B;D++){E=p[D];X=v[D];y=0;for(K=E.length;y<K;y++)S=c(E[y],X[y],Q),f(S.x,S.y,-Y)}}Q=k;for(y=0;y<R;y++)S=o?c(q[y],L[y],Q):q[y],r?f(S.x,S.y+s[0].y,s[0].x):f(S.x,S.y,0);for($=1;$<=m;$++)for(y=0;y<R;y++)S=o?c(q[y],L[y],Q):q[y],r?f(S.x,S.y+s[$-1].y,s[$-1].x):f(S.x,S.y,h/m*$);for($=j-1;$>=0;$--){Q=$/j;Y=i*(1-Q);Q=k*Math.sin(Q*Math.PI/2);y=0;for(K=u.length;y<K;y++)S=c(u[y],W[y],Q),f(S.x,S.y,h+Y);D=0;for(B=p.length;D<B;D++){E=
-p[D];X=v[D];y=0;for(K=E.length;y<K;y++)S=c(E[y],X[y],Q),r?f(S.x,S.y+s[m-1].y,s[m-1].x+Y):f(S.x,S.y,h+Y)}}if(o){o=R*0;for(y=0;y<l;y++)k=n[y],g(k[2]+o,k[1]+o,k[0]+o);o=R*(m+j*2);for(y=0;y<l;y++)k=n[y],g(k[0]+o,k[1]+o,k[2]+o)}else{for(y=0;y<l;y++)k=n[y],g(k[2],k[1],k[0]);for(y=0;y<l;y++)k=n[y],g(k[0]+R*m,k[1]+R*m,k[2]+R*m)}var Z,da,ba=0;e(u);ba+=u.length;D=0;for(B=p.length;D<B;D++)E=p[D],e(E),ba+=E.length};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;THREE.ExtrudeGeometry.__v2=new THREE.Vector2;
-THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;THREE.ExtrudeGeometry.__v6=new THREE.Vector2;
+0,c=m+j*2,b=0;b<c;b++){var d=R*b,e=R*(b+1),f=ba+Z+d,g=ba+Z+e,k=f,d=ba+da+d,e=ba+da+e,l=g;k+=G;d+=G;e+=G;l+=G;w.faces.push(new THREE.Face4(k,d,e,l,null,null,z));z!==void 0&&(k=b/c,d=(b+1)/c,e=h+i*2,f=(w.vertices[f].position.z+i)/e,g=(w.vertices[g].position.z+i)/e,w.faceVertexUvs[0].push([new THREE.UV(f,k),new THREE.UV(g,k),new THREE.UV(g,d),new THREE.UV(f,d)]))}}}function f(a,b,c){w.vertices.push(new THREE.Vertex(new THREE.Vector3(a,b,c)))}function g(a,b,c){a+=G;b+=G;c+=G;w.faces.push(new THREE.Face3(a,
+b,c,null,null,t));if(t!==void 0){var d=A.minX,e=A.minY,f=A.maxY,g=A.maxX,h=w.vertices[b].position.x-d,b=w.vertices[b].position.y-e,i=w.vertices[c].position.x-d,c=w.vertices[c].position.y-e;w.faceVertexUvs[0].push([new THREE.UV((w.vertices[a].position.x-d)/g,(w.vertices[a].position.y-e)/f),new THREE.UV(h/g,b/f),new THREE.UV(i/g,c/f)])}}var h=b.amount!==void 0?b.amount:100,i=b.bevelThickness!==void 0?b.bevelThickness:6,k=b.bevelSize!==void 0?b.bevelSize:i-2,j=b.bevelSegments!==void 0?b.bevelSegments:
+3,o=b.bevelEnabled!==void 0?b.bevelEnabled:!0,p=b.curveSegments!==void 0?b.curveSegments:12,m=b.steps!==void 0?b.steps:1,q=b.bendPath,n=b.extrudePath,s,r=!1,u=b.useSpacedPoints!==void 0?b.useSpacedPoints:!1,t=b.material,z=b.extrudeMaterial,A=this.shapebb;if(n)s=n.getPoints(p),m=s.length,r=!0,o=!1;o||(k=i=j=0);var E,D,B,w=this,G=this.vertices.length;q&&a.addWrapPath(q);p=u?a.extractAllSpacedPoints(p):a.extractAllPoints(p);q=p.shape;p=p.holes;if(n=!THREE.Shape.Utils.isClockWise(q)){q=q.reverse();D=
+0;for(B=p.length;D<B;D++)E=p[D],THREE.Shape.Utils.isClockWise(E)&&(p[D]=E.reverse());n=!1}n=THREE.Shape.Utils.triangulateShape(q,p);u=q;D=0;for(B=p.length;D<B;D++)E=p[D],q=q.concat(E);var y,K,$,Q,Y,S,R=q.length,l=n.length,W=[];y=0;K=u.length;Z=K-1;for(da=y+1;y<K;y++,Z++,da++)Z===K&&(Z=0),da===K&&(da=0),W[y]=d(u[y],u[Z],u[da]);var v=[],X,L=W.concat();D=0;for(B=p.length;D<B;D++){E=p[D];X=[];y=0;K=E.length;Z=K-1;for(da=y+1;y<K;y++,Z++,da++)Z===K&&(Z=0),da===K&&(da=0),X[y]=d(E[y],E[Z],E[da]);v.push(X);
+L=L.concat(X)}for($=0;$<j;$++){Q=$/j;Y=i*(1-Q);Q=k*Math.sin(Q*Math.PI/2);y=0;for(K=u.length;y<K;y++)S=c(u[y],W[y],Q),f(S.x,S.y,-Y);D=0;for(B=p.length;D<B;D++){E=p[D];X=v[D];y=0;for(K=E.length;y<K;y++)S=c(E[y],X[y],Q),f(S.x,S.y,-Y)}}Q=k;for(y=0;y<R;y++)S=o?c(q[y],L[y],Q):q[y],r?f(S.x,S.y+s[0].y,s[0].x):f(S.x,S.y,0);for($=1;$<=m;$++)for(y=0;y<R;y++)S=o?c(q[y],L[y],Q):q[y],r?f(S.x,S.y+s[$-1].y,s[$-1].x):f(S.x,S.y,h/m*$);for($=j-1;$>=0;$--){Q=$/j;Y=i*(1-Q);Q=k*Math.sin(Q*Math.PI/2);y=0;for(K=u.length;y<
+K;y++)S=c(u[y],W[y],Q),f(S.x,S.y,h+Y);D=0;for(B=p.length;D<B;D++){E=p[D];X=v[D];y=0;for(K=E.length;y<K;y++)S=c(E[y],X[y],Q),r?f(S.x,S.y+s[m-1].y,s[m-1].x+Y):f(S.x,S.y,h+Y)}}if(o){o=R*0;for(y=0;y<l;y++)k=n[y],g(k[2]+o,k[1]+o,k[0]+o);o=R*(m+j*2);for(y=0;y<l;y++)k=n[y],g(k[0]+o,k[1]+o,k[2]+o)}else{for(y=0;y<l;y++)k=n[y],g(k[2],k[1],k[0]);for(y=0;y<l;y++)k=n[y],g(k[0]+R*m,k[1]+R*m,k[2]+R*m)}var Z,da,ba=0;e(u);ba+=u.length;D=0;for(B=p.length;D<B;D++)E=p[D],e(E),ba+=E.length};
+THREE.ExtrudeGeometry.__v1=new THREE.Vector2;THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;THREE.ExtrudeGeometry.__v6=new THREE.Vector2;
 THREE.IcosahedronGeometry=function(a){function b(a,b,c){var d=Math.sqrt(a*a+b*b+c*c);return e.vertices.push(new THREE.Vertex(new THREE.Vector3(a/d,b/d,c/d)))-1}function c(a,b,c,d){var f=e.vertices[a].position,g=e.vertices[b].position,h=e.vertices[c].position,a=new THREE.Face3(a,b,c);a.vertexNormals.push(f.clone().normalize(),g.clone().normalize(),h.clone().normalize());d.faces.push(a);d.faceVertexUvs[0].push([new THREE.UV(1-(Math.atan2(f.z,f.x)+Math.PI)%Math.PI/Math.PI*0.5,0.5-f.y/2),new THREE.UV(1-
 (Math.atan2(g.z,g.x)+Math.PI)%Math.PI/Math.PI*0.5,0.5-g.y/2),new THREE.UV(1-(Math.atan2(h.z,h.x)+Math.PI)%Math.PI/Math.PI*0.5,0.5-h.y/2)])}function d(a,c){var d=e.vertices[a].position,f=e.vertices[c].position;return b((d.x+f.x)/2,(d.y+f.y)/2,(d.z+f.z)/2)}var e=this,f=new THREE.Geometry;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;b(-1,a,0);b(1,a,0);b(-1,-a,0);b(1,-a,0);b(0,-1,a);b(0,1,a);b(0,-1,-a);b(0,1,-a);b(a,0,-1);b(a,0,1);b(-a,0,-1);b(-a,0,1);c(0,11,5,f);c(0,5,1,f);c(0,
 1,7,f);c(0,7,10,f);c(0,10,11,f);c(1,5,9,f);c(5,11,4,f);c(11,10,2,f);c(10,7,6,f);c(7,1,8,f);c(3,9,4,f);c(3,4,2,f);c(3,2,6,f);c(3,6,8,f);c(3,8,9,f);c(4,9,5,f);c(2,4,11,f);c(6,2,10,f);c(8,6,7,f);c(9,8,1,f);for(var g=0;g<this.subdivisions;g++){var a=new THREE.Geometry,h;for(h in f.faces){var i=d(f.faces[h].a,f.faces[h].b),k=d(f.faces[h].b,f.faces[h].c),j=d(f.faces[h].c,f.faces[h].a);c(f.faces[h].a,i,j,a);c(f.faces[h].b,k,i,a);c(f.faces[h].c,j,k,a);c(i,k,j,a)}f.faces=a.faces;f.faceVertexUvs[0]=a.faceVertexUvs[0]}e.faces=

+ 7 - 7
build/custom/ThreeExtras.js

@@ -164,13 +164,13 @@ w=new THREE.UV(t.u,1),this.faces.push(new THREE.Face3(c,q,p,[l,n,r])),this.faceV
 THREE.ExtrudeGeometry=function(a,b){if(typeof a!=="undefined"){THREE.Geometry.call(this);var a=a instanceof Array?a:[a],c,d=a.length,e;this.shapebb=a[d-1].getBoundingBox();for(c=0;c<d;c++)e=a[c],this.addShape(e,b);this.computeCentroids();this.computeFaceNormals()}};THREE.ExtrudeGeometry.prototype=new THREE.Geometry;THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;
 THREE.ExtrudeGeometry.prototype.addShape=function(a,b){function c(a,b,c){b||console.log("die");return b.clone().multiplyScalar(c).addSelf(a)}function d(a,b,c){var d=THREE.ExtrudeGeometry.__v1,e=THREE.ExtrudeGeometry.__v2,g=THREE.ExtrudeGeometry.__v3,f=THREE.ExtrudeGeometry.__v4,h=THREE.ExtrudeGeometry.__v5,i=THREE.ExtrudeGeometry.__v6;d.set(a.x-b.x,a.y-b.y);e.set(a.x-c.x,a.y-c.y);d=d.normalize();e=e.normalize();g.set(-d.y,d.x);f.set(e.y,-e.x);h.copy(a).addSelf(g);i.copy(a).addSelf(f);if(h.equals(i))return f.clone();
 h.copy(b).addSelf(g);i.copy(c).addSelf(f);g=d.dot(f);f=i.subSelf(h).dot(f);g===0&&(console.log("Either infinite or no solutions!"),f===0?console.log("Its finite solutions."):console.log("Too bad, no solutions."));f/=g;if(f<0)return b=Math.atan2(b.y-a.y,b.x-a.x),a=Math.atan2(c.y-a.y,c.x-a.x),b>a&&(a+=Math.PI*2),a=(b+a)/2,new THREE.Vector2(-Math.cos(a),-Math.sin(a));return d.multiplyScalar(f).addSelf(h).subSelf(a).clone()}function e(a){for(v=a.length;--v>=0;){L=v;I=v-1;I<0&&(I=a.length-1);for(var b=
-0,c=m+j*2,b=0;b<c;b++){var d=J*b,e=J*(b+1),g=R+L+d,f=R+L+e,k=g,d=R+I+d,e=R+I+e,n=f;k+=D;d+=D;e+=D;n+=D;A.faces.push(new THREE.Face4(k,d,e,n,null,null,w));w&&(k=b/c,d=(b+1)/c,e=h+i*2,g=(A.vertices[g].position.z+i)/e,f=(A.vertices[f].position.z+i)/e,A.faceVertexUvs[0].push([new THREE.UV(g,k),new THREE.UV(f,k),new THREE.UV(f,d),new THREE.UV(g,d)]))}}}function g(a,b,c){A.vertices.push(new THREE.Vertex(new THREE.Vector3(a,b,c)))}function f(a,b,c){a+=D;b+=D;c+=D;A.faces.push(new THREE.Face3(a,b,c,null,
-null,t));if(t){var d=z.maxY,e=z.maxX,g=A.vertices[b].position.x,b=A.vertices[b].position.y,f=A.vertices[c].position.x,c=A.vertices[c].position.y;A.faceVertexUvs[0].push([new THREE.UV(A.vertices[a].position.x/e,A.vertices[a].position.y/d),new THREE.UV(g/e,b/d),new THREE.UV(f/e,c/d)])}}var h=b.amount!==void 0?b.amount:100,i=b.bevelThickness!==void 0?b.bevelThickness:6,k=b.bevelSize!==void 0?b.bevelSize:i-2,j=b.bevelSegments!==void 0?b.bevelSegments:3,q=b.bevelEnabled!==void 0?b.bevelEnabled:!0,p=b.curveSegments!==
-void 0?b.curveSegments:12,m=b.steps!==void 0?b.steps:1,l=b.bendPath,n=b.extrudePath,r,o=!1,s=b.useSpacedPoints!==void 0?b.useSpacedPoints:!1,t=b.material,w=b.extrudeMaterial,z=this.shapebb;if(n)r=n.getPoints(p),m=r.length,o=!0,q=!1;q||(k=i=j=0);var u,y,x,A=this,D=this.vertices.length;l&&a.addWrapPath(l);p=s?a.extractAllSpacedPoints(p):a.extractAllPoints(p);l=p.shape;p=p.holes;if(n=!THREE.Shape.Utils.isClockWise(l)){l=l.reverse();y=0;for(x=p.length;y<x;y++)u=p[y],THREE.Shape.Utils.isClockWise(u)&&
-(p[y]=u.reverse());n=!1}n=THREE.Shape.Utils.triangulateShape(l,p);s=l;y=0;for(x=p.length;y<x;y++)u=p[y],l=l.concat(u);var v,E,F,C,K,G,J=l.length,O=n.length,M=[];v=0;E=s.length;L=E-1;for(I=v+1;v<E;v++,L++,I++)L===E&&(L=0),I===E&&(I=0),M[v]=d(s[v],s[L],s[I]);var B=[],H,N=M.concat();y=0;for(x=p.length;y<x;y++){u=p[y];H=[];v=0;E=u.length;L=E-1;for(I=v+1;v<E;v++,L++,I++)L===E&&(L=0),I===E&&(I=0),H[v]=d(u[v],u[L],u[I]);B.push(H);N=N.concat(H)}for(F=0;F<j;F++){C=F/j;K=i*(1-C);C=k*Math.sin(C*Math.PI/2);v=
-0;for(E=s.length;v<E;v++)G=c(s[v],M[v],C),g(G.x,G.y,-K);y=0;for(x=p.length;y<x;y++){u=p[y];H=B[y];v=0;for(E=u.length;v<E;v++)G=c(u[v],H[v],C),g(G.x,G.y,-K)}}C=k;for(v=0;v<J;v++)G=q?c(l[v],N[v],C):l[v],o?g(G.x,G.y+r[0].y,r[0].x):g(G.x,G.y,0);for(F=1;F<=m;F++)for(v=0;v<J;v++)G=q?c(l[v],N[v],C):l[v],o?g(G.x,G.y+r[F-1].y,r[F-1].x):g(G.x,G.y,h/m*F);for(F=j-1;F>=0;F--){C=F/j;K=i*(1-C);C=k*Math.sin(C*Math.PI/2);v=0;for(E=s.length;v<E;v++)G=c(s[v],M[v],C),g(G.x,G.y,h+K);y=0;for(x=p.length;y<x;y++){u=p[y];
-H=B[y];v=0;for(E=u.length;v<E;v++)G=c(u[v],H[v],C),o?g(G.x,G.y+r[m-1].y,r[m-1].x+K):g(G.x,G.y,h+K)}}if(q){q=J*0;for(v=0;v<O;v++)k=n[v],f(k[2]+q,k[1]+q,k[0]+q);q=J*(m+j*2);for(v=0;v<O;v++)k=n[v],f(k[0]+q,k[1]+q,k[2]+q)}else{for(v=0;v<O;v++)k=n[v],f(k[2],k[1],k[0]);for(v=0;v<O;v++)k=n[v],f(k[0]+J*m,k[1]+J*m,k[2]+J*m)}var L,I,R=0;e(s);R+=s.length;y=0;for(x=p.length;y<x;y++)u=p[y],e(u),R+=u.length};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;THREE.ExtrudeGeometry.__v2=new THREE.Vector2;
-THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;THREE.ExtrudeGeometry.__v6=new THREE.Vector2;
+0,c=m+j*2,b=0;b<c;b++){var d=J*b,e=J*(b+1),g=R+L+d,f=R+L+e,k=g,d=R+I+d,e=R+I+e,n=f;k+=D;d+=D;e+=D;n+=D;A.faces.push(new THREE.Face4(k,d,e,n,null,null,w));w!==void 0&&(k=b/c,d=(b+1)/c,e=h+i*2,g=(A.vertices[g].position.z+i)/e,f=(A.vertices[f].position.z+i)/e,A.faceVertexUvs[0].push([new THREE.UV(g,k),new THREE.UV(f,k),new THREE.UV(f,d),new THREE.UV(g,d)]))}}}function g(a,b,c){A.vertices.push(new THREE.Vertex(new THREE.Vector3(a,b,c)))}function f(a,b,c){a+=D;b+=D;c+=D;A.faces.push(new THREE.Face3(a,
+b,c,null,null,t));if(t!==void 0){var d=z.minX,e=z.minY,g=z.maxY,f=z.maxX,h=A.vertices[b].position.x-d,b=A.vertices[b].position.y-e,i=A.vertices[c].position.x-d,c=A.vertices[c].position.y-e;A.faceVertexUvs[0].push([new THREE.UV((A.vertices[a].position.x-d)/f,(A.vertices[a].position.y-e)/g),new THREE.UV(h/f,b/g),new THREE.UV(i/f,c/g)])}}var h=b.amount!==void 0?b.amount:100,i=b.bevelThickness!==void 0?b.bevelThickness:6,k=b.bevelSize!==void 0?b.bevelSize:i-2,j=b.bevelSegments!==void 0?b.bevelSegments:
+3,q=b.bevelEnabled!==void 0?b.bevelEnabled:!0,p=b.curveSegments!==void 0?b.curveSegments:12,m=b.steps!==void 0?b.steps:1,l=b.bendPath,n=b.extrudePath,r,o=!1,s=b.useSpacedPoints!==void 0?b.useSpacedPoints:!1,t=b.material,w=b.extrudeMaterial,z=this.shapebb;if(n)r=n.getPoints(p),m=r.length,o=!0,q=!1;q||(k=i=j=0);var u,y,x,A=this,D=this.vertices.length;l&&a.addWrapPath(l);p=s?a.extractAllSpacedPoints(p):a.extractAllPoints(p);l=p.shape;p=p.holes;if(n=!THREE.Shape.Utils.isClockWise(l)){l=l.reverse();y=
+0;for(x=p.length;y<x;y++)u=p[y],THREE.Shape.Utils.isClockWise(u)&&(p[y]=u.reverse());n=!1}n=THREE.Shape.Utils.triangulateShape(l,p);s=l;y=0;for(x=p.length;y<x;y++)u=p[y],l=l.concat(u);var v,E,F,C,K,G,J=l.length,O=n.length,M=[];v=0;E=s.length;L=E-1;for(I=v+1;v<E;v++,L++,I++)L===E&&(L=0),I===E&&(I=0),M[v]=d(s[v],s[L],s[I]);var B=[],H,N=M.concat();y=0;for(x=p.length;y<x;y++){u=p[y];H=[];v=0;E=u.length;L=E-1;for(I=v+1;v<E;v++,L++,I++)L===E&&(L=0),I===E&&(I=0),H[v]=d(u[v],u[L],u[I]);B.push(H);N=N.concat(H)}for(F=
+0;F<j;F++){C=F/j;K=i*(1-C);C=k*Math.sin(C*Math.PI/2);v=0;for(E=s.length;v<E;v++)G=c(s[v],M[v],C),g(G.x,G.y,-K);y=0;for(x=p.length;y<x;y++){u=p[y];H=B[y];v=0;for(E=u.length;v<E;v++)G=c(u[v],H[v],C),g(G.x,G.y,-K)}}C=k;for(v=0;v<J;v++)G=q?c(l[v],N[v],C):l[v],o?g(G.x,G.y+r[0].y,r[0].x):g(G.x,G.y,0);for(F=1;F<=m;F++)for(v=0;v<J;v++)G=q?c(l[v],N[v],C):l[v],o?g(G.x,G.y+r[F-1].y,r[F-1].x):g(G.x,G.y,h/m*F);for(F=j-1;F>=0;F--){C=F/j;K=i*(1-C);C=k*Math.sin(C*Math.PI/2);v=0;for(E=s.length;v<E;v++)G=c(s[v],M[v],
+C),g(G.x,G.y,h+K);y=0;for(x=p.length;y<x;y++){u=p[y];H=B[y];v=0;for(E=u.length;v<E;v++)G=c(u[v],H[v],C),o?g(G.x,G.y+r[m-1].y,r[m-1].x+K):g(G.x,G.y,h+K)}}if(q){q=J*0;for(v=0;v<O;v++)k=n[v],f(k[2]+q,k[1]+q,k[0]+q);q=J*(m+j*2);for(v=0;v<O;v++)k=n[v],f(k[0]+q,k[1]+q,k[2]+q)}else{for(v=0;v<O;v++)k=n[v],f(k[2],k[1],k[0]);for(v=0;v<O;v++)k=n[v],f(k[0]+J*m,k[1]+J*m,k[2]+J*m)}var L,I,R=0;e(s);R+=s.length;y=0;for(x=p.length;y<x;y++)u=p[y],e(u),R+=u.length};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;
+THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;THREE.ExtrudeGeometry.__v6=new THREE.Vector2;
 THREE.IcosahedronGeometry=function(a){function b(a,b,c){var d=Math.sqrt(a*a+b*b+c*c);return e.vertices.push(new THREE.Vertex(new THREE.Vector3(a/d,b/d,c/d)))-1}function c(a,b,c,d){var g=e.vertices[a].position,f=e.vertices[b].position,h=e.vertices[c].position,a=new THREE.Face3(a,b,c);a.vertexNormals.push(g.clone().normalize(),f.clone().normalize(),h.clone().normalize());d.faces.push(a);d.faceVertexUvs[0].push([new THREE.UV(1-(Math.atan2(g.z,g.x)+Math.PI)%Math.PI/Math.PI*0.5,0.5-g.y/2),new THREE.UV(1-
 (Math.atan2(f.z,f.x)+Math.PI)%Math.PI/Math.PI*0.5,0.5-f.y/2),new THREE.UV(1-(Math.atan2(h.z,h.x)+Math.PI)%Math.PI/Math.PI*0.5,0.5-h.y/2)])}function d(a,c){var d=e.vertices[a].position,g=e.vertices[c].position;return b((d.x+g.x)/2,(d.y+g.y)/2,(d.z+g.z)/2)}var e=this,g=new THREE.Geometry;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;b(-1,a,0);b(1,a,0);b(-1,-a,0);b(1,-a,0);b(0,-1,a);b(0,1,a);b(0,-1,-a);b(0,1,-a);b(a,0,-1);b(a,0,1);b(-a,0,-1);b(-a,0,1);c(0,11,5,g);c(0,5,1,g);c(0,
 1,7,g);c(0,7,10,g);c(0,10,11,g);c(1,5,9,g);c(5,11,4,g);c(11,10,2,g);c(10,7,6,g);c(7,1,8,g);c(3,9,4,g);c(3,4,2,g);c(3,2,6,g);c(3,6,8,g);c(3,8,9,g);c(4,9,5,g);c(2,4,11,g);c(6,2,10,g);c(8,6,7,g);c(9,8,1,g);for(var f=0;f<this.subdivisions;f++){var a=new THREE.Geometry,h;for(h in g.faces){var i=d(g.faces[h].a,g.faces[h].b),k=d(g.faces[h].b,g.faces[h].c),j=d(g.faces[h].c,g.faces[h].a);c(g.faces[h].a,i,j,a);c(g.faces[h].b,k,i,a);c(g.faces[h].c,j,k,a);c(i,k,j,a)}g.faces=a.faces;g.faceVertexUvs[0]=a.faceVertexUvs[0]}e.faces=

+ 31 - 17
examples/webgl_extrude_material.html → examples/webgl_geometry_extrude.html

@@ -49,7 +49,7 @@
 
         var texture  = new THREE.Texture( image, new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping, THREE.NearestFilter, THREE.LinearMipMapLinearFilter );
 
-        return new THREE.MeshBasicMaterial( { map: texture } );
+        return new THREE.MeshPhongMaterial( { map: texture, color: 0x00aaff, shininess: 100 } );
 
       }
 
@@ -58,7 +58,7 @@
         container = document.createElement( 'div' );
         document.body.appendChild( container );
 
-        var grass = loadTexture( 'textures/minecraft/grass.png' );
+        var texturedMaterial = loadTexture( 'textures/water.jpg' );
 
         var info = document.createElement( 'div' );
         info.style.position = 'absolute';
@@ -68,46 +68,60 @@
         info.innerHTML = 'Procedurally generated 3D shapes with different materials on extrusions<br/>Drag to spin';
         container.appendChild( info );
 
-        camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
-        camera.position.y = 150;
-        camera.position.z = 500;
+        camera = new THREE.PerspectiveCamera( 30, window.innerWidth / window.innerHeight, 1, 1000 );
+        camera.position.set( 0, 0, 300 );
 
         scene = new THREE.Scene();
         scene.add( camera );
 
+		var light = new THREE.PointLight( 0xffffff );
+		light.position.set( 0, 0, 100 );
+		scene.add( light );
+
         parent = new THREE.Object3D();
-        parent.position.y = 150;
+        parent.position.y = 0;
         scene.add( parent );
 
-        var extrudeSettings = { amount: 20, bevelEnabled: true, bevelSegments: 2, steps: 2, material: 0, extrudeMaterial: 1 };
+        var extrudeSettings = { amount: 10, bevelEnabled: true, bevelSegments: 3, steps: 4, bevelThickness: 8, material: 0, extrudeMaterial: 1 };
 
-        var colorMaterials = [ new THREE.MeshBasicMaterial({ color: 0x006ed5 }), new THREE.MeshBasicMaterial({ color: 0x6ed500 }) ];
+        var colorMaterials = [ new THREE.MeshPhongMaterial( { color: 0xff5500, shininess: 100 } ), new THREE.MeshPhongMaterial( { color: 0xff0000, shininess: 100 } ) ];
+        var imageAndColorMaterials = [ texturedMaterial, new THREE.MeshPhongMaterial( { color: 0x00aaff, shininess: 100 } ) ];
 
-        var imageAndColorMaterials = [ grass, new THREE.MeshBasicMaterial({ color: 0x6ed500 }) ];
-        
         var pillShape1 = new THREE.Shape();
-        pillShape1.moveTo(  30, 10 );
-        pillShape1.lineTo(  100, 10 );
-        pillShape1.quadraticCurveTo( 120, 20, 100, 30 );
-        pillShape1.lineTo( 30, 30 );
-        pillShape1.quadraticCurveTo( 10, 20, 30, 10 );
+        pillShape1.moveTo(  30, 80 );
+        pillShape1.lineTo(  100, 80 );
+        pillShape1.quadraticCurveTo( 130, 90, 100, 100 );
+        pillShape1.lineTo( 30, 100 );
+        pillShape1.quadraticCurveTo( 0, 90, 30, 80 );
 
         var pillGeometry1 = pillShape1.extrude( extrudeSettings );
         pillGeometry1.materials = colorMaterials;
+		pillGeometry1.computeVertexNormals();
+
+		THREE.GeometryUtils.center( pillGeometry1 );
+
         var pillMesh1 = new THREE.Mesh( pillGeometry1, new THREE.MeshFaceMaterial() );
+		pillMesh1.position.y = -25;
+		pillMesh1.scale.x = 0.5;
 
         parent.add ( pillMesh1 );
 
         var pillShape2 = new THREE.Shape();
         pillShape2.moveTo(  30, 80 );
         pillShape2.lineTo(  100, 80 );
-        pillShape2.quadraticCurveTo( 120, 90, 100, 100 );
+        pillShape2.quadraticCurveTo( 130, 90, 100, 100 );
         pillShape2.lineTo( 30, 100 );
-        pillShape2.quadraticCurveTo( 10, 90, 30, 80 );
+        pillShape2.quadraticCurveTo( 0, 90, 30, 80 );
 
         var pillGeometry2 = pillShape2.extrude( extrudeSettings );
         pillGeometry2.materials = imageAndColorMaterials;
+		pillGeometry2.computeVertexNormals();
+
+		THREE.GeometryUtils.center( pillGeometry2 );
+
         var pillMesh2 = new THREE.Mesh( pillGeometry2, new THREE.MeshFaceMaterial() );
+		pillMesh2.position.y = 25;
+		pillMesh2.scale.x = 0.5;
 
         parent.add ( pillMesh2 );