Browse Source

ColladaLoader: Fallback if material doesn't match

If no material is found the loader errors.
For example when you download model as .dae from mecabricks it seems that the reference from symbol defined in the "instance_material" often doesn't match the one of the material of the linked geometry.
BUT for example Blender doesn't care and show the model with the correct materials. Even though it ignores the specification, but at least it doesn't errors. So I suggest that we still keep conform with the specification BUT if the model is a bit wrong with linking the correct materials we should at least fallback to some defined material. In my case I would fallback to the "first" (should be sorted alpha-numeric with ```Object.keys``` ) material. So the user can see that something is wrong with his materials when the model is displayed.
Pascal Häusler 7 years ago
parent
commit
d9826e829f
1 changed files with 5 additions and 0 deletions
  1. 5 0
      examples/js/loaders/ColladaLoader.js

+ 5 - 0
examples/js/loaders/ColladaLoader.js

@@ -3190,6 +3190,11 @@ THREE.ColladaLoader.prototype = {
 			for ( var i = 0, l = keys.length; i < l; i ++ ) {
 
 				var id = instanceMaterials[ keys[ i ] ];
+
+				if( id === undefined ) { // Fallback if no material matches
+					id = instanceMaterials[Object.keys(instanceMaterials)[0]] // take simply the first material 
+				}
+
 				materials.push( getMaterial( id ) );
 
 			}