Permalink
Browse files

Removing geometry.materials and returning materials from JSONLoader.

Also, removed GeometryLoader. I'll try doing the JSONLoader to GeometryLoader change again in the future.
  • Loading branch information...
1 parent 2922ff6 commit 1abc24587ec96e9d110c0a380547794abac33a01 @mrdoob committed Nov 14, 2012
View
790 build/three.js
@@ -2954,7 +2954,7 @@ THREE.Frustum.__v1 = new THREE.Vector3();
var vertices = geometry.vertices;
var isFaceMaterial = object.material instanceof THREE.MeshFaceMaterial;
- var geometryMaterials = ( isFaceMaterial && object.material.materials.length > 0 ) ? object.material.materials : object.geometry.materials;
+ var objectMaterials = isFaceMaterial === true ? object.material.materials : null;
var side = object.material.side;
@@ -2977,7 +2977,7 @@ THREE.Frustum.__v1 = new THREE.Vector3();
var face = geometry.faces[ f ];
- var material = isFaceMaterial === true ? geometryMaterials[ face.materialIndex ] : object.material;
+ var material = isFaceMaterial === true ? objectMaterials[ face.materialIndex ] : object.material;
if ( material === undefined ) continue;
@@ -3950,7 +3950,7 @@ THREE.Projector = function() {
o, ol, v, vl, f, fl, n, nl, c, cl, u, ul, object, modelMatrix,
geometry, vertices, vertex, vertexPositionScreen,
faces, face, faceVertexNormals, normal, faceVertexUvs, uvs,
- v1, v2, v3, v4, isFaceMaterial, material, side;
+ v1, v2, v3, v4, isFaceMaterial, objectMaterials, material, side;
_face3Count = 0;
_face4Count = 0;
@@ -3991,6 +3991,7 @@ THREE.Projector = function() {
_normalMatrix.transpose();
isFaceMaterial = object.material instanceof THREE.MeshFaceMaterial;
+ objectMaterials = isFaceMaterial === true ? object.material : null;
side = object.material.side;
@@ -4015,7 +4016,7 @@ THREE.Projector = function() {
face = faces[ f ];
- material = isFaceMaterial === true ? object.material.materials[ face.materialIndex ] : object.material;
+ material = isFaceMaterial === true ? objectMaterials.materials[ face.materialIndex ] : object.material;
if ( material === undefined ) continue;
@@ -6831,16 +6832,18 @@ THREE.Loader.prototype = {
},
- initMaterials: function ( scope, materials, texturePath ) {
+ initMaterials: function ( materials, texturePath ) {
- scope.materials = [];
+ var array = [];
for ( var i = 0; i < materials.length; ++ i ) {
- scope.materials[ i ] = THREE.Loader.prototype.createMaterial( materials[ i ], texturePath );
+ array[ i ] = THREE.Loader.prototype.createMaterial( materials[ i ], texturePath );
}
+ return array;
+
},
hasNormals: function ( scope ) {
@@ -8103,8 +8106,6 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath
geometry = new THREE.Geometry(),
scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
- this.initMaterials( geometry, json.materials, texturePath );
-
parseModel( scale );
parseSkin();
@@ -8431,7 +8432,9 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath
};
- callback( geometry );
+ var materials = this.initMaterials( json.materials, texturePath );
+
+ callback( geometry, materials );
};
/**
@@ -8470,697 +8473,6 @@ THREE.LoadingMonitor = function () {
};
};
-/**
- * @author mrdoob / http://mrdoob.com/
- * @author alteredq / http://alteredqualia.com/
- */
-
-THREE.GeometryLoader = function () {
-
- THREE.EventTarget.call( this );
-
- this.crossOrigin = null;
- this.path = null;
-
-
-};
-
-THREE.GeometryLoader.prototype = {
-
- constructor: THREE.GeometryLoader,
-
- load: function ( url ) {
-
- var scope = this;
- var geometry = null;
-
- if ( scope.path === null ) {
-
- var parts = url.split( '/' ); parts.pop();
- scope.path = ( parts.length < 1 ? '.' : parts.join( '/' ) );
-
- }
-
- //
-
- var xhr = new XMLHttpRequest();
-
- xhr.addEventListener( 'load', function ( event ) {
-
- if ( event.target.responseText ) {
-
- geometry = scope.parse( JSON.parse( event.target.responseText ), monitor );
-
- } else {
-
- scope.dispatchEvent( { type: 'error', message: 'Invalid file [' + url + ']' } );
-
- }
-
- }, false );
-
- xhr.addEventListener( 'error', function () {
-
- scope.dispatchEvent( { type: 'error', message: 'Couldn\'t load URL [' + url + ']' } );
-
- }, false );
-
- xhr.open( 'GET', url, true );
- xhr.send( null );
-
- //
-
- var monitor = new THREE.LoadingMonitor();
-
- monitor.addEventListener( 'load', function ( event ) {
-
- scope.dispatchEvent( { type: 'load', content: geometry } );
-
- } );
-
- monitor.add( xhr );
-
- },
-
- parse: function ( data, monitor ) {
-
- var scope = this;
- var geometry = new THREE.Geometry();
-
- var scale = ( data.scale !== undefined ) ? 1 / data.scale : 1;
-
- // materials
-
- if ( data.materials ) {
-
- geometry.materials = [];
-
- for ( var i = 0; i < data.materials.length; ++ i ) {
-
- var m = data.materials[ i ];
-
- function isPow2( n ) {
-
- var l = Math.log( n ) / Math.LN2;
- return Math.floor( l ) == l;
-
- }
-
- function nearestPow2( n ) {
-
- var l = Math.log( n ) / Math.LN2;
- return Math.pow( 2, Math.round( l ) );
-
- }
-
- function createTexture( where, name, sourceFile, repeat, offset, wrap ) {
-
- where[ name ] = new THREE.Texture();
- where[ name ].sourceFile = sourceFile;
-
- if ( repeat ) {
-
- where[ name ].repeat.set( repeat[ 0 ], repeat[ 1 ] );
-
- if ( repeat[ 0 ] !== 1 ) where[ name ].wrapS = THREE.RepeatWrapping;
- if ( repeat[ 1 ] !== 1 ) where[ name ].wrapT = THREE.RepeatWrapping;
-
- }
-
- if ( offset ) {
-
- where[ name ].offset.set( offset[ 0 ], offset[ 1 ] );
-
- }
-
- if ( wrap ) {
-
- var wrapMap = {
-
- "repeat": THREE.RepeatWrapping,
- "mirror": THREE.MirroredRepeatWrapping
-
- }
-
- if ( wrapMap[ wrap[ 0 ] ] !== undefined ) where[ name ].wrapS = wrapMap[ wrap[ 0 ] ];
- if ( wrapMap[ wrap[ 1 ] ] !== undefined ) where[ name ].wrapT = wrapMap[ wrap[ 1 ] ];
-
- }
-
- // load image
-
- var texture = where[ name ];
-
- var loader = new THREE.ImageLoader();
- loader.addEventListener( 'load', function ( event ) {
-
- var image = event.content;
-
- if ( !isPow2( image.width ) || !isPow2( image.height ) ) {
-
- var width = nearestPow2( image.width );
- var height = nearestPow2( image.height );
-
- texture.image = document.createElement( 'canvas' );
- texture.image.width = width;
- texture.image.height = height;
- texture.image.getContext( '2d' ).drawImage( image, 0, 0, width, height );
-
- } else {
-
- texture.image = image;
-
- }
-
- texture.needsUpdate = true;
-
- } );
- loader.crossOrigin = scope.crossOrigin;
- loader.load( scope.path + '/' + sourceFile );
-
- if ( monitor ) monitor.add( loader );
-
- }
-
- function rgb2hex( rgb ) {
-
- return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
-
- }
-
- // defaults
-
- var mtype = "MeshLambertMaterial";
- var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
-
- // parameters from model file
-
- if ( m.shading ) {
-
- var shading = m.shading.toLowerCase();
-
- if ( shading === "phong" ) mtype = "MeshPhongMaterial";
- else if ( shading === "basic" ) mtype = "MeshBasicMaterial";
-
- }
-
- if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
-
- mpars.blending = THREE[ m.blending ];
-
- }
-
- if ( m.transparent !== undefined || m.opacity < 1.0 ) {
-
- mpars.transparent = m.transparent;
-
- }
-
- if ( m.depthTest !== undefined ) {
-
- mpars.depthTest = m.depthTest;
-
- }
-
- if ( m.depthWrite !== undefined ) {
-
- mpars.depthWrite = m.depthWrite;
-
- }
-
- if ( m.vertexColors !== undefined ) {
-
- if ( m.vertexColors == "face" ) {
-
- mpars.vertexColors = THREE.FaceColors;
-
- } else if ( m.vertexColors ) {
-
- mpars.vertexColors = THREE.VertexColors;
-
- }
-
- }
-
- // colors
-
- if ( m.colorDiffuse ) {
-
- mpars.color = rgb2hex( m.colorDiffuse );
-
- } else if ( m.DbgColor ) {
-
- mpars.color = m.DbgColor;
-
- }
-
- if ( m.colorSpecular ) {
-
- mpars.specular = rgb2hex( m.colorSpecular );
-
- }
-
- if ( m.colorAmbient ) {
-
- mpars.ambient = rgb2hex( m.colorAmbient );
-
- }
-
- // modifiers
-
- if ( m.transparency ) {
-
- mpars.opacity = m.transparency;
-
- }
-
- if ( m.specularCoef ) {
-
- mpars.shininess = m.specularCoef;
-
- }
-
- if ( m.visible !== undefined ) {
-
- mpars.visible = m.visible;
-
- }
-
- if ( m.flipSided !== undefined ) {
-
- mpars.side = THREE.BackSide;
-
- }
-
- if ( m.doubleSided !== undefined ) {
-
- mpars.side = THREE.DoubleSide;
-
- }
-
- if ( m.wireframe !== undefined ) {
-
- mpars.wireframe = m.wireframe;
-
- }
-
- // textures
-
- if ( m.mapDiffuse ) {
-
- createTexture( mpars, "map", m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap );
-
- }
-
- if ( m.mapLight ) {
-
- createTexture( mpars, "lightMap", m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap );
-
- }
-
- if ( m.mapBump ) {
-
- createTexture( mpars, "bumpMap", m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap );
-
- }
-
- if ( m.mapNormal ) {
-
- createTexture( mpars, "normalMap", m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap );
-
- }
-
- if ( m.mapSpecular ) {
-
- createTexture( mpars, "specularMap", m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap );
-
- }
-
- // special case for normal mapped material
-
- if ( m.mapNormal ) {
-
- var shader = THREE.ShaderUtils.lib[ "normal" ];
- var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
-
- uniforms[ "tNormal" ].value = mpars.normalMap;
-
- if ( m.mapNormalFactor ) {
-
- uniforms[ "uNormalScale" ].value.set( m.mapNormalFactor, m.mapNormalFactor );
-
- }
-
- if ( mpars.map ) {
-
- uniforms[ "tDiffuse" ].value = mpars.map;
- uniforms[ "enableDiffuse" ].value = true;
-
- }
-
- if ( mpars.specularMap ) {
-
- uniforms[ "tSpecular" ].value = mpars.specularMap;
- uniforms[ "enableSpecular" ].value = true;
-
- }
-
- if ( mpars.lightMap ) {
-
- uniforms[ "tAO" ].value = mpars.lightMap;
- uniforms[ "enableAO" ].value = true;
-
- }
-
- // for the moment don't handle displacement texture
-
- uniforms[ "uDiffuseColor" ].value.setHex( mpars.color );
- uniforms[ "uSpecularColor" ].value.setHex( mpars.specular );
- uniforms[ "uAmbientColor" ].value.setHex( mpars.ambient );
-
- uniforms[ "uShininess" ].value = mpars.shininess;
-
- if ( mpars.opacity !== undefined ) {
-
- uniforms[ "uOpacity" ].value = mpars.opacity;
-
- }
-
- var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
- var material = new THREE.ShaderMaterial( parameters );
-
- } else {
-
- var material = new THREE[ mtype ]( mpars );
-
- }
-
- if ( m.DbgName !== undefined ) material.name = m.DbgName;
-
- geometry.materials[ i ] = material;
-
- }
-
- }
-
- // geometry
-
- function isBitSet( value, position ) {
-
- return value & ( 1 << position );
-
- }
-
- var faces = data.faces;
- var vertices = data.vertices;
- var normals = data.normals;
- var colors = data.colors;
- var nUvLayers = 0;
-
- // disregard empty arrays
-
- if ( data.uvs ) {
-
- for ( var i = 0; i < data.uvs.length; i ++ ) {
-
- if ( data.uvs[ i ].length ) nUvLayers ++;
-
- }
-
- }
-
- for ( var i = 0; i < nUvLayers; i ++ ) {
-
- geometry.faceUvs[ i ] = [];
- geometry.faceVertexUvs[ i ] = [];
-
- }
-
- var offset = 0;
- var zLength = vertices.length;
-
- while ( offset < zLength ) {
-
- var vertex = new THREE.Vector3();
-
- vertex.x = vertices[ offset ++ ] * scale;
- vertex.y = vertices[ offset ++ ] * scale;
- vertex.z = vertices[ offset ++ ] * scale;
-
- geometry.vertices.push( vertex );
-
- }
-
- offset = 0;
- zLength = faces.length;
-
- while ( offset < zLength ) {
-
- var type = faces[ offset ++ ];
-
- var isQuad = isBitSet( type, 0 );
-
- var hasMaterial = isBitSet( type, 1 );
- var hasFaceUv = isBitSet( type, 2 );
- var hasFaceVertexUv = isBitSet( type, 3 );
- var hasFaceNormal = isBitSet( type, 4 );
- var hasFaceVertexNormal = isBitSet( type, 5 );
- var hasFaceColor = isBitSet( type, 6 );
- var hasFaceVertexColor = isBitSet( type, 7 );
-
- // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceUv, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
-
- if ( isQuad ) {
-
- var face = new THREE.Face4();
-
- face.a = faces[ offset ++ ];
- face.b = faces[ offset ++ ];
- face.c = faces[ offset ++ ];
- face.d = faces[ offset ++ ];
-
- var nVertices = 4;
-
- } else {
-
- var face = new THREE.Face3();
-
- face.a = faces[ offset ++ ];
- face.b = faces[ offset ++ ];
- face.c = faces[ offset ++ ];
-
- var nVertices = 3;
-
- }
-
- if ( hasMaterial ) {
-
- var materialIndex = faces[ offset ++ ];
- face.materialIndex = materialIndex;
-
- }
-
- // to get face <=> uv index correspondence
-
- var fi = geometry.faces.length;
-
- if ( hasFaceUv ) {
-
- for ( var i = 0; i < nUvLayers; i ++ ) {
-
- var uvLayer = data.uvs[ i ];
-
- var uvIndex = faces[ offset ++ ];
-
- var u = uvLayer[ uvIndex * 2 ];
- var v = uvLayer[ uvIndex * 2 + 1 ];
-
- geometry.faceUvs[ i ][ fi ] = new THREE.UV( u, v );
-
- }
-
- }
-
- if ( hasFaceVertexUv ) {
-
- for ( var i = 0; i < nUvLayers; i ++ ) {
-
- var uvLayer = data.uvs[ i ];
-
- var uvs = [];
-
- for ( var j = 0; j < nVertices; j ++ ) {
-
- var uvIndex = faces[ offset ++ ];
-
- var u = uvLayer[ uvIndex * 2 ];
- var v = uvLayer[ uvIndex * 2 + 1 ];
-
- uvs[ j ] = new THREE.UV( u, v );
-
- }
-
- geometry.faceVertexUvs[ i ][ fi ] = uvs;
-
- }
-
- }
-
- if ( hasFaceNormal ) {
-
- var normalIndex = faces[ offset ++ ] * 3;
-
- var normal = new THREE.Vector3();
-
- normal.x = normals[ normalIndex ++ ];
- normal.y = normals[ normalIndex ++ ];
- normal.z = normals[ normalIndex ];
-
- face.normal = normal;
-
- }
-
- if ( hasFaceVertexNormal ) {
-
- for ( i = 0; i < nVertices; i ++ ) {
-
- var normalIndex = faces[ offset ++ ] * 3;
-
- var normal = new THREE.Vector3();
-
- normal.x = normals[ normalIndex ++ ];
- normal.y = normals[ normalIndex ++ ];
- normal.z = normals[ normalIndex ];
-
- face.vertexNormals.push( normal );
-
- }
-
- }
-
-
- if ( hasFaceColor ) {
-
- var colorIndex = faces[ offset ++ ];
-
- face.color = new THREE.Color( colors[ colorIndex ] );
-
- }
-
-
- if ( hasFaceVertexColor ) {
-
- for ( var i = 0; i < nVertices; i ++ ) {
-
- var colorIndex = faces[ offset ++ ];
-
- face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
-
- }
-
- }
-
- geometry.faces.push( face );
-
- }
-
-
- // skin
-
- if ( data.skinWeights ) {
-
- for ( var i = 0, l = data.skinWeights.length; i < l; i += 2 ) {
-
- var x = data.skinWeights[ i ];
- var y = data.skinWeights[ i + 1 ];
- var z = 0;
- var w = 0;
-
- geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
-
- }
-
- }
-
- if ( data.skinIndices ) {
-
- for ( var i = 0, l = data.skinIndices.length; i < l; i += 2 ) {
-
- var a = data.skinIndices[ i ];
- var b = data.skinIndices[ i + 1 ];
- var c = 0;
- var d = 0;
-
- geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
-
- }
-
- }
-
- geometry.bones = data.bones;
- geometry.animation = data.animation;
-
-
- // morphing
-
- if ( data.morphTargets ) {
-
- for ( var i = 0, l = data.morphTargets.length; i < l; i ++ ) {
-
- geometry.morphTargets[ i ] = {};
- geometry.morphTargets[ i ].name = data.morphTargets[ i ].name;
- geometry.morphTargets[ i ].vertices = [];
-
- var dstVertices = geometry.morphTargets[ i ].vertices;
- var srcVertices = data.morphTargets [ i ].vertices;
-
- for( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
-
- var vertex = new THREE.Vector3();
- vertex.x = srcVertices[ v ] * scale;
- vertex.y = srcVertices[ v + 1 ] * scale;
- vertex.z = srcVertices[ v + 2 ] * scale;
-
- dstVertices.push( vertex );
-
- }
-
- }
-
- }
-
- if ( data.morphColors ) {
-
- for ( var i = 0, l = data.morphColors.length; i < l; i++ ) {
-
- geometry.morphColors[ i ] = {};
- geometry.morphColors[ i ].name = data.morphColors[ i ].name;
- geometry.morphColors[ i ].colors = [];
-
- var dstColors = geometry.morphColors[ i ].colors;
- var srcColors = data.morphColors [ i ].colors;
-
- for ( var c = 0, cl = srcColors.length; c < cl; c += 3 ) {
-
- var color = new THREE.Color( 0xffaa00 );
- color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
-
- dstColors.push( color );
-
- }
-
- }
-
- }
-
- geometry.computeCentroids();
- geometry.computeFaceNormals();
-
- return geometry;
-
- }
-
-};
/**
* @author alteredq / http://alteredqualia.com/
*/
@@ -17043,23 +16355,9 @@ THREE.WebGLRenderer = function ( parameters ) {
function getBufferMaterial( object, geometryGroup ) {
- if ( object.material instanceof THREE.MeshFaceMaterial ) {
-
- if ( object.material.materials.length > 0 ) {
-
- return object.material.materials[ geometryGroup.materialIndex ];
-
- } else {
-
- return object.geometry.materials[ geometryGroup.materialIndex ];
-
- }
-
- } else {
-
- return object.material;
-
- }
+ return object.material instanceof THREE.MeshFaceMaterial
+ ? object.material.materials[ geometryGroup.materialIndex ]
+ : object.material;
};
@@ -20321,15 +19619,7 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( materialIndex >= 0 ) {
- if ( meshMaterial.materials.length > 0 ) {
-
- material = meshMaterial.materials[ materialIndex ];
-
- } else {
-
- material = object.geometry.materials[ materialIndex ];
-
- }
+ material = meshMaterial.materials[ materialIndex ];
if ( material.transparent ) {
@@ -23504,6 +22794,7 @@ THREE.GeometryUtils = {
uvs1 = geometry1.faceVertexUvs[ 0 ],
uvs2 = geometry2.faceVertexUvs[ 0 ];
+ /*
var geo1MaterialsMap = {};
for ( var i = 0; i < geometry1.materials.length; i ++ ) {
@@ -23513,6 +22804,7 @@ THREE.GeometryUtils = {
geo1MaterialsMap[ id ] = i;
}
+ */
if ( object2 instanceof THREE.Mesh ) {
@@ -23638,13 +22930,15 @@ THREE.GeometryUtils = {
faces = geometry.faces,
uvs = geometry.faceVertexUvs[ 0 ];
+ /*
// materials
if ( geometry.materials ) {
cloneGeo.materials = geometry.materials.slice();
}
+ */
// vertices
@@ -34917,7 +34211,7 @@ THREE.ShadowMapPlugin = function ( ) {
// while rendering depth map
// need to deal with MeshFaceMaterial somehow
- // in that case just use the first of geometry.materials for now
+ // in that case just use the first of material.materials for now
// (proper solution would require to break objects by materials
// similarly to regular rendering and then set corresponding
// depth materials per each chunk instead of just once per object)
@@ -35132,23 +34426,9 @@ THREE.ShadowMapPlugin = function ( ) {
function getObjectMaterial( object ) {
- if ( object.material instanceof THREE.MeshFaceMaterial ) {
-
- if ( object.material.materials.length > 0 ) {
-
- return object.material.materials[ 0 ];
-
- } else {
-
- return object.geometry.materials[ 0 ];
-
- }
-
- } else {
-
- return object.material;
-
- }
+ return object.material instanceof THREE.MeshFaceMaterial
+ ? object.material.materials[ 0 ]
+ : object.material;
};
@@ -35664,23 +34944,9 @@ THREE.DepthPassPlugin = function ( ) {
function getObjectMaterial( object ) {
- if ( object.material instanceof THREE.MeshFaceMaterial ) {
-
- if ( object.material.materials.length > 0 ) {
-
- return object.material.materials[ 0 ];
-
- } else {
-
- return object.geometry.materials[ 0 ];
-
- }
-
- } else {
-
- return object.material;
-
- }
+ return object.material instanceof THREE.MeshFaceMaterial
+ ? object.material.materials[ 0 ]
+ : object.material;
};
View
724 build/three.min.js
356 additions, 368 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
11 examples/webgl_loader_json_blender.html
@@ -89,19 +89,17 @@
// Add Blender exported Collada model
- var loader = new THREE.GeometryLoader();
- loader.addEventListener( 'load', function ( event ) {
-
- var geometry = event.content;
+ var loader = new THREE.JSONLoader();
+ loader.load( 'models/animated/monster/monster.js', function ( geometry, materials ) {
// adjust color a bit
- var material = geometry.materials[ 0 ];
+ var material = materials[ 0 ];
material.morphTargets = true;
material.color.setHex( 0xffaaaa );
material.ambient.setHex( 0x222222 );
- var faceMaterial = new THREE.MeshFaceMaterial();
+ var faceMaterial = new THREE.MeshFaceMaterial( materials );
for ( var i = 0; i < 729; i ++ ) {
@@ -140,7 +138,6 @@
}
} );
- loader.load( 'models/animated/monster/monster.js' );
// Add the COLLADA
View
5 src/core/Projector.js
@@ -174,7 +174,7 @@ THREE.Projector = function() {
o, ol, v, vl, f, fl, n, nl, c, cl, u, ul, object, modelMatrix,
geometry, vertices, vertex, vertexPositionScreen,
faces, face, faceVertexNormals, normal, faceVertexUvs, uvs,
- v1, v2, v3, v4, isFaceMaterial, material, side;
+ v1, v2, v3, v4, isFaceMaterial, objectMaterials, material, side;
_face3Count = 0;
_face4Count = 0;
@@ -215,6 +215,7 @@ THREE.Projector = function() {
_normalMatrix.transpose();
isFaceMaterial = object.material instanceof THREE.MeshFaceMaterial;
+ objectMaterials = isFaceMaterial === true ? object.material : null;
side = object.material.side;
@@ -239,7 +240,7 @@ THREE.Projector = function() {
face = faces[ f ];
- material = isFaceMaterial === true ? object.material.materials[ face.materialIndex ] : object.material;
+ material = isFaceMaterial === true ? objectMaterials.materials[ face.materialIndex ] : object.material;
if ( material === undefined ) continue;
View
4 src/core/Ray.js
@@ -110,7 +110,7 @@
var vertices = geometry.vertices;
var isFaceMaterial = object.material instanceof THREE.MeshFaceMaterial;
- var geometryMaterials = ( isFaceMaterial && object.material.materials.length > 0 ) ? object.material.materials : object.geometry.materials;
+ var objectMaterials = isFaceMaterial === true ? object.material.materials : null;
var side = object.material.side;
@@ -133,7 +133,7 @@
var face = geometry.faces[ f ];
- var material = isFaceMaterial === true ? geometryMaterials[ face.materialIndex ] : object.material;
+ var material = isFaceMaterial === true ? objectMaterials[ face.materialIndex ] : object.material;
if ( material === undefined ) continue;
View
4 src/extras/GeometryUtils.js
@@ -20,6 +20,7 @@ THREE.GeometryUtils = {
uvs1 = geometry1.faceVertexUvs[ 0 ],
uvs2 = geometry2.faceVertexUvs[ 0 ];
+ /*
@mrdoob
Owner
mrdoob added a line comment Nov 14, 2012

@alteredq I wonder if we shouldn't just leave the GeometryUtils.merge() without handling materialIndex/materials...

@mrdoob
Owner
mrdoob added a line comment Nov 14, 2012

This commit 41aa5e3 is a good example of why I'm suggesting this.

You knew that GeometryUtils.merge() would sort out the materialIndex, but it's not very intuitive. Right now GeometryUtils.merge() leaves the indices as they are and the resulting code is more understandable as Geometry.merge() is now just merging values.

Also, I don't think the previous behaviour would have allowed me to do this kind of stuff (which I think it's pretty neat):
https://github.com/mrdoob/three.js/blob/dev/examples/webgl_geometry_minecraft.html#L93-173

@alteredq
alteredq added a line comment Nov 14, 2012

Aha, so instead of trying to preserve materials from the original geometries, it would be about specifying indices into final materials array in the merged geometry.

So far sounds good, I still have to absorb the rest of commits, a lot of changes at once ;)

If we can make minecraft AO working, other things should be solvable. That's probably the most complex use case of geometry materials and merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
var geo1MaterialsMap = {};
for ( var i = 0; i < geometry1.materials.length; i ++ ) {
@@ -29,6 +30,7 @@ THREE.GeometryUtils = {
geo1MaterialsMap[ id ] = i;
}
+ */
if ( object2 instanceof THREE.Mesh ) {
@@ -154,13 +156,15 @@ THREE.GeometryUtils = {
faces = geometry.faces,
uvs = geometry.faceVertexUvs[ 0 ];
+ /*
// materials
if ( geometry.materials ) {
cloneGeo.materials = geometry.materials.slice();
}
+ */
// vertices
View
20 src/extras/renderers/plugins/DepthPassPlugin.js
@@ -196,23 +196,9 @@ THREE.DepthPassPlugin = function ( ) {
function getObjectMaterial( object ) {
- if ( object.material instanceof THREE.MeshFaceMaterial ) {
-
- if ( object.material.materials.length > 0 ) {
-
- return object.material.materials[ 0 ];
-
- } else {
-
- return object.geometry.materials[ 0 ];
-
- }
-
- } else {
-
- return object.material;
-
- }
+ return object.material instanceof THREE.MeshFaceMaterial
+ ? object.material.materials[ 0 ]
+ : object.material;
};
View
22 src/extras/renderers/plugins/ShadowMapPlugin.js
@@ -265,7 +265,7 @@ THREE.ShadowMapPlugin = function ( ) {
// while rendering depth map
// need to deal with MeshFaceMaterial somehow
- // in that case just use the first of geometry.materials for now
+ // in that case just use the first of material.materials for now
// (proper solution would require to break objects by materials
// similarly to regular rendering and then set corresponding
// depth materials per each chunk instead of just once per object)
@@ -480,23 +480,9 @@ THREE.ShadowMapPlugin = function ( ) {
function getObjectMaterial( object ) {
- if ( object.material instanceof THREE.MeshFaceMaterial ) {
-
- if ( object.material.materials.length > 0 ) {
-
- return object.material.materials[ 0 ];
-
- } else {
-
- return object.geometry.materials[ 0 ];
-
- }
-
- } else {
-
- return object.material;
-
- }
+ return object.material instanceof THREE.MeshFaceMaterial
+ ? object.material.materials[ 0 ]
+ : object.material;
};
View
691 src/loaders/GeometryLoader.js
@@ -1,691 +0,0 @@
-/**
- * @author mrdoob / http://mrdoob.com/
- * @author alteredq / http://alteredqualia.com/
- */
-
-THREE.GeometryLoader = function () {
-
- THREE.EventTarget.call( this );
-
- this.crossOrigin = null;
- this.path = null;
-
-
-};
-
-THREE.GeometryLoader.prototype = {
-
- constructor: THREE.GeometryLoader,
-
- load: function ( url ) {
-
- var scope = this;
- var geometry = null;
-
- if ( scope.path === null ) {
-
- var parts = url.split( '/' ); parts.pop();
- scope.path = ( parts.length < 1 ? '.' : parts.join( '/' ) );
-
- }
-
- //
-
- var xhr = new XMLHttpRequest();
-
- xhr.addEventListener( 'load', function ( event ) {
-
- if ( event.target.responseText ) {
-
- geometry = scope.parse( JSON.parse( event.target.responseText ), monitor );
-
- } else {
-
- scope.dispatchEvent( { type: 'error', message: 'Invalid file [' + url + ']' } );
-
- }
-
- }, false );
-
- xhr.addEventListener( 'error', function () {
-
- scope.dispatchEvent( { type: 'error', message: 'Couldn\'t load URL [' + url + ']' } );
-
- }, false );
-
- xhr.open( 'GET', url, true );
- xhr.send( null );
-
- //
-
- var monitor = new THREE.LoadingMonitor();
-
- monitor.addEventListener( 'load', function ( event ) {
-
- scope.dispatchEvent( { type: 'load', content: geometry } );
-
- } );
-
- monitor.add( xhr );
-
- },
-
- parse: function ( data, monitor ) {
-
- var scope = this;
- var geometry = new THREE.Geometry();
-
- var scale = ( data.scale !== undefined ) ? 1 / data.scale : 1;
-
- // materials
-
- if ( data.materials ) {
-
- geometry.materials = [];
-
- for ( var i = 0; i < data.materials.length; ++ i ) {
-
- var m = data.materials[ i ];
-
- function isPow2( n ) {
-
- var l = Math.log( n ) / Math.LN2;
- return Math.floor( l ) == l;
-
- }
-
- function nearestPow2( n ) {
-
- var l = Math.log( n ) / Math.LN2;
- return Math.pow( 2, Math.round( l ) );
-
- }
-
- function createTexture( where, name, sourceFile, repeat, offset, wrap ) {
-
- where[ name ] = new THREE.Texture();
- where[ name ].sourceFile = sourceFile;
-
- if ( repeat ) {
-
- where[ name ].repeat.set( repeat[ 0 ], repeat[ 1 ] );
-
- if ( repeat[ 0 ] !== 1 ) where[ name ].wrapS = THREE.RepeatWrapping;
- if ( repeat[ 1 ] !== 1 ) where[ name ].wrapT = THREE.RepeatWrapping;
-
- }
-
- if ( offset ) {
-
- where[ name ].offset.set( offset[ 0 ], offset[ 1 ] );
-
- }
-
- if ( wrap ) {
-
- var wrapMap = {
-
- "repeat": THREE.RepeatWrapping,
- "mirror": THREE.MirroredRepeatWrapping
-
- }
-
- if ( wrapMap[ wrap[ 0 ] ] !== undefined ) where[ name ].wrapS = wrapMap[ wrap[ 0 ] ];
- if ( wrapMap[ wrap[ 1 ] ] !== undefined ) where[ name ].wrapT = wrapMap[ wrap[ 1 ] ];
-
- }
-
- // load image
-
- var texture = where[ name ];
-
- var loader = new THREE.ImageLoader();
- loader.addEventListener( 'load', function ( event ) {
-
- var image = event.content;
-
- if ( !isPow2( image.width ) || !isPow2( image.height ) ) {
-
- var width = nearestPow2( image.width );
- var height = nearestPow2( image.height );
-
- texture.image = document.createElement( 'canvas' );
- texture.image.width = width;
- texture.image.height = height;
- texture.image.getContext( '2d' ).drawImage( image, 0, 0, width, height );
-
- } else {
-
- texture.image = image;
-
- }
-
- texture.needsUpdate = true;
-
- } );
- loader.crossOrigin = scope.crossOrigin;
- loader.load( scope.path + '/' + sourceFile );
-
- if ( monitor ) monitor.add( loader );
-
- }
-
- function rgb2hex( rgb ) {
-
- return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
-
- }
-
- // defaults
-
- var mtype = "MeshLambertMaterial";
- var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
-
- // parameters from model file
-
- if ( m.shading ) {
-
- var shading = m.shading.toLowerCase();
-
- if ( shading === "phong" ) mtype = "MeshPhongMaterial";
- else if ( shading === "basic" ) mtype = "MeshBasicMaterial";
-
- }
-
- if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
-
- mpars.blending = THREE[ m.blending ];
-
- }
-
- if ( m.transparent !== undefined || m.opacity < 1.0 ) {
-
- mpars.transparent = m.transparent;
-
- }
-
- if ( m.depthTest !== undefined ) {
-
- mpars.depthTest = m.depthTest;
-
- }
-
- if ( m.depthWrite !== undefined ) {
-
- mpars.depthWrite = m.depthWrite;
-
- }
-
- if ( m.vertexColors !== undefined ) {
-
- if ( m.vertexColors == "face" ) {
-
- mpars.vertexColors = THREE.FaceColors;
-
- } else if ( m.vertexColors ) {
-
- mpars.vertexColors = THREE.VertexColors;
-
- }
-
- }
-
- // colors
-
- if ( m.colorDiffuse ) {
-
- mpars.color = rgb2hex( m.colorDiffuse );
-
- } else if ( m.DbgColor ) {
-
- mpars.color = m.DbgColor;
-
- }
-
- if ( m.colorSpecular ) {
-
- mpars.specular = rgb2hex( m.colorSpecular );
-
- }
-
- if ( m.colorAmbient ) {
-
- mpars.ambient = rgb2hex( m.colorAmbient );
-
- }
-
- // modifiers
-
- if ( m.transparency ) {
-
- mpars.opacity = m.transparency;
-
- }
-
- if ( m.specularCoef ) {
-
- mpars.shininess = m.specularCoef;
-
- }
-
- if ( m.visible !== undefined ) {
-
- mpars.visible = m.visible;
-
- }
-
- if ( m.flipSided !== undefined ) {
-
- mpars.side = THREE.BackSide;
-
- }
-
- if ( m.doubleSided !== undefined ) {
-
- mpars.side = THREE.DoubleSide;
-
- }
-
- if ( m.wireframe !== undefined ) {
-
- mpars.wireframe = m.wireframe;
-
- }
-
- // textures
-
- if ( m.mapDiffuse ) {
-
- createTexture( mpars, "map", m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap );
-
- }
-
- if ( m.mapLight ) {
-
- createTexture( mpars, "lightMap", m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap );
-
- }
-
- if ( m.mapBump ) {
-
- createTexture( mpars, "bumpMap", m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap );
-
- }
-
- if ( m.mapNormal ) {
-
- createTexture( mpars, "normalMap", m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap );
-
- }
-
- if ( m.mapSpecular ) {
-
- createTexture( mpars, "specularMap", m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap );
-
- }
-
- // special case for normal mapped material
-
- if ( m.mapNormal ) {
-
- var shader = THREE.ShaderUtils.lib[ "normal" ];
- var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
-
- uniforms[ "tNormal" ].value = mpars.normalMap;
-
- if ( m.mapNormalFactor ) {
-
- uniforms[ "uNormalScale" ].value.set( m.mapNormalFactor, m.mapNormalFactor );
-
- }
-
- if ( mpars.map ) {
-
- uniforms[ "tDiffuse" ].value = mpars.map;
- uniforms[ "enableDiffuse" ].value = true;
-
- }
-
- if ( mpars.specularMap ) {
-
- uniforms[ "tSpecular" ].value = mpars.specularMap;
- uniforms[ "enableSpecular" ].value = true;
-
- }
-
- if ( mpars.lightMap ) {
-
- uniforms[ "tAO" ].value = mpars.lightMap;
- uniforms[ "enableAO" ].value = true;
-
- }
-
- // for the moment don't handle displacement texture
-
- uniforms[ "uDiffuseColor" ].value.setHex( mpars.color );
- uniforms[ "uSpecularColor" ].value.setHex( mpars.specular );
- uniforms[ "uAmbientColor" ].value.setHex( mpars.ambient );
-
- uniforms[ "uShininess" ].value = mpars.shininess;
-
- if ( mpars.opacity !== undefined ) {
-
- uniforms[ "uOpacity" ].value = mpars.opacity;
-
- }
-
- var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
- var material = new THREE.ShaderMaterial( parameters );
-
- } else {
-
- var material = new THREE[ mtype ]( mpars );
-
- }
-
- if ( m.DbgName !== undefined ) material.name = m.DbgName;
-
- geometry.materials[ i ] = material;
-
- }
-
- }
-
- // geometry
-
- function isBitSet( value, position ) {
-
- return value & ( 1 << position );
-
- }
-
- var faces = data.faces;
- var vertices = data.vertices;
- var normals = data.normals;
- var colors = data.colors;
- var nUvLayers = 0;
-
- // disregard empty arrays
-
- if ( data.uvs ) {
-
- for ( var i = 0; i < data.uvs.length; i ++ ) {
-
- if ( data.uvs[ i ].length ) nUvLayers ++;
-
- }
-
- }
-
- for ( var i = 0; i < nUvLayers; i ++ ) {
-
- geometry.faceUvs[ i ] = [];
- geometry.faceVertexUvs[ i ] = [];
-
- }
-
- var offset = 0;
- var zLength = vertices.length;
-
- while ( offset < zLength ) {
-
- var vertex = new THREE.Vector3();
-
- vertex.x = vertices[ offset ++ ] * scale;
- vertex.y = vertices[ offset ++ ] * scale;
- vertex.z = vertices[ offset ++ ] * scale;
-
- geometry.vertices.push( vertex );
-
- }
-
- offset = 0;
- zLength = faces.length;
-
- while ( offset < zLength ) {
-
- var type = faces[ offset ++ ];
-
- var isQuad = isBitSet( type, 0 );
-
- var hasMaterial = isBitSet( type, 1 );
- var hasFaceUv = isBitSet( type, 2 );
- var hasFaceVertexUv = isBitSet( type, 3 );
- var hasFaceNormal = isBitSet( type, 4 );
- var hasFaceVertexNormal = isBitSet( type, 5 );
- var hasFaceColor = isBitSet( type, 6 );
- var hasFaceVertexColor = isBitSet( type, 7 );
-
- // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceUv, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
-
- if ( isQuad ) {
-
- var face = new THREE.Face4();
-
- face.a = faces[ offset ++ ];
- face.b = faces[ offset ++ ];
- face.c = faces[ offset ++ ];
- face.d = faces[ offset ++ ];
-
- var nVertices = 4;
-
- } else {
-
- var face = new THREE.Face3();
-
- face.a = faces[ offset ++ ];
- face.b = faces[ offset ++ ];
- face.c = faces[ offset ++ ];
-
- var nVertices = 3;
-
- }
-
- if ( hasMaterial ) {
-
- var materialIndex = faces[ offset ++ ];
- face.materialIndex = materialIndex;
-
- }
-
- // to get face <=> uv index correspondence
-
- var fi = geometry.faces.length;
-
- if ( hasFaceUv ) {
-
- for ( var i = 0; i < nUvLayers; i ++ ) {
-
- var uvLayer = data.uvs[ i ];
-
- var uvIndex = faces[ offset ++ ];
-
- var u = uvLayer[ uvIndex * 2 ];
- var v = uvLayer[ uvIndex * 2 + 1 ];
-
- geometry.faceUvs[ i ][ fi ] = new THREE.UV( u, v );
-
- }
-
- }
-
- if ( hasFaceVertexUv ) {
-
- for ( var i = 0; i < nUvLayers; i ++ ) {
-
- var uvLayer = data.uvs[ i ];
-
- var uvs = [];
-
- for ( var j = 0; j < nVertices; j ++ ) {
-
- var uvIndex = faces[ offset ++ ];
-
- var u = uvLayer[ uvIndex * 2 ];
- var v = uvLayer[ uvIndex * 2 + 1 ];
-
- uvs[ j ] = new THREE.UV( u, v );
-
- }
-
- geometry.faceVertexUvs[ i ][ fi ] = uvs;
-
- }
-
- }
-
- if ( hasFaceNormal ) {
-
- var normalIndex = faces[ offset ++ ] * 3;
-
- var normal = new THREE.Vector3();
-
- normal.x = normals[ normalIndex ++ ];
- normal.y = normals[ normalIndex ++ ];
- normal.z = normals[ normalIndex ];
-
- face.normal = normal;
-
- }
-
- if ( hasFaceVertexNormal ) {
-
- for ( i = 0; i < nVertices; i ++ ) {
-
- var normalIndex = faces[ offset ++ ] * 3;
-
- var normal = new THREE.Vector3();
-
- normal.x = normals[ normalIndex ++ ];
- normal.y = normals[ normalIndex ++ ];
- normal.z = normals[ normalIndex ];
-
- face.vertexNormals.push( normal );
-
- }
-
- }
-
-
- if ( hasFaceColor ) {
-
- var colorIndex = faces[ offset ++ ];
-
- face.color = new THREE.Color( colors[ colorIndex ] );
-
- }
-
-
- if ( hasFaceVertexColor ) {
-
- for ( var i = 0; i < nVertices; i ++ ) {
-
- var colorIndex = faces[ offset ++ ];
-
- face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
-
- }
-
- }
-
- geometry.faces.push( face );
-
- }
-
-
- // skin
-
- if ( data.skinWeights ) {
-
- for ( var i = 0, l = data.skinWeights.length; i < l; i += 2 ) {
-
- var x = data.skinWeights[ i ];
- var y = data.skinWeights[ i + 1 ];
- var z = 0;
- var w = 0;
-
- geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
-
- }
-
- }
-
- if ( data.skinIndices ) {
-
- for ( var i = 0, l = data.skinIndices.length; i < l; i += 2 ) {
-
- var a = data.skinIndices[ i ];
- var b = data.skinIndices[ i + 1 ];
- var c = 0;
- var d = 0;
-
- geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
-
- }
-
- }
-
- geometry.bones = data.bones;
- geometry.animation = data.animation;
-
-
- // morphing
-
- if ( data.morphTargets ) {
-
- for ( var i = 0, l = data.morphTargets.length; i < l; i ++ ) {
-
- geometry.morphTargets[ i ] = {};
- geometry.morphTargets[ i ].name = data.morphTargets[ i ].name;
- geometry.morphTargets[ i ].vertices = [];
-
- var dstVertices = geometry.morphTargets[ i ].vertices;
- var srcVertices = data.morphTargets [ i ].vertices;
-
- for( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
-
- var vertex = new THREE.Vector3();
- vertex.x = srcVertices[ v ] * scale;
- vertex.y = srcVertices[ v + 1 ] * scale;
- vertex.z = srcVertices[ v + 2 ] * scale;
-
- dstVertices.push( vertex );
-
- }
-
- }
-
- }
-
- if ( data.morphColors ) {
-
- for ( var i = 0, l = data.morphColors.length; i < l; i++ ) {
-
- geometry.morphColors[ i ] = {};
- geometry.morphColors[ i ].name = data.morphColors[ i ].name;
- geometry.morphColors[ i ].colors = [];
-
- var dstColors = geometry.morphColors[ i ].colors;
- var srcColors = data.morphColors [ i ].colors;
-
- for ( var c = 0, cl = srcColors.length; c < cl; c += 3 ) {
-
- var color = new THREE.Color( 0xffaa00 );
- color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
-
- dstColors.push( color );
-
- }
-
- }
-
- }
-
- geometry.computeCentroids();
- geometry.computeFaceNormals();
-
- return geometry;
-
- }
-
-};
View
6 src/loaders/JSONLoader.js
@@ -96,8 +96,6 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath
geometry = new THREE.Geometry(),
scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
- this.initMaterials( geometry, json.materials, texturePath );
-
parseModel( scale );
parseSkin();
@@ -424,6 +422,8 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath
};
- callback( geometry );
+ var materials = this.initMaterials( json.materials, texturePath );
+
+ callback( geometry, materials );
};
View
8 src/loaders/Loader.js
@@ -67,16 +67,18 @@ THREE.Loader.prototype = {
},
- initMaterials: function ( scope, materials, texturePath ) {
+ initMaterials: function ( materials, texturePath ) {
- scope.materials = [];
+ var array = [];
for ( var i = 0; i < materials.length; ++ i ) {
- scope.materials[ i ] = THREE.Loader.prototype.createMaterial( materials[ i ], texturePath );
+ array[ i ] = THREE.Loader.prototype.createMaterial( materials[ i ], texturePath );
}
+ return array;
+
},
hasNormals: function ( scope ) {
View
30 src/renderers/WebGLRenderer.js
@@ -890,23 +890,9 @@ THREE.WebGLRenderer = function ( parameters ) {
function getBufferMaterial( object, geometryGroup ) {
- if ( object.material instanceof THREE.MeshFaceMaterial ) {
-
- if ( object.material.materials.length > 0 ) {
-
- return object.material.materials[ geometryGroup.materialIndex ];
-
- } else {
-
- return object.geometry.materials[ geometryGroup.materialIndex ];
-
- }
-
- } else {
-
- return object.material;
-
- }
+ return object.material instanceof THREE.MeshFaceMaterial
+ ? object.material.materials[ geometryGroup.materialIndex ]
+ : object.material;
};
@@ -4168,15 +4154,7 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( materialIndex >= 0 ) {
- if ( meshMaterial.materials.length > 0 ) {
-
- material = meshMaterial.materials[ materialIndex ];
-
- } else {
-
- material = object.geometry.materials[ materialIndex ];
-
- }
+ material = meshMaterial.materials[ materialIndex ];
if ( material.transparent ) {
View
1 utils/includes/canvas.json
@@ -30,7 +30,6 @@
"../src/loaders/BinaryLoader.js",
"../src/loaders/ImageLoader.js",
"../src/loaders/JSONLoader.js",
- "../src/loaders/GeometryLoader.js",
"../src/loaders/SceneLoader.js",
"../src/loaders/TextureLoader.js",
"../src/materials/Material.js",
View
1 utils/includes/common.json
@@ -36,7 +36,6 @@
"../src/loaders/ImageLoader.js",
"../src/loaders/JSONLoader.js",
"../src/loaders/LoadingMonitor.js",
- "../src/loaders/GeometryLoader.js",
"../src/loaders/SceneLoader.js",
"../src/loaders/TextureLoader.js",
"../src/materials/Material.js",
View
1 utils/includes/webgl.json
@@ -35,7 +35,6 @@
"../src/loaders/BinaryLoader.js",
"../src/loaders/ImageLoader.js",
"../src/loaders/JSONLoader.js",
- "../src/loaders/GeometryLoader.js",
"../src/loaders/SceneLoader.js",
"../src/loaders/TextureLoader.js",
"../src/materials/Material.js",

0 comments on commit 1abc245

Please sign in to comment.