提交 35b9c8dd 编写于 作者: A alteredq

Merge remote-tracking branch 'remotes/zz85/experimental' into experimental

......@@ -156,8 +156,8 @@ var h=this,m=null,n=new THREE.Projector,b=b||{},t=b.canvas!==void 0?b.canvas:doc
ta=!1,ua=new THREE.Color,wa=new THREE.Color,Da=new THREE.Color,ya=new THREE.Color,ra=new THREE.Vector3,Ea,Y,S,va,U,za,b=16;Ea=document.createElement("canvas");Ea.width=Ea.height=2;Y=Ea.getContext("2d");Y.fillStyle="rgba(0,0,0,1)";Y.fillRect(0,0,2,2);S=Y.getImageData(0,0,2,2);va=S.data;U=document.createElement("canvas");U.width=U.height=b;za=U.getContext("2d");za.translate(-b/2,-b/2);za.scale(b,b);b--;this.domElement=t;this.sortElements=this.sortObjects=this.autoClear=!0;this.data={vertices:0,faces:0};
this.setSize=function(b,e){o=b;p=e;v=o/2;u=p/2;t.width=o;t.height=p;W.set(-v,-u,v,u);ja.set(-v,-u,v,u);y=1;G=0;X=D=E=L=B=null};this.setClearColor=function(b,e){z=b;x=e;ja.set(-v,-u,v,u)};this.setClearColorHex=function(b,e){z.setHex(b);x=e;ja.set(-v,-u,v,u)};this.clear=function(){w.setTransform(1,0,0,-1,v,u);if(!ja.isEmpty())ja.inflate(1),ja.minSelf(W),x==0?w.clearRect(ja.getX(),ja.getY(),ja.getWidth(),ja.getHeight()):(e(THREE.NormalBlending),c(1),L="rgba("+Math.floor(z.r*255)+","+Math.floor(z.g*255)+
","+Math.floor(z.b*255)+","+x+")",w.fillStyle=L,w.fillRect(ja.getX(),ja.getY(),ja.getWidth(),ja.getHeight())),ja.empty()};this.render=function(b,j){function t(b){var e,c,f,h=b.lights;wa.setRGB(0,0,0);Da.setRGB(0,0,0);ya.setRGB(0,0,0);b=0;for(e=h.length;b<e;b++)c=h[b],f=c.color,c instanceof THREE.AmbientLight?(wa.r+=f.r,wa.g+=f.g,wa.b+=f.b):c instanceof THREE.DirectionalLight?(Da.r+=f.r,Da.g+=f.g,Da.b+=f.b):c instanceof THREE.PointLight&&(ya.r+=f.r,ya.g+=f.g,ya.b+=f.b)}function o(b,e,c,f){var h,g,
j,k,m=b.lights,b=0;for(h=m.length;b<h;b++)g=m[b],j=g.color,g instanceof THREE.DirectionalLight?(k=c.dot(g.position),k<=0||(k*=g.intensity,f.r+=j.r*k,f.g+=j.g*k,f.b+=j.b*k)):g instanceof THREE.PointLight&&(k=c.dot(ra.sub(g.position,e).normalize()),k<=0||(k*=g.distance==0?1:1-Math.min(e.distanceTo(g.position)/g.distance,1),k!=0&&(k*=g.intensity,f.r+=j.r*k,f.g+=j.g*k,f.b+=j.b*k)))}function p(b,h,j){c(j.opacity);e(j.blending);var k,m,n,t,ma,o;if(j instanceof THREE.ParticleBasicMaterial){if(j.map)t=j.map.image,
ma=t.width>>1,o=t.height>>1,j=h.scale.x*v,n=h.scale.y*u,k=j*ma,m=n*o,qa.set(b.x-k,b.y-m,b.x+k,b.y+m),W.instersects(qa)&&(w.save(),w.translate(b.x,b.y),w.rotate(-h.rotation),w.scale(j,-n),w.translate(-ma,-o),w.drawImage(t,0,0),w.restore())}else j instanceof THREE.ParticleCanvasMaterial&&(k=h.scale.x*v,m=h.scale.y*u,qa.set(b.x-k,b.y-m,b.x+k,b.y+m),W.instersects(qa)&&(f(j.color),g(j.color),w.save(),w.translate(b.x,b.y),w.rotate(-h.rotation),w.scale(k,m),j.program(w),w.restore()))}function y(b,h,j,g){c(g.opacity);
j,k,m=b.lights,b=0;for(h=m.length;b<h;b++)g=m[b],j=g.color,g instanceof THREE.DirectionalLight?(k=c.dot(g.position),k<=0||(k*=g.intensity,f.r+=j.r*k,f.g+=j.g*k,f.b+=j.b*k)):g instanceof THREE.PointLight&&(k=c.dot(ra.sub(g.position,e).normalize()),k<=0||(k*=g.distance==0?1:1-Math.min(e.distanceTo(g.position)/g.distance,1),k!=0&&(k*=g.intensity,f.r+=j.r*k,f.g+=j.g*k,f.b+=j.b*k)))}function p(b,h,k){c(k.opacity);e(k.blending);var j,m,n,t,ma,o;if(k instanceof THREE.ParticleBasicMaterial){if(k.map)t=k.map.image,
ma=t.width>>1,o=t.height>>1,k=h.scale.x*v,n=h.scale.y*u,j=k*ma,m=n*o,qa.set(b.x-j,b.y-m,b.x+j,b.y+m),W.instersects(qa)&&(w.save(),w.translate(b.x,b.y),w.rotate(-h.rotation),w.scale(k,-n),w.translate(-ma,-o),w.drawImage(t,0,0),w.restore())}else k instanceof THREE.ParticleCanvasMaterial&&(j=h.scale.x*v,m=h.scale.y*u,qa.set(b.x-j,b.y-m,b.x+j,b.y+m),W.instersects(qa)&&(f(k.color),g(k.color),w.save(),w.translate(b.x,b.y),w.rotate(-h.rotation),w.scale(j,m),k.program(w),w.restore()))}function y(b,h,k,g){c(g.opacity);
e(g.blending);w.beginPath();w.moveTo(b.positionScreen.x,b.positionScreen.y);w.lineTo(h.positionScreen.x,h.positionScreen.y);w.closePath();if(g instanceof THREE.LineBasicMaterial){b=g.linewidth;if(E!=b)w.lineWidth=E=b;b=g.linecap;if(D!=b)w.lineCap=D=b;b=g.linejoin;if(X!=b)w.lineJoin=X=b;f(g.color);w.stroke();qa.inflate(g.linewidth*2)}}function z(b,f,g,m,n,t,ma,p,u){h.data.vertices+=3;h.data.faces++;c(p.opacity);e(p.blending);R=b.positionScreen.x;T=b.positionScreen.y;$=f.positionScreen.x;k=f.positionScreen.y;
K=g.positionScreen.x;da=g.positionScreen.y;B(R,T,$,k,K,da);if(p instanceof THREE.MeshBasicMaterial)if(p.map)p.map.mapping instanceof THREE.UVMapping&&(ka=ma.uvs[0],Ga(R,T,$,k,K,da,p.map.image,ka[m].u,ka[m].v,ka[n].u,ka[n].v,ka[t].u,ka[t].v));else if(p.envMap){if(p.envMap.mapping instanceof THREE.SphericalReflectionMapping)b=j.matrixWorldInverse,ra.copy(ma.vertexNormalsWorld[0]),sa=(ra.x*b.n11+ra.y*b.n12+ra.z*b.n13)*0.5+0.5,xa=-(ra.x*b.n21+ra.y*b.n22+ra.z*b.n23)*0.5+0.5,ra.copy(ma.vertexNormalsWorld[1]),
Aa=(ra.x*b.n11+ra.y*b.n12+ra.z*b.n13)*0.5+0.5,Ia=-(ra.x*b.n21+ra.y*b.n22+ra.z*b.n23)*0.5+0.5,ra.copy(ma.vertexNormalsWorld[2]),Ba=(ra.x*b.n11+ra.y*b.n12+ra.z*b.n13)*0.5+0.5,Pa=-(ra.x*b.n21+ra.y*b.n22+ra.z*b.n23)*0.5+0.5,Ga(R,T,$,k,K,da,p.envMap.image,sa,xa,Aa,Ia,Ba,Pa)}else p.wireframe?Ja(p.color,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):L(p.color);else if(p instanceof THREE.MeshLambertMaterial)p.map&&!p.wireframe&&(p.map.mapping instanceof THREE.UVMapping&&(ka=ma.uvs[0],Ga(R,T,
......@@ -168,16 +168,16 @@ e(p.blending);if(p.map||p.envMap)z(b,f,m,0,1,3,ma,p,u),z(n,g,t,1,2,3,ma,p,u);els
THREE.MeshLambertMaterial)ta?!p.wireframe&&p.shading==THREE.SmoothShading&&ma.vertexNormalsWorld.length==4?(ia.r=na.r=ca.r=oa.r=wa.r,ia.g=na.g=ca.g=oa.g=wa.g,ia.b=na.b=ca.b=oa.b=wa.b,o(u,ma.v1.positionWorld,ma.vertexNormalsWorld[0],ia),o(u,ma.v2.positionWorld,ma.vertexNormalsWorld[1],na),o(u,ma.v4.positionWorld,ma.vertexNormalsWorld[3],ca),o(u,ma.v3.positionWorld,ma.vertexNormalsWorld[2],oa),ga=Sa(ia,na,ca,oa),B(R,T,$,k,Z,aa),Ga(R,T,$,k,Z,aa,ga,0,0,1,0,0,1),B(ha,la,K,da,ea,fa),Ga(ha,la,K,da,ea,fa,
ga,1,0,1,1,0,1)):(ua.r=wa.r,ua.g=wa.g,ua.b=wa.b,o(u,ma.centroidWorld,ma.normalWorld,ua),F.r=Math.max(0,Math.min(p.color.r*ua.r,1)),F.g=Math.max(0,Math.min(p.color.g*ua.g,1)),F.b=Math.max(0,Math.min(p.color.b*ua.b,1)),F.updateHex(),G(R,T,$,k,K,da,Z,aa),p.wireframe?Ja(F,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):L(F)):(G(R,T,$,k,K,da,Z,aa),p.wireframe?Ja(p.color,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):L(p.color));else if(p instanceof THREE.MeshNormalMaterial)F.r=
Qa(ma.normalWorld.x),F.g=Qa(ma.normalWorld.y),F.b=Qa(ma.normalWorld.z),F.updateHex(),G(R,T,$,k,K,da,Z,aa),p.wireframe?Ja(F,p.wireframeLinewidth,p.wireframeLinecap,p.wireframeLinejoin):L(F);else if(p instanceof THREE.MeshDepthMaterial)J=j.near,V=j.far,ia.r=ia.g=ia.b=1-Na(b.positionScreen.z,J,V),na.r=na.g=na.b=1-Na(f.positionScreen.z,J,V),ca.r=ca.g=ca.b=1-Na(m.positionScreen.z,J,V),oa.r=oa.g=oa.b=1-Na(g.positionScreen.z,J,V),ga=Sa(ia,na,ca,oa),B(R,T,$,k,Z,aa),Ga(R,T,$,k,Z,aa,ga,0,0,1,0,0,1),B(ha,la,
K,da,ea,fa),Ga(ha,la,K,da,ea,fa,ga,1,0,1,1,0,1)}function B(b,e,c,f,h,g){w.beginPath();w.moveTo(b,e);w.lineTo(c,f);w.lineTo(h,g);w.lineTo(b,e);w.closePath()}function G(b,e,c,f,h,g,j,k){w.beginPath();w.moveTo(b,e);w.lineTo(c,f);w.lineTo(h,g);w.lineTo(j,k);w.lineTo(b,e);w.closePath()}function Ja(b,e,c,h){if(E!=e)w.lineWidth=E=e;if(D!=c)w.lineCap=D=c;if(X!=h)w.lineJoin=X=h;f(b);w.stroke();qa.inflate(e*2)}function L(b){g(b);w.fill()}function Ga(b,e,c,f,h,g,j,k,m,n,t,p,ma){var o,u;o=j.width-1;u=j.height-
1;k*=o;m*=u;n*=o;t*=u;p*=o;ma*=u;c-=b;f-=e;h-=b;g-=e;n-=k;t-=m;p-=k;ma-=m;o=n*ma-p*t;if(!((o<0?-o:o)<1))u=1/o,o=(ma*c-t*h)*u,t=(ma*f-t*g)*u,c=(n*h-p*c)*u,f=(n*g-p*f)*u,b=b-o*k-c*m,e=e-t*k-f*m,w.save(),w.transform(o,t,c,f,b,e),w.clip(),w.drawImage(j,0,0),w.restore()}function Sa(b,e,c,f){var h=~~(b.r*255),g=~~(b.g*255),b=~~(b.b*255),j=~~(e.r*255),k=~~(e.g*255),e=~~(e.b*255),m=~~(c.r*255),n=~~(c.g*255),c=~~(c.b*255),t=~~(f.r*255),p=~~(f.g*255),f=~~(f.b*255);va[0]=h<0?0:h>255?255:h;va[1]=g<0?0:g>255?
255:g;va[2]=b<0?0:b>255?255:b;va[4]=j<0?0:j>255?255:j;va[5]=k<0?0:k>255?255:k;va[6]=e<0?0:e>255?255:e;va[8]=m<0?0:m>255?255:m;va[9]=n<0?0:n>255?255:n;va[10]=c<0?0:c>255?255:c;va[12]=t<0?0:t>255?255:t;va[13]=p<0?0:p>255?255:p;va[14]=f<0?0:f>255?255:f;Y.putImageData(S,0,0);za.drawImage(Ea,0,0);return U}function Na(b,e,c){b=(b-e)/(c-e);return b*b*(3-2*b)}function Qa(b){b=(b+1)*0.5;return b<0?0:b>1?1:b}function Ka(b,e){var c=e.x-b.x,f=e.y-b.y,h=c*c+f*f;h!=0&&(h=1/Math.sqrt(h),c*=h,f*=h,e.x+=c,e.y+=f,
K,da,ea,fa),Ga(ha,la,K,da,ea,fa,ga,1,0,1,1,0,1)}function B(b,e,c,f,h,g){w.beginPath();w.moveTo(b,e);w.lineTo(c,f);w.lineTo(h,g);w.lineTo(b,e);w.closePath()}function G(b,e,c,f,h,g,k,j){w.beginPath();w.moveTo(b,e);w.lineTo(c,f);w.lineTo(h,g);w.lineTo(k,j);w.lineTo(b,e);w.closePath()}function Ja(b,e,c,h){if(E!=e)w.lineWidth=E=e;if(D!=c)w.lineCap=D=c;if(X!=h)w.lineJoin=X=h;f(b);w.stroke();qa.inflate(e*2)}function L(b){g(b);w.fill()}function Ga(b,e,c,f,h,g,k,j,m,n,t,p,ma){var o,u;o=k.width-1;u=k.height-
1;j*=o;m*=u;n*=o;t*=u;p*=o;ma*=u;c-=b;f-=e;h-=b;g-=e;n-=j;t-=m;p-=j;ma-=m;o=n*ma-p*t;if(!((o<0?-o:o)<1))u=1/o,o=(ma*c-t*h)*u,t=(ma*f-t*g)*u,c=(n*h-p*c)*u,f=(n*g-p*f)*u,b=b-o*j-c*m,e=e-t*j-f*m,w.save(),w.transform(o,t,c,f,b,e),w.clip(),w.drawImage(k,0,0),w.restore()}function Sa(b,e,c,f){var h=~~(b.r*255),g=~~(b.g*255),b=~~(b.b*255),k=~~(e.r*255),j=~~(e.g*255),e=~~(e.b*255),m=~~(c.r*255),n=~~(c.g*255),c=~~(c.b*255),t=~~(f.r*255),p=~~(f.g*255),f=~~(f.b*255);va[0]=h<0?0:h>255?255:h;va[1]=g<0?0:g>255?
255:g;va[2]=b<0?0:b>255?255:b;va[4]=k<0?0:k>255?255:k;va[5]=j<0?0:j>255?255:j;va[6]=e<0?0:e>255?255:e;va[8]=m<0?0:m>255?255:m;va[9]=n<0?0:n>255?255:n;va[10]=c<0?0:c>255?255:c;va[12]=t<0?0:t>255?255:t;va[13]=p<0?0:p>255?255:p;va[14]=f<0?0:f>255?255:f;Y.putImageData(S,0,0);za.drawImage(Ea,0,0);return U}function Na(b,e,c){b=(b-e)/(c-e);return b*b*(3-2*b)}function Qa(b){b=(b+1)*0.5;return b<0?0:b>1?1:b}function Ka(b,e){var c=e.x-b.x,f=e.y-b.y,h=c*c+f*f;h!=0&&(h=1/Math.sqrt(h),c*=h,f*=h,e.x+=c,e.y+=f,
b.x-=c,b.y-=f)}var Ta,Va,pa,Ca,La,Ra,Ua,C;this.autoClear?this.clear():w.setTransform(1,0,0,-1,v,u);h.data.vertices=0;h.data.faces=0;m=n.projectScene(b,j,this.sortElements);(ta=b.lights.length>0)&&t(b);Ta=0;for(Va=m.length;Ta<Va;Ta++){pa=m[Ta];qa.empty();if(pa instanceof THREE.RenderableParticle){H=pa;H.x*=v;H.y*=u;Ca=0;for(La=pa.materials.length;Ca<La;)C=pa.materials[Ca++],C.opacity!=0&&p(H,pa,C,b)}else if(pa instanceof THREE.RenderableLine){if(H=pa.v1,I=pa.v2,H.positionScreen.x*=v,H.positionScreen.y*=
u,I.positionScreen.x*=v,I.positionScreen.y*=u,qa.addPoint(H.positionScreen.x,H.positionScreen.y),qa.addPoint(I.positionScreen.x,I.positionScreen.y),W.instersects(qa)){Ca=0;for(La=pa.materials.length;Ca<La;)C=pa.materials[Ca++],C.opacity!=0&&y(H,I,pa,C,b)}}else if(pa instanceof THREE.RenderableFace3){if(H=pa.v1,I=pa.v2,M=pa.v3,H.positionScreen.x*=v,H.positionScreen.y*=u,I.positionScreen.x*=v,I.positionScreen.y*=u,M.positionScreen.x*=v,M.positionScreen.y*=u,pa.overdraw&&(Ka(H.positionScreen,I.positionScreen),
Ka(I.positionScreen,M.positionScreen),Ka(M.positionScreen,H.positionScreen)),qa.add3Points(H.positionScreen.x,H.positionScreen.y,I.positionScreen.x,I.positionScreen.y,M.positionScreen.x,M.positionScreen.y),W.instersects(qa)){Ca=0;for(La=pa.meshMaterials.length;Ca<La;)if(C=pa.meshMaterials[Ca++],C instanceof THREE.MeshFaceMaterial){Ra=0;for(Ua=pa.faceMaterials.length;Ra<Ua;)(C=pa.faceMaterials[Ra++])&&C.opacity!=0&&z(H,I,M,0,1,2,pa,C,b)}else C.opacity!=0&&z(H,I,M,0,1,2,pa,C,b)}}else if(pa instanceof
THREE.RenderableFace4&&(H=pa.v1,I=pa.v2,M=pa.v3,P=pa.v4,H.positionScreen.x*=v,H.positionScreen.y*=u,I.positionScreen.x*=v,I.positionScreen.y*=u,M.positionScreen.x*=v,M.positionScreen.y*=u,P.positionScreen.x*=v,P.positionScreen.y*=u,Q.positionScreen.copy(I.positionScreen),O.positionScreen.copy(P.positionScreen),pa.overdraw&&(Ka(H.positionScreen,I.positionScreen),Ka(I.positionScreen,P.positionScreen),Ka(P.positionScreen,H.positionScreen),Ka(M.positionScreen,Q.positionScreen),Ka(M.positionScreen,O.positionScreen)),
qa.addPoint(H.positionScreen.x,H.positionScreen.y),qa.addPoint(I.positionScreen.x,I.positionScreen.y),qa.addPoint(M.positionScreen.x,M.positionScreen.y),qa.addPoint(P.positionScreen.x,P.positionScreen.y),W.instersects(qa))){Ca=0;for(La=pa.meshMaterials.length;Ca<La;)if(C=pa.meshMaterials[Ca++],C instanceof THREE.MeshFaceMaterial){Ra=0;for(Ua=pa.faceMaterials.length;Ra<Ua;)(C=pa.faceMaterials[Ra++])&&C.opacity!=0&&x(H,I,M,P,Q,O,pa,C,b)}else C.opacity!=0&&x(H,I,M,P,Q,O,pa,C,b)}ja.addRectangle(qa)}w.setTransform(1,
0,0,1,0,0)}};
THREE.SVGRenderer=function(){function b(b,e,c){var f,h,g,j;f=0;for(h=b.lights.length;f<h;f++)g=b.lights[f],g instanceof THREE.DirectionalLight?(j=e.normalWorld.dot(g.position)*g.intensity,j>0&&(c.r+=g.color.r*j,c.g+=g.color.g*j,c.b+=g.color.b*j)):g instanceof THREE.PointLight&&(P.sub(g.position,e.centroidWorld),P.normalize(),j=e.normalWorld.dot(P)*g.intensity,j>0&&(c.r+=g.color.r*j,c.g+=g.color.g*j,c.b+=g.color.b*j))}function c(e,c,k,m,n,p){h.data.vertices+=3;h.data.faces++;R=f(T++);R.setAttribute("d",
THREE.SVGRenderer=function(){function b(b,e,c){var f,h,g,k;f=0;for(h=b.lights.length;f<h;f++)g=b.lights[f],g instanceof THREE.DirectionalLight?(k=e.normalWorld.dot(g.position)*g.intensity,k>0&&(c.r+=g.color.r*k,c.g+=g.color.g*k,c.b+=g.color.b*k)):g instanceof THREE.PointLight&&(P.sub(g.position,e.centroidWorld),P.normalize(),k=e.normalWorld.dot(P)*g.intensity,k>0&&(c.r+=g.color.r*k,c.g+=g.color.g*k,c.b+=g.color.b*k))}function c(e,c,k,m,n,p){h.data.vertices+=3;h.data.faces++;R=f(T++);R.setAttribute("d",
"M "+e.positionScreen.x+" "+e.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+k.positionScreen.x+","+k.positionScreen.y+"z");n instanceof THREE.MeshBasicMaterial?E.hex=n.color.hex:n instanceof THREE.MeshLambertMaterial?L?(D.r=X.r,D.g=X.g,D.b=X.b,b(p,m,D),E.r=Math.max(0,Math.min(n.color.r*D.r,1)),E.g=Math.max(0,Math.min(n.color.g*D.g,1)),E.b=Math.max(0,Math.min(n.color.b*D.b,1)),E.updateHex()):E.hex=n.color.hex:n instanceof THREE.MeshDepthMaterial?(M=1-n.__2near/(n.__farPlusNear-
m.z*n.__farMinusNear),E.setRGB(M,M,M)):n instanceof THREE.MeshNormalMaterial&&E.setRGB(g(m.normalWorld.x),g(m.normalWorld.y),g(m.normalWorld.z));n.wireframe?R.setAttribute("style","fill: none; stroke: #"+j(E.hex.toString(16))+"; stroke-width: "+n.wireframeLinewidth+"; stroke-opacity: "+n.opacity+"; stroke-linecap: "+n.wireframeLinecap+"; stroke-linejoin: "+n.wireframeLinejoin):R.setAttribute("style","fill: #"+j(E.hex.toString(16))+"; fill-opacity: "+n.opacity);t.appendChild(R)}function e(e,c,k,m,
n,p,o){h.data.vertices+=4;h.data.faces++;R=f(T++);R.setAttribute("d","M "+e.positionScreen.x+" "+e.positionScreen.y+" L "+c.positionScreen.x+" "+c.positionScreen.y+" L "+k.positionScreen.x+","+k.positionScreen.y+" L "+m.positionScreen.x+","+m.positionScreen.y+"z");p instanceof THREE.MeshBasicMaterial?E.hex=p.color.hex:p instanceof THREE.MeshLambertMaterial?L?(D.r=X.r,D.g=X.g,D.b=X.b,b(o,n,D),E.r=Math.max(0,Math.min(p.color.r*D.r,1)),E.g=Math.max(0,Math.min(p.color.g*D.g,1)),E.b=Math.max(0,Math.min(p.color.b*
......@@ -452,10 +452,9 @@ THREE.CubicBezierCurve.prototype.getPoint=function(b){var c;c=THREE.Shape.Utils.
THREE.SplineCurve.prototype.getPoint=function(b){var c=new THREE.Vector2,e=[],f=this.points,g;g=(f.length-1)*b;b=Math.floor(g);g-=b;e[0]=b==0?b:b-1;e[1]=b;e[2]=b>f.length-2?b:b+1;e[3]=b>f.length-3?b:b+2;c.x=THREE.Curve.Utils.interpolate(f[e[0]].x,f[e[1]].x,f[e[2]].x,f[e[3]].x,g);c.y=THREE.Curve.Utils.interpolate(f[e[0]].y,f[e[1]].y,f[e[2]].y,f[e[3]].y,g);return c};THREE.ArcCurve=function(b,c,e,f,g,j){this.aX=b;this.aY=c;this.aRadius=e;this.aStartAngle=f;this.aEndAngle=g;this.aClockwise=j};
THREE.ArcCurve.prototype=new THREE.Curve;THREE.ArcCurve.prototype.constructor=THREE.ArcCurve;THREE.ArcCurve.prototype.getPoint=function(b){var c=this.aEndAngle-this.aStartAngle;this.aClockwise||(b=1-b);b=this.aStartAngle+b*c;return new THREE.Vector2(this.aX+this.aRadius*Math.cos(b),this.aY+this.aRadius*Math.sin(b))};
THREE.Curve.Utils={tangentQuadraticBezier:function(b,c,e,f){return 2*(1-b)*(e-c)+2*b*(f-e)},tangentSpline:function(){},interpolate:function(b,c,e,f,g){var b=(e-b)*0.5,f=(f-c)*0.5,j=g*g;return(2*c-2*e+b+f)*g*j+(-3*c+3*e-2*b-f)*j+b*g+c}};THREE.Curve.create=function(b,c){b.prototype=new THREE.Curve;b.prototype.constructor=b;b.prototype.getPoint=c;return b};
THREE.LineCurve3=THREE.Curve.create(function(b,c,e,f,g,j){this.x1=b;this.y1=c;this.z1=e;this.x2=f;this.y2=g;this.z2=j},function(b){return new THREE.Vector3(this.x1+(this.x2-this.x1)*b,this.y1+(this.y2-this.y1)*b,this.z1+(this.z2-this.z1)*b)});
THREE.QuadraticBezierCurve3=THREE.Curve.create(function(b,c,e,f,g,j,h,m,n){this.x0=b;this.y0=c;this.z0=e;this.x1=f;this.y1=g;this.z1=j;this.x2=h;this.y2=m;this.z2=n},function(b){var c,e;c=THREE.Shape.Utils.b2(b,this.x0,this.x1,this.x2);e=THREE.Shape.Utils.b2(b,this.y0,this.y1,this.y2);b=THREE.Shape.Utils.b2(b,this.z0,this.z1,this.z2);return new THREE.Vector2(c,e,b)});THREE.Path=function(b){this.actions=[];this.curves=[];b&&this.fromPoints(b)};
THREE.PathActions={MOVE_TO:"moveTo",LINE_TO:"lineTo",QUADRATIC_CURVE_TO:"quadraticCurveTo",BEZIER_CURVE_TO:"bezierCurveTo",CSPLINE_THRU:"splineThru",ARC:"arc"};THREE.Path.prototype.fromPoints=function(b){this.moveTo(b[0].x,b[0].y);var c,e=b.length;for(c=1;c<e;c++)this.lineTo(b[c].x,b[c].y)};THREE.Path.prototype.moveTo=function(){var b=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.MOVE_TO,args:b})};
THREE.Path.prototype.lineTo=function(b,c){var e=Array.prototype.slice.call(arguments),f=this.actions[this.actions.length-1].args,f=new THREE.LineCurve(f[f.length-2],f[f.length-1],b,c);this.curves.push(f);this.actions.push({action:THREE.PathActions.LINE_TO,args:e,curve:f})};
THREE.LineCurve3=THREE.Curve.create(function(b,c){this.v1=b;this.v2=c},function(b){var c=new THREE.Vector3;c.sub(v2,v1);c.multiplyScalar(b);c.addSelf(this.v1);return c});THREE.QuadraticBezierCurve3=THREE.Curve.create(function(b,c,e){this.v0=b;this.v1=c;this.v2=e},function(b){var c,e;c=THREE.Shape.Utils.b2(b,this.v0.x,this.v1.x,this.v2.x);e=THREE.Shape.Utils.b2(b,this.v0.y,this.v1.y,this.v2.y);b=THREE.Shape.Utils.b2(b,this.v0.z,this.v1.z,this.v2.z);return new THREE.Vector3(c,e,b)});
THREE.Path=function(b){this.actions=[];this.curves=[];b&&this.fromPoints(b)};THREE.PathActions={MOVE_TO:"moveTo",LINE_TO:"lineTo",QUADRATIC_CURVE_TO:"quadraticCurveTo",BEZIER_CURVE_TO:"bezierCurveTo",CSPLINE_THRU:"splineThru",ARC:"arc"};THREE.Path.prototype.fromPoints=function(b){this.moveTo(b[0].x,b[0].y);var c,e=b.length;for(c=1;c<e;c++)this.lineTo(b[c].x,b[c].y)};
THREE.Path.prototype.moveTo=function(){var b=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.MOVE_TO,args:b})};THREE.Path.prototype.lineTo=function(b,c){var e=Array.prototype.slice.call(arguments),f=this.actions[this.actions.length-1].args,f=new THREE.LineCurve(f[f.length-2],f[f.length-1],b,c);this.curves.push(f);this.actions.push({action:THREE.PathActions.LINE_TO,args:e,curve:f})};
THREE.Path.prototype.quadraticCurveTo=function(b,c,e,f){var g=Array.prototype.slice.call(arguments),j=this.actions[this.actions.length-1].args,j=new THREE.QuadraticBezierCurve(j[j.length-2],j[j.length-1],b,c,e,f);this.curves.push(j);this.actions.push({action:THREE.PathActions.QUADRATIC_CURVE_TO,args:g,curve:j})};
THREE.Path.prototype.bezierCurveTo=function(b,c,e,f,g,j){var h=Array.prototype.slice.call(arguments),m=this.actions[this.actions.length-1].args,m=new THREE.CubicBezierCurve(m[m.length-2],m[m.length-1],b,c,e,f,g,j);this.curves.push(m);this.actions.push({action:THREE.PathActions.BEZIER_CURVE_TO,args:h,curve:m})};
THREE.Path.prototype.splineThru=function(b){var c=Array.prototype.slice.call(arguments),e=this.actions[this.actions.length-1].args,e=[new THREE.Vector2(e[e.length-2],e[e.length-1])],e=e.concat(b),e=new THREE.SplineCurve(e);this.curves.push(e);this.actions.push({action:THREE.PathActions.CSPLINE_THRU,args:c,curve:e})};
......
......@@ -94,10 +94,9 @@ THREE.CubicBezierCurve.prototype.getPoint=function(a){var b;b=THREE.Shape.Utils.
THREE.SplineCurve.prototype.getPoint=function(a){var b=new THREE.Vector2,c=[],e=this.points,f;f=(e.length-1)*a;a=Math.floor(f);f-=a;c[0]=a==0?a:a-1;c[1]=a;c[2]=a>e.length-2?a:a+1;c[3]=a>e.length-3?a:a+2;b.x=THREE.Curve.Utils.interpolate(e[c[0]].x,e[c[1]].x,e[c[2]].x,e[c[3]].x,f);b.y=THREE.Curve.Utils.interpolate(e[c[0]].y,e[c[1]].y,e[c[2]].y,e[c[3]].y,f);return b};THREE.ArcCurve=function(a,b,c,e,f,h){this.aX=a;this.aY=b;this.aRadius=c;this.aStartAngle=e;this.aEndAngle=f;this.aClockwise=h};
THREE.ArcCurve.prototype=new THREE.Curve;THREE.ArcCurve.prototype.constructor=THREE.ArcCurve;THREE.ArcCurve.prototype.getPoint=function(a){var b=this.aEndAngle-this.aStartAngle;this.aClockwise||(a=1-a);a=this.aStartAngle+a*b;return new THREE.Vector2(this.aX+this.aRadius*Math.cos(a),this.aY+this.aRadius*Math.sin(a))};
THREE.Curve.Utils={tangentQuadraticBezier:function(a,b,c,e){return 2*(1-a)*(c-b)+2*a*(e-c)},tangentSpline:function(){},interpolate:function(a,b,c,e,f){var a=(c-a)*0.5,e=(e-b)*0.5,h=f*f;return(2*b-2*c+a+e)*f*h+(-3*b+3*c-2*a-e)*h+a*f+b}};THREE.Curve.create=function(a,b){a.prototype=new THREE.Curve;a.prototype.constructor=a;a.prototype.getPoint=b;return a};
THREE.LineCurve3=THREE.Curve.create(function(a,b,c,e,f,h){this.x1=a;this.y1=b;this.z1=c;this.x2=e;this.y2=f;this.z2=h},function(a){return new THREE.Vector3(this.x1+(this.x2-this.x1)*a,this.y1+(this.y2-this.y1)*a,this.z1+(this.z2-this.z1)*a)});
THREE.QuadraticBezierCurve3=THREE.Curve.create(function(a,b,c,e,f,h,g,j,k){this.x0=a;this.y0=b;this.z0=c;this.x1=e;this.y1=f;this.z1=h;this.x2=g;this.y2=j;this.z2=k},function(a){var b,c;b=THREE.Shape.Utils.b2(a,this.x0,this.x1,this.x2);c=THREE.Shape.Utils.b2(a,this.y0,this.y1,this.y2);a=THREE.Shape.Utils.b2(a,this.z0,this.z1,this.z2);return new THREE.Vector2(b,c,a)});THREE.Path=function(a){this.actions=[];this.curves=[];a&&this.fromPoints(a)};
THREE.PathActions={MOVE_TO:"moveTo",LINE_TO:"lineTo",QUADRATIC_CURVE_TO:"quadraticCurveTo",BEZIER_CURVE_TO:"bezierCurveTo",CSPLINE_THRU:"splineThru",ARC:"arc"};THREE.Path.prototype.fromPoints=function(a){this.moveTo(a[0].x,a[0].y);var b,c=a.length;for(b=1;b<c;b++)this.lineTo(a[b].x,a[b].y)};THREE.Path.prototype.moveTo=function(){var a=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.MOVE_TO,args:a})};
THREE.Path.prototype.lineTo=function(a,b){var c=Array.prototype.slice.call(arguments),e=this.actions[this.actions.length-1].args,e=new THREE.LineCurve(e[e.length-2],e[e.length-1],a,b);this.curves.push(e);this.actions.push({action:THREE.PathActions.LINE_TO,args:c,curve:e})};
THREE.LineCurve3=THREE.Curve.create(function(a,b){this.v1=a;this.v2=b},function(a){var b=new THREE.Vector3;b.sub(v2,v1);b.multiplyScalar(a);b.addSelf(this.v1);return b});THREE.QuadraticBezierCurve3=THREE.Curve.create(function(a,b,c){this.v0=a;this.v1=b;this.v2=c},function(a){var b,c;b=THREE.Shape.Utils.b2(a,this.v0.x,this.v1.x,this.v2.x);c=THREE.Shape.Utils.b2(a,this.v0.y,this.v1.y,this.v2.y);a=THREE.Shape.Utils.b2(a,this.v0.z,this.v1.z,this.v2.z);return new THREE.Vector3(b,c,a)});
THREE.Path=function(a){this.actions=[];this.curves=[];a&&this.fromPoints(a)};THREE.PathActions={MOVE_TO:"moveTo",LINE_TO:"lineTo",QUADRATIC_CURVE_TO:"quadraticCurveTo",BEZIER_CURVE_TO:"bezierCurveTo",CSPLINE_THRU:"splineThru",ARC:"arc"};THREE.Path.prototype.fromPoints=function(a){this.moveTo(a[0].x,a[0].y);var b,c=a.length;for(b=1;b<c;b++)this.lineTo(a[b].x,a[b].y)};
THREE.Path.prototype.moveTo=function(){var a=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.MOVE_TO,args:a})};THREE.Path.prototype.lineTo=function(a,b){var c=Array.prototype.slice.call(arguments),e=this.actions[this.actions.length-1].args,e=new THREE.LineCurve(e[e.length-2],e[e.length-1],a,b);this.curves.push(e);this.actions.push({action:THREE.PathActions.LINE_TO,args:c,curve:e})};
THREE.Path.prototype.quadraticCurveTo=function(a,b,c,e){var f=Array.prototype.slice.call(arguments),h=this.actions[this.actions.length-1].args,h=new THREE.QuadraticBezierCurve(h[h.length-2],h[h.length-1],a,b,c,e);this.curves.push(h);this.actions.push({action:THREE.PathActions.QUADRATIC_CURVE_TO,args:f,curve:h})};
THREE.Path.prototype.bezierCurveTo=function(a,b,c,e,f,h){var g=Array.prototype.slice.call(arguments),j=this.actions[this.actions.length-1].args,j=new THREE.CubicBezierCurve(j[j.length-2],j[j.length-1],a,b,c,e,f,h);this.curves.push(j);this.actions.push({action:THREE.PathActions.BEZIER_CURVE_TO,args:g,curve:j})};
THREE.Path.prototype.splineThru=function(a){var b=Array.prototype.slice.call(arguments),c=this.actions[this.actions.length-1].args,c=[new THREE.Vector2(c[c.length-2],c[c.length-1])],c=c.concat(a),c=new THREE.SplineCurve(c);this.curves.push(c);this.actions.push({action:THREE.PathActions.CSPLINE_THRU,args:b,curve:c})};
......
......@@ -392,8 +392,6 @@ THREE.Curve.Utils = {
};
/*
getPoint DONE
getLength DONE
......@@ -409,52 +407,48 @@ curve.getTangentAt(t)
* 3D Curves
**************************************************************/
// A Factory method for creating new curve subclasses
THREE.Curve.create = function( constructor, getPointFunc ) {
// A Factory Method for creating new curve subclasses
THREE.Curve.create = function(constructor, getpointfunc) {
var subClass = constructor;
subClass.prototype = new THREE.Curve();
subClass.prototype.constructor = constructor;
subClass.prototype.getPoint = getpointfunc;
return subClass;
};
subClass.prototype = new THREE.Curve();
subClass.prototype.constructor = constructor;
subClass.prototype.getPoint = getPointFunc;
return subClass;
};
/**************************************************************
* Line3D
**************************************************************/
THREE.LineCurve3 = THREE.Curve.create(
function ( x1, y1, z1, x2, y2, z2 ) {
this.x1 = x1;
this.y1 = y1;
this.z1 = z1;
function ( v1, v2 ) {
this.x2 = x2;
this.y2 = y2;
this.z2 = z2;
this.v1 = v1;
this.v2 = v2;
},
function ( t ) {
var dx = this.x2 - this.x1;
var dy = this.y2 - this.y1;
var dz = this.z2 - this.z1;
var tx = this.x1 + dx * t;
var ty = this.y1 + dy * t;
var tz = this.z1 + dz * t;
var r = new THREE.Vector3();
return new THREE.Vector3( tx, ty, tz );
r.sub( v2, v1 ); // diff
r.multiplyScalar( t );
r.addSelf( this.v1 );
return r;
}
);
......@@ -463,33 +457,25 @@ THREE.LineCurve3 = THREE.Curve.create(
**************************************************************/
THREE.QuadraticBezierCurve3 = THREE.Curve.create(
function ( x0, y0, z0,
x1, y1, z1,
x2, y2, z2 ) { // Qn should we use 2 Vector3 instead?
this.x0 = x0;
this.y0 = y0;
this.z0 = z0;
function ( v0, v1, v2 ) { // Qn should we use 2 Vector3 instead?
this.x1 = x1;
this.y1 = y1;
this.z1 = z1;
this.x2 = x2;
this.y2 = y2;
this.z2 = z2;
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
},
function ( t ) {
var tx, ty, tz;
tx = THREE.Shape.Utils.b2( t, this.x0, this.x1, this.x2 );
ty = THREE.Shape.Utils.b2( t, this.y0, this.y1, this.y2 );
tz = THREE.Shape.Utils.b2( t, this.z0, this.z1, this.z2 );
tx = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
ty = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
tz = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
return new THREE.Vector2( tx, ty, tz );
return new THREE.Vector3( tx, ty, tz );
}
);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册