提交 3db68227 编写于 作者: Z zz85

Fixed the fish, added a smiley to shapes demo

上级 bbdea5f4
......@@ -463,8 +463,8 @@ THREE.Path.prototype.getPoint=function(b){for(var c=b*this.getLength(),e=this.su
THREE.Path.prototype.createSpacedPointsGeometry=function(b){return this.createGeometry(this.getSpacedPoints(b,!0))};THREE.Path.prototype.createGeometry=function(b){for(var c=new THREE.Geometry,e=0;e<b.length;e++)c.vertices.push(new THREE.Vertex(new THREE.Vector3(b[e].x,b[e].y,0)));return c};
THREE.Path.prototype.transform=function(b){b=new THREE.Path;b.moveTo(0,0);b.quadraticCurveTo(100,20,140,80);console.log(b.cacheArcLengths());var c=this.getBoundingBox(),e=this.getPoints(),f,h,g,j,m,p;f=0;for(h=e.length;f<h;f++)g=e[f],j=g.x,m=g.y,p=j/c.maxX,j=b.getPoint(p),m=b.getNormalVector(p).multiplyScalar(m),g.x=j.x+m.x,g.y=j.y+m.y;return e};
THREE.Path.prototype.nltransform=function(b,c,e,f,h,g){var j=this.getPoints(),m,p,t,n,o;m=0;for(p=j.length;m<p;m++)t=j[m],n=t.x,o=t.y,t.x=b*n+c*o+e,t.y=f*o+h*n+g;return j};
THREE.Path.prototype.debug=function(b){var c=this.getMinAndMax();b||(b=document.createElement("canvas"),b.setAttribute("width",c.maxX+100),b.setAttribute("height",c.maxY+100),document.body.appendChild(b));c=b.getContext("2d");c.fillStyle="white";c.fillRect(0,0,b.width,b.height);c.strokeStyle="black";c.beginPath();var e,f,h,b=0;for(e=this.actions.length;b<e;b++)f=this.actions[b],h=f.args,f=f.action,f!=THREE.PathActions.CSPLINE_THRU&&c[f].apply(c,h);c.stroke();c.closePath();c.strokeStyle="red";f=this.getPoints();
b=0;for(e=f.length;b<e;b++)h=f[b],c.beginPath(),c.arc(h.x,h.y,1.5,0,Math.PI*2,!1),c.stroke(),c.closePath()};
THREE.Path.prototype.debug=function(b){var c=this.getBoundingBox();b||(b=document.createElement("canvas"),b.setAttribute("width",c.maxX+100),b.setAttribute("height",c.maxY+100),document.body.appendChild(b));c=b.getContext("2d");c.fillStyle="white";c.fillRect(0,0,b.width,b.height);c.strokeStyle="black";c.beginPath();var e,f,h,b=0;for(e=this.actions.length;b<e;b++)f=this.actions[b],h=f.args,f=f.action,f!=THREE.PathActions.CSPLINE_THRU&&c[f].apply(c,h);c.stroke();c.closePath();c.strokeStyle="red";f=
this.getPoints();b=0;for(e=f.length;b<e;b++)h=f[b],c.beginPath(),c.arc(h.x,h.y,1.5,0,Math.PI*2,!1),c.stroke(),c.closePath()};
THREE.Path.prototype.toShapes=function(){var b,c,e,f,h=[],g=new THREE.Path;b=0;for(c=this.actions.length;b<c;b++)e=this.actions[b],f=e.args,e=e.action,e==THREE.PathActions.MOVE_TO&&g.actions.length!=0&&(h.push(g),g=new THREE.Path),g[e].apply(g,f);g.actions.length!=0&&h.push(g);if(h.length==0)return[];var j,g=[];if(THREE.Shape.Utils.isClockWise(h[0].getPoints())){b=0;for(c=h.length;b<c;b++)f=h[b],THREE.Shape.Utils.isClockWise(f.getPoints())?(j&&g.push(j),j=new THREE.Shape,j.actions=f.actions,j.curves=
f.curves):j.holes.push(f);g.push(j)}else{j=new THREE.Shape;b=0;for(c=h.length;b<c;b++)f=h[b],THREE.Shape.Utils.isClockWise(f.getPoints())?(j.actions=f.actions,j.curves=f.curves,g.push(j),j=new THREE.Shape):j.holes.push(f)}return g};THREE.Shape=function(){THREE.Path.apply(this,arguments);this.holes=[]};THREE.Shape.prototype=new THREE.Path;THREE.Shape.prototype.constructor=THREE.Path;THREE.Shape.prototype.extrude=function(b){return new THREE.ExtrudeGeometry(this,b)};
THREE.Shape.prototype.getPointsHoles=function(){var b,c=this.holes.length,e=[];for(b=0;b<c;b++)e[b]=this.holes[b].getPoints();return e};THREE.Shape.prototype.getSpacedPointsHoles=function(){var b,c=this.holes.length,e=[];for(b=0;b<c;b++)e[b]=this.holes[b].getSpacedPoints();return e};THREE.Shape.prototype.extractAllPoints=function(){return{shape:this.getPoints(),holes:this.getPointsHoles()}};THREE.Shape.prototype.extractAllSpacedPoints=function(){return{shape:this.getSpacedPoints(),holes:this.getSpacedPointsHoles()}};
......@@ -484,11 +484,11 @@ f));e instanceof THREE.Face4&&c.push(new THREE.UV(0.5+Math.atan2(o.position.x,o.
THREE.ExtrudeGeometry.prototype=new THREE.Geometry;THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;
THREE.ExtrudeGeometry.prototype.addShape=function(b,c){function e(b,c,e){c||console.log("die");return c.clone().multiplyScalar(e).addSelf(b)}function f(b,c,e){var f,g,j,h,k;f=new THREE.Vector2(b.x-c.x,b.y-c.y);g=new THREE.Vector2(b.x-e.x,b.y-e.y);f=f.normalize();g=g.normalize();j=new THREE.Vector2(-f.y,f.x);h=new THREE.Vector2(g.y,-g.x);g=b.clone().addSelf(j);k=b.clone().addSelf(h);if(g.equals(k))return h;g=c.clone().addSelf(j);k=e.clone().addSelf(h);j=f.dot(h);h=k.clone().subSelf(g).dot(h);j==0&&
(console.log("Either infinite or no solutions!"),h==0?console.log("Its finite solutions."):console.log("Too bad, no solutions."));j=h/j;if(j<0)return c=Math.atan2(c.y-b.y,c.x-b.x),b=Math.atan2(e.y-b.y,e.x-b.x),c>b&&(b+=Math.PI*2),anglec=(c+b)/2,new THREE.Vector2(-Math.cos(anglec),-Math.sin(anglec));return f.clone().multiplyScalar(j).addSelf(g).subSelf(b)}function h(b){for(G=b.length;--G>=0;){Z=G;aa=G-1;aa<0&&(aa=b.length-1);for(var c=0,c=0;c<v+n*2;c++){var e=Q*c,f=Q*(c+1),g=ha+Z+e,e=ha+aa+e,j=ha+
aa+f,f=ha+Z+f;g+=K;e+=K;j+=K;f+=K;B.faces.push(new THREE.Face4(g,e,j,f))}}}function g(b,c,e){B.vertices.push(new THREE.Vertex(new THREE.Vector3(b,c,e)))}function j(b,c,e){b+=K;c+=K;e+=K;B.faces.push(new THREE.Face3(b,c,e))}var m=c.amount!==void 0?c.amount:100,p=c.bevelThickness!==void 0?c.bevelThickness:6,t=c.bevelSize!==void 0?c.bevelSize:p-2,n=c.bevelSegments!==void 0?c.bevelSegments:3,o=c.bevelEnabled!==void 0?c.bevelEnabled:!0;o||(n=0);var v=c.steps!==void 0?c.steps:1,u=c.path!==void 0?c.path:
null,y,w=!1;if(u)y=u.getPoints(),v=y.length,w=!0;var C,x,I,B=this,K=this.vertices.length,u=b.extractAllPoints(),F=u.shape,u=u.holes,A=!THREE.Shape.Utils.isClockWise(F);if(A){F=F.reverse();x=0;for(I=u.length;x<I;x++)C=u[x],THREE.Shape.Utils.isClockWise(C)&&(u[x]=C.reverse());A=!1}var A=THREE.Shape.Utils.triangulateShape(F,u),X=F;x=0;for(I=u.length;x<I;x++)C=u[x],F=F.concat(C);var G,H,L,O,P,N,Q=F.length,S=A.length,$=[];G=0;H=X.length;Z=H-1;for(aa=G+1;G<H;G++,Z++,aa++)Z==H&&(Z=0),aa==H&&(aa=0),$[G]=
f(X[G],X[Z],X[aa]);var k=[],J,da=$.concat();x=0;for(I=u.length;x<I;x++){C=u[x];J=[];G=0;H=C.length;Z=H-1;for(aa=G+1;G<H;G++,Z++,aa++)Z==H&&(Z=0),aa==H&&(aa=0),J[G]=f(C[G],C[Z],C[aa]);k.push(J);da=da.concat(J)}for(L=0;L<n;L++){O=L/n;P=p*(1-O);O=t*Math.sin(O*Math.PI/2);G=0;for(H=X.length;G<H;G++)N=e(X[G],$[G],O),g(N.x,N.y,-P);x=0;for(I=u.length;x<I;x++){C=u[x];J=k[x];G=0;for(H=C.length;G<H;G++)N=e(C[G],J[G],O),g(N.x,N.y,-P)}}O=t;for(G=0;G<Q;G++)N=o?e(F[G],da[G],O):F[G],w?g(N.x,N.y+y[0].y,y[0].x):g(N.x,
N.y,0);for(L=1;L<=v;L++)for(G=0;G<Q;G++)N=o?e(F[G],da[G],O):F[G],w?g(N.x,N.y+y[L-1].y,y[L-1].x):g(N.x,N.y,m/v*L);for(L=n-1;L>=0;L--){O=L/n;P=p*(1-O);O=t*Math.sin(O*Math.PI/2);G=0;for(H=X.length;G<H;G++)N=e(X[G],$[G],O),g(N.x,N.y,m+P);x=0;for(I=u.length;x<I;x++){C=u[x];J=k[x];G=0;for(H=C.length;G<H;G++)N=e(C[G],J[G],O),w?g(N.x,N.y+y[v-1].y,y[v-1].x+P):g(N.x,N.y,m+P)}}if(o){p=Q*0;for(G=0;G<S;G++)m=A[G],j(m[2]+p,m[1]+p,m[0]+p);p=Q*(v+n*2);for(G=0;G<S;G++)m=A[G],j(m[0]+p,m[1]+p,m[2]+p)}else{for(G=0;G<
S;G++)m=A[G],j(m[2],m[1],m[0]);for(G=0;G<S;G++)m=A[G],j(m[0]+Q*v,m[1]+Q*v,m[2]+Q*v)}var Z,aa,ha=0;h(X);ha+=X.length;x=0;for(I=u.length;x<I;x++)C=u[x],h(C),ha+=C.length;this.computeCentroids();this.computeFaceNormals()};
aa+f,f=ha+Z+f;g+=K;e+=K;j+=K;f+=K;B.faces.push(new THREE.Face4(g,e,j,f))}}}function g(b,c,e){B.vertices.push(new THREE.Vertex(new THREE.Vector3(b,c,e)))}function j(b,c,e){b+=K;c+=K;e+=K;B.faces.push(new THREE.Face3(b,c,e))}var m=c.amount!==void 0?c.amount:100,p=c.bevelThickness!==void 0?c.bevelThickness:6,t=c.bevelSize!==void 0?c.bevelSize:p-2,n=c.bevelSegments!==void 0?c.bevelSegments:3,o=c.bevelEnabled!==void 0?c.bevelEnabled:!0,v=c.steps!==void 0?c.steps:1,u=c.path!==void 0?c.path:null,y,w=!1;
if(u)y=u.getPoints(),v=y.length,w=!0,o=!1;o||(t=p=n=0);var C,x,I,B=this,K=this.vertices.length,u=b.extractAllPoints(),F=u.shape,u=u.holes,A=!THREE.Shape.Utils.isClockWise(F);if(A){F=F.reverse();x=0;for(I=u.length;x<I;x++)C=u[x],THREE.Shape.Utils.isClockWise(C)&&(u[x]=C.reverse());A=!1}var A=THREE.Shape.Utils.triangulateShape(F,u),X=F;x=0;for(I=u.length;x<I;x++)C=u[x],F=F.concat(C);var G,H,L,O,P,N,Q=F.length,S=A.length,$=[];G=0;H=X.length;Z=H-1;for(aa=G+1;G<H;G++,Z++,aa++)Z==H&&(Z=0),aa==H&&(aa=0),
$[G]=f(X[G],X[Z],X[aa]);var k=[],J,da=$.concat();x=0;for(I=u.length;x<I;x++){C=u[x];J=[];G=0;H=C.length;Z=H-1;for(aa=G+1;G<H;G++,Z++,aa++)Z==H&&(Z=0),aa==H&&(aa=0),J[G]=f(C[G],C[Z],C[aa]);k.push(J);da=da.concat(J)}for(L=0;L<n;L++){O=L/n;P=p*(1-O);O=t*Math.sin(O*Math.PI/2);G=0;for(H=X.length;G<H;G++)N=e(X[G],$[G],O),g(N.x,N.y,-P);x=0;for(I=u.length;x<I;x++){C=u[x];J=k[x];G=0;for(H=C.length;G<H;G++)N=e(C[G],J[G],O),g(N.x,N.y,-P)}}O=t;for(G=0;G<Q;G++)N=o?e(F[G],da[G],O):F[G],w?g(N.x,N.y+y[0].y,y[0].x):
g(N.x,N.y,0);for(L=1;L<=v;L++)for(G=0;G<Q;G++)N=o?e(F[G],da[G],O):F[G],w?g(N.x,N.y+y[L-1].y,y[L-1].x):g(N.x,N.y,m/v*L);for(L=n-1;L>=0;L--){O=L/n;P=p*(1-O);O=t*Math.sin(O*Math.PI/2);G=0;for(H=X.length;G<H;G++)N=e(X[G],$[G],O),g(N.x,N.y,m+P);x=0;for(I=u.length;x<I;x++){C=u[x];J=k[x];G=0;for(H=C.length;G<H;G++)N=e(C[G],J[G],O),w?g(N.x,N.y+y[v-1].y,y[v-1].x+P):g(N.x,N.y,m+P)}}if(o){p=Q*0;for(G=0;G<S;G++)m=A[G],j(m[2]+p,m[1]+p,m[0]+p);p=Q*(v+n*2);for(G=0;G<S;G++)m=A[G],j(m[0]+p,m[1]+p,m[2]+p)}else{for(G=
0;G<S;G++)m=A[G],j(m[2],m[1],m[0]);for(G=0;G<S;G++)m=A[G],j(m[0]+Q*v,m[1]+Q*v,m[2]+Q*v)}var Z,aa,ha=0;h(X);ha+=X.length;x=0;for(I=u.length;x<I;x++)C=u[x],h(C),ha+=C.length;this.computeCentroids();this.computeFaceNormals()};
THREE.IcosahedronGeometry=function(b){function c(b,c,e){var f=Math.sqrt(b*b+c*c+e*e);return h.vertices.push(new THREE.Vertex(new THREE.Vector3(b/f,c/f,e/f)))-1}function e(b,c,e,f){f.faces.push(new THREE.Face3(b,c,e))}function f(b,e){var f=h.vertices[b].position,g=h.vertices[e].position;return c((f.x+g.x)/2,(f.y+g.y)/2,(f.z+g.z)/2)}var h=this,g=new THREE.Geometry,j;this.subdivisions=b||0;THREE.Geometry.call(this);b=(1+Math.sqrt(5))/2;c(-1,b,0);c(1,b,0);c(-1,-b,0);c(1,-b,0);c(0,-1,b);c(0,1,b);c(0,-1,
-b);c(0,1,-b);c(b,0,-1);c(b,0,1);c(-b,0,-1);c(-b,0,1);e(0,11,5,g);e(0,5,1,g);e(0,1,7,g);e(0,7,10,g);e(0,10,11,g);e(1,5,9,g);e(5,11,4,g);e(11,10,2,g);e(10,7,6,g);e(7,1,8,g);e(3,9,4,g);e(3,4,2,g);e(3,2,6,g);e(3,6,8,g);e(3,8,9,g);e(4,9,5,g);e(2,4,11,g);e(6,2,10,g);e(8,6,7,g);e(9,8,1,g);for(b=0;b<this.subdivisions;b++){j=new THREE.Geometry;for(var m in g.faces){var p=f(g.faces[m].a,g.faces[m].b),t=f(g.faces[m].b,g.faces[m].c),n=f(g.faces[m].c,g.faces[m].a);e(g.faces[m].a,p,n,j);e(g.faces[m].b,t,p,j);
e(g.faces[m].c,n,t,j);e(p,t,n,j)}g.faces=j.faces}h.faces=g.faces;delete g;delete j;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.IcosahedronGeometry.prototype=new THREE.Geometry;THREE.IcosahedronGeometry.prototype.constructor=THREE.IcosahedronGeometry;
......
......@@ -106,8 +106,8 @@ THREE.Path.prototype.getPoint=function(a){for(var b=a*this.getLength(),c=this.su
THREE.Path.prototype.createSpacedPointsGeometry=function(a){return this.createGeometry(this.getSpacedPoints(a,!0))};THREE.Path.prototype.createGeometry=function(a){for(var b=new THREE.Geometry,c=0;c<a.length;c++)b.vertices.push(new THREE.Vertex(new THREE.Vector3(a[c].x,a[c].y,0)));return b};
THREE.Path.prototype.transform=function(a){a=new THREE.Path;a.moveTo(0,0);a.quadraticCurveTo(100,20,140,80);console.log(a.cacheArcLengths());var b=this.getBoundingBox(),c=this.getPoints(),f,g,h,e,j,k;f=0;for(g=c.length;f<g;f++)h=c[f],e=h.x,j=h.y,k=e/b.maxX,e=a.getPoint(k),j=a.getNormalVector(k).multiplyScalar(j),h.x=e.x+j.x,h.y=e.y+j.y;return c};
THREE.Path.prototype.nltransform=function(a,b,c,f,g,h){var e=this.getPoints(),j,k,l,m,n;j=0;for(k=e.length;j<k;j++)l=e[j],m=l.x,n=l.y,l.x=a*m+b*n+c,l.y=f*n+g*m+h;return e};
THREE.Path.prototype.debug=function(a){var b=this.getMinAndMax();a||(a=document.createElement("canvas"),a.setAttribute("width",b.maxX+100),a.setAttribute("height",b.maxY+100),document.body.appendChild(a));b=a.getContext("2d");b.fillStyle="white";b.fillRect(0,0,a.width,a.height);b.strokeStyle="black";b.beginPath();var c,f,g,a=0;for(c=this.actions.length;a<c;a++)f=this.actions[a],g=f.args,f=f.action,f!=THREE.PathActions.CSPLINE_THRU&&b[f].apply(b,g);b.stroke();b.closePath();b.strokeStyle="red";f=this.getPoints();
a=0;for(c=f.length;a<c;a++)g=f[a],b.beginPath(),b.arc(g.x,g.y,1.5,0,Math.PI*2,!1),b.stroke(),b.closePath()};
THREE.Path.prototype.debug=function(a){var b=this.getBoundingBox();a||(a=document.createElement("canvas"),a.setAttribute("width",b.maxX+100),a.setAttribute("height",b.maxY+100),document.body.appendChild(a));b=a.getContext("2d");b.fillStyle="white";b.fillRect(0,0,a.width,a.height);b.strokeStyle="black";b.beginPath();var c,f,g,a=0;for(c=this.actions.length;a<c;a++)f=this.actions[a],g=f.args,f=f.action,f!=THREE.PathActions.CSPLINE_THRU&&b[f].apply(b,g);b.stroke();b.closePath();b.strokeStyle="red";f=
this.getPoints();a=0;for(c=f.length;a<c;a++)g=f[a],b.beginPath(),b.arc(g.x,g.y,1.5,0,Math.PI*2,!1),b.stroke(),b.closePath()};
THREE.Path.prototype.toShapes=function(){var a,b,c,f,g=[],h=new THREE.Path;a=0;for(b=this.actions.length;a<b;a++)c=this.actions[a],f=c.args,c=c.action,c==THREE.PathActions.MOVE_TO&&h.actions.length!=0&&(g.push(h),h=new THREE.Path),h[c].apply(h,f);h.actions.length!=0&&g.push(h);if(g.length==0)return[];var e,h=[];if(THREE.Shape.Utils.isClockWise(g[0].getPoints())){a=0;for(b=g.length;a<b;a++)f=g[a],THREE.Shape.Utils.isClockWise(f.getPoints())?(e&&h.push(e),e=new THREE.Shape,e.actions=f.actions,e.curves=
f.curves):e.holes.push(f);h.push(e)}else{e=new THREE.Shape;a=0;for(b=g.length;a<b;a++)f=g[a],THREE.Shape.Utils.isClockWise(f.getPoints())?(e.actions=f.actions,e.curves=f.curves,h.push(e),e=new THREE.Shape):e.holes.push(f)}return h};THREE.Shape=function(){THREE.Path.apply(this,arguments);this.holes=[]};THREE.Shape.prototype=new THREE.Path;THREE.Shape.prototype.constructor=THREE.Path;THREE.Shape.prototype.extrude=function(a){return new THREE.ExtrudeGeometry(this,a)};
THREE.Shape.prototype.getPointsHoles=function(){var a,b=this.holes.length,c=[];for(a=0;a<b;a++)c[a]=this.holes[a].getPoints();return c};THREE.Shape.prototype.getSpacedPointsHoles=function(){var a,b=this.holes.length,c=[];for(a=0;a<b;a++)c[a]=this.holes[a].getSpacedPoints();return c};THREE.Shape.prototype.extractAllPoints=function(){return{shape:this.getPoints(),holes:this.getPointsHoles()}};THREE.Shape.prototype.extractAllSpacedPoints=function(){return{shape:this.getSpacedPoints(),holes:this.getSpacedPointsHoles()}};
......@@ -127,9 +127,9 @@ f));c instanceof THREE.Face4&&b.push(new THREE.UV(0.5+Math.atan2(n.position.x,n.
THREE.ExtrudeGeometry.prototype=new THREE.Geometry;THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;
THREE.ExtrudeGeometry.prototype.addShape=function(a,b){function c(a,c,b){c||console.log("die");return c.clone().multiplyScalar(b).addSelf(a)}function f(a,c,b){var e,f,h,g,j;e=new THREE.Vector2(a.x-c.x,a.y-c.y);f=new THREE.Vector2(a.x-b.x,a.y-b.y);e=e.normalize();f=f.normalize();h=new THREE.Vector2(-e.y,e.x);g=new THREE.Vector2(f.y,-f.x);f=a.clone().addSelf(h);j=a.clone().addSelf(g);if(f.equals(j))return g;f=c.clone().addSelf(h);j=b.clone().addSelf(g);h=e.dot(g);g=j.clone().subSelf(f).dot(g);h==0&&
(console.log("Either infinite or no solutions!"),g==0?console.log("Its finite solutions."):console.log("Too bad, no solutions."));h=g/h;if(h<0)return c=Math.atan2(c.y-a.y,c.x-a.x),a=Math.atan2(b.y-a.y,b.x-a.x),c>a&&(a+=Math.PI*2),anglec=(c+a)/2,new THREE.Vector2(-Math.cos(anglec),-Math.sin(anglec));return e.clone().multiplyScalar(h).addSelf(f).subSelf(a)}function g(a){for(z=a.length;--z>=0;){K=z;N=z-1;N<0&&(N=a.length-1);for(var c=0,c=0;c<p+m*2;c++){var b=L*c,e=L*(c+1),f=R+K+b,b=R+N+b,h=R+N+e,e=R+
K+e;f+=A;b+=A;h+=A;e+=A;t.faces.push(new THREE.Face4(f,b,h,e))}}}function h(a,c,b){t.vertices.push(new THREE.Vertex(new THREE.Vector3(a,c,b)))}function e(a,c,b){a+=A;c+=A;b+=A;t.faces.push(new THREE.Face3(a,c,b))}var j=b.amount!==void 0?b.amount:100,k=b.bevelThickness!==void 0?b.bevelThickness:6,l=b.bevelSize!==void 0?b.bevelSize:k-2,m=b.bevelSegments!==void 0?b.bevelSegments:3,n=b.bevelEnabled!==void 0?b.bevelEnabled:!0;n||(m=0);var p=b.steps!==void 0?b.steps:1,o=b.path!==void 0?b.path:null,x,v=
!1;if(o)x=o.getPoints(),p=x.length,v=!0;var w,u,y,t=this,A=this.vertices.length,o=a.extractAllPoints(),B=o.shape,o=o.holes,G=!THREE.Shape.Utils.isClockWise(B);if(G){B=B.reverse();u=0;for(y=o.length;u<y;u++)w=o[u],THREE.Shape.Utils.isClockWise(w)&&(o[u]=w.reverse());G=!1}var G=THREE.Shape.Utils.triangulateShape(B,o),H=B;u=0;for(y=o.length;u<y;u++)w=o[u],B=B.concat(w);var z,D,J,I,E,F,L=B.length,M=G.length,O=[];z=0;D=H.length;K=D-1;for(N=z+1;z<D;z++,K++,N++)K==D&&(K=0),N==D&&(N=0),O[z]=f(H[z],H[K],H[N]);
var Q=[],C,P=O.concat();u=0;for(y=o.length;u<y;u++){w=o[u];C=[];z=0;D=w.length;K=D-1;for(N=z+1;z<D;z++,K++,N++)K==D&&(K=0),N==D&&(N=0),C[z]=f(w[z],w[K],w[N]);Q.push(C);P=P.concat(C)}for(J=0;J<m;J++){I=J/m;E=k*(1-I);I=l*Math.sin(I*Math.PI/2);z=0;for(D=H.length;z<D;z++)F=c(H[z],O[z],I),h(F.x,F.y,-E);u=0;for(y=o.length;u<y;u++){w=o[u];C=Q[u];z=0;for(D=w.length;z<D;z++)F=c(w[z],C[z],I),h(F.x,F.y,-E)}}I=l;for(z=0;z<L;z++)F=n?c(B[z],P[z],I):B[z],v?h(F.x,F.y+x[0].y,x[0].x):h(F.x,F.y,0);for(J=1;J<=p;J++)for(z=
K+e;f+=A;b+=A;h+=A;e+=A;t.faces.push(new THREE.Face4(f,b,h,e))}}}function h(a,c,b){t.vertices.push(new THREE.Vertex(new THREE.Vector3(a,c,b)))}function e(a,c,b){a+=A;c+=A;b+=A;t.faces.push(new THREE.Face3(a,c,b))}var j=b.amount!==void 0?b.amount:100,k=b.bevelThickness!==void 0?b.bevelThickness:6,l=b.bevelSize!==void 0?b.bevelSize:k-2,m=b.bevelSegments!==void 0?b.bevelSegments:3,n=b.bevelEnabled!==void 0?b.bevelEnabled:!0,p=b.steps!==void 0?b.steps:1,o=b.path!==void 0?b.path:null,x,v=!1;if(o)x=o.getPoints(),
p=x.length,v=!0,n=!1;n||(l=k=m=0);var w,u,y,t=this,A=this.vertices.length,o=a.extractAllPoints(),B=o.shape,o=o.holes,G=!THREE.Shape.Utils.isClockWise(B);if(G){B=B.reverse();u=0;for(y=o.length;u<y;u++)w=o[u],THREE.Shape.Utils.isClockWise(w)&&(o[u]=w.reverse());G=!1}var G=THREE.Shape.Utils.triangulateShape(B,o),H=B;u=0;for(y=o.length;u<y;u++)w=o[u],B=B.concat(w);var z,D,J,I,E,F,L=B.length,M=G.length,O=[];z=0;D=H.length;K=D-1;for(N=z+1;z<D;z++,K++,N++)K==D&&(K=0),N==D&&(N=0),O[z]=f(H[z],H[K],H[N]);var Q=
[],C,P=O.concat();u=0;for(y=o.length;u<y;u++){w=o[u];C=[];z=0;D=w.length;K=D-1;for(N=z+1;z<D;z++,K++,N++)K==D&&(K=0),N==D&&(N=0),C[z]=f(w[z],w[K],w[N]);Q.push(C);P=P.concat(C)}for(J=0;J<m;J++){I=J/m;E=k*(1-I);I=l*Math.sin(I*Math.PI/2);z=0;for(D=H.length;z<D;z++)F=c(H[z],O[z],I),h(F.x,F.y,-E);u=0;for(y=o.length;u<y;u++){w=o[u];C=Q[u];z=0;for(D=w.length;z<D;z++)F=c(w[z],C[z],I),h(F.x,F.y,-E)}}I=l;for(z=0;z<L;z++)F=n?c(B[z],P[z],I):B[z],v?h(F.x,F.y+x[0].y,x[0].x):h(F.x,F.y,0);for(J=1;J<=p;J++)for(z=
0;z<L;z++)F=n?c(B[z],P[z],I):B[z],v?h(F.x,F.y+x[J-1].y,x[J-1].x):h(F.x,F.y,j/p*J);for(J=m-1;J>=0;J--){I=J/m;E=k*(1-I);I=l*Math.sin(I*Math.PI/2);z=0;for(D=H.length;z<D;z++)F=c(H[z],O[z],I),h(F.x,F.y,j+E);u=0;for(y=o.length;u<y;u++){w=o[u];C=Q[u];z=0;for(D=w.length;z<D;z++)F=c(w[z],C[z],I),v?h(F.x,F.y+x[p-1].y,x[p-1].x+E):h(F.x,F.y,j+E)}}if(n){k=L*0;for(z=0;z<M;z++)j=G[z],e(j[2]+k,j[1]+k,j[0]+k);k=L*(p+m*2);for(z=0;z<M;z++)j=G[z],e(j[0]+k,j[1]+k,j[2]+k)}else{for(z=0;z<M;z++)j=G[z],e(j[2],j[1],j[0]);
for(z=0;z<M;z++)j=G[z],e(j[0]+L*p,j[1]+L*p,j[2]+L*p)}var K,N,R=0;g(H);R+=H.length;u=0;for(y=o.length;u<y;u++)w=o[u],g(w),R+=w.length;this.computeCentroids();this.computeFaceNormals()};
THREE.IcosahedronGeometry=function(a){function b(a,c,b){var e=Math.sqrt(a*a+c*c+b*b);return g.vertices.push(new THREE.Vertex(new THREE.Vector3(a/e,c/e,b/e)))-1}function c(a,c,b,e){e.faces.push(new THREE.Face3(a,c,b))}function f(a,c){var e=g.vertices[a].position,f=g.vertices[c].position;return b((e.x+f.x)/2,(e.y+f.y)/2,(e.z+f.z)/2)}var g=this,h=new THREE.Geometry,e;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,
......
......@@ -125,7 +125,7 @@
}
var extrudeSettings = { amount: 20, bevelEnabled: true, bevelSegments: 2, steps: 2 }; // amount: 40, steps: 2
var extrudeSettings = { amount: 20, bevelEnabled: true, bevelSegments: 2, steps: 2 }; // bevelSegments: 2, steps: 2 , bevelSegments: 5, bevelSize: 8, bevelThickness:5,
// California
......@@ -266,12 +266,12 @@
var fishShape = new THREE.Shape();
fishShape.moveTo( x, y );
fishShape.quadraticCurveTo( x + 50, y + 80, x + 90, y + 10 );
fishShape.quadraticCurveTo( x + 100, y + 10, x + 115, y + 40 );
fishShape.quadraticCurveTo( x + 100, y, x + 115, y - 40 );
fishShape.quadraticCurveTo( x + 100, y + 10, x + 90, y - 10 );
fishShape.quadraticCurveTo( x + 50, y - 80, x, y );
fishShape.moveTo(x,y);
fishShape.quadraticCurveTo(x + 50, y - 80, x + 90, y - 10);
fishShape.quadraticCurveTo(x + 100, y - 10, x + 115, y - 40);
fishShape.quadraticCurveTo(x + 115, y, x + 115, y + 40);
fishShape.quadraticCurveTo(x + 100, y + 10, x + 90, y + 10);
fishShape.quadraticCurveTo(x + 50, y + 80, x, y);
var fish3d = fishShape.extrude( extrudeSettings );
var fishPoints = fishShape.createPointsGeometry();
......@@ -291,6 +291,44 @@
var arc3d = arcShape.extrude( extrudeSettings );
var arcPoints = arcShape.createPointsGeometry();
var arcSpacedPoints = arcShape.createSpacedPointsGeometry();
// Smiley
var smileyShape = new THREE.Shape();
smileyShape.moveTo( 0, 0 );
smileyShape.arc( 40, 40, 40, 0, Math.PI*2, false );
var smileyEye1Path = new THREE.Path();
smileyEye1Path.moveTo( 0, 0 );
smileyEye1Path.arc( 25, 20, 10, 0, Math.PI*2, true );
smileyShape.holes.push( smileyEye1Path );
var smileyEye2Path = new THREE.Path();
smileyEye2Path.moveTo( 0, 0 );
smileyEye2Path.arc( 55, 20, 10, 0, Math.PI*2, true );
smileyShape.holes.push( smileyEye2Path );
var smileyMouthPath = new THREE.Path();
// ugly box mouth
// smileyMouthPath.moveTo( 20, 40 );
// smileyMouthPath.lineTo( 60, 40 );
// smileyMouthPath.lineTo( 60, 60 );
// smileyMouthPath.lineTo( 20, 60 );
// smileyMouthPath.lineTo( 20, 40 );
smileyMouthPath.moveTo( 20, 40 );
smileyMouthPath.quadraticCurveTo( 40, 60, 60, 40 );
smileyMouthPath.bezierCurveTo( 70, 45, 70, 50, 60, 60 );
smileyMouthPath.quadraticCurveTo( 40, 80, 20, 60 );
smileyMouthPath.quadraticCurveTo( 5, 50, 20, 40 );
smileyShape.holes.push( smileyMouthPath );
var smiley3d = smileyShape.extrude( extrudeSettings );
var smileyPoints = smileyShape.createPointsGeometry();
var smileySpacedPoints = smileyShape.createSpacedPointsGeometry();
// Spline shape + path extrusion
......@@ -326,10 +364,12 @@
addGeometry( square3d, squarePoints, squareSpacedPoints, 0x0055ff, 150, 100, 0, 0, 0, 0, 1 );
addGeometry( heart3d, heartPoints, heartSpacedPoints, 0xff1100, 0, 100, 0, 3.14, 0, 0, 1 );
addGeometry( circle3d, circlePoints, circleSpacedPoints, 0x00ff11, 120, 250, 0, 0, 0, 0, 1 );
addGeometry( fish3d, fishPoints, fishSpacedPoints, 0x222222, -50, 200, 0, 0, 0, 0, 1 );
addGeometry( fish3d, fishPoints, fishSpacedPoints, 0x222222, -60, 200, 0, 0, 0, 0, 1 );
addGeometry( splineShape3d, splinePoints, splineSpacedPoints, 0x888888, -50, -100, -50, 0, 0, 0, 0.2 );
addGeometry( arc3d, arcPoints, arcSpacedPoints, 0xbb4422, 150, 0, 0, 0, 0, 0, 1 );
addGeometry( smiley3d, smileyPoints, smileySpacedPoints, 0xee00ff, -270, 250, 0, Math.PI, 0, 0, 1 );
//
renderer = new THREE.WebGLRenderer( { antialias: true } );
......
......@@ -38,8 +38,6 @@ THREE.ExtrudeGeometry = function( shapes, options ) {
shape = shapes[ s ];
//console.log(shape);
this.addShape( shape, options );
}
......@@ -60,17 +58,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
// We should set bevel segments to 0 if bevel is not enabled.
// (also bevelThickness and bevelSize make mess when bevel is not enabled,
// whole shape gets thicker)
if ( !bevelEnabled ) {
bevelSegments = 0;
//bevelThickness = 0;
//bevelSize = 0;
}
var steps = options.steps !== undefined ? options.steps : 1;
......@@ -78,11 +66,21 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
var extrudePts, extrudeByPath = false;
if ( extrudePath ) {
extrudePts = extrudePath.getPoints();
steps = extrudePts.length;
extrudeByPath = true;
bevelEnabled = false; // bevels not supported for path extrusion
}
// Safeguards if bevels are not enabled
if ( !bevelEnabled ) {
bevelSegments = 0;
bevelThickness = 0;
bevelSize = 0;
}
......@@ -96,7 +94,6 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
var shapesOffset = this.vertices.length;
//extractAllPoints
var shapePoints = shape.extractAllPoints(); // use shape.extractAllSpacedPoints() for points with equal divisions
var vertices = shapePoints.shape;
......@@ -146,11 +143,13 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
}
// Find all centroids of shapes and holes
var i, il;
// We no longer need centroids
// Find all centroids of shapes and holes
//var sum = new THREE.Vector2();
......@@ -254,6 +253,9 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
p, q, v_dot_w_hat, q_sub_p_dot_w_hat,
s,intersection;
// good reading for line-line intersection
//http://sputsoft.com/blog/2010/03/line-line-intersection.html
// define a as vector j->i
// define b as vectot k->i
a = new THREE.Vector2(pt_i.x - pt_j.x, pt_i.y - pt_j.y);
......@@ -280,13 +282,10 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
p = pt_j.clone().addSelf(v_hat);
q = pt_k.clone().addSelf(w_hat);
// good reading for line-line intersection
//http://sputsoft.com/blog/2010/03/line-line-intersection.html
v_dot_w_hat = v.dot(w_hat);
q_sub_p_dot_w_hat = q.clone().subSelf(p).dot(w_hat);
// We shoud not get these
// We should not reach these conditions
if (v_dot_w_hat ==0 ) {
console.log("Either infinite or no solutions!");
if (q_sub_p_dot_w_hat ==0 ) {
......@@ -305,7 +304,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
intersection = v.clone().multiplyScalar(s).addSelf(p);
return intersection.subSelf(pt_i); // .normalize() Don't normalize!
return intersection.subSelf(pt_i); // Don't normalize!, otherwise sharp corners become ugly
}
......@@ -594,6 +593,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) {
}
// UVs to be added
// How can we create UVs on this?
this.computeCentroids();
this.computeFaceNormals();
......
......@@ -596,7 +596,7 @@ THREE.Path.prototype.nltransform = function( a, b, c, d, e, f ) {
THREE.Path.prototype.debug = function( canvas ) {
var bounds = this.getMinAndMax();
var bounds = this.getBoundingBox();
if ( !canvas ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册