提交 e52edb5d 编写于 作者: A alteredq

Refactored Shape API: replaced bool parameter in extractAllPoints with two named methods.

(per Qt API design suggestions http://developer.qt.nokia.com/wiki/API_Design_Principles)

Also some more whitespace cleanup.
上级 f962eb2e
此差异已折叠。
......@@ -103,8 +103,8 @@ THREE.Path.prototype.createPathGeometry=function(a,c){var b=this.getPoints(a),f,
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 c=this.getMinAndMax(),b=this.getPoints(),f,e,g,h,j,k;f=0;for(e=b.length;f<e;f++)g=b[f],h=g.x,j=g.y,k=h/c.maxX,h=a.getPoint(k),j=a.getNormalVector(k).multiplyScalar(j),g.x=h.x+j.x,g.y=h.y+j.y;return b};
THREE.Path.prototype.nltransform=function(a,c,b,f,e,g){var h=this.getPoints(),j,k,l,m,n;j=0;for(k=h.length;j<k;j++)l=h[j],m=l.x,n=l.y,l.x=a*m+c*n+b,l.y=f*n+e*m+g;return h};
THREE.Path.prototype.debug=function(a){var c=this.getMinAndMax();a||(a=document.createElement("canvas"),a.setAttribute("width",c.maxX+100),a.setAttribute("height",c.maxY+100),document.body.appendChild(a));c=a.getContext("2d");c.fillStyle="white";c.fillRect(0,0,a.width,a.height);c.strokeStyle="black";c.beginPath();var b,f,e,a=0;for(b=this.actions.length;a<b;a++)f=this.actions[a],e=f.args,f=f.action,f!=THREE.PathActions.CSPLINE_THRU&&c[f].apply(c,e);c.stroke();c.closePath();c.strokeStyle="red";f=this.transform(0.866,
-0.866,0,0.5,0.5,-50);a=0;for(b=f.length;a<b;a++)e=f[a],c.beginPath(),c.arc(e.x,e.y,1.5,0,Math.PI*2,!1),c.stroke(),c.closePath()};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.getHoles=function(a){var a=a?"getSpacedPoints":"getPoints",c,b=this.holes.length,f=[];for(c=0;c<b;c++)f[c]=this.holes[c][a]();return f};THREE.Shape.prototype.extractAllPoints=function(a){return{shape:this[a?"getSpacedPoints":"getPoints"](),holes:this.getHoles(a)}};
-0.866,0,0.5,0.5,-50);a=0;for(b=f.length;a<b;a++)e=f[a],c.beginPath(),c.arc(e.x,e.y,1.5,0,Math.PI*2,!1),c.stroke(),c.closePath()};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,c=this.holes.length,b=[];for(a=0;a<c;a++)b[a]=this.holes[a].getPoints();return b};
THREE.Shape.prototype.getSpacedPointsHoles=function(){var a,c=this.holes.length,b=[];for(a=0;a<c;a++)b[a]=this.holes[a].getSpacedPoints();return b};THREE.Shape.prototype.extractAllPoints=function(){return{shape:this.getPoints(),holes:this.getPointsHoles()}};THREE.Shape.prototype.extractAllSpacedPoints=function(){return{shape:this.getSpacedPoints(),holes:this.getSpacedPointsHoles()}};
THREE.Shape.Utils={removeHoles:function(a,c){var b=a.concat(),f=b.concat(),e,g,h,j,k,l,m,n,o,p,v=[];for(k=0;k<c.length;k++){l=c[k];f=f.concat(l);g=Number.POSITIVE_INFINITY;for(e=0;e<l.length;e++){o=l[e];p=[];for(n=0;n<b.length;n++)m=b[n],m=o.distanceTo(m),p.push(m),m<g&&(g=m,h=e,j=n)}e=j-1>=0?j-1:b.length-1;g=h-1>=0?h-1:l.length-1;var u=[l[h],b[j],b[e]];n=THREE.FontUtils.Triangulate.area(u);var w=[l[h],l[g],b[j]];o=THREE.FontUtils.Triangulate.area(w);p=j;m=h;j+=1;h+=-1;j<0&&(j+=b.length);j%=b.length;
h<0&&(h+=l.length);h%=l.length;e=j-1>=0?j-1:b.length-1;g=h-1>=0?h-1:l.length-1;u=[l[h],b[j],b[e]];u=THREE.FontUtils.Triangulate.area(u);w=[l[h],l[g],b[j]];w=THREE.FontUtils.Triangulate.area(w);n+o>u+w&&(j=p,h=m,j<0&&(j+=b.length),j%=b.length,h<0&&(h+=l.length),h%=l.length,e=j-1>=0?j-1:b.length-1,g=h-1>=0?h-1:l.length-1);n=b.slice(0,j);o=b.slice(j);p=l.slice(h);m=l.slice(0,h);g=[l[h],l[g],b[j]];v.push([l[h],b[j],b[e]]);v.push(g);b=n.concat(p).concat(m).concat(o)}return{shape:b,isolatedPts:v,allpoints:f}},
triangulateShape:function(a,c){var b=THREE.Shape.Utils.removeHoles(a,c),f=b.allpoints,e=b.isolatedPts,b=THREE.FontUtils.Triangulate(b.shape,!1),g,h,j,k;for(g=0;g<b.length;g++){k=b[g];for(h=0;h<3;h++)for(j=0;j<f.length;j++)f[j].equals(k[h])&&(k[h]=j)}for(g=0;g<e.length;g++){k=e[g];for(h=0;h<3;h++)for(j=0;j<f.length;j++)f[j].equals(k[h])&&(k[h]=j)}return b.concat(e)},isClockWise:function(a){return THREE.FontUtils.Triangulate.area(a)<0}};
......@@ -116,10 +116,10 @@ THREE.CylinderGeometry=function(a,c,b,f,e,g){function h(a,b,c){j.vertices.push(n
(e||0));for(k=a+a/2;k<2*a;k++)j.faces.push(new THREE.Face4(2*a+1,(2*k-2*a+2)%a+a,(2*k-2*a+1)%a+a,(2*k-2*a)%a+a))}k=0;for(a=this.faces.length;k<a;k++){var c=[],b=this.faces[k],e=this.vertices[b.a],g=this.vertices[b.b],m=this.vertices[b.c],n=this.vertices[b.d];c.push(new THREE.UV(0.5+Math.atan2(e.position.x,e.position.y)/l,0.5+e.position.z/f));c.push(new THREE.UV(0.5+Math.atan2(g.position.x,g.position.y)/l,0.5+g.position.z/f));c.push(new THREE.UV(0.5+Math.atan2(m.position.x,m.position.y)/l,0.5+m.position.z/
f));b instanceof THREE.Face4&&c.push(new THREE.UV(0.5+Math.atan2(n.position.x,n.position.y)/l,0.5+n.position.z/f));this.faceVertexUvs[0].push(c)}this.computeCentroids();this.computeFaceNormals()};THREE.CylinderGeometry.prototype=new THREE.Geometry;THREE.CylinderGeometry.prototype.constructor=THREE.CylinderGeometry;
THREE.ExtrudeGeometry=function(a,c){function b(a,b,c,f){a=a.clone().subSelf(b);c/=a.length();return a.multiplyScalar(f?1+c:1-c).addSelf(b)}function f(a){for(A=a.length;--A>=0;){O=A;M=A-1;M<0&&(M=a.length-1);for(var b=0,b=0;b<n+m*2;b++){var c=I*b,f=I*(b+1);y.faces.push(new THREE.Face4(C+O+c,C+M+c,C+M+f,C+O+f))}}}function e(a,b,c){y.vertices.push(new THREE.Vertex(new THREE.Vector3(a,b,c)))}function g(a,b,c){y.faces.push(new THREE.Face3(a,b,c))}var h=c.amount!==void 0?c.amount:100,j=c.bevelThickness!==
void 0?c.bevelThickness:8,k=c.bevelSize!==void 0?c.bevelSize:j,l=c.bevelEnabled!==void 0?c.bevelEnabled:!0,m=c.bevelSegments!==void 0?c.bevelSegments:3;l||(m=0);var n=c.steps!==void 0?c.steps:1,o=c.path!==void 0?c.path:null,p,v=!1;if(o)p=o.getPoints(),n=p.length,v=!0;THREE.Geometry.call(this);var u,w,x,y=this,o=a.extractAllPoints(!1),t=o.shape,o=o.holes,z=!THREE.Shape.Utils.isClockWise(t);if(z){t=t.reverse();w=0;for(x=o.length;w<x;w++)u=o[w],THREE.Shape.Utils.isClockWise(u)&&(o[w]=u.reverse());z=
!1}var z=THREE.Shape.Utils.triangulateShape(t,o),B=t;w=0;for(x=o.length;w<x;w++)u=o[w],t=t.concat(u);var A,E,G=new THREE.Vector2;A=0;for(E=B.length;A<E;A++)G.addSelf(B[A]);var H=G.divideScalar(B.length),L=[];w=0;for(x=o.length;w<x;w++){G=new THREE.Vector2;u=o[w];A=0;for(E=u.length;A<E;A++)G.addSelf(u[A]);L[w]=G.divideScalar(u.length)}var J,D,K,F,I=t.length,G=z.length;for(J=m;J>0;J--){u=J/m;K=j*u;D=k*(1-Math.sin((1-u)*Math.PI/2));A=0;for(E=B.length;A<E;A++)F=b(B[A],H,D,!1),e(F.x,F.y,-K);w=0;for(x=
o.length;w<x;w++){u=o[w];A=0;for(E=u.length;A<E;A++)F=b(u[A],L[w],D,!0),e(F.x,F.y,-K)}}for(A=0;A<I;A++)F=t[A],v?e(F.x,F.y+p[0].y,p[0].x):e(F.x,F.y,0);for(u=1;u<=n;u++)for(A=0;A<I;A++)F=t[A],v?e(F.x,F.y+p[u-1].y,p[u-1].x):e(F.x,F.y,h/n*u);for(J=1;J<=m;J++){u=J/m;K=j*u;D=k*(1-Math.sin((1-u)*Math.PI/2));A=0;for(E=B.length;A<E;A++)F=b(B[A],H,D,!1),e(F.x,F.y,h+K);w=0;for(x=o.length;w<x;w++){u=o[w];A=0;for(E=u.length;A<E;A++)F=b(u[A],L[w],D,!0),v?e(F.x,F.y+p[n-1].y,p[n-1].x+K):e(F.x,F.y,h+K)}}if(l){j=I*
0;for(A=0;A<G;A++)h=z[A],g(h[2]+j,h[1]+j,h[0]+j);j=I*(n+m*2);for(A=0;A<G;A++)h=z[A],g(h[0]+j,h[1]+j,h[2]+j)}else{for(A=0;A<G;A++)h=z[A],g(h[2],h[1],h[0]);for(A=0;A<G;A++)h=z[A],g(h[0]+I*n,h[1]+I*n,h[2]+I*n)}var O,M,C=0;f(B);C+=B.length;w=0;for(x=o.length;w<x;w++)u=o[w],f(u),C+=u.length;this.computeCentroids();this.computeFaceNormals()};THREE.ExtrudeGeometry.prototype=new THREE.Geometry;THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;
void 0?c.bevelThickness:8,k=c.bevelSize!==void 0?c.bevelSize:j,l=c.bevelEnabled!==void 0?c.bevelEnabled:!0,m=c.bevelSegments!==void 0?c.bevelSegments:3;l||(m=0);var n=c.steps!==void 0?c.steps:1,o=c.path!==void 0?c.path:null,p,v=!1;if(o)p=o.getPoints(),n=p.length,v=!0;THREE.Geometry.call(this);var u,w,x,y=this,o=a.extractAllPoints(),t=o.shape,o=o.holes,z=!THREE.Shape.Utils.isClockWise(t);if(z){t=t.reverse();w=0;for(x=o.length;w<x;w++)u=o[w],THREE.Shape.Utils.isClockWise(u)&&(o[w]=u.reverse());z=!1}var z=
THREE.Shape.Utils.triangulateShape(t,o),B=t;w=0;for(x=o.length;w<x;w++)u=o[w],t=t.concat(u);var A,E,G=new THREE.Vector2;A=0;for(E=B.length;A<E;A++)G.addSelf(B[A]);var H=G.divideScalar(B.length),L=[];w=0;for(x=o.length;w<x;w++){G=new THREE.Vector2;u=o[w];A=0;for(E=u.length;A<E;A++)G.addSelf(u[A]);L[w]=G.divideScalar(u.length)}var J,D,K,F,I=t.length,G=z.length;for(J=m;J>0;J--){u=J/m;K=j*u;D=k*(1-Math.sin((1-u)*Math.PI/2));A=0;for(E=B.length;A<E;A++)F=b(B[A],H,D,!1),e(F.x,F.y,-K);w=0;for(x=o.length;w<
x;w++){u=o[w];A=0;for(E=u.length;A<E;A++)F=b(u[A],L[w],D,!0),e(F.x,F.y,-K)}}for(A=0;A<I;A++)F=t[A],v?e(F.x,F.y+p[0].y,p[0].x):e(F.x,F.y,0);for(u=1;u<=n;u++)for(A=0;A<I;A++)F=t[A],v?e(F.x,F.y+p[u-1].y,p[u-1].x):e(F.x,F.y,h/n*u);for(J=1;J<=m;J++){u=J/m;K=j*u;D=k*(1-Math.sin((1-u)*Math.PI/2));A=0;for(E=B.length;A<E;A++)F=b(B[A],H,D,!1),e(F.x,F.y,h+K);w=0;for(x=o.length;w<x;w++){u=o[w];A=0;for(E=u.length;A<E;A++)F=b(u[A],L[w],D,!0),v?e(F.x,F.y+p[n-1].y,p[n-1].x+K):e(F.x,F.y,h+K)}}if(l){j=I*0;for(A=0;A<
G;A++)h=z[A],g(h[2]+j,h[1]+j,h[0]+j);j=I*(n+m*2);for(A=0;A<G;A++)h=z[A],g(h[0]+j,h[1]+j,h[2]+j)}else{for(A=0;A<G;A++)h=z[A],g(h[2],h[1],h[0]);for(A=0;A<G;A++)h=z[A],g(h[0]+I*n,h[1]+I*n,h[2]+I*n)}var O,M,C=0;f(B);C+=B.length;w=0;for(x=o.length;w<x;w++)u=o[w],f(u),C+=u.length;this.computeCentroids();this.computeFaceNormals()};THREE.ExtrudeGeometry.prototype=new THREE.Geometry;THREE.ExtrudeGeometry.prototype.constructor=THREE.ExtrudeGeometry;
THREE.IcosahedronGeometry=function(a){function c(a,b,c){var f=Math.sqrt(a*a+b*b+c*c);return e.vertices.push(new THREE.Vertex(new THREE.Vector3(a/f,b/f,c/f)))-1}function b(a,b,c,f){f.faces.push(new THREE.Face3(a,b,c))}function f(a,b){var f=e.vertices[a].position,g=e.vertices[b].position;return c((f.x+g.x)/2,(f.y+g.y)/2,(f.z+g.z)/2)}var e=this,g=new THREE.Geometry,h;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;c(-1,a,0);c(1,a,0);c(-1,-a,0);c(1,-a,0);c(0,-1,a);c(0,1,a);c(0,-1,
-a);c(0,1,-a);c(a,0,-1);c(a,0,1);c(-a,0,-1);c(-a,0,1);b(0,11,5,g);b(0,5,1,g);b(0,1,7,g);b(0,7,10,g);b(0,10,11,g);b(1,5,9,g);b(5,11,4,g);b(11,10,2,g);b(10,7,6,g);b(7,1,8,g);b(3,9,4,g);b(3,4,2,g);b(3,2,6,g);b(3,6,8,g);b(3,8,9,g);b(4,9,5,g);b(2,4,11,g);b(6,2,10,g);b(8,6,7,g);b(9,8,1,g);for(a=0;a<this.subdivisions;a++){h=new THREE.Geometry;for(var j in g.faces){var k=f(g.faces[j].a,g.faces[j].b),l=f(g.faces[j].b,g.faces[j].c),m=f(g.faces[j].c,g.faces[j].a);b(g.faces[j].a,k,m,h);b(g.faces[j].b,l,k,h);
b(g.faces[j].c,m,l,h);b(k,l,m,h)}g.faces=h.faces}e.faces=g.faces;delete g;delete h;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.IcosahedronGeometry.prototype=new THREE.Geometry;THREE.IcosahedronGeometry.prototype.constructor=THREE.IcosahedronGeometry;
......
......@@ -518,7 +518,9 @@ THREE.Matrix4.prototype = {
e = Math.cos( z ), f = Math.sin( z );
switch ( order ) {
case 'YXZ':
var ce = c * e, cf = c * f, de = d * e, df = d * f;
this.n11 = ce + df * b;
......@@ -535,6 +537,7 @@ THREE.Matrix4.prototype = {
break;
case 'ZXY':
var ce = c * e, cf = c * f, de = d * e, df = d * f;
this.n11 = ce - df * b;
......@@ -551,6 +554,7 @@ THREE.Matrix4.prototype = {
break;
case 'ZYX':
var ae = a * e, af = a * f, be = b * e, bf = b * f;
this.n11 = c * e;
......@@ -567,6 +571,7 @@ THREE.Matrix4.prototype = {
break;
case 'YZX':
var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
this.n11 = c * e;
......@@ -583,6 +588,7 @@ THREE.Matrix4.prototype = {
break;
case 'XZY':
var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
this.n11 = c * e;
......@@ -599,6 +605,7 @@ THREE.Matrix4.prototype = {
break;
default: // 'XYZ'
var ae = a * e, af = a * f, be = b * e, bf = b * f;
this.n11 = c * e;
......@@ -613,6 +620,7 @@ THREE.Matrix4.prototype = {
this.n32 = be + af * d;
this.n33 = a * c;
break;
}
return this;
......
......@@ -17,7 +17,7 @@
* Abstract Curve base class
**************************************************************/
THREE.Curve = function() {
THREE.Curve = function () {
};
......@@ -88,7 +88,7 @@ THREE.Curve.prototype.getLength = function () {
// Get list of cumulative segment lengths
THREE.Curve.prototype.getLengths = function( divisions ) {
THREE.Curve.prototype.getLengths = function ( divisions ) {
if ( !divisions ) divisions = 200;
......@@ -119,7 +119,7 @@ THREE.Curve.prototype.getLengths = function( divisions ) {
// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equi distance
THREE.Curve.prototype.getUtoTmapping = function( u, distance ) {
THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
var lengths = this.getLengths();
var i = 0, il = lengths.length;
......
......@@ -3,7 +3,7 @@
* Creates extruded geometry from a path shape.
**/
THREE.ExtrudeGeometry = function( shape, options ) {
THREE.ExtrudeGeometry = function ( shape, options ) {
var amount = options.amount !== undefined ? options.amount : 100;
......@@ -43,11 +43,7 @@ THREE.ExtrudeGeometry = function( shape, options ) {
var scope = this;
var bevelPoints = [];
// getPoints
// false for getPoints | true for getSpacedPoints() for points with equal divisions
var shapePoints = shape.extractAllPoints( false );
var shapePoints = shape.extractAllPoints(); // use shape.extractAllSpacedPoints() for points with equal divisions
var vertices = shapePoints.shape;
var holes = shapePoints.holes;
......@@ -60,7 +56,7 @@ THREE.ExtrudeGeometry = function( shape, options ) {
// Maybe we should also check if holes are in the opposite direction, just to be safe ...
for ( h = 0, hl = holes.length; h < hl; h++ ) {
for ( h = 0, hl = holes.length; h < hl; h ++ ) {
ahole = holes[ h ];
......@@ -77,7 +73,7 @@ THREE.ExtrudeGeometry = function( shape, options ) {
}
var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
//var faces = THREE.Shape.Utils.triangulate2( vertices, holes );
//console.log(faces);
......@@ -153,7 +149,7 @@ THREE.ExtrudeGeometry = function( shape, options ) {
// Loop bevelSegments, 1 for the front, 1 for the back
for ( b = bevelSegments; b > 0; b-- ) {
for ( b = bevelSegments; b > 0; b -- ) {
t = b / bevelSegments;
z = bevelThickness * t;
......@@ -191,7 +187,7 @@ THREE.ExtrudeGeometry = function( shape, options ) {
// Back facing vertices
for ( i = 0; i < vlen; i++ ) {
for ( i = 0; i < vlen; i ++ ) {
vert = vertices[ i ];
//v( vert.x, vert.y, 0 );
......@@ -213,7 +209,7 @@ THREE.ExtrudeGeometry = function( shape, options ) {
var s;
for ( s = 1; s <= steps; s++ ) {
for ( s = 1; s <= steps; s ++ ) {
for ( i = 0; i < vlen; i ++ ) {
......@@ -221,7 +217,7 @@ THREE.ExtrudeGeometry = function( shape, options ) {
if ( !extrudeByPath ) {
v( vert.x, vert.y, amount/steps * s );
v( vert.x, vert.y, amount / steps * s );
} else {
......@@ -236,7 +232,7 @@ THREE.ExtrudeGeometry = function( shape, options ) {
// Add bevel segments planes
for ( b = 1; b <= bevelSegments; b++ ) {
for ( b = 1; b <= bevelSegments; b ++ ) {
t = b / bevelSegments;
z = bevelThickness * t;
......
......@@ -33,7 +33,7 @@ THREE.PathActions = {
// Create path using straight lines to connect all points
// - vectors: array of Vector2
THREE.Path.prototype.fromPoints = function( vectors ) {
THREE.Path.prototype.fromPoints = function ( vectors ) {
this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
......@@ -49,14 +49,14 @@ THREE.Path.prototype.fromPoints = function( vectors ) {
// startPath() endPath()?
THREE.Path.prototype.moveTo = function( x, y ) {
THREE.Path.prototype.moveTo = function ( x, y ) {
var args = Array.prototype.slice.call( arguments );
this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
};
THREE.Path.prototype.lineTo = function( x, y ) {
THREE.Path.prototype.lineTo = function ( x, y ) {
var args = Array.prototype.slice.call( arguments );
......@@ -86,8 +86,8 @@ THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args, curve: curve } );
//console.log(curve, curve.getPoints(), curve.getSpacedPoints());
//console.log(curve.getPointAt(0), curve.getPointAt(0),curve.getUtoTmapping(0), curve.getSpacedPoints());
//console.log( curve, curve.getPoints(), curve.getSpacedPoints() );
//console.log( curve.getPointAt(0), curve.getPointAt(0), curve.getUtoTmapping(0), curve.getSpacedPoints() );
};
......@@ -134,8 +134,8 @@ THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
// FUTURE: Change the API or follow canvas API?
// TODO ARC ( x, y, x - radius, y - radius, startAngle, endAngle )
THREE.Path.prototype.arc = function(aX, aY, aRadius,
aStartAngle, aEndAngle, aClockwise ) {
THREE.Path.prototype.arc = function ( aX, aY, aRadius,
aStartAngle, aEndAngle, aClockwise ) {
var args = Array.prototype.slice.call( arguments );
var curve = new THREE.ArcCurve( aX, aY, aRadius,
......@@ -162,7 +162,7 @@ THREE.Path.prototype.arc = function(aX, aY, aRadius,
*/
THREE.Path.prototype.getSpacedPoints = function( divisions ) {
THREE.Path.prototype.getSpacedPoints = function ( divisions ) {
if ( !divisions ) divisions = 40;
......@@ -369,7 +369,7 @@ THREE.Path.prototype.getPoints = function( divisions ) {
};
THREE.Path.prototype.getMinAndMax = function() {
THREE.Path.prototype.getMinAndMax = function () {
var points = this.getPoints();
......
......@@ -19,26 +19,24 @@ THREE.Shape = function ( ) {
THREE.Shape.prototype = new THREE.Path();
THREE.Shape.prototype.constructor = THREE.Path;
/* Convenience method to return ExtrudeGeometry */
// Convenience method to return ExtrudeGeometry
THREE.Shape.prototype.extrude = function( options ) {
THREE.Shape.prototype.extrude = function ( options ) {
var extruded = new THREE.ExtrudeGeometry( this, options );
return extruded;
};
/* Return array of holes' getPoints() */
// Get points of holes
THREE.Shape.prototype.getHoles = function( spaced ) {
var getPoints = spaced ? 'getSpacedPoints' : 'getPoints';
THREE.Shape.prototype.getPointsHoles = function () {
var i, il = this.holes.length, holesPts = [];
for ( i = 0; i < il; i ++ ) {
holesPts[ i ] = this.holes[ i ][ getPoints ](); // getSpacedPoints getPoints
holesPts[ i ] = this.holes[ i ].getPoints();
}
......@@ -46,24 +44,47 @@ THREE.Shape.prototype.getHoles = function( spaced ) {
};
/* Returns points of shape and holes
spaced, when true returns points spaced by regular distances
otherwise return keypoints based on segments paramater
*/
// Get points of holes (spaced by regular distance)
THREE.Shape.prototype.getSpacedPointsHoles = function () {
var i, il = this.holes.length, holesPts = [];
for ( i = 0; i < il; i ++ ) {
holesPts[ i ] = this.holes[ i ].getSpacedPoints();
}
return holesPts;
};
THREE.Shape.prototype.extractAllPoints = function( spaced ) {
// Get points of shape and holes (keypoints based on segments parameter)
var getPoints = spaced ? 'getSpacedPoints' : 'getPoints';
THREE.Shape.prototype.extractAllPoints = function () {
return {
shape: this[ getPoints ](),
holes: this.getHoles( spaced )
shape: this.getPoints(),
holes: this.getPointsHoles()
};
};
// Get points of shape and holes (spaced by regular distance)
THREE.Shape.prototype.extractAllSpacedPoints = function () {
return {
shape: this.getSpacedPoints(),
holes: this.getSpacedPointsHoles()
};
};
THREE.Shape.Utils = {
......@@ -71,7 +92,8 @@ THREE.Shape.Utils = {
contour - array of vector2 for contour
holes - array of array of vector2
*/
removeHoles: function( contour, holes ) {
removeHoles: function ( contour, holes ) {
var shape = contour.concat(); // work on this shape
var allpoints = shape.concat();
......@@ -263,7 +285,7 @@ THREE.Shape.Utils = {
},
triangulateShape: function( contour, holes ) {
triangulateShape: function ( contour, holes ) {
var shapeWithoutHoles = THREE.Shape.Utils.removeHoles( contour, holes );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册