From e52edb5d1ae1dea5571eef010ab69a425ec30913 Mon Sep 17 00:00:00 2001 From: alteredq Date: Thu, 21 Jul 2011 18:35:21 +0200 Subject: [PATCH] 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. --- build/Three.js | 40 ++++++++--------- build/custom/ThreeExtras.js | 12 ++--- src/core/Matrix4.js | 8 ++++ src/extras/geometries/Curve.js | 6 +-- src/extras/geometries/ExtrudeGeometry.js | 22 ++++------ src/extras/geometries/Path.js | 18 ++++---- src/extras/geometries/Shape.js | 56 +++++++++++++++++------- 7 files changed, 94 insertions(+), 68 deletions(-) diff --git a/build/Three.js b/build/Three.js index f34312ed..a8e2bf78 100755 --- a/build/Three.js +++ b/build/Three.js @@ -445,8 +445,8 @@ THREE.Path.prototype.createPathGeometry=function(b,c){var e=this.getPoints(b),f, 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.getMinAndMax(),e=this.getPoints(),f,g,h,j,m,n;f=0;for(g=e.length;f=0?m-1:e.length-1;h=j-1>=0?j-1:p.length-1;var z=[p[j],e[m],e[g]];t=THREE.FontUtils.Triangulate.area(z);var x=[p[j],p[h],e[m]];u=THREE.FontUtils.Triangulate.area(x);v=m;o=j;m+=1;j+=-1;m<0&&(m+=e.length);m%=e.length; j<0&&(j+=p.length);j%=p.length;g=m-1>=0?m-1:e.length-1;h=j-1>=0?j-1:p.length-1;z=[p[j],e[m],e[g]];z=THREE.FontUtils.Triangulate.area(z);x=[p[j],p[h],e[m]];x=THREE.FontUtils.Triangulate.area(x);t+u>z+x&&(m=v,j=o,m<0&&(m+=e.length),m%=e.length,j<0&&(j+=p.length),j%=p.length,g=m-1>=0?m-1:e.length-1,h=j-1>=0?j-1:p.length-1);t=e.slice(0,m);u=e.slice(m);v=p.slice(j);o=p.slice(0,j);h=[p[j],p[h],e[m]];w.push([p[j],e[m],e[g]]);w.push(h);e=t.concat(v).concat(o).concat(u)}return{shape:e,isolatedPts:w,allpoints:f}}, triangulateShape:function(b,c){var e=THREE.Shape.Utils.removeHoles(b,c),f=e.allpoints,g=e.isolatedPts,e=THREE.FontUtils.Triangulate(e.shape,!1),h,j,m,n;for(h=0;h=0;){k=B;V=B-1;V<0&&(V=b.length-1);for(var e=0,e=0;e0;U--){z=U/o;Y=m*z;J=n*(1-Math.sin((1-z)*Math.PI/2));B=0;for(P=G.length;B0;U--){z=U/o;Y=m*z;J=n*(1-Math.sin((1-z)*Math.PI/2));B=0;for(P=G.length;B>7)-127;f|=(h&127)<<16|g<<8;if(f==0&&k==-127)return 0;return(1-2*(j>>7))*(1+f*Math.pow(2,-23))*Math.pow(2,k)}function g(b,c){var e=o(b,c),f=o(b,c+1),h=o(b,c+2);return(o(b,c+3)<<24)+(h<<16)+(f<<8)+e}function n(b,c){var e=o(b,c);return(o(b,c+1)<<8)+e}function p(b,c){var e=o(b,c);return e>127?e-256:e}function o(b, -c){return b.charCodeAt(c)&255}function t(c){var e,f,h;e=g(b,c);f=g(b,c+B);h=g(b,c+P);c=n(b,c+I);THREE.BinaryLoader.prototype.f3(y,e,f,h,c)}function u(c){var e,f,h,j,k,o;e=g(b,c);f=g(b,c+B);h=g(b,c+P);j=n(b,c+I);k=g(b,c+H);o=g(b,c+T);c=g(b,c+U);THREE.BinaryLoader.prototype.f3n(y,E,e,f,h,j,k,o,c)}function v(c){var e,f,h,j;e=g(b,c);f=g(b,c+J);h=g(b,c+Y);j=g(b,c+K);c=n(b,c+S);THREE.BinaryLoader.prototype.f4(y,e,f,h,j,c)}function w(c){var e,f,h,j,o,p,t,u;e=g(b,c);f=g(b,c+J);h=g(b,c+Y);j=g(b,c+K);o=n(b, -c+S);p=g(b,c+k);t=g(b,c+V);u=g(b,c+O);c=g(b,c+fa);THREE.BinaryLoader.prototype.f4n(y,E,e,f,h,j,o,p,t,u,c)}function z(c){var e,f;e=g(b,c);f=g(b,c+ea);c=g(b,c+W);THREE.BinaryLoader.prototype.uv3(y.faceVertexUvs[0],G[e*2],G[e*2+1],G[f*2],G[f*2+1],G[c*2],G[c*2+1])}function x(c){var e,f,h;e=g(b,c);f=g(b,c+da);h=g(b,c+ga);c=g(b,c+ka);THREE.BinaryLoader.prototype.uv4(y.faceVertexUvs[0],G[e*2],G[e*2+1],G[f*2],G[f*2+1],G[h*2],G[h*2+1],G[c*2],G[c*2+1])}var y=this,F=0,C,E=[],G=[],B,P,I,H,T,U,J,Y,K,S,k,V,O,fa, -ea,W,da,ga,ka,pa,R,ha,$,ma,aa;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(y,f,c);C={signature:b.substr(F,8),header_bytes:o(b,F+8),vertex_coordinate_bytes:o(b,F+9),normal_coordinate_bytes:o(b,F+10),uv_coordinate_bytes:o(b,F+11),vertex_index_bytes:o(b,F+12),normal_index_bytes:o(b,F+13),uv_index_bytes:o(b,F+14),material_index_bytes:o(b,F+15),nvertices:g(b,F+16),nnormals:g(b,F+16+4),nuvs:g(b,F+16+8),ntri_flat:g(b,F+16+12),ntri_smooth:g(b,F+16+16),ntri_flat_uv:g(b,F+16+20),ntri_smooth_uv:g(b, +j.setRequestHeader("Content-Type","text/plain");j.send(null)},createBinModel:function(b,c,e,f){var g=function(e){function c(b,e){var f=o(b,e),g=o(b,e+1),h=o(b,e+2),j=o(b,e+3),k=(j<<1&255|h>>7)-127;f|=(h&127)<<16|g<<8;if(f==0&&k==-127)return 0;return(1-2*(j>>7))*(1+f*Math.pow(2,-23))*Math.pow(2,k)}function g(b,e){var c=o(b,e),f=o(b,e+1),h=o(b,e+2);return(o(b,e+3)<<24)+(h<<16)+(f<<8)+c}function n(b,e){var c=o(b,e);return(o(b,e+1)<<8)+c}function p(b,e){var c=o(b,e);return c>127?c-256:c}function o(b, +e){return b.charCodeAt(e)&255}function t(e){var c,f,h;c=g(b,e);f=g(b,e+B);h=g(b,e+P);e=n(b,e+I);THREE.BinaryLoader.prototype.f3(y,c,f,h,e)}function u(e){var c,f,h,j,k,o;c=g(b,e);f=g(b,e+B);h=g(b,e+P);j=n(b,e+I);k=g(b,e+H);o=g(b,e+T);e=g(b,e+U);THREE.BinaryLoader.prototype.f3n(y,E,c,f,h,j,k,o,e)}function v(e){var c,f,h,j;c=g(b,e);f=g(b,e+J);h=g(b,e+Y);j=g(b,e+K);e=n(b,e+S);THREE.BinaryLoader.prototype.f4(y,c,f,h,j,e)}function w(e){var c,f,h,j,o,p,t,u;c=g(b,e);f=g(b,e+J);h=g(b,e+Y);j=g(b,e+K);o=n(b, +e+S);p=g(b,e+k);t=g(b,e+V);u=g(b,e+O);e=g(b,e+fa);THREE.BinaryLoader.prototype.f4n(y,E,c,f,h,j,o,p,t,u,e)}function z(e){var c,f;c=g(b,e);f=g(b,e+ea);e=g(b,e+W);THREE.BinaryLoader.prototype.uv3(y.faceVertexUvs[0],G[c*2],G[c*2+1],G[f*2],G[f*2+1],G[e*2],G[e*2+1])}function x(e){var c,f,h;c=g(b,e);f=g(b,e+da);h=g(b,e+ga);e=g(b,e+ka);THREE.BinaryLoader.prototype.uv4(y.faceVertexUvs[0],G[c*2],G[c*2+1],G[f*2],G[f*2+1],G[h*2],G[h*2+1],G[e*2],G[e*2+1])}var y=this,F=0,C,E=[],G=[],B,P,I,H,T,U,J,Y,K,S,k,V,O,fa, +ea,W,da,ga,ka,pa,R,ha,$,ma,aa;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(y,f,e);C={signature:b.substr(F,8),header_bytes:o(b,F+8),vertex_coordinate_bytes:o(b,F+9),normal_coordinate_bytes:o(b,F+10),uv_coordinate_bytes:o(b,F+11),vertex_index_bytes:o(b,F+12),normal_index_bytes:o(b,F+13),uv_index_bytes:o(b,F+14),material_index_bytes:o(b,F+15),nvertices:g(b,F+16),nnormals:g(b,F+16+4),nuvs:g(b,F+16+8),ntri_flat:g(b,F+16+12),ntri_smooth:g(b,F+16+16),ntri_flat_uv:g(b,F+16+20),ntri_smooth_uv:g(b, F+16+24),nquad_flat:g(b,F+16+28),nquad_smooth:g(b,F+16+32),nquad_flat_uv:g(b,F+16+36),nquad_smooth_uv:g(b,F+16+40)};F+=C.header_bytes;B=C.vertex_index_bytes;P=C.vertex_index_bytes*2;I=C.vertex_index_bytes*3;H=C.vertex_index_bytes*3+C.material_index_bytes;T=C.vertex_index_bytes*3+C.material_index_bytes+C.normal_index_bytes;U=C.vertex_index_bytes*3+C.material_index_bytes+C.normal_index_bytes*2;J=C.vertex_index_bytes;Y=C.vertex_index_bytes*2;K=C.vertex_index_bytes*3;S=C.vertex_index_bytes*4;k=C.vertex_index_bytes* -4+C.material_index_bytes;V=C.vertex_index_bytes*4+C.material_index_bytes+C.normal_index_bytes;O=C.vertex_index_bytes*4+C.material_index_bytes+C.normal_index_bytes*2;fa=C.vertex_index_bytes*4+C.material_index_bytes+C.normal_index_bytes*3;ea=C.uv_index_bytes;W=C.uv_index_bytes*2;da=C.uv_index_bytes;ga=C.uv_index_bytes*2;ka=C.uv_index_bytes*3;c=C.vertex_index_bytes*3+C.material_index_bytes;aa=C.vertex_index_bytes*4+C.material_index_bytes;pa=C.ntri_flat*c;R=C.ntri_smooth*(c+C.normal_index_bytes*3);ha= -C.ntri_flat_uv*(c+C.uv_index_bytes*3);$=C.ntri_smooth_uv*(c+C.normal_index_bytes*3+C.uv_index_bytes*3);ma=C.nquad_flat*aa;c=C.nquad_smooth*(aa+C.normal_index_bytes*4);aa=C.nquad_flat_uv*(aa+C.uv_index_bytes*4);F+=function(c){for(var f,g,h,k=C.vertex_coordinate_bytes*3,m=c+C.nvertices*k;c1&&(T=[new THREE.MeshFaceMaterial]);object=new THREE.Mesh(B,T);object.name=v;object.position.set(C[0],C[1],C[2]);q?(object.quaternion.set(q[0],q[1],q[2],q[3]),object.useQuaternion=!0):object.rotation.set(r[0],r[1],r[2]);object.scale.set(s[0],s[1],s[2]);object.visible=F.visible;O.scene.addObject(object);O.objects[v]=object;F.meshCollider&&(b=THREE.CollisionUtils.MeshColliderWBox(object),O.scene.collisions.colliders.push(b)); if(F.castsShadow)b=new THREE.ShadowVolume(B),O.scene.addChild(b),b.position=object.position,b.rotation=object.rotation,b.scale=object.scale;F.trigger&&F.trigger.toLowerCase()!="none"&&(b={type:F.trigger,object:F},O.triggers[object.name]=b)}}else C=F.position,r=F.rotation,q=F.quaternion,s=F.scale,q=0,object=new THREE.Object3D,object.name=v,object.position.set(C[0],C[1],C[2]),q?(object.quaternion.set(q[0],q[1],q[2],q[3]),object.useQuaternion=!0):object.rotation.set(r[0],r[1],r[2]),object.scale.set(s[0], -s[1],s[2]),object.visible=F.visible!==void 0?F.visible:!1,O.scene.addObject(object),O.objects[v]=object,O.empties[v]=object,F.trigger&&F.trigger.toLowerCase()!="none"&&(b={type:F.trigger,object:F},O.triggers[object.name]=b)}function n(b){return function(c){O.geometries[b]=c;m();K-=1;e.onLoadComplete();o()}}function p(b){return function(c){O.geometries[b]=c}}function o(){e.callbackProgress({totalModels:k,totalTextures:V,loadedModels:k-K,loadedTextures:V-S},O);e.onLoadProgress();K==0&&S==0&&c(O)}var t, +s[1],s[2]),object.visible=F.visible!==void 0?F.visible:!1,O.scene.addObject(object),O.objects[v]=object,O.empties[v]=object,F.trigger&&F.trigger.toLowerCase()!="none"&&(b={type:F.trigger,object:F},O.triggers[object.name]=b)}function n(b){return function(c){O.geometries[b]=c;m();K-=1;e.onLoadComplete();o()}}function p(b){return function(e){O.geometries[b]=e}}function o(){e.callbackProgress({totalModels:k,totalTextures:V,loadedModels:k-K,loadedTextures:V-S},O);e.onLoadProgress();K==0&&S==0&&c(O)}var t, u,v,w,z,x,y,F,C,E,G,B,P,I,H,T,U,J,Y,K,S,k,V,O;J=b.data;H=new THREE.BinaryLoader;Y=new THREE.JSONLoader;S=K=0;O={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},triggers:{},empties:{}};b=!1;for(v in J.objects)if(F=J.objects[v],F.meshCollider){b=!0;break}if(b)O.scene.collisions=new THREE.CollisionSystem;if(J.transform){b=J.transform.position;E=J.transform.rotation;var fa=J.transform.scale;b&&O.scene.position.set(b[0],b[1],b[2]);E&&O.scene.rotation.set(E[0], E[1],E[2]);fa&&O.scene.scale.set(fa[0],fa[1],fa[2]);(b||E||fa)&&O.scene.updateMatrix()}b=function(){S-=1;o();e.onLoadComplete()};for(z in J.cameras){E=J.cameras[z];if(E.type=="perspective")P=new THREE.Camera(E.fov,E.aspect,E.near,E.far);else if(E.type=="ortho")P=new THREE.Camera,P.projectionMatrix=THREE.Matrix4.makeOrtho(E.left,E.right,E.top,E.bottom,E.near,E.far);C=E.position;E=E.target;P.position.set(C[0],C[1],C[2]);P.target.position.set(E[0],E[1],E[2]);O.cameras[z]=P}for(w in J.lights)z=J.lights[w], P=z.color!==void 0?z.color:16777215,E=z.intensity!==void 0?z.intensity:1,z.type=="directional"?(C=z.direction,U=new THREE.DirectionalLight(P,E),U.position.set(C[0],C[1],C[2]),U.position.normalize()):z.type=="point"?(C=z.position,d=z.distance,U=new THREE.PointLight(P,E,d),U.position.set(C[0],C[1],C[2])):z.type=="ambient"&&(U=new THREE.AmbientLight(P)),O.scene.addLight(U),O.lights[w]=U;for(x in J.fogs)w=J.fogs[x],w.type=="linear"?I=new THREE.Fog(0,w.near,w.far):w.type=="exp2"&&(I=new THREE.FogExp2(0, diff --git a/build/custom/ThreeExtras.js b/build/custom/ThreeExtras.js index d8b364e9..2a3f63b7 100644 --- a/build/custom/ThreeExtras.js +++ b/build/custom/ThreeExtras.js @@ -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=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=0;){O=A;M=A-1;M<0&&(M=a.length-1);for(var b=0,b=0;b0;J--){u=J/m;K=j*u;D=k*(1-Math.sin((1-u)*Math.PI/2));A=0;for(E=B.length;A0;J--){u=J/m;K=j*u;D=k*(1-Math.sin((1-u)*Math.PI/2));A=0;for(E=B.length;A 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; diff --git a/src/extras/geometries/Path.js b/src/extras/geometries/Path.js index baad1eab..c3e1202f 100644 --- a/src/extras/geometries/Path.js +++ b/src/extras/geometries/Path.js @@ -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(); diff --git a/src/extras/geometries/Shape.js b/src/extras/geometries/Shape.js index b03d4e04..0716e52d 100644 --- a/src/extras/geometries/Shape.js +++ b/src/extras/geometries/Shape.js @@ -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.extractAllPoints = function( spaced ) { +THREE.Shape.prototype.getSpacedPointsHoles = function () { - var getPoints = spaced ? 'getSpacedPoints' : 'getPoints'; + var i, il = this.holes.length, holesPts = []; + + for ( i = 0; i < il; i ++ ) { + + holesPts[ i ] = this.holes[ i ].getSpacedPoints(); + + } + + return holesPts; + +}; + +// Get points of shape and holes (keypoints based on segments parameter) + +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 );