ThreeExtras.js 145.7 KB
Newer Older
M
Mr.doob 已提交
1
// ThreeExtras.js - http://github.com/mrdoob/three.js
2
'use strict';THREE.ColorUtils={adjustHSV:function(b,a,c,d){var e=THREE.ColorUtils.__hsv;THREE.ColorUtils.rgbToHsv(b,e);e.h=THREE.Math.clamp(e.h+a,0,1);e.s=THREE.Math.clamp(e.s+c,0,1);e.v=THREE.Math.clamp(e.v+d,0,1);b.setHSV(e.h,e.s,e.v)},rgbToHsv:function(b,a){var c=b.r,d=b.g,e=b.b,f=Math.max(Math.max(c,d),e),g=Math.min(Math.min(c,d),e);if(g===f)g=c=0;else{var h=f-g,g=h/f,c=(c===f?(d-e)/h:d===f?2+(e-c)/h:4+(c-d)/h)/6;0>c&&(c+=1);1<c&&(c-=1)}void 0===a&&(a={h:0,s:0,v:0});a.h=c;a.s=g;a.v=f;return a}};
A
alteredq 已提交
3
THREE.ColorUtils.__hsv={h:0,s:0,v:0};
4 5 6
THREE.GeometryUtils={merge:function(b,a){for(var c,d,e=b.vertices.length,f=a instanceof THREE.Mesh?a.geometry:a,g=b.vertices,h=f.vertices,i=b.faces,j=f.faces,l=b.faceVertexUvs[0],m=f.faceVertexUvs[0],n={},k=0;k<b.materials.length;k++)n[b.materials[k].id]=k;a instanceof THREE.Mesh&&(a.matrixAutoUpdate&&a.updateMatrix(),c=a.matrix,d=new THREE.Matrix4,d.extractRotation(c,a.scale));for(var k=0,o=h.length;k<o;k++){var q=h[k].clone();c&&c.multiplyVector3(q);g.push(q)}k=0;for(o=j.length;k<o;k++){var g=j[k],
p,s,u=g.vertexNormals,t=g.vertexColors;g instanceof THREE.Face3?p=new THREE.Face3(g.a+e,g.b+e,g.c+e):g instanceof THREE.Face4&&(p=new THREE.Face4(g.a+e,g.b+e,g.c+e,g.d+e));p.normal.copy(g.normal);d&&d.multiplyVector3(p.normal);h=0;for(q=u.length;h<q;h++)s=u[h].clone(),d&&d.multiplyVector3(s),p.vertexNormals.push(s);p.color.copy(g.color);h=0;for(q=t.length;h<q;h++)s=t[h],p.vertexColors.push(s.clone());void 0!==g.materialIndex&&(h=f.materials[g.materialIndex],q=h.id,t=n[q],void 0===t&&(t=b.materials.length,
n[q]=t,b.materials.push(h)),p.materialIndex=t);p.centroid.copy(g.centroid);c&&c.multiplyVector3(p.centroid);i.push(p)}k=0;for(o=m.length;k<o;k++){c=m[k];d=[];h=0;for(q=c.length;h<q;h++)d.push(new THREE.UV(c[h].u,c[h].v));l.push(d)}},clone:function(b){var a=new THREE.Geometry,c,d=b.vertices,e=b.faces,f=b.faceVertexUvs[0];b.materials&&(a.materials=b.materials.slice());b=0;for(c=d.length;b<c;b++)a.vertices.push(d[b].clone());b=0;for(c=e.length;b<c;b++)a.faces.push(e[b].clone());b=0;for(c=f.length;b<
7 8
c;b++){for(var d=f[b],e=[],g=0,h=d.length;g<h;g++)e.push(new THREE.UV(d[g].u,d[g].v));a.faceVertexUvs[0].push(e)}return a},randomPointInTriangle:function(b,a,c){var d,e,f,g=new THREE.Vector3,h=THREE.GeometryUtils.__v1;d=THREE.GeometryUtils.random();e=THREE.GeometryUtils.random();1<d+e&&(d=1-d,e=1-e);f=1-d-e;g.copy(b);g.multiplyScalar(d);h.copy(a);h.multiplyScalar(e);g.addSelf(h);h.copy(c);h.multiplyScalar(f);g.addSelf(h);return g},randomPointInFace:function(b,a,c){var d,e,f;if(b instanceof THREE.Face3)return d=
a.vertices[b.a],e=a.vertices[b.b],f=a.vertices[b.c],THREE.GeometryUtils.randomPointInTriangle(d,e,f);if(b instanceof THREE.Face4){d=a.vertices[b.a];e=a.vertices[b.b];f=a.vertices[b.c];var a=a.vertices[b.d],g;c?b._area1&&b._area2?(c=b._area1,g=b._area2):(c=THREE.GeometryUtils.triangleArea(d,e,a),g=THREE.GeometryUtils.triangleArea(e,f,a),b._area1=c,b._area2=g):(c=THREE.GeometryUtils.triangleArea(d,e,a),g=THREE.GeometryUtils.triangleArea(e,f,a));return THREE.GeometryUtils.random()*(c+g)<c?THREE.GeometryUtils.randomPointInTriangle(d,
9 10
e,a):THREE.GeometryUtils.randomPointInTriangle(e,f,a)}},randomPointsInGeometry:function(b,a){function c(a){function b(c,d){if(d<c)return c;var e=c+Math.floor((d-c)/2);return j[e]>a?b(c,e-1):j[e]<a?b(e+1,d):e}return b(0,j.length-1)}var d,e,f=b.faces,g=b.vertices,h=f.length,i=0,j=[],l,m,n,k;for(e=0;e<h;e++)d=f[e],d instanceof THREE.Face3?(l=g[d.a],m=g[d.b],n=g[d.c],d._area=THREE.GeometryUtils.triangleArea(l,m,n)):d instanceof THREE.Face4&&(l=g[d.a],m=g[d.b],n=g[d.c],k=g[d.d],d._area1=THREE.GeometryUtils.triangleArea(l,
m,k),d._area2=THREE.GeometryUtils.triangleArea(m,n,k),d._area=d._area1+d._area2),i+=d._area,j[e]=i;d=[];for(e=0;e<a;e++)g=THREE.GeometryUtils.random()*i,g=c(g),d[e]=THREE.GeometryUtils.randomPointInFace(f[g],b,!0);return d},triangleArea:function(b,a,c){var d,e=THREE.GeometryUtils.__v1;e.sub(b,a);d=e.length();e.sub(b,c);b=e.length();e.sub(a,c);c=e.length();a=0.5*(d+b+c);return Math.sqrt(a*(a-d)*(a-b)*(a-c))},center:function(b){b.computeBoundingBox();var a=b.boundingBox,c=new THREE.Vector3;c.add(a.min,
11
a.max);c.multiplyScalar(-0.5);b.applyMatrix((new THREE.Matrix4).makeTranslation(c.x,c.y,c.z));b.computeBoundingBox();return c},normalizeUVs:function(b){for(var b=b.faceVertexUvs[0],a=0,c=b.length;a<c;a++)for(var d=b[a],e=0,f=d.length;e<f;e++)if(1!==d[e].u&&(d[e].u-=Math.floor(d[e].u)),1!==d[e].v)d[e].v-=Math.floor(d[e].v)},triangulateQuads:function(b){var a,c,d,e,f=[],g=[],h=[];a=0;for(c=b.faceUvs.length;a<c;a++)g[a]=[];a=0;for(c=b.faceVertexUvs.length;a<c;a++)h[a]=[];a=0;for(c=b.faces.length;a<c;a++)if(d=
12 13
b.faces[a],d instanceof THREE.Face4){e=d.a;var i=d.b,j=d.c,l=d.d,m=new THREE.Face3,n=new THREE.Face3;m.color.copy(d.color);n.color.copy(d.color);m.materialIndex=d.materialIndex;n.materialIndex=d.materialIndex;m.a=e;m.b=i;m.c=l;n.a=i;n.b=j;n.c=l;4===d.vertexColors.length&&(m.vertexColors[0]=d.vertexColors[0].clone(),m.vertexColors[1]=d.vertexColors[1].clone(),m.vertexColors[2]=d.vertexColors[3].clone(),n.vertexColors[0]=d.vertexColors[1].clone(),n.vertexColors[1]=d.vertexColors[2].clone(),n.vertexColors[2]=
d.vertexColors[3].clone());f.push(m,n);d=0;for(e=b.faceVertexUvs.length;d<e;d++)b.faceVertexUvs[d].length&&(m=b.faceVertexUvs[d][a],i=m[1],j=m[2],l=m[3],m=[m[0].clone(),i.clone(),l.clone()],i=[i.clone(),j.clone(),l.clone()],h[d].push(m,i));d=0;for(e=b.faceUvs.length;d<e;d++)b.faceUvs[d].length&&(i=b.faceUvs[d][a],g[d].push(i,i))}else{f.push(d);d=0;for(e=b.faceUvs.length;d<e;d++)g[d].push(b.faceUvs[d]);d=0;for(e=b.faceVertexUvs.length;d<e;d++)h[d].push(b.faceVertexUvs[d])}b.faces=f;b.faceUvs=g;b.faceVertexUvs=
14
h;b.computeCentroids();b.computeFaceNormals();b.computeVertexNormals();b.hasTangents&&b.computeTangents()},explode:function(b){for(var a=[],c=0,d=b.faces.length;c<d;c++){var e=a.length,f=b.faces[c];if(f instanceof THREE.Face4){var g=f.a,h=f.b,i=f.c,g=b.vertices[g],h=b.vertices[h],i=b.vertices[i],j=b.vertices[f.d];a.push(g.clone());a.push(h.clone());a.push(i.clone());a.push(j.clone());f.a=e;f.b=e+1;f.c=e+2;f.d=e+3}else g=f.a,h=f.b,i=f.c,g=b.vertices[g],h=b.vertices[h],i=b.vertices[i],a.push(g.clone()),
15 16 17 18 19 20 21 22 23
a.push(h.clone()),a.push(i.clone()),f.a=e,f.b=e+1,f.c=e+2}b.vertices=a;delete b.__tmpVertices},tessellate:function(b,a){var c,d,e,f,g,h,i,j,l,m,n,k,o,q,p,s,u,t,r,v=[],z=[];c=0;for(d=b.faceVertexUvs.length;c<d;c++)z[c]=[];c=0;for(d=b.faces.length;c<d;c++)if(e=b.faces[c],e instanceof THREE.Face3)if(f=e.a,g=e.b,h=e.c,j=b.vertices[f],l=b.vertices[g],m=b.vertices[h],k=j.distanceTo(l),o=l.distanceTo(m),n=j.distanceTo(m),k>a||o>a||n>a){i=b.vertices.length;t=e.clone();r=e.clone();k>=o&&k>=n?(j=j.clone(),
j.lerpSelf(l,0.5),t.a=f,t.b=i,t.c=h,r.a=i,r.b=g,r.c=h,3===e.vertexNormals.length&&(f=e.vertexNormals[0].clone(),f.lerpSelf(e.vertexNormals[1],0.5),t.vertexNormals[1].copy(f),r.vertexNormals[0].copy(f)),3===e.vertexColors.length&&(f=e.vertexColors[0].clone(),f.lerpSelf(e.vertexColors[1],0.5),t.vertexColors[1].copy(f),r.vertexColors[0].copy(f)),e=0):o>=k&&o>=n?(j=l.clone(),j.lerpSelf(m,0.5),t.a=f,t.b=g,t.c=i,r.a=i,r.b=h,r.c=f,3===e.vertexNormals.length&&(f=e.vertexNormals[1].clone(),f.lerpSelf(e.vertexNormals[2],
0.5),t.vertexNormals[2].copy(f),r.vertexNormals[0].copy(f),r.vertexNormals[1].copy(e.vertexNormals[2]),r.vertexNormals[2].copy(e.vertexNormals[0])),3===e.vertexColors.length&&(f=e.vertexColors[1].clone(),f.lerpSelf(e.vertexColors[2],0.5),t.vertexColors[2].copy(f),r.vertexColors[0].copy(f),r.vertexColors[1].copy(e.vertexColors[2]),r.vertexColors[2].copy(e.vertexColors[0])),e=1):(j=j.clone(),j.lerpSelf(m,0.5),t.a=f,t.b=g,t.c=i,r.a=i,r.b=g,r.c=h,3===e.vertexNormals.length&&(f=e.vertexNormals[0].clone(),
f.lerpSelf(e.vertexNormals[2],0.5),t.vertexNormals[2].copy(f),r.vertexNormals[0].copy(f)),3===e.vertexColors.length&&(f=e.vertexColors[0].clone(),f.lerpSelf(e.vertexColors[2],0.5),t.vertexColors[2].copy(f),r.vertexColors[0].copy(f)),e=2);v.push(t,r);b.vertices.push(j);f=0;for(g=b.faceVertexUvs.length;f<g;f++)b.faceVertexUvs[f].length&&(j=b.faceVertexUvs[f][c],r=j[0],h=j[1],t=j[2],0===e?(l=r.clone(),l.lerpSelf(h,0.5),j=[r.clone(),l.clone(),t.clone()],h=[l.clone(),h.clone(),t.clone()]):1===e?(l=h.clone(),
l.lerpSelf(t,0.5),j=[r.clone(),h.clone(),l.clone()],h=[l.clone(),t.clone(),r.clone()]):(l=r.clone(),l.lerpSelf(t,0.5),j=[r.clone(),h.clone(),l.clone()],h=[l.clone(),h.clone(),t.clone()]),z[f].push(j,h))}else{v.push(e);f=0;for(g=b.faceVertexUvs.length;f<g;f++)z[f].push(b.faceVertexUvs[f][c])}else if(f=e.a,g=e.b,h=e.c,i=e.d,j=b.vertices[f],l=b.vertices[g],m=b.vertices[h],n=b.vertices[i],k=j.distanceTo(l),o=l.distanceTo(m),q=m.distanceTo(n),p=j.distanceTo(n),k>a||o>a||q>a||p>a){s=b.vertices.length;u=
b.vertices.length+1;t=e.clone();r=e.clone();k>=o&&k>=q&&k>=p||q>=o&&q>=k&&q>=p?(k=j.clone(),k.lerpSelf(l,0.5),l=m.clone(),l.lerpSelf(n,0.5),t.a=f,t.b=s,t.c=u,t.d=i,r.a=s,r.b=g,r.c=h,r.d=u,4===e.vertexNormals.length&&(f=e.vertexNormals[0].clone(),f.lerpSelf(e.vertexNormals[1],0.5),g=e.vertexNormals[2].clone(),g.lerpSelf(e.vertexNormals[3],0.5),t.vertexNormals[1].copy(f),t.vertexNormals[2].copy(g),r.vertexNormals[0].copy(f),r.vertexNormals[3].copy(g)),4===e.vertexColors.length&&(f=e.vertexColors[0].clone(),
f.lerpSelf(e.vertexColors[1],0.5),g=e.vertexColors[2].clone(),g.lerpSelf(e.vertexColors[3],0.5),t.vertexColors[1].copy(f),t.vertexColors[2].copy(g),r.vertexColors[0].copy(f),r.vertexColors[3].copy(g)),e=0):(k=l.clone(),k.lerpSelf(m,0.5),l=n.clone(),l.lerpSelf(j,0.5),t.a=f,t.b=g,t.c=s,t.d=u,r.a=u,r.b=s,r.c=h,r.d=i,4===e.vertexNormals.length&&(f=e.vertexNormals[1].clone(),f.lerpSelf(e.vertexNormals[2],0.5),g=e.vertexNormals[3].clone(),g.lerpSelf(e.vertexNormals[0],0.5),t.vertexNormals[2].copy(f),t.vertexNormals[3].copy(g),
r.vertexNormals[0].copy(g),r.vertexNormals[1].copy(f)),4===e.vertexColors.length&&(f=e.vertexColors[1].clone(),f.lerpSelf(e.vertexColors[2],0.5),g=e.vertexColors[3].clone(),g.lerpSelf(e.vertexColors[0],0.5),t.vertexColors[2].copy(f),t.vertexColors[3].copy(g),r.vertexColors[0].copy(g),r.vertexColors[1].copy(f)),e=1);v.push(t,r);b.vertices.push(k,l);f=0;for(g=b.faceVertexUvs.length;f<g;f++)b.faceVertexUvs[f].length&&(j=b.faceVertexUvs[f][c],r=j[0],h=j[1],t=j[2],j=j[3],0===e?(l=r.clone(),l.lerpSelf(h,
0.5),m=t.clone(),m.lerpSelf(j,0.5),r=[r.clone(),l.clone(),m.clone(),j.clone()],h=[l.clone(),h.clone(),t.clone(),m.clone()]):(l=h.clone(),l.lerpSelf(t,0.5),m=j.clone(),m.lerpSelf(r,0.5),r=[r.clone(),h.clone(),l.clone(),m.clone()],h=[m.clone(),l.clone(),t.clone(),j.clone()]),z[f].push(r,h))}else{v.push(e);f=0;for(g=b.faceVertexUvs.length;f<g;f++)z[f].push(b.faceVertexUvs[f][c])}b.faces=v;b.faceVertexUvs=z}};THREE.GeometryUtils.random=THREE.Math.random16;THREE.GeometryUtils.__v1=new THREE.Vector3;
24
THREE.ImageUtils={crossOrigin:"anonymous",loadTexture:function(b,a,c,d){var e=new THREE.Texture(void 0,a),a=new THREE.ImageLoader;a.addEventListener("load",function(a){e.image=a.content;e.needsUpdate=!0;c&&c(e)});a.addEventListener("error",function(a){d&&d(a.message)});a.crossOrigin=this.crossOrigin;a.load(b);return e},loadTextureCube:function(b,a,c){var d,e=[],f=new THREE.Texture(e,a);f.flipY=!1;a=e.loadCount=0;for(d=b.length;a<d;++a)e[a]=new Image,e[a].onload=function(){e.loadCount+=1;6===e.loadCount&&
25 26 27
(f.needsUpdate=!0,c&&c())},e[a].crossOrigin=this.crossOrigin,e[a].src=b[a];return f},getNormalMap:function(b,a){var c=function(a){var b=Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);return[a[0]/b,a[1]/b,a[2]/b]},a=a|1,d=b.width,e=b.height,f=document.createElement("canvas");f.width=d;f.height=e;var g=f.getContext("2d");g.drawImage(b,0,0);for(var h=g.getImageData(0,0,d,e).data,i=g.createImageData(d,e),j=i.data,l=0;l<d;l++)for(var m=0;m<e;m++){var n=0>m-1?0:m-1,k=m+1>e-1?e-1:m+1,o=0>l-1?0:l-1,q=l+1>d-1?d-
1:l+1,p=[],s=[0,0,h[4*(m*d+l)]/255*a];p.push([-1,0,h[4*(m*d+o)]/255*a]);p.push([-1,-1,h[4*(n*d+o)]/255*a]);p.push([0,-1,h[4*(n*d+l)]/255*a]);p.push([1,-1,h[4*(n*d+q)]/255*a]);p.push([1,0,h[4*(m*d+q)]/255*a]);p.push([1,1,h[4*(k*d+q)]/255*a]);p.push([0,1,h[4*(k*d+l)]/255*a]);p.push([-1,1,h[4*(k*d+o)]/255*a]);n=[];o=p.length;for(k=0;k<o;k++){var q=p[k],u=p[(k+1)%o],q=[q[0]-s[0],q[1]-s[1],q[2]-s[2]],u=[u[0]-s[0],u[1]-s[1],u[2]-s[2]];n.push(c([q[1]*u[2]-q[2]*u[1],q[2]*u[0]-q[0]*u[2],q[0]*u[1]-q[1]*u[0]]))}p=
[0,0,0];for(k=0;k<n.length;k++)p[0]+=n[k][0],p[1]+=n[k][1],p[2]+=n[k][2];p[0]/=n.length;p[1]/=n.length;p[2]/=n.length;s=4*(m*d+l);j[s]=255*((p[0]+1)/2)|0;j[s+1]=255*((p[1]+1)/2)|0;j[s+2]=255*p[2]|0;j[s+3]=255}g.putImageData(i,0,0);return f},generateDataTexture:function(b,a,c){for(var d=b*a,e=new Uint8Array(3*d),f=Math.floor(255*c.r),g=Math.floor(255*c.g),c=Math.floor(255*c.b),h=0;h<d;h++)e[3*h]=f,e[3*h+1]=g,e[3*h+2]=c;b=new THREE.DataTexture(e,b,a,THREE.RGBFormat);b.needsUpdate=!0;return b}};
28 29 30
THREE.SceneUtils={showHierarchy:function(b,a){THREE.SceneUtils.traverseHierarchy(b,function(b){b.visible=a})},traverseHierarchy:function(b,a){var c,d,e=b.children.length;for(d=0;d<e;d++)c=b.children[d],a(c),THREE.SceneUtils.traverseHierarchy(c,a)},createMultiMaterialObject:function(b,a){var c,d=a.length,e=new THREE.Object3D;for(c=0;c<d;c++){var f=new THREE.Mesh(b,a[c]);e.add(f)}return e},cloneObject:function(b){var a;b instanceof THREE.MorphAnimMesh?(a=new THREE.MorphAnimMesh(b.geometry,b.material),
a.duration=b.duration,a.mirroredLoop=b.mirroredLoop,a.time=b.time,a.lastKeyframe=b.lastKeyframe,a.currentKeyframe=b.currentKeyframe,a.direction=b.direction,a.directionBackwards=b.directionBackwards):b instanceof THREE.SkinnedMesh?a=new THREE.SkinnedMesh(b.geometry,b.material):b instanceof THREE.Mesh?a=new THREE.Mesh(b.geometry,b.material):b instanceof THREE.Line?a=new THREE.Line(b.geometry,b.material,b.type):b instanceof THREE.Ribbon?a=new THREE.Ribbon(b.geometry,b.material):b instanceof THREE.ParticleSystem?
(a=new THREE.ParticleSystem(b.geometry,b.material),a.sortParticles=b.sortParticles):b instanceof THREE.Particle?a=new THREE.Particle(b.material):b instanceof THREE.Sprite?(a=new THREE.Sprite({}),a.color.copy(b.color),a.map=b.map,a.blending=b.blending,a.useScreenCoordinates=b.useScreenCoordinates,a.mergeWith3D=b.mergeWith3D,a.affectedByDistance=b.affectedByDistance,a.scaleByViewport=b.scaleByViewport,a.alignment=b.alignment,a.rotation3d.copy(b.rotation3d),a.rotation=b.rotation,a.opacity=b.opacity,
M
Mr.doob 已提交
31 32 33
a.uvOffset.copy(b.uvOffset),a.uvScale.copy(b.uvScale)):b instanceof THREE.LOD?a=new THREE.LOD:b instanceof THREE.Object3D&&(a=new THREE.Object3D);a.name=b.name;a.parent=b.parent;a.up.copy(b.up);a.position.copy(b.position);a.rotation instanceof THREE.Vector3&&a.rotation.copy(b.rotation);a.eulerOrder=b.eulerOrder;a.scale.copy(b.scale);a.dynamic=b.dynamic;a.doubleSided=b.doubleSided;a.flipSided=b.flipSided;a.renderDepth=b.renderDepth;a.rotationAutoUpdate=b.rotationAutoUpdate;a.matrix.copy(b.matrix);
a.matrixWorld.copy(b.matrixWorld);a.matrixRotationWorld.copy(b.matrixRotationWorld);a.matrixAutoUpdate=b.matrixAutoUpdate;a.matrixWorldNeedsUpdate=b.matrixWorldNeedsUpdate;a.quaternion.copy(b.quaternion);a.useQuaternion=b.useQuaternion;a.boundRadius=b.boundRadius;a.boundRadiusScale=b.boundRadiusScale;a.visible=b.visible;a.castShadow=b.castShadow;a.receiveShadow=b.receiveShadow;a.frustumCulled=b.frustumCulled;for(var c=0;c<b.children.length;c++){var d=THREE.SceneUtils.cloneObject(b.children[c]);a.children[c]=
d;d.parent=a}if(b instanceof THREE.LOD)for(c=0;c<b.LODs.length;c++)a.LODs[c]={visibleAtDistance:b.LODs[c].visibleAtDistance,object3D:a.children[c]};return a},detach:function(b,a,c){b.applyMatrix(a.matrixWorld);a.remove(b);c.add(b)},attach:function(b,a,c){var d=new THREE.Matrix4;d.getInverse(c.matrixWorld);b.applyMatrix(d);a.remove(b);c.add(b)}};
34
THREE.WebGLRenderer&&(THREE.ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragmentShader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
A
alteredq 已提交
35
vertexShader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"},
36 37 38 39 40
normal:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},enableSpecular:{type:"i",value:0},enableReflection:{type:"i",value:0},enableDisplacement:{type:"i",value:0},tDiffuse:{type:"t",value:0,texture:null},tCube:{type:"t",value:1,texture:null},tNormal:{type:"t",value:2,texture:null},tSpecular:{type:"t",value:3,texture:null},tAO:{type:"t",value:4,texture:null},tDisplacement:{type:"t",
value:5,texture:null},uNormalScale:{type:"f",value:1},uDisplacementBias:{type:"f",value:0},uDisplacementScale:{type:"f",value:1},uDiffuseColor:{type:"c",value:new THREE.Color(16777215)},uSpecularColor:{type:"c",value:new THREE.Color(1118481)},uAmbientColor:{type:"c",value:new THREE.Color(16777215)},uShininess:{type:"f",value:30},uOpacity:{type:"f",value:1},uReflectivity:{type:"f",value:0.5},uOffset:{type:"v2",value:new THREE.Vector2(0,0)},uRepeat:{type:"v2",value:new THREE.Vector2(1,1)},wrapRGB:{type:"v3",
value:new THREE.Vector3(1,1,1)}}]),fragmentShader:["uniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform float uOpacity;\nuniform bool enableDiffuse;\nuniform bool enableSpecular;\nuniform bool enableAO;\nuniform bool enableReflection;\nuniform sampler2D tDiffuse;\nuniform sampler2D tNormal;\nuniform sampler2D tSpecular;\nuniform sampler2D tAO;\nuniform samplerCube tCube;\nuniform float uNormalScale;\nuniform float uReflectivity;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nuniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif\n#if MAX_POINT_LIGHTS > 0\nuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n#endif\n#if MAX_SPOT_LIGHTS > 0\nuniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\nuniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\nuniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\nuniform float spotLightAngle[ MAX_SPOT_LIGHTS ];\nuniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\nuniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n#endif\n#ifdef WRAP_AROUND\nuniform vec3 wrapRGB;\n#endif\nvarying vec3 vWorldPosition;",
THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,"void main() {\nvec3 vViewPosition = cameraPosition - vWorldPosition;\ngl_FragColor = vec4( vec3( 1.0 ), uOpacity );\nvec3 specularTex = vec3( 1.0 );\nvec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;\nnormalTex.xy *= uNormalScale;\nnormalTex = normalize( normalTex );\nif( enableDiffuse ) {\n#ifdef GAMMA_INPUT\nvec4 texelColor = texture2D( tDiffuse, vUv );\ntexelColor.xyz *= texelColor.xyz;\ngl_FragColor = gl_FragColor * texelColor;\n#else\ngl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );\n#endif\n}\nif( enableAO ) {\n#ifdef GAMMA_INPUT\nvec4 aoColor = texture2D( tAO, vUv );\naoColor.xyz *= aoColor.xyz;\ngl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;\n#else\ngl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;\n#endif\n}\nif( enableSpecular )\nspecularTex = texture2D( tSpecular, vUv ).xyz;\nmat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\n#if MAX_POINT_LIGHTS > 0\nvec3 pointDiffuse = vec3( 0.0 );\nvec3 pointSpecular = vec3( 0.0 );\nfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 pointVector = lPosition.xyz + vViewPosition.xyz;\nfloat pointDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\npointDistance = 1.0 - min( ( length( pointVector ) / pointLightDistance[ i ] ), 1.0 );\npointVector = normalize( pointVector );\n#ifdef WRAP_AROUND\nfloat pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );\nfloat pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );\nvec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );\n#else\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\n#endif\npointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;\nvec3 pointHalfVector = normalize( pointVector + viewPosition );\nfloat pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );\nfloat pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( uShininess + 2.0001 ) / 8.0;\nvec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( pointVector, pointHalfVector ), 5.0 );\npointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;\n#else\npointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;\n#endif\n}\n#endif\n#if MAX_SPOT_LIGHTS > 0\nvec3 spotDiffuse = vec3( 0.0 );\nvec3 spotSpecular = vec3( 0.0 );\nfor ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\nvec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\nvec3 spotVector = lPosition.xyz + vViewPosition.xyz;\nfloat spotDistance = 1.0;\nif ( spotLightDistance[ i ] > 0.0 )\nspotDistance = 1.0 - min( ( length( spotVector ) / spotLightDistance[ i ] ), 1.0 );\nspotVector = normalize( spotVector );\nfloat spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );\nif ( spotEffect > spotLightAngle[ i ] ) {\nspotEffect = pow( spotEffect, spotLightExponent[ i ] );\n#ifdef WRAP_AROUND\nfloat spotDiffuseWeightFull = max( dot( normal, spotVector ), 0.0 );\nfloat spotDiffuseWeightHalf = max( 0.5 * dot( normal, spotVector ) + 0.5, 0.0 );\nvec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );\n#else\nfloat spotDiffuseWeight = max( dot( normal, spotVector ), 0.0 );\n#endif\nspotDiffuse += spotDistance * spotLightColor[ i ] * uDiffuseColor * spotDiffuseWeight * spotEffect;\nvec3 spotHalfVector = normalize( spotVector + viewPosition );\nfloat spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );\nfloat spotSpecularWeight = specularTex.r * max( pow( spotDotNormalHalf, uShininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( uShininess + 2.0001 ) / 8.0;\nvec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( spotVector, spotHalfVector ), 5.0 );\nspotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;\n#else\nspotSpecular += spotDistance * spotLightColor[ i ] * uSpecularColor * spotSpecularWeight * spotDiffuseWeight * spotEffect;\n#endif\n}\n}\n#endif\n#if MAX_DIR_LIGHTS > 0\nvec3 dirDiffuse = vec3( 0.0 );\nvec3 dirSpecular = vec3( 0.0 );\nfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {\nvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\n#ifdef WRAP_AROUND\nfloat directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );\nfloat directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );\nvec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );\n#else\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\n#endif\ndirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;\nvec3 dirHalfVector = normalize( dirVector + viewPosition );\nfloat dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );\nfloat dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );\n#ifdef PHYSICALLY_BASED_SHADING\nfloat specularNormalization = ( uShininess + 2.0001 ) / 8.0;\nvec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );\ndirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;\n#else\ndirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;\n#endif\n}\n#endif\nvec3 totalDiffuse = vec3( 0.0 );\nvec3 totalSpecular = vec3( 0.0 );\n#if MAX_DIR_LIGHTS > 0\ntotalDiffuse += dirDiffuse;\ntotalSpecular += dirSpecular;\n#endif\n#if MAX_POINT_LIGHTS > 0\ntotalDiffuse += pointDiffuse;\ntotalSpecular += pointSpecular;\n#endif\n#if MAX_SPOT_LIGHTS > 0\ntotalDiffuse += spotDiffuse;\ntotalSpecular += spotSpecular;\n#endif\ngl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor) + totalSpecular;\nif ( enableReflection ) {\nvec3 vReflect = reflect( normalize( vWorldPosition ), normal );\nvec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\n#ifdef GAMMA_INPUT\ncubeColor.xyz *= cubeColor.xyz;\n#endif\ngl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );\n}",
THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:["attribute vec4 tangent;\nuniform vec2 uOffset;\nuniform vec2 uRepeat;\nuniform bool enableDisplacement;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vWorldPosition;",
41
THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {",THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.skinnormal_vertex,"#ifdef USE_SKINNING\nvNormal = normalMatrix * skinnedNormal.xyz;\nvec4 skinnedTangent = skinMatrix * vec4( tangent.xyz, 0.0 );\nvTangent = normalMatrix * skinnedTangent.xyz;\n#else\nvNormal = normalMatrix * normal;\nvTangent = normalMatrix * tangent.xyz;\n#endif\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvUv = uv * uRepeat + uOffset;\nvec3 displacedPosition;\n#ifdef VERTEX_TEXTURES\nif ( enableDisplacement ) {\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\ndisplacedPosition = position + normalize( normal ) * df;\n} else {\n#ifdef USE_SKINNING\nvec4 skinned  = boneMatX * skinVertexA * skinWeight.x;\nskinned \t  += boneMatY * skinVertexB * skinWeight.y;\ndisplacedPosition  = skinned.xyz;\n#else\ndisplacedPosition = position;\n#endif\n}\n#else\n#ifdef USE_SKINNING\nvec4 skinned  = boneMatX * skinVertexA * skinWeight.x;\nskinned \t  += boneMatY * skinVertexB * skinWeight.y;\ndisplacedPosition  = skinned.xyz;\n#else\ndisplacedPosition = position;\n#endif\n#endif\nvec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );\nvec4 wPosition = objectMatrix * vec4( displacedPosition, 1.0 );\ngl_Position = projectionMatrix * mvPosition;\nvWorldPosition = wPosition.xyz;\n#ifdef USE_SHADOWMAP\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\nvShadowCoord[ i ] = shadowMatrix[ i ] * wPosition;\n}\n#endif\n}"].join("\n")},
42
cube:{uniforms:{tCube:{type:"t",value:1,texture:null},tFlip:{type:"f",value:-1}},vertexShader:"varying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"uniform samplerCube tCube;\nuniform float tFlip;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 wPos = cameraPosition - vViewPosition;\ngl_FragColor = textureCube( tCube, vec3( tFlip * wPos.x, wPos.yz ) );\n}"}}});
M
Mr.doob 已提交
43
THREE.FontUtils={faces:{},face:"helvetiker",weight:"normal",style:"normal",size:150,divisions:10,getFace:function(){return this.faces[this.face][this.weight][this.style]},loadFace:function(b){var a=b.familyName.toLowerCase();this.faces[a]=this.faces[a]||{};this.faces[a][b.cssFontWeight]=this.faces[a][b.cssFontWeight]||{};this.faces[a][b.cssFontWeight][b.cssFontStyle]=b;return this.faces[a][b.cssFontWeight][b.cssFontStyle]=b},drawText:function(b){for(var a=this.getFace(),c=this.size/a.resolution,d=
44 45
0,e=(""+b).split(""),f=e.length,g=[],b=0;b<f;b++){var h=new THREE.Path,h=this.extractGlyphPoints(e[b],a,c,d,h),d=d+h.offset;g.push(h.path)}return{paths:g,offset:d/2}},extractGlyphPoints:function(b,a,c,d,e){var f=[],g,h,i,j,l,m,n,k,o,q,p,s=a.glyphs[b]||a.glyphs["?"];if(s){if(s.o){a=s._cachedOutline||(s._cachedOutline=s.o.split(" "));j=a.length;for(b=0;b<j;){i=a[b++];switch(i){case "m":i=a[b++]*c+d;l=a[b++]*c;e.moveTo(i,l);break;case "l":i=a[b++]*c+d;l=a[b++]*c;e.lineTo(i,l);break;case "q":i=a[b++]*
c+d;l=a[b++]*c;k=a[b++]*c+d;o=a[b++]*c;e.quadraticCurveTo(k,o,i,l);if(g=f[f.length-1]){m=g.x;n=g.y;g=1;for(h=this.divisions;g<=h;g++){var u=g/h;THREE.Shape.Utils.b2(u,m,k,i);THREE.Shape.Utils.b2(u,n,o,l)}}break;case "b":i=a[b++]*c+d;l=a[b++]*c;k=a[b++]*c+d;o=a[b++]*-c;q=a[b++]*c+d;p=a[b++]*-c;e.bezierCurveTo(i,l,k,o,q,p);if(g=f[f.length-1]){m=g.x;n=g.y;g=1;for(h=this.divisions;g<=h;g++){u=g/h;THREE.Shape.Utils.b3(u,m,k,q,i);THREE.Shape.Utils.b3(u,n,o,p,l)}}}}}return{offset:s.ha*c,path:e}}}};
M
Mr.doob 已提交
46
THREE.FontUtils.generateShapes=function(b,a){var a=a||{},c=a.curveSegments!==void 0?a.curveSegments:4,d=a.font!==void 0?a.font:"helvetiker",e=a.weight!==void 0?a.weight:"normal",f=a.style!==void 0?a.style:"normal";THREE.FontUtils.size=a.size!==void 0?a.size:100;THREE.FontUtils.divisions=c;THREE.FontUtils.face=d;THREE.FontUtils.weight=e;THREE.FontUtils.style=f;c=THREE.FontUtils.drawText(b).paths;d=[];e=0;for(f=c.length;e<f;e++)Array.prototype.push.apply(d,c[e].toShapes());return d};
47 48 49
(function(b){var a=function(a){for(var b=a.length,e=0,f=b-1,g=0;g<b;f=g++)e=e+(a[f].x*a[g].y-a[g].x*a[f].y);return e*0.5};b.Triangulate=function(b,d){var e=b.length;if(e<3)return null;var f=[],g=[],h=[],i,j,l;if(a(b)>0)for(j=0;j<e;j++)g[j]=j;else for(j=0;j<e;j++)g[j]=e-1-j;var m=2*e;for(j=e-1;e>2;){if(m--<=0){console.log("Warning, unable to triangulate polygon!");break}i=j;e<=i&&(i=0);j=i+1;e<=j&&(j=0);l=j+1;e<=l&&(l=0);var n;a:{n=b;var k=i,o=j,q=l,p=e,s=g,u=void 0,t=void 0,r=void 0,v=void 0,z=void 0,
A=void 0,x=void 0,w=void 0,C=void 0,t=n[s[k]].x,r=n[s[k]].y,v=n[s[o]].x,z=n[s[o]].y,A=n[s[q]].x,x=n[s[q]].y;if(1.0E-10>(v-t)*(x-r)-(z-r)*(A-t))n=false;else{for(u=0;u<p;u++)if(!(u==k||u==o||u==q)){var w=n[s[u]].x,C=n[s[u]].y,B=void 0,E=void 0,G=void 0,L=void 0,H=void 0,D=void 0,K=void 0,F=void 0,O=void 0,I=void 0,M=void 0,J=void 0,B=G=H=void 0,B=A-v,E=x-z,G=t-A,L=r-x,H=v-t,D=z-r,K=w-t,F=C-r,O=w-v,I=C-z,M=w-A,J=C-x,B=B*I-E*O,H=H*F-D*K,G=G*J-L*M;if(B>=0&&G>=0&&H>=0){n=false;break a}}n=true}}if(n){f.push([b[g[i]],
b[g[j]],b[g[l]]]);h.push([g[i],g[j],g[l]]);i=j;for(l=j+1;l<e;i++,l++)g[i]=g[l];e--;m=2*e}}return d?h:f};b.Triangulate.area=a;return b})(THREE.FontUtils);self._typeface_js={faces:THREE.FontUtils.faces,loadFace:THREE.FontUtils.loadFace};THREE.BufferGeometry=function(){this.id=THREE.GeometryCount++;this.attributes={};this.dynamic=false;this.boundingSphere=this.boundingBox=null;this.hasTangents=false;this.morphTargets=[]};
50 51
THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,applyMatrix:function(b){var a,c;if(this.attributes.position)a=this.attributes.position.array;if(this.attributes.normal)c=this.attributes.normal.array;if(a!==void 0){b.multiplyVector3Array(a);this.verticesNeedUpdate=true}if(c!==void 0){a=new THREE.Matrix4;a.extractRotation(b);a.multiplyVector3Array(c);this.normalsNeedUpdate=true}},computeBoundingBox:function(){if(!this.boundingBox)this.boundingBox={min:new THREE.Vector3(Infinity,Infinity,
Infinity),max:new THREE.Vector3(-Infinity,-Infinity,-Infinity)};var b=this.attributes.position.array;if(b)for(var a=this.boundingBox,c,d,e,f=0,g=b.length;f<g;f=f+3){c=b[f];d=b[f+1];e=b[f+2];if(c<a.min.x)a.min.x=c;else if(c>a.max.x)a.max.x=c;if(d<a.min.y)a.min.y=d;else if(d>a.max.y)a.max.y=d;if(e<a.min.z)a.min.z=e;else if(e>a.max.z)a.max.z=e}if(b===void 0||b.length===0){this.boundingBox.min.set(0,0,0);this.boundingBox.max.set(0,0,0)}},computeBoundingSphere:function(){if(!this.boundingSphere)this.boundingSphere=
52
{radius:0};var b=this.attributes.position.array;if(b){for(var a,c=0,d,e,f=0,g=b.length;f<g;f=f+3){a=b[f];d=b[f+1];e=b[f+2];a=Math.sqrt(a*a+d*d+e*e);a>c&&(c=a)}this.boundingSphere.radius=c}},computeVertexNormals:function(){if(this.attributes.position&&this.attributes.index){var b,a,c,d;b=this.attributes.position.array.length;if(this.attributes.normal===void 0)this.attributes.normal={itemSize:3,array:new Float32Array(b),numItems:b};else{b=0;for(a=this.attributes.normal.array.length;b<a;b++)this.attributes.normal.array[b]=
53 54 55
0}var e=this.offsets,f=this.attributes.index.array,g=this.attributes.position.array,h=this.attributes.normal.array,i,j,l,m,n,k,o=new THREE.Vector3,q=new THREE.Vector3,p=new THREE.Vector3,s=new THREE.Vector3,u=new THREE.Vector3;c=0;for(d=e.length;c<d;++c){a=e[c].start;i=e[c].count;var t=e[c].index;b=a;for(a=a+i;b<a;b=b+3){i=t+f[b];j=t+f[b+1];l=t+f[b+2];m=g[i*3];n=g[i*3+1];k=g[i*3+2];o.set(m,n,k);m=g[j*3];n=g[j*3+1];k=g[j*3+2];q.set(m,n,k);m=g[l*3];n=g[l*3+1];k=g[l*3+2];p.set(m,n,k);s.sub(p,q);u.sub(o,
q);s.crossSelf(u);h[i*3]=h[i*3]+s.x;h[i*3+1]=h[i*3+1]+s.y;h[i*3+2]=h[i*3+2]+s.z;h[j*3]=h[j*3]+s.x;h[j*3+1]=h[j*3+1]+s.y;h[j*3+2]=h[j*3+2]+s.z;h[l*3]=h[l*3]+s.x;h[l*3+1]=h[l*3+1]+s.y;h[l*3+2]=h[l*3+2]+s.z}}b=0;for(a=h.length;b<a;b=b+3){m=h[b];n=h[b+1];k=h[b+2];c=1/Math.sqrt(m*m+n*n+k*k);h[b]=h[b]*c;h[b+1]=h[b+1]*c;h[b+2]=h[b+2]*c}this.normalsNeedUpdate=true}},computeTangents:function(){function b(a,b,c){m=d[a*3];n=d[a*3+1];k=d[a*3+2];o=d[b*3];q=d[b*3+1];p=d[b*3+2];s=d[c*3];u=d[c*3+1];t=d[c*3+2];r=
f[a*2];v=f[a*2+1];z=f[b*2];A=f[b*2+1];x=f[c*2];w=f[c*2+1];C=o-m;B=s-m;E=q-n;G=u-n;L=p-k;H=t-k;D=z-r;K=x-r;F=A-v;O=w-v;I=1/(D*O-K*F);M.set((O*C-F*B)*I,(O*E-F*G)*I,(O*L-F*H)*I);J.set((D*B-K*C)*I,(D*G-K*E)*I,(D*H-K*L)*I);j[a].addSelf(M);j[b].addSelf(M);j[c].addSelf(M);l[a].addSelf(J);l[b].addSelf(J);l[c].addSelf(J)}function a(a){U.x=e[a*3];U.y=e[a*3+1];U.z=e[a*3+2];X.copy(U);W=j[a];V.copy(W);V.subSelf(U.multiplyScalar(U.dot(W))).normalize();Y.cross(X,W);Z=Y.dot(l[a]);$=Z<0?-1:1;i[a*4]=V.x;i[a*4+1]=V.y;
56
i[a*4+2]=V.z;i[a*4+3]=$}if(this.attributes.index===void 0||this.attributes.position===void 0||this.attributes.normal===void 0||this.attributes.uv===void 0)console.warn("Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()");else{var c=this.attributes.index.array,d=this.attributes.position.array,e=this.attributes.normal.array,f=this.attributes.uv.array,g=d.length/3;if(this.attributes.tangent===void 0){var h=4*g;this.attributes.tangent={itemSize:4,array:new Float32Array(h),
57
numItems:h}}for(var i=this.attributes.tangent.array,j=[],l=[],h=0;h<g;h++){j[h]=new THREE.Vector3;l[h]=new THREE.Vector3}var m,n,k,o,q,p,s,u,t,r,v,z,A,x,w,C,B,E,G,L,H,D,K,F,O,I,M=new THREE.Vector3,J=new THREE.Vector3,N,y,Q,P,R,S=this.offsets,h=0;for(y=S.length;h<y;++h){N=S[h].start;Q=S[h].count;var T=S[h].index,g=N;for(N=N+Q;g<N;g=g+3){Q=T+c[g];P=T+c[g+1];R=T+c[g+2];b(Q,P,R)}}var V=new THREE.Vector3,Y=new THREE.Vector3,U=new THREE.Vector3,X=new THREE.Vector3,$,W,Z,h=0;for(y=S.length;h<y;++h){N=S[h].start;
58 59
Q=S[h].count;T=S[h].index;g=N;for(N=N+Q;g<N;g=g+3){Q=T+c[g];P=T+c[g+1];R=T+c[g+2];a(Q);a(P);a(R)}}this.tangentsNeedUpdate=this.hasTangents=true}}};THREE.Curve=function(){};THREE.Curve.prototype.getPoint=function(){console.log("Warning, getPoint() not implemented!");return null};THREE.Curve.prototype.getPointAt=function(b){return this.getPoint(this.getUtoTmapping(b))};THREE.Curve.prototype.getPoints=function(b){b||(b=5);var a,c=[];for(a=0;a<=b;a++)c.push(this.getPoint(a/b));return c};
THREE.Curve.prototype.getSpacedPoints=function(b){b||(b=5);var a,c=[];for(a=0;a<=b;a++)c.push(this.getPointAt(a/b));return c};THREE.Curve.prototype.getLength=function(){var b=this.getLengths();return b[b.length-1]};
60 61
THREE.Curve.prototype.getLengths=function(b){b||(b=this.__arcLengthDivisions?this.__arcLengthDivisions:200);if(this.cacheArcLengths&&this.cacheArcLengths.length==b+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=false;var a=[],c,d=this.getPoint(0),e,f=0;a.push(0);for(e=1;e<=b;e++){c=this.getPoint(e/b);f=f+c.distanceTo(d);a.push(f);d=c}return this.cacheArcLengths=a};THREE.Curve.prototype.updateArcLengths=function(){this.needsUpdate=true;this.getLengths()};
THREE.Curve.prototype.getUtoTmapping=function(b,a){var c=this.getLengths(),d=0,e=c.length,f;f=a?a:b*c[e-1];for(var g=0,h=e-1,i;g<=h;){d=Math.floor(g+(h-g)/2);i=c[d]-f;if(i<0)g=d+1;else if(i>0)h=d-1;else{h=d;break}}d=h;if(c[d]==f)return d/(e-1);g=c[d];return c=(d+(f-g)/(c[d+1]-g))/(e-1)};THREE.Curve.prototype.getNormalVector=function(b){b=this.getTangent(b);return new THREE.Vector2(-b.y,b.x)};
M
Mr.doob 已提交
62 63
THREE.Curve.prototype.getTangent=function(b){var a=b-1.0E-4,b=b+1.0E-4;a<0&&(a=0);b>1&&(b=1);a=this.getPoint(a);return this.getPoint(b).clone().subSelf(a).normalize()};THREE.Curve.prototype.getTangentAt=function(b){return this.getTangent(this.getUtoTmapping(b))};THREE.LineCurve=function(b,a){this.v1=b;this.v2=a};THREE.LineCurve.prototype=Object.create(THREE.Curve.prototype);THREE.LineCurve.prototype.getPoint=function(b){var a=this.v2.clone().subSelf(this.v1);a.multiplyScalar(b).addSelf(this.v1);return a};
THREE.LineCurve.prototype.getPointAt=function(b){return this.getPoint(b)};THREE.LineCurve.prototype.getTangent=function(){return this.v2.clone().subSelf(this.v1).normalize()};THREE.QuadraticBezierCurve=function(b,a,c){this.v0=b;this.v1=a;this.v2=c};THREE.QuadraticBezierCurve.prototype=Object.create(THREE.Curve.prototype);
64
THREE.QuadraticBezierCurve.prototype.getPoint=function(b){var a;a=THREE.Shape.Utils.b2(b,this.v0.x,this.v1.x,this.v2.x);b=THREE.Shape.Utils.b2(b,this.v0.y,this.v1.y,this.v2.y);return new THREE.Vector2(a,b)};THREE.QuadraticBezierCurve.prototype.getTangent=function(b){var a;a=THREE.Curve.Utils.tangentQuadraticBezier(b,this.v0.x,this.v1.x,this.v2.x);b=THREE.Curve.Utils.tangentQuadraticBezier(b,this.v0.y,this.v1.y,this.v2.y);a=new THREE.Vector2(a,b);a.normalize();return a};
M
Mr.doob 已提交
65 66
THREE.CubicBezierCurve=function(b,a,c,d){this.v0=b;this.v1=a;this.v2=c;this.v3=d};THREE.CubicBezierCurve.prototype=Object.create(THREE.Curve.prototype);THREE.CubicBezierCurve.prototype.getPoint=function(b){var a;a=THREE.Shape.Utils.b3(b,this.v0.x,this.v1.x,this.v2.x,this.v3.x);b=THREE.Shape.Utils.b3(b,this.v0.y,this.v1.y,this.v2.y,this.v3.y);return new THREE.Vector2(a,b)};
THREE.CubicBezierCurve.prototype.getTangent=function(b){var a;a=THREE.Curve.Utils.tangentCubicBezier(b,this.v0.x,this.v1.x,this.v2.x,this.v3.x);b=THREE.Curve.Utils.tangentCubicBezier(b,this.v0.y,this.v1.y,this.v2.y,this.v3.y);a=new THREE.Vector2(a,b);a.normalize();return a};THREE.SplineCurve=function(b){this.points=b==void 0?[]:b};THREE.SplineCurve.prototype=Object.create(THREE.Curve.prototype);
67
THREE.SplineCurve.prototype.getPoint=function(b){var a=new THREE.Vector2,c=[],d=this.points,e;e=(d.length-1)*b;b=Math.floor(e);e=e-b;c[0]=b==0?b:b-1;c[1]=b;c[2]=b>d.length-2?d.length-1:b+1;c[3]=b>d.length-3?d.length-1:b+2;a.x=THREE.Curve.Utils.interpolate(d[c[0]].x,d[c[1]].x,d[c[2]].x,d[c[3]].x,e);a.y=THREE.Curve.Utils.interpolate(d[c[0]].y,d[c[1]].y,d[c[2]].y,d[c[3]].y,e);return a};
M
Mr.doob 已提交
68 69
THREE.EllipseCurve=function(b,a,c,d,e,f,g){this.aX=b;this.aY=a;this.xRadius=c;this.yRadius=d;this.aStartAngle=e;this.aEndAngle=f;this.aClockwise=g};THREE.EllipseCurve.prototype=Object.create(THREE.Curve.prototype);THREE.EllipseCurve.prototype.getPoint=function(b){var a=this.aEndAngle-this.aStartAngle;this.aClockwise||(b=1-b);a=this.aStartAngle+b*a;b=this.aX+this.xRadius*Math.cos(a);a=this.aY+this.yRadius*Math.sin(a);return new THREE.Vector2(b,a)};
THREE.ArcCurve=function(b,a,c,d,e,f){THREE.EllipseCurve.call(this,b,a,c,c,d,e,f)};THREE.ArcCurve.prototype=Object.create(THREE.EllipseCurve.prototype);
70
THREE.Curve.Utils={tangentQuadraticBezier:function(b,a,c,d){return 2*(1-b)*(c-a)+2*b*(d-c)},tangentCubicBezier:function(b,a,c,d,e){return-3*a*(1-b)*(1-b)+3*c*(1-b)*(1-b)-6*b*c*(1-b)+6*b*d*(1-b)-3*b*b*d+3*b*b*e},tangentSpline:function(b){return 6*b*b-6*b+(3*b*b-4*b+1)+(-6*b*b+6*b)+(3*b*b-2*b)},interpolate:function(b,a,c,d,e){var b=(c-b)*0.5,d=(d-a)*0.5,f=e*e;return(2*a-2*c+b+d)*e*f+(-3*a+3*c-2*b-d)*f+b*e+a}};
M
Mr.doob 已提交
71
THREE.Curve.create=function(b,a){b.prototype=Object.create(THREE.Curve.prototype);b.prototype.getPoint=a;return b};THREE.LineCurve3=THREE.Curve.create(function(b,a){this.v1=b;this.v2=a},function(b){var a=new THREE.Vector3;a.sub(this.v2,this.v1);a.multiplyScalar(b);a.addSelf(this.v1);return a});
72 73 74 75
THREE.QuadraticBezierCurve3=THREE.Curve.create(function(b,a,c){this.v0=b;this.v1=a;this.v2=c},function(b){var a,c;a=THREE.Shape.Utils.b2(b,this.v0.x,this.v1.x,this.v2.x);c=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(a,c,b)});
THREE.CubicBezierCurve3=THREE.Curve.create(function(b,a,c,d){this.v0=b;this.v1=a;this.v2=c;this.v3=d},function(b){var a,c;a=THREE.Shape.Utils.b3(b,this.v0.x,this.v1.x,this.v2.x,this.v3.x);c=THREE.Shape.Utils.b3(b,this.v0.y,this.v1.y,this.v2.y,this.v3.y);b=THREE.Shape.Utils.b3(b,this.v0.z,this.v1.z,this.v2.z,this.v3.z);return new THREE.Vector3(a,c,b)});
THREE.SplineCurve3=THREE.Curve.create(function(b){this.points=b==void 0?[]:b},function(b){var a=new THREE.Vector3,c=[],d=this.points,e,b=(d.length-1)*b;e=Math.floor(b);b=b-e;c[0]=e==0?e:e-1;c[1]=e;c[2]=e>d.length-2?d.length-1:e+1;c[3]=e>d.length-3?d.length-1:e+2;e=d[c[0]];var f=d[c[1]],g=d[c[2]],c=d[c[3]];a.x=THREE.Curve.Utils.interpolate(e.x,f.x,g.x,c.x,b);a.y=THREE.Curve.Utils.interpolate(e.y,f.y,g.y,c.y,b);a.z=THREE.Curve.Utils.interpolate(e.z,f.z,g.z,c.z,b);return a});
THREE.ClosedSplineCurve3=THREE.Curve.create(function(b){this.points=b==void 0?[]:b},function(b){var a=new THREE.Vector3,c=[],d=this.points,e;e=(d.length-0)*b;b=Math.floor(e);e=e-b;b=b+(b>0?0:(Math.floor(Math.abs(b)/d.length)+1)*d.length);c[0]=(b-1)%d.length;c[1]=b%d.length;c[2]=(b+1)%d.length;c[3]=(b+2)%d.length;a.x=THREE.Curve.Utils.interpolate(d[c[0]].x,d[c[1]].x,d[c[2]].x,d[c[3]].x,e);a.y=THREE.Curve.Utils.interpolate(d[c[0]].y,d[c[1]].y,d[c[2]].y,d[c[3]].y,e);a.z=THREE.Curve.Utils.interpolate(d[c[0]].z,
M
Mr.doob 已提交
76 77
d[c[1]].z,d[c[2]].z,d[c[3]].z,e);return a});THREE.CurvePath=function(){this.curves=[];this.bends=[];this.autoClose=false};THREE.CurvePath.prototype=Object.create(THREE.Curve.prototype);THREE.CurvePath.prototype.add=function(b){this.curves.push(b)};THREE.CurvePath.prototype.checkConnection=function(){};THREE.CurvePath.prototype.closePath=function(){var b=this.curves[0].getPoint(0),a=this.curves[this.curves.length-1].getPoint(1);b.equals(a)||this.curves.push(new THREE.LineCurve(a,b))};
THREE.CurvePath.prototype.getPoint=function(b){for(var a=b*this.getLength(),c=this.getCurveLengths(),b=0;b<c.length;){if(c[b]>=a){a=c[b]-a;b=this.curves[b];a=1-a/b.getLength();return b.getPointAt(a)}b++}return null};THREE.CurvePath.prototype.getLength=function(){var b=this.getCurveLengths();return b[b.length-1]};
78
THREE.CurvePath.prototype.getCurveLengths=function(){if(this.cacheLengths&&this.cacheLengths.length==this.curves.length)return this.cacheLengths;var b=[],a=0,c,d=this.curves.length;for(c=0;c<d;c++){a=a+this.curves[c].getLength();b.push(a)}return this.cacheLengths=b};
M
Mr.doob 已提交
79
THREE.CurvePath.prototype.getBoundingBox=function(){var b=this.getPoints(),a,c,d,e;a=c=Number.NEGATIVE_INFINITY;d=e=Number.POSITIVE_INFINITY;var f,g,h,i;i=new THREE.Vector2;g=0;for(h=b.length;g<h;g++){f=b[g];if(f.x>a)a=f.x;else if(f.x<d)d=f.x;if(f.y>c)c=f.y;else if(f.y<e)e=f.y;i.addSelf(f.x,f.y)}return{minX:d,minY:e,maxX:a,maxY:c,centroid:i.divideScalar(h)}};THREE.CurvePath.prototype.createPointsGeometry=function(b){return this.createGeometry(this.getPoints(b,true))};
80 81
THREE.CurvePath.prototype.createSpacedPointsGeometry=function(b){return this.createGeometry(this.getSpacedPoints(b,true))};THREE.CurvePath.prototype.createGeometry=function(b){for(var a=new THREE.Geometry,c=0;c<b.length;c++)a.vertices.push(new THREE.Vector3(b[c].x,b[c].y,0));return a};THREE.CurvePath.prototype.addWrapPath=function(b){this.bends.push(b)};
THREE.CurvePath.prototype.getTransformedPoints=function(b,a){var c=this.getPoints(b),d,e;if(!a)a=this.bends;d=0;for(e=a.length;d<e;d++)c=this.getWrapPoints(c,a[d]);return c};THREE.CurvePath.prototype.getTransformedSpacedPoints=function(b,a){var c=this.getSpacedPoints(b),d,e;if(!a)a=this.bends;d=0;for(e=a.length;d<e;d++)c=this.getWrapPoints(c,a[d]);return c};
M
Mr.doob 已提交
82
THREE.CurvePath.prototype.getWrapPoints=function(b,a){var c=this.getBoundingBox(),d,e,f,g,h,i;d=0;for(e=b.length;d<e;d++){f=b[d];g=f.x;h=f.y;i=g/c.maxX;i=a.getUtoTmapping(i,g);g=a.getPoint(i);h=a.getNormalVector(i).multiplyScalar(h);f.x=g.x+h.x;f.y=g.y+h.y}return b};THREE.Gyroscope=function(){THREE.Object3D.call(this)};THREE.Gyroscope.prototype=Object.create(THREE.Object3D.prototype);
83 84
THREE.Gyroscope.prototype.updateMatrixWorld=function(b){this.matrixAutoUpdate&&this.updateMatrix();if(this.matrixWorldNeedsUpdate||b){if(this.parent){this.matrixWorld.multiply(this.parent.matrixWorld,this.matrix);this.matrixWorld.decompose(this.translationWorld,this.rotationWorld,this.scaleWorld);this.matrix.decompose(this.translationObject,this.rotationObject,this.scaleObject);this.matrixWorld.compose(this.translationWorld,this.rotationObject,this.scaleWorld)}else this.matrixWorld.copy(this.matrix);
this.matrixWorldNeedsUpdate=false;b=true}for(var a=0,c=this.children.length;a<c;a++)this.children[a].updateMatrixWorld(b)};THREE.Gyroscope.prototype.translationWorld=new THREE.Vector3;THREE.Gyroscope.prototype.translationObject=new THREE.Vector3;THREE.Gyroscope.prototype.rotationWorld=new THREE.Quaternion;THREE.Gyroscope.prototype.rotationObject=new THREE.Quaternion;THREE.Gyroscope.prototype.scaleWorld=new THREE.Vector3;THREE.Gyroscope.prototype.scaleObject=new THREE.Vector3;
M
Mr.doob 已提交
85
THREE.Path=function(b){THREE.CurvePath.call(this);this.actions=[];b&&this.fromPoints(b)};THREE.Path.prototype=Object.create(THREE.CurvePath.prototype);THREE.PathActions={MOVE_TO:"moveTo",LINE_TO:"lineTo",QUADRATIC_CURVE_TO:"quadraticCurveTo",BEZIER_CURVE_TO:"bezierCurveTo",CSPLINE_THRU:"splineThru",ARC:"arc",ELLIPSE:"ellipse"};THREE.Path.prototype.fromPoints=function(b){this.moveTo(b[0].x,b[0].y);for(var a=1,c=b.length;a<c;a++)this.lineTo(b[a].x,b[a].y)};
86 87 88
THREE.Path.prototype.moveTo=function(b,a){var c=Array.prototype.slice.call(arguments);this.actions.push({action:THREE.PathActions.MOVE_TO,args:c})};THREE.Path.prototype.lineTo=function(b,a){var c=Array.prototype.slice.call(arguments),d=this.actions[this.actions.length-1].args;this.curves.push(new THREE.LineCurve(new THREE.Vector2(d[d.length-2],d[d.length-1]),new THREE.Vector2(b,a)));this.actions.push({action:THREE.PathActions.LINE_TO,args:c})};
THREE.Path.prototype.quadraticCurveTo=function(b,a,c,d){var e=Array.prototype.slice.call(arguments),f=this.actions[this.actions.length-1].args;this.curves.push(new THREE.QuadraticBezierCurve(new THREE.Vector2(f[f.length-2],f[f.length-1]),new THREE.Vector2(b,a),new THREE.Vector2(c,d)));this.actions.push({action:THREE.PathActions.QUADRATIC_CURVE_TO,args:e})};
THREE.Path.prototype.bezierCurveTo=function(b,a,c,d,e,f){var g=Array.prototype.slice.call(arguments),h=this.actions[this.actions.length-1].args;this.curves.push(new THREE.CubicBezierCurve(new THREE.Vector2(h[h.length-2],h[h.length-1]),new THREE.Vector2(b,a),new THREE.Vector2(c,d),new THREE.Vector2(e,f)));this.actions.push({action:THREE.PathActions.BEZIER_CURVE_TO,args:g})};
M
Mr.doob 已提交
89 90 91
THREE.Path.prototype.splineThru=function(b){var a=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])];Array.prototype.push.apply(c,b);this.curves.push(new THREE.SplineCurve(c));this.actions.push({action:THREE.PathActions.CSPLINE_THRU,args:a})};THREE.Path.prototype.ellipse=function(b,a,c,d,e,f,g){var h=this.actions[this.actions.length-1];this.absellipse(h.x+b,h.y+a,c,d,e,f,g)};
THREE.Path.prototype.arc=function(b,a,c,d,e,f){var g=this.actions[this.actions.length-1];this.absarc(g.x+b,g.y+a,c,d,e,f)};THREE.Path.prototype.absellipse=function(b,a,c,d,e,f,g){var h=Array.prototype.slice.call(arguments),i=new THREE.EllipseCurve(b,a,c,d,e,f,g);this.curves.push(i);i=i.getPoint(g?1:0);h.push(i.x);h.push(i.y);this.actions.push({action:THREE.PathActions.ELLIPSE,args:h})};THREE.Path.prototype.absarc=function(b,a,c,d,e,f){this.absellipse(b,a,c,c,d,e,f)};
THREE.Path.prototype.getSpacedPoints=function(b){b||(b=40);for(var a=[],c=0;c<b;c++)a.push(this.getPoint(c/b));return a};
92 93 94 95
THREE.Path.prototype.getPoints=function(b,a){if(this.useSpacedPoints){console.log("tata");return this.getSpacedPoints(b,a)}var b=b||12,c=[],d,e,f,g,h,i,j,l,m,n,k,o,q;d=0;for(e=this.actions.length;d<e;d++){f=this.actions[d];g=f.action;f=f.args;switch(g){case THREE.PathActions.MOVE_TO:c.push(new THREE.Vector2(f[0],f[1]));break;case THREE.PathActions.LINE_TO:c.push(new THREE.Vector2(f[0],f[1]));break;case THREE.PathActions.QUADRATIC_CURVE_TO:h=f[2];i=f[3];m=f[0];n=f[1];if(c.length>0){g=c[c.length-1];
k=g.x;o=g.y}else{g=this.actions[d-1].args;k=g[g.length-2];o=g[g.length-1]}for(f=1;f<=b;f++){q=f/b;g=THREE.Shape.Utils.b2(q,k,m,h);q=THREE.Shape.Utils.b2(q,o,n,i);c.push(new THREE.Vector2(g,q))}break;case THREE.PathActions.BEZIER_CURVE_TO:h=f[4];i=f[5];m=f[0];n=f[1];j=f[2];l=f[3];if(c.length>0){g=c[c.length-1];k=g.x;o=g.y}else{g=this.actions[d-1].args;k=g[g.length-2];o=g[g.length-1]}for(f=1;f<=b;f++){q=f/b;g=THREE.Shape.Utils.b3(q,k,m,j,h);q=THREE.Shape.Utils.b3(q,o,n,l,i);c.push(new THREE.Vector2(g,
q))}break;case THREE.PathActions.CSPLINE_THRU:g=this.actions[d-1].args;q=[new THREE.Vector2(g[g.length-2],g[g.length-1])];g=b*f[0].length;q=q.concat(f[0]);q=new THREE.SplineCurve(q);for(f=1;f<=g;f++)c.push(q.getPointAt(f/g));break;case THREE.PathActions.ARC:h=f[0];i=f[1];n=f[2];j=f[3];g=f[4];m=!!f[5];k=g-j;o=b*2;for(f=1;f<=o;f++){q=f/o;m||(q=1-q);q=j+q*k;g=h+n*Math.cos(q);q=i+n*Math.sin(q);c.push(new THREE.Vector2(g,q))}break;case THREE.PathActions.ELLIPSE:h=f[0];i=f[1];n=f[2];l=f[3];j=f[4];g=f[5];
m=!!f[6];k=g-j;o=b*2;for(f=1;f<=o;f++){q=f/o;m||(q=1-q);q=j+q*k;g=h+n*Math.cos(q);q=i+l*Math.sin(q);c.push(new THREE.Vector2(g,q))}}}d=c[c.length-1];Math.abs(d.x-c[0].x)<1.0E-10&&Math.abs(d.y-c[0].y)<1.0E-10&&c.splice(c.length-1,1);a&&c.push(c[0]);return c};
96
THREE.Path.prototype.toShapes=function(){var b,a,c,d,e=[],f=new THREE.Path;b=0;for(a=this.actions.length;b<a;b++){c=this.actions[b];d=c.args;c=c.action;if(c==THREE.PathActions.MOVE_TO&&f.actions.length!=0){e.push(f);f=new THREE.Path}f[c].apply(f,d)}f.actions.length!=0&&e.push(f);if(e.length==0)return[];var g;d=[];b=!THREE.Shape.Utils.isClockWise(e[0].getPoints());if(e.length==1){f=e[0];g=new THREE.Shape;g.actions=f.actions;g.curves=f.curves;d.push(g);return d}if(b){g=new THREE.Shape;b=0;for(a=e.length;b<
M
Mr.doob 已提交
97
a;b++){f=e[b];if(THREE.Shape.Utils.isClockWise(f.getPoints())){g.actions=f.actions;g.curves=f.curves;d.push(g);g=new THREE.Shape}else g.holes.push(f)}}else{b=0;for(a=e.length;b<a;b++){f=e[b];if(THREE.Shape.Utils.isClockWise(f.getPoints())){g&&d.push(g);g=new THREE.Shape;g.actions=f.actions;g.curves=f.curves}else g.holes.push(f)}d.push(g)}return d};THREE.Shape=function(){THREE.Path.apply(this,arguments);this.holes=[]};THREE.Shape.prototype=Object.create(THREE.Path.prototype);
98 99
THREE.Shape.prototype.extrude=function(b){return new THREE.ExtrudeGeometry(this,b)};THREE.Shape.prototype.getPointsHoles=function(b){var a,c=this.holes.length,d=[];for(a=0;a<c;a++)d[a]=this.holes[a].getTransformedPoints(b,this.bends);return d};THREE.Shape.prototype.getSpacedPointsHoles=function(b){var a,c=this.holes.length,d=[];for(a=0;a<c;a++)d[a]=this.holes[a].getTransformedSpacedPoints(b,this.bends);return d};
THREE.Shape.prototype.extractAllPoints=function(b){return{shape:this.getTransformedPoints(b),holes:this.getPointsHoles(b)}};THREE.Shape.prototype.extractPoints=function(b){return this.useSpacedPoints?this.extractAllSpacedPoints(b):this.extractAllPoints(b)};THREE.Shape.prototype.extractAllSpacedPoints=function(b){return{shape:this.getTransformedSpacedPoints(b),holes:this.getSpacedPointsHoles(b)}};
100 101
THREE.Shape.Utils={removeHoles:function(b,a){var c=b.concat(),d=c.concat(),e,f,g,h,i,j,l,m,n,k,o=[];for(i=0;i<a.length;i++){j=a[i];Array.prototype.push.apply(d,j);f=Number.POSITIVE_INFINITY;for(e=0;e<j.length;e++){n=j[e];k=[];for(m=0;m<c.length;m++){l=c[m];l=n.distanceToSquared(l);k.push(l);if(l<f){f=l;g=e;h=m}}}e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1;var q=[j[g],c[h],c[e]];m=THREE.FontUtils.Triangulate.area(q);var p=[j[g],j[f],c[h]];n=THREE.FontUtils.Triangulate.area(p);k=h;l=g;h=h+1;g=g+
-1;h<0&&(h=h+c.length);h=h%c.length;g<0&&(g=g+j.length);g=g%j.length;e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1;q=[j[g],c[h],c[e]];q=THREE.FontUtils.Triangulate.area(q);p=[j[g],j[f],c[h]];p=THREE.FontUtils.Triangulate.area(p);if(m+n>q+p){h=k;g=l;h<0&&(h=h+c.length);h=h%c.length;g<0&&(g=g+j.length);g=g%j.length;e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1}m=c.slice(0,h);n=c.slice(h);k=j.slice(g);l=j.slice(0,g);f=[j[g],j[f],c[h]];o.push([j[g],c[h],c[e]]);o.push(f);c=m.concat(k).concat(l).concat(n)}return{shape:c,
M
Mr.doob 已提交
102
isolatedPts:o,allpoints:d}},triangulateShape:function(b,a){var c=THREE.Shape.Utils.removeHoles(b,a),d=c.allpoints,e=c.isolatedPts,c=THREE.FontUtils.Triangulate(c.shape,false),f,g,h,i,j={};f=0;for(g=d.length;f<g;f++){i=d[f].x+":"+d[f].y;j[i]!==void 0&&console.log("Duplicate point",i);j[i]=f}f=0;for(g=c.length;f<g;f++){h=c[f];for(d=0;d<3;d++){i=h[d].x+":"+h[d].y;i=j[i];i!==void 0&&(h[d]=i)}}f=0;for(g=e.length;f<g;f++){h=e[f];for(d=0;d<3;d++){i=h[d].x+":"+h[d].y;i=j[i];i!==void 0&&(h[d]=i)}}return c.concat(e)},
103
isClockWise:function(b){return THREE.FontUtils.Triangulate.area(b)<0},b2p0:function(b,a){var c=1-b;return c*c*a},b2p1:function(b,a){return 2*(1-b)*b*a},b2p2:function(b,a){return b*b*a},b2:function(b,a,c,d){return this.b2p0(b,a)+this.b2p1(b,c)+this.b2p2(b,d)},b3p0:function(b,a){var c=1-b;return c*c*c*a},b3p1:function(b,a){var c=1-b;return 3*c*c*b*a},b3p2:function(b,a){return 3*(1-b)*b*b*a},b3p3:function(b,a){return b*b*b*a},b3:function(b,a,c,d,e){return this.b3p0(b,a)+this.b3p1(b,c)+this.b3p2(b,d)+
M
Mr.doob 已提交
104 105 106 107 108
this.b3p3(b,e)}};
THREE.AnimationHandler=function(){var b=[],a={},c={update:function(a){for(var c=0;c<b.length;c++)b[c].update(a)},addToUpdate:function(a){b.indexOf(a)===-1&&b.push(a)},removeFromUpdate:function(a){a=b.indexOf(a);a!==-1&&b.splice(a,1)},add:function(b){a[b.name]!==void 0&&console.log("THREE.AnimationHandler.add: Warning! "+b.name+" already exists in library. Overwriting.");a[b.name]=b;if(b.initialized!==true){for(var c=0;c<b.hierarchy.length;c++){for(var d=0;d<b.hierarchy[c].keys.length;d++){if(b.hierarchy[c].keys[d].time<0)b.hierarchy[c].keys[d].time=
0;if(b.hierarchy[c].keys[d].rot!==void 0&&!(b.hierarchy[c].keys[d].rot instanceof THREE.Quaternion)){var h=b.hierarchy[c].keys[d].rot;b.hierarchy[c].keys[d].rot=new THREE.Quaternion(h[0],h[1],h[2],h[3])}}if(b.hierarchy[c].keys.length&&b.hierarchy[c].keys[0].morphTargets!==void 0){h={};for(d=0;d<b.hierarchy[c].keys.length;d++)for(var i=0;i<b.hierarchy[c].keys[d].morphTargets.length;i++){var j=b.hierarchy[c].keys[d].morphTargets[i];h[j]=-1}b.hierarchy[c].usedMorphTargets=h;for(d=0;d<b.hierarchy[c].keys.length;d++){var l=
{};for(j in h){for(i=0;i<b.hierarchy[c].keys[d].morphTargets.length;i++)if(b.hierarchy[c].keys[d].morphTargets[i]===j){l[j]=b.hierarchy[c].keys[d].morphTargetsInfluences[i];break}i===b.hierarchy[c].keys[d].morphTargets.length&&(l[j]=0)}b.hierarchy[c].keys[d].morphTargetsInfluences=l}}for(d=1;d<b.hierarchy[c].keys.length;d++)if(b.hierarchy[c].keys[d].time===b.hierarchy[c].keys[d-1].time){b.hierarchy[c].keys.splice(d,1);d--}for(d=0;d<b.hierarchy[c].keys.length;d++)b.hierarchy[c].keys[d].index=d}d=parseInt(b.length*
b.fps,10);b.JIT={};b.JIT.hierarchy=[];for(c=0;c<b.hierarchy.length;c++)b.JIT.hierarchy.push(Array(d));b.initialized=true}},get:function(b){if(typeof b==="string"){if(a[b])return a[b];console.log("THREE.AnimationHandler.get: Couldn't find animation "+b);return null}},parse:function(a){var b=[];if(a instanceof THREE.SkinnedMesh)for(var c=0;c<a.bones.length;c++)b.push(a.bones[c]);else d(a,b);return b}},d=function(a,b){b.push(a);for(var c=0;c<a.children.length;c++)d(a.children[c],b)};c.LINEAR=0;c.CATMULLROM=
109 110
1;c.CATMULLROM_FORWARD=2;return c}();THREE.Animation=function(b,a,c){this.root=b;this.data=THREE.AnimationHandler.get(a);this.hierarchy=THREE.AnimationHandler.parse(b);this.currentTime=0;this.timeScale=1;this.isPlaying=false;this.loop=this.isPaused=true;this.interpolationType=c!==void 0?c:THREE.AnimationHandler.LINEAR;this.points=[];this.target=new THREE.Vector3};
THREE.Animation.prototype.play=function(b,a){if(this.isPlaying===false){this.isPlaying=true;this.loop=b!==void 0?b:true;this.currentTime=a!==void 0?a:0;var c,d=this.hierarchy.length,e;for(c=0;c<d;c++){e=this.hierarchy[c];if(this.interpolationType!==THREE.AnimationHandler.CATMULLROM_FORWARD)e.useQuaternion=true;e.matrixAutoUpdate=true;if(e.animationCache===void 0){e.animationCache={};e.animationCache.prevKey={pos:0,rot:0,scl:0};e.animationCache.nextKey={pos:0,rot:0,scl:0};e.animationCache.originalMatrix=
111
e instanceof THREE.Bone?e.skinMatrix:e.matrix}var f=e.animationCache.prevKey;e=e.animationCache.nextKey;f.pos=this.data.hierarchy[c].keys[0];f.rot=this.data.hierarchy[c].keys[0];f.scl=this.data.hierarchy[c].keys[0];e.pos=this.getNextKeyWith("pos",c,1);e.rot=this.getNextKeyWith("rot",c,1);e.scl=this.getNextKeyWith("scl",c,1)}this.update(0)}this.isPaused=false;THREE.AnimationHandler.addToUpdate(this)};
112 113 114 115 116
THREE.Animation.prototype.pause=function(){this.isPaused===true?THREE.AnimationHandler.addToUpdate(this):THREE.AnimationHandler.removeFromUpdate(this);this.isPaused=!this.isPaused};THREE.Animation.prototype.stop=function(){this.isPaused=this.isPlaying=false;THREE.AnimationHandler.removeFromUpdate(this)};
THREE.Animation.prototype.update=function(b){if(this.isPlaying!==false){var a=["pos","rot","scl"],c,d,e,f,g,h,i,j,l;l=this.currentTime=this.currentTime+b*this.timeScale;j=this.currentTime=this.currentTime%this.data.length;parseInt(Math.min(j*this.data.fps,this.data.length*this.data.fps),10);for(var m=0,n=this.hierarchy.length;m<n;m++){b=this.hierarchy[m];i=b.animationCache;for(var k=0;k<3;k++){c=a[k];g=i.prevKey[c];h=i.nextKey[c];if(h.time<=l){if(j<l)if(this.loop){g=this.data.hierarchy[m].keys[0];
for(h=this.getNextKeyWith(c,m,1);h.time<j;){g=h;h=this.getNextKeyWith(c,m,h.index+1)}}else{this.stop();return}else{do{g=h;h=this.getNextKeyWith(c,m,h.index+1)}while(h.time<j)}i.prevKey[c]=g;i.nextKey[c]=h}b.matrixAutoUpdate=true;b.matrixWorldNeedsUpdate=true;d=(j-g.time)/(h.time-g.time);e=g[c];f=h[c];if(d<0||d>1){console.log("THREE.Animation.update: Warning! Scale out of bounds:"+d+" on bone "+m);d=d<0?0:1}if(c==="pos"){c=b.position;if(this.interpolationType===THREE.AnimationHandler.LINEAR){c.x=e[0]+
(f[0]-e[0])*d;c.y=e[1]+(f[1]-e[1])*d;c.z=e[2]+(f[2]-e[2])*d}else if(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD){this.points[0]=this.getPrevKeyWith("pos",m,g.index-1).pos;this.points[1]=e;this.points[2]=f;this.points[3]=this.getNextKeyWith("pos",m,h.index+1).pos;d=d*0.33+0.33;e=this.interpolateCatmullRom(this.points,d);c.x=e[0];c.y=e[1];c.z=e[2];if(this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD){d=
this.interpolateCatmullRom(this.points,d*1.01);this.target.set(d[0],d[1],d[2]);this.target.subSelf(c);this.target.y=0;this.target.normalize();d=Math.atan2(this.target.x,this.target.z);b.rotation.set(0,d,0)}}}else if(c==="rot")THREE.Quaternion.slerp(e,f,b.quaternion,d);else if(c==="scl"){c=b.scale;c.x=e[0]+(f[0]-e[0])*d;c.y=e[1]+(f[1]-e[1])*d;c.z=e[2]+(f[2]-e[2])*d}}}}};
117 118 119
THREE.Animation.prototype.interpolateCatmullRom=function(b,a){var c=[],d=[],e,f,g,h,i,j;e=(b.length-1)*a;f=Math.floor(e);e=e-f;c[0]=f===0?f:f-1;c[1]=f;c[2]=f>b.length-2?f:f+1;c[3]=f>b.length-3?f:f+2;f=b[c[0]];h=b[c[1]];i=b[c[2]];j=b[c[3]];c=e*e;g=e*c;d[0]=this.interpolate(f[0],h[0],i[0],j[0],e,c,g);d[1]=this.interpolate(f[1],h[1],i[1],j[1],e,c,g);d[2]=this.interpolate(f[2],h[2],i[2],j[2],e,c,g);return d};
THREE.Animation.prototype.interpolate=function(b,a,c,d,e,f,g){b=(c-b)*0.5;d=(d-a)*0.5;return(2*(a-c)+b+d)*g+(-3*(a-c)-2*b-d)*f+b*e+a};THREE.Animation.prototype.getNextKeyWith=function(b,a,c){for(var d=this.data.hierarchy[a].keys,c=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c<d.length-1?c:d.length-1:c%d.length;c<d.length;c++)if(d[c][b]!==void 0)return d[c];return this.data.hierarchy[a].keys[0]};
THREE.Animation.prototype.getPrevKeyWith=function(b,a,c){for(var d=this.data.hierarchy[a].keys,c=this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c>0?c:0:c>=0?c:c+d.length;c>=0;c--)if(d[c][b]!==void 0)return d[c];return this.data.hierarchy[a].keys[d.length-1]};
120
THREE.KeyFrameAnimation=function(b,a,c){this.root=b;this.data=THREE.AnimationHandler.get(a);this.hierarchy=THREE.AnimationHandler.parse(b);this.currentTime=0;this.timeScale=0.0010;this.isPlaying=false;this.loop=this.isPaused=true;this.JITCompile=c!==void 0?c:true;b=0;for(a=this.hierarchy.length;b<a;b++){var c=this.data.hierarchy[b].sids,d=this.hierarchy[b];if(this.data.hierarchy[b].keys.length&&c){for(var e=0;e<c.length;e++){var f=c[e],g=this.getNextKeyWith(f,b,0);g&&g.apply(f)}d.matrixAutoUpdate=
121 122 123 124 125
false;this.data.hierarchy[b].node.updateMatrix();d.matrixWorldNeedsUpdate=true}}};
THREE.KeyFrameAnimation.prototype.play=function(b,a){if(!this.isPlaying){this.isPlaying=true;this.loop=b!==void 0?b:true;this.currentTime=a!==void 0?a:0;this.startTimeMs=a;this.startTime=1E7;this.endTime=-this.startTime;var c,d=this.hierarchy.length,e,f;for(c=0;c<d;c++){e=this.hierarchy[c];f=this.data.hierarchy[c];e.useQuaternion=true;if(f.animationCache===void 0){f.animationCache={};f.animationCache.prevKey=null;f.animationCache.nextKey=null;f.animationCache.originalMatrix=e instanceof THREE.Bone?
e.skinMatrix:e.matrix}e=this.data.hierarchy[c].keys;if(e.length){f.animationCache.prevKey=e[0];f.animationCache.nextKey=e[1];this.startTime=Math.min(e[0].time,this.startTime);this.endTime=Math.max(e[e.length-1].time,this.endTime)}}this.update(0)}this.isPaused=false;THREE.AnimationHandler.addToUpdate(this)};THREE.KeyFrameAnimation.prototype.pause=function(){this.isPaused?THREE.AnimationHandler.addToUpdate(this):THREE.AnimationHandler.removeFromUpdate(this);this.isPaused=!this.isPaused};
THREE.KeyFrameAnimation.prototype.stop=function(){this.isPaused=this.isPlaying=false;THREE.AnimationHandler.removeFromUpdate(this);for(var b=0;b<this.data.hierarchy.length;b++){var a=this.hierarchy[b],c=this.data.hierarchy[b];if(c.animationCache!==void 0){var d=c.animationCache.originalMatrix;if(a instanceof THREE.Bone){d.copy(a.skinMatrix);a.skinMatrix=d}else{d.copy(a.matrix);a.matrix=d}delete c.animationCache}}};
THREE.KeyFrameAnimation.prototype.update=function(b){if(this.isPlaying){var a,c,d,e,f=this.data.JIT.hierarchy,g,h,i;h=this.currentTime=this.currentTime+b*this.timeScale;g=this.currentTime=this.currentTime%this.data.length;if(g<this.startTimeMs)g=this.currentTime=this.startTimeMs+g;e=parseInt(Math.min(g*this.data.fps,this.data.length*this.data.fps),10);if((i=g<h)&&!this.loop){for(var b=0,j=this.hierarchy.length;b<j;b++){var l=this.data.hierarchy[b].keys,f=this.data.hierarchy[b].sids;d=l.length-1;e=
126 127
this.hierarchy[b];if(l.length){for(l=0;l<f.length;l++){g=f[l];(h=this.getPrevKeyWith(g,b,d))&&h.apply(g)}this.data.hierarchy[b].node.updateMatrix();e.matrixWorldNeedsUpdate=true}}this.stop()}else if(!(g<this.startTime)){b=0;for(j=this.hierarchy.length;b<j;b++){d=this.hierarchy[b];a=this.data.hierarchy[b];var l=a.keys,m=a.animationCache;if(this.JITCompile&&f[b][e]!==void 0)if(d instanceof THREE.Bone){d.skinMatrix=f[b][e];d.matrixWorldNeedsUpdate=false}else{d.matrix=f[b][e];d.matrixWorldNeedsUpdate=
true}else if(l.length){if(this.JITCompile&&m)d instanceof THREE.Bone?d.skinMatrix=m.originalMatrix:d.matrix=m.originalMatrix;a=m.prevKey;c=m.nextKey;if(a&&c){if(c.time<=h){if(i&&this.loop){a=l[0];for(c=l[1];c.time<g;){a=c;c=l[a.index+1]}}else if(!i)for(var n=l.length-1;c.time<g&&c.index!==n;){a=c;c=l[a.index+1]}m.prevKey=a;m.nextKey=c}c.time>=g?a.interpolate(c,g):a.interpolate(c,c.time)}this.data.hierarchy[b].node.updateMatrix();d.matrixWorldNeedsUpdate=true}}if(this.JITCompile&&f[0][e]===void 0){this.hierarchy[0].updateMatrixWorld(true);
128 129 130
for(b=0;b<this.hierarchy.length;b++)f[b][e]=this.hierarchy[b]instanceof THREE.Bone?this.hierarchy[b].skinMatrix.clone():this.hierarchy[b].matrix.clone()}}}};THREE.KeyFrameAnimation.prototype.getNextKeyWith=function(b,a,c){a=this.data.hierarchy[a].keys;for(c=c%a.length;c<a.length;c++)if(a[c].hasTarget(b))return a[c];return a[0]};
THREE.KeyFrameAnimation.prototype.getPrevKeyWith=function(b,a,c){a=this.data.hierarchy[a].keys;for(c=c>=0?c:c+a.length;c>=0;c--)if(a[c].hasTarget(b))return a[c];return a[a.length-1]};
THREE.CubeCamera=function(b,a,c){THREE.Object3D.call(this);var d=new THREE.PerspectiveCamera(90,1,b,a);d.up.set(0,-1,0);d.lookAt(new THREE.Vector3(1,0,0));this.add(d);var e=new THREE.PerspectiveCamera(90,1,b,a);e.up.set(0,-1,0);e.lookAt(new THREE.Vector3(-1,0,0));this.add(e);var f=new THREE.PerspectiveCamera(90,1,b,a);f.up.set(0,0,1);f.lookAt(new THREE.Vector3(0,1,0));this.add(f);var g=new THREE.PerspectiveCamera(90,1,b,a);g.up.set(0,0,-1);g.lookAt(new THREE.Vector3(0,-1,0));this.add(g);var h=new THREE.PerspectiveCamera(90,
131 132
1,b,a);h.up.set(0,-1,0);h.lookAt(new THREE.Vector3(0,0,1));this.add(h);var i=new THREE.PerspectiveCamera(90,1,b,a);i.up.set(0,-1,0);i.lookAt(new THREE.Vector3(0,0,-1));this.add(i);this.renderTarget=new THREE.WebGLRenderTargetCube(c,c,{format:THREE.RGBFormat,magFilter:THREE.LinearFilter,minFilter:THREE.LinearFilter});this.updateCubeMap=function(a,b){var c=this.renderTarget,n=c.generateMipmaps;c.generateMipmaps=false;c.activeCubeFace=0;a.render(b,d,c);c.activeCubeFace=1;a.render(b,e,c);c.activeCubeFace=
2;a.render(b,f,c);c.activeCubeFace=3;a.render(b,g,c);c.activeCubeFace=4;a.render(b,h,c);c.generateMipmaps=n;c.activeCubeFace=5;a.render(b,i,c)}};THREE.CubeCamera.prototype=Object.create(THREE.Object3D.prototype);THREE.CombinedCamera=function(b,a,c,d,e,f,g){THREE.Camera.call(this);this.fov=c;this.left=-b/2;this.right=b/2;this.top=a/2;this.bottom=-a/2;this.cameraO=new THREE.OrthographicCamera(b/-2,b/2,a/2,a/-2,f,g);this.cameraP=new THREE.PerspectiveCamera(c,b/a,d,e);this.zoom=1;this.toPerspective()};
M
Mr.doob 已提交
133
THREE.CombinedCamera.prototype=Object.create(THREE.Camera.prototype);THREE.CombinedCamera.prototype.toPerspective=function(){this.near=this.cameraP.near;this.far=this.cameraP.far;this.cameraP.fov=this.fov/this.zoom;this.cameraP.updateProjectionMatrix();this.projectionMatrix=this.cameraP.projectionMatrix;this.inPerspectiveMode=true;this.inOrthographicMode=false};
134 135 136
THREE.CombinedCamera.prototype.toOrthographic=function(){var b=this.cameraP.aspect,a=(this.cameraP.near+this.cameraP.far)/2,a=Math.tan(this.fov/2)*a,b=2*a*b/2,a=a/this.zoom,b=b/this.zoom;this.cameraO.left=-b;this.cameraO.right=b;this.cameraO.top=a;this.cameraO.bottom=-a;this.cameraO.updateProjectionMatrix();this.near=this.cameraO.near;this.far=this.cameraO.far;this.projectionMatrix=this.cameraO.projectionMatrix;this.inPerspectiveMode=false;this.inOrthographicMode=true};
THREE.CombinedCamera.prototype.setSize=function(b,a){this.cameraP.aspect=b/a;this.left=-b/2;this.right=b/2;this.top=a/2;this.bottom=-a/2};THREE.CombinedCamera.prototype.setFov=function(b){this.fov=b;this.inPerspectiveMode?this.toPerspective():this.toOrthographic()};THREE.CombinedCamera.prototype.updateProjectionMatrix=function(){if(this.inPerspectiveMode)this.toPerspective();else{this.toPerspective();this.toOrthographic()}};
THREE.CombinedCamera.prototype.setLens=function(b,a){var c=2*Math.atan((a!==void 0?a:24)/(b*2))*(180/Math.PI);this.setFov(c);return c};THREE.CombinedCamera.prototype.setZoom=function(b){this.zoom=b;this.inPerspectiveMode?this.toPerspective():this.toOrthographic()};THREE.CombinedCamera.prototype.toFrontView=function(){this.rotation.x=0;this.rotation.y=0;this.rotation.z=0;this.rotationAutoUpdate=false};
137 138
THREE.CombinedCamera.prototype.toBackView=function(){this.rotation.x=0;this.rotation.y=Math.PI;this.rotation.z=0;this.rotationAutoUpdate=false};THREE.CombinedCamera.prototype.toLeftView=function(){this.rotation.x=0;this.rotation.y=-Math.PI/2;this.rotation.z=0;this.rotationAutoUpdate=false};THREE.CombinedCamera.prototype.toRightView=function(){this.rotation.x=0;this.rotation.y=Math.PI/2;this.rotation.z=0;this.rotationAutoUpdate=false};
THREE.CombinedCamera.prototype.toTopView=function(){this.rotation.x=-Math.PI/2;this.rotation.y=0;this.rotation.z=0;this.rotationAutoUpdate=false};THREE.CombinedCamera.prototype.toBottomView=function(){this.rotation.x=Math.PI/2;this.rotation.y=0;this.rotation.z=0;this.rotationAutoUpdate=false};
139
THREE.FirstPersonControls=function(b,a){function c(a,b){return function(){b.apply(a,arguments)}}this.object=b;this.target=new THREE.Vector3(0,0,0);this.domElement=a!==void 0?a:document;this.movementSpeed=1;this.lookSpeed=0.0050;this.lookVertical=true;this.autoForward=false;this.activeLook=true;this.heightSpeed=false;this.heightCoef=1;this.heightMin=0;this.heightMax=1;this.constrainVertical=false;this.verticalMin=0;this.verticalMax=Math.PI;this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=
140 141 142 143 144 145 146 147
this.autoSpeedFactor=0;this.mouseDragOn=this.freeze=this.moveRight=this.moveLeft=this.moveBackward=this.moveForward=false;this.viewHalfY=this.viewHalfX=0;this.domElement!==document&&this.domElement.setAttribute("tabindex",-1);this.handleResize=function(){if(this.domElement===document){this.viewHalfX=window.innerWidth/2;this.viewHalfY=window.innerHeight/2}else{this.viewHalfX=this.domElement.offsetWidth/2;this.viewHalfY=this.domElement.offsetHeight/2}};this.onMouseDown=function(a){this.domElement!==
document&&this.domElement.focus();a.preventDefault();a.stopPropagation();if(this.activeLook)switch(a.button){case 0:this.moveForward=true;break;case 2:this.moveBackward=true}this.mouseDragOn=true};this.onMouseUp=function(a){a.preventDefault();a.stopPropagation();if(this.activeLook)switch(a.button){case 0:this.moveForward=false;break;case 2:this.moveBackward=false}this.mouseDragOn=false};this.onMouseMove=function(a){if(this.domElement===document){this.mouseX=a.pageX-this.viewHalfX;this.mouseY=a.pageY-
this.viewHalfY}else{this.mouseX=a.pageX-this.domElement.offsetLeft-this.viewHalfX;this.mouseY=a.pageY-this.domElement.offsetTop-this.viewHalfY}};this.onKeyDown=function(a){switch(a.keyCode){case 38:case 87:this.moveForward=true;break;case 37:case 65:this.moveLeft=true;break;case 40:case 83:this.moveBackward=true;break;case 39:case 68:this.moveRight=true;break;case 82:this.moveUp=true;break;case 70:this.moveDown=true;break;case 81:this.freeze=!this.freeze}};this.onKeyUp=function(a){switch(a.keyCode){case 38:case 87:this.moveForward=
false;break;case 37:case 65:this.moveLeft=false;break;case 40:case 83:this.moveBackward=false;break;case 39:case 68:this.moveRight=false;break;case 82:this.moveUp=false;break;case 70:this.moveDown=false}};this.update=function(a){var b=0;if(!this.freeze){if(this.heightSpeed){b=THREE.Math.clamp(this.object.position.y,this.heightMin,this.heightMax)-this.heightMin;this.autoSpeedFactor=a*b*this.heightCoef}else this.autoSpeedFactor=0;b=a*this.movementSpeed;(this.moveForward||this.autoForward&&!this.moveBackward)&&
this.object.translateZ(-(b+this.autoSpeedFactor));this.moveBackward&&this.object.translateZ(b);this.moveLeft&&this.object.translateX(-b);this.moveRight&&this.object.translateX(b);this.moveUp&&this.object.translateY(b);this.moveDown&&this.object.translateY(-b);a=a*this.lookSpeed;this.activeLook||(a=0);this.lon=this.lon+this.mouseX*a;if(this.lookVertical)this.lat=this.lat-this.mouseY*a;this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*Math.PI/180;this.theta=this.lon*Math.PI/180;var b=
this.target,c=this.object.position;b.x=c.x+100*Math.sin(this.phi)*Math.cos(this.theta);b.y=c.y+100*Math.cos(this.phi);b.z=c.z+100*Math.sin(this.phi)*Math.sin(this.theta);b=1;this.constrainVertical&&(b=Math.PI/(this.verticalMax-this.verticalMin));this.lon=this.lon+this.mouseX*a;if(this.lookVertical)this.lat=this.lat-this.mouseY*a*b;this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*Math.PI/180;this.theta=this.lon*Math.PI/180;if(this.constrainVertical)this.phi=THREE.Math.mapLinear(this.phi,
0,Math.PI,this.verticalMin,this.verticalMax);b=this.target;c=this.object.position;b.x=c.x+100*Math.sin(this.phi)*Math.cos(this.theta);b.y=c.y+100*Math.cos(this.phi);b.z=c.z+100*Math.sin(this.phi)*Math.sin(this.theta);this.object.lookAt(b)}};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},false);this.domElement.addEventListener("mousemove",c(this,this.onMouseMove),false);this.domElement.addEventListener("mousedown",c(this,this.onMouseDown),false);this.domElement.addEventListener("mouseup",
c(this,this.onMouseUp),false);this.domElement.addEventListener("keydown",c(this,this.onKeyDown),false);this.domElement.addEventListener("keyup",c(this,this.onKeyUp),false);this.handleResize()};
148
THREE.PathControls=function(b,a){function c(a){return(a=a*2)<1?0.5*a*a:-0.5*(--a*(a-2)-1)}function d(a,b){return function(){b.apply(a,arguments)}}function e(a,b,c,d){var e={name:c,fps:0.6,length:d,hierarchy:[]},f,g=b.getControlPointsArray(),h=b.getLength(),p=g.length,s=0;f=p-1;b={parent:-1,keys:[]};b.keys[0]={time:0,pos:g[0],rot:[0,0,0,1],scl:[1,1,1]};b.keys[f]={time:d,pos:g[f],rot:[0,0,0,1],scl:[1,1,1]};for(f=1;f<p-1;f++){s=d*h.chunks[f]/h.total;b.keys[f]={time:s,pos:g[f]}}e.hierarchy[0]=b;THREE.AnimationHandler.add(e);
149
return new THREE.Animation(a,c,THREE.AnimationHandler.CATMULLROM_FORWARD,false)}function f(a,b){var c,d,e=new THREE.Geometry;for(c=0;c<a.points.length*b;c++){d=c/(a.points.length*b);d=a.getPoint(d);e.vertices[c]=new THREE.Vector3(d.x,d.y,d.z)}return e}this.object=b;this.domElement=a!==void 0?a:document;this.id="PathControls"+THREE.PathControlsIdCounter++;this.duration=1E4;this.waypoints=[];this.useConstantSpeed=true;this.resamplingCoef=50;this.debugPath=new THREE.Object3D;this.debugDummy=new THREE.Object3D;
150
this.animationParent=new THREE.Object3D;this.lookSpeed=0.0050;this.lookHorizontal=this.lookVertical=true;this.verticalAngleMap={srcRange:[0,2*Math.PI],dstRange:[0,2*Math.PI]};this.horizontalAngleMap={srcRange:[0,2*Math.PI],dstRange:[0,2*Math.PI]};this.target=new THREE.Object3D;this.theta=this.phi=this.lon=this.lat=this.mouseY=this.mouseX=0;var g=Math.PI*2,h=Math.PI/180;this.viewHalfY=this.viewHalfX=0;this.domElement!==document&&this.domElement.setAttribute("tabindex",-1);this.handleResize=function(){if(this.domElement===
151 152 153 154
document){this.viewHalfX=window.innerWidth/2;this.viewHalfY=window.innerHeight/2}else{this.viewHalfX=this.domElement.offsetWidth/2;this.viewHalfY=this.domElement.offsetHeight/2}};this.update=function(a){var b;if(this.lookHorizontal)this.lon=this.lon+this.mouseX*this.lookSpeed*a;if(this.lookVertical)this.lat=this.lat-this.mouseY*this.lookSpeed*a;this.lon=Math.max(0,Math.min(360,this.lon));this.lat=Math.max(-85,Math.min(85,this.lat));this.phi=(90-this.lat)*h;this.theta=this.lon*h;a=this.phi%g;this.phi=
a>=0?a:a+g;b=this.verticalAngleMap.srcRange;a=this.verticalAngleMap.dstRange;b=THREE.Math.mapLinear(this.phi,b[0],b[1],a[0],a[1]);var d=a[1]-a[0];this.phi=c((b-a[0])/d)*d+a[0];b=this.horizontalAngleMap.srcRange;a=this.horizontalAngleMap.dstRange;b=THREE.Math.mapLinear(this.theta,b[0],b[1],a[0],a[1]);d=a[1]-a[0];this.theta=c((b-a[0])/d)*d+a[0];a=this.target.position;a.x=100*Math.sin(this.phi)*Math.cos(this.theta);a.y=100*Math.cos(this.phi);a.z=100*Math.sin(this.phi)*Math.sin(this.theta);this.object.lookAt(this.target.position)};
this.onMouseMove=function(a){if(this.domElement===document){this.mouseX=a.pageX-this.viewHalfX;this.mouseY=a.pageY-this.viewHalfY}else{this.mouseX=a.pageX-this.domElement.offsetLeft-this.viewHalfX;this.mouseY=a.pageY-this.domElement.offsetTop-this.viewHalfY}};this.init=function(){this.spline=new THREE.Spline;this.spline.initFromArray(this.waypoints);this.useConstantSpeed&&this.spline.reparametrizeByArcLength(this.resamplingCoef);if(this.createDebugDummy){var a=new THREE.MeshLambertMaterial({color:30719}),
b=new THREE.MeshLambertMaterial({color:65280}),c=new THREE.CubeGeometry(10,10,20),g=new THREE.CubeGeometry(2,2,10);this.animationParent=new THREE.Mesh(c,a);a=new THREE.Mesh(g,b);a.position.set(0,10,0);this.animation=e(this.animationParent,this.spline,this.id,this.duration);this.animationParent.add(this.object);this.animationParent.add(this.target);this.animationParent.add(a)}else{this.animation=e(this.animationParent,this.spline,this.id,this.duration);this.animationParent.add(this.target);this.animationParent.add(this.object)}if(this.createDebugPath){var a=
155
this.debugPath,b=this.spline,g=f(b,10),c=f(b,10),h=new THREE.LineBasicMaterial({color:16711680,linewidth:3}),g=new THREE.Line(g,h),c=new THREE.ParticleSystem(c,new THREE.ParticleBasicMaterial({color:16755200,size:3}));g.scale.set(1,1,1);a.add(g);c.scale.set(1,1,1);a.add(c);for(var g=new THREE.SphereGeometry(1,16,8),h=new THREE.MeshBasicMaterial({color:65280}),k=0;k<b.points.length;k++){c=new THREE.Mesh(g,h);c.position.copy(b.points[k]);a.add(c)}}this.domElement.addEventListener("mousemove",d(this,
156
this.onMouseMove),false)};this.handleResize()};THREE.PathControlsIdCounter=0;
157
THREE.FlyControls=function(b,a){function c(a,b){return function(){b.apply(a,arguments)}}this.object=b;this.domElement=a!==void 0?a:document;a&&this.domElement.setAttribute("tabindex",-1);this.movementSpeed=1;this.rollSpeed=0.0050;this.autoForward=this.dragToLook=false;this.object.useQuaternion=true;this.tmpQuaternion=new THREE.Quaternion;this.mouseStatus=0;this.moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0};this.moveVector=
158
new THREE.Vector3(0,0,0);this.rotationVector=new THREE.Vector3(0,0,0);this.handleEvent=function(a){if(typeof this[a.type]=="function")this[a.type](a)};this.keydown=function(a){if(!a.altKey){switch(a.keyCode){case 16:this.movementSpeedMultiplier=0.1;break;case 87:this.moveState.forward=1;break;case 83:this.moveState.back=1;break;case 65:this.moveState.left=1;break;case 68:this.moveState.right=1;break;case 82:this.moveState.up=1;break;case 70:this.moveState.down=1;break;case 38:this.moveState.pitchUp=
159 160 161 162 163 164 165
1;break;case 40:this.moveState.pitchDown=1;break;case 37:this.moveState.yawLeft=1;break;case 39:this.moveState.yawRight=1;break;case 81:this.moveState.rollLeft=1;break;case 69:this.moveState.rollRight=1}this.updateMovementVector();this.updateRotationVector()}};this.keyup=function(a){switch(a.keyCode){case 16:this.movementSpeedMultiplier=1;break;case 87:this.moveState.forward=0;break;case 83:this.moveState.back=0;break;case 65:this.moveState.left=0;break;case 68:this.moveState.right=0;break;case 82:this.moveState.up=
0;break;case 70:this.moveState.down=0;break;case 38:this.moveState.pitchUp=0;break;case 40:this.moveState.pitchDown=0;break;case 37:this.moveState.yawLeft=0;break;case 39:this.moveState.yawRight=0;break;case 81:this.moveState.rollLeft=0;break;case 69:this.moveState.rollRight=0}this.updateMovementVector();this.updateRotationVector()};this.mousedown=function(a){this.domElement!==document&&this.domElement.focus();a.preventDefault();a.stopPropagation();if(this.dragToLook)this.mouseStatus++;else switch(a.button){case 0:this.object.moveForward=
true;break;case 2:this.object.moveBackward=true}};this.mousemove=function(a){if(!this.dragToLook||this.mouseStatus>0){var b=this.getContainerDimensions(),c=b.size[0]/2,g=b.size[1]/2;this.moveState.yawLeft=-(a.pageX-b.offset[0]-c)/c;this.moveState.pitchDown=(a.pageY-b.offset[1]-g)/g;this.updateRotationVector()}};this.mouseup=function(a){a.preventDefault();a.stopPropagation();if(this.dragToLook){this.mouseStatus--;this.moveState.yawLeft=this.moveState.pitchDown=0}else switch(a.button){case 0:this.moveForward=
false;break;case 2:this.moveBackward=false}this.updateRotationVector()};this.update=function(a){var b=a*this.movementSpeed,a=a*this.rollSpeed;this.object.translateX(this.moveVector.x*b);this.object.translateY(this.moveVector.y*b);this.object.translateZ(this.moveVector.z*b);this.tmpQuaternion.set(this.rotationVector.x*a,this.rotationVector.y*a,this.rotationVector.z*a,1).normalize();this.object.quaternion.multiplySelf(this.tmpQuaternion);this.object.matrix.setPosition(this.object.position);this.object.matrix.setRotationFromQuaternion(this.object.quaternion);
this.object.matrixWorldNeedsUpdate=true};this.updateMovementVector=function(){var a=this.moveState.forward||this.autoForward&&!this.moveState.back?1:0;this.moveVector.x=-this.moveState.left+this.moveState.right;this.moveVector.y=-this.moveState.down+this.moveState.up;this.moveVector.z=-a+this.moveState.back};this.updateRotationVector=function(){this.rotationVector.x=-this.moveState.pitchDown+this.moveState.pitchUp;this.rotationVector.y=-this.moveState.yawRight+this.moveState.yawLeft;this.rotationVector.z=
-this.moveState.rollRight+this.moveState.rollLeft};this.getContainerDimensions=function(){return this.domElement!=document?{size:[this.domElement.offsetWidth,this.domElement.offsetHeight],offset:[this.domElement.offsetLeft,this.domElement.offsetTop]}:{size:[window.innerWidth,window.innerHeight],offset:[0,0]}};this.domElement.addEventListener("mousemove",c(this,this.mousemove),false);this.domElement.addEventListener("mousedown",c(this,this.mousedown),false);this.domElement.addEventListener("mouseup",
c(this,this.mouseup),false);this.domElement.addEventListener("keydown",c(this,this.keydown),false);this.domElement.addEventListener("keyup",c(this,this.keyup),false);this.updateMovementVector();this.updateRotationVector()};
166 167
THREE.RollControls=function(b,a){this.object=b;this.domElement=a!==void 0?a:document;this.mouseLook=true;this.autoForward=false;this.rollSpeed=this.movementSpeed=this.lookSpeed=1;this.constrainVertical=[-0.9,0.9];this.object.matrixAutoUpdate=false;this.forward=new THREE.Vector3(0,0,1);this.roll=0;var c=new THREE.Vector3,d=new THREE.Vector3,e=new THREE.Vector3,f=new THREE.Matrix4,g=false,h=1,i=0,j=0,l=0,m=0,n=0,k=0,o=0;this.handleResize=function(){k=window.innerWidth/2;o=window.innerHeight/2};this.update=
function(a){if(this.mouseLook){var b=a*this.lookSpeed;this.rotateHorizontally(b*m);this.rotateVertically(b*n)}b=a*this.movementSpeed;this.object.translateZ(-b*(i>0||this.autoForward&&!(i<0)?1:i));this.object.translateX(b*j);this.object.translateY(b*l);if(g)this.roll=this.roll+this.rollSpeed*a*h;if(this.forward.y>this.constrainVertical[1]){this.forward.y=this.constrainVertical[1];this.forward.normalize()}else if(this.forward.y<this.constrainVertical[0]){this.forward.y=this.constrainVertical[0];this.forward.normalize()}e.copy(this.forward);
168 169
d.set(0,1,0);c.cross(d,e).normalize();d.cross(e,c).normalize();this.object.matrix.elements[0]=c.x;this.object.matrix.elements[4]=d.x;this.object.matrix.elements[8]=e.x;this.object.matrix.elements[1]=c.y;this.object.matrix.elements[5]=d.y;this.object.matrix.elements[9]=e.y;this.object.matrix.elements[2]=c.z;this.object.matrix.elements[6]=d.z;this.object.matrix.elements[10]=e.z;f.identity();f.elements[0]=Math.cos(this.roll);f.elements[4]=-Math.sin(this.roll);f.elements[1]=Math.sin(this.roll);f.elements[5]=
Math.cos(this.roll);this.object.matrix.multiplySelf(f);this.object.matrixWorldNeedsUpdate=true;this.object.matrix.elements[12]=this.object.position.x;this.object.matrix.elements[13]=this.object.position.y;this.object.matrix.elements[14]=this.object.position.z};this.translateX=function(a){this.object.position.x=this.object.position.x+this.object.matrix.elements[0]*a;this.object.position.y=this.object.position.y+this.object.matrix.elements[1]*a;this.object.position.z=this.object.position.z+this.object.matrix.elements[2]*
M
Mr.doob 已提交
170 171
a};this.translateY=function(a){this.object.position.x=this.object.position.x+this.object.matrix.elements[4]*a;this.object.position.y=this.object.position.y+this.object.matrix.elements[5]*a;this.object.position.z=this.object.position.z+this.object.matrix.elements[6]*a};this.translateZ=function(a){this.object.position.x=this.object.position.x-this.object.matrix.elements[8]*a;this.object.position.y=this.object.position.y-this.object.matrix.elements[9]*a;this.object.position.z=this.object.position.z-
this.object.matrix.elements[10]*a};this.rotateHorizontally=function(a){c.set(this.object.matrix.elements[0],this.object.matrix.elements[1],this.object.matrix.elements[2]);c.multiplyScalar(a);this.forward.subSelf(c);this.forward.normalize()};this.rotateVertically=function(a){d.set(this.object.matrix.elements[4],this.object.matrix.elements[5],this.object.matrix.elements[6]);d.multiplyScalar(a);this.forward.addSelf(d);this.forward.normalize()};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},
172
false);this.domElement.addEventListener("mousemove",function(a){m=(a.clientX-k)/window.innerWidth;n=(a.clientY-o)/window.innerHeight},false);this.domElement.addEventListener("mousedown",function(a){a.preventDefault();a.stopPropagation();switch(a.button){case 0:i=1;break;case 2:i=-1}},false);this.domElement.addEventListener("mouseup",function(a){a.preventDefault();a.stopPropagation();switch(a.button){case 0:i=0;break;case 2:i=0}},false);this.domElement.addEventListener("keydown",function(a){switch(a.keyCode){case 38:case 87:i=
173 174
1;break;case 37:case 65:j=-1;break;case 40:case 83:i=-1;break;case 39:case 68:j=1;break;case 81:g=true;h=1;break;case 69:g=true;h=-1;break;case 82:l=1;break;case 70:l=-1}},false);this.domElement.addEventListener("keyup",function(a){switch(a.keyCode){case 38:case 87:i=0;break;case 37:case 65:j=0;break;case 40:case 83:i=0;break;case 39:case 68:j=0;break;case 81:g=false;break;case 69:g=false;break;case 82:l=0;break;case 70:l=0}},false);this.handleResize()};
THREE.TrackballControls=function(b,a){THREE.EventTarget.call(this);var c=this;this.object=b;this.domElement=a!==void 0?a:document;this.enabled=true;this.screen={width:0,height:0,offsetLeft:0,offsetTop:0};this.radius=(this.screen.width+this.screen.height)/4;this.rotateSpeed=1;this.zoomSpeed=1.2;this.panSpeed=0.3;this.staticMoving=this.noPan=this.noZoom=this.noRotate=false;this.dynamicDampingFactor=0.2;this.minDistance=0;this.maxDistance=Infinity;this.keys=[65,83,68];this.target=new THREE.Vector3;var d=
175
new THREE.Vector3,e=false,f=-1,g=new THREE.Vector3,h=new THREE.Vector3,i=new THREE.Vector3,j=new THREE.Vector2,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,k={type:"change"};this.handleResize=function(){this.screen.width=window.innerWidth;this.screen.height=window.innerHeight;this.screen.offsetLeft=0;this.screen.offsetTop=0;this.radius=(this.screen.width+this.screen.height)/4};this.handleEvent=function(a){if(typeof this[a.type]=="function")this[a.type](a)};this.getMouseOnScreen=function(a,
176 177
b){return new THREE.Vector2((a-c.screen.offsetLeft)/c.radius*0.5,(b-c.screen.offsetTop)/c.radius*0.5)};this.getMouseProjectionOnBall=function(a,b){var d=new THREE.Vector3((a-c.screen.width*0.5-c.screen.offsetLeft)/c.radius,(c.screen.height*0.5+c.screen.offsetTop-b)/c.radius,0),e=d.length();e>1?d.normalize():d.z=Math.sqrt(1-e*e);g.copy(c.object.position).subSelf(c.target);e=c.object.up.clone().setLength(d.y);e.addSelf(c.object.up.clone().crossSelf(g).setLength(d.x));e.addSelf(g.setLength(d.z));return e};
this.rotateCamera=function(){var a=Math.acos(h.dot(i)/h.length()/i.length());if(a){var b=(new THREE.Vector3).cross(h,i).normalize(),d=new THREE.Quaternion,a=a*c.rotateSpeed;d.setFromAxisAngle(b,-a);d.multiplyVector3(g);d.multiplyVector3(c.object.up);d.multiplyVector3(i);if(c.staticMoving)h=i;else{d.setFromAxisAngle(b,a*(c.dynamicDampingFactor-1));d.multiplyVector3(h)}}};this.zoomCamera=function(){var a=1+(l.y-j.y)*c.zoomSpeed;if(a!==1&&a>0){g.multiplyScalar(a);c.staticMoving?j=l:j.y=j.y+(l.y-j.y)*
178 179 180 181
this.dynamicDampingFactor}};this.panCamera=function(){var a=n.clone().subSelf(m);if(a.lengthSq()){a.multiplyScalar(g.length()*c.panSpeed);var b=g.clone().crossSelf(c.object.up).setLength(a.x);b.addSelf(c.object.up.clone().setLength(a.y));c.object.position.addSelf(b);c.target.addSelf(b);c.staticMoving?m=n:m.addSelf(a.sub(n,m).multiplyScalar(c.dynamicDampingFactor))}};this.checkDistances=function(){if(!c.noZoom||!c.noPan){c.object.position.lengthSq()>c.maxDistance*c.maxDistance&&c.object.position.setLength(c.maxDistance);
g.lengthSq()<c.minDistance*c.minDistance&&c.object.position.add(c.target,g.setLength(c.minDistance))}};this.update=function(){g.copy(c.object.position).subSelf(c.target);c.noRotate||c.rotateCamera();c.noZoom||c.zoomCamera();c.noPan||c.panCamera();c.object.position.add(c.target,g);c.checkDistances();c.object.lookAt(c.target);if(d.distanceToSquared(c.object.position)>0){c.dispatchEvent(k);d.copy(c.object.position)}};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},false);
this.domElement.addEventListener("mousemove",function(a){if(c.enabled){if(e){h=i=c.getMouseProjectionOnBall(a.clientX,a.clientY);j=l=c.getMouseOnScreen(a.clientX,a.clientY);m=n=c.getMouseOnScreen(a.clientX,a.clientY);e=false}f!==-1&&(f===0&&!c.noRotate?i=c.getMouseProjectionOnBall(a.clientX,a.clientY):f===1&&!c.noZoom?l=c.getMouseOnScreen(a.clientX,a.clientY):f===2&&!c.noPan&&(n=c.getMouseOnScreen(a.clientX,a.clientY)))}},false);this.domElement.addEventListener("mousedown",function(a){if(c.enabled){a.preventDefault();
a.stopPropagation();if(f===-1){f=a.button;f===0&&!c.noRotate?h=i=c.getMouseProjectionOnBall(a.clientX,a.clientY):f===1&&!c.noZoom?j=l=c.getMouseOnScreen(a.clientX,a.clientY):this.noPan||(m=n=c.getMouseOnScreen(a.clientX,a.clientY))}}},false);this.domElement.addEventListener("mouseup",function(a){if(c.enabled){a.preventDefault();a.stopPropagation();f=-1}},false);window.addEventListener("keydown",function(a){if(c.enabled&&f===-1){a.keyCode===c.keys[0]&&!c.noRotate?f=0:a.keyCode===c.keys[1]&&!c.noZoom?
M
Mr.doob 已提交
182
f=1:a.keyCode===c.keys[2]&&!c.noPan&&(f=2);f!==-1&&(e=true)}},false);window.addEventListener("keyup",function(){c.enabled&&f!==-1&&(f=-1)},false);this.handleResize()};
183 184 185 186 187 188 189 190 191 192 193 194
THREE.OrbitControls=function(b,a){var c,d,e;function f(){return 2*Math.PI/60/60*i.autoRotateSpeed}function g(a){a.preventDefault();if(r===c){m.set(a.clientX,a.clientY);n.sub(m,l);i.rotateLeft(2*Math.PI*n.x/j*i.userRotateSpeed);i.rotateUp(2*Math.PI*n.y/j*i.userRotateSpeed);l.copy(m)}else if(r===d){o.set(a.clientX,a.clientY);q.sub(o,k);q.y>0?i.zoomIn():i.zoomOut();k.copy(o)}}function h(){if(i.userRotate){document.removeEventListener("mousemove",g,false);document.removeEventListener("mouseup",h,false);
r=e}}THREE.EventTarget.call(this);this.object=b;this.domElement=a!==void 0?a:document;this.center=new THREE.Vector3;this.userZoom=true;this.userZoomSpeed=1;this.userRotate=true;this.userRotateSpeed=1;this.autoRotate=false;this.autoRotateSpeed=2;var i=this,j=1800,l=new THREE.Vector2,m=new THREE.Vector2,n=new THREE.Vector2,k=new THREE.Vector2,o=new THREE.Vector2,q=new THREE.Vector2,p=0,s=0,u=1,t=new THREE.Vector3;e=-1;c=0;d=1;var r=e,v={type:"change"};this.rotateLeft=function(a){a===void 0&&(a=f());
s=s-a};this.rotateRight=function(a){a===void 0&&(a=f());s=s+a};this.rotateUp=function(a){a===void 0&&(a=f());p=p-a};this.rotateDown=function(a){a===void 0&&(a=f());p=p+a};this.zoomIn=function(a){a===void 0&&(a=Math.pow(0.95,i.userZoomSpeed));u=u/a};this.zoomOut=function(a){a===void 0&&(a=Math.pow(0.95,i.userZoomSpeed));u=u*a};this.update=function(){var a=this.object.position,b=a.clone().subSelf(this.center),c=Math.atan2(b.x,b.z),d=Math.atan2(Math.sqrt(b.x*b.x+b.z*b.z),b.y);this.autoRotate&&this.rotateLeft(f());
var c=c+s,d=d+p,d=Math.max(1.0E-6,Math.min(Math.PI-1.0E-6,d)),e=b.length();b.x=e*Math.sin(d)*Math.sin(c);b.y=e*Math.cos(d);b.z=e*Math.sin(d)*Math.cos(c);b.multiplyScalar(u);a.copy(this.center).addSelf(b);this.object.lookAt(this.center);p=s=0;u=1;if(t.distanceTo(this.object.position)>0){this.dispatchEvent(v);t.copy(this.object.position)}};this.domElement.addEventListener("contextmenu",function(a){a.preventDefault()},false);this.domElement.addEventListener("mousedown",function(a){if(i.userRotate){a.preventDefault();
if(a.button===0||a.button===2){r=c;l.set(a.clientX,a.clientY)}else if(a.button===1){r=d;k.set(a.clientX,a.clientY)}document.addEventListener("mousemove",g,false);document.addEventListener("mouseup",h,false)}},false);this.domElement.addEventListener("mousewheel",function(a){i.userZoom&&(a.wheelDelta>0?i.zoomOut():i.zoomIn())},false)};
THREE.CubeGeometry=function(b,a,c,d,e,f,g,h){function i(a,b,c,g,h,i,k,n){var m,l=d||1,o=e||1,q=h/2,p=i/2,s=j.vertices.length;if(a==="x"&&b==="y"||a==="y"&&b==="x")m="z";else if(a==="x"&&b==="z"||a==="z"&&b==="x"){m="y";o=f||1}else if(a==="z"&&b==="y"||a==="y"&&b==="z"){m="x";l=f||1}var t=l+1,u=o+1,I=h/l,M=i/o,J=new THREE.Vector3;J[m]=k>0?1:-1;for(h=0;h<u;h++)for(i=0;i<t;i++){var N=new THREE.Vector3;N[a]=(i*I-q)*c;N[b]=(h*M-p)*g;N[m]=k;j.vertices.push(N)}for(h=0;h<o;h++)for(i=0;i<l;i++){a=new THREE.Face4(i+
t*h+s,i+t*(h+1)+s,i+1+t*(h+1)+s,i+1+t*h+s);a.normal.copy(J);a.vertexNormals.push(J.clone(),J.clone(),J.clone(),J.clone());a.materialIndex=n;j.faces.push(a);j.faceVertexUvs[0].push([new THREE.UV(i/l,1-h/o),new THREE.UV(i/l,1-(h+1)/o),new THREE.UV((i+1)/l,1-(h+1)/o),new THREE.UV((i+1)/l,1-h/o)])}}THREE.Geometry.call(this);var j=this,l=b/2,m=a/2,n=c/2,k,o,q,p,s,u;if(g!==void 0){if(g instanceof Array)this.materials=g;else{this.materials=[];for(k=0;k<6;k++)this.materials.push(g)}k=0;p=1;o=2;s=3;q=4;u=
5}else this.materials=[];this.sides={px:true,nx:true,py:true,ny:true,pz:true,nz:true};if(h!=void 0)for(var t in h)this.sides[t]!==void 0&&(this.sides[t]=h[t]);this.sides.px&&i("z","y",-1,-1,c,a,l,k);this.sides.nx&&i("z","y",1,-1,c,a,-l,p);this.sides.py&&i("x","z",1,1,b,c,m,o);this.sides.ny&&i("x","z",1,-1,b,c,-m,s);this.sides.pz&&i("x","y",1,-1,b,a,n,q);this.sides.nz&&i("x","y",-1,-1,b,a,-n,u);this.computeCentroids();this.mergeVertices()};THREE.CubeGeometry.prototype=Object.create(THREE.Geometry.prototype);
THREE.CylinderGeometry=function(b,a,c,d,e,f){THREE.Geometry.call(this);var b=b!==void 0?b:20,a=a!==void 0?a:20,c=c!==void 0?c:100,g=c/2,d=d||8,e=e||1,h,i,j=[],l=[];for(i=0;i<=e;i++){var m=[],n=[],k=i/e,o=k*(a-b)+b;for(h=0;h<=d;h++){var q=h/d,p=new THREE.Vector3;p.x=o*Math.sin(q*Math.PI*2);p.y=-k*c+g;p.z=o*Math.cos(q*Math.PI*2);this.vertices.push(p);m.push(this.vertices.length-1);n.push(new THREE.UV(q,k))}j.push(m);l.push(n)}c=(a-b)/c;for(h=0;h<d;h++){if(b!==0){m=this.vertices[j[0][h]].clone();n=this.vertices[j[0][h+
1]].clone()}else{m=this.vertices[j[1][h]].clone();n=this.vertices[j[1][h+1]].clone()}m.setY(Math.sqrt(m.x*m.x+m.z*m.z)*c).normalize();n.setY(Math.sqrt(n.x*n.x+n.z*n.z)*c).normalize();for(i=0;i<e;i++){var k=j[i][h],o=j[i+1][h],q=j[i+1][h+1],p=j[i][h+1],s=m.clone(),u=m.clone(),t=n.clone(),r=n.clone(),v=l[i][h].clone(),z=l[i+1][h].clone(),A=l[i+1][h+1].clone(),x=l[i][h+1].clone();this.faces.push(new THREE.Face4(k,o,q,p,[s,u,t,r]));this.faceVertexUvs[0].push([v,z,A,x])}}if(!f&&b>0){this.vertices.push(new THREE.Vector3(0,
g,0));for(h=0;h<d;h++){k=j[0][h];o=j[0][h+1];q=this.vertices.length-1;s=new THREE.Vector3(0,1,0);u=new THREE.Vector3(0,1,0);t=new THREE.Vector3(0,1,0);v=l[0][h].clone();z=l[0][h+1].clone();A=new THREE.UV(z.u,0);this.faces.push(new THREE.Face3(k,o,q,[s,u,t]));this.faceVertexUvs[0].push([v,z,A])}}if(!f&&a>0){this.vertices.push(new THREE.Vector3(0,-g,0));for(h=0;h<d;h++){k=j[i][h+1];o=j[i][h];q=this.vertices.length-1;s=new THREE.Vector3(0,-1,0);u=new THREE.Vector3(0,-1,0);t=new THREE.Vector3(0,-1,0);
v=l[i][h+1].clone();z=l[i][h].clone();A=new THREE.UV(z.u,1);this.faces.push(new THREE.Face3(k,o,q,[s,u,t]));this.faceVertexUvs[0].push([v,z,A])}}this.computeCentroids();this.computeFaceNormals()};THREE.CylinderGeometry.prototype=Object.create(THREE.Geometry.prototype);THREE.ExtrudeGeometry=function(b,a){if(typeof b!=="undefined"){THREE.Geometry.call(this);b=b instanceof Array?b:[b];this.shapebb=b[b.length-1].getBoundingBox();this.addShapeList(b,a);this.computeCentroids();this.computeFaceNormals()}};
M
Mr.doob 已提交
195
THREE.ExtrudeGeometry.prototype=Object.create(THREE.Geometry.prototype);THREE.ExtrudeGeometry.prototype.addShapeList=function(b,a){for(var c=b.length,d=0;d<c;d++)this.addShape(b[d],a)};
196 197
THREE.ExtrudeGeometry.prototype.addShape=function(b,a){function c(a,b,c){b||console.log("die");return b.clone().multiplyScalar(c).addSelf(a)}function d(a,b,c){var d=THREE.ExtrudeGeometry.__v1,e=THREE.ExtrudeGeometry.__v2,f=THREE.ExtrudeGeometry.__v3,g=THREE.ExtrudeGeometry.__v4,h=THREE.ExtrudeGeometry.__v5,i=THREE.ExtrudeGeometry.__v6;d.set(a.x-b.x,a.y-b.y);e.set(a.x-c.x,a.y-c.y);d=d.normalize();e=e.normalize();f.set(-d.y,d.x);g.set(e.y,-e.x);h.copy(a).addSelf(f);i.copy(a).addSelf(g);if(h.equals(i))return g.clone();
h.copy(b).addSelf(f);i.copy(c).addSelf(g);f=d.dot(g);g=i.subSelf(h).dot(g);if(f===0){console.log("Either infinite or no solutions!");g===0?console.log("Its finite solutions."):console.log("Too bad, no solutions.")}g=g/f;if(g<0){b=Math.atan2(b.y-a.y,b.x-a.x);a=Math.atan2(c.y-a.y,c.x-a.x);b>a&&(a=a+Math.PI*2);c=(b+a)/2;a=-Math.cos(c);c=-Math.sin(c);a=new THREE.Vector2(a,c)}else a=d.multiplyScalar(g).addSelf(h).subSelf(a).clone();return a}function e(c,d){var e,f;for(y=c.length;--y>=0;){e=y;f=y-1;f<0&&
198 199 200 201 202 203 204
(f=c.length-1);for(var g=0,h=n+l*2,g=0;g<h;g++){var i=M*g,j=M*(g+1),k=d+e+i,i=d+f+i,m=d+f+j,j=d+e+j,o=c,q=g,p=h,s=e,r=f,k=k+E,i=i+E,m=m+E,j=j+E;B.faces.push(new THREE.Face4(k,i,m,j,null,null,u));k=t.generateSideWallUV(B,b,o,a,k,i,m,j,q,p,s,r);B.faceVertexUvs[0].push(k)}}}function f(a,b,c){B.vertices.push(new THREE.Vector3(a,b,c))}function g(c,d,e,f){c=c+E;d=d+E;e=e+E;B.faces.push(new THREE.Face3(c,d,e,null,null,s));c=f?t.generateBottomUV(B,b,a,c,d,e):t.generateTopUV(B,b,a,c,d,e);B.faceVertexUvs[0].push(c)}
var h=a.amount!==void 0?a.amount:100,i=a.bevelThickness!==void 0?a.bevelThickness:6,j=a.bevelSize!==void 0?a.bevelSize:i-2,l=a.bevelSegments!==void 0?a.bevelSegments:3,m=a.bevelEnabled!==void 0?a.bevelEnabled:true,n=a.steps!==void 0?a.steps:1,k=a.bendPath,o=a.extrudePath,q,p=false,s=a.material,u=a.extrudeMaterial,t=a.UVGenerator!==void 0?a.UVGenerator:THREE.ExtrudeGeometry.WorldUVGenerator,r,v,z,A;if(o){q=o.getSpacedPoints(n);p=true;m=false;r=a.frames!==void 0?a.frames:new THREE.TubeGeometry.FrenetFrames(o,
n,false);v=new THREE.Vector3;z=new THREE.Vector3;A=new THREE.Vector3}if(!m)j=i=l=0;var x,w,C,B=this,E=this.vertices.length;k&&b.addWrapPath(k);var o=b.extractPoints(),k=o.shape,G=o.holes;if(o=!THREE.Shape.Utils.isClockWise(k)){k=k.reverse();w=0;for(C=G.length;w<C;w++){x=G[w];THREE.Shape.Utils.isClockWise(x)&&(G[w]=x.reverse())}o=false}var L=THREE.Shape.Utils.triangulateShape(k,G),H=k;w=0;for(C=G.length;w<C;w++){x=G[w];k=k.concat(x)}var D,K,F,O,I,M=k.length,J,N=L.length,o=[],y=0;F=H.length;D=F-1;for(K=
y+1;y<F;y++,D++,K++){D===F&&(D=0);K===F&&(K=0);o[y]=d(H[y],H[D],H[K])}var Q=[],P,R=o.concat();w=0;for(C=G.length;w<C;w++){x=G[w];P=[];y=0;F=x.length;D=F-1;for(K=y+1;y<F;y++,D++,K++){D===F&&(D=0);K===F&&(K=0);P[y]=d(x[y],x[D],x[K])}Q.push(P);R=R.concat(P)}for(D=0;D<l;D++){F=D/l;O=i*(1-F);K=j*Math.sin(F*Math.PI/2);y=0;for(F=H.length;y<F;y++){I=c(H[y],o[y],K);f(I.x,I.y,-O)}w=0;for(C=G.length;w<C;w++){x=G[w];P=Q[w];y=0;for(F=x.length;y<F;y++){I=c(x[y],P[y],K);f(I.x,I.y,-O)}}}K=j;for(y=0;y<M;y++){I=m?
c(k[y],R[y],K):k[y];if(p){z.copy(r.normals[0]).multiplyScalar(I.x);v.copy(r.binormals[0]).multiplyScalar(I.y);A.copy(q[0]).addSelf(z).addSelf(v);f(A.x,A.y,A.z)}else f(I.x,I.y,0)}for(F=1;F<=n;F++)for(y=0;y<M;y++){I=m?c(k[y],R[y],K):k[y];if(p){z.copy(r.normals[F]).multiplyScalar(I.x);v.copy(r.binormals[F]).multiplyScalar(I.y);A.copy(q[F]).addSelf(z).addSelf(v);f(A.x,A.y,A.z)}else f(I.x,I.y,h/n*F)}for(D=l-1;D>=0;D--){F=D/l;O=i*(1-F);K=j*Math.sin(F*Math.PI/2);y=0;for(F=H.length;y<F;y++){I=c(H[y],o[y],
K);f(I.x,I.y,h+O)}w=0;for(C=G.length;w<C;w++){x=G[w];P=Q[w];y=0;for(F=x.length;y<F;y++){I=c(x[y],P[y],K);p?f(I.x,I.y+q[n-1].y,q[n-1].x+O):f(I.x,I.y,h+O)}}}(function(){if(m){var a;a=M*0;for(y=0;y<N;y++){J=L[y];g(J[2]+a,J[1]+a,J[0]+a,true)}a=n+l*2;a=M*a;for(y=0;y<N;y++){J=L[y];g(J[0]+a,J[1]+a,J[2]+a,false)}}else{for(y=0;y<N;y++){J=L[y];g(J[2],J[1],J[0],true)}for(y=0;y<N;y++){J=L[y];g(J[0]+M*n,J[1]+M*n,J[2]+M*n,false)}}})();(function(){var a=0;e(H,a);a=a+H.length;w=0;for(C=G.length;w<C;w++){x=G[w];e(x,
a);a=a+x.length}})()};
205
THREE.ExtrudeGeometry.WorldUVGenerator={generateTopUV:function(b,a,c,d,e,f){a=b.vertices[e].x;e=b.vertices[e].y;c=b.vertices[f].x;f=b.vertices[f].y;return[new THREE.UV(b.vertices[d].x,1-b.vertices[d].y),new THREE.UV(a,1-e),new THREE.UV(c,1-f)]},generateBottomUV:function(b,a,c,d,e,f){return this.generateTopUV(b,a,c,d,e,f)},generateSideWallUV:function(b,a,c,d,e,f,g,h){var a=b.vertices[e].x,c=b.vertices[e].y,e=b.vertices[e].z,d=b.vertices[f].x,i=b.vertices[f].y,f=b.vertices[f].z,j=b.vertices[g].x,l=
206
b.vertices[g].y,g=b.vertices[g].z,m=b.vertices[h].x,n=b.vertices[h].y,b=b.vertices[h].z;return Math.abs(c-i)<0.01?[new THREE.UV(a,e),new THREE.UV(d,f),new THREE.UV(j,g),new THREE.UV(m,b)]:[new THREE.UV(c,e),new THREE.UV(i,f),new THREE.UV(l,g),new THREE.UV(n,b)]}};THREE.ExtrudeGeometry.__v1=new THREE.Vector2;THREE.ExtrudeGeometry.__v2=new THREE.Vector2;THREE.ExtrudeGeometry.__v3=new THREE.Vector2;THREE.ExtrudeGeometry.__v4=new THREE.Vector2;THREE.ExtrudeGeometry.__v5=new THREE.Vector2;
207
THREE.ExtrudeGeometry.__v6=new THREE.Vector2;
208
THREE.LatheGeometry=function(b,a,c){THREE.Geometry.call(this);for(var a=a||12,c=c||2*Math.PI,d=[],e=(new THREE.Matrix4).makeRotationZ(c/a),f=0;f<b.length;f++){d[f]=b[f].clone();this.vertices.push(d[f])}for(var g=a+1,c=0;c<g;c++)for(f=0;f<d.length;f++){d[f]=e.multiplyVector3(d[f].clone());this.vertices.push(d[f])}for(c=0;c<a;c++){d=0;for(e=b.length;d<e-1;d++){this.faces.push(new THREE.Face4(c*e+d,(c+1)%g*e+d,(c+1)%g*e+(d+1)%e,c*e+(d+1)%e));this.faceVertexUvs[0].push([new THREE.UV(1-c/a,d/e),new THREE.UV(1-
M
Mr.doob 已提交
209
(c+1)/a,d/e),new THREE.UV(1-(c+1)/a,(d+1)/e),new THREE.UV(1-c/a,(d+1)/e)])}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.LatheGeometry.prototype=Object.create(THREE.Geometry.prototype);
210 211
THREE.PlaneGeometry=function(b,a,c,d){THREE.Geometry.call(this);for(var e=b/2,f=a/2,c=c||1,d=d||1,g=c+1,h=d+1,i=b/c,j=a/d,l=new THREE.Vector3(0,1,0),b=0;b<h;b++)for(a=0;a<g;a++)this.vertices.push(new THREE.Vector3(a*i-e,0,b*j-f));for(b=0;b<d;b++)for(a=0;a<c;a++){e=new THREE.Face4(a+g*b,a+g*(b+1),a+1+g*(b+1),a+1+g*b);e.normal.copy(l);e.vertexNormals.push(l.clone(),l.clone(),l.clone(),l.clone());this.faces.push(e);this.faceVertexUvs[0].push([new THREE.UV(a/c,1-b/d),new THREE.UV(a/c,1-(b+1)/d),new THREE.UV((a+
1)/c,1-(b+1)/d),new THREE.UV((a+1)/c,1-b/d)])}this.computeCentroids()};THREE.PlaneGeometry.prototype=Object.create(THREE.Geometry.prototype);
212 213 214
THREE.SphereGeometry=function(b,a,c,d,e,f,g){THREE.Geometry.call(this);var b=b||50,d=d!==void 0?d:0,e=e!==void 0?e:Math.PI*2,f=f!==void 0?f:0,g=g!==void 0?g:Math.PI,a=Math.max(3,Math.floor(a)||8),c=Math.max(2,Math.floor(c)||6),h,i,j=[],l=[];for(i=0;i<=c;i++){var m=[],n=[];for(h=0;h<=a;h++){var k=h/a,o=i/c,q=new THREE.Vector3;q.x=-b*Math.cos(d+k*e)*Math.sin(f+o*g);q.y=b*Math.cos(f+o*g);q.z=b*Math.sin(d+k*e)*Math.sin(f+o*g);this.vertices.push(q);m.push(this.vertices.length-1);n.push(new THREE.UV(k,
1-o))}j.push(m);l.push(n)}for(i=0;i<c;i++)for(h=0;h<a;h++){var d=j[i][h+1],e=j[i][h],f=j[i+1][h],g=j[i+1][h+1],m=this.vertices[d].clone().normalize(),n=this.vertices[e].clone().normalize(),k=this.vertices[f].clone().normalize(),o=this.vertices[g].clone().normalize(),q=l[i][h+1].clone(),p=l[i][h].clone(),s=l[i+1][h].clone(),u=l[i+1][h+1].clone();if(Math.abs(this.vertices[d].y)==b){this.faces.push(new THREE.Face3(d,f,g,[m,k,o]));this.faceVertexUvs[0].push([q,s,u])}else if(Math.abs(this.vertices[f].y)==
b){this.faces.push(new THREE.Face3(d,e,f,[m,n,k]));this.faceVertexUvs[0].push([q,p,s])}else{this.faces.push(new THREE.Face4(d,e,f,g,[m,n,k,o]));this.faceVertexUvs[0].push([q,p,s,u])}}this.computeCentroids();this.computeFaceNormals();this.boundingSphere={radius:b}};THREE.SphereGeometry.prototype=Object.create(THREE.Geometry.prototype);
M
Mr.doob 已提交
215
THREE.TextGeometry=function(b,a){var c=THREE.FontUtils.generateShapes(b,a);a.amount=a.height!==void 0?a.height:50;if(a.bevelThickness===void 0)a.bevelThickness=10;if(a.bevelSize===void 0)a.bevelSize=8;if(a.bevelEnabled===void 0)a.bevelEnabled=false;if(a.bend){var d=c[c.length-1].getBoundingBox().maxX;a.bendPath=new THREE.QuadraticBezierCurve(new THREE.Vector2(0,0),new THREE.Vector2(d/2,120),new THREE.Vector2(d,0))}THREE.ExtrudeGeometry.call(this,c,a)};THREE.TextGeometry.prototype=Object.create(THREE.ExtrudeGeometry.prototype);
216 217
THREE.TorusGeometry=function(b,a,c,d,e){THREE.Geometry.call(this);this.radius=b||100;this.tube=a||40;this.segmentsR=c||8;this.segmentsT=d||6;this.arc=e||Math.PI*2;e=new THREE.Vector3;b=[];a=[];for(c=0;c<=this.segmentsR;c++)for(d=0;d<=this.segmentsT;d++){var f=d/this.segmentsT*this.arc,g=c/this.segmentsR*Math.PI*2;e.x=this.radius*Math.cos(f);e.y=this.radius*Math.sin(f);var h=new THREE.Vector3;h.x=(this.radius+this.tube*Math.cos(g))*Math.cos(f);h.y=(this.radius+this.tube*Math.cos(g))*Math.sin(f);h.z=
this.tube*Math.sin(g);this.vertices.push(h);b.push(new THREE.UV(d/this.segmentsT,1-c/this.segmentsR));a.push(h.clone().subSelf(e).normalize())}for(c=1;c<=this.segmentsR;c++)for(d=1;d<=this.segmentsT;d++){var e=(this.segmentsT+1)*c+d-1,f=(this.segmentsT+1)*(c-1)+d-1,g=(this.segmentsT+1)*(c-1)+d,h=(this.segmentsT+1)*c+d,i=new THREE.Face4(e,f,g,h,[a[e],a[f],a[g],a[h]]);i.normal.addSelf(a[e]);i.normal.addSelf(a[f]);i.normal.addSelf(a[g]);i.normal.addSelf(a[h]);i.normal.normalize();this.faces.push(i);
M
Mr.doob 已提交
218
this.faceVertexUvs[0].push([b[e].clone(),b[f].clone(),b[g].clone(),b[h].clone()])}this.computeCentroids()};THREE.TorusGeometry.prototype=Object.create(THREE.Geometry.prototype);
219 220 221
THREE.TorusKnotGeometry=function(b,a,c,d,e,f,g){function h(a,b,c,d,e,f){var g=Math.cos(a);Math.cos(b);b=Math.sin(a);a=c/d*a;c=Math.cos(a);g=e*(2+c)*0.5*g;b=e*(2+c)*b*0.5;e=f*e*Math.sin(a)*0.5;return new THREE.Vector3(g,b,e)}THREE.Geometry.call(this);this.radius=b||200;this.tube=a||40;this.segmentsR=c||64;this.segmentsT=d||8;this.p=e||2;this.q=f||3;this.heightScale=g||1;this.grid=Array(this.segmentsR);c=new THREE.Vector3;d=new THREE.Vector3;e=new THREE.Vector3;for(b=0;b<this.segmentsR;++b){this.grid[b]=
Array(this.segmentsT);for(a=0;a<this.segmentsT;++a){var i=b/this.segmentsR*2*this.p*Math.PI,g=a/this.segmentsT*2*Math.PI,f=h(i,g,this.q,this.p,this.radius,this.heightScale),i=h(i+0.01,g,this.q,this.p,this.radius,this.heightScale);c.sub(i,f);d.add(i,f);e.cross(c,d);d.cross(e,c);e.normalize();d.normalize();i=-this.tube*Math.cos(g);g=this.tube*Math.sin(g);f.x=f.x+(i*d.x+g*e.x);f.y=f.y+(i*d.y+g*e.y);f.z=f.z+(i*d.z+g*e.z);this.grid[b][a]=this.vertices.push(new THREE.Vector3(f.x,f.y,f.z))-1}}for(b=0;b<
this.segmentsR;++b)for(a=0;a<this.segmentsT;++a){var e=(b+1)%this.segmentsR,f=(a+1)%this.segmentsT,c=this.grid[b][a],d=this.grid[e][a],e=this.grid[e][f],f=this.grid[b][f],g=new THREE.UV(b/this.segmentsR,a/this.segmentsT),i=new THREE.UV((b+1)/this.segmentsR,a/this.segmentsT),j=new THREE.UV((b+1)/this.segmentsR,(a+1)/this.segmentsT),l=new THREE.UV(b/this.segmentsR,(a+1)/this.segmentsT);this.faces.push(new THREE.Face4(c,d,e,f));this.faceVertexUvs[0].push([g,i,j,l])}this.computeCentroids();this.computeFaceNormals();
M
Mr.doob 已提交
222
this.computeVertexNormals()};THREE.TorusKnotGeometry.prototype=Object.create(THREE.Geometry.prototype);
223 224 225 226
THREE.TubeGeometry=function(b,a,c,d,e,f){THREE.Geometry.call(this);this.path=b;this.segments=a||64;this.radius=c||1;this.segmentsRadius=d||8;this.closed=e||false;if(f)this.debug=new THREE.Object3D;this.grid=[];var g,h,f=this.segments+1,i,j,l,m=new THREE.Vector3,n,k,o,a=new THREE.TubeGeometry.FrenetFrames(b,a,e);n=a.tangents;k=a.normals;o=a.binormals;this.tangents=n;this.normals=k;this.binormals=o;for(a=0;a<f;a++){this.grid[a]=[];d=a/(f-1);l=b.getPointAt(d);d=n[a];g=k[a];h=o[a];if(this.debug){this.debug.add(new THREE.ArrowHelper(d,
l,c,255));this.debug.add(new THREE.ArrowHelper(g,l,c,16711680));this.debug.add(new THREE.ArrowHelper(h,l,c,65280))}for(d=0;d<this.segmentsRadius;d++){i=d/this.segmentsRadius*2*Math.PI;j=-this.radius*Math.cos(i);i=this.radius*Math.sin(i);m.copy(l);m.x=m.x+(j*g.x+i*h.x);m.y=m.y+(j*g.y+i*h.y);m.z=m.z+(j*g.z+i*h.z);this.grid[a][d]=this.vertices.push(new THREE.Vector3(m.x,m.y,m.z))-1}}for(a=0;a<this.segments;a++)for(d=0;d<this.segmentsRadius;d++){f=e?(a+1)%this.segments:a+1;m=(d+1)%this.segmentsRadius;
b=this.grid[a][d];c=this.grid[f][d];f=this.grid[f][m];m=this.grid[a][m];n=new THREE.UV(a/this.segments,d/this.segmentsRadius);k=new THREE.UV((a+1)/this.segments,d/this.segmentsRadius);o=new THREE.UV((a+1)/this.segments,(d+1)/this.segmentsRadius);g=new THREE.UV(a/this.segments,(d+1)/this.segmentsRadius);this.faces.push(new THREE.Face4(b,c,f,m));this.faceVertexUvs[0].push([n,k,o,g])}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.TubeGeometry.prototype=Object.create(THREE.Geometry.prototype);
THREE.TubeGeometry.FrenetFrames=function(b,a,c){new THREE.Vector3;var d=new THREE.Vector3;new THREE.Vector3;var e=[],f=[],g=[],h=new THREE.Vector3,i=new THREE.Matrix4,a=a+1,j,l,m;this.tangents=e;this.normals=f;this.binormals=g;for(j=0;j<a;j++){l=j/(a-1);e[j]=b.getTangentAt(l);e[j].normalize()}f[0]=new THREE.Vector3;g[0]=new THREE.Vector3;b=Number.MAX_VALUE;j=Math.abs(e[0].x);l=Math.abs(e[0].y);m=Math.abs(e[0].z);if(j<=b){b=j;d.set(1,0,0)}if(l<=b){b=l;d.set(0,1,0)}m<=b&&d.set(0,0,1);h.cross(e[0],d).normalize();
227 228
f[0].cross(e[0],h);g[0].cross(e[0],f[0]);for(j=1;j<a;j++){f[j]=f[j-1].clone();g[j]=g[j-1].clone();h.cross(e[j-1],e[j]);if(h.length()>1.0E-4){h.normalize();d=Math.acos(e[j-1].dot(e[j]));i.makeRotationAxis(h,d).multiplyVector3(f[j])}g[j].cross(e[j],f[j])}if(c){d=Math.acos(f[0].dot(f[a-1]));d=d/(a-1);e[0].dot(h.cross(f[0],f[a-1]))>0&&(d=-d);for(j=1;j<a;j++){i.makeRotationAxis(e[j],d*j).multiplyVector3(f[j]);g[j].cross(e[j],f[j])}}};
THREE.PolyhedronGeometry=function(b,a,c,d){function e(a){var b=a.normalize().clone();b.index=i.vertices.push(b)-1;var c=Math.atan2(a.z,-a.x)/2/Math.PI+0.5,a=Math.atan2(-a.y,Math.sqrt(a.x*a.x+a.z*a.z))/Math.PI+0.5;b.uv=new THREE.UV(c,a);return b}function f(a,b,c,d){if(d<1){d=new THREE.Face3(a.index,b.index,c.index,[a.clone(),b.clone(),c.clone()]);d.centroid.addSelf(a).addSelf(b).addSelf(c).divideScalar(3);d.normal=d.centroid.clone().normalize();i.faces.push(d);d=Math.atan2(d.centroid.z,-d.centroid.x);
229 230
i.faceVertexUvs[0].push([h(a.uv,a,d),h(b.uv,b,d),h(c.uv,c,d)])}else{d=d-1;f(a,g(a,b),g(a,c),d);f(g(a,b),b,g(b,c),d);f(g(a,c),g(b,c),c,d);f(g(a,b),g(b,c),g(a,c),d)}}function g(a,b){m[a.index]||(m[a.index]=[]);m[b.index]||(m[b.index]=[]);var c=m[a.index][b.index];c===void 0&&(m[a.index][b.index]=m[b.index][a.index]=c=e((new THREE.Vector3).add(a,b).divideScalar(2)));return c}function h(a,b,c){c<0&&a.u===1&&(a=new THREE.UV(a.u-1,a.v));b.x===0&&b.z===0&&(a=new THREE.UV(c/2/Math.PI+0.5,a.v));return a}THREE.Geometry.call(this);
for(var c=c||1,d=d||0,i=this,j=0,l=b.length;j<l;j++)e(new THREE.Vector3(b[j][0],b[j][1],b[j][2]));for(var m=[],b=this.vertices,j=0,l=a.length;j<l;j++)f(b[a[j][0]],b[a[j][1]],b[a[j][2]],d);this.mergeVertices();j=0;for(l=this.vertices.length;j<l;j++)this.vertices[j].multiplyScalar(c);this.computeCentroids();this.boundingSphere={radius:c}};THREE.PolyhedronGeometry.prototype=Object.create(THREE.Geometry.prototype);
M
Mr.doob 已提交
231 232
THREE.IcosahedronGeometry=function(b,a){var c=(1+Math.sqrt(5))/2;THREE.PolyhedronGeometry.call(this,[[-1,c,0],[1,c,0],[-1,-c,0],[1,-c,0],[0,-1,c],[0,1,c],[0,-1,-c],[0,1,-c],[c,0,-1],[c,0,1],[-c,0,-1],[-c,0,1]],[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]],b,a)};THREE.IcosahedronGeometry.prototype=Object.create(THREE.Geometry.prototype);
THREE.OctahedronGeometry=function(b,a){THREE.PolyhedronGeometry.call(this,[[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]],[[0,2,4],[0,4,3],[0,3,5],[0,5,2],[1,2,5],[1,5,3],[1,3,4],[1,4,2]],b,a)};THREE.OctahedronGeometry.prototype=Object.create(THREE.Geometry.prototype);THREE.TetrahedronGeometry=function(b,a){THREE.PolyhedronGeometry.call(this,[[1,1,1],[-1,-1,1],[-1,1,-1],[1,-1,-1]],[[2,1,0],[0,3,2],[1,3,0],[2,3,1]],b,a)};THREE.TetrahedronGeometry.prototype=Object.create(THREE.Geometry.prototype);
233 234 235 236
THREE.ParametricGeometry=function(b,a,c,d){THREE.Geometry.call(this);var e=this.vertices,f=this.faces,g=this.faceVertexUvs[0],d=d===void 0?false:d,h,i,j,l,m=a+1;for(h=0;h<=c;h++){l=h/c;for(i=0;i<=a;i++){j=i/a;j=b(j,l);e.push(j)}}var n,k,o,q;for(h=0;h<c;h++)for(i=0;i<a;i++){b=h*m+i;e=h*m+i+1;l=(h+1)*m+i;j=(h+1)*m+i+1;n=new THREE.UV(i/a,h/c);k=new THREE.UV((i+1)/a,h/c);o=new THREE.UV(i/a,(h+1)/c);q=new THREE.UV((i+1)/a,(h+1)/c);if(d){f.push(new THREE.Face3(b,e,l));f.push(new THREE.Face3(e,j,l));g.push([n,
k,o]);g.push([k,q,o])}else{f.push(new THREE.Face4(b,e,j,l));g.push([n,k,q,o])}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.ParametricGeometry.prototype=Object.create(THREE.Geometry.prototype);
THREE.ConvexGeometry=function(b){function a(a){var d=b[a].clone(),f=d.length();d.x=d.x+f*c();d.y=d.y+f*c();d.z=d.z+f*c();for(var f=[],g=0;g<e.length;){var h=e[g],i=d,j=b[h[0]],s;s=j;var u=b[h[1]],t=b[h[2]],r=new THREE.Vector3,v=new THREE.Vector3;r.sub(t,u);v.sub(s,u);r.crossSelf(v);r.isZero()||r.normalize();s=r;j=s.dot(j);if(s.dot(i)>=j){for(i=0;i<3;i++){j=[h[i],h[(i+1)%3]];s=true;for(u=0;u<f.length;u++)if(f[u][0]===j[1]&&f[u][1]===j[0]){f[u]=f[f.length-1];f.pop();s=false;break}s&&f.push(j)}e[g]=
e[e.length-1];e.pop()}else g++}for(u=0;u<f.length;u++)e.push([f[u][0],f[u][1],a])}function c(){return(Math.random()-0.5)*2.0E-6}function d(a){var b=a.length();return new THREE.UV(a.x/b,a.y/b)}THREE.Geometry.call(this);for(var e=[[0,1,2],[0,2,1]],f=3;f<b.length;f++)a(f);for(var g=0,h=Array(b.length),f=0;f<e.length;f++)for(var i=e[f],j=0;j<3;j++){if(h[i[j]]===void 0){h[i[j]]=g++;this.vertices.push(b[i[j]])}i[j]=h[i[j]]}for(f=0;f<e.length;f++)this.faces.push(new THREE.Face3(e[f][0],e[f][1],e[f][2]));
M
Mr.doob 已提交
237
for(f=0;f<this.faces.length;f++){i=this.faces[f];this.faceVertexUvs[0].push([d(this.vertices[i.a]),d(this.vertices[i.b]),d(this.vertices[i.c])])}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};THREE.ConvexGeometry.prototype=Object.create(THREE.Geometry.prototype);
238
THREE.AxisHelper=function(){THREE.Object3D.call(this);var b=new THREE.Geometry;b.vertices.push(new THREE.Vector3);b.vertices.push(new THREE.Vector3(0,100,0));var a=new THREE.CylinderGeometry(0,5,25,5,1),c;c=new THREE.Line(b,new THREE.LineBasicMaterial({color:16711680}));c.rotation.z=-Math.PI/2;this.add(c);c=new THREE.Mesh(a,new THREE.MeshBasicMaterial({color:16711680}));c.position.x=100;c.rotation.z=-Math.PI/2;this.add(c);c=new THREE.Line(b,new THREE.LineBasicMaterial({color:65280}));this.add(c);
M
Mr.doob 已提交
239
c=new THREE.Mesh(a,new THREE.MeshBasicMaterial({color:65280}));c.position.y=100;this.add(c);c=new THREE.Line(b,new THREE.LineBasicMaterial({color:255}));c.rotation.x=Math.PI/2;this.add(c);c=new THREE.Mesh(a,new THREE.MeshBasicMaterial({color:255}));c.position.z=100;c.rotation.x=Math.PI/2;this.add(c)};THREE.AxisHelper.prototype=Object.create(THREE.Object3D.prototype);
240
THREE.ArrowHelper=function(b,a,c,d){THREE.Object3D.call(this);d===void 0&&(d=16776960);c===void 0&&(c=20);var e=new THREE.Geometry;e.vertices.push(new THREE.Vector3(0,0,0));e.vertices.push(new THREE.Vector3(0,1,0));this.line=new THREE.Line(e,new THREE.LineBasicMaterial({color:d}));this.add(this.line);e=new THREE.CylinderGeometry(0,0.05,0.25,5,1);this.cone=new THREE.Mesh(e,new THREE.MeshBasicMaterial({color:d}));this.cone.position.set(0,1,0);this.add(this.cone);if(a instanceof THREE.Vector3)this.position=
M
Mr.doob 已提交
241 242
a;this.setDirection(b);this.setLength(c)};THREE.ArrowHelper.prototype=Object.create(THREE.Object3D.prototype);THREE.ArrowHelper.prototype.setDirection=function(b){var a=(new THREE.Vector3(0,1,0)).crossSelf(b),b=Math.acos((new THREE.Vector3(0,1,0)).dot(b.clone().normalize()));this.matrix=(new THREE.Matrix4).makeRotationAxis(a.normalize(),b);this.rotation.setEulerFromRotationMatrix(this.matrix,this.eulerOrder)};THREE.ArrowHelper.prototype.setLength=function(b){this.scale.set(b,b,b)};
THREE.ArrowHelper.prototype.setColor=function(b){this.line.material.color.setHex(b);this.cone.material.color.setHex(b)};
243 244
THREE.CameraHelper=function(b){function a(a,b,d){c(a,d);c(b,d)}function c(a,b){d.lineGeometry.vertices.push(new THREE.Vector3);d.lineGeometry.colors.push(new THREE.Color(b));d.pointMap[a]===void 0&&(d.pointMap[a]=[]);d.pointMap[a].push(d.lineGeometry.vertices.length-1)}THREE.Object3D.call(this);var d=this;this.lineGeometry=new THREE.Geometry;this.lineMaterial=new THREE.LineBasicMaterial({color:16777215,vertexColors:THREE.FaceColors});this.pointMap={};a("n1","n2",16755200);a("n2","n4",16755200);a("n4",
"n3",16755200);a("n3","n1",16755200);a("f1","f2",16755200);a("f2","f4",16755200);a("f4","f3",16755200);a("f3","f1",16755200);a("n1","f1",16755200);a("n2","f2",16755200);a("n3","f3",16755200);a("n4","f4",16755200);a("p","n1",16711680);a("p","n2",16711680);a("p","n3",16711680);a("p","n4",16711680);a("u1","u2",43775);a("u2","u3",43775);a("u3","u1",43775);a("c","t",16777215);a("p","c",3355443);a("cn1","cn2",3355443);a("cn3","cn4",3355443);a("cf1","cf2",3355443);a("cf3","cf4",3355443);this.camera=b;this.update(b);
M
Mr.doob 已提交
245
this.lines=new THREE.Line(this.lineGeometry,this.lineMaterial,THREE.LinePieces);this.add(this.lines)};THREE.CameraHelper.prototype=Object.create(THREE.Object3D.prototype);
246 247
THREE.CameraHelper.prototype.update=function(){function b(b,d,e,f){THREE.CameraHelper.__v.set(d,e,f);THREE.CameraHelper.__projector.unprojectVector(THREE.CameraHelper.__v,THREE.CameraHelper.__c);b=a.pointMap[b];if(b!==void 0){d=0;for(e=b.length;d<e;d++)a.lineGeometry.vertices[b[d]].copy(THREE.CameraHelper.__v)}}var a=this;THREE.CameraHelper.__c.projectionMatrix.copy(this.camera.projectionMatrix);b("c",0,0,-1);b("t",0,0,1);b("n1",-1,-1,-1);b("n2",1,-1,-1);b("n3",-1,1,-1);b("n4",1,1,-1);b("f1",-1,-1,
1);b("f2",1,-1,1);b("f3",-1,1,1);b("f4",1,1,1);b("u1",0.7,1.1,-1);b("u2",-0.7,1.1,-1);b("u3",0,2,-1);b("cf1",-1,0,1);b("cf2",1,0,1);b("cf3",0,-1,1);b("cf4",0,1,1);b("cn1",-1,0,-1);b("cn2",1,0,-1);b("cn3",0,-1,-1);b("cn4",0,1,-1);this.lineGeometry.verticesNeedUpdate=true};THREE.CameraHelper.__projector=new THREE.Projector;THREE.CameraHelper.__v=new THREE.Vector3;THREE.CameraHelper.__c=new THREE.Camera;
M
Mr.doob 已提交
248
THREE.SubdivisionModifier=function(b){this.subdivisions=b===void 0?1:b;this.useOldVertexColors=false;this.supportUVs=true;this.debug=false};THREE.SubdivisionModifier.prototype.modify=function(b){for(var a=this.subdivisions;a-- >0;)this.smooth(b)};
249 250 251 252 253 254 255 256 257
THREE.SubdivisionModifier.prototype.smooth=function(b){function a(){n.debug&&console.log.apply(console,arguments)}function c(){console&&console.log.apply(console,arguments)}function d(b,c,d,e,g,h,i){var j=new THREE.Face4(b,c,d,e,null,g.color,g.materialIndex);if(n.useOldVertexColors){j.vertexColors=[];for(var k,o,p,q=0;q<4;q++){p=h[q];k=new THREE.Color;k.setRGB(0,0,0);for(var r=0;r<p.length;r++){o=g.vertexColors[p[r]-1];k.r=k.r+o.r;k.g=k.g+o.g;k.b=k.b+o.b}k.r=k.r/p.length;k.g=k.g/p.length;k.b=k.b/
p.length;j.vertexColors[q]=k}}l.push(j);if(n.supportUVs){g=[f(b,""),f(c,i),f(d,i),f(e,i)];g[0]?g[1]?g[2]?g[3]?m.push(g):a("d :( ",e+":"+i):a("c :( ",d+":"+i):a("b :( ",c+":"+i):a("a :( ",b+":"+i)}}function e(a,b){return Math.min(a,b)+"_"+Math.max(a,b)}function f(b,d){var e=b+":"+d,f=u[e];if(!f){b>=t&&b<t+o.length?a("face pt"):a("edge pt");c("warning, UV not found for",e);return null}return f}function g(a,b,d){var e=a+":"+b;e in u?c("dup vertexNo",a,"oldFaceNo",b,"value",d,"key",e,u[e]):u[e]=d}function h(a,
b){G[a]===void 0&&(G[a]=[]);G[a].push(b)}function i(a,b,c){L[a]===void 0&&(L[a]={});L[a][b]=c}var j=[],l=[],m=[],n=this,k=b.vertices,o=b.faces,j=k.concat(),q=[],p={},s={},u={},t=k.length,r,v,z,A,x,w=b.faceVertexUvs[0],C;a("originalFaces, uvs, originalVerticesLength",o.length,w.length,t);if(n.supportUVs){r=0;for(v=w.length;r<v;r++){z=0;for(A=w[r].length;z<A;z++){C=o[r]["abcd".charAt(z)];g(C,r,w[r][z])}}}if(w.length==0)n.supportUVs=false;r=0;for(x in u)r++;if(!r){n.supportUVs=false;a("no uvs")}a("-- Original Faces + Vertices UVs completed",
u,"vs",w.length);r=0;for(v=o.length;r<v;r++){x=o[r];q.push(x.centroid);j.push(x.centroid);if(n.supportUVs){w=new THREE.UV;if(x instanceof THREE.Face3){w.u=f(x.a,r).u+f(x.b,r).u+f(x.c,r).u;w.v=f(x.a,r).v+f(x.b,r).v+f(x.c,r).v;w.u=w.u/3;w.v=w.v/3}else if(x instanceof THREE.Face4){w.u=f(x.a,r).u+f(x.b,r).u+f(x.c,r).u+f(x.d,r).u;w.v=f(x.a,r).v+f(x.b,r).v+f(x.c,r).v+f(x.d,r).v;w.u=w.u/4;w.v=w.v/4}g(t+r,"",w)}}a("-- added UVs for new Faces",u);v=function(a){function b(a,c){h[a]===void 0&&(h[a]=[]);h[a].push(c)}
var c,d,f,g,h={};c=0;for(d=a.faces.length;c<d;c++){f=a.faces[c];if(f instanceof THREE.Face3){g=e(f.a,f.b);b(g,c);g=e(f.b,f.c);b(g,c);g=e(f.c,f.a);b(g,c)}else if(f instanceof THREE.Face4){g=e(f.a,f.b);b(g,c);g=e(f.b,f.c);b(g,c);g=e(f.c,f.d);b(g,c);g=e(f.d,f.a);b(g,c)}}return h}(b);C=0;var B,E,G={},L={};for(r in v){w=v[r];B=r.split("_");E=B[0];B=B[1];h(E,[E,B]);h(B,[E,B]);z=0;for(A=w.length;z<A;z++){x=w[z];i(E,x,r);i(B,x,r)}w.length<2&&(s[r]=true)}a("vertexEdgeMap",G,"vertexFaceMap",L);for(r in v){w=
v[r];x=w[0];A=w[1];B=r.split("_");E=B[0];B=B[1];w=new THREE.Vector3;if(s[r]){w.addSelf(k[E]);w.addSelf(k[B]);w.multiplyScalar(0.5)}else{w.addSelf(q[x]);w.addSelf(q[A]);w.addSelf(k[E]);w.addSelf(k[B]);w.multiplyScalar(0.25)}p[r]=t+o.length+C;j.push(w);C++;if(n.supportUVs){w=new THREE.UV;w.u=f(E,x).u+f(B,x).u;w.v=f(E,x).v+f(B,x).v;w.u=w.u/2;w.v=w.v/2;g(p[r],x,w);if(!s[r]){w=new THREE.UV;w.u=f(E,A).u+f(B,A).u;w.v=f(E,A).v+f(B,A).v;w.u=w.u/2;w.v=w.v/2;g(p[r],A,w)}}}a("-- Step 2 done");var H,D;A=["123",
"12","2","23"];B=["123","23","3","31"];var K=["123","31","1","12"],F=["1234","12","2","23"],O=["1234","23","3","34"],I=["1234","34","4","41"],M=["1234","41","1","12"];r=0;for(v=q.length;r<v;r++){x=o[r];w=t+r;if(x instanceof THREE.Face3){C=e(x.a,x.b);E=e(x.b,x.c);H=e(x.c,x.a);d(w,p[C],x.b,p[E],x,A,r);d(w,p[E],x.c,p[H],x,B,r);d(w,p[H],x.a,p[C],x,K,r)}else if(x instanceof THREE.Face4){C=e(x.a,x.b);E=e(x.b,x.c);H=e(x.c,x.d);D=e(x.d,x.a);d(w,p[C],x.b,p[E],x,F,r);d(w,p[E],x.c,p[H],x,O,r);d(w,p[H],x.d,p[D],
x,I,r);d(w,p[D],x.a,p[C],x,M,r)}else a("face should be a face!",x)}p=new THREE.Vector3;x=new THREE.Vector3;r=0;for(v=k.length;r<v;r++)if(G[r]!==void 0){p.set(0,0,0);x.set(0,0,0);E=new THREE.Vector3(0,0,0);w=0;for(z in L[r]){p.addSelf(q[z]);w++}A=0;C=G[r].length;for(z=0;z<C;z++)s[e(G[r][z][0],G[r][z][1])]&&A++;if(A!=2){p.divideScalar(w);for(z=0;z<C;z++){w=G[r][z];w=k[w[0]].clone().addSelf(k[w[1]]).divideScalar(2);x.addSelf(w)}x.divideScalar(C);E.addSelf(k[r]);E.multiplyScalar(C-3);E.addSelf(p);E.addSelf(x.multiplyScalar(2));
E.divideScalar(C);j[r]=E}}b.vertices=j;b.faces=l;b.faceVertexUvs[0]=m;delete b.__tmpVertices;b.computeCentroids();b.computeFaceNormals();b.computeVertexNormals()};THREE.ImmediateRenderObject=function(){THREE.Object3D.call(this);this.render=function(){}};THREE.ImmediateRenderObject.prototype=Object.create(THREE.Object3D.prototype);
M
Mr.doob 已提交
258
THREE.LensFlare=function(b,a,c,d,e){THREE.Object3D.call(this);this.lensFlares=[];this.positionScreen=new THREE.Vector3;this.customUpdateCallback=void 0;b!==void 0&&this.add(b,a,c,d,e)};THREE.LensFlare.prototype=Object.create(THREE.Object3D.prototype);
259 260
THREE.LensFlare.prototype.add=function(b,a,c,d,e,f){a===void 0&&(a=-1);c===void 0&&(c=0);f===void 0&&(f=1);e===void 0&&(e=new THREE.Color(16777215));if(d===void 0)d=THREE.NormalBlending;c=Math.min(c,Math.max(0,c));this.lensFlares.push({texture:b,size:a,distance:c,x:0,y:0,z:0,scale:1,rotation:1,opacity:f,color:e,blending:d})};
THREE.LensFlare.prototype.updateLensFlares=function(){var b,a=this.lensFlares.length,c,d=-this.positionScreen.x*2,e=-this.positionScreen.y*2;for(b=0;b<a;b++){c=this.lensFlares[b];c.x=this.positionScreen.x+d*c.distance;c.y=this.positionScreen.y+e*c.distance;c.wantedRotation=c.x*Math.PI*0.25;c.rotation=c.rotation+(c.wantedRotation-c.rotation)*0.25}};
M
Mr.doob 已提交
261
THREE.MorphBlendMesh=function(b,a){THREE.Mesh.call(this,b,a);this.animationsMap={};this.animationsList=[];var c=this.geometry.morphTargets.length;this.createAnimation("__default",0,c-1,c/1);this.setAnimationWeight("__default",1)};THREE.MorphBlendMesh.prototype=Object.create(THREE.Mesh.prototype);
262 263 264 265 266 267 268
THREE.MorphBlendMesh.prototype.createAnimation=function(b,a,c,d){a={startFrame:a,endFrame:c,length:c-a+1,fps:d,duration:(c-a)/d,lastFrame:0,currentFrame:0,active:false,time:0,direction:1,weight:1,directionBackwards:false,mirroredLoop:false};this.animationsMap[b]=a;this.animationsList.push(a)};
THREE.MorphBlendMesh.prototype.autoCreateAnimations=function(b){for(var a=/([a-z]+)(\d+)/,c,d={},e=this.geometry,f=0,g=e.morphTargets.length;f<g;f++){var h=e.morphTargets[f].name.match(a);if(h&&h.length>1){var i=h[1];d[i]||(d[i]={start:Infinity,end:-Infinity});h=d[i];if(f<h.start)h.start=f;if(f>h.end)h.end=f;c||(c=i)}}for(i in d){h=d[i];this.createAnimation(i,h.start,h.end,b)}this.firstAnimation=c};
THREE.MorphBlendMesh.prototype.setAnimationDirectionForward=function(b){if(b=this.animationsMap[b]){b.direction=1;b.directionBackwards=false}};THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward=function(b){if(b=this.animationsMap[b]){b.direction=-1;b.directionBackwards=true}};THREE.MorphBlendMesh.prototype.setAnimationFPS=function(b,a){var c=this.animationsMap[b];if(c){c.fps=a;c.duration=(c.end-c.start)/c.fps}};
THREE.MorphBlendMesh.prototype.setAnimationDuration=function(b,a){var c=this.animationsMap[b];if(c){c.duration=a;c.fps=(c.end-c.start)/c.duration}};THREE.MorphBlendMesh.prototype.setAnimationWeight=function(b,a){var c=this.animationsMap[b];if(c)c.weight=a};THREE.MorphBlendMesh.prototype.setAnimationTime=function(b,a){var c=this.animationsMap[b];if(c)c.time=a};THREE.MorphBlendMesh.prototype.getAnimationTime=function(b){var a=0;if(b=this.animationsMap[b])a=b.time;return a};
THREE.MorphBlendMesh.prototype.getAnimationDuration=function(b){var a=-1;if(b=this.animationsMap[b])a=b.duration;return a};THREE.MorphBlendMesh.prototype.playAnimation=function(b){var a=this.animationsMap[b];if(a){a.time=0;a.active=true}else console.warn("animation["+b+"] undefined")};THREE.MorphBlendMesh.prototype.stopAnimation=function(b){if(b=this.animationsMap[b])b.active=false};
THREE.MorphBlendMesh.prototype.update=function(b){for(var a=0,c=this.animationsList.length;a<c;a++){var d=this.animationsList[a];if(d.active){var e=d.duration/d.length;d.time=d.time+d.direction*b;if(d.mirroredLoop){if(d.time>d.duration||d.time<0){d.direction=d.direction*-1;if(d.time>d.duration){d.time=d.duration;d.directionBackwards=true}if(d.time<0){d.time=0;d.directionBackwards=false}}}else{d.time=d.time%d.duration;if(d.time<0)d.time=d.time+d.duration}var f=d.startFrame+THREE.Math.clamp(Math.floor(d.time/
e),0,d.length-1),g=d.weight;if(f!==d.currentFrame){this.morphTargetInfluences[d.lastFrame]=0;this.morphTargetInfluences[d.currentFrame]=1*g;this.morphTargetInfluences[f]=0;d.lastFrame=d.currentFrame;d.currentFrame=f}e=d.time%e/e;d.directionBackwards&&(e=1-e);this.morphTargetInfluences[d.currentFrame]=e*g;this.morphTargetInfluences[d.lastFrame]=(1-e)*g}}};
269
THREE.LensFlarePlugin=function(){function b(b){var c=a.createProgram(),d=a.createShader(a.FRAGMENT_SHADER),e=a.createShader(a.VERTEX_SHADER);a.shaderSource(d,b.fragmentShader);a.shaderSource(e,b.vertexShader);a.compileShader(d);a.compileShader(e);a.attachShader(c,d);a.attachShader(c,e);a.linkProgram(c);return c}var a,c,d,e,f,g,h,i,j,l,m,n,k;this.init=function(o){a=o.context;c=o;d=new Float32Array(16);e=new Uint16Array(6);o=0;d[o++]=-1;d[o++]=-1;d[o++]=0;d[o++]=0;d[o++]=1;d[o++]=-1;d[o++]=1;d[o++]=
M
Mr.doob 已提交
270
0;d[o++]=1;d[o++]=1;d[o++]=1;d[o++]=1;d[o++]=-1;d[o++]=1;d[o++]=0;d[o++]=1;o=0;e[o++]=0;e[o++]=1;e[o++]=2;e[o++]=0;e[o++]=2;e[o++]=3;f=a.createBuffer();g=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,f);a.bufferData(a.ARRAY_BUFFER,d,a.STATIC_DRAW);a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,g);a.bufferData(a.ELEMENT_ARRAY_BUFFER,e,a.STATIC_DRAW);h=a.createTexture();i=a.createTexture();a.bindTexture(a.TEXTURE_2D,h);a.texImage2D(a.TEXTURE_2D,0,a.RGB,16,16,0,a.RGB,a.UNSIGNED_BYTE,null);a.texParameteri(a.TEXTURE_2D,
271
a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST);a.bindTexture(a.TEXTURE_2D,i);a.texImage2D(a.TEXTURE_2D,0,a.RGBA,16,16,0,a.RGBA,a.UNSIGNED_BYTE,null);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE);a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST);
272 273 274 275 276
a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST);if(a.getParameter(a.MAX_VERTEX_TEXTURE_IMAGE_UNITS)<=0){j=false;l=b(THREE.ShaderFlares.lensFlare)}else{j=true;l=b(THREE.ShaderFlares.lensFlareVertexTexture)}m={};n={};m.vertex=a.getAttribLocation(l,"position");m.uv=a.getAttribLocation(l,"uv");n.renderType=a.getUniformLocation(l,"renderType");n.map=a.getUniformLocation(l,"map");n.occlusionMap=a.getUniformLocation(l,"occlusionMap");n.opacity=a.getUniformLocation(l,"opacity");n.color=a.getUniformLocation(l,
"color");n.scale=a.getUniformLocation(l,"scale");n.rotation=a.getUniformLocation(l,"rotation");n.screenPosition=a.getUniformLocation(l,"screenPosition");k=false};this.render=function(b,d,e,s){var b=b.__webglFlares,u=b.length;if(u){var t=new THREE.Vector3,r=s/e,v=e*0.5,z=s*0.5,A=16/s,x=new THREE.Vector2(A*r,A),w=new THREE.Vector3(1,1,0),C=new THREE.Vector2(1,1),B=n,A=m;a.useProgram(l);if(!k){a.enableVertexAttribArray(m.vertex);a.enableVertexAttribArray(m.uv);k=true}a.uniform1i(B.occlusionMap,0);a.uniform1i(B.map,
1);a.bindBuffer(a.ARRAY_BUFFER,f);a.vertexAttribPointer(A.vertex,2,a.FLOAT,false,16,0);a.vertexAttribPointer(A.uv,2,a.FLOAT,false,16,8);a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,g);a.disable(a.CULL_FACE);a.depthMask(false);var E,G,L,H,D;for(E=0;E<u;E++){A=16/s;x.set(A*r,A);H=b[E];t.set(H.matrixWorld.elements[12],H.matrixWorld.elements[13],H.matrixWorld.elements[14]);d.matrixWorldInverse.multiplyVector3(t);d.projectionMatrix.multiplyVector3(t);w.copy(t);C.x=w.x*v+v;C.y=w.y*z+z;if(j||C.x>0&&C.x<e&&C.y>0&&
C.y<s){a.activeTexture(a.TEXTURE1);a.bindTexture(a.TEXTURE_2D,h);a.copyTexImage2D(a.TEXTURE_2D,0,a.RGB,C.x-8,C.y-8,16,16,0);a.uniform1i(B.renderType,0);a.uniform2f(B.scale,x.x,x.y);a.uniform3f(B.screenPosition,w.x,w.y,w.z);a.disable(a.BLEND);a.enable(a.DEPTH_TEST);a.drawElements(a.TRIANGLES,6,a.UNSIGNED_SHORT,0);a.activeTexture(a.TEXTURE0);a.bindTexture(a.TEXTURE_2D,i);a.copyTexImage2D(a.TEXTURE_2D,0,a.RGBA,C.x-8,C.y-8,16,16,0);a.uniform1i(B.renderType,1);a.disable(a.DEPTH_TEST);a.activeTexture(a.TEXTURE1);
a.bindTexture(a.TEXTURE_2D,h);a.drawElements(a.TRIANGLES,6,a.UNSIGNED_SHORT,0);H.positionScreen.copy(w);H.customUpdateCallback?H.customUpdateCallback(H):H.updateLensFlares();a.uniform1i(B.renderType,2);a.enable(a.BLEND);G=0;for(L=H.lensFlares.length;G<L;G++){D=H.lensFlares[G];if(D.opacity>0.0010&&D.scale>0.0010){w.x=D.x;w.y=D.y;w.z=D.z;A=D.size*D.scale/s;x.x=A*r;x.y=A;a.uniform3f(B.screenPosition,w.x,w.y,w.z);a.uniform2f(B.scale,x.x,x.y);a.uniform1f(B.rotation,D.rotation);a.uniform1f(B.opacity,D.opacity);
M
Mr.doob 已提交
277
a.uniform3f(B.color,D.color.r,D.color.g,D.color.b);c.setBlending(D.blending,D.blendEquation,D.blendSrc,D.blendDst);c.setTexture(D.texture,1);a.drawElements(a.TRIANGLES,6,a.UNSIGNED_SHORT,0)}}}}a.enable(a.CULL_FACE);a.enable(a.DEPTH_TEST);a.depthMask(true)}}};
278 279 280 281 282 283 284 285 286 287 288 289
THREE.ShadowMapPlugin=function(){var b,a,c,d,e,f=new THREE.Frustum,g=new THREE.Matrix4,h=new THREE.Vector3,i=new THREE.Vector3;this.init=function(f){b=f.context;a=f;var f=THREE.ShaderLib.depthRGBA,g=THREE.UniformsUtils.clone(f.uniforms);c=new THREE.ShaderMaterial({fragmentShader:f.fragmentShader,vertexShader:f.vertexShader,uniforms:g});d=new THREE.ShaderMaterial({fragmentShader:f.fragmentShader,vertexShader:f.vertexShader,uniforms:g,morphTargets:true});e=new THREE.ShaderMaterial({fragmentShader:f.fragmentShader,
vertexShader:f.vertexShader,uniforms:g,skinning:true});c._shadowPass=true;d._shadowPass=true;e._shadowPass=true};this.render=function(b,c){a.shadowMapEnabled&&a.shadowMapAutoUpdate&&this.update(b,c)};this.update=function(j,l){var m,n,k,o,q,p,s,u,t,r=[];o=0;b.clearColor(1,1,1,1);b.disable(b.BLEND);b.enable(b.CULL_FACE);a.shadowMapCullFrontFaces?b.cullFace(b.FRONT):b.cullFace(b.BACK);a.setDepthTest(true);m=0;for(n=j.__lights.length;m<n;m++){k=j.__lights[m];if(k.castShadow)if(k instanceof THREE.DirectionalLight&&
k.shadowCascade)for(q=0;q<k.shadowCascadeCount;q++){var v;if(k.shadowCascadeArray[q])v=k.shadowCascadeArray[q];else{t=k;s=q;v=new THREE.DirectionalLight;v.isVirtual=true;v.onlyShadow=true;v.castShadow=true;v.shadowCameraNear=t.shadowCameraNear;v.shadowCameraFar=t.shadowCameraFar;v.shadowCameraLeft=t.shadowCameraLeft;v.shadowCameraRight=t.shadowCameraRight;v.shadowCameraBottom=t.shadowCameraBottom;v.shadowCameraTop=t.shadowCameraTop;v.shadowCameraVisible=t.shadowCameraVisible;v.shadowDarkness=t.shadowDarkness;
v.shadowBias=t.shadowCascadeBias[s];v.shadowMapWidth=t.shadowCascadeWidth[s];v.shadowMapHeight=t.shadowCascadeHeight[s];v.pointsWorld=[];v.pointsFrustum=[];u=v.pointsWorld;p=v.pointsFrustum;for(var z=0;z<8;z++){u[z]=new THREE.Vector3;p[z]=new THREE.Vector3}u=t.shadowCascadeNearZ[s];t=t.shadowCascadeFarZ[s];p[0].set(-1,-1,u);p[1].set(1,-1,u);p[2].set(-1,1,u);p[3].set(1,1,u);p[4].set(-1,-1,t);p[5].set(1,-1,t);p[6].set(-1,1,t);p[7].set(1,1,t);v.originalCamera=l;p=new THREE.Gyroscope;p.position=k.shadowCascadeOffset;
p.add(v);p.add(v.target);l.add(p);k.shadowCascadeArray[q]=v;console.log("Created virtualLight",v)}s=k;u=q;t=s.shadowCascadeArray[u];t.position.copy(s.position);t.target.position.copy(s.target.position);t.lookAt(t.target);t.shadowCameraVisible=s.shadowCameraVisible;t.shadowDarkness=s.shadowDarkness;t.shadowBias=s.shadowCascadeBias[u];p=s.shadowCascadeNearZ[u];s=s.shadowCascadeFarZ[u];t=t.pointsFrustum;t[0].z=p;t[1].z=p;t[2].z=p;t[3].z=p;t[4].z=s;t[5].z=s;t[6].z=s;t[7].z=s;r[o]=v;o++}else{r[o]=k;o++}}m=
0;for(n=r.length;m<n;m++){k=r[m];if(!k.shadowMap){k.shadowMap=new THREE.WebGLRenderTarget(k.shadowMapWidth,k.shadowMapHeight,{minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,format:THREE.RGBAFormat});k.shadowMapSize=new THREE.Vector2(k.shadowMapWidth,k.shadowMapHeight);k.shadowMatrix=new THREE.Matrix4}if(!k.shadowCamera){if(k instanceof THREE.SpotLight)k.shadowCamera=new THREE.PerspectiveCamera(k.shadowCameraFov,k.shadowMapWidth/k.shadowMapHeight,k.shadowCameraNear,k.shadowCameraFar);else if(k instanceof
THREE.DirectionalLight)k.shadowCamera=new THREE.OrthographicCamera(k.shadowCameraLeft,k.shadowCameraRight,k.shadowCameraTop,k.shadowCameraBottom,k.shadowCameraNear,k.shadowCameraFar);else{console.error("Unsupported light type for shadow");continue}j.add(k.shadowCamera);a.autoUpdateScene&&j.updateMatrixWorld()}if(k.shadowCameraVisible&&!k.cameraHelper){k.cameraHelper=new THREE.CameraHelper(k.shadowCamera);k.shadowCamera.add(k.cameraHelper)}if(k.isVirtual&&v.originalCamera==l){q=l;o=k.shadowCamera;
p=k.pointsFrustum;t=k.pointsWorld;h.set(Infinity,Infinity,Infinity);i.set(-Infinity,-Infinity,-Infinity);for(s=0;s<8;s++){u=t[s];u.copy(p[s]);THREE.ShadowMapPlugin.__projector.unprojectVector(u,q);o.matrixWorldInverse.multiplyVector3(u);if(u.x<h.x)h.x=u.x;if(u.x>i.x)i.x=u.x;if(u.y<h.y)h.y=u.y;if(u.y>i.y)i.y=u.y;if(u.z<h.z)h.z=u.z;if(u.z>i.z)i.z=u.z}o.left=h.x;o.right=i.x;o.top=i.y;o.bottom=h.y;o.updateProjectionMatrix()}o=k.shadowMap;p=k.shadowMatrix;q=k.shadowCamera;q.position.copy(k.matrixWorld.getPosition());
q.lookAt(k.target.matrixWorld.getPosition());q.updateMatrixWorld();q.matrixWorldInverse.getInverse(q.matrixWorld);if(k.cameraHelper)k.cameraHelper.lines.visible=k.shadowCameraVisible;k.shadowCameraVisible&&k.cameraHelper.update();p.set(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1);p.multiplySelf(q.projectionMatrix);p.multiplySelf(q.matrixWorldInverse);if(!q._viewMatrixArray)q._viewMatrixArray=new Float32Array(16);if(!q._projectionMatrixArray)q._projectionMatrixArray=new Float32Array(16);q.matrixWorldInverse.flattenToArray(q._viewMatrixArray);
q.projectionMatrix.flattenToArray(q._projectionMatrixArray);g.multiply(q.projectionMatrix,q.matrixWorldInverse);f.setFromMatrix(g);a.setRenderTarget(o);a.clear();t=j.__webglObjects;k=0;for(o=t.length;k<o;k++){s=t[k];p=s.object;s.render=false;if(p.visible&&p.castShadow&&(!(p instanceof THREE.Mesh)||!p.frustumCulled||f.contains(p))){p._modelViewMatrix.multiply(q.matrixWorldInverse,p.matrixWorld);s.render=true}}k=0;for(o=t.length;k<o;k++){s=t[k];if(s.render){p=s.object;s=s.buffer;u=p.customDepthMaterial?
p.customDepthMaterial:p.geometry.morphTargets.length?d:p instanceof THREE.SkinnedMesh?e:c;s instanceof THREE.BufferGeometry?a.renderBufferDirect(q,j.__lights,null,u,s,p):a.renderBuffer(q,j.__lights,null,u,s,p)}}t=j.__webglObjectsImmediate;k=0;for(o=t.length;k<o;k++){s=t[k];p=s.object;if(p.visible&&p.castShadow){p._modelViewMatrix.multiply(q.matrixWorldInverse,p.matrixWorld);a.renderImmediateObject(q,j.__lights,null,c,p)}}}m=a.getClearColor();n=a.getClearAlpha();b.clearColor(m.r,m.g,m.b,n);b.enable(b.BLEND);
a.shadowMapCullFrontFaces&&b.cullFace(b.BACK)}};THREE.ShadowMapPlugin.__projector=new THREE.Projector;
A
alteredq 已提交
290
THREE.SpritePlugin=function(){function b(a,b){return b.z-a.z}var a,c,d,e,f,g,h,i,j,l;this.init=function(b){a=b.context;c=b;d=new Float32Array(16);e=new Uint16Array(6);b=0;d[b++]=-1;d[b++]=-1;d[b++]=0;d[b++]=0;d[b++]=1;d[b++]=-1;d[b++]=1;d[b++]=0;d[b++]=1;d[b++]=1;d[b++]=1;d[b++]=1;d[b++]=-1;d[b++]=1;d[b++]=0;d[b++]=1;b=0;e[b++]=0;e[b++]=1;e[b++]=2;e[b++]=0;e[b++]=2;e[b++]=3;f=a.createBuffer();g=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,f);a.bufferData(a.ARRAY_BUFFER,d,a.STATIC_DRAW);a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,
291
g);a.bufferData(a.ELEMENT_ARRAY_BUFFER,e,a.STATIC_DRAW);var b=THREE.ShaderSprite.sprite,n=a.createProgram(),k=a.createShader(a.FRAGMENT_SHADER),o=a.createShader(a.VERTEX_SHADER);a.shaderSource(k,b.fragmentShader);a.shaderSource(o,b.vertexShader);a.compileShader(k);a.compileShader(o);a.attachShader(n,k);a.attachShader(n,o);a.linkProgram(n);h=n;i={};j={};i.position=a.getAttribLocation(h,"position");i.uv=a.getAttribLocation(h,"uv");j.uvOffset=a.getUniformLocation(h,"uvOffset");j.uvScale=a.getUniformLocation(h,
292
"uvScale");j.rotation=a.getUniformLocation(h,"rotation");j.scale=a.getUniformLocation(h,"scale");j.alignment=a.getUniformLocation(h,"alignment");j.color=a.getUniformLocation(h,"color");j.map=a.getUniformLocation(h,"map");j.opacity=a.getUniformLocation(h,"opacity");j.useScreenCoordinates=a.getUniformLocation(h,"useScreenCoordinates");j.affectedByDistance=a.getUniformLocation(h,"affectedByDistance");j.screenPosition=a.getUniformLocation(h,"screenPosition");j.modelViewMatrix=a.getUniformLocation(h,"modelViewMatrix");
293 294 295 296
j.projectionMatrix=a.getUniformLocation(h,"projectionMatrix");l=false};this.render=function(d,e,k,o){var d=d.__webglSprites,q=d.length;if(q){var p=i,s=j,u=o/k,k=k*0.5,t=o*0.5,r=true;a.useProgram(h);if(!l){a.enableVertexAttribArray(p.position);a.enableVertexAttribArray(p.uv);l=true}a.disable(a.CULL_FACE);a.enable(a.BLEND);a.depthMask(true);a.bindBuffer(a.ARRAY_BUFFER,f);a.vertexAttribPointer(p.position,2,a.FLOAT,false,16,0);a.vertexAttribPointer(p.uv,2,a.FLOAT,false,16,8);a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,
g);a.uniformMatrix4fv(s.projectionMatrix,false,e._projectionMatrixArray);a.activeTexture(a.TEXTURE0);a.uniform1i(s.map,0);for(var v,z=[],p=0;p<q;p++){v=d[p];if(v.visible&&v.opacity!==0)if(v.useScreenCoordinates)v.z=-v.position.z;else{v._modelViewMatrix.multiply(e.matrixWorldInverse,v.matrixWorld);v.z=-v._modelViewMatrix.elements[14]}}d.sort(b);for(p=0;p<q;p++){v=d[p];if(v.visible&&v.opacity!==0&&v.map&&v.map.image&&v.map.image.width){if(v.useScreenCoordinates){a.uniform1i(s.useScreenCoordinates,1);
a.uniform3f(s.screenPosition,(v.position.x-k)/k,(t-v.position.y)/t,Math.max(0,Math.min(1,v.position.z)))}else{a.uniform1i(s.useScreenCoordinates,0);a.uniform1i(s.affectedByDistance,v.affectedByDistance?1:0);a.uniformMatrix4fv(s.modelViewMatrix,false,v._modelViewMatrix.elements)}e=v.map.image.width/(v.scaleByViewport?o:1);z[0]=e*u*v.scale.x;z[1]=e*v.scale.y;a.uniform2f(s.uvScale,v.uvScale.x,v.uvScale.y);a.uniform2f(s.uvOffset,v.uvOffset.x,v.uvOffset.y);a.uniform2f(s.alignment,v.alignment.x,v.alignment.y);
a.uniform1f(s.opacity,v.opacity);a.uniform3f(s.color,v.color.r,v.color.g,v.color.b);a.uniform1f(s.rotation,v.rotation);a.uniform2fv(s.scale,z);if(v.mergeWith3D&&!r){a.enable(a.DEPTH_TEST);r=true}else if(!v.mergeWith3D&&r){a.disable(a.DEPTH_TEST);r=false}c.setBlending(v.blending,v.blendEquation,v.blendSrc,v.blendDst);c.setTexture(v.map,0);a.drawElements(a.TRIANGLES,6,a.UNSIGNED_SHORT,0)}}a.enable(a.CULL_FACE);a.enable(a.DEPTH_TEST);a.depthMask(true)}}};
297
THREE.DepthPassPlugin=function(){this.enabled=false;this.renderTarget=null;var b,a,c,d,e=new THREE.Frustum,f=new THREE.Matrix4;this.init=function(e){b=e.context;a=e;var e=THREE.ShaderLib.depthRGBA,f=THREE.UniformsUtils.clone(e.uniforms);c=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f});d=new THREE.ShaderMaterial({fragmentShader:e.fragmentShader,vertexShader:e.vertexShader,uniforms:f,morphTargets:true});c._shadowPass=true;d._shadowPass=true};this.render=
298 299 300
function(a,b){this.enabled&&this.update(a,b)};this.update=function(g,h){var i,j,l,m,n,k;b.clearColor(1,1,1,1);b.disable(b.BLEND);a.setDepthTest(true);a.autoUpdateScene&&g.updateMatrixWorld();if(!h._viewMatrixArray)h._viewMatrixArray=new Float32Array(16);if(!h._projectionMatrixArray)h._projectionMatrixArray=new Float32Array(16);h.matrixWorldInverse.getInverse(h.matrixWorld);h.matrixWorldInverse.flattenToArray(h._viewMatrixArray);h.projectionMatrix.flattenToArray(h._projectionMatrixArray);f.multiply(h.projectionMatrix,
h.matrixWorldInverse);e.setFromMatrix(f);a.setRenderTarget(this.renderTarget);a.clear();k=g.__webglObjects;i=0;for(j=k.length;i<j;i++){l=k[i];n=l.object;l.render=false;if(n.visible&&(!(n instanceof THREE.Mesh)||!n.frustumCulled||e.contains(n))){n._modelViewMatrix.multiply(h.matrixWorldInverse,n.matrixWorld);l.render=true}}i=0;for(j=k.length;i<j;i++){l=k[i];if(l.render){n=l.object;l=l.buffer;a.setObjectFaces(n);m=n.customDepthMaterial?n.customDepthMaterial:n.geometry.morphTargets.length?d:c;l instanceof
THREE.BufferGeometry?a.renderBufferDirect(h,g.__lights,null,m,l,n):a.renderBuffer(h,g.__lights,null,m,l,n)}}k=g.__webglObjectsImmediate;i=0;for(j=k.length;i<j;i++){l=k[i];n=l.object;if(n.visible&&n.castShadow){n._modelViewMatrix.multiply(h.matrixWorldInverse,n.matrixWorld);a.renderImmediateObject(h,g.__lights,null,c,n)}}i=a.getClearColor();j=a.getClearAlpha();b.clearColor(i.r,i.g,i.b,j);b.enable(b.BLEND)}};
A
alteredq 已提交
301 302
THREE.ShaderFlares={lensFlareVertexTexture:{vertexShader:"uniform vec3 screenPosition;\nuniform vec2 scale;\nuniform float rotation;\nuniform int renderType;\nuniform sampler2D occlusionMap;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvarying float vVisibility;\nvoid main() {\nvUV = uv;\nvec2 pos = position;\nif( renderType == 2 ) {\nvec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.1 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 ) ) +\ntexture2D( occlusionMap, vec2( 0.9, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.1, 0.9 ) ) +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 ) ) +\ntexture2D( occlusionMap, vec2( 0.5, 0.5 ) );\nvVisibility = (       visibility.r / 9.0 ) *\n( 1.0 - visibility.g / 9.0 ) *\n(       visibility.b / 9.0 ) *\n( 1.0 - visibility.a / 9.0 );\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",fragmentShader:"precision mediump float;\nuniform sampler2D map;\nuniform float opacity;\nuniform int renderType;\nuniform vec3 color;\nvarying vec2 vUV;\nvarying float vVisibility;\nvoid main() {\nif( renderType == 0 ) {\ngl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nvec4 texture = texture2D( map, vUV );\ntexture.a *= opacity * vVisibility;\ngl_FragColor = texture;\ngl_FragColor.rgb *= color;\n}\n}"},
lensFlare:{vertexShader:"uniform vec3 screenPosition;\nuniform vec2 scale;\nuniform float rotation;\nuniform int renderType;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvoid main() {\nvUV = uv;\nvec2 pos = position;\nif( renderType == 2 ) {\npos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;\npos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;\n}\ngl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );\n}",fragmentShader:"precision mediump float;\nuniform sampler2D map;\nuniform sampler2D occlusionMap;\nuniform float opacity;\nuniform int renderType;\nuniform vec3 color;\nvarying vec2 vUV;\nvoid main() {\nif( renderType == 0 ) {\ngl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );\n} else if( renderType == 1 ) {\ngl_FragColor = texture2D( map, vUV );\n} else {\nfloat visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a +\ntexture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a +\ntexture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a +\ntexture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;\nvisibility = ( 1.0 - visibility / 4.0 );\nvec4 texture = texture2D( map, vUV );\ntexture.a *= opacity * visibility;\ngl_FragColor = texture;\ngl_FragColor.rgb *= color;\n}\n}"}};
A
alteredq 已提交
303
THREE.ShaderSprite={sprite:{vertexShader:"uniform int useScreenCoordinates;\nuniform int affectedByDistance;\nuniform vec3 screenPosition;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform float rotation;\nuniform vec2 scale;\nuniform vec2 alignment;\nuniform vec2 uvOffset;\nuniform vec2 uvScale;\nattribute vec2 position;\nattribute vec2 uv;\nvarying vec2 vUV;\nvoid main() {\nvUV = uvOffset + uv * uvScale;\nvec2 alignedPosition = position + alignment;\nvec2 rotatedPosition;\nrotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;\nrotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;\nvec4 finalPosition;\nif( useScreenCoordinates != 0 ) {\nfinalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );\n} else {\nfinalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\nfinalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );\n}\ngl_Position = finalPosition;\n}",
A
alteredq 已提交
304
fragmentShader:"precision mediump float;\nuniform vec3 color;\nuniform sampler2D map;\nuniform float opacity;\nvarying vec2 vUV;\nvoid main() {\nvec4 texture = texture2D( map, vUV );\ngl_FragColor = vec4( color * texture.xyz, texture.a * opacity );\n}"}};