Browse Source

Synced with mrdoob's branch.

alteredq 14 years ago
parent
commit
e10d8c6680
3 changed files with 13 additions and 9 deletions
  1. 6 6
      build/ThreeExtras.js
  2. 2 3
      examples/materials.html
  3. 5 0
      src/extras/GeometryUtils.js

+ 6 - 6
build/ThreeExtras.js

@@ -165,12 +165,12 @@ u.set(w.m);A.set(h.matrix.flatten())};this.loadMatrices=function(h){c.uniformMat
 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,i){if(h){!i||i=="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)}};
 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,i){if(h){!i||i=="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)}};
 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};
 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};
 THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
 THREE.RenderableLine=function(){this.z=null;this.v1=new THREE.Vertex;this.v2=new THREE.Vertex;this.material=null};
-var GeometryUtils={merge:function(a,b){var d=b instanceof THREE.Mesh,e=a.vertices.length,f=d?b.geometry:b,j=a.vertices,k=f.vertices,g=a.faces,o=f.faces,c=a.uvs;f=f.uvs;d&&b.updateMatrix();for(var s=0,F=k.length;s<F;s++){var r=new THREE.Vertex(k[s].position.clone());d&&b.matrix.transformVector3(r.position);j.push(r)}s=0;for(F=o.length;s<F;s++){d=o[s];var w;k=d.vertexNormals;if(d instanceof THREE.Face3)w=new THREE.Face3(d.a+e,d.b+e,d.c+e);else if(d instanceof THREE.Face4)w=new THREE.Face4(d.a+e,d.b+
-e,d.c+e,d.d+e);d=0;for(j=k.length;d<j;d++){r=k[d];w.vertexNormals.push(r.clone())}g.push(w)}s=0;for(F=f.length;s<F;s++){e=f[s];g=[];d=0;for(j=e.length;d<j;d++)g.push(new THREE.UV(e[d].u,e[d].v));c.push(g)}}},ImageUtils={loadTexture:function(a,b){var d=new THREE.Texture(null,b),e=new Image;e.onload=function(){d.image=this;d.loaded=true};e.src=a;return d},loadArray:function(a){var b,d,e=[];b=e.loadCount=0;for(d=a.length;b<d;++b){e[b]=new Image;e[b].loaded=0;e[b].onload=function(){e.loadCount+=1;this.loaded=
-1};e[b].src=a[b]}return e}},SceneUtils={addMesh:function(a,b,d,e,f,j,k,g,o,c){b=new THREE.Mesh(b,c);b.scale.x=b.scale.y=b.scale.z=d;b.position.x=e;b.position.y=f;b.position.z=j;b.rotation.x=k;b.rotation.y=g;b.rotation.z=o;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,d){d=new THREE.MeshCubeMaterial({env_map:d});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),d);a.addObject(b);return b},addPanoramaCube:function(a,b,d){var e=[];e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));
-e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[4])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));mesh=new THREE.Mesh(new Cube(b,b,b,1,1,e,true),new THREE.MeshFaceMaterial);a.addObject(mesh);return mesh},addPanoramaCubePlanes:function(a,b,d){var e=b/2;b=new Plane(b,
-b);var f=Math.PI/2,j=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-e,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));SceneUtils.addMesh(a,b,1,-e,0,0,0,f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));SceneUtils.addMesh(a,b,1,e,0,0,0,-f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));SceneUtils.addMesh(a,b,1,0,e,0,f,0,j,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));SceneUtils.addMesh(a,b,1,0,-e,0,-f,0,j,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}",
+var GeometryUtils={merge:function(a,b){var d=b instanceof THREE.Mesh,e=a.vertices.length,f=d?b.geometry:b,j=a.vertices,k=f.vertices,g=a.faces,o=f.faces,c=a.uvs;f=f.uvs;d&&b.updateMatrix();for(var s=0,F=k.length;s<F;s++){var r=new THREE.Vertex(k[s].position.clone());d&&b.matrix.transformVector3(r.position);j.push(r)}s=0;for(F=o.length;s<F;s++){k=o[s];var w,v=k.vertexNormals;if(k instanceof THREE.Face3)w=new THREE.Face3(k.a+e,k.b+e,k.c+e);else if(k instanceof THREE.Face4)w=new THREE.Face4(k.a+e,k.b+
+e,k.c+e,k.d+e);w.centroid.copy(k.centroid);w.normal.copy(k.normal);d=0;for(j=v.length;d<j;d++){r=v[d];w.vertexNormals.push(r.clone())}w.material=k.material.slice();g.push(w)}s=0;for(F=f.length;s<F;s++){e=f[s];g=[];d=0;for(j=e.length;d<j;d++)g.push(new THREE.UV(e[d].u,e[d].v));c.push(g)}}},ImageUtils={loadTexture:function(a,b){var d=new THREE.Texture(null,b),e=new Image;e.onload=function(){d.image=this;d.loaded=true};e.src=a;return d},loadArray:function(a){var b,d,e=[];b=e.loadCount=0;for(d=a.length;b<
+d;++b){e[b]=new Image;e[b].loaded=0;e[b].onload=function(){e.loadCount+=1;this.loaded=1};e[b].src=a[b]}return e}},SceneUtils={addMesh:function(a,b,d,e,f,j,k,g,o,c){b=new THREE.Mesh(b,c);b.scale.x=b.scale.y=b.scale.z=d;b.position.x=e;b.position.y=f;b.position.z=j;b.rotation.x=k;b.rotation.y=g;b.rotation.z=o;a.addObject(b);return b},addPanoramaCubeWebGL:function(a,b,d){d=new THREE.MeshCubeMaterial({env_map:d});b=new THREE.Mesh(new Cube(b,b,b,1,1,null,true),d);a.addObject(b);return b},addPanoramaCube:function(a,
+b,d){var e=[];e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[3])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[4])}));e.push(new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));mesh=new THREE.Mesh(new Cube(b,b,b,1,1,e,true),new THREE.MeshFaceMaterial);a.addObject(mesh);
+return mesh},addPanoramaCubePlanes:function(a,b,d){var e=b/2;b=new Plane(b,b);var f=Math.PI/2,j=Math.PI;SceneUtils.addMesh(a,b,1,0,0,-e,0,0,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[5])}));SceneUtils.addMesh(a,b,1,-e,0,0,0,f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[0])}));SceneUtils.addMesh(a,b,1,e,0,0,0,-f,0,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[1])}));SceneUtils.addMesh(a,b,1,0,e,0,f,0,j,new THREE.MeshBasicMaterial({map:new THREE.Texture(d[2])}));SceneUtils.addMesh(a,
+b,1,0,-e,0,-f,0,j,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}",
 vertex_shader:"uniform 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}"}}},
 vertex_shader:"uniform 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,e,f,j,k){function g(w,v,y,L,u,A,n,h){var i=e||1,p=f||1,x=i+1,m=p+1;u=u/i;A=A/p;var l=o.vertices.length,E;if(w=="x"&&v=="y"||w=="y"&&v=="x")E="z";else if(w=="x"&&v=="z"||w=="z"&&v=="x")E="y";else if(w=="z"&&v=="y"||w=="y"&&v=="z")E="x";for(iy=0;iy<m;iy++)for(ix=0;ix<x;ix++){var B=new THREE.Vector3;B[w]=(ix*u-c)*y;B[v]=(iy*A-s)*L;B[E]=n;o.vertices.push(new THREE.Vertex(B))}for(iy=0;iy<p;iy++)for(ix=0;ix<i;ix++){o.faces.push(new THREE.Face4(ix+x*iy+l,ix+x*(iy+1)+l,ix+1+x*(iy+1)+l,
 Cube=function(a,b,d,e,f,j,k){function g(w,v,y,L,u,A,n,h){var i=e||1,p=f||1,x=i+1,m=p+1;u=u/i;A=A/p;var l=o.vertices.length,E;if(w=="x"&&v=="y"||w=="y"&&v=="x")E="z";else if(w=="x"&&v=="z"||w=="z"&&v=="x")E="y";else if(w=="z"&&v=="y"||w=="y"&&v=="z")E="x";for(iy=0;iy<m;iy++)for(ix=0;ix<x;ix++){var B=new THREE.Vector3;B[w]=(ix*u-c)*y;B[v]=(iy*A-s)*L;B[E]=n;o.vertices.push(new THREE.Vertex(B))}for(iy=0;iy<p;iy++)for(ix=0;ix<i;ix++){o.faces.push(new THREE.Face4(ix+x*iy+l,ix+x*(iy+1)+l,ix+1+x*(iy+1)+l,
 ix+1+x*iy+l,null,h));o.uvs.push([new THREE.UV(ix/i,iy/p),new THREE.UV(ix/i,(iy+1)/p),new THREE.UV((ix+1)/i,(iy+1)/p),new THREE.UV((ix+1)/i,iy/p)])}}THREE.Geometry.call(this);var o=this,c=a/2,s=b/2,F=d/2;k=k?-1:1;if(j!==undefined)if(j instanceof Array)this.materials=j;else{this.materials=[];for(var r=0;r<6;r++)this.materials.push([j])}else this.materials=[];g("z","y",1*k,-1,d,b,-c,this.materials[0]);g("z","y",-1*k,-1,d,b,c,this.materials[1]);g("x","z",1*k,1,a,d,s,this.materials[2]);g("x","z",1*k,-1,
 ix+1+x*iy+l,null,h));o.uvs.push([new THREE.UV(ix/i,iy/p),new THREE.UV(ix/i,(iy+1)/p),new THREE.UV((ix+1)/i,(iy+1)/p),new THREE.UV((ix+1)/i,iy/p)])}}THREE.Geometry.call(this);var o=this,c=a/2,s=b/2,F=d/2;k=k?-1:1;if(j!==undefined)if(j instanceof Array)this.materials=j;else{this.materials=[];for(var r=0;r<6;r++)this.materials.push([j])}else this.materials=[];g("z","y",1*k,-1,d,b,-c,this.materials[0]);g("z","y",-1*k,-1,d,b,c,this.materials[1]);g("x","z",1*k,1,a,d,s,this.materials[2]);g("x","z",1*k,-1,

+ 2 - 3
examples/materials.html

@@ -155,9 +155,8 @@
 
 
 				}
 				}
 
 
