提交 90c9768b 编写于 作者: M Mr.doob

Merge remote-tracking branch 'alteredq/dev' into dev

......@@ -197,8 +197,9 @@ n.metadata=C.metadata;n&&E.createModel(n,g(j),"")}}for(s in C.textures){j=C.text
C.urlBaseType),j.mapping,a(1));if(THREE[j.minFilter]!==void 0)n.minFilter=THREE[j.minFilter];if(THREE[j.magFilter]!==void 0)n.magFilter=THREE[j.magFilter];if(j.anisotropy)n.anisotropy=j.anisotropy;if(j.repeat){n.repeat.set(j.repeat[0],j.repeat[1]);if(j.repeat[0]!==1)n.wrapS=THREE.RepeatWrapping;if(j.repeat[1]!==1)n.wrapT=THREE.RepeatWrapping}j.offset&&n.offset.set(j.offset[0],j.offset[1]);if(j.wrap){M={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};if(M[j.wrap[0]]!==void 0)n.wrapS=
M[j.wrap[0]];if(M[j.wrap[1]]!==void 0)n.wrapT=M[j.wrap[1]]}}J.textures[s]=n}for(o in C.materials){u=C.materials[o];for(I in u.parameters)if(I==="envMap"||I==="map"||I==="lightMap"||I==="bumpMap")u.parameters[I]=J.textures[u.parameters[I]];else if(I==="shading")u.parameters[I]=u.parameters[I]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(I==="blending")u.parameters[I]=u.parameters[I]in THREE?THREE[u.parameters[I]]:THREE.NormalBlending;else if(I==="combine")u.parameters[I]=u.parameters[I]==
"MixOperation"?THREE.MixOperation:THREE.MultiplyOperation;else if(I==="vertexColors")if(u.parameters[I]=="face")u.parameters[I]=THREE.FaceColors;else if(u.parameters[I])u.parameters[I]=THREE.VertexColors;if(u.parameters.opacity!==void 0&&u.parameters.opacity<1)u.parameters.transparent=true;if(u.parameters.normalMap){s=THREE.ShaderUtils.lib.normal;a=THREE.UniformsUtils.clone(s.uniforms);j=u.parameters.color;n=u.parameters.specular;M=u.parameters.ambient;c=u.parameters.shininess;a.tNormal.value=J.textures[u.parameters.normalMap];
u.parameters.normalMapFactor&&a.uNormalScale.value.set(u.parameters.normalMapFactor,u.parameters.normalMapFactor);if(u.parameters.map){a.tDiffuse.value=u.parameters.map;a.enableDiffuse.value=true}if(u.parameters.lightMap){a.tAO.value=u.parameters.lightMap;a.enableAO.value=true}if(u.parameters.specularMap){a.tSpecular.value=J.textures[u.parameters.specularMap];a.enableSpecular.value=true}a.uDiffuseColor.value.setHex(j);a.uSpecularColor.value.setHex(n);a.uAmbientColor.value.setHex(M);a.uShininess.value=
c;if(u.parameters.opacity)a.uOpacity.value=u.parameters.opacity;L=new THREE.ShaderMaterial({fragmentShader:s.fragmentShader,vertexShader:s.vertexShader,uniforms:a,lights:true,fog:true})}else L=new THREE[u.type](u.parameters);J.materials[o]=L}f(J.scene,C.objects);i.callbackSync(J);h()};THREE.TextureLoader=function(){THREE.EventTarget.call(this);this.crossOrigin=null};
u.parameters.normalScale&&a.uNormalScale.value.set(u.parameters.normalScale[0],u.parameters.normalScale[1]);if(u.parameters.map){a.tDiffuse.value=u.parameters.map;a.enableDiffuse.value=true}if(u.parameters.envMap){a.tCube.value=u.parameters.envMap;a.enableReflection.value=true;a.uReflectivity.value=u.parameters.reflectivity}if(u.parameters.lightMap){a.tAO.value=u.parameters.lightMap;a.enableAO.value=true}if(u.parameters.specularMap){a.tSpecular.value=J.textures[u.parameters.specularMap];a.enableSpecular.value=
true}if(u.parameters.displacementMap){a.tDisplacement.value=J.textures[u.parameters.displacementMap];a.enableDisplacement.value=true;a.uDisplacementBias.value=u.parameters.displacementBias;a.uDisplacementScale.value=u.parameters.displacementScale}a.uDiffuseColor.value.setHex(j);a.uSpecularColor.value.setHex(n);a.uAmbientColor.value.setHex(M);a.uShininess.value=c;if(u.parameters.opacity)a.uOpacity.value=u.parameters.opacity;L=new THREE.ShaderMaterial({fragmentShader:s.fragmentShader,vertexShader:s.vertexShader,
uniforms:a,lights:true,fog:true})}else L=new THREE[u.type](u.parameters);J.materials[o]=L}f(J.scene,C.objects);i.callbackSync(J);h()};THREE.TextureLoader=function(){THREE.EventTarget.call(this);this.crossOrigin=null};
THREE.TextureLoader.prototype={constructor:THREE.TextureLoader,load:function(a){var b=this,c=new Image;c.addEventListener("load",function(){var a=new THREE.Texture(c);a.needsUpdate=true;b.dispatchEvent({type:"load",content:a})},false);c.addEventListener("error",function(){b.dispatchEvent({type:"error",message:"Couldn't load URL ["+a+"]"})},false);if(b.crossOrigin)c.crossOrigin=b.crossOrigin;c.src=a}};
THREE.Material=function(){this.id=THREE.MaterialCount++;this.name="";this.side=THREE.FrontSide;this.opacity=1;this.transparent=false;this.blending=THREE.NormalBlending;this.blendSrc=THREE.SrcAlphaFactor;this.blendDst=THREE.OneMinusSrcAlphaFactor;this.blendEquation=THREE.AddEquation;this.depthWrite=this.depthTest=true;this.polygonOffset=false;this.alphaTest=this.polygonOffsetUnits=this.polygonOffsetFactor=0;this.overdraw=false;this.needsUpdate=this.visible=true};
THREE.Material.prototype.setValues=function(a){if(a!==void 0)for(var b in a){var c=a[b];if(c===void 0)console.warn("THREE.Material: '"+b+"' parameter is undefined.");else if(b in this){var d=this[b];d instanceof THREE.Color&&c instanceof THREE.Color?d.copy(c):d instanceof THREE.Color&&typeof c==="number"?d.setHex(c):d instanceof THREE.Vector3&&c instanceof THREE.Vector3?d.copy(c):this[b]=c}}};
......@@ -491,9 +492,9 @@ THREE.Face3){d=b.vertices[a.a];f=b.vertices[a.b];e=b.vertices[a.c];return THREE.
g[d.a];o=g[d.b];m=g[d.c];p=g[d.d];d._area1=THREE.GeometryUtils.triangleArea(j,o,p);d._area2=THREE.GeometryUtils.triangleArea(o,m,p);d._area=d._area1+d._area2}i=i+d._area;l[f]=i}d=[];for(f=0;f<b;f++){g=THREE.GeometryUtils.random()*i;g=c(g);d[f]=THREE.GeometryUtils.randomPointInFace(e[g],a,true)}return d},triangleArea:function(a,b,c){var d,f=THREE.GeometryUtils.__v1;f.sub(a,b);d=f.length();f.sub(a,c);a=f.length();f.sub(b,c);c=f.length();b=0.5*(d+a+c);return Math.sqrt(b*(b-d)*(b-a)*(b-c))},center:function(a){a.computeBoundingBox();
var b=a.boundingBox,c=new THREE.Vector3;c.add(b.min,b.max);c.multiplyScalar(-0.5);a.applyMatrix((new THREE.Matrix4).makeTranslation(c.x,c.y,c.z));a.computeBoundingBox();return c},normalizeUVs:function(a){for(var a=a.faceVertexUvs[0],b=0,c=a.length;b<c;b++)for(var d=a[b],f=0,e=d.length;f<e;f++){if(d[f].u!==1)d[f].u=d[f].u-Math.floor(d[f].u);if(d[f].v!==1)d[f].v=d[f].v-Math.floor(d[f].v)}},triangulateQuads:function(a){var b,c,d,f,e=[],g=[],h=[];b=0;for(c=a.faceUvs.length;b<c;b++)g[b]=[];b=0;for(c=a.faceVertexUvs.length;b<
c;b++)h[b]=[];b=0;for(c=a.faces.length;b<c;b++){d=a.faces[b];if(d instanceof THREE.Face4){f=d.a;var i=d.b,l=d.c,j=d.d,o=new THREE.Face3,m=new THREE.Face3;o.color.copy(d.color);m.color.copy(d.color);o.materialIndex=d.materialIndex;m.materialIndex=d.materialIndex;o.a=f;o.b=i;o.c=j;m.a=i;m.b=l;m.c=j;if(d.vertexColors.length===4){o.vertexColors[0]=d.vertexColors[0].clone();o.vertexColors[1]=d.vertexColors[1].clone();o.vertexColors[2]=d.vertexColors[3].clone();m.vertexColors[0]=d.vertexColors[1].clone();
m.vertexColors[1]=d.vertexColors[2].clone();m.vertexColors[2]=d.vertexColors[3].clone()}e.push(o,m);d=0;for(f=a.faceVertexUvs.length;d<f;d++)if(a.faceVertexUvs[d].length){o=a.faceVertexUvs[d][b];i=o[1];l=o[2];j=o[3];o=[o[0].clone(),i.clone(),j.clone()];i=[i.clone(),l.clone(),j.clone()];h[d].push(o,i)}d=0;for(f=a.faceUvs.length;d<f;d++)if(a.faceUvs[d].length){i=a.faceUvs[d][b];g[d].push(i,i)}}else{e.push(d);d=0;for(f=a.faceUvs.length;d<f;d++)g[d].push(a.faceUvs[d]);d=0;for(f=a.faceVertexUvs.length;d<
f;d++)h[d].push(a.faceVertexUvs[d])}}a.faces=e;a.faceUvs=g;a.faceVertexUvs=h;a.computeCentroids();a.computeFaceNormals();a.computeVertexNormals();a.hasTangents&&a.computeTangents()},explode:function(a){for(var b=[],c=0,d=a.faces.length;c<d;c++){var f=b.length,e=a.faces[c];if(e instanceof THREE.Face4){var g=e.a,h=e.b,i=e.c,g=a.vertices[g],h=a.vertices[h],i=a.vertices[i],l=a.vertices[e.d];b.push(g.clone());b.push(h.clone());b.push(i.clone());b.push(l.clone());e.a=f;e.b=f+1;e.c=f+2;e.d=f+3}else{g=e.a;
h=e.b;i=e.c;g=a.vertices[g];h=a.vertices[h];i=a.vertices[i];b.push(g.clone());b.push(h.clone());b.push(i.clone());e.a=f;e.b=f+1;e.c=f+2}}a.vertices=b;delete a.__tmpVertices},tessellate:function(a,b){var c,d,f,e,g,h,i,l,j,o,m,p,q,n,s,r,u,v,t,A=[],y=[];c=0;for(d=a.faceVertexUvs.length;c<d;c++)y[c]=[];c=0;for(d=a.faces.length;c<d;c++){f=a.faces[c];if(f instanceof THREE.Face3){e=f.a;g=f.b;h=f.c;l=a.vertices[e];j=a.vertices[g];o=a.vertices[h];p=l.distanceTo(j);q=j.distanceTo(o);m=l.distanceTo(o);if(p>
m.vertexColors[1]=d.vertexColors[2].clone();m.vertexColors[2]=d.vertexColors[3].clone()}e.push(o,m);d=0;for(f=a.faceVertexUvs.length;d<f;d++)if(a.faceVertexUvs[d].length){o=a.faceVertexUvs[d][b];i=o[1];l=o[2];j=o[3];o=[o[0].clone(),i.clone(),j.clone()];i=[i.clone(),l.clone(),j.clone()];h[d].push(o,i)}d=0;for(f=a.faceUvs.length;d<f;d++)if(a.faceUvs[d].length){i=a.faceUvs[d][b];g[d].push(i,i)}}else{e.push(d);d=0;for(f=a.faceUvs.length;d<f;d++)g[d].push(a.faceUvs[d][b]);d=0;for(f=a.faceVertexUvs.length;d<
f;d++)h[d].push(a.faceVertexUvs[d][b])}}a.faces=e;a.faceUvs=g;a.faceVertexUvs=h;a.computeCentroids();a.computeFaceNormals();a.computeVertexNormals();a.hasTangents&&a.computeTangents()},explode:function(a){for(var b=[],c=0,d=a.faces.length;c<d;c++){var f=b.length,e=a.faces[c];if(e instanceof THREE.Face4){var g=e.a,h=e.b,i=e.c,g=a.vertices[g],h=a.vertices[h],i=a.vertices[i],l=a.vertices[e.d];b.push(g.clone());b.push(h.clone());b.push(i.clone());b.push(l.clone());e.a=f;e.b=f+1;e.c=f+2;e.d=f+3}else{g=
e.a;h=e.b;i=e.c;g=a.vertices[g];h=a.vertices[h];i=a.vertices[i];b.push(g.clone());b.push(h.clone());b.push(i.clone());e.a=f;e.b=f+1;e.c=f+2}}a.vertices=b;delete a.__tmpVertices},tessellate:function(a,b){var c,d,f,e,g,h,i,l,j,o,m,p,q,n,s,r,u,v,t,A=[],y=[];c=0;for(d=a.faceVertexUvs.length;c<d;c++)y[c]=[];c=0;for(d=a.faces.length;c<d;c++){f=a.faces[c];if(f instanceof THREE.Face3){e=f.a;g=f.b;h=f.c;l=a.vertices[e];j=a.vertices[g];o=a.vertices[h];p=l.distanceTo(j);q=j.distanceTo(o);m=l.distanceTo(o);if(p>
b||q>b||m>b){i=a.vertices.length;v=f.clone();t=f.clone();if(p>=q&&p>=m){l=l.clone();l.lerpSelf(j,0.5);v.a=e;v.b=i;v.c=h;t.a=i;t.b=g;t.c=h;if(f.vertexNormals.length===3){e=f.vertexNormals[0].clone();e.lerpSelf(f.vertexNormals[1],0.5);v.vertexNormals[1].copy(e);t.vertexNormals[0].copy(e)}if(f.vertexColors.length===3){e=f.vertexColors[0].clone();e.lerpSelf(f.vertexColors[1],0.5);v.vertexColors[1].copy(e);t.vertexColors[0].copy(e)}f=0}else if(q>=p&&q>=m){l=j.clone();l.lerpSelf(o,0.5);v.a=e;v.b=g;v.c=
i;t.a=i;t.b=h;t.c=e;if(f.vertexNormals.length===3){e=f.vertexNormals[1].clone();e.lerpSelf(f.vertexNormals[2],0.5);v.vertexNormals[2].copy(e);t.vertexNormals[0].copy(e);t.vertexNormals[1].copy(f.vertexNormals[2]);t.vertexNormals[2].copy(f.vertexNormals[0])}if(f.vertexColors.length===3){e=f.vertexColors[1].clone();e.lerpSelf(f.vertexColors[2],0.5);v.vertexColors[2].copy(e);t.vertexColors[0].copy(e);t.vertexColors[1].copy(f.vertexColors[2]);t.vertexColors[2].copy(f.vertexColors[0])}f=1}else{l=l.clone();
l.lerpSelf(o,0.5);v.a=e;v.b=g;v.c=i;t.a=i;t.b=g;t.c=h;if(f.vertexNormals.length===3){e=f.vertexNormals[0].clone();e.lerpSelf(f.vertexNormals[2],0.5);v.vertexNormals[2].copy(e);t.vertexNormals[0].copy(e)}if(f.vertexColors.length===3){e=f.vertexColors[0].clone();e.lerpSelf(f.vertexColors[2],0.5);v.vertexColors[2].copy(e);t.vertexColors[0].copy(e)}f=2}A.push(v,t);a.vertices.push(l);e=0;for(g=a.faceVertexUvs.length;e<g;e++)if(a.faceVertexUvs[e].length){l=a.faceVertexUvs[e][c];t=l[0];h=l[1];v=l[2];if(f===
......
......@@ -151,6 +151,15 @@
"visible" : true
},
"ninja" : {
"geometry" : "NinjaLo",
"materials": [ "phong_normal" ],
"position" : [ 75, 10, -30 ],
"rotation" : [ 0, -0.5, 0 ],
"scale" : [ 1.25, 1.25, 1.25 ],
"visible" : true
},
"quad_bg" : {
"geometry" : "quad",
"materials": [ "textured_bg" ],
......@@ -269,6 +278,11 @@
"url" : "obj/walt/WaltHead_bin.js"
},
"NinjaLo": {
"type": "bin_mesh",
"url" : "obj/ninja/NinjaLo_bin.js"
},
"veyron": {
"type": "bin_mesh",
"url" : "obj/veyron/VeyronNoUv_bin.js"
......@@ -341,6 +355,11 @@
"parameters": { "color": 16711680, "specular": 16711680, "shininess": 25, "bumpMap": "texture_bump", "bumpScale": -0.75 }
},
"phong_normal": {
"type": "MeshPhongMaterial",
"parameters": { "color": 1118481, "specular": 16777215, "shininess": 25, "envMap": "cube_reflection", "reflectivity": 0.1, "lightMap": "texture_ao", "normalMap": "texture_normal", "normalScale": [ 1, -1 ], "displacementMap": "texture_displacement", "displacementScale": 2.436143, "displacementBias": -0.428408 }
},
"lambert_green": {
"type": "MeshLambertMaterial",
"parameters": { "color": 30481, "blending": "AdditiveBlending", "transparent": true }
......@@ -446,6 +465,21 @@
"anisotropy": 4
},
"texture_normal": {
"url": "textures/normal/ninja/normal.jpg",
"anisotropy": 4
},
"texture_ao": {
"url": "textures/normal/ninja/ao.jpg",
"anisotropy": 4
},
"texture_displacement": {
"url": "textures/normal/ninja/displacement.jpg",
"anisotropy": 4
},
"texture_minecraft": {
"url": "textures/minecraft/grass.png",
"magFilter": "NearestFilter",
......
......@@ -192,7 +192,7 @@
for ( m in result.materials ) {
material = result.materials[ m ];
if ( ! ( material instanceof THREE.MeshFaceMaterial ) ) {
if ( ! ( material instanceof THREE.MeshFaceMaterial || material instanceof THREE.ShaderMaterial ) ) {
if( !material.program ) {
......
......@@ -584,13 +584,13 @@ THREE.GeometryUtils = {
for ( j = 0, jl = geometry.faceUvs.length; j < jl; j ++ ) {
faceUvs[ j ].push( geometry.faceUvs[ j ] );
faceUvs[ j ].push( geometry.faceUvs[ j ][ i ] );
}
for ( j = 0, jl = geometry.faceVertexUvs.length; j < jl; j ++ ) {
faceVertexUvs[ j ].push( geometry.faceVertexUvs[ j ] );
faceVertexUvs[ j ].push( geometry.faceVertexUvs[ j ][ i ] );
}
......
......@@ -728,9 +728,9 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
uniforms[ "tNormal" ].value = result.textures[ m.parameters.normalMap ];
if ( m.parameters.normalMapFactor ) {
if ( m.parameters.normalScale ) {
uniforms[ "uNormalScale" ].value.set( m.parameters.normalMapFactor, m.parameters.normalMapFactor );
uniforms[ "uNormalScale" ].value.set( m.parameters.normalScale[ 0 ], m.parameters.normalScale[ 1 ] );
}
......@@ -741,6 +741,14 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
}
if ( m.parameters.envMap ) {
uniforms[ "tCube" ].value = m.parameters.envMap;
uniforms[ "enableReflection" ].value = true;
uniforms[ "uReflectivity" ].value = m.parameters.reflectivity;
}
if ( m.parameters.lightMap ) {
uniforms[ "tAO" ].value = m.parameters.lightMap;
......@@ -755,6 +763,16 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
}
if ( m.parameters.displacementMap ) {
uniforms[ "tDisplacement" ].value = result.textures[ m.parameters.displacementMap ];
uniforms[ "enableDisplacement" ].value = true;
uniforms[ "uDisplacementBias" ].value = m.parameters.displacementBias;
uniforms[ "uDisplacementScale" ].value = m.parameters.displacementScale;
}
uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
uniforms[ "uSpecularColor" ].value.setHex( specular );
uniforms[ "uAmbientColor" ].value.setHex( ambient );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册