diff --git a/examples/files.js b/examples/files.js index 12619856517d81..2d87931c7b6433 100644 --- a/examples/files.js +++ b/examples/files.js @@ -347,6 +347,7 @@ var files = { "misc_controls_pointerlock", "misc_controls_trackball", "misc_controls_transform", + "misc_exporter_collada", "misc_exporter_gltf", "misc_exporter_obj", "misc_exporter_stl", diff --git a/examples/js/exporters/ColladaExporter.js b/examples/js/exporters/ColladaExporter.js index fa83fe28730b78..9733f4bc76ede1 100644 --- a/examples/js/exporters/ColladaExporter.js +++ b/examples/js/exporters/ColladaExporter.js @@ -402,28 +402,35 @@ THREE.ColladaExporter.prototype = { '' + - '' + - ( - m.map ? - '' : - `${ diffuse.r } ${ diffuse.g } ${ diffuse.b } 1` + type !== 'constant' ? + '' + + + ( + m.map ? + '' : + `${ diffuse.r } ${ diffuse.g } ${ diffuse.b } 1` + ) + + '' + : '' ) + - '' + + ( + type === 'phong' ? + `${ specular.r } ${ specular.g } ${ specular.b } 1` + - `${ specular.r } ${ specular.g } ${ specular.b } 1` + + '' + - '' + + ( + m.specularMap ? + '' : + `${ shininess }` + ) + - ( - m.specularMap ? - '' : - `${ shininess }` + '' + : '' ) + - '' + - `${ diffuse.r } ${ diffuse.g } ${ diffuse.b } 1` + `${ reflectivity }` + @@ -502,17 +509,21 @@ THREE.ColladaExporter.prototype = { // ids of the materials to bind to the geometry var matids = null; + var matidsArray = []; // get a list of materials to bind to the sub groups of the geometry. // If the amount of subgroups is greater than the materials, than reuse // the materials. var mat = o.material || new THREE.MeshBasicMaterial(); var materials = Array.isArray( mat ) ? mat : [ mat ]; - matids = new Array( geometry.groups.length ) - .fill() + if ( geometry.groups.length > materials.length ) { + matidsArray = new Array( geometry.groups.length ); + } else { + matidsArray = new Array( materials.length ) + } + matids = matidsArray.fill() .map( ( v, i ) => processMaterial( materials[ i % materials.length ] ) ); - node += `` + diff --git a/examples/misc_exporter_collada.html b/examples/misc_exporter_collada.html new file mode 100644 index 00000000000000..88cc0825c4d75d --- /dev/null +++ b/examples/misc_exporter_collada.html @@ -0,0 +1,420 @@ + + + + three.js webgl - collada exporter + + + + + +
+ three.js - the Utah Teapot
+ from Udacity Interactive 3D Graphics + +
+ + + + + + + + + + + + + + + + +