-				//particleLight = new THREE.Particle( new THREE.ParticleCircleMaterial( { color: 0xffffff } ) );
-				//particleLight.scale.x = particleLight.scale.y = particleLight.scale.z = 4;
-				particleLight = new THREE.Mesh( new Sphere( 4, 8, 8 ), new THREE.MeshBasicMaterial( { color: 0xffffff } ) );
+				particleLight = new THREE.Particle( new THREE.ParticleCircleMaterial( { color: 0xffffff } ) );
+				particleLight.scale.x = particleLight.scale.y = particleLight.scale.z = 4;
 				scene.addObject( particleLight );
 				scene.addObject( particleLight );
 
 
 				// Lights
 				// Lights

+ 5 - 0
src/extras/GeometryUtils.js

@@ -43,6 +43,9 @@ var GeometryUtils = {
 
 
 			}
 			}
 
 
+			faceCopy.centroid.copy( face.centroid );
+			faceCopy.normal.copy( face.normal );
+
 			for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
 			for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
 
 
 				normal = faceVertexNormals[ j ];
 				normal = faceVertexNormals[ j ];
@@ -50,6 +53,8 @@ var GeometryUtils = {
 
 
 			}
 			}
 
 
+			faceCopy.material = face.material.slice();
+
 			faces1.push( faceCopy );
 			faces1.push( faceCopy );
 
 
 		}
 		}