|
@@ -124,13 +124,12 @@ G.setAttribute("y1",X.positionScreen.y);G.setAttribute("x2",l.positionScreen.x);
|
|
-D;w.positionScreen.x*=s;w.positionScreen.y*=-D;v.positionScreen.x*=s;v.positionScreen.y*=-D;u.addPoint(q.positionScreen.x,q.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);u.addPoint(v.positionScreen.x,v.positionScreen.y);if(K.instersects(u)){M=0;for(J=n.meshMaterial.length;M<J;){t=n.meshMaterial[M++];if(t instanceof THREE.MeshFaceMaterial){X=0;for(l=n.faceMaterial.length;X<l;)(t=n.faceMaterial[X++])&&b(q,w,v,n,t,A)}else t&&b(q,w,v,n,t,A)}}}else if(n instanceof THREE.RenderableFace4){q=
|
|
-D;w.positionScreen.x*=s;w.positionScreen.y*=-D;v.positionScreen.x*=s;v.positionScreen.y*=-D;u.addPoint(q.positionScreen.x,q.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);u.addPoint(v.positionScreen.x,v.positionScreen.y);if(K.instersects(u)){M=0;for(J=n.meshMaterial.length;M<J;){t=n.meshMaterial[M++];if(t instanceof THREE.MeshFaceMaterial){X=0;for(l=n.faceMaterial.length;X<l;)(t=n.faceMaterial[X++])&&b(q,w,v,n,t,A)}else t&&b(q,w,v,n,t,A)}}}else if(n instanceof THREE.RenderableFace4){q=
|
|
n.v1;w=n.v2;v=n.v3;z=n.v4;q.positionScreen.x*=s;q.positionScreen.y*=-D;w.positionScreen.x*=s;w.positionScreen.y*=-D;v.positionScreen.x*=s;v.positionScreen.y*=-D;z.positionScreen.x*=s;z.positionScreen.y*=-D;u.addPoint(q.positionScreen.x,q.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);u.addPoint(v.positionScreen.x,v.positionScreen.y);u.addPoint(z.positionScreen.x,z.positionScreen.y);if(K.instersects(u)){M=0;for(J=n.meshMaterial.length;M<J;){t=n.meshMaterial[M++];if(t instanceof
|
|
n.v1;w=n.v2;v=n.v3;z=n.v4;q.positionScreen.x*=s;q.positionScreen.y*=-D;w.positionScreen.x*=s;w.positionScreen.y*=-D;v.positionScreen.x*=s;v.positionScreen.y*=-D;z.positionScreen.x*=s;z.positionScreen.y*=-D;u.addPoint(q.positionScreen.x,q.positionScreen.y);u.addPoint(w.positionScreen.x,w.positionScreen.y);u.addPoint(v.positionScreen.x,v.positionScreen.y);u.addPoint(z.positionScreen.x,z.positionScreen.y);if(K.instersects(u)){M=0;for(J=n.meshMaterial.length;M<J;){t=n.meshMaterial[M++];if(t instanceof
|
|
THREE.MeshFaceMaterial){X=0;for(l=n.faceMaterial.length;X<l;)(t=n.faceMaterial[X++])&&d(q,w,v,z,n,t,A)}else t&&d(q,w,v,z,n,t,A)}}}}}};
|
|
THREE.MeshFaceMaterial){X=0;for(l=n.faceMaterial.length;X<l;)(t=n.faceMaterial[X++])&&d(q,w,v,z,n,t,A)}else t&&d(q,w,v,z,n,t,A)}}}}}};
|
|
-THREE.WebGLRenderer=function(a){function b(h,e){var m=c.createProgram();c.attachShader(m,g("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+h));c.attachShader(m,g("vertex",e));c.linkProgram(m);if(!c.getProgramParameter(m,c.LINK_STATUS)){alert("Could not initialise shaders");alert("VALIDATE_STATUS: "+c.getProgramParameter(m,c.VALIDATE_STATUS));alert(c.getError())}m.uniforms={};return m}function d(h,e){var m,r,p;m=0;for(r=e.length;m<r;m++){p=e[m];h.uniforms[p]=c.getUniformLocation(h,p)}}
|
|
|
|
-function f(h){h.position=c.getAttribLocation(h,"position");c.enableVertexAttribArray(h.position);h.normal=c.getAttribLocation(h,"normal");c.enableVertexAttribArray(h.normal);h.uv=c.getAttribLocation(h,"uv");c.enableVertexAttribArray(h.uv)}function g(h,e){var m;if(h=="fragment")m=c.createShader(c.FRAGMENT_SHADER);else if(h=="vertex")m=c.createShader(c.VERTEX_SHADER);c.shaderSource(m,e);c.compileShader(m);if(!c.getShaderParameter(m,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(m));return null}return m}
|
|
|
|
-function i(h){switch(h){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var k=document.createElement("canvas"),c,j,y,s=new THREE.Matrix4,D,q=new Float32Array(16),w=new Float32Array(16),v=new Float32Array(16),z=new Float32Array(9),K=new Float32Array(16);a=function(h,e){if(h){var m,r,p,o=pointLights=maxDirLights=maxPointLights=0;m=0;for(r=h.lights.length;m<r;m++){p=h.lights[m];p instanceof THREE.DirectionalLight&&
|
|
|
|
-o++;p instanceof THREE.PointLight&&pointLights++}if(pointLights+o<=e){maxDirLights=o;maxPointLights=pointLights}else{maxDirLights=Math.ceil(e*o/(pointLights+o));maxPointLights=e-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:e-1}}(a,4);this.domElement=k;this.autoClear=true;try{c=k.getContext("experimental-webgl",{antialias:true})}catch(u){}if(!c){alert("WebGL not supported");throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);
|
|
|
|
-c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);(function(h,e){var m=[h?"#define MAX_DIR_LIGHTS "+h:"",e?"#define MAX_POINT_LIGHTS "+e:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform vec3 cameraPosition;\nuniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
|
|
|
|
-h?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",e?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 objMatrix;\nuniform mat4 viewMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",e?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":
|
|
|
|
-"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objMatrix[0].xyz, objMatrix[1].xyz, objMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
|
|
|
|
|
|
+THREE.WebGLRenderer=function(a){function b(h,e){var m=c.createProgram();c.attachShader(m,g("fragment","#ifdef GL_ES\nprecision highp float;\n#endif\n"+h));c.attachShader(m,g("vertex","uniform mat4 objectMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\n"+e));c.linkProgram(m);if(!c.getProgramParameter(m,c.LINK_STATUS)){alert("Could not initialise shaders");alert("VALIDATE_STATUS: "+c.getProgramParameter(m,c.VALIDATE_STATUS));alert(c.getError())}m.uniforms=
|
|
|
|
+{};return m}function d(h,e){var m,r,p;m=0;for(r=e.length;m<r;m++){p=e[m];h.uniforms[p]=c.getUniformLocation(h,p)}}function f(h){h.position=c.getAttribLocation(h,"position");c.enableVertexAttribArray(h.position);h.normal=c.getAttribLocation(h,"normal");c.enableVertexAttribArray(h.normal);h.uv=c.getAttribLocation(h,"uv");c.enableVertexAttribArray(h.uv)}function g(h,e){var m;if(h=="fragment")m=c.createShader(c.FRAGMENT_SHADER);else if(h=="vertex")m=c.createShader(c.VERTEX_SHADER);c.shaderSource(m,e);
|
|
|
|
+c.compileShader(m);if(!c.getShaderParameter(m,c.COMPILE_STATUS)){alert(c.getShaderInfoLog(m));return null}return m}function i(h){switch(h){case THREE.Repeat:return c.REPEAT;case THREE.ClampToEdge:return c.CLAMP_TO_EDGE;case THREE.MirroredRepeat:return c.MIRRORED_REPEAT}return 0}var k=document.createElement("canvas"),c,j,y,s=new THREE.Matrix4,D,q=new Float32Array(16),w=new Float32Array(16),v=new Float32Array(16),z=new Float32Array(9),K=new Float32Array(16);a=function(h,e){if(h){var m,r,p,o=pointLights=
|
|
|
|
+maxDirLights=maxPointLights=0;m=0;for(r=h.lights.length;m<r;m++){p=h.lights[m];p instanceof THREE.DirectionalLight&&o++;p instanceof THREE.PointLight&&pointLights++}if(pointLights+o<=e){maxDirLights=o;maxPointLights=pointLights}else{maxDirLights=Math.ceil(e*o/(pointLights+o));maxPointLights=e-maxDirLights}return{directional:maxDirLights,point:maxPointLights}}return{directional:1,point:e-1}}(a,4);this.domElement=k;this.autoClear=true;try{c=k.getContext("experimental-webgl",{antialias:true})}catch(u){}if(!c){alert("WebGL not supported");
|
|
|
|
+throw"cannot create webgl context";}c.clearColor(0,0,0,1);c.clearDepth(1);c.enable(c.DEPTH_TEST);c.depthFunc(c.LEQUAL);c.frontFace(c.CCW);c.cullFace(c.BACK);c.enable(c.CULL_FACE);c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);c.clearColor(0,0,0,0);(function(h,e){var m=[h?"#define MAX_DIR_LIGHTS "+h:"",e?"#define MAX_POINT_LIGHTS "+e:"","attribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nuniform bool enableLighting;\nuniform bool useRefract;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;\nuniform vec3 ambientLightColor;",
|
|
|
|
+h?"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];":"",h?"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];":"",e?"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];":"",e?"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];":"","uniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nvarying vec3 vNormal;\nvarying vec2 vUv;\nvarying vec3 vLightWeighting;",e?"varying vec3 vPointLightVector[ MAX_POINT_LIGHTS ];":"","varying vec3 vViewPosition;\nvarying vec3 vReflect;\nuniform float mRefractionRatio;\nvoid main(void) {\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvViewPosition = cameraPosition - mPosition.xyz;\nvec3 nWorld = mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal;\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec3 transformedNormal = normalize( normalMatrix * normal );\nif ( !enableLighting ) {\nvLightWeighting = vec3( 1.0, 1.0, 1.0 );\n} else {\nvLightWeighting = ambientLightColor;",
|
|
h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",h?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",h?"}":"",e?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",e?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",e?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
|
|
h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"float directionalLightWeighting = max( dot( transformedNormal, normalize(lDirection.xyz ) ), 0.0 );":"",h?"vLightWeighting += directionalLightColor[ i ] * directionalLightWeighting;":"",h?"}":"",e?"for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {":"",e?"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );":"",e?"vPointLightVector[ i ] = normalize( lPosition.xyz - mvPosition.xyz );":
|
|
"",e?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",e?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",e?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
|
|
"",e?"float pointLightWeighting = max( dot( transformedNormal, vPointLightVector[ i ] ), 0.0 );":"",e?"vLightWeighting += pointLightColor[ i ] * pointLightWeighting;":"",e?"}":"","}\nvNormal = transformedNormal;\nvUv = uv;\nif ( useRefract ) {\nvReflect = refract( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz), mRefractionRatio );\n} else {\nvReflect = reflect( normalize(mPosition.xyz - cameraPosition), normalize(nWorld.xyz) );\n}\ngl_Position = projectionMatrix * mvPosition;\n}"].join("\n"),
|
|
r=[h?"#define MAX_DIR_LIGHTS "+h:"",e?"#define MAX_POINT_LIGHTS "+e:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
|
|
r=[h?"#define MAX_DIR_LIGHTS "+h:"",e?"#define MAX_POINT_LIGHTS "+e:"","uniform int material;\nuniform bool enableMap;\nuniform bool enableCubeMap;\nuniform bool mixEnvMap;\nuniform samplerCube tCube;\nuniform float mReflectivity;\nuniform sampler2D tMap;\nuniform vec4 mColor;\nuniform float mOpacity;\nuniform vec4 mAmbient;\nuniform vec4 mSpecular;\nuniform float mShininess;\nuniform float m2Near;\nuniform float mFarPlusNear;\nuniform float mFarMinusNear;\nuniform int pointLightNumber;\nuniform int directionalLightNumber;",
|
|
@@ -139,7 +138,7 @@ e?"vec4 pointDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",e?"vec4 pointSpecular =
|
|
"",e?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",e?"pointDiffuse += mColor * pointDiffuseWeight;":"",e?"pointSpecular += mSpecular * pointSpecularWeight;":"",e?"}":"",h?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"vec3 dirVector = normalize( lDirection.xyz );":"",h?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
|
|
"",e?"pointSpecularWeight = pow( pointDotNormalHalf, mShininess );":"",e?"pointDiffuse += mColor * pointDiffuseWeight;":"",e?"pointSpecular += mSpecular * pointSpecularWeight;":"",e?"}":"",h?"vec4 dirDiffuse = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"vec4 dirSpecular = vec4( 0.0, 0.0, 0.0, 0.0 );":"",h?"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {":"",h?"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );":"",h?"vec3 dirVector = normalize( lDirection.xyz );":"",h?"vec3 dirHalfVector = normalize( lDirection.xyz + vViewPosition );":
|
|
"",h?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",h?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",h?"float dirSpecularWeight = 0.0;":"",h?"if ( dirDotNormalHalf >= 0.0 )":"",h?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",h?"dirDiffuse += mColor * dirDiffuseWeight;":"",h?"dirSpecular += mSpecular * dirSpecularWeight;":"",h?"}":"","vec4 totalLight = mAmbient;",h?"totalLight += dirDiffuse + dirSpecular;":"",e?"totalLight += pointDiffuse + pointSpecular;":
|
|
"",h?"float dirDotNormalHalf = dot( normal, dirHalfVector );":"",h?"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );":"",h?"float dirSpecularWeight = 0.0;":"",h?"if ( dirDotNormalHalf >= 0.0 )":"",h?"dirSpecularWeight = pow( dirDotNormalHalf, mShininess );":"",h?"dirDiffuse += mColor * dirDiffuseWeight;":"",h?"dirSpecular += mSpecular * dirSpecularWeight;":"",h?"}":"","vec4 totalLight = mAmbient;",h?"totalLight += dirDiffuse + dirSpecular;":"",e?"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");
|
|
"","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");
|
|
-j=b(r,m);c.useProgram(j);d(j,["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objMatrix","cameraPosition","enableLighting","ambientLightColor","material","mColor","mAmbient","mSpecular","mShininess","mOpacity","enableMap","tMap","enableCubeMap","tCube","mixEnvMap","mReflectivity","mRefractionRatio","useRefract","m2Near","mFarPlusNear","mFarMinusNear"]);h&&d(j,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);e&&d(j,["pointLightNumber","pointLightColor",
|
|
|
|
|
|
+j=b(r,m);c.useProgram(j);d(j,["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"]);h&&d(j,["directionalLightNumber","directionalLightColor","directionalLightDirection"]);e&&d(j,["pointLightNumber","pointLightColor",
|
|
"pointLightPosition"]);c.uniform1i(j.uniforms.enableMap,0);c.uniform1i(j.uniforms.tMap,0);c.uniform1i(j.uniforms.enableCubeMap,0);c.uniform1i(j.uniforms.tCube,1);c.uniform1i(j.uniforms.mixEnvMap,0);c.uniform1i(j.uniforms.useRefract,0);f(j)})(a.directional,a.point);this.setSize=function(h,e){k.width=h;k.height=e;c.viewport(0,0,k.width,k.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(h,e){var m,r,p,o,x,C=[],S=[],B=[];o=[];x=[];c.uniform1i(h.uniforms.enableLighting,
|
|
"pointLightPosition"]);c.uniform1i(j.uniforms.enableMap,0);c.uniform1i(j.uniforms.tMap,0);c.uniform1i(j.uniforms.enableCubeMap,0);c.uniform1i(j.uniforms.tCube,1);c.uniform1i(j.uniforms.mixEnvMap,0);c.uniform1i(j.uniforms.useRefract,0);f(j)})(a.directional,a.point);this.setSize=function(h,e){k.width=h;k.height=e;c.viewport(0,0,k.width,k.height)};this.clear=function(){c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT)};this.setupLights=function(h,e){var m,r,p,o,x,C=[],S=[],B=[];o=[];x=[];c.uniform1i(h.uniforms.enableLighting,
|
|
e.lights.length);m=0;for(r=e.lights.length;m<r;m++){p=e.lights[m];if(p instanceof THREE.AmbientLight)C.push(p);else if(p instanceof THREE.DirectionalLight)B.push(p);else p instanceof THREE.PointLight&&S.push(p)}m=p=o=x=0;for(r=C.length;m<r;m++){p+=C[m].color.r;o+=C[m].color.g;x+=C[m].color.b}c.uniform3f(h.uniforms.ambientLightColor,p,o,x);o=[];x=[];m=0;for(r=B.length;m<r;m++){p=B[m];o.push(p.color.r*p.intensity);o.push(p.color.g*p.intensity);o.push(p.color.b*p.intensity);x.push(p.position.x);x.push(p.position.y);
|
|
e.lights.length);m=0;for(r=e.lights.length;m<r;m++){p=e.lights[m];if(p instanceof THREE.AmbientLight)C.push(p);else if(p instanceof THREE.DirectionalLight)B.push(p);else p instanceof THREE.PointLight&&S.push(p)}m=p=o=x=0;for(r=C.length;m<r;m++){p+=C[m].color.r;o+=C[m].color.g;x+=C[m].color.b}c.uniform3f(h.uniforms.ambientLightColor,p,o,x);o=[];x=[];m=0;for(r=B.length;m<r;m++){p=B[m];o.push(p.color.r*p.intensity);o.push(p.color.g*p.intensity);o.push(p.color.b*p.intensity);x.push(p.position.x);x.push(p.position.y);
|
|
x.push(p.position.z)}if(B.length){c.uniform1i(h.uniforms.directionalLightNumber,B.length);c.uniform3fv(h.uniforms.directionalLightDirection,x);c.uniform3fv(h.uniforms.directionalLightColor,o)}o=[];x=[];m=0;for(r=S.length;m<r;m++){p=S[m];o.push(p.color.r*p.intensity);o.push(p.color.g*p.intensity);o.push(p.color.b*p.intensity);x.push(p.position.x);x.push(p.position.y);x.push(p.position.z)}if(S.length){c.uniform1i(h.uniforms.pointLightNumber,S.length);c.uniform3fv(h.uniforms.pointLightPosition,x);c.uniform3fv(h.uniforms.pointLightColor,
|
|
x.push(p.position.z)}if(B.length){c.uniform1i(h.uniforms.directionalLightNumber,B.length);c.uniform3fv(h.uniforms.directionalLightDirection,x);c.uniform3fv(h.uniforms.directionalLightColor,o)}o=[];x=[];m=0;for(r=S.length;m<r;m++){p=S[m];o.push(p.color.r*p.intensity);o.push(p.color.g*p.intensity);o.push(p.color.b*p.intensity);x.push(p.position.x);x.push(p.position.y);x.push(p.position.z)}if(S.length){c.uniform1i(h.uniforms.pointLightNumber,S.length);c.uniform3fv(h.uniforms.pointLightPosition,x);c.uniform3fv(h.uniforms.pointLightColor,
|
|
@@ -148,7 +147,7 @@ p;m=0;for(r=A.faces.length;m<r;m++){p=A.faces[m];o=h.geometry.faces[p];x=o.verte
|
|
I+1,I+2);G.push(I,I+1);G.push(I,I+2);G.push(I+1,I+2);I+=3}else if(o instanceof THREE.Face4){C=h.geometry.vertices[o.a].position;S=h.geometry.vertices[o.b].position;B=h.geometry.vertices[o.c].position;o=h.geometry.vertices[o.d].position;E.push(C.x,C.y,C.z);E.push(S.x,S.y,S.z);E.push(B.x,B.y,B.z);E.push(o.x,o.y,o.z);if(x.length==4&&L)for(o=0;o<4;o++)W.push(x[o].x,x[o].y,x[o].z);else for(o=0;o<4;o++)W.push(faceNormal.x,faceNormal.y,faceNormal.z);if(p)for(o=0;o<4;o++)O.push(p[o].u,p[o].v);V.push(I,I+
|
|
I+1,I+2);G.push(I,I+1);G.push(I,I+2);G.push(I+1,I+2);I+=3}else if(o instanceof THREE.Face4){C=h.geometry.vertices[o.a].position;S=h.geometry.vertices[o.b].position;B=h.geometry.vertices[o.c].position;o=h.geometry.vertices[o.d].position;E.push(C.x,C.y,C.z);E.push(S.x,S.y,S.z);E.push(B.x,B.y,B.z);E.push(o.x,o.y,o.z);if(x.length==4&&L)for(o=0;o<4;o++)W.push(x[o].x,x[o].y,x[o].z);else for(o=0;o<4;o++)W.push(faceNormal.x,faceNormal.y,faceNormal.z);if(p)for(o=0;o<4;o++)O.push(p[o].u,p[o].v);V.push(I,I+
|
|
1,I+2);V.push(I,I+2,I+3);G.push(I,I+1);G.push(I,I+2);G.push(I,I+3);G.push(I+1,I+2);G.push(I+2,I+3);I+=4}}if(E.length){A.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,A.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(E),c.STATIC_DRAW);A.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,A.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(W),c.STATIC_DRAW);A.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,A.__webGLUVBuffer);
|
|
1,I+2);V.push(I,I+2,I+3);G.push(I,I+1);G.push(I,I+2);G.push(I,I+3);G.push(I+1,I+2);G.push(I+2,I+3);I+=4}}if(E.length){A.__webGLVertexBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,A.__webGLVertexBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(E),c.STATIC_DRAW);A.__webGLNormalBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,A.__webGLNormalBuffer);c.bufferData(c.ARRAY_BUFFER,new Float32Array(W),c.STATIC_DRAW);A.__webGLUVBuffer=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,A.__webGLUVBuffer);
|
|
c.bufferData(c.ARRAY_BUFFER,new Float32Array(O),c.STATIC_DRAW);A.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,A.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(V),c.STATIC_DRAW);A.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,A.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);A.__webGLFaceCount=V.length;A.__webGLLineCount=G.length}};this.renderBuffer=function(h,e,m){var r,p,o,x,C,S,B,
|
|
c.bufferData(c.ARRAY_BUFFER,new Float32Array(O),c.STATIC_DRAW);A.__webGLFaceBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,A.__webGLFaceBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(V),c.STATIC_DRAW);A.__webGLLineBuffer=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,A.__webGLLineBuffer);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(G),c.STATIC_DRAW);A.__webGLFaceCount=V.length;A.__webGLLineCount=G.length}};this.renderBuffer=function(h,e,m){var r,p,o,x,C,S,B,
|
|
-V,G,E;if(e instanceof THREE.MeshShaderMaterial){if(!e.program){e.program=b(e.fragment_shader,e.vertex_shader);C=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objMatrix","cameraPosition"];for(E in e.uniforms)C.push(E);d(e.program,C);f(e.program)}E=e.program}else E=j;if(E!=y){c.useProgram(E);y=E}if(e instanceof THREE.MeshShaderMaterial){C=E;V=e.uniforms;var W,O;for(p in V){W=V[p].type;G=V[p].value;O=C.uniforms[p];if(W=="i")c.uniform1i(O,G);else if(W=="f")c.uniform1f(O,G);else if(W==
|
|
|
|
|
|
+V,G,E;if(e instanceof THREE.MeshShaderMaterial){if(!e.program){e.program=b(e.fragment_shader,e.vertex_shader);C=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","objectMatrix","cameraPosition"];for(E in e.uniforms)C.push(E);d(e.program,C);f(e.program)}E=e.program}else E=j;if(E!=y){c.useProgram(E);y=E}if(e instanceof THREE.MeshShaderMaterial){C=E;V=e.uniforms;var W,O;for(p in V){W=V[p].type;G=V[p].value;O=C.uniforms[p];if(W=="i")c.uniform1i(O,G);else if(W=="f")c.uniform1f(O,G);else if(W==
|
|
"t"){c.uniform1i(O,G);G=V[p].texture;if(G instanceof THREE.TextureCube&&G.image.length==6){if(!G.image.__webGLTextureCube&&!G.image.__cubeMapInitialized&&G.image.loadCount==6){G.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,G.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,
|
|
"t"){c.uniform1i(O,G);G=V[p].texture;if(G instanceof THREE.TextureCube&&G.image.length==6){if(!G.image.__webGLTextureCube&&!G.image.__cubeMapInitialized&&G.image.loadCount==6){G.image.__webGLTextureCube=c.createTexture();c.bindTexture(c.TEXTURE_CUBE_MAP,G.image.__webGLTextureCube);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE);c.texParameteri(c.TEXTURE_CUBE_MAP,c.TEXTURE_MAG_FILTER,c.LINEAR);c.texParameteri(c.TEXTURE_CUBE_MAP,
|
|
c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(W=0;W<6;++W)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+W,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,G.image[W]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);G.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE1);c.bindTexture(c.TEXTURE_CUBE_MAP,G.image.__webGLTextureCube)}}}this.loadCamera(E,h);this.loadMatrices(E)}else if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){h=
|
|
c.TEXTURE_MIN_FILTER,c.LINEAR_MIPMAP_LINEAR);for(W=0;W<6;++W)c.texImage2D(c.TEXTURE_CUBE_MAP_POSITIVE_X+W,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,G.image[W]);c.generateMipmap(c.TEXTURE_CUBE_MAP);c.bindTexture(c.TEXTURE_CUBE_MAP,null);G.image.__cubeMapInitialized=true}c.activeTexture(c.TEXTURE1);c.bindTexture(c.TEXTURE_CUBE_MAP,G.image.__webGLTextureCube)}}}this.loadCamera(E,h);this.loadMatrices(E)}else if(e instanceof THREE.MeshPhongMaterial||e instanceof THREE.MeshLambertMaterial||e instanceof THREE.MeshBasicMaterial){h=
|
|
e.color;r=e.opacity;o=e.wireframe;x=e.wireframe_linewidth;S=e.map;B=e.env_map;C=e.combine==THREE.Mix;p=e.reflectivity;G=e.env_map&&e.env_map.mapping==THREE.RefractionMap;V=e.refraction_ratio;c.uniform4f(E.uniforms.mColor,h.r*r,h.g*r,h.b*r,r);c.uniform1i(E.uniforms.mixEnvMap,C);c.uniform1f(E.uniforms.mReflectivity,p);c.uniform1i(E.uniforms.useRefract,G);c.uniform1f(E.uniforms.mRefractionRatio,V)}if(e instanceof THREE.MeshNormalMaterial){r=e.opacity;c.uniform1f(E.uniforms.mOpacity,r);c.uniform1i(E.uniforms.material,
|
|
e.color;r=e.opacity;o=e.wireframe;x=e.wireframe_linewidth;S=e.map;B=e.env_map;C=e.combine==THREE.Mix;p=e.reflectivity;G=e.env_map&&e.env_map.mapping==THREE.RefractionMap;V=e.refraction_ratio;c.uniform4f(E.uniforms.mColor,h.r*r,h.g*r,h.b*r,r);c.uniform1i(E.uniforms.mixEnvMap,C);c.uniform1f(E.uniforms.mReflectivity,p);c.uniform1i(E.uniforms.useRefract,G);c.uniform1f(E.uniforms.mRefractionRatio,V)}if(e instanceof THREE.MeshNormalMaterial){r=e.opacity;c.uniform1f(E.uniforms.mOpacity,r);c.uniform1i(E.uniforms.material,
|
|
@@ -162,7 +161,7 @@ c.UNSIGNED_SHORT,0)}else{c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,m.__webGLFaceBuffer
|
|
this.renderBuffer(h,B,m)}}};this.render=function(h,e){var m,r;this.initWebGLObjects(h);this.autoClear&&this.clear();e.autoUpdateMatrix&&e.updateMatrix();this.loadCamera(j,e);this.setupLights(j,h);m=0;for(r=h.__webGLObjects.length;m<r;m++){webGLObject=h.__webGLObjects[m];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,e);this.loadMatrices(j);this.renderPass(e,webGLObject.__object,webGLObject,THREE.NormalBlending,false)}}m=0;for(r=h.__webGLObjects.length;m<r;m++){webGLObject=
|
|
this.renderBuffer(h,B,m)}}};this.render=function(h,e){var m,r;this.initWebGLObjects(h);this.autoClear&&this.clear();e.autoUpdateMatrix&&e.updateMatrix();this.loadCamera(j,e);this.setupLights(j,h);m=0;for(r=h.__webGLObjects.length;m<r;m++){webGLObject=h.__webGLObjects[m];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,e);this.loadMatrices(j);this.renderPass(e,webGLObject.__object,webGLObject,THREE.NormalBlending,false)}}m=0;for(r=h.__webGLObjects.length;m<r;m++){webGLObject=
|
|
h.__webGLObjects[m];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,e);this.loadMatrices(j);this.renderPass(e,webGLObject.__object,webGLObject,THREE.AdditiveBlending,false);this.renderPass(e,webGLObject.__object,webGLObject,THREE.SubtractiveBlending,false);this.renderPass(e,webGLObject.__object,webGLObject,THREE.AdditiveBlending,true);this.renderPass(e,webGLObject.__object,webGLObject,THREE.SubtractiveBlending,true);this.renderPass(e,webGLObject.__object,webGLObject,THREE.NormalBlending,
|
|
h.__webGLObjects[m];if(webGLObject.__object.visible){this.setupMatrices(webGLObject.__object,e);this.loadMatrices(j);this.renderPass(e,webGLObject.__object,webGLObject,THREE.AdditiveBlending,false);this.renderPass(e,webGLObject.__object,webGLObject,THREE.SubtractiveBlending,false);this.renderPass(e,webGLObject.__object,webGLObject,THREE.AdditiveBlending,true);this.renderPass(e,webGLObject.__object,webGLObject,THREE.SubtractiveBlending,true);this.renderPass(e,webGLObject.__object,webGLObject,THREE.NormalBlending,
|
|
true)}}};this.initWebGLObjects=function(h){var e,m,r,p,o;if(!h.__webGLObjects)h.__webGLObjects=[];e=0;for(m=h.objects.length;e<m;e++){r=h.objects[e];if(r instanceof THREE.Mesh)for(p in r.materialFaceGroup){o=r.materialFaceGroup[p];if(!o.__webGLVertexBuffer){this.createBuffers(r,p);o.__object=r;h.__webGLObjects.push(o)}}}};this.removeObject=function(h,e){var m,r;for(m=h.__webGLObjects.length-1;m>=0;m--){r=h.__webGLObjects[m].__object;e==r&&h.__webGLObjects.splice(m,1)}};this.setupMatrices=function(h,
|
|
true)}}};this.initWebGLObjects=function(h){var e,m,r,p,o;if(!h.__webGLObjects)h.__webGLObjects=[];e=0;for(m=h.objects.length;e<m;e++){r=h.objects[e];if(r instanceof THREE.Mesh)for(p in r.materialFaceGroup){o=r.materialFaceGroup[p];if(!o.__webGLVertexBuffer){this.createBuffers(r,p);o.__object=r;h.__webGLObjects.push(o)}}}};this.removeObject=function(h,e){var m,r;for(m=h.__webGLObjects.length-1;m>=0;m--){r=h.__webGLObjects[m].__object;e==r&&h.__webGLObjects.splice(m,1)}};this.setupMatrices=function(h,
|
|
-e){h.autoUpdateMatrix&&h.updateMatrix();s.multiply(e.matrix,h.matrix);q.set(e.matrix.flatten());w.set(s.flatten());v.set(e.projectionMatrix.flatten());D=THREE.Matrix4.makeInvert3x3(s).transpose();z.set(D.m);K.set(h.matrix.flatten())};this.loadMatrices=function(h){c.uniformMatrix4fv(h.uniforms.viewMatrix,false,q);c.uniformMatrix4fv(h.uniforms.modelViewMatrix,false,w);c.uniformMatrix4fv(h.uniforms.projectionMatrix,false,v);c.uniformMatrix3fv(h.uniforms.normalMatrix,false,z);c.uniformMatrix4fv(h.uniforms.objMatrix,
|
|
|
|
|
|
+e){h.autoUpdateMatrix&&h.updateMatrix();s.multiply(e.matrix,h.matrix);q.set(e.matrix.flatten());w.set(s.flatten());v.set(e.projectionMatrix.flatten());D=THREE.Matrix4.makeInvert3x3(s).transpose();z.set(D.m);K.set(h.matrix.flatten())};this.loadMatrices=function(h){c.uniformMatrix4fv(h.uniforms.viewMatrix,false,q);c.uniformMatrix4fv(h.uniforms.modelViewMatrix,false,w);c.uniformMatrix4fv(h.uniforms.projectionMatrix,false,v);c.uniformMatrix3fv(h.uniforms.normalMatrix,false,z);c.uniformMatrix4fv(h.uniforms.objectMatrix,
|
|
false,K)};this.loadCamera=function(h,e){c.uniform3f(h.uniforms.cameraPosition,e.position.x,e.position.y,e.position.z)};this.setBlending=function(h){switch(h){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(h,e){if(h){!e||e=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(h=="back")c.cullFace(c.BACK);
|
|
false,K)};this.loadCamera=function(h,e){c.uniform3f(h.uniforms.cameraPosition,e.position.x,e.position.y,e.position.z)};this.setBlending=function(h){switch(h){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(h,e){if(h){!e||e=="ccw"?c.frontFace(c.CCW):c.frontFace(c.CW);if(h=="back")c.cullFace(c.BACK);
|
|
else h=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};
|
|
else h=="front"?c.cullFace(c.FRONT):c.cullFace(c.FRONT_AND_BACK);c.enable(c.CULL_FACE)}else c.disable(c.CULL_FACE)}};
|
|
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=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};
|
|
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=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];this.faceMaterial=this.meshMaterial=null;this.overdraw=false;this.uvs=[null,null,null]};
|
|
@@ -173,7 +172,7 @@ f;b.position.y=g;b.position.z=i;b.rotation.x=k;b.rotation.y=c;b.rotation.z=j;a.a
|
|
f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[4])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));mesh=new THREE.Mesh(new Cube(b,b,b,1,1,f,true),new THREE.MeshFaceMaterial);a.addObject(mesh);return mesh},addPanoramaCubePlanes:function(a,b,d){var f=b/2;b=new Plane(b,b);var g=Math.PI/2,i=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-f,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));SceneUtils.addMesh(a,b,1,-f,0,0,0,g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));
|
|
f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[4])}));f.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));mesh=new THREE.Mesh(new Cube(b,b,b,1,1,f,true),new THREE.MeshFaceMaterial);a.addObject(mesh);return mesh},addPanoramaCubePlanes:function(a,b,d){var f=b/2;b=new Plane(b,b);var g=Math.PI/2,i=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-f,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));SceneUtils.addMesh(a,b,1,-f,0,0,0,g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));
|
|
SceneUtils.addMesh(a,b,1,f,0,0,0,-g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));SceneUtils.addMesh(a,b,1,0,f,0,g,0,i,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));SceneUtils.addMesh(a,b,1,0,-f,0,-g,0,i,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}))}},ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},
|
|
SceneUtils.addMesh(a,b,1,f,0,0,0,-g,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));SceneUtils.addMesh(a,b,1,0,f,0,g,0,i,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));SceneUtils.addMesh(a,b,1,0,-f,0,-g,0,i,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}))}},ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},
|
|
fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
|
|
fragment_shader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
|
|
-vertex_shader:"attribute vec3 position;\nattribute vec3 normal;\nattribute vec3 uv;\nuniform mat4 objMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform vec3 cameraPosition;\nuniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main(void) {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objMatrix[0].xyz, objMatrix[1].xyz, objMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"}}},
|
|
|
|
|
|
+vertex_shader:"attribute vec3 position;\nattribute vec3 normal;\nattribute vec3 uv;\nuniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main(void) {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"}}},
|
|
Cube=function(a,b,d,f,g,i,k){function c(w,v,z,K,u,h,e,m){var r=f||1,p=g||1,o=r+1,x=p+1;u=u/r;h=h/p;var C=j.vertices.length,S;if(w=="x"&&v=="y"||w=="y"&&v=="x")S="z";else if(w=="x"&&v=="z"||w=="z"&&v=="x")S="y";else if(w=="z"&&v=="y"||w=="y"&&v=="z")S="x";for(iy=0;iy<x;iy++)for(ix=0;ix<o;ix++){var B=new THREE.Vector3;B[w]=(ix*u-y)*z;B[v]=(iy*h-s)*K;B[S]=e;j.vertices.push(new THREE.Vertex(B))}for(iy=0;iy<p;iy++)for(ix=0;ix<r;ix++){j.faces.push(new THREE.Face4(ix+o*iy+C,ix+o*(iy+1)+C,ix+1+o*(iy+1)+C,
|
|
Cube=function(a,b,d,f,g,i,k){function c(w,v,z,K,u,h,e,m){var r=f||1,p=g||1,o=r+1,x=p+1;u=u/r;h=h/p;var C=j.vertices.length,S;if(w=="x"&&v=="y"||w=="y"&&v=="x")S="z";else if(w=="x"&&v=="z"||w=="z"&&v=="x")S="y";else if(w=="z"&&v=="y"||w=="y"&&v=="z")S="x";for(iy=0;iy<x;iy++)for(ix=0;ix<o;ix++){var B=new THREE.Vector3;B[w]=(ix*u-y)*z;B[v]=(iy*h-s)*K;B[S]=e;j.vertices.push(new THREE.Vertex(B))}for(iy=0;iy<p;iy++)for(ix=0;ix<r;ix++){j.faces.push(new THREE.Face4(ix+o*iy+C,ix+o*(iy+1)+C,ix+1+o*(iy+1)+C,
|
|
ix+1+o*iy+C,null,m));j.uvs.push([new THREE.UV(ix/r,iy/p),new THREE.UV(ix/r,(iy+1)/p),new THREE.UV((ix+1)/r,(iy+1)/p),new THREE.UV((ix+1)/r,iy/p)])}}THREE.Geometry.call(this);var j=this,y=a/2,s=b/2,D=d/2;k=k?-1:1;if(i!==undefined)if(i instanceof Array)this.materials=i;else{this.materials=[];for(var q=0;q<6;q++)this.materials.push([i])}else this.materials=[];c("z","y",1*k,-1,d,b,-y,this.materials[0]);c("z","y",-1*k,-1,d,b,y,this.materials[1]);c("x","z",1*k,1,a,d,s,this.materials[2]);c("x","z",1*k,-1,
|
|
ix+1+o*iy+C,null,m));j.uvs.push([new THREE.UV(ix/r,iy/p),new THREE.UV(ix/r,(iy+1)/p),new THREE.UV((ix+1)/r,(iy+1)/p),new THREE.UV((ix+1)/r,iy/p)])}}THREE.Geometry.call(this);var j=this,y=a/2,s=b/2,D=d/2;k=k?-1:1;if(i!==undefined)if(i instanceof Array)this.materials=i;else{this.materials=[];for(var q=0;q<6;q++)this.materials.push([i])}else this.materials=[];c("z","y",1*k,-1,d,b,-y,this.materials[0]);c("z","y",-1*k,-1,d,b,y,this.materials[1]);c("x","z",1*k,1,a,d,s,this.materials[2]);c("x","z",1*k,-1,
|
|
a,d,-s,this.materials[3]);c("x","y",1*k,-1,a,b,D,this.materials[4]);c("x","y",-1*k,-1,a,b,-D,this.materials[5]);(function(){for(var w=[],v=[],z=0,K=j.vertices.length;z<K;z++){for(var u=j.vertices[z],h=false,e=0,m=w.length;e<m;e++){var r=w[e];if(u.position.x==r.position.x&&u.position.y==r.position.y&&u.position.z==r.position.z){v[z]=e;h=true;break}}if(!h){v[z]=w.length;w.push(new THREE.Vertex(u.position.clone()))}}z=0;for(K=j.faces.length;z<K;z++){u=j.faces[z];u.a=v[u.a];u.b=v[u.b];u.c=v[u.c];u.d=
|
|
a,d,-s,this.materials[3]);c("x","y",1*k,-1,a,b,D,this.materials[4]);c("x","y",-1*k,-1,a,b,-D,this.materials[5]);(function(){for(var w=[],v=[],z=0,K=j.vertices.length;z<K;z++){for(var u=j.vertices[z],h=false,e=0,m=w.length;e<m;e++){var r=w[e];if(u.position.x==r.position.x&&u.position.y==r.position.y&&u.position.z==r.position.z){v[z]=e;h=true;break}}if(!h){v[z]=w.length;w.push(new THREE.Vertex(u.position.clone()))}}z=0;for(K=j.faces.length;z<K;z++){u=j.faces[z];u.a=v[u.a];u.b=v[u.b];u.c=v[u.c];u.d=
|