浏览代码

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 年之前
父节点
当前提交
d9826e829f
共有 1 个文件被更改,包括 5 次插入0 次删除
  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 ) );
 
 			}