提交 b11e457e 编写于 作者: A alteredq

Fixed loading of models which were using normalmap materials inside MeshFaceMaterials.

上级 bf8bc4b0
......@@ -6846,13 +6846,11 @@ THREE.Loader.prototype = {
},
hasNormals: function ( scope ) {
needsTangents: function ( materials ) {
var m, i, il = scope.materials.length;
for( var i = 0, il = materials.length; i < il; i ++ ) {
for( i = 0; i < il; i ++ ) {
m = scope.materials[ i ];
var m = materials[ i ];
if ( m instanceof THREE.ShaderMaterial ) return true;
......@@ -7318,7 +7316,7 @@ THREE.BinaryLoader.prototype.loadAjaxBuffers = function ( json, callback, binary
// Binary AJAX parser
THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texturePath, materials ) {
THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texturePath, jsonMaterials ) {
var Model = function ( texturePath ) {
......@@ -7399,8 +7397,6 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
this.computeCentroids();
this.computeFaceNormals();
if ( THREE.Loader.prototype.hasNormals( this ) ) this.computeTangents();
function handlePadding( n ) {
return ( n % 4 ) ? ( 4 - n % 4 ) : 0;
......@@ -7961,7 +7957,12 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
Model.prototype = Object.create( THREE.Geometry.prototype );
callback( new Model( texturePath ), this.initMaterials( materials, texturePath ) );
var geometry = new Model( texturePath );
var materials = this.initMaterials( jsonMaterials, texturePath );
if ( this.needsTangents( materials ) ) geometry.computeTangents();
callback( geometry, materials );
};
/**
......@@ -8111,9 +8112,6 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath
geometry.computeCentroids();
geometry.computeFaceNormals();
if ( this.hasNormals( geometry ) ) geometry.computeTangents();
function parseModel( scale ) {
function isBitSet( value, position ) {
......@@ -8431,6 +8429,8 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath
var materials = this.initMaterials( json.materials, texturePath );
if ( this.needsTangents( materials ) ) geometry.computeTangents();
callback( geometry, materials );
};
......@@ -8706,16 +8706,10 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
if ( geometry ) {
var hasNormals = false;
var needsTangents = false;
material = result.materials[ o.material ];
hasNormals = material instanceof THREE.ShaderMaterial;
if ( hasNormals ) {
geometry.computeTangents();
}
needsTangents = material instanceof THREE.ShaderMaterial;
p = o.position;
r = o.rotation;
......@@ -8746,6 +8740,22 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
}
if ( material instanceof THREE.MeshFaceMaterial ) {
for ( var i = 0; i < material.materials.length; i ++ ) {
needsTangents = needsTangents || ( material.materials[ i ] instanceof THREE.ShaderMaterial );
}
}
if ( needsTangents ) {
geometry.computeTangents();
}
if ( o.skin ) {
object = new THREE.SkinnedMesh( geometry, material );
......
此差异已折叠。
......@@ -116,7 +116,7 @@ THREE.BinaryLoader.prototype.loadAjaxBuffers = function ( json, callback, binary
// Binary AJAX parser
THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texturePath, materials ) {
THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texturePath, jsonMaterials ) {
var Model = function ( texturePath ) {
......@@ -197,8 +197,6 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
this.computeCentroids();
this.computeFaceNormals();
if ( THREE.Loader.prototype.hasNormals( this ) ) this.computeTangents();
function handlePadding( n ) {
return ( n % 4 ) ? ( 4 - n % 4 ) : 0;
......@@ -759,6 +757,11 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
Model.prototype = Object.create( THREE.Geometry.prototype );
callback( new Model( texturePath ), this.initMaterials( materials, texturePath ) );
var geometry = new Model( texturePath );
var materials = this.initMaterials( jsonMaterials, texturePath );
if ( this.needsTangents( materials ) ) geometry.computeTangents();
callback( geometry, materials );
};
......@@ -104,9 +104,6 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath
geometry.computeCentroids();
geometry.computeFaceNormals();
if ( this.hasNormals( geometry ) ) geometry.computeTangents();
function parseModel( scale ) {
function isBitSet( value, position ) {
......@@ -424,6 +421,8 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath
var materials = this.initMaterials( json.materials, texturePath );
if ( this.needsTangents( materials ) ) geometry.computeTangents();
callback( geometry, materials );
};
......@@ -81,13 +81,11 @@ THREE.Loader.prototype = {
},
hasNormals: function ( scope ) {
needsTangents: function ( materials ) {
var m, i, il = scope.materials.length;
for( var i = 0, il = materials.length; i < il; i ++ ) {
for( i = 0; i < il; i ++ ) {
m = scope.materials[ i ];
var m = materials[ i ];
if ( m instanceof THREE.ShaderMaterial ) return true;
......
......@@ -234,16 +234,10 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
if ( geometry ) {
var hasNormals = false;
var needsTangents = false;
material = result.materials[ o.material ];
hasNormals = material instanceof THREE.ShaderMaterial;
if ( hasNormals ) {
geometry.computeTangents();
}
needsTangents = material instanceof THREE.ShaderMaterial;
p = o.position;
r = o.rotation;
......@@ -274,6 +268,22 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
}
if ( material instanceof THREE.MeshFaceMaterial ) {
for ( var i = 0; i < material.materials.length; i ++ ) {
needsTangents = needsTangents || ( material.materials[ i ] instanceof THREE.ShaderMaterial );
}
}
if ( needsTangents ) {
geometry.computeTangents();
}
if ( o.skin ) {
object = new THREE.SkinnedMesh( geometry, material );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册