From 8ec6317ef8e3c9d5880608924669af56d3bbdc68 Mon Sep 17 00:00:00 2001 From: alteredq Date: Wed, 7 Dec 2011 01:47:39 +0100 Subject: [PATCH] Added BufferGeometry for direct rendering from typed arrays. Work in progress. For the moment works just with CTMLoader. Still not sure where some pieces of code would go. Upsides: - initialization time cut down significantly (1.8 seconds => 0.7 seconds for CTM example) - much smaller GL buffers thanks to fully used indexing (Walt has 6x less vertices) - consequently much smaller memory footprint all around, both for main and GPU memories, which means less swapping and better vertex caching Downsides: - can't have anymore sharp per-face effects like flat shading (at least if mesh is not constructed in a way where each face has own vertices) - can't have multiple materials per mesh - no more easy manipulation of anything (for the moment actually no runtime manipulation at all, typed arrays are just thrown away, dynamic geometries code path not yet implemented) --- build/Three.js | 719 +++++++++++++++--------------- build/custom/ThreeCanvas.js | 2 +- build/custom/ThreeExtras.js | 1 + build/custom/ThreeSVG.js | 2 +- build/custom/ThreeWebGL.js | 220 ++++----- examples/js/ctm/CTMLoader.js | 347 +++++++++++++- examples/webgl_loader_ctm.html | 11 +- src/core/Geometry.js | 9 +- src/extras/core/BufferGeometry.js | 56 +++ src/objects/Mesh.js | 2 +- src/renderers/WebGLRenderer.js | 212 +++++++-- utils/build.py | 4 +- 12 files changed, 1060 insertions(+), 525 deletions(-) create mode 100644 src/extras/core/BufferGeometry.js diff --git a/build/Three.js b/build/Three.js index 2831070634..c35a289d1d 100644 --- a/build/Three.js +++ b/build/Three.js @@ -18,66 +18,66 @@ this.y=Math.asin(a.n13);Math.abs(b)>1.0E-5?(this.x=Math.atan2(-a.n23/b,a.n33/b), THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w!==void 0?a.w:1},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z- b.z;this.w=a.w-b.w;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a,this.w/=a):(this.z=this.y=this.x=0,this.w=1);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w},lengthSq:function(){return this.dot(this)},length:function(){return Math.sqrt(this.lengthSq())}, normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},lerpSelf:function(a,b){this.x+=(a.x-this.x)*b;this.y+=(a.y-this.y)*b;this.z+=(a.z-this.z)*b;this.w+=(a.w-this.w)*b;return this}}; -THREE.Ray=function(a,b){function c(a,b,c){o.sub(c,a);q=o.dot(b);if(q<=0)return null;n=p.add(a,m.copy(b).multiplyScalar(q));return s=c.distanceTo(n)}function d(a,b,c,d){o.sub(d,b);p.sub(c,b);m.sub(a,b);r=o.dot(o);u=o.dot(p);t=o.dot(m);z=p.dot(p);A=p.dot(m);E=1/(r*z-u*u);D=(z*t-u*A)*E;B=(r*A-u*t)*E;return D>=0&&B>=0&&D+B<1}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;this.intersectScene=function(a){return this.intersectObjects(a.children)};this.intersectObjects=function(a){var b, -c,d=[];b=0;for(c=a.length;b=0&&H>=0&&D+H<1}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;this.intersectScene=function(a){return this.intersectObjects(a.children)};this.intersectObjects=function(a){var b, +c,d=[];b=0;for(c=a.length;bm.scale.x)return[];n={distance:o,point:m.position,face:null,object:m};q.push(n)}else if(m instanceof THREE.Mesh){o=c(this.origin,this.direction,m.matrixWorld.getPosition());if(o===null||o>m.geometry.boundingSphere.radius*Math.max(m.scale.x,Math.max(m.scale.y,m.scale.z)))return q;var s,r=m.geometry,u=r.vertices,t;m.matrixRotationWorld.extractRotation(m.matrixWorld);o=0;for(p=r.faces.length;o0:s<0)))if(s=k.dot(i.sub(e,a))/s,j.add(a,b.multiplyScalar(s)),n instanceof THREE.Face3)d(j, -e,f,g)&&(n={distance:a.distanceTo(j),point:j.clone(),face:n,object:m},q.push(n));else if(n instanceof THREE.Face4&&(d(j,e,f,h)||d(j,f,g,h)))n={distance:a.distanceTo(j),point:j.clone(),face:n,object:m},q.push(n)}return q};var o=new THREE.Vector3,p=new THREE.Vector3,m=new THREE.Vector3,q,n,s,r,u,t,z,A,E,D,B}; -THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,j,o){h=!1;b=f;c=g;d=j;e=o;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=bf?d:f,e=e>g?e:g);a()};this.add3Points= -function(f,g,j,o,p,m){h?(h=!1,b=fj?f>p?f:p:j>p?j:p,e=g>o?g>m?g:m:o>m?o:m):(b=fj?f>p?f>d?f:d:p>d?p:d:j>p?j>d?j:d:p>d?p:d,e=g>o?g>m?g>e?g:e:m>e?m:e:o>m?o>e?o:e:m>e?m:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=bf.getRight()?d:f.getRight(),e=e> +b.copy(this.direction),t=m.matrixWorld,i=t.multiplyVector3(i.copy(n.centroid)).subSelf(a),s=i.dot(b),!(s<=0)&&(e=t.multiplyVector3(e.copy(u[n.a].position)),f=t.multiplyVector3(f.copy(u[n.b].position)),g=t.multiplyVector3(g.copy(u[n.c].position)),n instanceof THREE.Face4&&(h=t.multiplyVector3(h.copy(u[n.d].position))),j=m.matrixRotationWorld.multiplyVector3(j.copy(n.normal)),s=b.dot(j),m.doubleSided||(m.flipSided?s>0:s<0)))if(s=j.dot(i.sub(e,a))/s,k.add(a,b.multiplyScalar(s)),n instanceof THREE.Face3)d(k, +e,f,g)&&(n={distance:a.distanceTo(k),point:k.clone(),face:n,object:m},q.push(n));else if(n instanceof THREE.Face4&&(d(k,e,f,h)||d(k,f,g,h)))n={distance:a.distanceTo(k),point:k.clone(),face:n,object:m},q.push(n)}return q};var o=new THREE.Vector3,p=new THREE.Vector3,m=new THREE.Vector3,q,n,s,r,u,t,A,B,z,D,H}; +THREE.Rectangle=function(){function a(){f=d-b;g=e-c}var b,c,d,e,f,g,h=!0;this.getX=function(){return b};this.getY=function(){return c};this.getWidth=function(){return f};this.getHeight=function(){return g};this.getLeft=function(){return b};this.getTop=function(){return c};this.getRight=function(){return d};this.getBottom=function(){return e};this.set=function(f,g,k,o){h=!1;b=f;c=g;d=k;e=o;a()};this.addPoint=function(f,g){h?(h=!1,b=f,c=g,d=f,e=g):(b=bf?d:f,e=e>g?e:g);a()};this.add3Points= +function(f,g,k,o,p,m){h?(h=!1,b=fk?f>p?f:p:k>p?k:p,e=g>o?g>m?g:m:o>m?o:m):(b=fk?f>p?f>d?f:d:p>d?p:d:k>p?k>d?k:d:p>d?p:d,e=g>o?g>m?g>e?g:e:m>e?m:e:o>m?o>e?o:e:m>e?m:e);a()};this.addRectangle=function(f){h?(h=!1,b=f.getLeft(),c=f.getTop(),d=f.getRight(),e=f.getBottom()):(b=bf.getRight()?d:f.getRight(),e=e> f.getBottom()?e:f.getBottom());a()};this.inflate=function(f){b-=f;c-=f;d+=f;e+=f;a()};this.minSelf=function(f){b=b>f.getLeft()?b:f.getLeft();c=c>f.getTop()?c:f.getTop();d=da.getRight())return!1;if(ea.getBottom())return!1;return!0};this.empty=function(){h=!0;e=d=c=b=0;a()};this.isEmpty=function(){return h}}; THREE.Math={clamp:function(a,b,c){return ac?c:a},clampBottom:function(a,b){return a=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(e<0?c=Math.max(c,e/(e-f)):f<0&&(d=Math.min(d,e/(e-f))),g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h))),dg&&h.positionScreen.z0&&D.z<1))g=z[t]=z[t]||new THREE.RenderableParticle,t++,u=g,u.x= -D.x/D.w,u.y=D.y/D.w,u.z=D.z,u.rotation=T.rotation.z,u.scale.x=T.scale.x*Math.abs(u.x-(D.x+e.projectionMatrix.n11)/(D.w+e.projectionMatrix.n14)),u.scale.y=T.scale.y*Math.abs(u.y-(D.y+e.projectionMatrix.n22)/(D.w+e.projectionMatrix.n24)),u.material=T.material,A.elements.push(u);f&&A.elements.sort(c);return A}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)}; +THREE.Projector=function(){function a(){var a=g[f]=g[f]||new THREE.RenderableObject;f++;return a}function b(){var a=j[i]=j[i]||new THREE.RenderableVertex;i++;return a}function c(a,b){return b.z-a.z}function d(a,b){var c=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;return e>=0&&f>=0&&g>=0&&h>=0?!0:e<0&&f<0||g<0&&h<0?!1:(e<0?c=Math.max(c,e/(e-f)):f<0&&(d=Math.min(d,e/(e-f))),g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h))),dg&&h.positionScreen.z0&&D.z<1))g=A[t]=A[t]||new THREE.RenderableParticle,t++,u=g, +u.x=D.x/D.w,u.y=D.y/D.w,u.z=D.z,u.rotation=ea.rotation.z,u.scale.x=ea.scale.x*Math.abs(u.x-(D.x+e.projectionMatrix.n11)/(D.w+e.projectionMatrix.n14)),u.scale.y=ea.scale.y*Math.abs(u.y-(D.y+e.projectionMatrix.n22)/(D.w+e.projectionMatrix.n24)),u.material=ea.material,B.elements.push(u);f&&B.elements.sort(c);return B}};THREE.Quaternion=function(a,b,c,d){this.set(a||0,b||0,c||0,d!==void 0?d:1)}; THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,c,d){this.x=a;this.y=b;this.z=c;this.w=d;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,c=a.x*b,d=a.y*b,e=a.z*b,a=Math.cos(d),d=Math.sin(d),b=Math.cos(-e),e=Math.sin(-e),f=Math.cos(c),c=Math.sin(c),g=a*b,h=d*e;this.w=g*f-h*c;this.x=g*c+h*f;this.y=d*b*f+a*e*c;this.z=a*e*f-d*b*c;return this},setFromAxisAngle:function(a,b){var c=b/2,d=Math.sin(c); this.x=a.x*d;this.y=a.y*d;this.z=a.z*d;this.w=Math.cos(c);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,b+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,b-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,b-a.n11-a.n22+a.n33))/2;this.x=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-Math.abs(this.z):Math.abs(this.z); this.normalize();return this},calculateW:function(){this.w=-Math.sqrt(Math.abs(1-this.x*this.x-this.y*this.y-this.z*this.z));return this},inverse:function(){this.x*=-1;this.y*=-1;this.z*=-1;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){var a=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);a===0?this.w=this.z=this.y=this.x=0:(a=1/a,this.x*=a,this.y*=a,this.z*=a,this.w*=a);return this},multiplySelf:function(a){var b= -this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,h=a.z,a=a.w;this.x=b*a+e*f+c*h-d*g;this.y=c*a+e*g+d*f-b*h;this.z=d*a+e*h+b*g-c*f;this.w=e*a-b*f-c*g-d*h;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,h=this.z,i=this.w,k=i*c+g*e-h*d,j=i*d+h*c-f*e,o=i*e+f*d-g*c,c=-f* -c-g*d-h*e;b.x=k*i+c*-f+j*-h-o*-g;b.y=j*i+c*-g+o*-f-k*-h;b.z=o*i+c*-h+k*-g-j*-f;return b}}; +this.x,c=this.y,d=this.z,e=this.w,f=a.x,g=a.y,h=a.z,a=a.w;this.x=b*a+e*f+c*h-d*g;this.y=c*a+e*g+d*f-b*h;this.z=d*a+e*h+b*g-c*f;this.w=e*a-b*f-c*g-d*h;return this},multiply:function(a,b){this.x=a.x*b.w+a.y*b.z-a.z*b.y+a.w*b.x;this.y=-a.x*b.z+a.y*b.w+a.z*b.x+a.w*b.y;this.z=a.x*b.y-a.y*b.x+a.z*b.w+a.w*b.z;this.w=-a.x*b.x-a.y*b.y-a.z*b.z+a.w*b.w;return this},multiplyVector3:function(a,b){b||(b=a);var c=a.x,d=a.y,e=a.z,f=this.x,g=this.y,h=this.z,i=this.w,j=i*c+g*e-h*d,k=i*d+h*c-f*e,o=i*e+f*d-g*c,c=-f* +c-g*d-h*e;b.x=j*i+c*-f+k*-h-o*-g;b.y=k*i+c*-g+o*-f-j*-h;b.z=o*i+c*-h+j*-g-k*-f;return b}}; THREE.Quaternion.slerp=function(a,b,c,d){var e=a.w*b.w+a.x*b.x+a.y*b.y+a.z*b.z;e<0?(c.w=-b.w,c.x=-b.x,c.y=-b.y,c.z=-b.z,e=-e):c.copy(b);if(Math.abs(e)>=1)return c.w=a.w,c.x=a.x,c.y=a.y,c.z=a.z,c;var f=Math.acos(e),e=Math.sqrt(1-e*e);if(Math.abs(e)<0.0010)return c.w=0.5*(a.w+b.w),c.x=0.5*(a.x+b.x),c.y=0.5*(a.y+b.y),c.z=0.5*(a.z+b.z),c;b=Math.sin((1-d)*f)/e;d=Math.sin(d*f)/e;c.w=a.w*b+c.w*d;c.x=a.x*b+c.x*d;c.y=a.y*b+c.y*d;c.z=a.z*b+c.z*d;return c};THREE.Vertex=function(a){this.position=a||new THREE.Vector3}; THREE.Face3=function(a,b,c,d,e,f){this.a=a;this.b=b;this.c=c;this.normal=d instanceof THREE.Vector3?d:new THREE.Vector3;this.vertexNormals=d instanceof Array?d:[];this.color=e instanceof THREE.Color?e:new THREE.Color;this.vertexColors=e instanceof Array?e:[];this.vertexTangents=[];this.materialIndex=f;this.centroid=new THREE.Vector3}; THREE.Face4=function(a,b,c,d,e,f,g){this.a=a;this.b=b;this.c=c;this.d=d;this.normal=e instanceof THREE.Vector3?e:new THREE.Vector3;this.vertexNormals=e instanceof Array?e:[];this.color=f instanceof THREE.Color?f:new THREE.Color;this.vertexColors=f instanceof Array?f:[];this.vertexTangents=[];this.materialIndex=g;this.centroid=new THREE.Vector3};THREE.UV=function(a,b){this.u=a||0;this.v=b||0}; @@ -88,14 +88,14 @@ b;a++)c=this.faces[a],c.centroid.set(0,0,0),c instanceof THREE.Face3?(c.centroid b,c,d,e,f,g=new THREE.Vector3,h=new THREE.Vector3;a=0;for(b=this.faces.length;a0){var a;a=this.vertices[0].position;this.boundingBox?(this.boundingBox.min.copy(a),this.boundingBox.max.copy(a)):this.boundingBox={min:a.clone(),max:a.clone()};for(var b=this.boundingBox.min,c=this.boundingBox.max,d=1,e=this.vertices.length;dc.x)c.x=a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}},computeBoundingSphere:function(){for(var a=0,b=0,c=this.vertices.length;b0){var a;a=this.vertices[0].position;this.boundingBox?(this.boundingBox.min.copy(a),this.boundingBox.max.copy(a)):this.boundingBox={min:a.clone(),max:a.clone()};for(var b=this.boundingBox.min,c=this.boundingBox.max,d=1,e=this.vertices.length;dc.x)c.x=a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}},computeBoundingSphere:function(){for(var a,b=0,c=0,d=this.vertices.length;cb&&(b=a);this.boundingSphere={radius:b}},mergeVertices:function(){var a={},b=[],c=[],d,e=Math.pow(10,4),f,g;f=0;for(g=this.vertices.length;fthis.points.length-2?f:f+1;c[3]=f>this.points.length-3?f:f+2;k=this.points[c[0]];j=this.points[c[1]]; -o=this.points[c[2]];p=this.points[c[3]];h=g*g;i=g*h;d.x=b(k.x,j.x,o.x,p.x,g,h,i);d.y=b(k.y,j.y,o.y,p.y,g,h,i);d.z=b(k.z,j.z,o.z,p.z,g,h,i);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;athis.points.length-2?f:f+1;c[3]=f>this.points.length-3?f:f+2;j=this.points[c[0]];k=this.points[c[1]]; +o=this.points[c[2]];p=this.points[c[3]];h=g*g;i=g*h;d.x=b(j.x,k.x,o.x,p.x,g,h,i);d.y=b(j.y,k.y,o.y,p.y,g,h,i);d.z=b(j.z,k.z,o.z,p.z,g,h,i);return d};this.getControlPointsArray=function(){var a,b,c=this.points.length,d=[];for(a=0;a0&&(c(THREE.NormalBlending),b(1),e("rgba("+Math.floor(s.r*255)+","+Math.floor(s.g*255)+","+Math.floor(s.b*255)+","+r+")"),n.fillRect(Math.floor(ta.getX()), -Math.floor(ta.getY()),Math.floor(ta.getWidth()),Math.floor(ta.getHeight()))),ta.empty())};this.render=function(a,j){function o(a){var b,c,d,e;ea.setRGB(0,0,0);V.setRGB(0,0,0);H.setRGB(0,0,0);b=0;for(c=a.length;b> -1,H=i.height>>1,g=f.scale.x*m,l=f.scale.y*q,ea=g*j,h=l*H,pa.set(a.x-ea,a.y-h,a.x+ea,a.y+h),la.intersects(pa)&&(n.save(),n.translate(a.x,a.y),n.rotate(-f.rotation),n.scale(g,-l),n.translate(-j,-H),n.drawImage(i,0,0),n.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(ea=f.scale.x*m,h=f.scale.y*q,pa.set(a.x-ea,a.y-h,a.x+ea,a.y+h),la.intersects(pa)&&(d(g.color.getContextStyle()),e(g.color.getContextStyle()),n.save(),n.translate(a.x,a.y),n.rotate(-f.rotation),n.scale(ea,h),g.program(n),n.restore()))} -function r(a,e,f,g){b(g.opacity);c(g.blending);n.beginPath();n.moveTo(a.positionScreen.x,a.positionScreen.y);n.lineTo(e.positionScreen.x,e.positionScreen.y);n.closePath();if(g instanceof THREE.LineBasicMaterial){a=g.linewidth;if(E!=a)n.lineWidth=E=a;a=g.linecap;if(D!=a)n.lineCap=D=a;a=g.linejoin;if(B!=a)n.lineJoin=B=a;d(g.color.getContextStyle());n.stroke();pa.inflate(g.linewidth*2)}}function u(a,d,e,g,h,H,k,V){f.info.render.vertices+=3;f.info.render.faces++;b(V.opacity);c(V.blending);Y=a.positionScreen.x; -S=a.positionScreen.y;R=d.positionScreen.x;l=d.positionScreen.y;W=e.positionScreen.x;v=e.positionScreen.y;z(Y,S,R,l,W,v);if(V instanceof THREE.MeshBasicMaterial)if(V.map)V.map.mapping instanceof THREE.UVMapping&&(qa=k.uvs[0],Pa(Y,S,R,l,W,v,qa[g].u,qa[g].v,qa[h].u,qa[h].v,qa[H].u,qa[H].v,V.map));else if(V.envMap){if(V.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=j.matrixWorldInverse,ra.copy(k.vertexNormalsWorld[g]),Ba=(ra.x*a.n11+ra.y*a.n12+ra.z*a.n13)*0.5+0.5,wa=-(ra.x*a.n21+ra.y*a.n22+ -ra.z*a.n23)*0.5+0.5,ra.copy(k.vertexNormalsWorld[h]),xa=(ra.x*a.n11+ra.y*a.n12+ra.z*a.n13)*0.5+0.5,ya=-(ra.x*a.n21+ra.y*a.n22+ra.z*a.n23)*0.5+0.5,ra.copy(k.vertexNormalsWorld[H]),za=(ra.x*a.n11+ra.y*a.n12+ra.z*a.n13)*0.5+0.5,Aa=-(ra.x*a.n21+ra.y*a.n22+ra.z*a.n23)*0.5+0.5,Pa(Y,S,R,l,W,v,Ba,wa,xa,ya,za,Aa,V.envMap)}else V.wireframe?J(V.color,V.wireframeLinewidth,V.wireframeLinecap,V.wireframeLinejoin):Ea(V.color);else if(V instanceof THREE.MeshLambertMaterial)V.map&&!V.wireframe&&(V.map.mapping instanceof -THREE.UVMapping&&(qa=k.uvs[0],Pa(Y,S,R,l,W,v,qa[g].u,qa[g].v,qa[h].u,qa[h].v,qa[H].u,qa[H].v,V.map)),c(THREE.SubtractiveBlending)),Ia?!V.wireframe&&V.shading==THREE.SmoothShading&&k.vertexNormalsWorld.length==3?(O.r=aa.r=ca.r=ea.r,O.g=aa.g=ca.g=ea.g,O.b=aa.b=ca.b=ea.b,p(i,k.v1.positionWorld,k.vertexNormalsWorld[0],O),p(i,k.v2.positionWorld,k.vertexNormalsWorld[1],aa),p(i,k.v3.positionWorld,k.vertexNormalsWorld[2],ca),O.r=Math.max(0,Math.min(V.color.r*O.r,1)),O.g=Math.max(0,Math.min(V.color.g*O.g, -1)),O.b=Math.max(0,Math.min(V.color.b*O.b,1)),aa.r=Math.max(0,Math.min(V.color.r*aa.r,1)),aa.g=Math.max(0,Math.min(V.color.g*aa.g,1)),aa.b=Math.max(0,Math.min(V.color.b*aa.b,1)),ca.r=Math.max(0,Math.min(V.color.r*ca.r,1)),ca.g=Math.max(0,Math.min(V.color.g*ca.g,1)),ca.b=Math.max(0,Math.min(V.color.b*ca.b,1)),ga.r=(aa.r+ca.r)*0.5,ga.g=(aa.g+ca.g)*0.5,ga.b=(aa.b+ca.b)*0.5,sa=P(O,aa,ca,ga),Ja(Y,S,R,l,W,v,0,0,1,0,0,1,sa)):(U.r=ea.r,U.g=ea.g,U.b=ea.b,p(i,k.centroidWorld,k.normalWorld,U),U.r=Math.max(0, -Math.min(V.color.r*U.r,1)),U.g=Math.max(0,Math.min(V.color.g*U.g,1)),U.b=Math.max(0,Math.min(V.color.b*U.b,1)),V.wireframe?J(U,V.wireframeLinewidth,V.wireframeLinecap,V.wireframeLinejoin):Ea(U)):V.wireframe?J(V.color,V.wireframeLinewidth,V.wireframeLinecap,V.wireframeLinejoin):Ea(V.color);else if(V instanceof THREE.MeshDepthMaterial)na=j.near,ja=j.far,O.r=O.g=O.b=1-M(a.positionScreen.z,na,ja),aa.r=aa.g=aa.b=1-M(d.positionScreen.z,na,ja),ca.r=ca.g=ca.b=1-M(e.positionScreen.z,na,ja),ga.r=(aa.r+ca.r)* -0.5,ga.g=(aa.g+ca.g)*0.5,ga.b=(aa.b+ca.b)*0.5,sa=P(O,aa,ca,ga),Ja(Y,S,R,l,W,v,0,0,1,0,0,1,sa);else if(V instanceof THREE.MeshNormalMaterial)U.r=N(k.normalWorld.x),U.g=N(k.normalWorld.y),U.b=N(k.normalWorld.z),V.wireframe?J(U,V.wireframeLinewidth,V.wireframeLinecap,V.wireframeLinejoin):Ea(U)}function t(a,d,e,g,h,V,H,k,n){f.info.render.vertices+=4;f.info.render.faces++;b(k.opacity);c(k.blending);if(k.map||k.envMap)u(a,d,g,0,1,3,H,k,n),u(h,e,V,1,2,3,H,k,n);else if(Y=a.positionScreen.x,S=a.positionScreen.y, -R=d.positionScreen.x,l=d.positionScreen.y,W=e.positionScreen.x,v=e.positionScreen.y,X=g.positionScreen.x,L=g.positionScreen.y,Z=h.positionScreen.x,da=h.positionScreen.y,ba=V.positionScreen.x,T=V.positionScreen.y,k instanceof THREE.MeshBasicMaterial)A(Y,S,R,l,W,v,X,L),k.wireframe?J(k.color,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):Ea(k.color);else if(k instanceof THREE.MeshLambertMaterial)Ia?!k.wireframe&&k.shading==THREE.SmoothShading&&H.vertexNormalsWorld.length==4?(O.r=aa.r=ca.r= -ga.r=ea.r,O.g=aa.g=ca.g=ga.g=ea.g,O.b=aa.b=ca.b=ga.b=ea.b,p(i,H.v1.positionWorld,H.vertexNormalsWorld[0],O),p(i,H.v2.positionWorld,H.vertexNormalsWorld[1],aa),p(i,H.v4.positionWorld,H.vertexNormalsWorld[3],ca),p(i,H.v3.positionWorld,H.vertexNormalsWorld[2],ga),O.r=Math.max(0,Math.min(k.color.r*O.r,1)),O.g=Math.max(0,Math.min(k.color.g*O.g,1)),O.b=Math.max(0,Math.min(k.color.b*O.b,1)),aa.r=Math.max(0,Math.min(k.color.r*aa.r,1)),aa.g=Math.max(0,Math.min(k.color.g*aa.g,1)),aa.b=Math.max(0,Math.min(k.color.b* -aa.b,1)),ca.r=Math.max(0,Math.min(k.color.r*ca.r,1)),ca.g=Math.max(0,Math.min(k.color.g*ca.g,1)),ca.b=Math.max(0,Math.min(k.color.b*ca.b,1)),ga.r=Math.max(0,Math.min(k.color.r*ga.r,1)),ga.g=Math.max(0,Math.min(k.color.g*ga.g,1)),ga.b=Math.max(0,Math.min(k.color.b*ga.b,1)),sa=P(O,aa,ca,ga),z(Y,S,R,l,X,L),Ja(Y,S,R,l,X,L,0,0,1,0,0,1,sa),z(Z,da,W,v,ba,T),Ja(Z,da,W,v,ba,T,1,0,1,1,0,1,sa)):(U.r=ea.r,U.g=ea.g,U.b=ea.b,p(i,H.centroidWorld,H.normalWorld,U),U.r=Math.max(0,Math.min(k.color.r*U.r,1)),U.g=Math.max(0, -Math.min(k.color.g*U.g,1)),U.b=Math.max(0,Math.min(k.color.b*U.b,1)),A(Y,S,R,l,W,v,X,L),k.wireframe?J(U,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):Ea(U)):(A(Y,S,R,l,W,v,X,L),k.wireframe?J(k.color,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):Ea(k.color));else if(k instanceof THREE.MeshNormalMaterial)U.r=N(H.normalWorld.x),U.g=N(H.normalWorld.y),U.b=N(H.normalWorld.z),A(Y,S,R,l,W,v,X,L),k.wireframe?J(U,k.wireframeLinewidth,k.wireframeLinecap,k.wireframeLinejoin):Ea(U); -else if(k instanceof THREE.MeshDepthMaterial)na=j.near,ja=j.far,O.r=O.g=O.b=1-M(a.positionScreen.z,na,ja),aa.r=aa.g=aa.b=1-M(d.positionScreen.z,na,ja),ca.r=ca.g=ca.b=1-M(g.positionScreen.z,na,ja),ga.r=ga.g=ga.b=1-M(e.positionScreen.z,na,ja),sa=P(O,aa,ca,ga),z(Y,S,R,l,X,L),Ja(Y,S,R,l,X,L,0,0,1,0,0,1,sa),z(Z,da,W,v,ba,T),Ja(Z,da,W,v,ba,T,1,0,1,1,0,1,sa)}function z(a,b,c,d,e,f){n.beginPath();n.moveTo(a,b);n.lineTo(c,d);n.lineTo(e,f);n.lineTo(a,b);n.closePath()}function A(a,b,c,d,e,f,g,ea){n.beginPath(); -n.moveTo(a,b);n.lineTo(c,d);n.lineTo(e,f);n.lineTo(g,ea);n.lineTo(a,b);n.closePath()}function J(a,b,c,e){if(E!=b)n.lineWidth=E=b;if(D!=c)n.lineCap=D=c;if(B!=e)n.lineJoin=B=e;d(a.getContextStyle());n.stroke();pa.inflate(b*2)}function Ea(a){e(a.getContextStyle());n.fill()}function Pa(a,b,c,d,f,g,ea,h,l,i,k,j,V){if(V.image.width!=0){if(V.needsUpdate==!0||va[V.id]==void 0){var H=V.wrapS==THREE.RepeatWrapping,m=V.wrapT==THREE.RepeatWrapping;va[V.id]=n.createPattern(V.image,H&&m?"repeat":H&&!m?"repeat-x": -!H&&m?"repeat-y":"no-repeat");V.needsUpdate=!1}e(va[V.id]);var H=V.offset.x/V.repeat.x,m=V.offset.y/V.repeat.y,o=V.image.width*V.repeat.x,p=V.image.height*V.repeat.y,ea=(ea+H)*o,h=(h+m)*p,l=(l+H)*o,i=(i+m)*p,k=(k+H)*o,j=(j+m)*p;c-=a;d-=b;f-=a;g-=b;l-=ea;i-=h;k-=ea;j-=h;H=l*j-k*i;if(H==0){if(fa[V.id]==void 0)b=document.createElement("canvas"),b.width=V.image.width,b.height=V.image.height,a=b.getContext("2d"),a.drawImage(V.image,0,0),fa[V.id]=a.getImageData(0,0,V.image.width,V.image.height).data,delete b; -b=fa[V.id];ea=(Math.floor(ea)+Math.floor(h)*V.image.width)*4;U.setRGB(b[ea]/255,b[ea+1]/255,b[ea+2]/255);Ea(U)}else H=1/H,V=(j*c-i*f)*H,i=(j*d-i*g)*H,c=(l*f-k*c)*H,d=(l*g-k*d)*H,a=a-V*ea-c*h,ea=b-i*ea-d*h,n.save(),n.transform(V,i,c,d,a,ea),n.fill(),n.restore()}}function Ja(a,b,c,d,e,f,g,ea,h,l,i,V,k){var j,H;j=k.width-1;H=k.height-1;g*=j;ea*=H;h*=j;l*=H;i*=j;V*=H;c-=a;d-=b;e-=a;f-=b;h-=g;l-=ea;i-=g;V-=ea;H=1/(h*V-i*l);j=(V*c-l*e)*H;l=(V*d-l*f)*H;c=(h*e-i*c)*H;d=(h*f-i*d)*H;a=a-j*g-c*ea;b=b-l*g-d* -ea;n.save();n.transform(j,l,c,d,a,b);n.clip();n.drawImage(k,0,0);n.restore()}function P(a,b,c,d){var e=~~(a.r*255),f=~~(a.g*255),a=~~(a.b*255),g=~~(b.r*255),ea=~~(b.g*255),b=~~(b.b*255),h=~~(c.r*255),l=~~(c.g*255),c=~~(c.b*255),i=~~(d.r*255),V=~~(d.g*255),d=~~(d.b*255);Ca[0]=e<0?0:e>255?255:e;Ca[1]=f<0?0:f>255?255:f;Ca[2]=a<0?0:a>255?255:a;Ca[4]=g<0?0:g>255?255:g;Ca[5]=ea<0?0:ea>255?255:ea;Ca[6]=b<0?0:b>255?255:b;Ca[8]=h<0?0:h>255?255:h;Ca[9]=l<0?0:l>255?255:l;Ca[10]=c<0?0:c>255?255:c;Ca[12]=i<0? -0:i>255?255:i;Ca[13]=V<0?0:V>255?255:V;Ca[14]=d<0?0:d>255?255:d;La.putImageData(Oa,0,0);C.drawImage(Ka,0,0);return Ma}function M(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function N(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function Fa(a,b){var c=b.x-a.x,d=b.y-a.y,e=c*c+d*d;e!=0&&(e=1/Math.sqrt(e),c*=e,d*=e,b.x+=c,b.y+=d,a.x-=c,a.y-=d)}var Na,Qa,ua,Da;this.autoClear?this.clear():n.setTransform(1,0,0,-1,m,q);f.info.render.vertices=0;f.info.render.faces=0;g=k.projectScene(a,j,this.sortElements);h=g.elements; -i=g.lights;(Ia=i.length>0)&&o(i);Na=0;for(Qa=h.length;Na1?1:a}var d=this,e,f,g,h=new THREE.Projector,i=document.createElementNS("http://www.w3.org/2000/svg","svg"),k,j,o,p,m,q,n,s,r=new THREE.Rectangle,u=new THREE.Rectangle,t=!1,z=new THREE.Color,A=new THREE.Color,E=new THREE.Color,D=new THREE.Color,B,w=new THREE.Vector3,G=[],y=[],K,$,Q,Y=1;this.domElement=i;this.sortElements=this.sortObjects=this.autoClear=!0;this.info={render:{vertices:0, -faces:0}};this.setQuality=function(a){switch(a){case "high":Y=1;break;case "low":Y=0}};this.setSize=function(a,b){k=a;j=b;o=k/2;p=j/2;i.setAttribute("viewBox",-o+" "+-p+" "+k+" "+j);i.setAttribute("width",k);i.setAttribute("height",j);r.set(-o,-p,o,p)};this.clear=function(){for(;i.childNodes.length>0;)i.removeChild(i.childNodes[0])};this.render=function(k,j){var l,G,v,w;this.autoClear&&this.clear();d.info.render.vertices=0;d.info.render.faces=0;e=h.projectScene(k,j,this.sortElements);f=e.elements; -g=e.lights;Q=$=0;if(t=g.length>0){A.setRGB(0,0,0);E.setRGB(0,0,0);D.setRGB(0,0,0);l=0;for(G=g.length;l0&&(c(THREE.NormalBlending),b(1),e("rgba("+Math.floor(s.r*255)+","+Math.floor(s.g*255)+","+Math.floor(s.b*255)+","+r+")"),n.fillRect(Math.floor(ta.getX()), +Math.floor(ta.getY()),Math.floor(ta.getWidth()),Math.floor(ta.getHeight()))),ta.empty())};this.render=function(a,k){function o(a){var b,c,d,e;da.setRGB(0,0,0);Y.setRGB(0,0,0);G.setRGB(0,0,0);b=0;for(c=a.length;b> +1,G=i.height>>1,g=f.scale.x*m,l=f.scale.y*q,da=g*k,h=l*G,pa.set(a.x-da,a.y-h,a.x+da,a.y+h),la.intersects(pa)&&(n.save(),n.translate(a.x,a.y),n.rotate(-f.rotation),n.scale(g,-l),n.translate(-k,-G),n.drawImage(i,0,0),n.restore())}else g instanceof THREE.ParticleCanvasMaterial&&(da=f.scale.x*m,h=f.scale.y*q,pa.set(a.x-da,a.y-h,a.x+da,a.y+h),la.intersects(pa)&&(d(g.color.getContextStyle()),e(g.color.getContextStyle()),n.save(),n.translate(a.x,a.y),n.rotate(-f.rotation),n.scale(da,h),g.program(n),n.restore()))} +function r(a,e,f,g){b(g.opacity);c(g.blending);n.beginPath();n.moveTo(a.positionScreen.x,a.positionScreen.y);n.lineTo(e.positionScreen.x,e.positionScreen.y);n.closePath();if(g instanceof THREE.LineBasicMaterial){a=g.linewidth;if(z!=a)n.lineWidth=z=a;a=g.linecap;if(D!=a)n.lineCap=D=a;a=g.linejoin;if(H!=a)n.lineJoin=H=a;d(g.color.getContextStyle());n.stroke();pa.inflate(g.linewidth*2)}}function u(a,d,e,g,h,G,Y,j){f.info.render.vertices+=3;f.info.render.faces++;b(j.opacity);c(j.blending);X=a.positionScreen.x; +T=a.positionScreen.y;R=d.positionScreen.x;l=d.positionScreen.y;S=e.positionScreen.x;v=e.positionScreen.y;A(X,T,R,l,S,v);if(j instanceof THREE.MeshBasicMaterial)if(j.map)j.map.mapping instanceof THREE.UVMapping&&(qa=Y.uvs[0],Pa(X,T,R,l,S,v,qa[g].u,qa[g].v,qa[h].u,qa[h].v,qa[G].u,qa[G].v,j.map));else if(j.envMap){if(j.envMap.mapping instanceof THREE.SphericalReflectionMapping)a=k.matrixWorldInverse,ra.copy(Y.vertexNormalsWorld[g]),Ba=(ra.x*a.n11+ra.y*a.n12+ra.z*a.n13)*0.5+0.5,wa=-(ra.x*a.n21+ra.y*a.n22+ +ra.z*a.n23)*0.5+0.5,ra.copy(Y.vertexNormalsWorld[h]),xa=(ra.x*a.n11+ra.y*a.n12+ra.z*a.n13)*0.5+0.5,ya=-(ra.x*a.n21+ra.y*a.n22+ra.z*a.n23)*0.5+0.5,ra.copy(Y.vertexNormalsWorld[G]),za=(ra.x*a.n11+ra.y*a.n12+ra.z*a.n13)*0.5+0.5,Aa=-(ra.x*a.n21+ra.y*a.n22+ra.z*a.n23)*0.5+0.5,Pa(X,T,R,l,S,v,Ba,wa,xa,ya,za,Aa,j.envMap)}else j.wireframe?J(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):Ea(j.color);else if(j instanceof THREE.MeshLambertMaterial)j.map&&!j.wireframe&&(j.map.mapping instanceof +THREE.UVMapping&&(qa=Y.uvs[0],Pa(X,T,R,l,S,v,qa[g].u,qa[g].v,qa[h].u,qa[h].v,qa[G].u,qa[G].v,j.map)),c(THREE.SubtractiveBlending)),Ia?!j.wireframe&&j.shading==THREE.SmoothShading&&Y.vertexNormalsWorld.length==3?(L.r=V.r=ba.r=da.r,L.g=V.g=ba.g=da.g,L.b=V.b=ba.b=da.b,p(i,Y.v1.positionWorld,Y.vertexNormalsWorld[0],L),p(i,Y.v2.positionWorld,Y.vertexNormalsWorld[1],V),p(i,Y.v3.positionWorld,Y.vertexNormalsWorld[2],ba),L.r=Math.max(0,Math.min(j.color.r*L.r,1)),L.g=Math.max(0,Math.min(j.color.g*L.g,1)), +L.b=Math.max(0,Math.min(j.color.b*L.b,1)),V.r=Math.max(0,Math.min(j.color.r*V.r,1)),V.g=Math.max(0,Math.min(j.color.g*V.g,1)),V.b=Math.max(0,Math.min(j.color.b*V.b,1)),ba.r=Math.max(0,Math.min(j.color.r*ba.r,1)),ba.g=Math.max(0,Math.min(j.color.g*ba.g,1)),ba.b=Math.max(0,Math.min(j.color.b*ba.b,1)),ga.r=(V.r+ba.r)*0.5,ga.g=(V.g+ba.g)*0.5,ga.b=(V.b+ba.b)*0.5,sa=P(L,V,ba,ga),Ja(X,T,R,l,S,v,0,0,1,0,0,1,sa)):(U.r=da.r,U.g=da.g,U.b=da.b,p(i,Y.centroidWorld,Y.normalWorld,U),U.r=Math.max(0,Math.min(j.color.r* +U.r,1)),U.g=Math.max(0,Math.min(j.color.g*U.g,1)),U.b=Math.max(0,Math.min(j.color.b*U.b,1)),j.wireframe?J(U,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):Ea(U)):j.wireframe?J(j.color,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):Ea(j.color);else if(j instanceof THREE.MeshDepthMaterial)na=k.near,ja=k.far,L.r=L.g=L.b=1-N(a.positionScreen.z,na,ja),V.r=V.g=V.b=1-N(d.positionScreen.z,na,ja),ba.r=ba.g=ba.b=1-N(e.positionScreen.z,na,ja),ga.r=(V.r+ba.r)*0.5,ga.g=(V.g+ba.g)*0.5, +ga.b=(V.b+ba.b)*0.5,sa=P(L,V,ba,ga),Ja(X,T,R,l,S,v,0,0,1,0,0,1,sa);else if(j instanceof THREE.MeshNormalMaterial)U.r=O(Y.normalWorld.x),U.g=O(Y.normalWorld.y),U.b=O(Y.normalWorld.z),j.wireframe?J(U,j.wireframeLinewidth,j.wireframeLinecap,j.wireframeLinejoin):Ea(U)}function t(a,d,e,g,h,j,G,Y,n){f.info.render.vertices+=4;f.info.render.faces++;b(Y.opacity);c(Y.blending);if(Y.map||Y.envMap)u(a,d,g,0,1,3,G,Y,n),u(h,e,j,1,2,3,G,Y,n);else if(X=a.positionScreen.x,T=a.positionScreen.y,R=d.positionScreen.x, +l=d.positionScreen.y,S=e.positionScreen.x,v=e.positionScreen.y,W=g.positionScreen.x,M=g.positionScreen.y,Z=h.positionScreen.x,ca=h.positionScreen.y,aa=j.positionScreen.x,ea=j.positionScreen.y,Y instanceof THREE.MeshBasicMaterial)B(X,T,R,l,S,v,W,M),Y.wireframe?J(Y.color,Y.wireframeLinewidth,Y.wireframeLinecap,Y.wireframeLinejoin):Ea(Y.color);else if(Y instanceof THREE.MeshLambertMaterial)Ia?!Y.wireframe&&Y.shading==THREE.SmoothShading&&G.vertexNormalsWorld.length==4?(L.r=V.r=ba.r=ga.r=da.r,L.g=V.g= +ba.g=ga.g=da.g,L.b=V.b=ba.b=ga.b=da.b,p(i,G.v1.positionWorld,G.vertexNormalsWorld[0],L),p(i,G.v2.positionWorld,G.vertexNormalsWorld[1],V),p(i,G.v4.positionWorld,G.vertexNormalsWorld[3],ba),p(i,G.v3.positionWorld,G.vertexNormalsWorld[2],ga),L.r=Math.max(0,Math.min(Y.color.r*L.r,1)),L.g=Math.max(0,Math.min(Y.color.g*L.g,1)),L.b=Math.max(0,Math.min(Y.color.b*L.b,1)),V.r=Math.max(0,Math.min(Y.color.r*V.r,1)),V.g=Math.max(0,Math.min(Y.color.g*V.g,1)),V.b=Math.max(0,Math.min(Y.color.b*V.b,1)),ba.r=Math.max(0, +Math.min(Y.color.r*ba.r,1)),ba.g=Math.max(0,Math.min(Y.color.g*ba.g,1)),ba.b=Math.max(0,Math.min(Y.color.b*ba.b,1)),ga.r=Math.max(0,Math.min(Y.color.r*ga.r,1)),ga.g=Math.max(0,Math.min(Y.color.g*ga.g,1)),ga.b=Math.max(0,Math.min(Y.color.b*ga.b,1)),sa=P(L,V,ba,ga),A(X,T,R,l,W,M),Ja(X,T,R,l,W,M,0,0,1,0,0,1,sa),A(Z,ca,S,v,aa,ea),Ja(Z,ca,S,v,aa,ea,1,0,1,1,0,1,sa)):(U.r=da.r,U.g=da.g,U.b=da.b,p(i,G.centroidWorld,G.normalWorld,U),U.r=Math.max(0,Math.min(Y.color.r*U.r,1)),U.g=Math.max(0,Math.min(Y.color.g* +U.g,1)),U.b=Math.max(0,Math.min(Y.color.b*U.b,1)),B(X,T,R,l,S,v,W,M),Y.wireframe?J(U,Y.wireframeLinewidth,Y.wireframeLinecap,Y.wireframeLinejoin):Ea(U)):(B(X,T,R,l,S,v,W,M),Y.wireframe?J(Y.color,Y.wireframeLinewidth,Y.wireframeLinecap,Y.wireframeLinejoin):Ea(Y.color));else if(Y instanceof THREE.MeshNormalMaterial)U.r=O(G.normalWorld.x),U.g=O(G.normalWorld.y),U.b=O(G.normalWorld.z),B(X,T,R,l,S,v,W,M),Y.wireframe?J(U,Y.wireframeLinewidth,Y.wireframeLinecap,Y.wireframeLinejoin):Ea(U);else if(Y instanceof +THREE.MeshDepthMaterial)na=k.near,ja=k.far,L.r=L.g=L.b=1-N(a.positionScreen.z,na,ja),V.r=V.g=V.b=1-N(d.positionScreen.z,na,ja),ba.r=ba.g=ba.b=1-N(g.positionScreen.z,na,ja),ga.r=ga.g=ga.b=1-N(e.positionScreen.z,na,ja),sa=P(L,V,ba,ga),A(X,T,R,l,W,M),Ja(X,T,R,l,W,M,0,0,1,0,0,1,sa),A(Z,ca,S,v,aa,ea),Ja(Z,ca,S,v,aa,ea,1,0,1,1,0,1,sa)}function A(a,b,c,d,e,f){n.beginPath();n.moveTo(a,b);n.lineTo(c,d);n.lineTo(e,f);n.lineTo(a,b);n.closePath()}function B(a,b,c,d,e,f,g,da){n.beginPath();n.moveTo(a,b);n.lineTo(c, +d);n.lineTo(e,f);n.lineTo(g,da);n.lineTo(a,b);n.closePath()}function J(a,b,c,e){if(z!=b)n.lineWidth=z=b;if(D!=c)n.lineCap=D=c;if(H!=e)n.lineJoin=H=e;d(a.getContextStyle());n.stroke();pa.inflate(b*2)}function Ea(a){e(a.getContextStyle());n.fill()}function Pa(a,b,c,d,f,g,da,h,l,i,Y,j,G){if(G.image.width!=0){if(G.needsUpdate==!0||va[G.id]==void 0){var k=G.wrapS==THREE.RepeatWrapping,m=G.wrapT==THREE.RepeatWrapping;va[G.id]=n.createPattern(G.image,k&&m?"repeat":k&&!m?"repeat-x":!k&&m?"repeat-y":"no-repeat"); +G.needsUpdate=!1}e(va[G.id]);var k=G.offset.x/G.repeat.x,m=G.offset.y/G.repeat.y,o=G.image.width*G.repeat.x,p=G.image.height*G.repeat.y,da=(da+k)*o,h=(h+m)*p,l=(l+k)*o,i=(i+m)*p,Y=(Y+k)*o,j=(j+m)*p;c-=a;d-=b;f-=a;g-=b;l-=da;i-=h;Y-=da;j-=h;k=l*j-Y*i;if(k==0){if(fa[G.id]==void 0)b=document.createElement("canvas"),b.width=G.image.width,b.height=G.image.height,a=b.getContext("2d"),a.drawImage(G.image,0,0),fa[G.id]=a.getImageData(0,0,G.image.width,G.image.height).data,delete b;b=fa[G.id];da=(Math.floor(da)+ +Math.floor(h)*G.image.width)*4;U.setRGB(b[da]/255,b[da+1]/255,b[da+2]/255);Ea(U)}else k=1/k,G=(j*c-i*f)*k,i=(j*d-i*g)*k,c=(l*f-Y*c)*k,d=(l*g-Y*d)*k,a=a-G*da-c*h,da=b-i*da-d*h,n.save(),n.transform(G,i,c,d,a,da),n.fill(),n.restore()}}function Ja(a,b,c,d,e,f,g,da,h,l,i,Y,G){var k,j;k=G.width-1;j=G.height-1;g*=k;da*=j;h*=k;l*=j;i*=k;Y*=j;c-=a;d-=b;e-=a;f-=b;h-=g;l-=da;i-=g;Y-=da;j=1/(h*Y-i*l);k=(Y*c-l*e)*j;l=(Y*d-l*f)*j;c=(h*e-i*c)*j;d=(h*f-i*d)*j;a=a-k*g-c*da;b=b-l*g-d*da;n.save();n.transform(k,l,c, +d,a,b);n.clip();n.drawImage(G,0,0);n.restore()}function P(a,b,c,d){var e=~~(a.r*255),f=~~(a.g*255),a=~~(a.b*255),g=~~(b.r*255),da=~~(b.g*255),b=~~(b.b*255),h=~~(c.r*255),l=~~(c.g*255),c=~~(c.b*255),i=~~(d.r*255),Y=~~(d.g*255),d=~~(d.b*255);Ca[0]=e<0?0:e>255?255:e;Ca[1]=f<0?0:f>255?255:f;Ca[2]=a<0?0:a>255?255:a;Ca[4]=g<0?0:g>255?255:g;Ca[5]=da<0?0:da>255?255:da;Ca[6]=b<0?0:b>255?255:b;Ca[8]=h<0?0:h>255?255:h;Ca[9]=l<0?0:l>255?255:l;Ca[10]=c<0?0:c>255?255:c;Ca[12]=i<0?0:i>255?255:i;Ca[13]=Y<0?0:Y>255? +255:Y;Ca[14]=d<0?0:d>255?255:d;La.putImageData(Oa,0,0);C.drawImage(Ka,0,0);return Ma}function N(a,b,c){a=(a-b)/(c-b);return a*a*(3-2*a)}function O(a){a=(a+1)*0.5;return a<0?0:a>1?1:a}function Fa(a,b){var c=b.x-a.x,d=b.y-a.y,e=c*c+d*d;e!=0&&(e=1/Math.sqrt(e),c*=e,d*=e,b.x+=c,b.y+=d,a.x-=c,a.y-=d)}var Na,Qa,ua,Da;this.autoClear?this.clear():n.setTransform(1,0,0,-1,m,q);f.info.render.vertices=0;f.info.render.faces=0;g=j.projectScene(a,k,this.sortElements);h=g.elements;i=g.lights;(Ia=i.length>0)&&o(i); +Na=0;for(Qa=h.length;Na1?1:a}var d=this,e,f,g,h=new THREE.Projector,i=document.createElementNS("http://www.w3.org/2000/svg","svg"),j,k,o,p,m,q,n,s,r=new THREE.Rectangle,u=new THREE.Rectangle,t=!1,A=new THREE.Color,B=new THREE.Color,z=new THREE.Color,D=new THREE.Color,H,w=new THREE.Vector3,F=[],y=[],K,$,Q,X=1;this.domElement=i;this.sortElements=this.sortObjects=this.autoClear=!0;this.info={render:{vertices:0, +faces:0}};this.setQuality=function(a){switch(a){case "high":X=1;break;case "low":X=0}};this.setSize=function(a,b){j=a;k=b;o=j/2;p=k/2;i.setAttribute("viewBox",-o+" "+-p+" "+j+" "+k);i.setAttribute("width",j);i.setAttribute("height",k);r.set(-o,-p,o,p)};this.clear=function(){for(;i.childNodes.length>0;)i.removeChild(i.childNodes[0])};this.render=function(k,j){var l,F,v,w;this.autoClear&&this.clear();d.info.render.vertices=0;d.info.render.faces=0;e=h.projectScene(k,j,this.sortElements);f=e.elements; +g=e.lights;Q=$=0;if(t=g.length>0){B.setRGB(0,0,0);z.setRGB(0,0,0);D.setRGB(0,0,0);l=0;for(F=g.length;l=0;c--)a[c].object===b&&a.splice(c,1)}function n(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function s(a,b,c,d,e){d.program||R.initMaterial(d,b,c,e);if(d.morphTargets&&!e.__webglMorphTargetInfluences){e.__webglMorphTargetInfluences= -new Float32Array(R.maxMorphTargets);for(var f=0,g=R.maxMorphTargets;f0;this.getContext=function(){return l};this.supportsVertexTextures=function(){return la};this.setSize=function(a,b){w.width=a;w.height=b;this.setViewport(0,0,w.width,w.height)};this.setViewport=function(a,b,c,d){na=a;ja=b;sa=c;qa=d;l.viewport(na,ja,sa,qa)};this.setScissor=function(a,b,c,d){l.scissor(a,b,c,d)};this.enableScissorTest=function(a){a?l.enable(l.SCISSOR_TEST):l.disable(l.SCISSOR_TEST)};this.setClearColorHex=function(a,b){Q.setHex(a); -Y=b;l.clearColor(Q.r,Q.g,Q.b,Y)};this.setClearColor=function(a,b){Q.copy(a);Y=b;l.clearColor(Q.r,Q.g,Q.b,Y)};this.getClearColor=function(){return Q};this.getClearAlpha=function(){return Y};this.clear=function(a,b,c){var d=0;if(a===void 0||a)d|=l.COLOR_BUFFER_BIT;if(b===void 0||b)d|=l.DEPTH_BUFFER_BIT;if(c===void 0||c)d|=l.STENCIL_BUFFER_BIT;l.clear(d)};this.clearTarget=function(a,b,c,d){this.setRenderTarget(a);this.clear(b,c,d)};this.addPostPlugin=function(a){a.init(this);this.renderPluginsPost.push(a)}; -this.addPrePlugin=function(a){a.init(this);this.renderPluginsPre.push(a)};this.deallocateObject=function(a){if(a.__webglInit)if(a.__webglInit=!1,delete a._modelViewMatrix,delete a._normalMatrixArray,delete a._modelViewMatrixArray,delete a._objectMatrixArray,a instanceof THREE.Mesh)for(var b in a.geometry.geometryGroups){var c=a.geometry.geometryGroups[b];l.deleteBuffer(c.__webglVertexBuffer);l.deleteBuffer(c.__webglNormalBuffer);l.deleteBuffer(c.__webglTangentBuffer);l.deleteBuffer(c.__webglColorBuffer); -l.deleteBuffer(c.__webglUVBuffer);l.deleteBuffer(c.__webglUV2Buffer);l.deleteBuffer(c.__webglSkinVertexABuffer);l.deleteBuffer(c.__webglSkinVertexBBuffer);l.deleteBuffer(c.__webglSkinIndicesBuffer);l.deleteBuffer(c.__webglSkinWeightsBuffer);l.deleteBuffer(c.__webglFaceBuffer);l.deleteBuffer(c.__webglLineBuffer);if(c.numMorphTargets)for(var d=0,e=c.numMorphTargets;d=0)a&&(l.bindBuffer(l.ARRAY_BUFFER,e.__webglVertexBuffer),l.vertexAttribPointer(b.position,3,l.FLOAT,!1,0,0));else if(f.morphTargetBase){c=d.program.attributes;f.morphTargetBase!==-1?(l.bindBuffer(l.ARRAY_BUFFER, -e.__webglMorphTargetsBuffers[f.morphTargetBase]),l.vertexAttribPointer(c.position,3,l.FLOAT,!1,0,0)):c.position>=0&&(l.bindBuffer(l.ARRAY_BUFFER,e.__webglVertexBuffer),l.vertexAttribPointer(c.position,3,l.FLOAT,!1,0,0));if(f.morphTargetForcedOrder.length){g=0;var i=f.morphTargetForcedOrder;for(h=f.morphTargetInfluences;gk&&(j=m,k=h[j]);l.bindBuffer(l.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[j]);l.vertexAttribPointer(c["morphTarget"+g],3,l.FLOAT,!1,0,0);f.__webglMorphTargetInfluences[g]=k;i[j]=1;k=-1;g++}}d.program.uniforms.morphTargetInfluences!==null&&l.uniform1fv(d.program.uniforms.morphTargetInfluences,f.__webglMorphTargetInfluences)}if(a){if(e.__webglCustomAttributesList){g= +a.__webglColorBuffer),l.bufferData(l.ARRAY_BUFFER,m,b);if(q){i=0;for(k=q.length;i=0;c--)a[c].object===b&&a.splice(c,1)}function n(a,b){for(var c=a.length-1;c>=0;c--)a[c]===b&&a.splice(c,1)}function s(a,b,c,d,e){d.program|| +R.initMaterial(d,b,c,e);if(d.morphTargets&&!e.__webglMorphTargetInfluences){e.__webglMorphTargetInfluences=new Float32Array(R.maxMorphTargets);for(var f=0,g=R.maxMorphTargets;f0;this.getContext=function(){return l};this.supportsVertexTextures=function(){return la};this.setSize=function(a,b){w.width=a;w.height=b;this.setViewport(0,0,w.width,w.height)};this.setViewport=function(a, +b,c,d){na=a;ja=b;sa=c;qa=d;l.viewport(na,ja,sa,qa)};this.setScissor=function(a,b,c,d){l.scissor(a,b,c,d)};this.enableScissorTest=function(a){a?l.enable(l.SCISSOR_TEST):l.disable(l.SCISSOR_TEST)};this.setClearColorHex=function(a,b){Q.setHex(a);X=b;l.clearColor(Q.r,Q.g,Q.b,X)};this.setClearColor=function(a,b){Q.copy(a);X=b;l.clearColor(Q.r,Q.g,Q.b,X)};this.getClearColor=function(){return Q};this.getClearAlpha=function(){return X};this.clear=function(a,b,c){var d=0;if(a===void 0||a)d|=l.COLOR_BUFFER_BIT; +if(b===void 0||b)d|=l.DEPTH_BUFFER_BIT;if(c===void 0||c)d|=l.STENCIL_BUFFER_BIT;l.clear(d)};this.clearTarget=function(a,b,c,d){this.setRenderTarget(a);this.clear(b,c,d)};this.addPostPlugin=function(a){a.init(this);this.renderPluginsPost.push(a)};this.addPrePlugin=function(a){a.init(this);this.renderPluginsPre.push(a)};this.deallocateObject=function(a){if(a.__webglInit)if(a.__webglInit=!1,delete a._modelViewMatrix,delete a._normalMatrixArray,delete a._modelViewMatrixArray,delete a._objectMatrixArray, +a instanceof THREE.Mesh)for(var b in a.geometry.geometryGroups){var c=a.geometry.geometryGroups[b];l.deleteBuffer(c.__webglVertexBuffer);l.deleteBuffer(c.__webglNormalBuffer);l.deleteBuffer(c.__webglTangentBuffer);l.deleteBuffer(c.__webglColorBuffer);l.deleteBuffer(c.__webglUVBuffer);l.deleteBuffer(c.__webglUV2Buffer);l.deleteBuffer(c.__webglSkinVertexABuffer);l.deleteBuffer(c.__webglSkinVertexBBuffer);l.deleteBuffer(c.__webglSkinIndicesBuffer);l.deleteBuffer(c.__webglSkinWeightsBuffer);l.deleteBuffer(c.__webglFaceBuffer); +l.deleteBuffer(c.__webglLineBuffer);if(c.numMorphTargets)for(var d=0,e=c.numMorphTargets;d=0&&e.vertexNormalBuffer&&(l.bindBuffer(l.ARRAY_BUFFER,e.vertexNormalBuffer),l.vertexAttribPointer(a.normal,e.vertexNormalBuffer.itemSize,l.FLOAT,!1,0,d[f].index*12)),a.uv>=0&&e.vertexUvBuffer&& +(e.vertexUvBuffer?(l.bindBuffer(l.ARRAY_BUFFER,e.vertexUvBuffer),l.vertexAttribPointer(a.uv,e.vertexUvBuffer.itemSize,l.FLOAT,!1,0,d[f].index*8),l.enableVertexAttribArray(a.uv)):l.disableVertexAttribArray(a.uv)),a.color>=0&&e.vertexColorBuffer&&(l.bindBuffer(l.ARRAY_BUFFER,e.vertexColorBuffer),l.vertexAttribPointer(a.color,e.vertexColorBuffer.itemSize,l.FLOAT,!1,0,d[f].index*16)),l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,e.vertexIndexBuffer)),l.drawElements(l.TRIANGLES,d[f].count,l.UNSIGNED_SHORT,d[f].start* +2),R.info.render.calls++,R.info.render.vertices+=d[f].count,R.info.render.faces+=d[f].count/3}};this.renderBuffer=function(a,b,c,d,e,f){if(d.opacity!==0){var g,h,c=s(a,b,c,d,f),b=c.attributes,a=!1,c=e.id*16777215+c.id*2+(d.wireframe?1:0);c!==Z&&(Z=c,a=!0);if(!d.morphTargets&&b.position>=0)a&&(l.bindBuffer(l.ARRAY_BUFFER,e.__webglVertexBuffer),l.vertexAttribPointer(b.position,3,l.FLOAT,!1,0,0));else if(f.morphTargetBase){c=d.program.attributes;f.morphTargetBase!==-1?(l.bindBuffer(l.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[f.morphTargetBase]), +l.vertexAttribPointer(c.position,3,l.FLOAT,!1,0,0)):c.position>=0&&(l.bindBuffer(l.ARRAY_BUFFER,e.__webglVertexBuffer),l.vertexAttribPointer(c.position,3,l.FLOAT,!1,0,0));if(f.morphTargetForcedOrder.length){g=0;var i=f.morphTargetForcedOrder;for(h=f.morphTargetInfluences;gk&&(j=m,k=h[j]);l.bindBuffer(l.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[j]);l.vertexAttribPointer(c["morphTarget"+g],3,l.FLOAT,!1,0,0);f.__webglMorphTargetInfluences[g]=k;i[j]=1;k=-1;g++}}d.program.uniforms.morphTargetInfluences!==null&&l.uniform1fv(d.program.uniforms.morphTargetInfluences,f.__webglMorphTargetInfluences)}if(a){if(e.__webglCustomAttributesList){g= 0;for(h=e.__webglCustomAttributesList.length;g=0&&(l.bindBuffer(l.ARRAY_BUFFER,c.buffer),l.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,l.FLOAT,!1,0,0))}b.color>=0&&(l.bindBuffer(l.ARRAY_BUFFER,e.__webglColorBuffer),l.vertexAttribPointer(b.color,3,l.FLOAT,!1,0,0));b.normal>=0&&(l.bindBuffer(l.ARRAY_BUFFER,e.__webglNormalBuffer),l.vertexAttribPointer(b.normal,3,l.FLOAT,!1,0,0));b.tangent>=0&&(l.bindBuffer(l.ARRAY_BUFFER, e.__webglTangentBuffer),l.vertexAttribPointer(b.tangent,4,l.FLOAT,!1,0,0));b.uv>=0&&(e.__webglUVBuffer?(l.bindBuffer(l.ARRAY_BUFFER,e.__webglUVBuffer),l.vertexAttribPointer(b.uv,2,l.FLOAT,!1,0,0),l.enableVertexAttribArray(b.uv)):l.disableVertexAttribArray(b.uv));b.uv2>=0&&(e.__webglUV2Buffer?(l.bindBuffer(l.ARRAY_BUFFER,e.__webglUV2Buffer),l.vertexAttribPointer(b.uv2,2,l.FLOAT,!1,0,0),l.enableVertexAttribArray(b.uv2)):l.disableVertexAttribArray(b.uv2));d.skinning&&b.skinVertexA>=0&&b.skinVertexB>= 0&&b.skinIndex>=0&&b.skinWeight>=0&&(l.bindBuffer(l.ARRAY_BUFFER,e.__webglSkinVertexABuffer),l.vertexAttribPointer(b.skinVertexA,4,l.FLOAT,!1,0,0),l.bindBuffer(l.ARRAY_BUFFER,e.__webglSkinVertexBBuffer),l.vertexAttribPointer(b.skinVertexB,4,l.FLOAT,!1,0,0),l.bindBuffer(l.ARRAY_BUFFER,e.__webglSkinIndicesBuffer),l.vertexAttribPointer(b.skinIndex,4,l.FLOAT,!1,0,0),l.bindBuffer(l.ARRAY_BUFFER,e.__webglSkinWeightsBuffer),l.vertexAttribPointer(b.skinWeight,4,l.FLOAT,!1,0,0))}f instanceof THREE.Mesh?(d.wireframe? (d=d.wireframeLinewidth,d!==fa&&(l.lineWidth(d),fa=d),a&&l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,e.__webglLineBuffer),l.drawElements(l.LINES,e.__webglLineCount,l.UNSIGNED_SHORT,0)):(a&&l.bindBuffer(l.ELEMENT_ARRAY_BUFFER,e.__webglFaceBuffer),l.drawElements(l.TRIANGLES,e.__webglFaceCount,l.UNSIGNED_SHORT,0)),R.info.render.calls++,R.info.render.vertices+=e.__webglFaceCount,R.info.render.faces+=e.__webglFaceCount/3):f instanceof THREE.Line?(f=f.type===THREE.LineStrip?l.LINE_STRIP:l.LINES,d=d.linewidth,d!== -fa&&(l.lineWidth(d),fa=d),l.drawArrays(f,0,e.__webglLineCount),R.info.render.calls++):f instanceof THREE.ParticleSystem?(l.drawArrays(l.POINTS,0,e.__webglParticleCount),R.info.render.calls++,R.info.render.points+=e.__webglParticleCount):f instanceof THREE.Ribbon&&(l.drawArrays(l.TRIANGLE_STRIP,0,e.__webglVertexCount),R.info.render.calls++)}};this.render=function(a,b,c,d){var e,f,g,m,n=a.lights,o=a.fog;L=-1;this.autoUpdateObjects&&this.initWebGLObjects(a);b.parent===void 0&&(console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it..."), +fa&&(l.lineWidth(d),fa=d),l.drawArrays(f,0,e.__webglLineCount),R.info.render.calls++):f instanceof THREE.ParticleSystem?(l.drawArrays(l.POINTS,0,e.__webglParticleCount),R.info.render.calls++,R.info.render.points+=e.__webglParticleCount):f instanceof THREE.Ribbon&&(l.drawArrays(l.TRIANGLE_STRIP,0,e.__webglVertexCount),R.info.render.calls++)}};this.render=function(a,b,c,d){var e,f,g,m,n=a.lights,o=a.fog;M=-1;this.autoUpdateObjects&&this.initWebGLObjects(a);b.parent===void 0&&(console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it..."), a.add(b));this.autoUpdateScene&&a.updateMatrixWorld();i(this.renderPluginsPre,a,b);R.info.render.calls=0;R.info.render.vertices=0;R.info.render.faces=0;R.info.render.points=0;b.matrixWorldInverse.getInverse(b.matrixWorld);if(!b._viewMatrixArray)b._viewMatrixArray=new Float32Array(16);b.matrixWorldInverse.flattenToArray(b._viewMatrixArray);if(!b._projectionMatrixArray)b._projectionMatrixArray=new Float32Array(16);b.projectionMatrix.flattenToArray(b._projectionMatrixArray);ya.multiply(b.projectionMatrix, b.matrixWorldInverse);xa.setFromMatrix(ya);this.setRenderTarget(c);(this.autoClear||d)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);m=a.__webglObjects;d=0;for(e=m.length;d=0)y=q.geometry.materials[y],y.transparent?(p.transparent=y,p.opaque=null):(p.opaque=y,p.transparent=null)}else if(y)y.transparent?(p.transparent=y,p.opaque=null):(p.opaque=y,p.transparent=null);f.render=!0;if(this.sortObjects)g.renderDepth?f.z=g.renderDepth:(za.copy(g.position),ya.multiplyVector3(za),f.z=za.z)}this.sortObjects&&m.sort(h);m=a.__webglObjectsImmediate;d=0;for(e=m.length;d65535&&(v[w].counter+=1,C=v[w].hash+"_"+v[w].counter,H.geometryGroups[C]===void 0&&(H.geometryGroups[C]={faces3:[],faces4:[],materialIndex:u,vertices:0,numMorphTargets:z})),y instanceof THREE.Face3?H.geometryGroups[C].faces3.push(s): -H.geometryGroups[C].faces4.push(s),H.geometryGroups[C].vertices+=t;H.geometryGroupsList=[];s=void 0;for(s in H.geometryGroups)H.geometryGroups[s].id=da++,H.geometryGroupsList.push(H.geometryGroups[s])}for(k in j.geometryGroups)if(H=j.geometryGroups[k],!H.__webglVertexBuffer){s=H;s.__webglVertexBuffer=l.createBuffer();s.__webglNormalBuffer=l.createBuffer();s.__webglTangentBuffer=l.createBuffer();s.__webglColorBuffer=l.createBuffer();s.__webglUVBuffer=l.createBuffer();s.__webglUV2Buffer=l.createBuffer(); -s.__webglSkinVertexABuffer=l.createBuffer();s.__webglSkinVertexBBuffer=l.createBuffer();s.__webglSkinIndicesBuffer=l.createBuffer();s.__webglSkinWeightsBuffer=l.createBuffer();s.__webglFaceBuffer=l.createBuffer();s.__webglLineBuffer=l.createBuffer();if(s.numMorphTargets){y=r=void 0;s.__webglMorphTargetsBuffers=[];r=0;for(y=s.numMorphTargets;r0||t.faceVertexUvs.length>0)H.__uvArray=new Float32Array(s*2);if(t.faceUvs.length>1||t.faceVertexUvs.length>1)H.__uv2Array=new Float32Array(s*2)}if(u.geometry.skinWeights.length&&u.geometry.skinIndices.length)H.__skinVertexAArray= -new Float32Array(s*4),H.__skinVertexBArray=new Float32Array(s*4),H.__skinIndexArray=new Float32Array(s*4),H.__skinWeightArray=new Float32Array(s*4);H.__faceArray=new Uint16Array(y*3);H.__lineArray=new Uint16Array(w*2);if(H.numMorphTargets){H.__morphTargetsArrays=[];u=0;for(t=H.numMorphTargets;u0&&(l.bindBuffer(l.ARRAY_BUFFER,r.__webglSkinVertexABuffer),l.bufferData(l.ARRAY_BUFFER,X,y),l.bindBuffer(l.ARRAY_BUFFER, -r.__webglSkinVertexBBuffer),l.bufferData(l.ARRAY_BUFFER,W,y),l.bindBuffer(l.ARRAY_BUFFER,r.__webglSkinIndicesBuffer),l.bufferData(l.ARRAY_BUFFER,D,y),l.bindBuffer(l.ARRAY_BUFFER,r.__webglSkinWeightsBuffer),l.bufferData(l.ARRAY_BUFFER,oa,y))}if(za&&w){C=0;for(v=G.length;C0&&(l.bindBuffer(l.ARRAY_BUFFER,r.__webglColorBuffer),l.bufferData(l.ARRAY_BUFFER,U,y))}if($&&Y.hasTangents){C=0;for(v=G.length;C0&&(l.bindBuffer(l.ARRAY_BUFFER,r.__webglUVBuffer),l.bufferData(l.ARRAY_BUFFER,ga,y))}if(sa&&Ba&&B){C=0;for(v=G.length;C -0&&(l.bindBuffer(l.ARRAY_BUFFER,r.__webglUV2Buffer),l.bufferData(l.ARRAY_BUFFER,F,y))}if(qa){C=0;for(v=G.length;C65535&&(v[w].counter+=1,C=v[w].hash+"_"+v[w].counter,G.geometryGroups[C]===void 0&&(G.geometryGroups[C]={faces3:[],faces4:[],materialIndex:u,vertices:0,numMorphTargets:A})),y instanceof THREE.Face3? +G.geometryGroups[C].faces3.push(s):G.geometryGroups[C].faces4.push(s),G.geometryGroups[C].vertices+=t;G.geometryGroupsList=[];s=void 0;for(s in G.geometryGroups)G.geometryGroups[s].id=ca++,G.geometryGroupsList.push(G.geometryGroups[s])}for(k in j.geometryGroups)if(G=j.geometryGroups[k],!G.__webglVertexBuffer){s=G;s.__webglVertexBuffer=l.createBuffer();s.__webglNormalBuffer=l.createBuffer();s.__webglTangentBuffer=l.createBuffer();s.__webglColorBuffer=l.createBuffer();s.__webglUVBuffer=l.createBuffer(); +s.__webglUV2Buffer=l.createBuffer();s.__webglSkinVertexABuffer=l.createBuffer();s.__webglSkinVertexBBuffer=l.createBuffer();s.__webglSkinIndicesBuffer=l.createBuffer();s.__webglSkinWeightsBuffer=l.createBuffer();s.__webglFaceBuffer=l.createBuffer();s.__webglLineBuffer=l.createBuffer();if(s.numMorphTargets){y=r=void 0;s.__webglMorphTargetsBuffers=[];r=0;for(y=s.numMorphTargets;r0||t.faceVertexUvs.length>0)G.__uvArray=new Float32Array(s*2);if(t.faceUvs.length>1||t.faceVertexUvs.length>1)G.__uv2Array=new Float32Array(s*2)}if(u.geometry.skinWeights.length&&u.geometry.skinIndices.length)G.__skinVertexAArray= +new Float32Array(s*4),G.__skinVertexBArray=new Float32Array(s*4),G.__skinIndexArray=new Float32Array(s*4),G.__skinWeightArray=new Float32Array(s*4);G.__faceArray=new Uint16Array(y*3);G.__lineArray=new Uint16Array(w*2);if(G.numMorphTargets){G.__morphTargetsArrays=[];u=0;for(t=G.numMorphTargets;u0&&(l.bindBuffer(l.ARRAY_BUFFER,r.__webglSkinVertexABuffer),l.bufferData(l.ARRAY_BUFFER,W,y),l.bindBuffer(l.ARRAY_BUFFER,r.__webglSkinVertexBBuffer),l.bufferData(l.ARRAY_BUFFER,V,y),l.bindBuffer(l.ARRAY_BUFFER,r.__webglSkinIndicesBuffer),l.bufferData(l.ARRAY_BUFFER,D,y),l.bindBuffer(l.ARRAY_BUFFER,r.__webglSkinWeightsBuffer),l.bufferData(l.ARRAY_BUFFER,oa,y))}if(za&&w){C=0;for(v=F.length;C< +v;C++)I=ka[F[C]],J=I.vertexColors,D=I.color,J.length===3&&w===THREE.VertexColors?(I=J[0],W=J[1],V=J[2]):V=W=I=D,U[T]=I.r,U[T+1]=I.g,U[T+2]=I.b,U[T+3]=W.r,U[T+4]=W.g,U[T+5]=W.b,U[T+6]=V.r,U[T+7]=V.g,U[T+8]=V.b,T+=9;C=0;for(v=ia.length;C0&& +(l.bindBuffer(l.ARRAY_BUFFER,r.__webglColorBuffer),l.bufferData(l.ARRAY_BUFFER,U,y))}if($&&X.hasTangents){C=0;for(v=F.length;C0&&(l.bindBuffer(l.ARRAY_BUFFER,r.__webglUVBuffer),l.bufferData(l.ARRAY_BUFFER, +ga,y))}if(sa&&Ba&&z){C=0;for(v=F.length;C0&&(l.bindBuffer(l.ARRAY_BUFFER,r.__webglUV2Buffer),l.bufferData(l.ARRAY_BUFFER,E,y))}if(qa){C=0;for(v=F.length;C=0&&l.enableVertexAttribArray(o.position);o.color>=0&&l.enableVertexAttribArray(o.color);o.normal>=0&&l.enableVertexAttribArray(o.normal); +j);d=["position","normal","uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];for(q=0;q=0&&l.enableVertexAttribArray(o.position);o.color>=0&&l.enableVertexAttribArray(o.color);o.normal>=0&&l.enableVertexAttribArray(o.normal); o.tangent>=0&&l.enableVertexAttribArray(o.tangent);a.skinning&&o.skinVertexA>=0&&o.skinVertexB>=0&&o.skinIndex>=0&&o.skinWeight>=0&&(l.enableVertexAttribArray(o.skinVertexA),l.enableVertexAttribArray(o.skinVertexB),l.enableVertexAttribArray(o.skinIndex),l.enableVertexAttribArray(o.skinWeight));if(a.attributes)for(f in a.attributes)o[f]!==void 0&&o[f]>=0&&l.enableVertexAttribArray(o[f]);if(a.morphTargets)for(f=a.numSupportedMorphTargets=0;f=0&&(l.enableVertexAttribArray(o[q]), -a.numSupportedMorphTargets++);a.uniformsList=[];for(e in a.uniforms)a.uniformsList.push([a.uniforms[e],e])};this.setFaceCulling=function(a,b){a?(!b||b==="ccw"?l.frontFace(l.CCW):l.frontFace(l.CW),a==="back"?l.cullFace(l.BACK):a==="front"?l.cullFace(l.FRONT):l.cullFace(l.FRONT_AND_BACK),l.enable(l.CULL_FACE)):l.disable(l.CULL_FACE)};this.setObjectFaces=function(a){if(ba!==a.doubleSided)a.doubleSided?l.disable(l.CULL_FACE):l.enable(l.CULL_FACE),ba=a.doubleSided;if(T!==a.flipSided)a.flipSided?l.frontFace(l.CW): -l.frontFace(l.CCW),T=a.flipSided};this.setDepthTest=function(a){O!==a&&(a?l.enable(l.DEPTH_TEST):l.disable(l.DEPTH_TEST),O=a)};this.setBlending=function(a){if(a!==U){switch(a){case THREE.AdditiveBlending:l.blendEquation(l.FUNC_ADD);l.blendFunc(l.SRC_ALPHA,l.ONE);break;case THREE.SubtractiveBlending:l.blendEquation(l.FUNC_ADD);l.blendFunc(l.ZERO,l.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:l.blendEquation(l.FUNC_ADD);l.blendFunc(l.ZERO,l.SRC_COLOR);break;default:l.blendEquationSeparate(l.FUNC_ADD, -l.FUNC_ADD),l.blendFuncSeparate(l.SRC_ALPHA,l.ONE_MINUS_SRC_ALPHA,l.ONE,l.ONE_MINUS_SRC_ALPHA)}U=a}};this.setTexture=function(a,b){if(a.needsUpdate){if(!a.__webglInit)a.__webglInit=!0,a.__webglTexture=l.createTexture(),R.info.memory.textures++;l.activeTexture(l.TEXTURE0+b);l.bindTexture(l.TEXTURE_2D,a.__webglTexture);var c=A(l.TEXTURE_2D,a,a.image);a instanceof THREE.DataTexture?l.texImage2D(l.TEXTURE_2D,0,B(a.format),a.image.width,a.image.height,0,B(a.format),l.UNSIGNED_BYTE,a.image.data):l.texImage2D(l.TEXTURE_2D, +a.numSupportedMorphTargets++);a.uniformsList=[];for(e in a.uniforms)a.uniformsList.push([a.uniforms[e],e])};this.setFaceCulling=function(a,b){a?(!b||b==="ccw"?l.frontFace(l.CCW):l.frontFace(l.CW),a==="back"?l.cullFace(l.BACK):a==="front"?l.cullFace(l.FRONT):l.cullFace(l.FRONT_AND_BACK),l.enable(l.CULL_FACE)):l.disable(l.CULL_FACE)};this.setObjectFaces=function(a){if(aa!==a.doubleSided)a.doubleSided?l.disable(l.CULL_FACE):l.enable(l.CULL_FACE),aa=a.doubleSided;if(ea!==a.flipSided)a.flipSided?l.frontFace(l.CW): +l.frontFace(l.CCW),ea=a.flipSided};this.setDepthTest=function(a){L!==a&&(a?l.enable(l.DEPTH_TEST):l.disable(l.DEPTH_TEST),L=a)};this.setBlending=function(a){if(a!==U){switch(a){case THREE.AdditiveBlending:l.blendEquation(l.FUNC_ADD);l.blendFunc(l.SRC_ALPHA,l.ONE);break;case THREE.SubtractiveBlending:l.blendEquation(l.FUNC_ADD);l.blendFunc(l.ZERO,l.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:l.blendEquation(l.FUNC_ADD);l.blendFunc(l.ZERO,l.SRC_COLOR);break;default:l.blendEquationSeparate(l.FUNC_ADD, +l.FUNC_ADD),l.blendFuncSeparate(l.SRC_ALPHA,l.ONE_MINUS_SRC_ALPHA,l.ONE,l.ONE_MINUS_SRC_ALPHA)}U=a}};this.setTexture=function(a,b){if(a.needsUpdate){if(!a.__webglInit)a.__webglInit=!0,a.__webglTexture=l.createTexture(),R.info.memory.textures++;l.activeTexture(l.TEXTURE0+b);l.bindTexture(l.TEXTURE_2D,a.__webglTexture);var c=B(l.TEXTURE_2D,a,a.image);a instanceof THREE.DataTexture?l.texImage2D(l.TEXTURE_2D,0,H(a.format),a.image.width,a.image.height,0,H(a.format),l.UNSIGNED_BYTE,a.image.data):l.texImage2D(l.TEXTURE_2D, 0,l.RGBA,l.RGBA,l.UNSIGNED_BYTE,a.image);c&&l.generateMipmap(l.TEXTURE_2D);a.needsUpdate=!1;if(a.onUpdated)a.onUpdated()}else l.activeTexture(l.TEXTURE0+b),l.bindTexture(l.TEXTURE_2D,a.__webglTexture)};this.setRenderTarget=function(a){var b=a instanceof THREE.WebGLRenderTargetCube;if(a&&!a.__webglFramebuffer){if(a.depthBuffer===void 0)a.depthBuffer=!0;if(a.stencilBuffer===void 0)a.stencilBuffer=!0;a.__webglTexture=l.createTexture();if(b){a.__webglFramebuffer=[];a.__webglRenderbuffer=[];l.bindTexture(l.TEXTURE_CUBE_MAP, -a.__webglTexture);A(l.TEXTURE_CUBE_MAP,a,a);for(var c=0;c<6;c++){a.__webglFramebuffer[c]=l.createFramebuffer();a.__webglRenderbuffer[c]=l.createRenderbuffer();l.texImage2D(l.TEXTURE_CUBE_MAP_POSITIVE_X+c,0,B(a.format),a.width,a.height,0,B(a.format),B(a.type),null);var d=a,e=l.TEXTURE_CUBE_MAP_POSITIVE_X+c;l.bindFramebuffer(l.FRAMEBUFFER,a.__webglFramebuffer[c]);l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,e,d.__webglTexture,0);E(a.__webglRenderbuffer[c],a)}}else a.__webglFramebuffer=l.createFramebuffer(), -a.__webglRenderbuffer=l.createRenderbuffer(),l.bindTexture(l.TEXTURE_2D,a.__webglTexture),A(l.TEXTURE_2D,a,a),l.texImage2D(l.TEXTURE_2D,0,B(a.format),a.width,a.height,0,B(a.format),B(a.type),null),c=l.TEXTURE_2D,l.bindFramebuffer(l.FRAMEBUFFER,a.__webglFramebuffer),l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,c,a.__webglTexture,0),E(a.__webglRenderbuffer,a);b?l.bindTexture(l.TEXTURE_CUBE_MAP,null):l.bindTexture(l.TEXTURE_2D,null);l.bindRenderbuffer(l.RENDERBUFFER,null);l.bindFramebuffer(l.FRAMEBUFFER, -null)}a?(b=b?a.__webglFramebuffer[a.activeCubeFace]:a.__webglFramebuffer,c=a.width,a=a.height,e=d=0):(b=null,c=sa,a=qa,d=na,e=ja);b!==X&&(l.bindFramebuffer(l.FRAMEBUFFER,b),l.viewport(d,e,c,a),X=b);Ba=c;wa=a};this.shadowMapPlugin=new THREE.ShadowMapPlugin;this.addPrePlugin(this.shadowMapPlugin);this.addPostPlugin(new THREE.SpritePlugin);this.addPostPlugin(new THREE.LensFlarePlugin)}; +a.__webglTexture);B(l.TEXTURE_CUBE_MAP,a,a);for(var c=0;c<6;c++){a.__webglFramebuffer[c]=l.createFramebuffer();a.__webglRenderbuffer[c]=l.createRenderbuffer();l.texImage2D(l.TEXTURE_CUBE_MAP_POSITIVE_X+c,0,H(a.format),a.width,a.height,0,H(a.format),H(a.type),null);var d=a,e=l.TEXTURE_CUBE_MAP_POSITIVE_X+c;l.bindFramebuffer(l.FRAMEBUFFER,a.__webglFramebuffer[c]);l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,e,d.__webglTexture,0);z(a.__webglRenderbuffer[c],a)}}else a.__webglFramebuffer=l.createFramebuffer(), +a.__webglRenderbuffer=l.createRenderbuffer(),l.bindTexture(l.TEXTURE_2D,a.__webglTexture),B(l.TEXTURE_2D,a,a),l.texImage2D(l.TEXTURE_2D,0,H(a.format),a.width,a.height,0,H(a.format),H(a.type),null),c=l.TEXTURE_2D,l.bindFramebuffer(l.FRAMEBUFFER,a.__webglFramebuffer),l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0,c,a.__webglTexture,0),z(a.__webglRenderbuffer,a);b?l.bindTexture(l.TEXTURE_CUBE_MAP,null):l.bindTexture(l.TEXTURE_2D,null);l.bindRenderbuffer(l.RENDERBUFFER,null);l.bindFramebuffer(l.FRAMEBUFFER, +null)}a?(b=b?a.__webglFramebuffer[a.activeCubeFace]:a.__webglFramebuffer,c=a.width,a=a.height,e=d=0):(b=null,c=sa,a=qa,d=na,e=ja);b!==W&&(l.bindFramebuffer(l.FRAMEBUFFER,b),l.viewport(d,e,c,a),W=b);Ba=c;wa=a};this.shadowMapPlugin=new THREE.ShadowMapPlugin;this.addPrePlugin(this.shadowMapPlugin);this.addPostPlugin(new THREE.SpritePlugin);this.addPostPlugin(new THREE.LensFlarePlugin)}; THREE.WebGLRenderTarget=function(a,b,c){this.width=a;this.height=b;c=c||{};this.wrapS=c.wrapS!==void 0?c.wrapS:THREE.ClampToEdgeWrapping;this.wrapT=c.wrapT!==void 0?c.wrapT:THREE.ClampToEdgeWrapping;this.magFilter=c.magFilter!==void 0?c.magFilter:THREE.LinearFilter;this.minFilter=c.minFilter!==void 0?c.minFilter:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.format=c.format!==void 0?c.format:THREE.RGBAFormat;this.type=c.type!==void 0?c.type: THREE.UnsignedByteType;this.depthBuffer=c.depthBuffer!==void 0?c.depthBuffer:!0;this.stencilBuffer=c.stencilBuffer!==void 0?c.stencilBuffer:!0}; THREE.WebGLRenderTarget.prototype.clone=function(){var a=new THREE.WebGLRenderTarget(this.width,this.height);a.wrapS=this.wrapS;a.wrapT=this.wrapT;a.magFilter=this.magFilter;a.minFilter=this.minFilter;a.offset.copy(this.offset);a.repeat.copy(this.repeat);a.format=this.format;a.type=this.type;a.depthBuffer=this.depthBuffer;a.stencilBuffer=this.stencilBuffer;return a};THREE.WebGLRenderTargetCube=function(a,b,c){THREE.WebGLRenderTarget.call(this,a,b,c);this.activeCubeFace=0}; @@ -344,20 +348,20 @@ THREE.RenderableFace4=function(){this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null};THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.RenderableVertex;this.v2=new THREE.RenderableVertex;this.material=null}; THREE.ColorUtils={adjustHSV:function(a,b,c,d){var e=THREE.ColorUtils.__hsv;THREE.ColorUtils.rgbToHsv(a,e);e.h=THREE.Math.clamp(e.h+b,0,1);e.s=THREE.Math.clamp(e.s+c,0,1);e.v=THREE.Math.clamp(e.v+d,0,1);a.setHSV(e.h,e.s,e.v)},rgbToHsv:function(a,b){var c=a.r,d=a.g,e=a.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;c/=6;c<0&&(c+=1);c>1&&(c-=1)}b===void 0&&(b={h:0,s:0,v:0});b.h=c;b.s=g;b.v=f;return b}}; THREE.ColorUtils.__hsv={h:0,s:0,v:0}; -THREE.GeometryUtils={merge:function(a,b){for(var c,d,e=a.vertices.length,f=b instanceof THREE.Mesh?b.geometry:b,g=a.vertices,h=f.vertices,i=a.faces,k=f.faces,j=a.faceVertexUvs[0],o=f.faceVertexUvs[0],p={},m=0;m1&&(d=1-d,e=1-e);f=1-d-e;g.copy(a);g.multiplyScalar(d);h.copy(b);h.multiplyScalar(e);g.addSelf(h);h.copy(c);h.multiplyScalar(f);g.addSelf(h);return g},randomPointInFace:function(a,b,c){var d,e,f;if(a instanceof THREE.Face3)return d=b.vertices[a.a].position,e=b.vertices[a.b].position, f=b.vertices[a.c].position,THREE.GeometryUtils.randomPointInTriangle(d,e,f);else if(a instanceof THREE.Face4){d=b.vertices[a.a].position;e=b.vertices[a.b].position;f=b.vertices[a.c].position;var b=b.vertices[a.d].position,g;c?a._area1&&a._area2?(c=a._area1,g=a._area2):(c=THREE.GeometryUtils.triangleArea(d,e,b),g=THREE.GeometryUtils.triangleArea(e,f,b),a._area1=c,a._area2=g):(c=THREE.GeometryUtils.triangleArea(d,e,b),g=THREE.GeometryUtils.triangleArea(e,f,b));return THREE.GeometryUtils.random()*(c+ -g)a?b(c,e-1):k[e]a?b(c,e-1):j[e] 0\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;", THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvViewPosition = -mvPosition.xyz;\nvNormal = normalMatrix * normal;\nvTangent = normalMatrix * tangent.xyz;\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvUv = uv * uRepeat + uOffset;\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nvPointLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( normalize( vNormal.xyz ) * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif", THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n")},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}"}}}; +THREE.BufferGeometry=function(){this.id=THREE.GeometryCount++;this.vertexColorArray=this.vertexUvArray=this.vertexNormalArray=this.vertexPositionArray=this.vertexIndexArray=this.vertexColorBuffer=this.vertexUvBuffer=this.vertexNormalBuffer=this.vertexPositionBuffer=this.vertexIndexBuffer=null;this.dynamic=!1;this.boundingSphere=this.boundingBox=null;this.morphTargets=[]};THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,computeBoundingBox:function(){},computeBoundingSphere:function(){}}; THREE.Curve=function(){};THREE.Curve.prototype.getPoint=function(){console.log("Warning, getPoint() not implemented!");return null};THREE.Curve.prototype.getPointAt=function(a){return this.getPoint(this.getUtoTmapping(a))};THREE.Curve.prototype.getPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPoint(b/a));return c};THREE.Curve.prototype.getSpacedPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPointAt(b/a));return c}; THREE.Curve.prototype.getLength=function(){var a=this.getLengths();return a[a.length-1]};THREE.Curve.prototype.getLengths=function(a){a||(a=200);if(this.cacheArcLengths&&this.cacheArcLengths.length==a+1)return this.cacheArcLengths;var b=[],c,d=this.getPoint(0),e,f=0;b.push(0);for(e=1;e<=a;e++)c=this.getPoint(e/a),f+=c.distanceTo(d),b.push(f),d=c;return this.cacheArcLengths=b}; THREE.Curve.prototype.getUtoTmapping=function(a,b){var c=this.getLengths(),d=0,e=c.length,f;f=b?b:a*c[e-1];for(var g=0,h=e-1,i;g<=h;)if(d=Math.floor(g+(h-g)/2),i=c[d]-f,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(a){a=this.getTangent(a);return new THREE.Vector2(-a.y,a.x)}; @@ -402,37 +407,37 @@ THREE.Path.prototype.quadraticCurveTo=function(a,b,c,d){var e=Array.prototype.sl THREE.Path.prototype.bezierCurveTo=function(a,b,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(a,b),new THREE.Vector2(c,d),new THREE.Vector2(e,f)));this.actions.push({action:THREE.PathActions.BEZIER_CURVE_TO,args:g})}; THREE.Path.prototype.splineThru=function(a){var b=Array.prototype.slice.call(arguments),c=this.actions[this.actions.length-1].args,c=[new THREE.Vector2(c[c.length-2],c[c.length-1])];Array.prototype.push.apply(c,a);this.curves.push(new THREE.SplineCurve(c));this.actions.push({action:THREE.PathActions.CSPLINE_THRU,args:b})}; THREE.Path.prototype.arc=function(a,b,c,d,e,f){var g=Array.prototype.slice.call(arguments);this.curves.push(new THREE.ArcCurve(a,b,c,d,e,f));this.actions.push({action:THREE.PathActions.ARC,args:g})};THREE.Path.prototype.getSpacedPoints=function(a){a||(a=40);for(var b=[],c=0;c0?(g=c[c.length-1],m=g.x,q=g.y):(g=this.actions[d-1].args,m=g[g.length-2],q=g[g.length-1]);for(g=1;g<=a;g++)n=g/a,f=THREE.Shape.Utils.b2(n,m,o,h),n=THREE.Shape.Utils.b2(n,q,p, -i),c.push(new THREE.Vector2(f,n));break;case THREE.PathActions.BEZIER_CURVE_TO:h=f[4];i=f[5];o=f[0];p=f[1];k=f[2];j=f[3];c.length>0?(g=c[c.length-1],m=g.x,q=g.y):(g=this.actions[d-1].args,m=g[g.length-2],q=g[g.length-1]);for(g=1;g<=a;g++)n=g/a,f=THREE.Shape.Utils.b3(n,m,o,k,h),n=THREE.Shape.Utils.b3(n,q,p,j,i),c.push(new THREE.Vector2(f,n));break;case THREE.PathActions.CSPLINE_THRU:g=this.actions[d-1].args;g=[new THREE.Vector2(g[g.length-2],g[g.length-1])];n=a*f[0].length;g=g.concat(f[0]);f=new THREE.SplineCurve(g); -for(g=1;g<=n;g++)c.push(f.getPointAt(g/n));break;case THREE.PathActions.ARC:g=this.actions[d-1].args;h=f[0];i=f[1];k=f[2];o=f[3];n=f[4];p=!!f[5];j=g[g.length-2];m=g[g.length-1];g.length==0&&(j=m=0);q=n-o;var s=a*2;for(g=1;g<=s;g++)n=g/s,p||(n=1-n),n=o+n*q,f=j+h+k*Math.cos(n),n=m+i+k*Math.sin(n),c.push(new THREE.Vector2(f,n))}b&&c.push(c[0]);return c};THREE.Path.prototype.transform=function(a,b){this.getBoundingBox();return this.getWrapPoints(this.getPoints(b),a)}; -THREE.Path.prototype.nltransform=function(a,b,c,d,e,f){var g=this.getPoints(),h,i,k,j,o;h=0;for(i=g.length;h0?(g=c[c.length-1],m=g.x,q=g.y):(g=this.actions[d-1].args,m=g[g.length-2],q=g[g.length-1]);for(g=1;g<=a;g++)n=g/a,f=THREE.Shape.Utils.b2(n,m,o,h),n=THREE.Shape.Utils.b2(n,q,p, +i),c.push(new THREE.Vector2(f,n));break;case THREE.PathActions.BEZIER_CURVE_TO:h=f[4];i=f[5];o=f[0];p=f[1];j=f[2];k=f[3];c.length>0?(g=c[c.length-1],m=g.x,q=g.y):(g=this.actions[d-1].args,m=g[g.length-2],q=g[g.length-1]);for(g=1;g<=a;g++)n=g/a,f=THREE.Shape.Utils.b3(n,m,o,j,h),n=THREE.Shape.Utils.b3(n,q,p,k,i),c.push(new THREE.Vector2(f,n));break;case THREE.PathActions.CSPLINE_THRU:g=this.actions[d-1].args;g=[new THREE.Vector2(g[g.length-2],g[g.length-1])];n=a*f[0].length;g=g.concat(f[0]);f=new THREE.SplineCurve(g); +for(g=1;g<=n;g++)c.push(f.getPointAt(g/n));break;case THREE.PathActions.ARC:g=this.actions[d-1].args;h=f[0];i=f[1];j=f[2];o=f[3];n=f[4];p=!!f[5];k=g[g.length-2];m=g[g.length-1];g.length==0&&(k=m=0);q=n-o;var s=a*2;for(g=1;g<=s;g++)n=g/s,p||(n=1-n),n=o+n*q,f=k+h+j*Math.cos(n),n=m+i+j*Math.sin(n),c.push(new THREE.Vector2(f,n))}b&&c.push(c[0]);return c};THREE.Path.prototype.transform=function(a,b){this.getBoundingBox();return this.getWrapPoints(this.getPoints(b),a)}; +THREE.Path.prototype.nltransform=function(a,b,c,d,e,f){var g=this.getPoints(),h,i,j,k,o;h=0;for(i=g.length;h=0?h-1:c.length-1;f=g-1>=0?g-1:k.length-1;var n=[k[g],c[h],c[e]];o=THREE.FontUtils.Triangulate.area(n);var s=[k[g],k[f],c[h]];p=THREE.FontUtils.Triangulate.area(s);m=h;j=g;h+=1;g+=-1;h< -0&&(h+=c.length);h%=c.length;g<0&&(g+=k.length);g%=k.length;e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:k.length-1;n=[k[g],c[h],c[e]];n=THREE.FontUtils.Triangulate.area(n);s=[k[g],k[f],c[h]];s=THREE.FontUtils.Triangulate.area(s);o+p>n+s&&(h=m,g=j,h<0&&(h+=c.length),h%=c.length,g<0&&(g+=k.length),g%=k.length,e=h-1>=0?h-1:c.length-1,f=g-1>=0?g-1:k.length-1);o=c.slice(0,h);p=c.slice(h);m=k.slice(g);j=k.slice(0,g);f=[k[g],k[f],c[h]];q.push([k[g],c[h],c[e]]);q.push(f);c=o.concat(m).concat(j).concat(p)}return{shape:c, -isolatedPts:q,allpoints:d}},triangulateShape:function(a,b){var c=THREE.Shape.Utils.removeHoles(a,b),d=c.allpoints,e=c.isolatedPts,c=THREE.FontUtils.Triangulate(c.shape,!1),f,g,h,i,k={};f=0;for(g=d.length;f=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1;var n=[j[g],c[h],c[e]];o=THREE.FontUtils.Triangulate.area(n);var s=[j[g],j[f],c[h]];p=THREE.FontUtils.Triangulate.area(s);m=h;k=g;h+=1;g+=-1;h< +0&&(h+=c.length);h%=c.length;g<0&&(g+=j.length);g%=j.length;e=h-1>=0?h-1:c.length-1;f=g-1>=0?g-1:j.length-1;n=[j[g],c[h],c[e]];n=THREE.FontUtils.Triangulate.area(n);s=[j[g],j[f],c[h]];s=THREE.FontUtils.Triangulate.area(s);o+p>n+s&&(h=m,g=k,h<0&&(h+=c.length),h%=c.length,g<0&&(g+=j.length),g%=j.length,e=h-1>=0?h-1:c.length-1,f=g-1>=0?g-1:j.length-1);o=c.slice(0,h);p=c.slice(h);m=j.slice(g);k=j.slice(0,g);f=[j[g],j[f],c[h]];q.push([j[g],c[h],c[e]]);q.push(f);c=o.concat(m).concat(k).concat(p)}return{shape:c, +isolatedPts:q,allpoints:d}},triangulateShape:function(a,b){var c=THREE.Shape.Utils.removeHoles(a,b),d=c.allpoints,e=c.isolatedPts,c=THREE.FontUtils.Triangulate(c.shape,!1),f,g,h,i,j={};f=0;for(g=d.length;f1)console.log("THREE.Animation.update: Warning! Scale out of bounds:"+d+" on bone "+m),d=d<0?0:1;if(c==="pos")if(c=a.position,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)if(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],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),a.rotation.set(0,d,0)}else if(c=== -"rot")THREE.Quaternion.slerp(e,f,a.quaternion,d);else if(c==="scl")c=a.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}}if(this.JITCompile&&j[0][k]===void 0){this.hierarchy[0].updateMatrixWorld(!0);for(m=0;ma.length-2?f:f+1;c[3]=f>a.length-3?f:f+2;f=a[c[0]];h=a[c[1]];i=a[c[2]];k=a[c[3]];c=e*e;g=e*c;d[0]=this.interpolate(f[0],h[0],i[0],k[0],e,c,g);d[1]=this.interpolate(f[1],h[1],i[1],k[1],e,c,g);d[2]=this.interpolate(f[2],h[2],i[2],k[2],e,c,g);return d}; +"rot")THREE.Quaternion.slerp(e,f,a.quaternion,d);else if(c==="scl")c=a.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}}if(this.JITCompile&&k[0][j]===void 0){this.hierarchy[0].updateMatrixWorld(!0);for(m=0;ma.length-2?f:f+1;c[3]=f>a.length-3?f:f+2;f=a[c[0]];h=a[c[1]];i=a[c[2]];j=a[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(a,b,c,d,e,f,g){a=(c-a)*0.5;d=(d-b)*0.5;return(2*(b-c)+a+d)*g+(-3*(b-c)-2*a-d)*f+a*e+b};THREE.Animation.prototype.getNextKeyWith=function(a,b,c){var d=this.data.hierarchy[b].keys;for(this.interpolationType===THREE.AnimationHandler.CATMULLROM||this.interpolationType===THREE.AnimationHandler.CATMULLROM_FORWARD?c=c0?c:0:c>=0?c:c+d.length;c>=0;c--)if(d[c][a]!==void 0)return d[c];return this.data.hierarchy[b].keys[d.length-1]}; THREE.KeyFrameAnimation=function(a,b,c){this.root=a;this.data=THREE.AnimationHandler.get(b);this.hierarchy=THREE.AnimationHandler.parse(a);this.currentTime=0;this.timeScale=0.0010;this.isPlaying=!1;this.loop=this.isPaused=!0;this.JITCompile=c!==void 0?c:!0;a=0;for(b=this.hierarchy.length;a=0?c:c+b.length;c>=0;c--)if(b[c].hasTarget(a))return b[c];return b[b.length-1]}; THREE.CubeCamera=function(a,b,c,d){this.heightOffset=c;this.position=new THREE.Vector3(0,c,0);this.cameraPX=new THREE.PerspectiveCamera(90,1,a,b);this.cameraNX=new THREE.PerspectiveCamera(90,1,a,b);this.cameraPY=new THREE.PerspectiveCamera(90,1,a,b);this.cameraNY=new THREE.PerspectiveCamera(90,1,a,b);this.cameraPZ=new THREE.PerspectiveCamera(90,1,a,b);this.cameraNZ=new THREE.PerspectiveCamera(90,1,a,b);this.cameraPX.position=this.position;this.cameraNX.position=this.position;this.cameraPY.position= this.position;this.cameraNY.position=this.position;this.cameraPZ.position=this.position;this.cameraNZ.position=this.position;this.cameraPX.up.set(0,-1,0);this.cameraNX.up.set(0,-1,0);this.cameraPY.up.set(0,0,1);this.cameraNY.up.set(0,0,-1);this.cameraPZ.up.set(0,-1,0);this.cameraNZ.up.set(0,-1,0);this.targetPX=new THREE.Vector3(0,0,0);this.targetNX=new THREE.Vector3(0,0,0);this.targetPY=new THREE.Vector3(0,0,0);this.targetNY=new THREE.Vector3(0,0,0);this.targetPZ=new THREE.Vector3(0,0,0);this.targetNZ= @@ -481,42 +486,42 @@ THREE.FlyControls=function(a,b){function c(a,b){return function(){b.apply(a,argu this.object.matrixWorldNeedsUpdate=!0};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),!1);this.domElement.addEventListener("mousedown",c(this,this.mousedown),!1);this.domElement.addEventListener("mouseup",c(this, this.mouseup),!1);this.domElement.addEventListener("keydown",c(this,this.keydown),!1);this.domElement.addEventListener("keyup",c(this,this.keyup),!1);this.updateMovementVector();this.updateRotationVector()}; -THREE.RollControls=function(a,b){this.object=a;this.domElement=b!==void 0?b:document;this.mouseLook=!0;this.autoForward=!1;this.rollSpeed=this.movementSpeed=this.lookSpeed=1;this.constrainVertical=[-0.9,0.9];this.object.matrixAutoUpdate=!1;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=!1,h=1,i=0,k=0,j=0,o=0,p=0,m=window.innerWidth/2,q=window.innerHeight/2;this.update=function(a){if(this.mouseLook){var b=a*this.lookSpeed; -this.rotateHorizontally(b*o);this.rotateVertically(b*p)}b=a*this.movementSpeed;this.object.translateZ(-b*(i>0||this.autoForward&&!(i<0)?1:i));this.object.translateX(b*k);this.object.translateY(b*j);g&&(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.y0||this.autoForward&&!(i<0)?1:i));this.object.translateX(b*j);this.object.translateY(b*k);g&&(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.y1?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*=c.rotateSpeed;d.setFromAxisAngle(b, --a);d.multiplyVector3(g);d.multiplyVector3(c.object.up);d.multiplyVector3(i);c.staticMoving?h=i:(d.setFromAxisAngle(b,a*(c.dynamicDampingFactor-1)),d.multiplyVector3(h))}};this.zoomCamera=function(){var a=1+(j.y-k.y)*c.zoomSpeed;a!==1&&a>0&&(g.multiplyScalar(a),c.staticMoving?k=j:k.y+=(j.y-k.y)*this.dynamicDampingFactor)};this.panCamera=function(){var a=p.clone().subSelf(o);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)); +-a);d.multiplyVector3(g);d.multiplyVector3(c.object.up);d.multiplyVector3(i);c.staticMoving?h=i:(d.setFromAxisAngle(b,a*(c.dynamicDampingFactor-1)),d.multiplyVector3(h))}};this.zoomCamera=function(){var a=1+(k.y-j.y)*c.zoomSpeed;a!==1&&a>0&&(g.multiplyScalar(a),c.staticMoving?j=k:j.y+=(k.y-j.y)*this.dynamicDampingFactor)};this.panCamera=function(){var a=p.clone().subSelf(o);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?o=p:o.addSelf(a.sub(p,o).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()0?1:-1;for(h=0;h0?1:-1;for(h=0;h0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,g,0)));for(h=0;h0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,-g,0)));for(h=0;h0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,g,0)));for(h=0;h0){this.vertices.push(new THREE.Vertex(new THREE.Vector3(0,-g,0)));for(h=0;ha&&(a+=Math.PI*2),a=(b+a)/2,new THREE.Vector2(-Math.cos(a),-Math.sin(a));return d.multiplyScalar(g).addSelf(h).subSelf(a).clone()}function e(a){for(y=a.length;--y>=0;){Z=y;da=y-1;da<0&&(da=a.length-1);for(var b= -0,c=m+j*2,b=0;b=0;$--){Q=$/j;Y=i*(1-Q);Q=k*Math.sin(Q*Math.PI/2);y=0;for(K=u.length;y< -K;y++)S=c(u[y],W[y],Q),f(S.x,S.y,h+Y);D=0;for(B=p.length;Da&&(a+=Math.PI*2),a=(b+a)/2,new THREE.Vector2(-Math.cos(a),-Math.sin(a));return d.multiplyScalar(g).addSelf(h).subSelf(a).clone()}function e(a){for(y=a.length;--y>=0;){Z=y;ca=y-1;ca<0&&(ca=a.length-1);for(var b= +0,c=m+k*2,b=0;b=0;$--){Q=$/k;X=i*(1-Q);Q=j*Math.sin(Q*Math.PI/2);y=0;for(K=u.length;y< +K;y++)T=c(u[y],S[y],Q),f(T.x,T.y,h+X);D=0;for(H=p.length;D0)for(k=0;k2;){if(o--<=0){console.log("Warning, unable to triangulate polygon!");if(d)return h;return f}i=k;e<=i&&(i=0);k=i+1;e<=k&&(k=0);j=k+1;e<=j&&(j=0);var p;a:{p=a;var m=i,q=k,n=j,s=e,r=g,u=void 0,t=void 0,z=void 0, -A=void 0,E=void 0,D=void 0,B=void 0,w=void 0,G=void 0,t=p[r[m]].x,z=p[r[m]].y,A=p[r[q]].x,E=p[r[q]].y,D=p[r[n]].x,B=p[r[n]].y;if(1.0E-10>(A-t)*(B-z)-(E-z)*(D-t))p=!1;else{for(u=0;u=0&&$>=0&&Y>=0){p=!1;break a}}p=!0}}if(p){f.push([a[g[i]], -a[g[k]],a[g[j]]]);h.push([g[i],g[k],g[j]]);i=k;for(j=k+1;j0)for(j=0;j2;){if(o--<=0){console.log("Warning, unable to triangulate polygon!");if(d)return h;return f}i=j;e<=i&&(i=0);j=i+1;e<=j&&(j=0);k=j+1;e<=k&&(k=0);var p;a:{p=a;var m=i,q=j,n=k,s=e,r=g,u=void 0,t=void 0,A=void 0, +B=void 0,z=void 0,D=void 0,H=void 0,w=void 0,F=void 0,t=p[r[m]].x,A=p[r[m]].y,B=p[r[q]].x,z=p[r[q]].y,D=p[r[n]].x,H=p[r[n]].y;if(1.0E-10>(B-t)*(H-A)-(z-A)*(D-t))p=!1;else{for(u=0;u=0&&$>=0&&X>=0){p=!1;break a}}p=!0}}if(p){f.push([a[g[i]], +a[g[j]],a[g[k]]]);h.push([g[i],g[j],g[k]]);i=j;for(k=j+1;k0;)this.smooth(a)}; THREE.SubdivisionModifier.prototype.smooth=function(a){function b(a,b,c,d,h,i){var j=new THREE.Face4(a,b,c,d,null,h.color,h.material);if(g.useOldVertexColors){j.vertexColors=[];for(var k,n,m,o=0;o<4;o++){m=i[o];k=new THREE.Color;k.setRGB(0,0,0);for(var q=0;q=0){o=k.invBindMatrices[n];l.invBindMatrix=o;l.skinningMatrix=new THREE.Matrix4;l.skinningMatrix.multiply(l.world,o);l.weights=[];for(o=0;o1){j=new THREE.MeshFaceMaterial;i.materials= l;for(h=0;h1?b.add(j):b=j}}b.name=a.id||"";b.matrix=a.matrix;c=a.matrix.decompose();b.position=c[0];b.quaternion=c[1];b.useQuaternion=!0;b.scale=c[2];la.centerGeometry&&b.geometry&&(c=THREE.GeometryUtils.center(b.geometry),b.quaternion.multiplyVector3(c.multiplySelf(b.scale)), -b.position.subSelf(c));for(g=0;g=0,g=e.indexOf("(")>=0,h;if(f)d=e.split("."),e=d.shift(),d.shift();else if(g){h=e.split("(");e=h.shift();for(d=0;dq)break}if(!r){r=new l(q);t=-1;u=0;for(v=d.length;u=q&&(t=u);q=t;d.splice(q==-1?d.length:q,0,r)}r.addTarget(f,j,g,s)}}else console.log('Could not find transform "'+b.sid+'" in node '+ -this.id)}for(c=0;c=0?i:i+h.length;i>=0;i--)if(k=h[i],k.hasTarget(g)){i=k;break a}i=null}k=void 0;a:{for(j+=1;j4&&la.subdivideFaces){r=r.length?r:new THREE.Color;for(e=1;e4?[r[0],r[n+1],r[n+2]]:m===4?[r[0],r[1],r[2],r[3]]:[r[0],r[1],r[2]],b.faceVertexUvs[e]||(b.faceVertexUvs[e]=[]),b.faceVertexUvs[e].push(r)}}else console.log("dropped face with vcount "+m+" for geometry with id: "+b.id);c+=g.length*m}};u.prototype=new t;u.prototype.constructor=u;t.prototype.setVertices=function(a){for(var b=0;b0&&(this[c.nodeName]=parseFloat(d[0].textContent))}}this.create(); -return this};G.prototype.create=function(){var a={},b=this.transparency!==void 0&&this.transparency<1,c;for(c in this)switch(c){case "ambient":case "emission":case "diffuse":case "specular":var d=this[c];if(d instanceof w)if(d.isTexture()){if(this.effect.sampler&&this.effect.surface&&this.effect.sampler.source==this.effect.surface.sid){var e=va[this.effect.surface.init_from];if(e)e=THREE.ImageUtils.loadTexture(xa+e.init_from),e.wrapS=d.texOpts.wrapU?THREE.RepeatWrapping:THREE.ClampToEdgeWrapping, -e.wrapT=d.texOpts.wrapV?THREE.RepeatWrapping:THREE.ClampToEdgeWrapping,e.offset.x=d.texOpts.offsetU,e.offset.y=d.texOpts.offsetV,e.repeat.x=d.texOpts.repeatU,e.repeat.y=d.texOpts.repeatV,a.map=e}}else c=="diffuse"?a.color=d.color.getHex():b||(a[c]=d.color.getHex());break;case "shininess":case "reflectivity":a[c]=this[c];break;case "transparency":if(b)a.transparent=!0,a.opacity=this[c],b=!0}a.shading=Aa;return this.material=new THREE.MeshLambertMaterial(a)};y.prototype.parse=function(a){for(var b= -0;b=0,d=a.indexOf("(")>=0;if(c)b=a.split("."),this.sid=b.shift(),this.member=b.shift();else if(d){b=a.split("(");this.sid=b.shift();for(var e=0;e1){c=[];b*=this.strideOut;for(var d=0;d1)console.log("Key.interpolate: Warning! Scale out of bounds:"+f),f=f<0?0:1;if(h.length)for(var e=[],i=0;i=0,g=e.indexOf("(")>=0,h;if(f)d=e.split("."),e=d.shift(),d.shift();else if(g){h=e.split("(");e=h.shift();for(d=0;dq)break}if(!r){r=new l(q);t=-1;u=0;for(v=d.length;u=q&&(t=u);q=t;d.splice(q==-1?d.length:q,0,r)}r.addTarget(f,j,g,s)}}else console.log('Could not find transform "'+ +b.sid+'" in node '+this.id)}for(c=0;c=0?i:i+h.length;i>=0;i--)if(k=h[i],k.hasTarget(g)){i=k;break a}i=null}k=void 0;a:{for(j+=1;j4&&la.subdivideFaces){r=r.length?r:new THREE.Color; +for(e=1;e4?[r[0],r[n+1],r[n+2]]:m===4?[r[0],r[1],r[2],r[3]]:[r[0],r[1],r[2]],b.faceVertexUvs[e]||(b.faceVertexUvs[e]=[]),b.faceVertexUvs[e].push(r)}}else console.log("dropped face with vcount "+m+" for geometry with id: "+b.id);c+=g.length*m}};u.prototype=new t;u.prototype.constructor=u;t.prototype.setVertices= +function(a){for(var b=0;b0&&(this[c.nodeName]=parseFloat(d[0].textContent))}}this.create();return this};F.prototype.create=function(){var a={},b=this.transparency!==void 0&&this.transparency<1,c;for(c in this)switch(c){case "ambient":case "emission":case "diffuse":case "specular":var d=this[c];if(d instanceof w)if(d.isTexture()){if(this.effect.sampler&&this.effect.surface&&this.effect.sampler.source==this.effect.surface.sid){var e=va[this.effect.surface.init_from];if(e)e=THREE.ImageUtils.loadTexture(xa+ +e.init_from),e.wrapS=d.texOpts.wrapU?THREE.RepeatWrapping:THREE.ClampToEdgeWrapping,e.wrapT=d.texOpts.wrapV?THREE.RepeatWrapping:THREE.ClampToEdgeWrapping,e.offset.x=d.texOpts.offsetU,e.offset.y=d.texOpts.offsetV,e.repeat.x=d.texOpts.repeatU,e.repeat.y=d.texOpts.repeatV,a.map=e}}else c=="diffuse"?a.color=d.color.getHex():b||(a[c]=d.color.getHex());break;case "shininess":case "reflectivity":a[c]=this[c];break;case "transparency":if(b)a.transparent=!0,a.opacity=this[c],b=!0}a.shading=Aa;return this.material= +new THREE.MeshLambertMaterial(a)};y.prototype.parse=function(a){for(var b=0;b=0,d=a.indexOf("(")>=0;if(c)b=a.split("."),this.sid=b.shift(),this.member=b.shift();else if(d){b=a.split("(");this.sid=b.shift();for(var e=0;e1){c=[];b*=this.strideOut;for(var d=0;d1)console.log("Key.interpolate: Warning! Scale out of bounds:"+f),f=f<0?0:1;if(h.length)for(var e=[],i=0;i1&&($=new THREE.MeshFaceMaterial); -a=new THREE.Mesh(G,$);a.name=p;a.position.set(z[0],z[1],z[2]);E?(a.quaternion.set(E[0],E[1],E[2],E[3]),a.useQuaternion=!0):a.rotation.set(A[0],A[1],A[2]);a.scale.set(D[0],D[1],D[2]);a.visible=r.visible;v.scene.add(a);v.objects[p]=a;if(r.meshCollider){var b=THREE.CollisionUtils.MeshColliderWBox(a);v.scene.collisions.colliders.push(b)}if(r.castsShadow)b=new THREE.ShadowVolume(G),v.scene.add(b),b.position=a.position,b.rotation=a.rotation,b.scale=a.scale;r.trigger&&r.trigger.toLowerCase()!="none"&&(b= -{type:r.trigger,object:r},v.triggers[a.name]=b)}}else z=r.position,A=r.rotation,E=r.quaternion,D=r.scale,E=0,a=new THREE.Object3D,a.name=p,a.position.set(z[0],z[1],z[2]),E?(a.quaternion.set(E[0],E[1],E[2],E[3]),a.useQuaternion=!0):a.rotation.set(A[0],A[1],A[2]),a.scale.set(D[0],D[1],D[2]),a.visible=r.visible!==void 0?r.visible:!1,v.scene.add(a),v.objects[p]=a,v.empties[p]=a,r.trigger&&r.trigger.toLowerCase()!="none"&&(b={type:r.trigger,object:r},v.triggers[a.name]=b)}function f(a){return function(b){v.geometries[a]= -b;e();S-=1;i.onLoadComplete();h()}}function g(a){return function(b){v.geometries[a]=b}}function h(){i.callbackProgress({totalModels:l,totalTextures:W,loadedModels:l-S,loadedTextures:W-R},v);i.onLoadProgress();S==0&&R==0&&b(v)}var i=this,k=THREE.Loader.prototype.extractUrlbase(c),j,o,p,m,q,n,s,r,u,t,z,A,E,D,B,w,G,y,K,$,Q,Y,S,R,l,W,v;Q=a;c=new THREE.BinaryLoader;Y=new THREE.JSONLoader;R=S=0;v={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},triggers:{}, -empties:{}};a=!1;for(p in Q.objects)if(r=Q.objects[p],r.meshCollider){a=!0;break}if(a)v.scene.collisions=new THREE.CollisionSystem;if(Q.transform)a=Q.transform.position,u=Q.transform.rotation,B=Q.transform.scale,a&&v.scene.position.set(a[0],a[1],a[2]),u&&v.scene.rotation.set(u[0],u[1],u[2]),B&&v.scene.scale.set(B[0],B[1],B[2]),(a||u||B)&&v.scene.updateMatrix();a=function(){R-=1;h();i.onLoadComplete()};for(q in Q.cameras)B=Q.cameras[q],B.type=="perspective"?y=new THREE.PerspectiveCamera(B.fov,B.aspect, -B.near,B.far):B.type=="ortho"&&(y=new THREE.OrthographicCamera(B.left,B.right,B.top,B.bottom,B.near,B.far)),z=B.position,u=B.target,B=B.up,y.position.set(z[0],z[1],z[2]),y.target=new THREE.Vector3(u[0],u[1],u[2]),B&&y.up.set(B[0],B[1],B[2]),v.cameras[q]=y;for(m in Q.lights)u=Q.lights[m],q=u.color!==void 0?u.color:16777215,y=u.intensity!==void 0?u.intensity:1,u.type=="directional"?(z=u.direction,t=new THREE.DirectionalLight(q,y),t.position.set(z[0],z[1],z[2]),t.position.normalize()):u.type=="point"? -(z=u.position,t=u.distance,t=new THREE.PointLight(q,y,t),t.position.set(z[0],z[1],z[2])):u.type=="ambient"&&(t=new THREE.AmbientLight(q)),v.scene.add(t),v.lights[m]=t;for(n in Q.fogs)m=Q.fogs[n],m.type=="linear"?K=new THREE.Fog(0,m.near,m.far):m.type=="exp2"&&(K=new THREE.FogExp2(0,m.density)),B=m.color,K.color.setRGB(B[0],B[1],B[2]),v.fogs[n]=K;if(v.cameras&&Q.defaults.camera)v.currentCamera=v.cameras[Q.defaults.camera];if(v.fogs&&Q.defaults.fog)v.scene.fog=v.fogs[Q.defaults.fog];B=Q.defaults.bgcolor; -v.bgColor=new THREE.Color;v.bgColor.setRGB(B[0],B[1],B[2]);v.bgColorAlpha=Q.defaults.bgalpha;for(j in Q.geometries)if(n=Q.geometries[j],n.type=="bin_mesh"||n.type=="ascii_mesh")S+=1,i.onLoadStart();l=S;for(j in Q.geometries)n=Q.geometries[j],n.type=="cube"?(G=new THREE.CubeGeometry(n.width,n.height,n.depth,n.segmentsWidth,n.segmentsHeight,n.segmentsDepth,null,n.flipped,n.sides),v.geometries[j]=G):n.type=="plane"?(G=new THREE.PlaneGeometry(n.width,n.height,n.segmentsWidth,n.segmentsHeight),v.geometries[j]= -G):n.type=="sphere"?(G=new THREE.SphereGeometry(n.radius,n.segmentsWidth,n.segmentsHeight),v.geometries[j]=G):n.type=="cylinder"?(G=new THREE.CylinderGeometry(n.topRad,n.botRad,n.height,n.radSegs,n.heightSegs),v.geometries[j]=G):n.type=="torus"?(G=new THREE.TorusGeometry(n.radius,n.tube,n.segmentsR,n.segmentsT),v.geometries[j]=G):n.type=="icosahedron"?(G=new THREE.IcosahedronGeometry(n.subdivisions),v.geometries[j]=G):n.type=="bin_mesh"?c.load(d(n.url,Q.urlBaseType),f(j)):n.type=="ascii_mesh"?Y.load(d(n.url, -Q.urlBaseType),f(j)):n.type=="embedded_mesh"&&(n=Q.embeds[n.id])&&Y.createModel(n,g(j),"");for(s in Q.textures)if(j=Q.textures[s],j.url instanceof Array){R+=j.url.length;for(n=0;n1&&($=new THREE.MeshFaceMaterial); +a=new THREE.Mesh(F,$);a.name=p;a.position.set(A[0],A[1],A[2]);z?(a.quaternion.set(z[0],z[1],z[2],z[3]),a.useQuaternion=!0):a.rotation.set(B[0],B[1],B[2]);a.scale.set(D[0],D[1],D[2]);a.visible=r.visible;v.scene.add(a);v.objects[p]=a;if(r.meshCollider){var b=THREE.CollisionUtils.MeshColliderWBox(a);v.scene.collisions.colliders.push(b)}if(r.castsShadow)b=new THREE.ShadowVolume(F),v.scene.add(b),b.position=a.position,b.rotation=a.rotation,b.scale=a.scale;r.trigger&&r.trigger.toLowerCase()!="none"&&(b= +{type:r.trigger,object:r},v.triggers[a.name]=b)}}else A=r.position,B=r.rotation,z=r.quaternion,D=r.scale,z=0,a=new THREE.Object3D,a.name=p,a.position.set(A[0],A[1],A[2]),z?(a.quaternion.set(z[0],z[1],z[2],z[3]),a.useQuaternion=!0):a.rotation.set(B[0],B[1],B[2]),a.scale.set(D[0],D[1],D[2]),a.visible=r.visible!==void 0?r.visible:!1,v.scene.add(a),v.objects[p]=a,v.empties[p]=a,r.trigger&&r.trigger.toLowerCase()!="none"&&(b={type:r.trigger,object:r},v.triggers[a.name]=b)}function f(a){return function(b){v.geometries[a]= +b;e();T-=1;i.onLoadComplete();h()}}function g(a){return function(b){v.geometries[a]=b}}function h(){i.callbackProgress({totalModels:l,totalTextures:S,loadedModels:l-T,loadedTextures:S-R},v);i.onLoadProgress();T==0&&R==0&&b(v)}var i=this,j=THREE.Loader.prototype.extractUrlbase(c),k,o,p,m,q,n,s,r,u,t,A,B,z,D,H,w,F,y,K,$,Q,X,T,R,l,S,v;Q=a;c=new THREE.BinaryLoader;X=new THREE.JSONLoader;R=T=0;v={scene:new THREE.Scene,geometries:{},materials:{},textures:{},objects:{},cameras:{},lights:{},fogs:{},triggers:{}, +empties:{}};a=!1;for(p in Q.objects)if(r=Q.objects[p],r.meshCollider){a=!0;break}if(a)v.scene.collisions=new THREE.CollisionSystem;if(Q.transform)a=Q.transform.position,u=Q.transform.rotation,H=Q.transform.scale,a&&v.scene.position.set(a[0],a[1],a[2]),u&&v.scene.rotation.set(u[0],u[1],u[2]),H&&v.scene.scale.set(H[0],H[1],H[2]),(a||u||H)&&v.scene.updateMatrix();a=function(){R-=1;h();i.onLoadComplete()};for(q in Q.cameras)H=Q.cameras[q],H.type=="perspective"?y=new THREE.PerspectiveCamera(H.fov,H.aspect, +H.near,H.far):H.type=="ortho"&&(y=new THREE.OrthographicCamera(H.left,H.right,H.top,H.bottom,H.near,H.far)),A=H.position,u=H.target,H=H.up,y.position.set(A[0],A[1],A[2]),y.target=new THREE.Vector3(u[0],u[1],u[2]),H&&y.up.set(H[0],H[1],H[2]),v.cameras[q]=y;for(m in Q.lights)u=Q.lights[m],q=u.color!==void 0?u.color:16777215,y=u.intensity!==void 0?u.intensity:1,u.type=="directional"?(A=u.direction,t=new THREE.DirectionalLight(q,y),t.position.set(A[0],A[1],A[2]),t.position.normalize()):u.type=="point"? +(A=u.position,t=u.distance,t=new THREE.PointLight(q,y,t),t.position.set(A[0],A[1],A[2])):u.type=="ambient"&&(t=new THREE.AmbientLight(q)),v.scene.add(t),v.lights[m]=t;for(n in Q.fogs)m=Q.fogs[n],m.type=="linear"?K=new THREE.Fog(0,m.near,m.far):m.type=="exp2"&&(K=new THREE.FogExp2(0,m.density)),H=m.color,K.color.setRGB(H[0],H[1],H[2]),v.fogs[n]=K;if(v.cameras&&Q.defaults.camera)v.currentCamera=v.cameras[Q.defaults.camera];if(v.fogs&&Q.defaults.fog)v.scene.fog=v.fogs[Q.defaults.fog];H=Q.defaults.bgcolor; +v.bgColor=new THREE.Color;v.bgColor.setRGB(H[0],H[1],H[2]);v.bgColorAlpha=Q.defaults.bgalpha;for(k in Q.geometries)if(n=Q.geometries[k],n.type=="bin_mesh"||n.type=="ascii_mesh")T+=1,i.onLoadStart();l=T;for(k in Q.geometries)n=Q.geometries[k],n.type=="cube"?(F=new THREE.CubeGeometry(n.width,n.height,n.depth,n.segmentsWidth,n.segmentsHeight,n.segmentsDepth,null,n.flipped,n.sides),v.geometries[k]=F):n.type=="plane"?(F=new THREE.PlaneGeometry(n.width,n.height,n.segmentsWidth,n.segmentsHeight),v.geometries[k]= +F):n.type=="sphere"?(F=new THREE.SphereGeometry(n.radius,n.segmentsWidth,n.segmentsHeight),v.geometries[k]=F):n.type=="cylinder"?(F=new THREE.CylinderGeometry(n.topRad,n.botRad,n.height,n.radSegs,n.heightSegs),v.geometries[k]=F):n.type=="torus"?(F=new THREE.TorusGeometry(n.radius,n.tube,n.segmentsR,n.segmentsT),v.geometries[k]=F):n.type=="icosahedron"?(F=new THREE.IcosahedronGeometry(n.subdivisions),v.geometries[k]=F):n.type=="bin_mesh"?c.load(d(n.url,Q.urlBaseType),f(k)):n.type=="ascii_mesh"?X.load(d(n.url, +Q.urlBaseType),f(k)):n.type=="embedded_mesh"&&(n=Q.embeds[n.id])&&X.createModel(n,g(k),"");for(s in Q.textures)if(k=Q.textures[s],k.url instanceof Array){R+=k.url.length;for(n=0;n=57344&&(b-=2048);b++;for(var c=new Float32Array(8*b),d=1,e=0;e<8;e++){for(var f=0,g=0;g>1^-(h&1);c[8*g+e]=f}d+=b}b=a.length-d;f=new Uint16Array(b);for(e=g=0;e=this.maxCount-3&&h(this)};this.begin=function(){this.count=0; -this.hasNormal=this.hasPos=!1};this.end=function(a){if(this.count!==0){for(var b=this.count*3;bthis.size-1&&(i=this.size-1);var p=Math.floor(k-h);p<1&&(p=1);k=Math.floor(k+h);k>this.size-1&&(k=this.size-1);var m=Math.floor(j-h);m<1&&(m=1);h=Math.floor(j+h);h>this.size-1&&(h=this.size- -1);for(var q,n,s,r,u,t;o0&&(this.field[s+q]+=r)}}};this.addPlaneX=function(a,b){var e,f,g,h,i,k=this.size,j=this.yd,o=this.zd,p=this.field,m=k*Math.sqrt(a/b);m>k&&(m=k);for(e=0;e0)for(f=0;fj&&(q=j);for(f=0;f0){i=f*o;for(e=0;ej&&(q=j);for(g=0;g0){i=p*g;for(f=0;fthis.size-1&&(i=this.size-1);var p=Math.floor(j-h);p<1&&(p=1);j=Math.floor(j+h);j>this.size-1&&(j=this.size-1);var m=Math.floor(k-h);m<1&&(m=1);h=Math.floor(k+h);h>this.size-1&&(h=this.size- +1);for(var q,n,s,r,u,t;o0&&(this.field[s+q]+=r)}}};this.addPlaneX=function(a,b){var e,f,g,h,i,j=this.size,k=this.yd,o=this.zd,p=this.field,m=j*Math.sqrt(a/b);m>j&&(m=j);for(e=0;e0)for(f=0;fk&&(q=k);for(f=0;f0){i=f*o;for(e=0;ek&&(q=k);for(g=0;g0){i=p*g;for(f=0;f0&&s.x0&&s.y0.0010&&E.scale>0.0010)n.x=E.x,n.y=E.y,n.z=E.z,m=E.size*E.scale/ -h,q.x=m*j,q.y=m,b.uniform3f(r.screenPosition,n.x,n.y,n.z),b.uniform2f(r.scale,q.x,q.y),b.uniform1f(r.rotation,E.rotation),b.uniform1f(r.opacity,E.opacity),b.uniform3f(r.color,E.color.r,E.color.g,E.color.b),c.setBlending(E.blending),c.setTexture(E.texture,1),b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(!0)}}}; +"color");d.uniforms.scale=b.getUniformLocation(d.program,"scale");d.uniforms.rotation=b.getUniformLocation(d.program,"rotation");d.uniforms.screenPosition=b.getUniformLocation(d.program,"screenPosition");d.attributesEnabled=!1};this.render=function(a,f,g,h){var a=a.__webglFlares,i=a.length;if(i){var j=new THREE.Vector3,k=h/g,o=g*0.5,p=h*0.5,m=16/h,q=new THREE.Vector2(m*k,m),n=new THREE.Vector3(1,1,0),s=new THREE.Vector2(1,1),r=d.uniforms,m=d.attributes;b.useProgram(d.program);if(!d.attributesEnabled)b.enableVertexAttribArray(d.attributes.vertex), +b.enableVertexAttribArray(d.attributes.uv),d.attributesEnabled=!0;b.uniform1i(r.occlusionMap,0);b.uniform1i(r.map,1);b.bindBuffer(b.ARRAY_BUFFER,d.vertexBuffer);b.vertexAttribPointer(m.vertex,2,b.FLOAT,!1,16,0);b.vertexAttribPointer(m.uv,2,b.FLOAT,!1,16,8);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,d.elementBuffer);b.disable(b.CULL_FACE);b.depthMask(!1);var u,t,A,B,z;for(u=0;u0&&s.x0&&s.y0.0010&&z.scale>0.0010)n.x=z.x,n.y=z.y,n.z=z.z,m=z.size*z.scale/ +h,q.x=m*k,q.y=m,b.uniform3f(r.screenPosition,n.x,n.y,n.z),b.uniform2f(r.scale,q.x,q.y),b.uniform1f(r.rotation,z.rotation),b.uniform1f(r.opacity,z.opacity),b.uniform3f(r.color,z.color.r,z.color.g,z.color.b),c.setBlending(z.blending),c.setTexture(z.texture,1),b.drawElements(b.TRIANGLES,6,b.UNSIGNED_SHORT,0)}b.enable(b.CULL_FACE);b.enable(b.DEPTH_TEST);b.depthMask(!0)}}}; THREE.ShadowMapPlugin=function(){var a,b,c,d,e,f=new THREE.Frustum,g=new THREE.Matrix4;this.shadowMatrix=[];this.shadowMap=[];this.init=function(e){a=e.context;b=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:!0});c._shadowPass=!0;d._shadowPass=!0};this.render= -function(a,c){b.shadowMapEnabled&&b.shadowMapAutoUpdate&&this.update(a,c)};this.update=function(h){var i,k,j,o,p,m,q,n,s=0,r=h.lights;e||(e=new THREE.PerspectiveCamera(b.shadowCameraFov,b.shadowMapWidth/b.shadowMapHeight,b.shadowCameraNear,b.shadowCameraFar));i=0;for(k=r.length;i0){var a;a=this.vertices[0].position;this.boundingBox?(this.boundingBox.min.copy(a),this.boundingBox.max.copy(a)):this.boundingBox={min:a.clone(),max:a.clone()};for(var b=this.boundingBox.min,c=this.boundingBox.max,d=1,e=this.vertices.length;dc.x)c.x=a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}},computeBoundingSphere:function(){for(var a=0,b=0,c=this.vertices.length;bc.x)c.x=a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}},computeBoundingSphere:function(){for(var a,b=0,c=0,d=this.vertices.length;cb&&(b=a);this.boundingSphere={radius:b}},mergeVertices:function(){var a={},b=[],c=[],d,e=Math.pow(10,4),f,g;f=0;for(g=this.vertices.length;f 0\nuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\nuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\nvarying vec4 vPointLight[ MAX_POINT_LIGHTS ];\n#endif\nvarying vec3 vViewPosition;", THREE.ShaderChunk.shadowmap_pars_vertex,"void main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvViewPosition = -mvPosition.xyz;\nvNormal = normalMatrix * normal;\nvTangent = normalMatrix * tangent.xyz;\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvUv = uv * uRepeat + uOffset;\n#if MAX_POINT_LIGHTS > 0\nfor( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {\nvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\nvec3 lVector = lPosition.xyz - mvPosition.xyz;\nfloat lDistance = 1.0;\nif ( pointLightDistance[ i ] > 0.0 )\nlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\nlVector = normalize( lVector );\nvPointLight[ i ] = vec4( lVector, lDistance );\n}\n#endif\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( normalize( vNormal.xyz ) * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif", THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n")},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}"}}}; +THREE.BufferGeometry=function(){this.id=THREE.GeometryCount++;this.vertexColorArray=this.vertexUvArray=this.vertexNormalArray=this.vertexPositionArray=this.vertexIndexArray=this.vertexColorBuffer=this.vertexUvBuffer=this.vertexNormalBuffer=this.vertexPositionBuffer=this.vertexIndexBuffer=null;this.dynamic=!1;this.boundingSphere=this.boundingBox=null;this.morphTargets=[]};THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,computeBoundingBox:function(){},computeBoundingSphere:function(){}}; THREE.Curve=function(){};THREE.Curve.prototype.getPoint=function(){console.log("Warning, getPoint() not implemented!");return null};THREE.Curve.prototype.getPointAt=function(a){return this.getPoint(this.getUtoTmapping(a))};THREE.Curve.prototype.getPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPoint(b/a));return c};THREE.Curve.prototype.getSpacedPoints=function(a){a||(a=5);var b,c=[];for(b=0;b<=a;b++)c.push(this.getPointAt(b/a));return c}; THREE.Curve.prototype.getLength=function(){var a=this.getLengths();return a[a.length-1]};THREE.Curve.prototype.getLengths=function(a){a||(a=200);if(this.cacheArcLengths&&this.cacheArcLengths.length==a+1)return this.cacheArcLengths;var b=[],c,d=this.getPoint(0),e,g=0;b.push(0);for(e=1;e<=a;e++)c=this.getPoint(e/a),g+=c.distanceTo(d),b.push(g),d=c;return this.cacheArcLengths=b}; THREE.Curve.prototype.getUtoTmapping=function(a,b){var c=this.getLengths(),d=0,e=c.length,g;g=b?b:a*c[e-1];for(var f=0,h=e-1,i;f<=h;)if(d=Math.floor(f+(h-f)/2),i=c[d]-g,i<0)f=d+1;else if(i>0)h=d-1;else{h=d;break}d=h;if(c[d]==g)return d/(e-1);f=c[d];return c=(d+(g-f)/(c[d+1]-f))/(e-1)};THREE.Curve.prototype.getNormalVector=function(a){a=this.getTangent(a);return new THREE.Vector2(-a.y,a.x)}; diff --git a/build/custom/ThreeSVG.js b/build/custom/ThreeSVG.js index a5806ca990..f668589897 100644 --- a/build/custom/ThreeSVG.js +++ b/build/custom/ThreeSVG.js @@ -89,7 +89,7 @@ d[c.b].addSelf(c.normal),d[c.c].addSelf(c.normal),d[c.d].addSelf(c.normal));a=0; b,c,d,e,f,A){h=a.vertices[b].position;l=a.vertices[c].position;i=a.vertices[d].position;k=g[e];j=g[f];n=g[A];m=l.x-h.x;o=i.x-h.x;p=l.y-h.y;u=i.y-h.y;F=l.z-h.z;v=i.z-h.z;D=j.u-k.u;s=n.u-k.u;t=j.v-k.v;B=n.v-k.v;x=1/(D*B-s*t);I.set((B*m-t*o)*x,(B*p-t*u)*x,(B*F-t*v)*x);z.set((D*o-s*m)*x,(D*u-s*p)*x,(D*v-s*F)*x);H[b].addSelf(I);H[c].addSelf(I);H[d].addSelf(I);C[b].addSelf(z);C[c].addSelf(z);C[d].addSelf(z)}var b,c,d,e,f,g,h,l,i,k,j,n,m,o,p,u,F,v,D,s,t,B,x,y,H=[],C=[],I=new THREE.Vector3,z=new THREE.Vector3, L=new THREE.Vector3,J=new THREE.Vector3,M=new THREE.Vector3;b=0;for(c=this.vertices.length;b0){var a;a=this.vertices[0].position;this.boundingBox?(this.boundingBox.min.copy(a),this.boundingBox.max.copy(a)):this.boundingBox={min:a.clone(),max:a.clone()};for(var b=this.boundingBox.min,c=this.boundingBox.max,d=1,e=this.vertices.length;dc.x)c.x=a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}},computeBoundingSphere:function(){for(var a=0,b=0,c=this.vertices.length;bc.x)c.x=a.x;if(a.yc.y)c.y=a.y;if(a.zc.z)c.z=a.z}}},computeBoundingSphere:function(){for(var a,b=0,c=0,d=this.vertices.length;cb&&(b=a);this.boundingSphere={radius:b}},mergeVertices:function(){var a={},b=[],c=[],d,e=Math.pow(10,4),f,g;f=0;for(g=this.vertices.length;f=0&&O>=0&&N+O<1}this.origin=a||new THREE.Vector3;this.direction=b||new THREE.Vector3;this.intersectScene=function(a){return this.intersectObjects(a.children)};this.intersectObjects=function(a){var b, d,c=[];b=0;for(d=a.length;bn.scale.x)return[];w={distance:s,point:n.position,face:null,object:n};p.push(w)}else if(n instanceof THREE.Mesh){s=d(this.origin,this.direction,n.matrixWorld.getPosition());if(s===null||s>n.geometry.boundingSphere.radius*Math.max(n.scale.x,Math.max(n.scale.y,n.scale.z)))return p;var y,C=n.geometry,J=C.vertices,I;n.matrixRotationWorld.extractRotation(n.matrixWorld);s=0;for(E=C.faces.length;s0:y<0)))if(y=k.dot(l.sub(f,a))/y,j.add(a,b.multiplyScalar(y)),w instanceof THREE.Face3)c(j, +d(this.origin,this.direction,n.matrixWorld.getPosition());if(s===null||s>n.scale.x)return[];w={distance:s,point:n.position,face:null,object:n};p.push(w)}else if(n instanceof THREE.Mesh){s=d(this.origin,this.direction,n.matrixWorld.getPosition());if(s===null||s>n.geometry.boundingSphere.radius*Math.max(n.scale.x,Math.max(n.scale.y,n.scale.z)))return p;var y,C=n.geometry,J=C.vertices,H;n.matrixRotationWorld.extractRotation(n.matrixWorld);s=0;for(E=C.faces.length;s0:y<0)))if(y=k.dot(l.sub(f,a))/y,j.add(a,b.multiplyScalar(y)),w instanceof THREE.Face3)c(j, f,g,h)&&(w={distance:a.distanceTo(j),point:j.clone(),face:w,object:n},p.push(w));else if(w instanceof THREE.Face4&&(c(j,f,g,i)||c(j,g,h,i)))w={distance:a.distanceTo(j),point:j.clone(),face:w,object:n},p.push(w)}return p};var p=new THREE.Vector3,s=new THREE.Vector3,w=new THREE.Vector3,n,E,y,J,P,Q,V,C,D,N,O}; THREE.Rectangle=function(){function a(){g=c-b;h=f-d}var b,d,c,f,g,h,i=!0;this.getX=function(){return b};this.getY=function(){return d};this.getWidth=function(){return g};this.getHeight=function(){return h};this.getLeft=function(){return b};this.getTop=function(){return d};this.getRight=function(){return c};this.getBottom=function(){return f};this.set=function(g,h,j,p){i=!1;b=g;d=h;c=j;f=p;a()};this.addPoint=function(g,h){i?(i=!1,b=g,d=h,c=g,f=h):(b=bg?c:g,f=f>h?f:h);a()};this.add3Points= function(g,h,j,p,s,w){i?(i=!1,b=gj?g>s?g:s:j>s?j:s,f=h>p?h>w?h:w:p>w?p:w):(b=gj?g>s?g>c?g:c:s>c?s:c:j>s?j>c?j:c:s>c?s:c,f=h>p?h>w?h>f?h:f:w>f?w:f:p>w?p>f?p:f:w>f?w:f);a()};this.addRectangle=function(g){i?(i=!1,b=g.getLeft(),d=g.getTop(),c=g.getRight(),f=g.getBottom()):(b=bg.getRight()?c:g.getRight(),f=f> @@ -29,8 +29,8 @@ THREE.Matrix3.prototype={constructor:THREE.Matrix3,transpose:function(){var a,b= THREE.Matrix4=function(a,b,d,c,f,g,h,i,l,k,j,p,s,w,n,E){this.set(a!==void 0?a:1,b||0,d||0,c||0,f||0,g!==void 0?g:1,h||0,i||0,l||0,k||0,j!==void 0?j:1,p||0,s||0,w||0,n||0,E!==void 0?E:1);this.flat=Array(16);this.m33=new THREE.Matrix3}; THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(a,b,d,c,f,g,h,i,l,k,j,p,s,w,n,E){this.n11=a;this.n12=b;this.n13=d;this.n14=c;this.n21=f;this.n22=g;this.n23=h;this.n24=i;this.n31=l;this.n32=k;this.n33=j;this.n34=p;this.n41=s;this.n42=w;this.n43=n;this.n44=E;return this},identity:function(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this},copy:function(a){this.set(a.n11,a.n12,a.n13,a.n14,a.n21,a.n22,a.n23,a.n24,a.n31,a.n32,a.n33,a.n34,a.n41,a.n42,a.n43,a.n44);return this},lookAt:function(a, b,d){var c=THREE.Matrix4.__v1,f=THREE.Matrix4.__v2,g=THREE.Matrix4.__v3;g.sub(a,b).normalize();if(g.length()===0)g.z=1;c.cross(d,g).normalize();c.length()===0&&(g.x+=1.0E-4,c.cross(d,g).normalize());f.cross(g,c).normalize();this.n11=c.x;this.n12=f.x;this.n13=g.x;this.n21=c.y;this.n22=f.y;this.n23=g.y;this.n31=c.z;this.n32=f.z;this.n33=g.z;return this},multiply:function(a,b){var d=a.n11,c=a.n12,f=a.n13,g=a.n14,h=a.n21,i=a.n22,l=a.n23,k=a.n24,j=a.n31,p=a.n32,s=a.n33,w=a.n34,n=a.n41,E=a.n42,y=a.n43, -J=a.n44,P=b.n11,Q=b.n12,V=b.n13,C=b.n14,D=b.n21,N=b.n22,O=b.n23,ma=b.n24,ua=b.n31,ha=b.n32,ca=b.n33,pa=b.n34,ja=b.n41,xa=b.n42,va=b.n43,I=b.n44;this.n11=d*P+c*D+f*ua+g*ja;this.n12=d*Q+c*N+f*ha+g*xa;this.n13=d*V+c*O+f*ca+g*va;this.n14=d*C+c*ma+f*pa+g*I;this.n21=h*P+i*D+l*ua+k*ja;this.n22=h*Q+i*N+l*ha+k*xa;this.n23=h*V+i*O+l*ca+k*va;this.n24=h*C+i*ma+l*pa+k*I;this.n31=j*P+p*D+s*ua+w*ja;this.n32=j*Q+p*N+s*ha+w*xa;this.n33=j*V+p*O+s*ca+w*va;this.n34=j*C+p*ma+s*pa+w*I;this.n41=n*P+E*D+y*ua+J*ja;this.n42= -n*Q+E*N+y*ha+J*xa;this.n43=n*V+E*O+y*ca+J*va;this.n44=n*C+E*ma+y*pa+J*I;return this},multiplySelf:function(a){return this.multiply(this,a)},multiplyToArray:function(a,b,d){this.multiply(a,b);d[0]=this.n11;d[1]=this.n21;d[2]=this.n31;d[3]=this.n41;d[4]=this.n12;d[5]=this.n22;d[6]=this.n32;d[7]=this.n42;d[8]=this.n13;d[9]=this.n23;d[10]=this.n33;d[11]=this.n43;d[12]=this.n14;d[13]=this.n24;d[14]=this.n34;d[15]=this.n44;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*= +J=a.n44,P=b.n11,Q=b.n12,V=b.n13,C=b.n14,D=b.n21,N=b.n22,O=b.n23,ma=b.n24,ua=b.n31,ha=b.n32,ca=b.n33,pa=b.n34,ja=b.n41,xa=b.n42,va=b.n43,H=b.n44;this.n11=d*P+c*D+f*ua+g*ja;this.n12=d*Q+c*N+f*ha+g*xa;this.n13=d*V+c*O+f*ca+g*va;this.n14=d*C+c*ma+f*pa+g*H;this.n21=h*P+i*D+l*ua+k*ja;this.n22=h*Q+i*N+l*ha+k*xa;this.n23=h*V+i*O+l*ca+k*va;this.n24=h*C+i*ma+l*pa+k*H;this.n31=j*P+p*D+s*ua+w*ja;this.n32=j*Q+p*N+s*ha+w*xa;this.n33=j*V+p*O+s*ca+w*va;this.n34=j*C+p*ma+s*pa+w*H;this.n41=n*P+E*D+y*ua+J*ja;this.n42= +n*Q+E*N+y*ha+J*xa;this.n43=n*V+E*O+y*ca+J*va;this.n44=n*C+E*ma+y*pa+J*H;return this},multiplySelf:function(a){return this.multiply(this,a)},multiplyToArray:function(a,b,d){this.multiply(a,b);d[0]=this.n11;d[1]=this.n21;d[2]=this.n31;d[3]=this.n41;d[4]=this.n12;d[5]=this.n22;d[6]=this.n32;d[7]=this.n42;d[8]=this.n13;d[9]=this.n23;d[10]=this.n33;d[11]=this.n43;d[12]=this.n14;d[13]=this.n24;d[14]=this.n34;d[15]=this.n44;return this},multiplyScalar:function(a){this.n11*=a;this.n12*=a;this.n13*=a;this.n14*= a;this.n21*=a;this.n22*=a;this.n23*=a;this.n24*=a;this.n31*=a;this.n32*=a;this.n33*=a;this.n34*=a;this.n41*=a;this.n42*=a;this.n43*=a;this.n44*=a;return this},multiplyVector3:function(a){var b=a.x,d=a.y,c=a.z,f=1/(this.n41*b+this.n42*d+this.n43*c+this.n44);a.x=(this.n11*b+this.n12*d+this.n13*c+this.n14)*f;a.y=(this.n21*b+this.n22*d+this.n23*c+this.n24)*f;a.z=(this.n31*b+this.n32*d+this.n33*c+this.n34)*f;return a},multiplyVector4:function(a){var b=a.x,d=a.y,c=a.z,f=a.w;a.x=this.n11*b+this.n12*d+this.n13* c+this.n14*f;a.y=this.n21*b+this.n22*d+this.n23*c+this.n24*f;a.z=this.n31*b+this.n32*d+this.n33*c+this.n34*f;a.w=this.n41*b+this.n42*d+this.n43*c+this.n44*f;return a},rotateAxis:function(a){var b=a.x,d=a.y,c=a.z;a.x=b*this.n11+d*this.n12+c*this.n13;a.y=b*this.n21+d*this.n22+c*this.n23;a.z=b*this.n31+d*this.n32+c*this.n33;a.normalize();return a},crossVector:function(a){var b=new THREE.Vector4;b.x=this.n11*a.x+this.n12*a.y+this.n13*a.z+this.n14*a.w;b.y=this.n21*a.x+this.n22*a.y+this.n23*a.z+this.n24* a.w;b.z=this.n31*a.x+this.n32*a.y+this.n33*a.z+this.n34*a.w;b.w=a.w?this.n41*a.x+this.n42*a.y+this.n43*a.z+this.n44*a.w:1;return b},determinant:function(){var a=this.n11,b=this.n12,d=this.n13,c=this.n14,f=this.n21,g=this.n22,h=this.n23,i=this.n24,l=this.n31,k=this.n32,j=this.n33,p=this.n34,s=this.n41,w=this.n42,n=this.n43,E=this.n44;return c*h*k*s-d*i*k*s-c*g*j*s+b*i*j*s+d*g*p*s-b*h*p*s-c*h*l*w+d*i*l*w+c*f*j*w-a*i*j*w-d*f*p*w+a*h*p*w+c*g*l*n-b*i*l*n-c*f*k*n+a*i*k*n+b*f*p*n-a*g*p*n-d*g*l*E+b*h*l*E+ @@ -63,13 +63,13 @@ this.updateMatrix();if(this.matrixWorldNeedsUpdate||a)this.parent?this.matrixWor THREE.Projector=function(){function a(){var a=h[g]=h[g]||new THREE.RenderableObject;g++;return a}function b(){var a=k[l]=k[l]||new THREE.RenderableVertex;l++;return a}function d(a,b){return b.z-a.z}function c(a,b){var d=0,c=1,f=a.z+a.w,e=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;return f>=0&&e>=0&&g>=0&&h>=0?!0:f<0&&e<0||g<0&&h<0?!1:(f<0?d=Math.max(d,f/(f-e)):e<0&&(c=Math.min(c,f/(f-e))),g<0?d=Math.max(d,g/(g-h)):h<0&&(c=Math.min(c,g/(g-h))),ch&&i.positionScreen.z0&&N.z<1))h=V[Q]=V[Q]||new THREE.RenderableParticle, +f.object=b,f.z=D.z,C.objects.push(f)):b instanceof THREE.Sprite||b instanceof THREE.Particle?(O.multiplyVector3(D.copy(b.position)),f=a(),f.object=b,f.z=D.z,C.sprites.push(f)):b instanceof THREE.Light&&C.lights.push(b);for(var d=0,e=b.children.length;dh&&i.positionScreen.z0&&N.z<1))h=V[Q]=V[Q]||new THREE.RenderableParticle, Q++,P=h,P.x=N.x/N.w,P.y=N.y/N.w,P.z=N.z,P.rotation=Z.rotation.z,P.scale.x=Z.scale.x*Math.abs(P.x-(N.x+f.projectionMatrix.n11)/(N.w+f.projectionMatrix.n14)),P.scale.y=Z.scale.y*Math.abs(P.y-(N.y+f.projectionMatrix.n22)/(N.w+f.projectionMatrix.n24)),P.material=Z.material,C.elements.push(P);g&&C.elements.sort(d);return C}};THREE.Quaternion=function(a,b,d,c){this.set(a||0,b||0,d||0,c!==void 0?c:1)}; THREE.Quaternion.prototype={constructor:THREE.Quaternion,set:function(a,b,d,c){this.x=a;this.y=b;this.z=d;this.w=c;return this},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},setFromEuler:function(a){var b=Math.PI/360,d=a.x*b,c=a.y*b,f=a.z*b,a=Math.cos(c),c=Math.sin(c),b=Math.cos(-f),f=Math.sin(-f),g=Math.cos(d),d=Math.sin(d),h=a*b,i=c*f;this.w=h*g-i*d;this.x=h*d+i*g;this.y=c*b*g+a*f*d;this.z=a*f*g-c*b*d;return this},setFromAxisAngle:function(a,b){var d=b/2,c=Math.sin(d); this.x=a.x*c;this.y=a.y*c;this.z=a.z*c;this.w=Math.cos(d);return this},setFromRotationMatrix:function(a){var b=Math.pow(a.determinant(),1/3);this.w=Math.sqrt(Math.max(0,b+a.n11+a.n22+a.n33))/2;this.x=Math.sqrt(Math.max(0,b+a.n11-a.n22-a.n33))/2;this.y=Math.sqrt(Math.max(0,b-a.n11+a.n22-a.n33))/2;this.z=Math.sqrt(Math.max(0,b-a.n11-a.n22+a.n33))/2;this.x=a.n32-a.n23<0?-Math.abs(this.x):Math.abs(this.x);this.y=a.n13-a.n31<0?-Math.abs(this.y):Math.abs(this.y);this.z=a.n21-a.n12<0?-Math.abs(this.z):Math.abs(this.z); @@ -89,7 +89,7 @@ c[d.b].addSelf(d.normal),c[d.c].addSelf(d.normal),c[d.d].addSelf(d.normal));a=0; b,d,c,f,g,O){i=a.vertices[b].position;l=a.vertices[d].position;k=a.vertices[c].position;j=h[f];p=h[g];s=h[O];w=l.x-i.x;n=k.x-i.x;E=l.y-i.y;y=k.y-i.y;J=l.z-i.z;P=k.z-i.z;Q=p.u-j.u;V=s.u-j.u;C=p.v-j.v;D=s.v-j.v;N=1/(Q*D-V*C);ha.set((D*w-C*n)*N,(D*E-C*y)*N,(D*J-C*P)*N);ca.set((Q*n-V*w)*N,(Q*y-V*E)*N,(Q*P-V*J)*N);ma[b].addSelf(ha);ma[d].addSelf(ha);ma[c].addSelf(ha);ua[b].addSelf(ca);ua[d].addSelf(ca);ua[c].addSelf(ca)}var b,d,c,f,g,h,i,l,k,j,p,s,w,n,E,y,J,P,Q,V,C,D,N,O,ma=[],ua=[],ha=new THREE.Vector3, ca=new THREE.Vector3,pa=new THREE.Vector3,ja=new THREE.Vector3,xa=new THREE.Vector3;b=0;for(d=this.vertices.length;b0){var a;a=this.vertices[0].position;this.boundingBox?(this.boundingBox.min.copy(a),this.boundingBox.max.copy(a)):this.boundingBox={min:a.clone(),max:a.clone()};for(var b=this.boundingBox.min,d=this.boundingBox.max,c=1,f=this.vertices.length;c< -f;c++){a=this.vertices[c].position;if(a.xd.x)d.x=a.x;if(a.yd.y)d.y=a.y;if(a.zd.z)d.z=a.z}}},computeBoundingSphere:function(){for(var a=0,b=0,d=this.vertices.length;bd.x)d.x=a.x;if(a.yd.y)d.y=a.y;if(a.zd.z)d.z=a.z}}},computeBoundingSphere:function(){for(var a,b=0,d=0,c=this.vertices.length;db&&(b=a);this.boundingSphere={radius:b}},mergeVertices:function(){var a={},b=[],d=[],c,f=Math.pow(10,4),g,h;g=0;for(h=this.vertices.length;gthis.points.length-2?g:g+1;d[3]=g>this.points.length-3?g:g+2;k=this.points[d[0]];j=this.points[d[1]]; p=this.points[d[2]];s=this.points[d[3]];i=h*h;l=h*i;c.x=b(k.x,j.x,p.x,s.x,h,i,l);c.y=b(k.y,j.y,p.y,s.y,h,i,l);c.z=b(k.z,j.z,p.z,s.z,h,i,l);return c};this.getControlPointsArray=function(){var a,b,d=this.points.length,c=[];for(a=0;a=0;d--)a[d].object===b&&a.splice(d,1)}function E(a,b){for(var d=a.length-1;d>=0;d--)a[d]===b&&a.splice(d,1)}function y(a,b,d,c,f){c.program||I.initMaterial(c,b,d,f);if(c.morphTargets&&!f.__webglMorphTargetInfluences){f.__webglMorphTargetInfluences= -new Float32Array(I.maxMorphTargets);for(var g=0,h=I.maxMorphTargets;g0;this.getContext=function(){return e};this.supportsVertexTextures=function(){return Ma};this.setSize=function(a,b){ma.width=a;ma.height=b;this.setViewport(0,0,ma.width,ma.height)};this.setViewport=function(a,b,c,d){Ea=a;Fa=b;Ga=c;Ha=d;e.viewport(Ea,Fa,Ga,Ha)};this.setScissor=function(a,b,c,d){e.scissor(a,b,c,d)};this.enableScissorTest=function(a){a?e.enable(e.SCISSOR_TEST):e.disable(e.SCISSOR_TEST)};this.setClearColorHex=function(a, -b){ja.setHex(a);xa=b;e.clearColor(ja.r,ja.g,ja.b,xa)};this.setClearColor=function(a,b){ja.copy(a);xa=b;e.clearColor(ja.r,ja.g,ja.b,xa)};this.getClearColor=function(){return ja};this.getClearAlpha=function(){return xa};this.clear=function(a,b,c){var d=0;if(a===void 0||a)d|=e.COLOR_BUFFER_BIT;if(b===void 0||b)d|=e.DEPTH_BUFFER_BIT;if(c===void 0||c)d|=e.STENCIL_BUFFER_BIT;e.clear(d)};this.clearTarget=function(a,b,c,d){this.setRenderTarget(a);this.clear(b,c,d)};this.addPostPlugin=function(a){a.init(this); -this.renderPluginsPost.push(a)};this.addPrePlugin=function(a){a.init(this);this.renderPluginsPre.push(a)};this.deallocateObject=function(a){if(a.__webglInit)if(a.__webglInit=!1,delete a._modelViewMatrix,delete a._normalMatrixArray,delete a._modelViewMatrixArray,delete a._objectMatrixArray,a instanceof THREE.Mesh)for(var b in a.geometry.geometryGroups){var c=a.geometry.geometryGroups[b];e.deleteBuffer(c.__webglVertexBuffer);e.deleteBuffer(c.__webglNormalBuffer);e.deleteBuffer(c.__webglTangentBuffer); -e.deleteBuffer(c.__webglColorBuffer);e.deleteBuffer(c.__webglUVBuffer);e.deleteBuffer(c.__webglUV2Buffer);e.deleteBuffer(c.__webglSkinVertexABuffer);e.deleteBuffer(c.__webglSkinVertexBBuffer);e.deleteBuffer(c.__webglSkinIndicesBuffer);e.deleteBuffer(c.__webglSkinWeightsBuffer);e.deleteBuffer(c.__webglFaceBuffer);e.deleteBuffer(c.__webglLineBuffer);if(c.numMorphTargets)for(var d=0,f=c.numMorphTargets;d=0)a&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglVertexBuffer),e.vertexAttribPointer(b.position, -3,e.FLOAT,!1,0,0));else if(g.morphTargetBase){c=d.program.attributes;g.morphTargetBase!==-1?(e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphTargetsBuffers[g.morphTargetBase]),e.vertexAttribPointer(c.position,3,e.FLOAT,!1,0,0)):c.position>=0&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglVertexBuffer),e.vertexAttribPointer(c.position,3,e.FLOAT,!1,0,0));if(g.morphTargetForcedOrder.length){h=0;var j=g.morphTargetForcedOrder;for(i=g.morphTargetInfluences;hn&&(k=l,n=i[k]);e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphTargetsBuffers[k]);e.vertexAttribPointer(c["morphTarget"+h],3,e.FLOAT,!1,0,0);g.__webglMorphTargetInfluences[h]=n;j[k]= -1;n=-1;h++}}d.program.uniforms.morphTargetInfluences!==null&&e.uniform1fv(d.program.uniforms.morphTargetInfluences,g.__webglMorphTargetInfluences)}if(a){if(f.__webglCustomAttributesList){h=0;for(i=f.__webglCustomAttributesList.length;h=0&&(e.bindBuffer(e.ARRAY_BUFFER,c.buffer),e.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,e.FLOAT,!1,0,0))}b.color>=0&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglColorBuffer),e.vertexAttribPointer(b.color, -3,e.FLOAT,!1,0,0));b.normal>=0&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglNormalBuffer),e.vertexAttribPointer(b.normal,3,e.FLOAT,!1,0,0));b.tangent>=0&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglTangentBuffer),e.vertexAttribPointer(b.tangent,4,e.FLOAT,!1,0,0));b.uv>=0&&(f.__webglUVBuffer?(e.bindBuffer(e.ARRAY_BUFFER,f.__webglUVBuffer),e.vertexAttribPointer(b.uv,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(b.uv)):e.disableVertexAttribArray(b.uv));b.uv2>=0&&(f.__webglUV2Buffer?(e.bindBuffer(e.ARRAY_BUFFER,f.__webglUV2Buffer), -e.vertexAttribPointer(b.uv2,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(b.uv2)):e.disableVertexAttribArray(b.uv2));d.skinning&&b.skinVertexA>=0&&b.skinVertexB>=0&&b.skinIndex>=0&&b.skinWeight>=0&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinVertexABuffer),e.vertexAttribPointer(b.skinVertexA,4,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinVertexBBuffer),e.vertexAttribPointer(b.skinVertexB,4,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinIndicesBuffer),e.vertexAttribPointer(b.skinIndex, -4,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinWeightsBuffer),e.vertexAttribPointer(b.skinWeight,4,e.FLOAT,!1,0,0))}g instanceof THREE.Mesh?(d.wireframe?(d=d.wireframeLinewidth,d!==ta&&(e.lineWidth(d),ta=d),a&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.__webglLineBuffer),e.drawElements(e.LINES,f.__webglLineCount,e.UNSIGNED_SHORT,0)):(a&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.__webglFaceBuffer),e.drawElements(e.TRIANGLES,f.__webglFaceCount,e.UNSIGNED_SHORT,0)),I.info.render.calls++,I.info.render.vertices+= -f.__webglFaceCount,I.info.render.faces+=f.__webglFaceCount/3):g instanceof THREE.Line?(g=g.type===THREE.LineStrip?e.LINE_STRIP:e.LINES,d=d.linewidth,d!==ta&&(e.lineWidth(d),ta=d),e.drawArrays(g,0,f.__webglLineCount),I.info.render.calls++):g instanceof THREE.ParticleSystem?(e.drawArrays(e.POINTS,0,f.__webglParticleCount),I.info.render.calls++,I.info.render.points+=f.__webglParticleCount):g instanceof THREE.Ribbon&&(e.drawArrays(e.TRIANGLE_STRIP,0,f.__webglVertexCount),I.info.render.calls++)}};this.render= -function(a,b,c,d){var f,g,h,n,p=a.lights,s=a.fog;H=-1;this.autoUpdateObjects&&this.initWebGLObjects(a);b.parent===void 0&&(console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it..."),a.add(b));this.autoUpdateScene&&a.updateMatrixWorld();l(this.renderPluginsPre,a,b);I.info.render.calls=0;I.info.render.vertices=0;I.info.render.faces=0;I.info.render.points=0;b.matrixWorldInverse.getInverse(b.matrixWorld);if(!b._viewMatrixArray)b._viewMatrixArray=new Float32Array(16);b.matrixWorldInverse.flattenToArray(b._viewMatrixArray); -if(!b._projectionMatrixArray)b._projectionMatrixArray=new Float32Array(16);b.projectionMatrix.flattenToArray(b._projectionMatrixArray);Da.multiply(b.projectionMatrix,b.matrixWorldInverse);Ia.setFromMatrix(Da);this.setRenderTarget(c);(this.autoClear||d)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);n=a.__webglObjects;d=0;for(f=n.length;d=0)q=w.geometry.materials[q],q.transparent?(t.transparent=q,t.opaque=null):(t.opaque=q,t.transparent=null)}else if(q)q.transparent?(t.transparent=q,t.opaque=null):(t.opaque=q,t.transparent=null);g.render=!0;if(this.sortObjects)h.renderDepth?g.z=h.renderDepth:(Ba.copy(h.position),Da.multiplyVector3(Ba),g.z=Ba.z)}this.sortObjects&&n.sort(i);n=a.__webglObjectsImmediate; -d=0;for(f=n.length;d65535&&(q[D].counter+=1,m=q[D].hash+"_"+q[D].counter,F.geometryGroups[m]===void 0&&(F.geometryGroups[m]= -{faces3:[],faces4:[],materialIndex:C,vertices:0,numMorphTargets:J})),y instanceof THREE.Face3?F.geometryGroups[m].faces3.push(G):F.geometryGroups[m].faces4.push(G),F.geometryGroups[m].vertices+=t;F.geometryGroupsList=[];G=void 0;for(G in F.geometryGroups)F.geometryGroups[G].id=na++,F.geometryGroupsList.push(F.geometryGroups[G])}for(k in l.geometryGroups)if(F=l.geometryGroups[k],!F.__webglVertexBuffer){G=F;G.__webglVertexBuffer=e.createBuffer();G.__webglNormalBuffer=e.createBuffer();G.__webglTangentBuffer= -e.createBuffer();G.__webglColorBuffer=e.createBuffer();G.__webglUVBuffer=e.createBuffer();G.__webglUV2Buffer=e.createBuffer();G.__webglSkinVertexABuffer=e.createBuffer();G.__webglSkinVertexBBuffer=e.createBuffer();G.__webglSkinIndicesBuffer=e.createBuffer();G.__webglSkinWeightsBuffer=e.createBuffer();G.__webglFaceBuffer=e.createBuffer();G.__webglLineBuffer=e.createBuffer();if(G.numMorphTargets){y=v=void 0;G.__webglMorphTargetsBuffers=[];v=0;for(y=G.numMorphTargets;v0||t.faceVertexUvs.length>0)F.__uvArray=new Float32Array(G*2);if(t.faceUvs.length>1||t.faceVertexUvs.length>1)F.__uv2Array=new Float32Array(G*2)}if(C.geometry.skinWeights.length&& -C.geometry.skinIndices.length)F.__skinVertexAArray=new Float32Array(G*4),F.__skinVertexBArray=new Float32Array(G*4),F.__skinIndexArray=new Float32Array(G*4),F.__skinWeightArray=new Float32Array(G*4);F.__faceArray=new Uint16Array(y*3);F.__lineArray=new Uint16Array(D*2);if(F.numMorphTargets){F.__morphTargetsArrays=[];C=0;for(t=F.numMorphTargets;C0&&(e.bindBuffer(e.ARRAY_BUFFER,v.__webglSkinVertexABuffer),e.bufferData(e.ARRAY_BUFFER,W,y),e.bindBuffer(e.ARRAY_BUFFER, -v.__webglSkinVertexBBuffer),e.bufferData(e.ARRAY_BUFFER,X,y),e.bindBuffer(e.ARRAY_BUFFER,v.__webglSkinIndicesBuffer),e.bufferData(e.ARRAY_BUFFER,U,y),e.bindBuffer(e.ARRAY_BUFFER,v.__webglSkinWeightsBuffer),e.bufferData(e.ARRAY_BUFFER,ia,y))}if(xa&&D){m=0;for(q=M.length;m0&&(e.bindBuffer(e.ARRAY_BUFFER,v.__webglColorBuffer),e.bufferData(e.ARRAY_BUFFER,ea,y))}if(Q&&la.hasTangents){m=0;for(q=M.length;m0&&(e.bindBuffer(e.ARRAY_BUFFER,v.__webglUVBuffer),e.bufferData(e.ARRAY_BUFFER,Z,y))}if(ua&&sa&&O){m=0;for(q=M.length;m0&&(e.bindBuffer(e.ARRAY_BUFFER,v.__webglUV2Buffer),e.bufferData(e.ARRAY_BUFFER,r,y))}if(ra){m=0;for(q=M.length;m=0;d--)a[d].object===b&&a.splice(d,1)}function E(a,b){for(var d=a.length-1;d>=0;d--)a[d]===b&&a.splice(d,1)}function y(a,b,d,c,f){c.program|| +H.initMaterial(c,b,d,f);if(c.morphTargets&&!f.__webglMorphTargetInfluences){f.__webglMorphTargetInfluences=new Float32Array(H.maxMorphTargets);for(var g=0,h=H.maxMorphTargets;g0;this.getContext=function(){return e};this.supportsVertexTextures=function(){return Ma};this.setSize=function(a,b){ma.width=a;ma.height=b;this.setViewport(0,0,ma.width,ma.height)};this.setViewport= +function(a,b,c,d){Ea=a;Fa=b;Ga=c;Ha=d;e.viewport(Ea,Fa,Ga,Ha)};this.setScissor=function(a,b,c,d){e.scissor(a,b,c,d)};this.enableScissorTest=function(a){a?e.enable(e.SCISSOR_TEST):e.disable(e.SCISSOR_TEST)};this.setClearColorHex=function(a,b){ja.setHex(a);xa=b;e.clearColor(ja.r,ja.g,ja.b,xa)};this.setClearColor=function(a,b){ja.copy(a);xa=b;e.clearColor(ja.r,ja.g,ja.b,xa)};this.getClearColor=function(){return ja};this.getClearAlpha=function(){return xa};this.clear=function(a,b,c){var d=0;if(a===void 0|| +a)d|=e.COLOR_BUFFER_BIT;if(b===void 0||b)d|=e.DEPTH_BUFFER_BIT;if(c===void 0||c)d|=e.STENCIL_BUFFER_BIT;e.clear(d)};this.clearTarget=function(a,b,c,d){this.setRenderTarget(a);this.clear(b,c,d)};this.addPostPlugin=function(a){a.init(this);this.renderPluginsPost.push(a)};this.addPrePlugin=function(a){a.init(this);this.renderPluginsPre.push(a)};this.deallocateObject=function(a){if(a.__webglInit)if(a.__webglInit=!1,delete a._modelViewMatrix,delete a._normalMatrixArray,delete a._modelViewMatrixArray,delete a._objectMatrixArray, +a instanceof THREE.Mesh)for(var b in a.geometry.geometryGroups){var c=a.geometry.geometryGroups[b];e.deleteBuffer(c.__webglVertexBuffer);e.deleteBuffer(c.__webglNormalBuffer);e.deleteBuffer(c.__webglTangentBuffer);e.deleteBuffer(c.__webglColorBuffer);e.deleteBuffer(c.__webglUVBuffer);e.deleteBuffer(c.__webglUV2Buffer);e.deleteBuffer(c.__webglSkinVertexABuffer);e.deleteBuffer(c.__webglSkinVertexBBuffer);e.deleteBuffer(c.__webglSkinIndicesBuffer);e.deleteBuffer(c.__webglSkinWeightsBuffer);e.deleteBuffer(c.__webglFaceBuffer); +e.deleteBuffer(c.__webglLineBuffer);if(c.numMorphTargets)for(var d=0,f=c.numMorphTargets;d=0&&f.vertexNormalBuffer&&(e.bindBuffer(e.ARRAY_BUFFER,f.vertexNormalBuffer),e.vertexAttribPointer(a.normal,f.vertexNormalBuffer.itemSize,e.FLOAT,!1,0,d[g].index*12)),a.uv>=0&&f.vertexUvBuffer&& +(f.vertexUvBuffer?(e.bindBuffer(e.ARRAY_BUFFER,f.vertexUvBuffer),e.vertexAttribPointer(a.uv,f.vertexUvBuffer.itemSize,e.FLOAT,!1,0,d[g].index*8),e.enableVertexAttribArray(a.uv)):e.disableVertexAttribArray(a.uv)),a.color>=0&&f.vertexColorBuffer&&(e.bindBuffer(e.ARRAY_BUFFER,f.vertexColorBuffer),e.vertexAttribPointer(a.color,f.vertexColorBuffer.itemSize,e.FLOAT,!1,0,d[g].index*16)),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.vertexIndexBuffer)),e.drawElements(e.TRIANGLES,d[g].count,e.UNSIGNED_SHORT,d[g].start* +2),H.info.render.calls++,H.info.render.vertices+=d[g].count,H.info.render.faces+=d[g].count/3}};this.renderBuffer=function(a,b,c,d,f,g){if(d.opacity!==0){var h,i,c=y(a,b,c,d,g),b=c.attributes,a=!1,c=f.id*16777215+c.id*2+(d.wireframe?1:0);c!==R&&(R=c,a=!0);if(!d.morphTargets&&b.position>=0)a&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglVertexBuffer),e.vertexAttribPointer(b.position,3,e.FLOAT,!1,0,0));else if(g.morphTargetBase){c=d.program.attributes;g.morphTargetBase!==-1?(e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphTargetsBuffers[g.morphTargetBase]), +e.vertexAttribPointer(c.position,3,e.FLOAT,!1,0,0)):c.position>=0&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglVertexBuffer),e.vertexAttribPointer(c.position,3,e.FLOAT,!1,0,0));if(g.morphTargetForcedOrder.length){h=0;var j=g.morphTargetForcedOrder;for(i=g.morphTargetInfluences;hn&&(k=l,n=i[k]);e.bindBuffer(e.ARRAY_BUFFER,f.__webglMorphTargetsBuffers[k]);e.vertexAttribPointer(c["morphTarget"+h],3,e.FLOAT,!1,0,0);g.__webglMorphTargetInfluences[h]=n;j[k]=1;n=-1;h++}}d.program.uniforms.morphTargetInfluences!==null&&e.uniform1fv(d.program.uniforms.morphTargetInfluences,g.__webglMorphTargetInfluences)}if(a){if(f.__webglCustomAttributesList){h= +0;for(i=f.__webglCustomAttributesList.length;h=0&&(e.bindBuffer(e.ARRAY_BUFFER,c.buffer),e.vertexAttribPointer(b[c.buffer.belongsToAttribute],c.size,e.FLOAT,!1,0,0))}b.color>=0&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglColorBuffer),e.vertexAttribPointer(b.color,3,e.FLOAT,!1,0,0));b.normal>=0&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglNormalBuffer),e.vertexAttribPointer(b.normal,3,e.FLOAT,!1,0,0));b.tangent>=0&&(e.bindBuffer(e.ARRAY_BUFFER, +f.__webglTangentBuffer),e.vertexAttribPointer(b.tangent,4,e.FLOAT,!1,0,0));b.uv>=0&&(f.__webglUVBuffer?(e.bindBuffer(e.ARRAY_BUFFER,f.__webglUVBuffer),e.vertexAttribPointer(b.uv,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(b.uv)):e.disableVertexAttribArray(b.uv));b.uv2>=0&&(f.__webglUV2Buffer?(e.bindBuffer(e.ARRAY_BUFFER,f.__webglUV2Buffer),e.vertexAttribPointer(b.uv2,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(b.uv2)):e.disableVertexAttribArray(b.uv2));d.skinning&&b.skinVertexA>=0&&b.skinVertexB>= +0&&b.skinIndex>=0&&b.skinWeight>=0&&(e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinVertexABuffer),e.vertexAttribPointer(b.skinVertexA,4,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinVertexBBuffer),e.vertexAttribPointer(b.skinVertexB,4,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinIndicesBuffer),e.vertexAttribPointer(b.skinIndex,4,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,f.__webglSkinWeightsBuffer),e.vertexAttribPointer(b.skinWeight,4,e.FLOAT,!1,0,0))}g instanceof THREE.Mesh?(d.wireframe? +(d=d.wireframeLinewidth,d!==ta&&(e.lineWidth(d),ta=d),a&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.__webglLineBuffer),e.drawElements(e.LINES,f.__webglLineCount,e.UNSIGNED_SHORT,0)):(a&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,f.__webglFaceBuffer),e.drawElements(e.TRIANGLES,f.__webglFaceCount,e.UNSIGNED_SHORT,0)),H.info.render.calls++,H.info.render.vertices+=f.__webglFaceCount,H.info.render.faces+=f.__webglFaceCount/3):g instanceof THREE.Line?(g=g.type===THREE.LineStrip?e.LINE_STRIP:e.LINES,d=d.linewidth,d!== +ta&&(e.lineWidth(d),ta=d),e.drawArrays(g,0,f.__webglLineCount),H.info.render.calls++):g instanceof THREE.ParticleSystem?(e.drawArrays(e.POINTS,0,f.__webglParticleCount),H.info.render.calls++,H.info.render.points+=f.__webglParticleCount):g instanceof THREE.Ribbon&&(e.drawArrays(e.TRIANGLE_STRIP,0,f.__webglVertexCount),H.info.render.calls++)}};this.render=function(a,b,c,d){var f,g,h,n,p=a.lights,s=a.fog;I=-1;this.autoUpdateObjects&&this.initWebGLObjects(a);b.parent===void 0&&(console.warn("DEPRECATED: Camera hasn't been added to a Scene. Adding it..."), +a.add(b));this.autoUpdateScene&&a.updateMatrixWorld();l(this.renderPluginsPre,a,b);H.info.render.calls=0;H.info.render.vertices=0;H.info.render.faces=0;H.info.render.points=0;b.matrixWorldInverse.getInverse(b.matrixWorld);if(!b._viewMatrixArray)b._viewMatrixArray=new Float32Array(16);b.matrixWorldInverse.flattenToArray(b._viewMatrixArray);if(!b._projectionMatrixArray)b._projectionMatrixArray=new Float32Array(16);b.projectionMatrix.flattenToArray(b._projectionMatrixArray);Da.multiply(b.projectionMatrix, +b.matrixWorldInverse);Ia.setFromMatrix(Da);this.setRenderTarget(c);(this.autoClear||d)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);n=a.__webglObjects;d=0;for(f=n.length;d=0)q=w.geometry.materials[q],q.transparent?(t.transparent=q,t.opaque=null):(t.opaque=q,t.transparent=null)}else if(q)q.transparent?(t.transparent=q,t.opaque=null):(t.opaque=q,t.transparent=null);g.render=!0;if(this.sortObjects)h.renderDepth?g.z=h.renderDepth:(Ba.copy(h.position),Da.multiplyVector3(Ba),g.z=Ba.z)}this.sortObjects&&n.sort(i);n=a.__webglObjectsImmediate;d=0;for(f=n.length;d65535&&(q[D].counter+=1,m=q[D].hash+"_"+q[D].counter,F.geometryGroups[m]===void 0&&(F.geometryGroups[m]={faces3:[],faces4:[],materialIndex:C,vertices:0,numMorphTargets:J})),y instanceof THREE.Face3? +F.geometryGroups[m].faces3.push(G):F.geometryGroups[m].faces4.push(G),F.geometryGroups[m].vertices+=t;F.geometryGroupsList=[];G=void 0;for(G in F.geometryGroups)F.geometryGroups[G].id=na++,F.geometryGroupsList.push(F.geometryGroups[G])}for(k in l.geometryGroups)if(F=l.geometryGroups[k],!F.__webglVertexBuffer){G=F;G.__webglVertexBuffer=e.createBuffer();G.__webglNormalBuffer=e.createBuffer();G.__webglTangentBuffer=e.createBuffer();G.__webglColorBuffer=e.createBuffer();G.__webglUVBuffer=e.createBuffer(); +G.__webglUV2Buffer=e.createBuffer();G.__webglSkinVertexABuffer=e.createBuffer();G.__webglSkinVertexBBuffer=e.createBuffer();G.__webglSkinIndicesBuffer=e.createBuffer();G.__webglSkinWeightsBuffer=e.createBuffer();G.__webglFaceBuffer=e.createBuffer();G.__webglLineBuffer=e.createBuffer();if(G.numMorphTargets){y=v=void 0;G.__webglMorphTargetsBuffers=[];v=0;for(y=G.numMorphTargets;v0||t.faceVertexUvs.length>0)F.__uvArray=new Float32Array(G*2);if(t.faceUvs.length>1||t.faceVertexUvs.length>1)F.__uv2Array=new Float32Array(G*2)}if(C.geometry.skinWeights.length&&C.geometry.skinIndices.length)F.__skinVertexAArray= +new Float32Array(G*4),F.__skinVertexBArray=new Float32Array(G*4),F.__skinIndexArray=new Float32Array(G*4),F.__skinWeightArray=new Float32Array(G*4);F.__faceArray=new Uint16Array(y*3);F.__lineArray=new Uint16Array(D*2);if(F.numMorphTargets){F.__morphTargetsArrays=[];C=0;for(t=F.numMorphTargets;C0&&(e.bindBuffer(e.ARRAY_BUFFER,v.__webglSkinVertexABuffer),e.bufferData(e.ARRAY_BUFFER,W,y),e.bindBuffer(e.ARRAY_BUFFER,v.__webglSkinVertexBBuffer),e.bufferData(e.ARRAY_BUFFER,X,y),e.bindBuffer(e.ARRAY_BUFFER,v.__webglSkinIndicesBuffer),e.bufferData(e.ARRAY_BUFFER,U,y),e.bindBuffer(e.ARRAY_BUFFER,v.__webglSkinWeightsBuffer),e.bufferData(e.ARRAY_BUFFER,ia,y))}if(xa&&D){m=0;for(q=M.length;m0&&(e.bindBuffer(e.ARRAY_BUFFER,v.__webglColorBuffer), +e.bufferData(e.ARRAY_BUFFER,ea,y))}if(Q&&la.hasTangents){m=0;for(q=M.length;m0&&(e.bindBuffer(e.ARRAY_BUFFER,v.__webglUVBuffer),e.bufferData(e.ARRAY_BUFFER,Z,y))}if(ua&&sa&& +O){m=0;for(q=M.length;m0&&(e.bindBuffer(e.ARRAY_BUFFER,v.__webglUV2Buffer),e.bufferData(e.ARRAY_BUFFER,r,y))}if(ra){m=0;for(q=M.length;m=0&&e.enableVertexAttribArray(q.position);q.color>=0&&e.enableVertexAttribArray(q.color);q.normal>=0&&e.enableVertexAttribArray(q.normal); +k);d=["position","normal","uv","uv2","tangent","color","skinVertexA","skinVertexB","skinIndex","skinWeight"];for(s=0;s=0&&e.enableVertexAttribArray(q.position);q.color>=0&&e.enableVertexAttribArray(q.color);q.normal>=0&&e.enableVertexAttribArray(q.normal); q.tangent>=0&&e.enableVertexAttribArray(q.tangent);a.skinning&&q.skinVertexA>=0&&q.skinVertexB>=0&&q.skinIndex>=0&&q.skinWeight>=0&&(e.enableVertexAttribArray(q.skinVertexA),e.enableVertexAttribArray(q.skinVertexB),e.enableVertexAttribArray(q.skinIndex),e.enableVertexAttribArray(q.skinWeight));if(a.attributes)for(g in a.attributes)q[g]!==void 0&&q[g]>=0&&e.enableVertexAttribArray(q[g]);if(a.morphTargets)for(g=a.numSupportedMorphTargets=0;g=0&&(e.enableVertexAttribArray(q[s]), a.numSupportedMorphTargets++);a.uniformsList=[];for(f in a.uniforms)a.uniformsList.push([a.uniforms[f],f])};this.setFaceCulling=function(a,b){a?(!b||b==="ccw"?e.frontFace(e.CCW):e.frontFace(e.CW),a==="back"?e.cullFace(e.BACK):a==="front"?e.cullFace(e.FRONT):e.cullFace(e.FRONT_AND_BACK),e.enable(e.CULL_FACE)):e.disable(e.CULL_FACE)};this.setObjectFaces=function(a){if(ra!==a.doubleSided)a.doubleSided?e.disable(e.CULL_FACE):e.enable(e.CULL_FACE),ra=a.doubleSided;if(Z!==a.flipSided)a.flipSided?e.frontFace(e.CW): e.frontFace(e.CCW),Z=a.flipSided};this.setDepthTest=function(a){oa!==a&&(a?e.enable(e.DEPTH_TEST):e.disable(e.DEPTH_TEST),oa=a)};this.setBlending=function(a){if(a!==sa){switch(a){case THREE.AdditiveBlending:e.blendEquation(e.FUNC_ADD);e.blendFunc(e.SRC_ALPHA,e.ONE);break;case THREE.SubtractiveBlending:e.blendEquation(e.FUNC_ADD);e.blendFunc(e.ZERO,e.ONE_MINUS_SRC_COLOR);break;case THREE.MultiplyBlending:e.blendEquation(e.FUNC_ADD);e.blendFunc(e.ZERO,e.SRC_COLOR);break;default:e.blendEquationSeparate(e.FUNC_ADD, -e.FUNC_ADD),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}sa=a}};this.setTexture=function(a,b){if(a.needsUpdate){if(!a.__webglInit)a.__webglInit=!0,a.__webglTexture=e.createTexture(),I.info.memory.textures++;e.activeTexture(e.TEXTURE0+b);e.bindTexture(e.TEXTURE_2D,a.__webglTexture);var c=C(e.TEXTURE_2D,a,a.image);a instanceof THREE.DataTexture?e.texImage2D(e.TEXTURE_2D,0,O(a.format),a.image.width,a.image.height,0,O(a.format),e.UNSIGNED_BYTE,a.image.data):e.texImage2D(e.TEXTURE_2D, +e.FUNC_ADD),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}sa=a}};this.setTexture=function(a,b){if(a.needsUpdate){if(!a.__webglInit)a.__webglInit=!0,a.__webglTexture=e.createTexture(),H.info.memory.textures++;e.activeTexture(e.TEXTURE0+b);e.bindTexture(e.TEXTURE_2D,a.__webglTexture);var c=C(e.TEXTURE_2D,a,a.image);a instanceof THREE.DataTexture?e.texImage2D(e.TEXTURE_2D,0,O(a.format),a.image.width,a.image.height,0,O(a.format),e.UNSIGNED_BYTE,a.image.data):e.texImage2D(e.TEXTURE_2D, 0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,a.image);c&&e.generateMipmap(e.TEXTURE_2D);a.needsUpdate=!1;if(a.onUpdated)a.onUpdated()}else e.activeTexture(e.TEXTURE0+b),e.bindTexture(e.TEXTURE_2D,a.__webglTexture)};this.setRenderTarget=function(a){var b=a instanceof THREE.WebGLRenderTargetCube;if(a&&!a.__webglFramebuffer){if(a.depthBuffer===void 0)a.depthBuffer=!0;if(a.stencilBuffer===void 0)a.stencilBuffer=!0;a.__webglTexture=e.createTexture();if(b){a.__webglFramebuffer=[];a.__webglRenderbuffer=[];e.bindTexture(e.TEXTURE_CUBE_MAP, a.__webglTexture);C(e.TEXTURE_CUBE_MAP,a,a);for(var c=0;c<6;c++){a.__webglFramebuffer[c]=e.createFramebuffer();a.__webglRenderbuffer[c]=e.createRenderbuffer();e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+c,0,O(a.format),a.width,a.height,0,O(a.format),O(a.type),null);var d=a,f=e.TEXTURE_CUBE_MAP_POSITIVE_X+c;e.bindFramebuffer(e.FRAMEBUFFER,a.__webglFramebuffer[c]);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,f,d.__webglTexture,0);D(a.__webglRenderbuffer[c],a)}}else a.__webglFramebuffer=e.createFramebuffer(), a.__webglRenderbuffer=e.createRenderbuffer(),e.bindTexture(e.TEXTURE_2D,a.__webglTexture),C(e.TEXTURE_2D,a,a),e.texImage2D(e.TEXTURE_2D,0,O(a.format),a.width,a.height,0,O(a.format),O(a.type),null),c=e.TEXTURE_2D,e.bindFramebuffer(e.FRAMEBUFFER,a.__webglFramebuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,c,a.__webglTexture,0),D(a.__webglRenderbuffer,a);b?e.bindTexture(e.TEXTURE_CUBE_MAP,null):e.bindTexture(e.TEXTURE_2D,null);e.bindRenderbuffer(e.RENDERBUFFER,null);e.bindFramebuffer(e.FRAMEBUFFER, @@ -291,7 +295,9 @@ null)}a?(b=b?a.__webglFramebuffer[a.activeCubeFace]:a.__webglFramebuffer,c=a.wid THREE.WebGLRenderTarget=function(a,b,d){this.width=a;this.height=b;d=d||{};this.wrapS=d.wrapS!==void 0?d.wrapS:THREE.ClampToEdgeWrapping;this.wrapT=d.wrapT!==void 0?d.wrapT:THREE.ClampToEdgeWrapping;this.magFilter=d.magFilter!==void 0?d.magFilter:THREE.LinearFilter;this.minFilter=d.minFilter!==void 0?d.minFilter:THREE.LinearMipMapLinearFilter;this.offset=new THREE.Vector2(0,0);this.repeat=new THREE.Vector2(1,1);this.format=d.format!==void 0?d.format:THREE.RGBAFormat;this.type=d.type!==void 0?d.type: THREE.UnsignedByteType;this.depthBuffer=d.depthBuffer!==void 0?d.depthBuffer:!0;this.stencilBuffer=d.stencilBuffer!==void 0?d.stencilBuffer:!0}; THREE.WebGLRenderTarget.prototype.clone=function(){var a=new THREE.WebGLRenderTarget(this.width,this.height);a.wrapS=this.wrapS;a.wrapT=this.wrapT;a.magFilter=this.magFilter;a.minFilter=this.minFilter;a.offset.copy(this.offset);a.repeat.copy(this.repeat);a.format=this.format;a.type=this.type;a.depthBuffer=this.depthBuffer;a.stencilBuffer=this.stencilBuffer;return a};THREE.WebGLRenderTargetCube=function(a,b,d){THREE.WebGLRenderTarget.call(this,a,b,d);this.activeCubeFace=0}; -THREE.WebGLRenderTargetCube.prototype=new THREE.WebGLRenderTarget;THREE.WebGLRenderTargetCube.prototype.constructor=THREE.WebGLRenderTargetCube;THREE.LensFlare=function(a,b,d,c,f){THREE.Object3D.call(this);this.lensFlares=[];this.positionScreen=new THREE.Vector3;this.customUpdateCallback=void 0;a!==void 0&&this.add(a,b,d,c,f)};THREE.LensFlare.prototype=new THREE.Object3D;THREE.LensFlare.prototype.constructor=THREE.LensFlare;THREE.LensFlare.prototype.supr=THREE.Object3D.prototype; +THREE.WebGLRenderTargetCube.prototype=new THREE.WebGLRenderTarget;THREE.WebGLRenderTargetCube.prototype.constructor=THREE.WebGLRenderTargetCube; +THREE.BufferGeometry=function(){this.id=THREE.GeometryCount++;this.vertexColorArray=this.vertexUvArray=this.vertexNormalArray=this.vertexPositionArray=this.vertexIndexArray=this.vertexColorBuffer=this.vertexUvBuffer=this.vertexNormalBuffer=this.vertexPositionBuffer=this.vertexIndexBuffer=null;this.dynamic=!1;this.boundingSphere=this.boundingBox=null;this.morphTargets=[]};THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,computeBoundingBox:function(){},computeBoundingSphere:function(){}}; +THREE.LensFlare=function(a,b,d,c,f){THREE.Object3D.call(this);this.lensFlares=[];this.positionScreen=new THREE.Vector3;this.customUpdateCallback=void 0;a!==void 0&&this.add(a,b,d,c,f)};THREE.LensFlare.prototype=new THREE.Object3D;THREE.LensFlare.prototype.constructor=THREE.LensFlare;THREE.LensFlare.prototype.supr=THREE.Object3D.prototype; THREE.LensFlare.prototype.add=function(a,b,d,c,f,g){b===void 0&&(b=-1);d===void 0&&(d=0);g===void 0&&(g=1);f===void 0&&(f=new THREE.Color(16777215));if(c===void 0)c=THREE.BillboardBlending;d=Math.min(d,Math.max(0,d));this.lensFlares.push({texture:a,size:b,distance:d,x:0,y:0,z:0,scale:1,rotation:1,opacity:g,color:f,blending:c})}; THREE.LensFlare.prototype.updateLensFlares=function(){var a,b=this.lensFlares.length,d,c=-this.positionScreen.x*2,f=-this.positionScreen.y*2;for(a=0;a max ) max = idx; + + } + + if ( max - min > 65535 ) { + + i -= 3; + + for ( var k = start; k < i; ++ k ) { + + indices[ k ] -= minPrev; + + } + + scope.offsets.push( { start: start, count: i - start, index: minPrev } ); + + start = i; + min = file.body.vertices.length; + max = 0; + + } + + minPrev = min; + + } + + for ( var k = start; k < i; ++ k ) { + + indices[ k ] -= minPrev; + + } + + scope.offsets.push( { start: start, count: i - start, index: minPrev } ); + + + // indices + + scope.vertexIndexBuffer = gl.createBuffer(); + gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, scope.vertexIndexBuffer ); + gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, new Uint16Array( vertexIndexArray ), gl.STATIC_DRAW ); + + scope.vertexIndexBuffer.itemSize = 1; + scope.vertexIndexBuffer.numItems = vertexIndexArray.length; + + // vertices + + scope.vertexPositionBuffer = gl.createBuffer(); + gl.bindBuffer( gl.ARRAY_BUFFER, scope.vertexPositionBuffer ); + gl.bufferData( gl.ARRAY_BUFFER, vertexPositionArray, gl.STATIC_DRAW ); + + scope.vertexPositionBuffer.itemSize = 3; + scope.vertexPositionBuffer.numItems = vertexPositionArray.length; + + // normals + + if ( vertexNormalArray !== undefined ) { + + scope.vertexNormalBuffer = gl.createBuffer(); + gl.bindBuffer( gl.ARRAY_BUFFER, scope.vertexNormalBuffer ); + gl.bufferData( gl.ARRAY_BUFFER, vertexNormalArray, gl.STATIC_DRAW ); + + scope.vertexNormalBuffer.itemSize = 3; + scope.vertexNormalBuffer.numItems = vertexNormalArray.length; + + } + + // uvs + + if ( file.body.uvMaps !== undefined && file.body.uvMaps.length > 0 ) { + + vertexUvArray = file.body.uvMaps[ 0 ].uv; + + // "fix" flipping + + for ( var i = 0; i < vertexUvArray.length; i += 2 ) { + + vertexUvArray[ i + 1 ] = 1 - vertexUvArray[ i + 1 ]; + + } + + scope.vertexUvBuffer = gl.createBuffer(); + gl.bindBuffer( gl.ARRAY_BUFFER, scope.vertexUvBuffer ); + gl.bufferData( gl.ARRAY_BUFFER, vertexUvArray, gl.STATIC_DRAW ); + + scope.vertexUvBuffer.itemSize = 2; + scope.vertexUvBuffer.numItems = vertexUvArray.length; + + } + + // colors + + if ( file.body.attrMaps !== undefined && file.body.attrMaps.length > 0 && file.body.attrMaps[ 0 ].name === "Color" ) { + + vertexColorArray = file.body.attrMaps[ 0 ].attr; + + scope.vertexColorBuffer = gl.createBuffer(); + gl.bindBuffer( gl.ARRAY_BUFFER, scope.vertexColorBuffer ); + gl.bufferData( gl.ARRAY_BUFFER, vertexColorArray, gl.STATIC_DRAW ); + + scope.vertexColorBuffer.itemSize = 4; + scope.vertexColorBuffer.numItems = vertexColorArray.length; + + } + + // compute bounding sphere and bounding box + // (must do it now as we don't keep typed arrays after setting GL buffers) + + scope.boundingBox = { min: new THREE.Vector3( Infinity, Infinity, Infinity ), max: new THREE.Vector3( -Infinity, -Infinity, -Infinity ) }; + + var vertices = file.body.vertices, + bb = scope.boundingBox, + radius, maxRadius = 0, + x, y, z; + + for ( var i = 0, il = vertices.length; i < il; i += 3 ) { + + x = vertices[ i ]; + y = vertices[ i + 1 ]; + z = vertices[ i + 2 ]; + + // bounding sphere + + radius = Math.sqrt( x * x + y * y + z * z ); + if ( radius > maxRadius ) maxRadius = radius; + + // bounding box + + if ( x < bb.min.x ) { - var Model = function ( texture_path ) { + bb.min.x = x; + + } else if ( x > bb.max.x ) { + + bb.max.x = x; + + } + + if ( y < bb.min.y ) { + + bb.min.y = y; + + } else if ( y > bb.max.y ) { + + bb.max.y = y; + + } + + if ( z < bb.min.z ) { + + bb.min.z = z; + + } else if ( z > bb.max.z ) { + + bb.max.z = z; + + } + + } + + scope.boundingSphere = { radius: maxRadius }; + + // keep references to typed arrays + + if ( dynamic ) { + + scope.vertexIndexArray = vertexIndexArray; + scope.vertexPositionArray = vertexPositionArray; + scope.vertexNormalArray = vertexNormalArray; + scope.vertexUvArray = vertexUvArray; + scope.vertexColorArray = vertexColorArray; + + } + + } + + Model.prototype = new THREE.BufferGeometry(); + Model.prototype.constructor = Model; + + callback( new Model() ); + +}; + +THREE.CTMLoader.prototype.createModelClassic = function ( file, callback ) { + + var Model = function ( ) { var scope = this; @@ -217,11 +543,16 @@ THREE.CTMLoader.prototype.createModel = function ( file, callback ) { b = buffer[ i + 1 ]; c = buffer[ i + 2 ]; - if ( hasNormals ) + if ( hasNormals ){ + face = f3n( scope, normals, a, b, c, m, a, b, c ); - else + + } else { + face = f3( scope, a, b, c, m ); + } + if ( hasColors ) { face.vertexColors[ 0 ] = colors[ a ]; diff --git a/examples/webgl_loader_ctm.html b/examples/webgl_loader_ctm.html index 5b5d995dae..886a7a6136 100644 --- a/examples/webgl_loader_ctm.html +++ b/examples/webgl_loader_ctm.html @@ -141,9 +141,10 @@ } - var useWorker = true; + var useWorker = true + useBuffers = true; - var loader = new THREE.CTMLoader(); + var loader = new THREE.CTMLoader( renderer.context ); loader.load( "ctm/ben.ctm", function( geometry ) { @@ -151,7 +152,7 @@ callbackModel( geometry, 450, material, 0, -200, 0, 0, 0 ); checkTime(); - }, useWorker ); + }, useWorker, useBuffers ); loader.load( "ctm/WaltHead.ctm", function( geometry ) { @@ -161,7 +162,7 @@ callbackModel( geometry, 5, material, -200, 0, 0, 0, 0 ); checkTime(); - }, useWorker ); + }, useWorker, useBuffers ); loader.load( "ctm/LeePerry.ctm", function( geometry ) { @@ -169,7 +170,7 @@ callbackModel( geometry, 1300, material, 200, 50, 0, 0, 0 ); checkTime(); - }, useWorker ); + }, useWorker, useBuffers ); } diff --git a/src/core/Geometry.js b/src/core/Geometry.js index 393b00120b..385545b789 100644 --- a/src/core/Geometry.js +++ b/src/core/Geometry.js @@ -401,17 +401,16 @@ THREE.Geometry.prototype = { computeBoundingSphere: function () { - // var radius = this.boundingSphere === null ? 0 : this.boundingSphere.radius; - - var radius = 0; + var radius, maxRadius = 0; for ( var v = 0, vl = this.vertices.length; v < vl; v ++ ) { - radius = Math.max( radius, this.vertices[ v ].position.length() ); + radius = this.vertices[ v ].position.length(); + if ( radius > maxRadius ) maxRadius = radius; } - this.boundingSphere = { radius: radius }; + this.boundingSphere = { radius: maxRadius }; }, diff --git a/src/extras/core/BufferGeometry.js b/src/extras/core/BufferGeometry.js new file mode 100644 index 0000000000..2933afe324 --- /dev/null +++ b/src/extras/core/BufferGeometry.js @@ -0,0 +1,56 @@ +/** + * @author alteredq / http://alteredqualia.com/ + */ + +THREE.BufferGeometry = function () { + + this.id = THREE.GeometryCount ++; + + // GL buffers + + this.vertexIndexBuffer = null; + this.vertexPositionBuffer = null; + this.vertexNormalBuffer = null; + this.vertexUvBuffer = null; + this.vertexColorBuffer = null; + + // typed arrays (kept only if dynamic flag is set) + + this.vertexIndexArray = null; + this.vertexPositionArray = null; + this.vertexNormalArray = null; + this.vertexUvArray = null; + this.vertexColorArray = null; + + this.dynamic = false; + + // boundings + + this.boundingBox = null; + this.boundingSphere = null; + + // for compatibility + + this.morphTargets = []; + +}; + +THREE.BufferGeometry.prototype = { + + constructor : THREE.BufferGeometry, + + // for compatibility + + computeBoundingBox: function () { + + }, + + // for compatibility + + computeBoundingSphere: function () { + + } + + +}; + diff --git a/src/objects/Mesh.js b/src/objects/Mesh.js index 601c5c51b9..d4fea73a71 100644 --- a/src/objects/Mesh.js +++ b/src/objects/Mesh.js @@ -22,7 +22,7 @@ THREE.Mesh = function ( geometry, material ) { // calc bound radius - if( !this.geometry.boundingSphere ) { + if( ! this.geometry.boundingSphere ) { this.geometry.computeBoundingSphere(); diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 03fa0b2d2f..f07b719d7b 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -2703,6 +2703,98 @@ THREE.WebGLRenderer = function ( parameters ) { }; + this.renderBufferDirect = function ( camera, lights, fog, material, geometryGroup, object ) { + + if ( material.opacity === 0 ) return; + + var program, attributes, linewidth, primitives, a, attribute, i, il; + + program = setProgram( camera, lights, fog, material, object ); + + attributes = program.attributes; + + var updateBuffers = false, + wireframeBit = material.wireframe ? 1 : 0, + geometryGroupHash = ( geometryGroup.id * 0xffffff ) + ( program.id * 2 ) + wireframeBit; + + if ( geometryGroupHash !== _currentGeometryGroupHash ) { + + _currentGeometryGroupHash = geometryGroupHash; + updateBuffers = true; + + } + + // render mesh + + if ( object instanceof THREE.Mesh ) { + + var offsets = geometryGroup.offsets; + + for ( var i = 0; i < offsets.length; ++ i ) { + + if ( updateBuffers ) { + + // vertices + + _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexPositionBuffer ); + _gl.vertexAttribPointer( attributes.position, geometryGroup.vertexPositionBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 3 ); + + // normals + + if ( attributes.normal >= 0 && geometryGroup.vertexNormalBuffer ) { + + _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexNormalBuffer ); + _gl.vertexAttribPointer( attributes.normal, geometryGroup.vertexNormalBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 3 ); + + } + + // uvs + + if ( attributes.uv >= 0 && geometryGroup.vertexUvBuffer ) { + + if ( geometryGroup.vertexUvBuffer ) { + + _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexUvBuffer ); + _gl.vertexAttribPointer( attributes.uv, geometryGroup.vertexUvBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 2 ); + + _gl.enableVertexAttribArray( attributes.uv ); + + } else { + + _gl.disableVertexAttribArray( attributes.uv ); + + } + + } + + // colors + + if ( attributes.color >= 0 && geometryGroup.vertexColorBuffer ) { + + _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.vertexColorBuffer ); + _gl.vertexAttribPointer( attributes.color, geometryGroup.vertexColorBuffer.itemSize, _gl.FLOAT, false, 0, offsets[ i ].index * 4 * 4 ); + + + } + + _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.vertexIndexBuffer ); + + } + + // render indexed triangles + + _gl.drawElements( _gl.TRIANGLES, offsets[ i ].count, _gl.UNSIGNED_SHORT, offsets[ i ].start * 2 ); // 2 = Uint16 + + _this.info.render.calls ++; + _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared + _this.info.render.faces += offsets[ i ].count / 3; + + } + + } + + }; + this.renderBuffer = function ( camera, lights, fog, material, geometryGroup, object ) { if ( material.opacity === 0 ) return; @@ -3253,7 +3345,16 @@ THREE.WebGLRenderer = function ( parameters ) { } _this.setObjectFaces( object ); - _this.renderBuffer( camera, lights, fog, material, buffer, object ); + + if ( buffer instanceof THREE.BufferGeometry ) { + + _this.renderBufferDirect( camera, lights, fog, material, buffer, object ); + + } else { + + _this.renderBuffer( camera, lights, fog, material, buffer, object ); + + } } @@ -3524,32 +3625,36 @@ THREE.WebGLRenderer = function ( parameters ) { geometry = object.geometry; - if ( geometry.geometryGroups === undefined ) { + if ( geometry instanceof THREE.Geometry ) { - sortFacesByMaterial( geometry ); + if ( geometry.geometryGroups === undefined ) { - } + sortFacesByMaterial( geometry ); - // create separate VBOs per geometry chunk + } + + // create separate VBOs per geometry chunk - for ( g in geometry.geometryGroups ) { + for ( g in geometry.geometryGroups ) { - geometryGroup = geometry.geometryGroups[ g ]; + geometryGroup = geometry.geometryGroups[ g ]; - // initialise VBO on the first access + // initialise VBO on the first access - if ( ! geometryGroup.__webglVertexBuffer ) { + if ( ! geometryGroup.__webglVertexBuffer ) { - createMeshBuffers( geometryGroup ); - initMeshBuffers( geometryGroup, object ); + createMeshBuffers( geometryGroup ); + initMeshBuffers( geometryGroup, object ); - geometry.__dirtyVertices = true; - geometry.__dirtyMorphTargets = true; - geometry.__dirtyElements = true; - geometry.__dirtyUvs = true; - geometry.__dirtyNormals = true; - geometry.__dirtyTangents = true; - geometry.__dirtyColors = true; + geometry.__dirtyVertices = true; + geometry.__dirtyMorphTargets = true; + geometry.__dirtyElements = true; + geometry.__dirtyUvs = true; + geometry.__dirtyNormals = true; + geometry.__dirtyTangents = true; + geometry.__dirtyColors = true; + + } } @@ -3607,11 +3712,19 @@ THREE.WebGLRenderer = function ( parameters ) { geometry = object.geometry; - for ( g in geometry.geometryGroups ) { + if ( geometry instanceof THREE.BufferGeometry ) { + + addBuffer( scene.__webglObjects, geometry, object ); + + } else { + + for ( g in geometry.geometryGroups ) { + + geometryGroup = geometry.geometryGroups[ g ]; - geometryGroup = geometry.geometryGroups[ g ]; + addBuffer( scene.__webglObjects, geometryGroup, object ); - addBuffer( scene.__webglObjects, geometryGroup, object ); + } } @@ -3676,35 +3789,56 @@ THREE.WebGLRenderer = function ( parameters ) { if ( object instanceof THREE.Mesh ) { - // check all geometry groups + if ( geometry instanceof THREE.BufferGeometry ) { + + if ( geometry.__dirtyVertices || geometry.__dirtyElements || + geometry.__dirtyUvs || geometry.__dirtyNormals || + geometry.__dirtyColors ) { - for( var i = 0, il = geometry.geometryGroupsList.length; i < il; i ++ ) { + // TODO + // set buffers from typed arrays - geometryGroup = geometry.geometryGroupsList[ i ]; + } - material = getBufferMaterial( object, geometryGroup ); + geometry.__dirtyVertices = false; + geometry.__dirtyElements = false; + geometry.__dirtyUvs = false; + geometry.__dirtyNormals = false; + geometry.__dirtyColors = false; - customAttributesDirty = material.attributes && areCustomAttributesDirty( material ); + } else { - if ( geometry.__dirtyVertices || geometry.__dirtyMorphTargets || geometry.__dirtyElements || - geometry.__dirtyUvs || geometry.__dirtyNormals || - geometry.__dirtyColors || geometry.__dirtyTangents || customAttributesDirty ) { + // check all geometry groups - setMeshBuffers( geometryGroup, object, _gl.DYNAMIC_DRAW, !geometry.dynamic, material ); + for( var i = 0, il = geometry.geometryGroupsList.length; i < il; i ++ ) { + + geometryGroup = geometry.geometryGroupsList[ i ]; + + material = getBufferMaterial( object, geometryGroup ); + + customAttributesDirty = material.attributes && areCustomAttributesDirty( material ); + + if ( geometry.__dirtyVertices || geometry.__dirtyMorphTargets || geometry.__dirtyElements || + geometry.__dirtyUvs || geometry.__dirtyNormals || + geometry.__dirtyColors || geometry.__dirtyTangents || customAttributesDirty ) { + + setMeshBuffers( geometryGroup, object, _gl.DYNAMIC_DRAW, !geometry.dynamic, material ); + + } } - } + geometry.__dirtyVertices = false; + geometry.__dirtyMorphTargets = false; + geometry.__dirtyElements = false; + geometry.__dirtyUvs = false; + geometry.__dirtyNormals = false; + geometry.__dirtyColors = false; + geometry.__dirtyTangents = false; - geometry.__dirtyVertices = false; - geometry.__dirtyMorphTargets = false; - geometry.__dirtyElements = false; - geometry.__dirtyUvs = false; - geometry.__dirtyNormals = false; - geometry.__dirtyColors = false; - geometry.__dirtyTangents = false; + material.attributes && clearCustomAttributes( material ); - material.attributes && clearCustomAttributes( material ); + } } else if ( object instanceof THREE.Ribbon ) { diff --git a/utils/build.py b/utils/build.py index 67b68b92c4..8c5526d884 100644 --- a/utils/build.py +++ b/utils/build.py @@ -91,6 +91,7 @@ EXTRAS_FILES = [ 'extras/ImageUtils.js', 'extras/SceneUtils.js', 'extras/ShaderUtils.js', +'extras/core/BufferGeometry.js', 'extras/core/Curve.js', 'extras/core/CurvePath.js', 'extras/core/Path.js', @@ -335,6 +336,7 @@ WEBGL_FILES = [ 'renderers/WebGLRenderer.js', 'renderers/WebGLRenderTarget.js', 'renderers/WebGLRenderTargetCube.js', +'extras/core/BufferGeometry.js', 'extras/objects/LensFlare.js', 'extras/plugins/LensFlarePlugin.js', 'extras/plugins/ShadowMapPlugin.js', @@ -425,7 +427,7 @@ def buildLib(files, debug, minified, filename): def buildIncludes(files, filename): - template = '\t\t' + template = '\t\t' text = "\n".join(template % f for f in files) output(text, filename + '.js') -- GitLab