From 0c1851393d20e5441d33a268029aac71933a27e9 Mon Sep 17 00:00:00 2001 From: alteredq Date: Sun, 12 Dec 2010 16:52:50 +0100 Subject: [PATCH] Added check for normals in shader when rendering VBOs. --- build/Three.js | 2 +- build/ThreeDebug.js | 2 +- build/ThreeExtras.js | 102 ++++++++++++++++----------------- src/renderers/WebGLRenderer.js | 8 ++- 4 files changed, 59 insertions(+), 55 deletions(-) diff --git a/build/Three.js b/build/Three.js index 1b346cd066..8f7635bf2c 100755 --- a/build/Three.js +++ b/build/Three.js @@ -166,7 +166,7 @@ f.program}else z=x;if(z!=A){c.useProgram(z);A=z}z==x&&this.setupLights(z,k);this 6?d(Q,H):e(Q,H)}}}if(f instanceof THREE.MeshPhongMaterial||f instanceof THREE.MeshLambertMaterial||f instanceof THREE.MeshBasicMaterial){j=f.color;i=f.opacity;u=f.wireframe;s=f.wireframe_linewidth;G=f.map;y=f.env_map;k=f.combine==THREE.MixOperation;g=f.reflectivity;Q=f.env_map&&f.env_map.mapping instanceof THREE.CubeRefractionMapping;H=f.refraction_ratio;c.uniform4f(z.uniforms.mColor,j.r*i,j.g*i,j.b*i,i);c.uniform1i(z.uniforms.mixEnvMap,k);c.uniform1f(z.uniforms.mReflectivity,g);c.uniform1i(z.uniforms.useRefract, Q);c.uniform1f(z.uniforms.mRefractionRatio,H)}if(f instanceof THREE.MeshNormalMaterial){i=f.opacity;c.uniform1f(z.uniforms.mOpacity,i);c.uniform1i(z.uniforms.material,4)}else if(f instanceof THREE.MeshDepthMaterial){i=f.opacity;u=f.wireframe;s=f.wireframe_linewidth;c.uniform1f(z.uniforms.mOpacity,i);c.uniform1f(z.uniforms.m2Near,f.__2near);c.uniform1f(z.uniforms.mFarPlusNear,f.__farPlusNear);c.uniform1f(z.uniforms.mFarMinusNear,f.__farMinusNear);c.uniform1i(z.uniforms.material,3)}else if(f instanceof THREE.MeshPhongMaterial){j=f.ambient;g=f.specular;f=f.shininess;c.uniform4f(z.uniforms.mAmbient,j.r,j.g,j.b,i);c.uniform4f(z.uniforms.mSpecular,g.r,g.g,g.b,i);c.uniform1f(z.uniforms.mShininess,f);c.uniform1i(z.uniforms.material,2)}else if(f instanceof THREE.MeshLambertMaterial)c.uniform1i(z.uniforms.material,1);else if(f instanceof THREE.MeshBasicMaterial)c.uniform1i(z.uniforms.material,0);else if(f instanceof THREE.MeshCubeMaterial){c.uniform1i(z.uniforms.material,5);y=f.env_map}if(G){e(G,0);c.uniform1i(z.uniforms.tMap, -0);c.uniform1i(z.uniforms.enableMap,1)}else c.uniform1i(z.uniforms.enableMap,0);if(y){d(y,1);c.uniform1i(z.uniforms.tCube,1);c.uniform1i(z.uniforms.enableCubeMap,1)}else c.uniform1i(z.uniforms.enableCubeMap,0);i=z.attributes;c.bindBuffer(c.ARRAY_BUFFER,p.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,p.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0);if(i.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLTangentBuffer); +0);c.uniform1i(z.uniforms.enableMap,1)}else c.uniform1i(z.uniforms.enableMap,0);if(y){d(y,1);c.uniform1i(z.uniforms.tCube,1);c.uniform1i(z.uniforms.enableCubeMap,1)}else c.uniform1i(z.uniforms.enableCubeMap,0);i=z.attributes;c.bindBuffer(c.ARRAY_BUFFER,p.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);if(i.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0)}if(i.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLTangentBuffer); c.vertexAttribPointer(i.tangent,4,c.FLOAT,false,0,0)}if(i.uv>=0)if(p.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(u){c.lineWidth(s);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLLineBuffer);c.drawElements(c.LINES,p.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,p.__webGLFaceCount,c.UNSIGNED_SHORT, 0)}};this.renderPass=function(g,k,f,p,j,i){var u,s,G,y,H;G=0;for(y=f.material.length;G=0){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLTangentBuffer); +0);c.uniform1i(A.uniforms.enableMap,1)}else c.uniform1i(A.uniforms.enableMap,0);if(z){d(z,1);c.uniform1i(A.uniforms.tCube,1);c.uniform1i(A.uniforms.enableCubeMap,1)}else c.uniform1i(A.uniforms.enableCubeMap,0);i=A.attributes;c.bindBuffer(c.ARRAY_BUFFER,p.__webGLVertexBuffer);c.vertexAttribPointer(i.position,3,c.FLOAT,false,0,0);if(i.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLNormalBuffer);c.vertexAttribPointer(i.normal,3,c.FLOAT,false,0,0)}if(i.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLTangentBuffer); c.vertexAttribPointer(i.tangent,4,c.FLOAT,false,0,0)}if(i.uv>=0)if(p.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,p.__webGLUVBuffer);c.enableVertexAttribArray(i.uv);c.vertexAttribPointer(i.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(i.uv);if(u){c.lineWidth(t);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLLineBuffer);c.drawElements(c.LINES,p.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,p.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,p.__webGLFaceCount,c.UNSIGNED_SHORT, 0)}};this.renderPass=function(g,l,f,p,j,i){var u,t,G,z,H;G=0;for(z=f.material.length;G0){this.bbox={x:[this.vertices[0].position.x,this.vertices[0].position.x], +g=E.vertices[G].position;j=f[0];c=f[1];t=f[2];x=l.x-k.x;q=g.x-k.x;s=l.y-k.y;v=g.y-k.y;z=l.z-k.z;K=g.z-k.z;F=c.u-j.u;y=t.u-j.u;o=c.v-j.v;i=t.v-j.v;p=1/(F*i-y*o);m.set((i*x-o*q)*p,(i*s-o*v)*p,(i*z-o*K)*p);D.set((F*q-y*x)*p,(F*v-y*s)*p,(F*K-y*z)*p);w[O].addSelf(m);w[S].addSelf(m);w[G].addSelf(m);n[O].addSelf(D);n[S].addSelf(D);n[G].addSelf(D)}var b,d,e,f,k,l,g,j,c,t,x,q,s,v,z,K,F,y,o,i,p,h,w=[],n=[],m=new THREE.Vector3,D=new THREE.Vector3,A=new THREE.Vector3,L=new THREE.Vector3;h=new THREE.Vector3;b= +0;for(d=this.vertices.length;b0){this.bbox={x:[this.vertices[0].position.x,this.vertices[0].position.x], y:[this.vertices[0].position.y,this.vertices[0].position.y],z:[this.vertices[0].position.z,this.vertices[0].position.z]};for(var a=1,b=this.vertices.length;athis.bbox.x[1])this.bbox.x[1]=vertex.position.x;if(vertex.position.ythis.bbox.y[1])this.bbox.y[1]=vertex.position.y;if(vertex.position.zthis.bbox.z[1])this.bbox.z[1]=vertex.position.z}}},sortFacesByMaterial:function(){function a(t){var x=[];b=0;for(d=t.length;b65535){c[g].counter+=1;j=c[g].hash+"_"+c[g].counter;if(this.geometryChunks[j]==undefined)this.geometryChunks[j]={faces:[],material:l,vertices:0}}this.geometryChunks[j].faces.push(e);this.geometryChunks[j].vertices+=k}},toString:function(){return"THREE.Geometry ( vertices: "+this.vertices+", faces: "+this.faces+", uvs: "+this.uvs+" )"}}; @@ -90,19 +90,19 @@ THREE.Texture=function(a,b,d,e,f,k){this.image=a;this.mapping=b!==undefined?b:ne this.min_filter+"
)"}};THREE.MultiplyOperation=0;THREE.MixOperation=1;THREE.RepeatWrapping=0;THREE.ClampToEdgeWrapping=1;THREE.MirroredRepeatWrapping=2;THREE.NearestFilter=3;THREE.NearestMipMapNearestFilter=4;THREE.NearestMipMapLinearFilter=5;THREE.LinearFilter=6;THREE.LinearMipMapNearestFilter=7;THREE.LinearMipMapLinearFilter=8;THREE.CubeReflectionMapping=function(){};THREE.CubeRefractionMapping=function(){};THREE.LatitudeReflectionMapping=function(){};THREE.LatitudeRefractionMapping=function(){}; THREE.SphericalReflectionMapping=function(){};THREE.SphericalRefractionMapping=function(){};THREE.UVMapping=function(){}; THREE.Scene=function(){this.objects=[];this.lights=[];this.addObject=function(a){this.objects.push(a)};this.removeObject=function(a){a=this.objects.indexOf(a);a!==-1&&this.objects.splice(a,1)};this.addLight=function(a){this.lights.push(a)};this.removeLight=function(a){a=this.lights.indexOf(a);a!==-1&&this.lights.splice(a,1)};this.toString=function(){return"THREE.Scene ( "+this.objects+" )"}}; -THREE.Projector=function(){function a(y,o){var i=0,p=1,h=y.z+y.w,w=o.z+o.w,m=-y.z+y.w,n=-o.z+o.w;if(h>=0&&w>=0&&m>=0&&n>=0)return true;else if(h<0&&w<0||m<0&&n<0)return false;else{if(h<0)i=Math.max(i,h/(h-w));else if(w<0)p=Math.min(p,h/(h-w));if(m<0)i=Math.max(i,m/(m-n));else if(n<0)p=Math.min(p,m/(m-n));if(p0&&N.z<1}T=A.geometry.faces;h=0;for(w=T.length;h=0&&w>=0&&n>=0&&m>=0)return true;else if(h<0&&w<0||n<0&&m<0)return false;else{if(h<0)i=Math.max(i,h/(h-w));else if(w<0)p=Math.min(p,h/(h-w));if(n<0)i=Math.max(i,n/(n-m));else if(m<0)p=Math.min(p,n/(n-m));if(p0&&N.z<1}T=A.geometry.faces;h=0;for(w=T.length;h0&&q.z<1){c=x[t]=x[t]||new THREE.RenderableParticle;c.x=q.x/q.w;c.y=q.y/q.w;c.z=q.z;c.rotation=A.rotation.z;c.scale.x=A.scale.x*Math.abs(c.x-(q.x+o.projectionMatrix.n11)/(q.w+o.projectionMatrix.n14));c.scale.y=A.scale.y*Math.abs(c.y-(q.y+o.projectionMatrix.n22)/(q.w+o.projectionMatrix.n24));c.material=A.material;b.push(c);t++}}}b.sort(function(Q,H){return H.z-Q.z});return b};this.unprojectVector=function(y,o){var i=new THREE.Matrix4; i.multiply(THREE.Matrix4.makeInvert(o.matrix),THREE.Matrix4.makeInvert(o.projectionMatrix));i.multiplyVector3(y);return y}}; THREE.DOMRenderer=function(){THREE.Renderer.call(this);var a=null,b=new THREE.Projector,d,e,f,k;this.domElement=document.createElement("div");this.setSize=function(l,g){d=l;e=g;f=d/2;k=e/2};this.render=function(l,g){var j,c,t,x,q,s,v,z;a=b.projectScene(l,g);j=0;for(c=a.length;j0){I.r+=ba.r*Z;I.g+=ba.g*Z;I.b+=ba.b*Z}}else if(Z instanceof THREE.PointLight){Y.sub(Z.position,W);Y.normalize();Z=R.dot(Y)*ca;if(Z>0){I.r+=ba.r*Z;I.g+=ba.g*Z;I.b+=ba.b*Z}}}}function La(C,W,R){if(R.opacity!=0){Ca(R.opacity);ya(R.blending);var I,P,Z,ba,ca,da;if(R instanceof THREE.ParticleBasicMaterial){if(R.map){ba=R.map;ca=ba.width>>1;da=ba.height>>1;P=W.scale.x*k;Z=W.scale.y*l;R=P*ca;I=Z*da;J.set(C.x-R,C.y-I,C.x+R,C.y+I);if(Q.instersects(J)){g.save();g.translate(C.x,C.y); @@ -110,22 +110,22 @@ g.rotate(-W.rotation);g.scale(P,-Z);g.translate(-ca,-da);g.drawImage(ba,0,0);g.r g.beginPath();g.arc(0,0,1,0,X,true);g.closePath();g.fill();g.restore()}}}}function Ma(C,W,R,I){if(I.opacity!=0){Ca(I.opacity);ya(I.blending);g.beginPath();g.moveTo(C.positionScreen.x,C.positionScreen.y);g.lineTo(W.positionScreen.x,W.positionScreen.y);g.closePath();if(I instanceof THREE.LineBasicMaterial){h.__styleString=I.color.__styleString;C=I.linewidth;if(q!=C)g.lineWidth=q=C;C=h.__styleString;if(t!=C)g.strokeStyle=t=C;g.stroke();J.inflate(I.linewidth*2)}}}function Ga(C,W,R,I,P,Z){if(P.opacity!= 0){Ca(P.opacity);ya(P.blending);K=C.positionScreen.x;F=C.positionScreen.y;y=W.positionScreen.x;o=W.positionScreen.y;i=R.positionScreen.x;p=R.positionScreen.y;g.beginPath();g.moveTo(K,F);g.lineTo(y,o);g.lineTo(i,p);g.lineTo(K,F);g.closePath();if(P instanceof THREE.MeshBasicMaterial)if(P.map)P.map.image.loaded&&P.map.mapping instanceof THREE.UVMapping&&sa(K,F,y,o,i,p,P.map.image,I.uvs[0].u,I.uvs[0].v,I.uvs[1].u,I.uvs[1].v,I.uvs[2].u,I.uvs[2].v);else if(P.env_map){if(P.env_map.image.loaded)if(P.env_map.mapping instanceof THREE.SphericalReflectionMapping){C=wa.matrix;Y.copy(I.vertexNormalsWorld[0]);S=(Y.x*C.n11+Y.y*C.n12+Y.z*C.n13)*0.5+0.5;G=-(Y.x*C.n21+Y.y*C.n22+Y.z*C.n23)*0.5+0.5;Y.copy(I.vertexNormalsWorld[1]);T=(Y.x*C.n11+Y.y*C.n12+Y.z*C.n13)*0.5+0.5;N=-(Y.x*C.n21+Y.y*C.n22+Y.z*C.n23)*0.5+0.5;Y.copy(I.vertexNormalsWorld[2]);U=(Y.x*C.n11+Y.y*C.n12+Y.z*C.n13)*0.5+0.5;V=-(Y.x*C.n21+Y.y*C.n22+Y.z*C.n23)*0.5+0.5;sa(K,F,y,o,i,p,P.env_map.image,S,G,T,N,U,V)}}else P.wireframe?za(P.color.__styleString,P.wireframe_linewidth): -Aa(P.color.__styleString);else if(P instanceof THREE.MeshLambertMaterial){if(P.map&&!P.wireframe){P.map.mapping instanceof THREE.UVMapping&&sa(K,F,y,o,i,p,P.map.image,I.uvs[0].u,I.uvs[0].v,I.uvs[1].u,I.uvs[1].v,I.uvs[2].u,I.uvs[2].v);ya(THREE.SubtractiveBlending)}if($)if(!P.wireframe&&P.shading==THREE.SmoothShading&&I.vertexNormalsWorld.length==3){w.r=m.r=n.r=u.r;w.g=m.g=n.g=u.g;w.b=m.b=n.b=u.b;xa(Z,I.v1.positionWorld,I.vertexNormalsWorld[0],w);xa(Z,I.v2.positionWorld,I.vertexNormalsWorld[1],m);xa(Z, -I.v3.positionWorld,I.vertexNormalsWorld[2],n);D.r=(m.r+n.r)*0.5;D.g=(m.g+n.g)*0.5;D.b=(m.b+n.b)*0.5;O=Ha(w,m,n,D);sa(K,F,y,o,i,p,O,0,0,1,0,0,1)}else{r.r=u.r;r.g=u.g;r.b=u.b;xa(Z,I.centroidWorld,I.normalWorld,r);h.r=P.color.r*r.r;h.g=P.color.g*r.g;h.b=P.color.b*r.b;h.updateStyleString();P.wireframe?za(h.__styleString,P.wireframe_linewidth):Aa(h.__styleString)}else P.wireframe?za(P.color.__styleString,P.wireframe_linewidth):Aa(P.color.__styleString)}else if(P instanceof THREE.MeshDepthMaterial){A=P.__2near; -L=P.__farPlusNear;E=P.__farMinusNear;w.r=w.g=w.b=1-A/(L-C.positionScreen.z*E);m.r=m.g=m.b=1-A/(L-W.positionScreen.z*E);n.r=n.g=n.b=1-A/(L-R.positionScreen.z*E);D.r=(m.r+n.r)*0.5;D.g=(m.g+n.g)*0.5;D.b=(m.b+n.b)*0.5;O=Ha(w,m,n,D);sa(K,F,y,o,i,p,O,0,0,1,0,0,1)}else if(P instanceof THREE.MeshNormalMaterial){h.r=Da(I.normalWorld.x);h.g=Da(I.normalWorld.y);h.b=Da(I.normalWorld.z);h.updateStyleString();P.wireframe?za(h.__styleString,P.wireframe_linewidth):Aa(h.__styleString)}}}function za(C,W){if(t!=C)g.strokeStyle= +Aa(P.color.__styleString);else if(P instanceof THREE.MeshLambertMaterial){if(P.map&&!P.wireframe){P.map.mapping instanceof THREE.UVMapping&&sa(K,F,y,o,i,p,P.map.image,I.uvs[0].u,I.uvs[0].v,I.uvs[1].u,I.uvs[1].v,I.uvs[2].u,I.uvs[2].v);ya(THREE.SubtractiveBlending)}if($)if(!P.wireframe&&P.shading==THREE.SmoothShading&&I.vertexNormalsWorld.length==3){w.r=n.r=m.r=u.r;w.g=n.g=m.g=u.g;w.b=n.b=m.b=u.b;xa(Z,I.v1.positionWorld,I.vertexNormalsWorld[0],w);xa(Z,I.v2.positionWorld,I.vertexNormalsWorld[1],n);xa(Z, +I.v3.positionWorld,I.vertexNormalsWorld[2],m);D.r=(n.r+m.r)*0.5;D.g=(n.g+m.g)*0.5;D.b=(n.b+m.b)*0.5;O=Ha(w,n,m,D);sa(K,F,y,o,i,p,O,0,0,1,0,0,1)}else{r.r=u.r;r.g=u.g;r.b=u.b;xa(Z,I.centroidWorld,I.normalWorld,r);h.r=P.color.r*r.r;h.g=P.color.g*r.g;h.b=P.color.b*r.b;h.updateStyleString();P.wireframe?za(h.__styleString,P.wireframe_linewidth):Aa(h.__styleString)}else P.wireframe?za(P.color.__styleString,P.wireframe_linewidth):Aa(P.color.__styleString)}else if(P instanceof THREE.MeshDepthMaterial){A=P.__2near; +L=P.__farPlusNear;E=P.__farMinusNear;w.r=w.g=w.b=1-A/(L-C.positionScreen.z*E);n.r=n.g=n.b=1-A/(L-W.positionScreen.z*E);m.r=m.g=m.b=1-A/(L-R.positionScreen.z*E);D.r=(n.r+m.r)*0.5;D.g=(n.g+m.g)*0.5;D.b=(n.b+m.b)*0.5;O=Ha(w,n,m,D);sa(K,F,y,o,i,p,O,0,0,1,0,0,1)}else if(P instanceof THREE.MeshNormalMaterial){h.r=Da(I.normalWorld.x);h.g=Da(I.normalWorld.y);h.b=Da(I.normalWorld.z);h.updateStyleString();P.wireframe?za(h.__styleString,P.wireframe_linewidth):Aa(h.__styleString)}}}function za(C,W){if(t!=C)g.strokeStyle= t=C;if(q!=W)g.lineWidth=q=W;g.stroke();J.inflate(W*2)}function Aa(C){if(x!=C)g.fillStyle=x=C;g.fill()}function sa(C,W,R,I,P,Z,ba,ca,da,ja,ga,ka,ta){var na,la;na=ba.width-1;la=ba.height-1;ca*=na;da*=la;ja*=na;ga*=la;ka*=na;ta*=la;R-=C;I-=W;P-=C;Z-=W;ja-=ca;ga-=da;ka-=ca;ta-=da;la=1/(ja*ta-ka*ga);na=(ta*R-ga*P)*la;ga=(ta*I-ga*Z)*la;R=(ja*P-ka*R)*la;I=(ja*Z-ka*I)*la;C=C-na*ca-R*da;W=W-ga*ca-I*da;g.save();g.transform(na,ga,R,I,C,W);g.clip();g.drawImage(ba,0,0);g.restore()}function Ca(C){if(j!=C)g.globalAlpha= j=C}function ya(C){if(c!=C){switch(C){case THREE.NormalBlending:g.globalCompositeOperation="source-over";break;case THREE.AdditiveBlending:g.globalCompositeOperation="lighter";break;case THREE.SubtractiveBlending:g.globalCompositeOperation="darker"}c=C}}function Ha(C,W,R,I){var P=~~(C.r*255),Z=~~(C.g*255);C=~~(C.b*255);var ba=~~(W.r*255),ca=~~(W.g*255);W=~~(W.b*255);var da=~~(R.r*255),ja=~~(R.g*255);R=~~(R.b*255);var ga=~~(I.r*255),ka=~~(I.g*255);I=~~(I.b*255);fa[0]=P<0?0:P>255?255:P;fa[1]=Z<0?0: Z>255?255:Z;fa[2]=C<0?0:C>255?255:C;fa[4]=ba<0?0:ba>255?255:ba;fa[5]=ca<0?0:ca>255?255:ca;fa[6]=W<0?0:W>255?255:W;fa[8]=da<0?0:da>255?255:da;fa[9]=ja<0?0:ja>255?255:ja;fa[10]=R<0?0:R>255?255:R;fa[12]=ga<0?0:ga>255?255:ga;fa[13]=ka<0?0:ka>255?255:ka;fa[14]=I<0?0:I>255?255:I;ma.putImageData(oa,0,0);va.drawImage(ea,0,0);return ra}function Da(C){C=(C+1)*0.5;return C<0?0:C>1?1:C}function Ea(C,W){var R=W.x-C.x,I=W.y-C.y,P=1/Math.sqrt(R*R+I*I);R*=P;I*=P;W.x+=R;W.y+=I;C.x-=R;C.y-=I}var Ba,Ia,aa,ha,qa,Fa, Ja,ua;g.setTransform(1,0,0,-1,k,l);this.autoClear&&this.clear();a=b.projectScene(ia,wa);($=ia.lights.length>0)&&Ka(ia);Ba=0;for(Ia=a.length;Ba0){V.r+=J.color.r*$;V.g+=J.color.g*$;V.b+=J.color.b*$}}else if(J instanceof THREE.PointLight){n.sub(J.position,U.centroidWorld);n.normalize();$=U.normalWorld.dot(n)*J.intensity;if($>0){V.r+=J.color.r*$;V.g+=J.color.g*$;V.b+=J.color.b*$}}}}function b(N,U,V,Q,H,J){E=e(O++);E.setAttribute("d","M "+N.positionScreen.x+ -" "+N.positionScreen.y+" L "+U.positionScreen.x+" "+U.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(H instanceof THREE.MeshBasicMaterial)o.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshLambertMaterial)if(y){i.r=p.r;i.g=p.g;i.b=p.b;a(J,Q,i);o.r=H.color.r*i.r;o.g=H.color.g*i.g;o.b=H.color.b*i.b;o.updateStyleString()}else o.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshDepthMaterial){m=1-H.__2near/(H.__farPlusNear-Q.z*H.__farMinusNear); -o.setRGB(m,m,m)}else H instanceof THREE.MeshNormalMaterial&&o.setRGB(f(Q.normalWorld.x),f(Q.normalWorld.y),f(Q.normalWorld.z));H.wireframe?E.setAttribute("style","fill: none; stroke: "+o.__styleString+"; stroke-width: "+H.wireframe_linewidth+"; stroke-opacity: "+H.opacity+"; stroke-linecap: "+H.wireframe_linecap+"; stroke-linejoin: "+H.wireframe_linejoin):E.setAttribute("style","fill: "+o.__styleString+"; fill-opacity: "+H.opacity);g.appendChild(E)}function d(N,U,V,Q,H,J,$){E=e(O++);E.setAttribute("d", -"M "+N.positionScreen.x+" "+N.positionScreen.y+" L "+U.positionScreen.x+" "+U.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+"z");if(J instanceof THREE.MeshBasicMaterial)o.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshLambertMaterial)if(y){i.r=p.r;i.g=p.g;i.b=p.b;a($,H,i);o.r=J.color.r*i.r;o.g=J.color.g*i.g;o.b=J.color.b*i.b;o.updateStyleString()}else o.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshDepthMaterial){m= -1-J.__2near/(J.__farPlusNear-H.z*J.__farMinusNear);o.setRGB(m,m,m)}else J instanceof THREE.MeshNormalMaterial&&o.setRGB(f(H.normalWorld.x),f(H.normalWorld.y),f(H.normalWorld.z));J.wireframe?E.setAttribute("style","fill: none; stroke: "+o.__styleString+"; stroke-width: "+J.wireframe_linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.wireframe_linecap+"; stroke-linejoin: "+J.wireframe_linejoin):E.setAttribute("style","fill: "+o.__styleString+"; fill-opacity: "+J.opacity);g.appendChild(E)} +THREE.SVGRenderer=function(){function a(N,U,V){var Q,H,J,$;Q=0;for(H=N.lights.length;Q0){V.r+=J.color.r*$;V.g+=J.color.g*$;V.b+=J.color.b*$}}else if(J instanceof THREE.PointLight){m.sub(J.position,U.centroidWorld);m.normalize();$=U.normalWorld.dot(m)*J.intensity;if($>0){V.r+=J.color.r*$;V.g+=J.color.g*$;V.b+=J.color.b*$}}}}function b(N,U,V,Q,H,J){E=e(O++);E.setAttribute("d","M "+N.positionScreen.x+ +" "+N.positionScreen.y+" L "+U.positionScreen.x+" "+U.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+"z");if(H instanceof THREE.MeshBasicMaterial)o.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshLambertMaterial)if(y){i.r=p.r;i.g=p.g;i.b=p.b;a(J,Q,i);o.r=H.color.r*i.r;o.g=H.color.g*i.g;o.b=H.color.b*i.b;o.updateStyleString()}else o.__styleString=H.color.__styleString;else if(H instanceof THREE.MeshDepthMaterial){n=1-H.__2near/(H.__farPlusNear-Q.z*H.__farMinusNear); +o.setRGB(n,n,n)}else H instanceof THREE.MeshNormalMaterial&&o.setRGB(f(Q.normalWorld.x),f(Q.normalWorld.y),f(Q.normalWorld.z));H.wireframe?E.setAttribute("style","fill: none; stroke: "+o.__styleString+"; stroke-width: "+H.wireframe_linewidth+"; stroke-opacity: "+H.opacity+"; stroke-linecap: "+H.wireframe_linecap+"; stroke-linejoin: "+H.wireframe_linejoin):E.setAttribute("style","fill: "+o.__styleString+"; fill-opacity: "+H.opacity);g.appendChild(E)}function d(N,U,V,Q,H,J,$){E=e(O++);E.setAttribute("d", +"M "+N.positionScreen.x+" "+N.positionScreen.y+" L "+U.positionScreen.x+" "+U.positionScreen.y+" L "+V.positionScreen.x+","+V.positionScreen.y+" L "+Q.positionScreen.x+","+Q.positionScreen.y+"z");if(J instanceof THREE.MeshBasicMaterial)o.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshLambertMaterial)if(y){i.r=p.r;i.g=p.g;i.b=p.b;a($,H,i);o.r=J.color.r*i.r;o.g=J.color.g*i.g;o.b=J.color.b*i.b;o.updateStyleString()}else o.__styleString=J.color.__styleString;else if(J instanceof THREE.MeshDepthMaterial){n= +1-J.__2near/(J.__farPlusNear-H.z*J.__farMinusNear);o.setRGB(n,n,n)}else J instanceof THREE.MeshNormalMaterial&&o.setRGB(f(H.normalWorld.x),f(H.normalWorld.y),f(H.normalWorld.z));J.wireframe?E.setAttribute("style","fill: none; stroke: "+o.__styleString+"; stroke-width: "+J.wireframe_linewidth+"; stroke-opacity: "+J.opacity+"; stroke-linecap: "+J.wireframe_linecap+"; stroke-linejoin: "+J.wireframe_linejoin):E.setAttribute("style","fill: "+o.__styleString+"; fill-opacity: "+J.opacity);g.appendChild(E)} function e(N){if(D[N]==null){D[N]=document.createElementNS("http://www.w3.org/2000/svg","path");T==0&&D[N].setAttribute("shape-rendering","crispEdges");return D[N]}return D[N]}function f(N){return N<0?Math.min((1+N)*0.5,0.5):0.5+Math.min(N*0.5,0.5)}var k=null,l=new THREE.Projector,g=document.createElementNS("http://www.w3.org/2000/svg","svg"),j,c,t,x,q,s,v,z,K=new THREE.Rectangle,F=new THREE.Rectangle,y=false,o=new THREE.Color(16777215),i=new THREE.Color(16777215),p=new THREE.Color(0),h=new THREE.Color(0), -w=new THREE.Color(0),m,n=new THREE.Vector3,D=[],A=[],L=[],E,O,S,G,T=1;this.domElement=g;this.autoClear=true;this.setQuality=function(N){switch(N){case "high":T=1;break;case "low":T=0}};this.setSize=function(N,U){j=N;c=U;t=j/2;x=c/2;g.setAttribute("viewBox",-t+" "+-x+" "+j+" "+c);g.setAttribute("width",j);g.setAttribute("height",c);K.set(-t,-x,t,x)};this.clear=function(){for(;g.childNodes.length>0;)g.removeChild(g.childNodes[0])};this.render=function(N,U){var V,Q,H,J,$,r,u,B;this.autoClear&&this.clear(); +w=new THREE.Color(0),n,m=new THREE.Vector3,D=[],A=[],L=[],E,O,S,G,T=1;this.domElement=g;this.autoClear=true;this.setQuality=function(N){switch(N){case "high":T=1;break;case "low":T=0}};this.setSize=function(N,U){j=N;c=U;t=j/2;x=c/2;g.setAttribute("viewBox",-t+" "+-x+" "+j+" "+c);g.setAttribute("width",j);g.setAttribute("height",c);K.set(-t,-x,t,x)};this.clear=function(){for(;g.childNodes.length>0;)g.removeChild(g.childNodes[0])};this.render=function(N,U){var V,Q,H,J,$,r,u,B;this.autoClear&&this.clear(); k=l.projectScene(N,U);G=S=O=0;if(y=N.lights.length>0){u=N.lights;p.setRGB(0,0,0);h.setRGB(0,0,0);w.setRGB(0,0,0);V=0;for(Q=u.length;V=0&&c.enableVertexAttribArray(i.attributes[m])}}function l(i,p){var h;if(i=="fragment")h=c.createShader(c.FRAGMENT_SHADER);else if(i=="vertex")h=c.createShader(c.VERTEX_SHADER); +c.bindTexture(c.TEXTURE_2D,null)}c.activeTexture(c.TEXTURE0+p);c.bindTexture(c.TEXTURE_2D,i.__webGLTexture)}function f(i,p){var h,w,n;h=0;for(w=p.length;h=0&&c.enableVertexAttribArray(i.attributes[n])}}function l(i,p){var h;if(i=="fragment")h=c.createShader(c.FRAGMENT_SHADER);else if(i=="vertex")h=c.createShader(c.VERTEX_SHADER); c.shaderSource(h,p);c.compileShader(h);if(!c.getShaderParameter(h,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(h));return null}return h}function g(i){switch(i){case THREE.RepeatWrapping:return c.REPEAT;case THREE.ClampToEdgeWrapping:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeatWrapping:return c.MIRRORED_REPEAT;case THREE.NearestFilter:return c.NEAREST;case THREE.NearestMipMapNearestFilter:return c.NEAREST_MIPMAP_NEAREST;case THREE.NearestMipMapLinearFilter:return c.NEAREST_MIPMAP_LINEAR;case THREE.LinearFilter:return c.LINEAR; -case THREE.LinearMipMapNearestFilter:return c.LINEAR_MIPMAP_NEAREST;case THREE.LinearMipMapLinearFilter:return c.LINEAR_MIPMAP_LINEAR}return 0}var j=document.createElement("canvas"),c,t,x,q=new THREE.Matrix4,s,v=new Float32Array(16),z=new Float32Array(16),K=new Float32Array(16),F=new Float32Array(9),y=new Float32Array(16);a=function(i,p){if(i){var h,w,m,n=pointLights=maxDirLights=maxPointLights=0;h=0;for(w=i.lights.length;h= 0.0 )":"",i?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",i?"dirDiffuse += mColor * dirDiffuseWeight;":"",i?"dirSpecular += mSpecular * dirSpecularWeight;":"",i?"}":"","vec4 totalLight = mAmbient;",i?"totalLight += dirDiffuse + dirSpecular;":"",p?"totalLight += pointDiffuse + pointSpecular;": "","if ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mapColor.rgb * totalLight.xyz * vLightWeighting, cubeColor.rgb, mReflectivity ), mapColor.a );\n} else {\ngl_FragColor = vec4( mapColor.rgb * cubeColor.rgb * totalLight.xyz * vLightWeighting, mapColor.a );\n}\n} else if ( material == 1 ) {\nif ( mixEnvMap ) {\ngl_FragColor = vec4( mix( mColor.rgb * mapColor.rgb * vLightWeighting, cubeColor.rgb, mReflectivity ), mColor.a * mapColor.a );\n} else {\ngl_FragColor = vec4( mColor.rgb * mapColor.rgb * cubeColor.rgb * vLightWeighting, mColor.a * mapColor.a );\n}\n} else {\nif ( mixEnvMap ) {\ngl_FragColor = mix( mColor * mapColor, cubeColor, mReflectivity );\n} else {\ngl_FragColor = mColor * mapColor * cubeColor;\n}\n}\n}"].join("\n"); h=b(w,h);c.useProgram(h);f(h,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);i&&f(h,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);p&&f(h,["pointLightNumber","pointLightColor", -"pointLightPosition"]);c.uniform1i(h.uniforms.enableMap,0);c.uniform1i(h.uniforms.tMap,0);c.uniform1i(h.uniforms.enableCubeMap,0);c.uniform1i(h.uniforms.tCube,1);c.uniform1i(h.uniforms.mixEnvMap,0);c.uniform1i(h.uniforms.useRefract,0);k(h,["position","normal","uv"]);return h}(a.directional,a.point);this.setSize=function(i,p){j.width=i;j.height=p;c.viewport(0,0,j.width,j.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(i,p){var h,w,m,n,D,A=[], -L=[],E=[];n=[];D=[];c.uniform1i(i.uniforms.enableLighting,p.length);h=0;for(w=p.length;h0){H.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,H.__webGLUVBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(V),c.STATIC_DRAW)}H.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,H.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(S),c.STATIC_DRAW);H.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER, -H.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);H.__webGLFaceCount=S.length;H.__webGLLineCount=G.length}};this.renderBuffer=function(i,p,h,w){var m,n,D,A,L,E,O,S,G;if(h instanceof THREE.MeshShaderMaterial){if(!h.program){h.program=b(h.fragment_shader,h.vertex_shader);O=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(G in h.uniforms)O.push(G);f(h.program,O);k(h.program,["position","normal","uv","tangent"])}G= -h.program}else G=x;if(G!=t){c.useProgram(G);t=G}G==x&&this.setupLights(G,p);this.loadCamera(G,i);this.loadMatrices(G);if(h instanceof THREE.MeshShaderMaterial){D=h.wireframe;A=h.wireframe_linewidth;i=G;p=h.uniforms;var T;for(m in p){S=p[m].type;O=p[m].value;T=i.uniforms[m];if(S=="i")c.uniform1i(T,O);else if(S=="f")c.uniform1f(T,O);else if(S=="v3")c.uniform3f(T,O.x,O.y,O.z);else if(S=="c")c.uniform3f(T,O.r,O.g,O.b);else if(S=="t"){c.uniform1i(T,O);if(S=p[m].texture)S.image instanceof Array&&S.image.length== -6?d(S,O):e(S,O)}}}if(h instanceof THREE.MeshPhongMaterial||h instanceof THREE.MeshLambertMaterial||h instanceof THREE.MeshBasicMaterial){m=h.color;n=h.opacity;D=h.wireframe;A=h.wireframe_linewidth;L=h.map;E=h.env_map;p=h.combine==THREE.MixOperation;i=h.reflectivity;S=h.env_map&&h.env_map.mapping instanceof THREE.CubeRefractionMapping;O=h.refraction_ratio;c.uniform4f(G.uniforms.mColor,m.r*n,m.g*n,m.b*n,n);c.uniform1i(G.uniforms.mixEnvMap,p);c.uniform1f(G.uniforms.mReflectivity,i);c.uniform1i(G.uniforms.useRefract, -S);c.uniform1f(G.uniforms.mRefractionRatio,O)}if(h instanceof THREE.MeshNormalMaterial){n=h.opacity;c.uniform1f(G.uniforms.mOpacity,n);c.uniform1i(G.uniforms.material,4)}else if(h instanceof THREE.MeshDepthMaterial){n=h.opacity;D=h.wireframe;A=h.wireframe_linewidth;c.uniform1f(G.uniforms.mOpacity,n);c.uniform1f(G.uniforms.m2Near,h.__2near);c.uniform1f(G.uniforms.mFarPlusNear,h.__farPlusNear);c.uniform1f(G.uniforms.mFarMinusNear,h.__farMinusNear);c.uniform1i(G.uniforms.material,3)}else if(h instanceof -THREE.MeshPhongMaterial){m=h.ambient;i=h.specular;h=h.shininess;c.uniform4f(G.uniforms.mAmbient,m.r,m.g,m.b,n);c.uniform4f(G.uniforms.mSpecular,i.r,i.g,i.b,n);c.uniform1f(G.uniforms.mShininess,h);c.uniform1i(G.uniforms.material,2)}else if(h instanceof THREE.MeshLambertMaterial)c.uniform1i(G.uniforms.material,1);else if(h instanceof THREE.MeshBasicMaterial)c.uniform1i(G.uniforms.material,0);else if(h instanceof THREE.MeshCubeMaterial){c.uniform1i(G.uniforms.material,5);E=h.env_map}if(L){e(L,0);c.uniform1i(G.uniforms.tMap, -0);c.uniform1i(G.uniforms.enableMap,1)}else c.uniform1i(G.uniforms.enableMap,0);if(E){d(E,1);c.uniform1i(G.uniforms.tCube,1);c.uniform1i(G.uniforms.enableCubeMap,1)}else c.uniform1i(G.uniforms.enableCubeMap,0);n=G.attributes;c.bindBuffer(c.ARRAY_BUFFER,w.__webGLVertexBuffer);c.vertexAttribPointer(n.position,3,c.FLOAT,false,0,0);c.bindBuffer(c.ARRAY_BUFFER,w.__webGLNormalBuffer);c.vertexAttribPointer(n.normal,3,c.FLOAT,false,0,0);if(n.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,w.__webGLTangentBuffer); -c.vertexAttribPointer(n.tangent,4,c.FLOAT,false,0,0)}if(n.uv>=0)if(w.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,w.__webGLUVBuffer);c.enableVertexAttribArray(n.uv);c.vertexAttribPointer(n.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(n.uv);if(D){c.lineWidth(A);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,w.__webGLLineBuffer);c.drawElements(c.LINES,w.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,w.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,w.__webGLFaceCount,c.UNSIGNED_SHORT, -0)}};this.renderPass=function(i,p,h,w,m,n){var D,A,L,E,O;L=0;for(E=h.material.length;L=0;h--){w=i.__webGLObjects[h].object;p==w&&i.__webGLObjects.splice(h,1)}};this.setupMatrices=function(i,p){i.autoUpdateMatrix&&i.updateMatrix();q.multiply(p.matrix,i.matrix);v.set(p.matrix.flatten());z.set(q.flatten());K.set(p.projectionMatrix.flatten());s=THREE.Matrix4.makeInvert3x3(q).transpose();F.set(s.m);y.set(i.matrix.flatten())};this.loadMatrices= +H.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);H.__webGLFaceCount=S.length;H.__webGLLineCount=G.length}};this.renderBuffer=function(i,p,h,w){var n,m,D,A,L,E,O,S,G;if(h instanceof THREE.MeshShaderMaterial){if(!h.program){h.program=b(h.fragment_shader,h.vertex_shader);O=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(G in h.uniforms)O.push(G);f(h.program,O);k(h.program,["position","normal","uv","tangent"])}G= +h.program}else G=x;if(G!=t){c.useProgram(G);t=G}G==x&&this.setupLights(G,p);this.loadCamera(G,i);this.loadMatrices(G);if(h instanceof THREE.MeshShaderMaterial){D=h.wireframe;A=h.wireframe_linewidth;i=G;p=h.uniforms;var T;for(n in p){S=p[n].type;O=p[n].value;T=i.uniforms[n];if(S=="i")c.uniform1i(T,O);else if(S=="f")c.uniform1f(T,O);else if(S=="v3")c.uniform3f(T,O.x,O.y,O.z);else if(S=="c")c.uniform3f(T,O.r,O.g,O.b);else if(S=="t"){c.uniform1i(T,O);if(S=p[n].texture)S.image instanceof Array&&S.image.length== +6?d(S,O):e(S,O)}}}if(h instanceof THREE.MeshPhongMaterial||h instanceof THREE.MeshLambertMaterial||h instanceof THREE.MeshBasicMaterial){n=h.color;m=h.opacity;D=h.wireframe;A=h.wireframe_linewidth;L=h.map;E=h.env_map;p=h.combine==THREE.MixOperation;i=h.reflectivity;S=h.env_map&&h.env_map.mapping instanceof THREE.CubeRefractionMapping;O=h.refraction_ratio;c.uniform4f(G.uniforms.mColor,n.r*m,n.g*m,n.b*m,m);c.uniform1i(G.uniforms.mixEnvMap,p);c.uniform1f(G.uniforms.mReflectivity,i);c.uniform1i(G.uniforms.useRefract, +S);c.uniform1f(G.uniforms.mRefractionRatio,O)}if(h instanceof THREE.MeshNormalMaterial){m=h.opacity;c.uniform1f(G.uniforms.mOpacity,m);c.uniform1i(G.uniforms.material,4)}else if(h instanceof THREE.MeshDepthMaterial){m=h.opacity;D=h.wireframe;A=h.wireframe_linewidth;c.uniform1f(G.uniforms.mOpacity,m);c.uniform1f(G.uniforms.m2Near,h.__2near);c.uniform1f(G.uniforms.mFarPlusNear,h.__farPlusNear);c.uniform1f(G.uniforms.mFarMinusNear,h.__farMinusNear);c.uniform1i(G.uniforms.material,3)}else if(h instanceof +THREE.MeshPhongMaterial){n=h.ambient;i=h.specular;h=h.shininess;c.uniform4f(G.uniforms.mAmbient,n.r,n.g,n.b,m);c.uniform4f(G.uniforms.mSpecular,i.r,i.g,i.b,m);c.uniform1f(G.uniforms.mShininess,h);c.uniform1i(G.uniforms.material,2)}else if(h instanceof THREE.MeshLambertMaterial)c.uniform1i(G.uniforms.material,1);else if(h instanceof THREE.MeshBasicMaterial)c.uniform1i(G.uniforms.material,0);else if(h instanceof THREE.MeshCubeMaterial){c.uniform1i(G.uniforms.material,5);E=h.env_map}if(L){e(L,0);c.uniform1i(G.uniforms.tMap, +0);c.uniform1i(G.uniforms.enableMap,1)}else c.uniform1i(G.uniforms.enableMap,0);if(E){d(E,1);c.uniform1i(G.uniforms.tCube,1);c.uniform1i(G.uniforms.enableCubeMap,1)}else c.uniform1i(G.uniforms.enableCubeMap,0);m=G.attributes;c.bindBuffer(c.ARRAY_BUFFER,w.__webGLVertexBuffer);c.vertexAttribPointer(m.position,3,c.FLOAT,false,0,0);if(m.normal>=0){c.bindBuffer(c.ARRAY_BUFFER,w.__webGLNormalBuffer);c.vertexAttribPointer(m.normal,3,c.FLOAT,false,0,0)}if(m.tangent>=0){c.bindBuffer(c.ARRAY_BUFFER,w.__webGLTangentBuffer); +c.vertexAttribPointer(m.tangent,4,c.FLOAT,false,0,0)}if(m.uv>=0)if(w.__webGLUVBuffer){c.bindBuffer(c.ARRAY_BUFFER,w.__webGLUVBuffer);c.enableVertexAttribArray(m.uv);c.vertexAttribPointer(m.uv,2,c.FLOAT,false,0,0)}else c.disableVertexAttribArray(m.uv);if(D){c.lineWidth(A);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,w.__webGLLineBuffer);c.drawElements(c.LINES,w.__webGLLineCount,c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,w.__webGLFaceBuffer);c.drawElements(c.TRIANGLES,w.__webGLFaceCount,c.UNSIGNED_SHORT, +0)}};this.renderPass=function(i,p,h,w,n,m){var D,A,L,E,O;L=0;for(E=h.material.length;L=0;h--){w=i.__webGLObjects[h].object;p==w&&i.__webGLObjects.splice(h,1)}};this.setupMatrices=function(i,p){i.autoUpdateMatrix&&i.updateMatrix();q.multiply(p.matrix,i.matrix);v.set(p.matrix.flatten());z.set(q.flatten());K.set(p.projectionMatrix.flatten());s=THREE.Matrix4.makeInvert3x3(q).transpose();F.set(s.m);y.set(i.matrix.flatten())};this.loadMatrices= function(i){c.uniformMatrix4fv(i.uniforms.viewMatrix,false,v);c.uniformMatrix4fv(i.uniforms.modelViewMatrix,false,z);c.uniformMatrix4fv(i.uniforms.projectionMatrix,false,K);c.uniformMatrix3fv(i.uniforms.normalMatrix,false,F);c.uniformMatrix4fv(i.uniforms.objectMatrix,false,y)};this.loadCamera=function(i,p){c.uniform3f(i.uniforms.cameraPosition,p.position.x,p.position.y,p.position.z)};this.setBlending=function(i){switch(i){case THREE.AdditiveBlending:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE); break;case THREE.SubtractiveBlending:c.blendFunc(c.DST_COLOR,c.ZERO);break;default:c.blendEquation(c.FUNC_ADD);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA)}};this.setFaceCulling=function(i,p){if(i){!p||p=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(i=="back")c.cullFace(c.BACK);else i=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)};this.supportsVertexTextures=function(){return c.getParameter(c.MAX_VERTEX_TEXTURE_IMAGE_UNITS)>0}}; THREE.RenderableFace3=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.v3=new THREE.Vertex;this.centroidWorld=new THREE.Vector3;this.centroidScreen=new THREE.Vector3;this.normalWorld=new THREE.Vector3;this.vertexNormalsWorld=[];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};THREE.RenderableParticle=function(){this.rotation=this.z=this.y=this.x=null;this.scale=new THREE.Vector2;this.material=null}; @@ -186,8 +186,8 @@ vertex_shader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuni normal:{uniforms:{tNormal:{type:"t",value:2,texture:null},tAO:{type:"t",value:3,texture:null},tDisplacement:{type:"t",value:4,texture:null},uDisplacementBias:{type:"f",value:-0.5},uDisplacementScale:{type:"f",value:2.5},uPointLightPos:{type:"v3",value:new THREE.Vector3},uPointLightColor:{type:"c",value:new THREE.Color(15658734)},uDirLightPos:{type:"v3",value:new THREE.Vector3},uDirLightColor:{type:"c",value:new THREE.Color(15658734)},uAmbientLightColor:{type:"c",value:new THREE.Color(328965)},uDiffuseColor:{type:"c", value:new THREE.Color(15658734)},uSpecularColor:{type:"c",value:new THREE.Color(1118481)},uAmbientColor:{type:"c",value:new THREE.Color(328965)},uShininess:{type:"f",value:30}},fragment_shader:"uniform vec3 uDirLightPos;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightPos;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientColor;\nuniform vec3 uDiffuseColor;\nuniform vec3 uSpecularColor;\nuniform float uShininess;\nuniform sampler2D tNormal;\nuniform sampler2D tAO;\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec3 normalTex = normalize( texture2D( tNormal, vUv ).xyz * 2.0 - 1.0 );\nvec3 aoTex = texture2D( tAO, vUv ).xyz;\nmat3 tsb = mat3( vTangent, vBinormal, vNormal );\nvec3 finalNormal = tsb * normalTex;\nvec3 normal = normalize( finalNormal );\nvec3 viewPosition = normalize( vViewPosition );\nvec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 pointSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec3 pointVector = normalize( vPointLightVector );\nvec3 pointHalfVector = normalize( vPointLightVector + vViewPosition );\nfloat pointDotNormalHalf = dot( normal, pointHalfVector );\nfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );\nfloat pointSpecularWeight = 0.0;\nif ( pointDotNormalHalf >= 0.0 )\npointSpecularWeight = pow( pointDotNormalHalf, uShininess );\npointDiffuse += vec4( uDiffuseColor, 1.0 ) * pointDiffuseWeight;\npointSpecular += vec4( uSpecularColor, 1.0 ) * pointSpecularWeight;\nvec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nvec3 dirVector = normalize( lDirection.xyz );\nvec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );\nfloat dirDotNormalHalf = dot( normal, dirHalfVector );\nfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );\nfloat dirSpecularWeight = 0.0;\nif ( dirDotNormalHalf >= 0.0 )\ndirSpecularWeight = pow( dirDotNormalHalf, uShininess );\ndirDiffuse += vec4( uDiffuseColor, 1.0 ) * dirDiffuseWeight;\ndirSpecular += vec4( uSpecularColor, 1.0 ) * dirSpecularWeight;\nvec4 totalLight = vec4( uAmbientColor, 1.0 );\ntotalLight += dirDiffuse + dirSpecular;\ntotalLight += pointDiffuse + pointSpecular;\ngl_FragColor = vec4( totalLight.xyz * vLightWeighting * aoTex, 1.0 );\n}", vertex_shader:"attribute vec4 tangent;\nuniform vec3 uDirLightPos;\nuniform vec3 uDirLightColor;\nuniform vec3 uPointLightPos;\nuniform vec3 uPointLightColor;\nuniform vec3 uAmbientLightColor;\n#ifdef VERTEX_TEXTURES\nuniform sampler2D tDisplacement;\nuniform float uDisplacementScale;\nuniform float uDisplacementBias;\n#endif\nvarying vec3 vTangent;\nvarying vec3 vBinormal;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;\nvarying vec3 vPointLightVector;\nvarying vec3 vViewPosition;\nvoid main() {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvNormal = normalize( normalMatrix * normal );\nvTangent = normalize( normalMatrix * tangent.xyz );\nvBinormal = cross( vNormal, vTangent ) * tangent.w;\nvBinormal = normalize( vBinormal );\nvUv = uv;\nvLightWeighting = uAmbientLightColor;\nvec4 lPosition = viewMatrix * vec4( uPointLightPos, 1.0 );\nvPointLightVector = normalize( lPosition.xyz - mvPosition.xyz );\nfloat pointLightWeighting = max( dot( vNormal, vPointLightVector ), 0.0 );\nvLightWeighting += uPointLightColor * pointLightWeighting;\nvec4 lDirection = viewMatrix * vec4( uDirLightPos, 0.0 );\nfloat directionalLightWeighting = max( dot( vNormal, normalize( lDirection.xyz ) ), 0.0 );\nvLightWeighting += uDirLightColor * directionalLightWeighting;\n#ifdef VERTEX_TEXTURES\nvec3 dv = texture2D( tDisplacement, uv ).xyz;\nfloat df = uDisplacementScale * dv.x + uDisplacementBias;\nvec4 displacedPosition = vec4( vNormal.xyz * df, 0.0 ) + mvPosition;\ngl_Position = projectionMatrix * displacedPosition;\n#else\ngl_Position = projectionMatrix * mvPosition;\n#endif\n}"}}}, -Cube=function(a,b,d,e,f,k,l,g){function j(z,K,F,y,o,i,p,h){var w=e||1,m=f||1,n=w+1,D=m+1;o=o/w;i=i/m;var A=c.vertices.length,L;if(z=="x"&&K=="y"||z=="y"&&K=="x")L="z";else if(z=="x"&&K=="z"||z=="z"&&K=="x")L="y";else if(z=="z"&&K=="y"||z=="y"&&K=="z")L="x";for(iy=0;iy>7)-127;B=(X&127)<<16|M<<8|B;if(B==0&&ea==-127)return 0;return(1-2*(Y>>7))*(1+B*Math.pow(2,-23))*Math.pow(2,ea)}function g(r,u){var B=t(r,u),M=t(r,u+1),X=t(r,u+2);return(t(r,u+3)<<24)+(X<<16)+ -(M<<8)+B}function j(r,u){var B=t(r,u);return(t(r,u+1)<<8)+B}function c(r,u){var B=t(r,u);return B>127?B-256:B}function t(r,u){return r.charCodeAt(u)&255}function x(r){var u,B,M;u=g(a,r);B=g(a,r+h);M=g(a,r+w);r=j(a,r+m);THREE.Loader.prototype.f3(F,u,B,M,r)}function q(r){var u,B,M,X,Y,ea;u=g(a,r);B=g(a,r+h);M=g(a,r+w);X=j(a,r+m);Y=g(a,r+n);ea=g(a,r+D);r=g(a,r+A);THREE.Loader.prototype.f3n(F,i,u,B,M,X,Y,ea,r)}function s(r){var u,B,M,X;u=g(a,r);B=g(a,r+L);M=g(a,r+E);X=g(a,r+O);r=j(a,r+S);THREE.Loader.prototype.f4(F, +(M<<8)+B}function j(r,u){var B=t(r,u);return(t(r,u+1)<<8)+B}function c(r,u){var B=t(r,u);return B>127?B-256:B}function t(r,u){return r.charCodeAt(u)&255}function x(r){var u,B,M;u=g(a,r);B=g(a,r+h);M=g(a,r+w);r=j(a,r+n);THREE.Loader.prototype.f3(F,u,B,M,r)}function q(r){var u,B,M,X,Y,ea;u=g(a,r);B=g(a,r+h);M=g(a,r+w);X=j(a,r+n);Y=g(a,r+m);ea=g(a,r+D);r=g(a,r+A);THREE.Loader.prototype.f3n(F,i,u,B,M,X,Y,ea,r)}function s(r){var u,B,M,X;u=g(a,r);B=g(a,r+L);M=g(a,r+E);X=g(a,r+O);r=j(a,r+S);THREE.Loader.prototype.f4(F, u,B,M,X,r)}function v(r){var u,B,M,X,Y,ea,ma,oa;u=g(a,r);B=g(a,r+L);M=g(a,r+E);X=g(a,r+O);Y=j(a,r+S);ea=g(a,r+G);ma=g(a,r+T);oa=g(a,r+N);r=g(a,r+U);THREE.Loader.prototype.f4n(F,i,u,B,M,X,Y,ea,ma,oa,r)}function z(r){var u,B;u=g(a,r);B=g(a,r+V);r=g(a,r+Q);THREE.Loader.prototype.uv3(F,p[u*2],p[u*2+1],p[B*2],p[B*2+1],p[r*2],p[r*2+1])}function K(r){var u,B,M;u=g(a,r);B=g(a,r+H);M=g(a,r+J);r=g(a,r+$);THREE.Loader.prototype.uv4(F,p[u*2],p[u*2+1],p[B*2],p[B*2+1],p[M*2],p[M*2+1],p[r*2],p[r*2+1])}var F=this, -y=0,o,i=[],p=[],h,w,m,n,D,A,L,E,O,S,G,T,N,U,V,Q,H,J,$;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(F,e,k);o={signature:a.substr(y,8),header_bytes:t(a,y+8),vertex_coordinate_bytes:t(a,y+9),normal_coordinate_bytes:t(a,y+10),uv_coordinate_bytes:t(a,y+11),vertex_index_bytes:t(a,y+12),normal_index_bytes:t(a,y+13),uv_index_bytes:t(a,y+14),material_index_bytes:t(a,y+15),nvertices:g(a,y+16),nnormals:g(a,y+16+4),nuvs:g(a,y+16+8),ntri_flat:g(a,y+16+12),ntri_smooth:g(a,y+16+16),ntri_flat_uv:g(a, -y+16+20),ntri_smooth_uv:g(a,y+16+24),nquad_flat:g(a,y+16+28),nquad_smooth:g(a,y+16+32),nquad_flat_uv:g(a,y+16+36),nquad_smooth_uv:g(a,y+16+40)};y+=o.header_bytes;h=o.vertex_index_bytes;w=o.vertex_index_bytes*2;m=o.vertex_index_bytes*3;n=o.vertex_index_bytes*3+o.material_index_bytes;D=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes;A=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes*2;L=o.vertex_index_bytes;E=o.vertex_index_bytes*2;O=o.vertex_index_bytes*3;S=o.vertex_index_bytes* +y=0,o,i=[],p=[],h,w,n,m,D,A,L,E,O,S,G,T,N,U,V,Q,H,J,$;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(F,e,k);o={signature:a.substr(y,8),header_bytes:t(a,y+8),vertex_coordinate_bytes:t(a,y+9),normal_coordinate_bytes:t(a,y+10),uv_coordinate_bytes:t(a,y+11),vertex_index_bytes:t(a,y+12),normal_index_bytes:t(a,y+13),uv_index_bytes:t(a,y+14),material_index_bytes:t(a,y+15),nvertices:g(a,y+16),nnormals:g(a,y+16+4),nuvs:g(a,y+16+8),ntri_flat:g(a,y+16+12),ntri_smooth:g(a,y+16+16),ntri_flat_uv:g(a, +y+16+20),ntri_smooth_uv:g(a,y+16+24),nquad_flat:g(a,y+16+28),nquad_smooth:g(a,y+16+32),nquad_flat_uv:g(a,y+16+36),nquad_smooth_uv:g(a,y+16+40)};y+=o.header_bytes;h=o.vertex_index_bytes;w=o.vertex_index_bytes*2;n=o.vertex_index_bytes*3;m=o.vertex_index_bytes*3+o.material_index_bytes;D=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes;A=o.vertex_index_bytes*3+o.material_index_bytes+o.normal_index_bytes*2;L=o.vertex_index_bytes;E=o.vertex_index_bytes*2;O=o.vertex_index_bytes*3;S=o.vertex_index_bytes* 4;G=o.vertex_index_bytes*4+o.material_index_bytes;T=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes;N=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*2;U=o.vertex_index_bytes*4+o.material_index_bytes+o.normal_index_bytes*3;V=o.uv_index_bytes;Q=o.uv_index_bytes*2;H=o.uv_index_bytes;J=o.uv_index_bytes*2;$=o.uv_index_bytes*3;y+=function(r){var u,B,M,X=o.vertex_coordinate_bytes*3,Y=r+o.nvertices*X;for(r=r;r= 0 ) { + + _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryChunk.__webGLNormalBuffer ); + _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 ); + + } // tangents -- GitLab