提交 ae22b78c 编写于 作者: A alteredq

Added MorphAnimMesh. Added MathUtils.

Added morph to rendering testbed.
Simplified shadowmap shader snippet gamma handling.
上级 55e23374
此差异已折叠。
......@@ -13,7 +13,7 @@ m[f]=l}e=[];g={};for(f=0;f<b;f++)k=THREE.GeometryUtils.random()*l,k=c(k),e[f]=TH
THREE.ImageUtils={loadTexture:function(a,b,c){var e=new Image,f=new THREE.Texture(e,b);e.onload=function(){f.needsUpdate=!0;c&&c(this)};e.crossOrigin="";e.src=a;return f},loadTextureCube:function(a,b,c){var e,f=[],h=new THREE.Texture(f,b),b=f.loadCount=0;for(e=a.length;b<e;++b)f[b]=new Image,f[b].onload=function(){f.loadCount+=1;if(f.loadCount==6)h.needsUpdate=!0;c&&c(this)},f[b].crossOrigin="",f[b].src=a[b];return h},getNormalMap:function(a,b){var c=function(a){var c=Math.sqrt(a[0]*a[0]+a[1]*a[1]+
a[2]*a[2]);return[a[0]/c,a[1]/c,a[2]/c]};b|=1;var e=a.width,f=a.height,h=document.createElement("canvas");h.width=e;h.height=f;var g=h.getContext("2d");g.drawImage(a,0,0);for(var k=g.getImageData(0,0,e,f).data,l=g.createImageData(e,f),m=l.data,n=0;n<e;n++)for(var o=1;o<f;o++){var t=o-1<0?f-1:o-1,u=(o+1)%f,v=n-1<0?e-1:n-1,y=(n+1)%e,p=[],z=[0,0,k[(o*e+n)*4]/255*b];p.push([-1,0,k[(o*e+v)*4]/255*b]);p.push([-1,-1,k[(t*e+v)*4]/255*b]);p.push([0,-1,k[(t*e+n)*4]/255*b]);p.push([1,-1,k[(t*e+y)*4]/255*b]);
p.push([1,0,k[(o*e+y)*4]/255*b]);p.push([1,1,k[(u*e+y)*4]/255*b]);p.push([0,1,k[(u*e+n)*4]/255*b]);p.push([-1,1,k[(u*e+v)*4]/255*b]);t=[];v=p.length;for(u=0;u<v;u++){var y=p[u],x=p[(u+1)%v],y=[y[0]-z[0],y[1]-z[1],y[2]-z[2]],x=[x[0]-z[0],x[1]-z[1],x[2]-z[2]];t.push(c([y[1]*x[2]-y[2]*x[1],y[2]*x[0]-y[0]*x[2],y[0]*x[1]-y[1]*x[0]]))}p=[0,0,0];for(u=0;u<t.length;u++)p[0]+=t[u][0],p[1]+=t[u][1],p[2]+=t[u][2];p[0]/=t.length;p[1]/=t.length;p[2]/=t.length;z=(o*e+n)*4;m[z]=(p[0]+1)/2*255|0;m[z+1]=(p[1]+0.5)*
255|0;m[z+2]=p[2]*255|0;m[z+3]=255}g.putImageData(l,0,0);return h}};THREE.SceneUtils={showHierarchy:function(a,b){THREE.SceneUtils.traverseHierarchy(a,function(a){a.visible=b})},traverseHierarchy:function(a,b){var c,e,f=a.children.length;for(e=0;e<f;e++)c=a.children[e],b(c),THREE.SceneUtils.traverseHierarchy(c,b)}};
255|0;m[z+2]=p[2]*255|0;m[z+3]=255}g.putImageData(l,0,0);return h}};THREE.MathUtils={clamp:function(a,b,c){return a<b?b:a>c?c:a},mapLinear:function(a,b,c,e,f){return(a-b)*(f-e)/(c-b)+e}};THREE.SceneUtils={showHierarchy:function(a,b){THREE.SceneUtils.traverseHierarchy(a,function(a){a.visible=b})},traverseHierarchy:function(a,b){var c,e,f=a.children.length;for(e=0;e<f;e++)c=a.children[e],b(c),THREE.SceneUtils.traverseHierarchy(c,b)}};
if(THREE.WebGLRenderer)THREE.ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRatio:{type:"f",value:1.02},mFresnelBias:{type:"f",value:0.1},mFresnelPower:{type:"f",value:2},mFresnelScale:{type:"f",value:1},tCube:{type:"t",value:1,texture:null}},fragmentShader:"uniform samplerCube tCube;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );\nvec4 refractedColor = vec4( 1.0, 1.0, 1.0, 1.0 );\nrefractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;\nrefractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;\nrefractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;\nrefractedColor.a = 1.0;\ngl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );\n}",
vertexShader:"uniform float mRefractionRatio;\nuniform float mFresnelBias;\nuniform float mFresnelScale;\nuniform float mFresnelPower;\nvarying vec3 vReflect;\nvarying vec3 vRefract[3];\nvarying float vReflectionFactor;\nvoid main() {\nvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\nvec4 mPosition = objectMatrix * vec4( position, 1.0 );\nvec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );\nvec3 I = mPosition.xyz - cameraPosition;\nvReflect = reflect( I, nWorld );\nvRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );\nvRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );\nvRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );\nvReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );\ngl_Position = projectionMatrix * mvPosition;\n}"},
normal:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},enableSpecular:{type:"i",value:0},enableReflection:{type:"i",value:0},tDiffuse:{type:"t",value:0,texture:null},tCube:{type:"t",value:1,texture:null},tNormal:{type:"t",value:2,texture:null},tSpecular:{type:"t",value:3,texture:null},tAO:{type:"t",value:4,texture:null},tDisplacement:{type:"t",value:5,texture:null},uNormalScale:{type:"f",
......@@ -212,8 +212,8 @@ m))}function y(c){var b,e,g,h;b=f(a,c);e=f(a,c+P);g=f(a,c+T);c=D[b*2];h=D[b*2+1]
g));p.push(new THREE.UV(n,h));o.push(p)}var z=this,x=0,w,A=[],D=[],B,E,I,G,K,C,F,J,M,N,L,O,H,Q,P,T,X,R,S,W,U,Z,Y,$,V;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(z,e,c);w={signature:a.substr(x,8),header_bytes:n(a,x+8),vertex_coordinate_bytes:n(a,x+9),normal_coordinate_bytes:n(a,x+10),uv_coordinate_bytes:n(a,x+11),vertex_index_bytes:n(a,x+12),normal_index_bytes:n(a,x+13),uv_index_bytes:n(a,x+14),material_index_bytes:n(a,x+15),nvertices:f(a,x+16),nnormals:f(a,x+16+4),nuvs:f(a,x+16+
8),ntri_flat:f(a,x+16+12),ntri_smooth:f(a,x+16+16),ntri_flat_uv:f(a,x+16+20),ntri_smooth_uv:f(a,x+16+24),nquad_flat:f(a,x+16+28),nquad_smooth:f(a,x+16+32),nquad_flat_uv:f(a,x+16+36),nquad_smooth_uv:f(a,x+16+40)};x+=w.header_bytes;B=w.vertex_index_bytes;E=w.vertex_index_bytes*2;I=w.vertex_index_bytes*3;G=w.vertex_index_bytes*3+w.material_index_bytes;K=w.vertex_index_bytes*3+w.material_index_bytes+w.normal_index_bytes;C=w.vertex_index_bytes*3+w.material_index_bytes+w.normal_index_bytes*2;F=w.vertex_index_bytes;
J=w.vertex_index_bytes*2;M=w.vertex_index_bytes*3;N=w.vertex_index_bytes*4;L=w.vertex_index_bytes*4+w.material_index_bytes;O=w.vertex_index_bytes*4+w.material_index_bytes+w.normal_index_bytes;H=w.vertex_index_bytes*4+w.material_index_bytes+w.normal_index_bytes*2;Q=w.vertex_index_bytes*4+w.material_index_bytes+w.normal_index_bytes*3;P=w.uv_index_bytes;T=w.uv_index_bytes*2;X=w.uv_index_bytes;R=w.uv_index_bytes*2;S=w.uv_index_bytes*3;c=w.vertex_index_bytes*3+w.material_index_bytes;V=w.vertex_index_bytes*
4+w.material_index_bytes;W=w.ntri_flat*c;U=w.ntri_smooth*(c+w.normal_index_bytes*3);Z=w.ntri_flat_uv*(c+w.uv_index_bytes*3);Y=w.ntri_smooth_uv*(c+w.normal_index_bytes*3+w.uv_index_bytes*3);$=w.nquad_flat*V;c=w.nquad_smooth*(V+w.normal_index_bytes*4);V=w.nquad_flat_uv*(V+w.uv_index_bytes*4);x+=function(c){for(var e,h,f,k=w.vertex_coordinate_bytes*3,l=c+w.nvertices*k;c<l;c+=k)e=b(a,c),h=b(a,c+w.vertex_coordinate_bytes),f=b(a,c+w.vertex_coordinate_bytes*2),z.vertices.push(new THREE.Vertex(new THREE.Vector3(e,
h,f)));return w.nvertices*k}(x);x+=function(c){for(var b,e,g,h=w.normal_coordinate_bytes*3,f=c+w.nnormals*h;c<f;c+=h)b=m(a,c),e=m(a,c+w.normal_coordinate_bytes),g=m(a,c+w.normal_coordinate_bytes*2),A.push(b/127,e/127,g/127);return w.nnormals*h}(x);x+=function(c){for(var e,h,f=w.uv_coordinate_bytes*2,k=c+w.nuvs*f;c<k;c+=f)e=b(a,c),h=b(a,c+w.uv_coordinate_bytes),D.push(e,h);return w.nuvs*f}(x);W=x+W;U=W+U;Z=U+Z;Y=Z+Y;$=Y+$;c=$+c;V=c+V;(function(a){var c,b=w.vertex_index_bytes*3+w.material_index_bytes,
4+w.material_index_bytes;W=w.ntri_flat*c;U=w.ntri_smooth*(c+w.normal_index_bytes*3);Z=w.ntri_flat_uv*(c+w.uv_index_bytes*3);Y=w.ntri_smooth_uv*(c+w.normal_index_bytes*3+w.uv_index_bytes*3);$=w.nquad_flat*V;c=w.nquad_smooth*(V+w.normal_index_bytes*4);V=w.nquad_flat_uv*(V+w.uv_index_bytes*4);x+=function(c){for(var e,f,h,k=w.vertex_coordinate_bytes*3,l=c+w.nvertices*k;c<l;c+=k)e=b(a,c),f=b(a,c+w.vertex_coordinate_bytes),h=b(a,c+w.vertex_coordinate_bytes*2),z.vertices.push(new THREE.Vertex(new THREE.Vector3(e,
f,h)));return w.nvertices*k}(x);x+=function(c){for(var b,e,g,f=w.normal_coordinate_bytes*3,h=c+w.nnormals*f;c<h;c+=f)b=m(a,c),e=m(a,c+w.normal_coordinate_bytes),g=m(a,c+w.normal_coordinate_bytes*2),A.push(b/127,e/127,g/127);return w.nnormals*f}(x);x+=function(c){for(var e,f,h=w.uv_coordinate_bytes*2,k=c+w.nuvs*h;c<k;c+=h)e=b(a,c),f=b(a,c+w.uv_coordinate_bytes),D.push(e,f);return w.nuvs*h}(x);W=x+W;U=W+U;Z=U+Z;Y=Z+Y;$=Y+$;c=$+c;V=c+V;(function(a){var c,b=w.vertex_index_bytes*3+w.material_index_bytes,
e=b+w.uv_index_bytes*3,g=a+w.ntri_flat_uv*e;for(c=a;c<g;c+=e)o(c),y(c+b);return g-a})(U);(function(a){var c,b=w.vertex_index_bytes*3+w.material_index_bytes+w.normal_index_bytes*3,e=b+w.uv_index_bytes*3,g=a+w.ntri_smooth_uv*e;for(c=a;c<g;c+=e)t(c),y(c+b);return g-a})(Z);(function(a){var c,b=w.vertex_index_bytes*4+w.material_index_bytes,e=b+w.uv_index_bytes*4,g=a+w.nquad_flat_uv*e;for(c=a;c<g;c+=e)u(c),p(c+b);return g-a})(c);(function(a){var c,b=w.vertex_index_bytes*4+w.material_index_bytes+w.normal_index_bytes*
4,e=b+w.uv_index_bytes*4,g=a+w.nquad_smooth_uv*e;for(c=a;c<g;c+=e)v(c),p(c+b);return g-a})(V);(function(a){var c,b=w.vertex_index_bytes*3+w.material_index_bytes,e=a+w.ntri_flat*b;for(c=a;c<e;c+=b)o(c);return e-a})(x);(function(a){var c,b=w.vertex_index_bytes*3+w.material_index_bytes+w.normal_index_bytes*3,e=a+w.ntri_smooth*b;for(c=a;c<e;c+=b)t(c);return e-a})(W);(function(a){var c,b=w.vertex_index_bytes*4+w.material_index_bytes,e=a+w.nquad_flat*b;for(c=a;c<e;c+=b)u(c);return e-a})(Y);(function(a){var c,
b=w.vertex_index_bytes*4+w.material_index_bytes+w.normal_index_bytes*4,e=a+w.nquad_smooth*b;for(c=a;c<e;c+=b)v(c);return e-a})($);this.computeCentroids();this.computeFaceNormals();THREE.Loader.prototype.hasNormals(this)&&this.computeTangents()};f.prototype=new THREE.Geometry;f.prototype.constructor=f;b(new f(c))};
......
......@@ -157,7 +157,7 @@ lights_pars_fragment:"uniform vec3 ambientLightColor;\n#if MAX_DIR_LIGHTS > 0\nu
color_pars_fragment:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_fragment:"#ifdef USE_COLOR\ngl_FragColor = gl_FragColor * vec4( vColor, opacity );\n#endif",color_pars_vertex:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\n#ifdef GAMMA_INPUT\nvColor = color * color;\n#else\nvColor = color;\n#endif\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\nuniform mat4 boneGlobalMatrices[ MAX_BONES ];\n#endif",skinning_vertex:"#ifdef USE_SKINNING\ngl_Position = ( boneGlobalMatrices[ int( skinIndex.x ) ] * skinVertexA ) * skinWeight.x;\ngl_Position += ( boneGlobalMatrices[ int( skinIndex.y ) ] * skinVertexB ) * skinWeight.y;\ngl_Position = projectionMatrix * viewMatrix * objectMatrix * gl_Position;\n#endif",
morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\nuniform float morphTargetInfluences[ 8 ];\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\nvec3 morphed = vec3( 0.0, 0.0, 0.0 );\nmorphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\nmorphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\nmorphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\nmorphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\nmorphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\nmorphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\nmorphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\nmorphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\nmorphed += position;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( morphed, 1.0 );\n#endif",
default_vertex:"#ifndef USE_MORPHTARGETS\n#ifndef USE_SKINNING\ngl_Position = projectionMatrix * mvPosition;\n#endif\n#endif",shadowmap_pars_fragment:"#ifdef USE_SHADOWMAP\nuniform sampler2D shadowMap[ MAX_SHADOWS ];\nuniform float shadowDarkness;\nuniform float shadowBias;\nvarying vec4 vShadowCoord[ MAX_SHADOWS ];\nfloat unpackDepth( const in vec4 rgba_depth ) {\nconst vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\nfloat depth = dot( rgba_depth, bit_shift );\nreturn depth;\n}\n#endif",
shadowmap_fragment:"#ifdef USE_SHADOWMAP\n#ifdef SHADOWMAP_SOFT\nconst float xPixelOffset = 1.0 / SHADOWMAP_WIDTH;\nconst float yPixelOffset = 1.0 / SHADOWMAP_HEIGHT;\n#endif\nvec3 shadowColor = vec3( 1.0 );\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\nvec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\nshadowCoord.z += shadowBias;\nif ( shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0 ) {\n#ifdef SHADOWMAP_SOFT\nfloat shadow = 0.0;\nfor ( float y = -1.25; y <= 1.25; y += 1.25 )\nfor ( float x = -1.25; x <= 1.25; x += 1.25 ) {\nvec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\nfloat fDepth = unpackDepth( rgbaDepth );\nif ( fDepth < shadowCoord.z )\nshadow += 1.0;\n}\nshadow /= 9.0;\n#ifdef GAMMA_OUTPUT\nvec3 darkening = vec3( ( 1.0 - shadowDarkness * shadow ) );\ndarkening *= darkening;\nshadowColor = shadowColor * darkening;\n#else\nshadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness * shadow ) );\n#endif\n#else\nvec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\nfloat fDepth = unpackDepth( rgbaDepth );\nif ( fDepth < shadowCoord.z )\nshadowColor = shadowColor * vec3( shadowDarkness );\n#endif\n}\n}\ngl_FragColor.xyz = gl_FragColor.xyz * shadowColor;\n#endif",
shadowmap_fragment:"#ifdef USE_SHADOWMAP\n#ifdef SHADOWMAP_SOFT\nconst float xPixelOffset = 1.0 / SHADOWMAP_WIDTH;\nconst float yPixelOffset = 1.0 / SHADOWMAP_HEIGHT;\n#endif\nvec3 shadowColor = vec3( 1.0 );\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\nvec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\nshadowCoord.z += shadowBias;\nif ( shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0 ) {\n#ifdef SHADOWMAP_SOFT\nfloat shadow = 0.0;\nfor ( float y = -1.25; y <= 1.25; y += 1.25 )\nfor ( float x = -1.25; x <= 1.25; x += 1.25 ) {\nvec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\nfloat fDepth = unpackDepth( rgbaDepth );\nif ( fDepth < shadowCoord.z )\nshadow += 1.0;\n}\nshadow /= 9.0;\nshadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness * shadow ) );\n#else\nvec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\nfloat fDepth = unpackDepth( rgbaDepth );\nif ( fDepth < shadowCoord.z )\nshadowColor = shadowColor * vec3( shadowDarkness );\n#endif\n}\n}\n#ifdef GAMMA_OUTPUT\nshadowColor *= shadowColor;\n#endif\ngl_FragColor.xyz = gl_FragColor.xyz * shadowColor;\n#endif",
shadowmap_pars_vertex:"#ifdef USE_SHADOWMAP\nvarying vec4 vShadowCoord[ MAX_SHADOWS ];\nuniform mat4 shadowMatrix[ MAX_SHADOWS ];\n#endif",shadowmap_vertex:"#ifdef USE_SHADOWMAP\nfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\nvShadowCoord[ i ] = shadowMatrix[ i ] * objectMatrix * vec4( position, 1.0 );\n}\n#endif",alphatest_fragment:"#ifdef ALPHATEST\nif ( gl_FragColor.a < ALPHATEST ) discard;\n#endif",linear_to_gamma_fragment:"#ifdef GAMMA_OUTPUT\ngl_FragColor.xyz = sqrt( gl_FragColor.xyz );\n#endif"};
THREE.UniformsUtils={merge:function(b){var c,e,d,h={};for(c=0;c<b.length;c++)for(e in d=this.clone(b[c]),d)h[e]=d[e];return h},clone:function(b){var c,e,d,h={};for(c in b)for(e in h[c]={},b[c])d=b[c][e],h[c][e]=d instanceof THREE.Color||d instanceof THREE.Vector2||d instanceof THREE.Vector3||d instanceof THREE.Vector4||d instanceof THREE.Matrix4||d instanceof THREE.Texture?d.clone():d instanceof Array?d.slice():d;return h}};
THREE.UniformsLib={common:{diffuse:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:0,texture:null},offsetRepeat:{type:"v4",value:new THREE.Vector4(0,0,1,1)},lightMap:{type:"t",value:2,texture:null},envMap:{type:"t",value:1,texture:null},flipEnvMap:{type:"f",value:-1},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refractionRatio:{type:"f",value:0.98},combine:{type:"i",value:0},morphTargetInfluences:{type:"f",value:0}},fog:{fogDensity:{type:"f",
......
......@@ -88,6 +88,7 @@
<script type="text/javascript" src="../src/objects/Mesh.js"></script>
<script type="text/javascript" src="../src/objects/Bone.js"></script>
<script type="text/javascript" src="../src/objects/SkinnedMesh.js"></script>
<script type="text/javascript" src="../src/objects/MorphAnimMesh.js"></script>
<script type="text/javascript" src="../src/objects/Ribbon.js"></script>
<script type="text/javascript" src="../src/objects/LOD.js"></script>
<script type="text/javascript" src="../src/objects/Sprite.js"></script>
......@@ -110,6 +111,7 @@
<script type="text/javascript" src="../src/extras/ColorUtils.js"></script>
<script type="text/javascript" src="../src/extras/GeometryUtils.js"></script>
<script type="text/javascript" src="../src/extras/ImageUtils.js"></script>
<script type="text/javascript" src="../src/extras/MathUtils.js"></script>
<script type="text/javascript" src="../src/extras/SceneUtils.js"></script>
<script type="text/javascript" src="../src/extras/ShaderUtils.js"></script>
<script type="text/javascript" src="../src/extras/core/Curve.js"></script>
......@@ -190,6 +192,14 @@
var sunLight, pointLight, ambientLight;
var morph;
var composer, effectFXAA, hblur, vblur;
var parameters, tweenDirection, tweenDay, tweenNight;
var oldTime;
init();
animate();
......@@ -368,6 +378,31 @@
addObjectColor( new THREE.SphereGeometry( 100, 32, 26 ), 0xffffff, -300, 100, 300, 0 );
// MORPHS
var loader = new THREE.JSONLoader();
loader.load( "models/animated/sittingBox.js", function( geometry ) {
var morphMaterial = new THREE.MeshPhongMaterial( { ambient: 0x444444, color: 0x000000, specular: 0xff9900, shininess: 50, morphTargets: true } );
morphMaterial.shading = THREE.FlatShading;
//geometry.computeVertexNormals();
morph = new THREE.MorphAnimMesh( geometry, morphMaterial );
var s = 200;
morph.scale.set( s, s, s );
morph.duration = 8000;
morph.mirroredLoop = true;
morph.castShadow = true;
morph.receiveShadow = true;
scene.add( morph );
} );
// LIGHTS
var sunIntensity = 0.3,
......@@ -485,7 +520,7 @@
parameters = { control: 0 };
direction = -1;
tweenDirection = -1;
tweenDay = new TWEEN.Tween( parameters ).to( { control: 100 }, 1000 ).easing( TWEEN.Easing.Exponential.EaseOut );
tweenNight = new TWEEN.Tween( parameters ).to( { control: 0 }, 1000 ).easing( TWEEN.Easing.Exponential.EaseOut );
......@@ -522,35 +557,26 @@
switch( event.keyCode ) {
case 78: /*N*/ if ( direction == 1 ) {
case 78: /*N*/ if ( tweenDirection == 1 ) {
tweenDay.stop();
tweenNight.start();
direction = -1;
tweenDirection = -1;
} else {
tweenNight.stop();
tweenDay.start();
direction = 1;
tweenDirection = 1;
}
break;
}
};
//
function map_linear( x, sa, sb, ea, eb ) {
return ( x - sa ) * ( eb - ea ) / ( sb - sa ) + ea;
};
}
//
......@@ -565,16 +591,24 @@
function render() {
if ( oldTime === undefined ) oldTime = new Date().getTime();
var newTime = new Date().getTime();
var delta = newTime - oldTime;
oldTime = newTime;
TWEEN.update();
controls.update();
scene.fog.color.setHSV( 0.13, 0.25, map_linear( parameters.control, 0, 100, 0.1, 0.99 ) );
if ( morph ) morph.updateAnimation( delta );
scene.fog.color.setHSV( 0.13, 0.25, THREE.MathUtils.mapLinear( parameters.control, 0, 100, 0.1, 0.99 ) );
renderer.setClearColor( scene.fog.color, 1 );
sunLight.intensity = map_linear( parameters.control, 0, 100, 0.3, 1 );
pointLight.intensity = map_linear( parameters.control, 0, 100, 1, 0.5 );
sunLight.intensity = THREE.MathUtils.mapLinear( parameters.control, 0, 100, 0.3, 1 );
pointLight.intensity = THREE.MathUtils.mapLinear( parameters.control, 0, 100, 1, 0.5 );
pointLight.color.setHSV( 0.1, map_linear( parameters.control, 0, 100, 0.99, 0 ), 0.9 );
pointLight.color.setHSV( 0.1, THREE.MathUtils.mapLinear( parameters.control, 0, 100, 0.99, 0 ), 0.9 );
renderer.shadowMapDarkness = 0.5 * sunLight.intensity;
......
/**
* @author alteredq / http://alteredqualia.com/
*/
THREE.MathUtils = {
clamp: function ( x, a, b ) {
return ( x < a ) ? a : ( ( x > b ) ? b : x );
},
mapLinear: function( x, sa, sb, ea, eb ) {
return ( x - sa ) * ( eb - ea ) / ( sb - sa ) + ea;
}
};
/**
* @author alteredq / http://alteredqualia.com/
*/
THREE.MorphAnimMesh = function( geometry, materials ) {
THREE.Mesh.call( this, geometry, materials );
// API
this.duration = 1000; // milliseconds
this.mirroredLoop = false;
// internals
this.lastKeyframe = 0;
this.currentKeyframe = 0;
this.time = 0;
this.offset = 0;
this.direction = 1;
this.directionBackwards = false;
};
THREE.MorphAnimMesh.prototype = new THREE.Mesh();
THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh;
THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
var frameTime = this.duration / this.geometry.morphTargets.length;
this.time += this.direction * delta;
if ( this.mirroredLoop ) {
if ( this.time > this.duration || this.time < 0 ) {
this.direction *= -1;
if ( this.time > this.duration ) {
this.time = this.duration;
this.directionBackwards = true;
}
if ( this.time < 0 ) {
this.time = 0;
this.directionBackwards = false;
}
}
} else {
this.time = this.time % this.duration;
}
var keyframe = THREE.MathUtils.clamp( Math.floor( this.time / frameTime ), 0, this.geometry.morphTargets.length - 1 );
if ( keyframe != this.currentKeyframe ) {
this.morphTargetInfluences[ this.lastKeyframe ] = 0;
this.morphTargetInfluences[ this.currentKeyframe ] = 1;
this.morphTargetInfluences[ keyframe ] = 0;
this.lastKeyframe = this.currentKeyframe;
this.currentKeyframe = keyframe;
}
var mix = ( this.time % frameTime ) / frameTime;
if ( this.directionBackwards ) {
mix = 1 - mix;
}
this.morphTargetInfluences[ this.currentKeyframe ] = mix;
this.morphTargetInfluences[ this.lastKeyframe ] = 1 - mix;
};
......@@ -702,19 +702,7 @@ THREE.ShaderChunk = {
"}",
"shadow /= 9.0;",
"#ifdef GAMMA_OUTPUT",
"vec3 darkening = vec3( ( 1.0 - shadowDarkness * shadow ) );",
"darkening *= darkening;",
"shadowColor = shadowColor * darkening;",
"#else",
"shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness * shadow ) );",
"#endif",
"shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness * shadow ) );",
"#else",
......@@ -742,6 +730,12 @@ THREE.ShaderChunk = {
"}",
"#ifdef GAMMA_OUTPUT",
"shadowColor *= shadowColor;",
"#endif",
"gl_FragColor.xyz = gl_FragColor.xyz * shadowColor;",
"#endif"
......
......@@ -60,6 +60,7 @@ COMMON_FILES = [
'objects/Mesh.js',
'objects/Bone.js',
'objects/SkinnedMesh.js',
'objects/MorphAnimMesh.js',
'objects/Ribbon.js',
'objects/LOD.js',
'objects/Sprite.js',
......@@ -85,6 +86,7 @@ EXTRAS_FILES = [
'extras/ColorUtils.js',
'extras/GeometryUtils.js',
'extras/ImageUtils.js',
'extras/MathUtils.js',
'extras/SceneUtils.js',
'extras/ShaderUtils.js',
'extras/core/Curve.js',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册