Переглянути джерело

fixed my matid error, changed output file names to be unique, removed console logs

clinton 6 роки тому
батько
коміт
3d93da45d5

+ 7 - 4
examples/js/exporters/ColladaExporter.js

@@ -509,18 +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 )
-				matids = new Array( materials.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 +=
 					`<instance_geometry url="#${ meshid }">` +
 

+ 12 - 20
examples/webgl_geometry_teapot_collada.html

@@ -366,7 +366,8 @@
 			}
 
 			var exporter = new THREE.ColladaExporter();
-			function exportASCII() {
+			
+			function saveColladaFile() {
 
 				var result = exporter.parse( teapot );
 				var material_type = "Phong";
@@ -376,24 +377,14 @@
 				if ( shading === "smooth" ) {
 					material_type = "Lambert"
 				}
-				console.log(result.textures)
-				saveString( result.data, 'teapot_' + material_type + '.dae' );
+
+				saveString( result.data, 'teapot_' + shading + "_" + material_type + '.dae' );
 				result.textures.forEach( tex => {
 					saveArrayBuffer( tex.data, `${ tex.name }.${ tex.ext }` );
 				});
 
 			}
 
-			var link = document.createElement( 'a' );
-			link.style.display = 'none';
-			document.body.appendChild( link );
-
-			var savecolladabutton = document.getElementById("savecolladabutton");
-			savecolladabutton.addEventListener('click', function(){
-				exportASCII();
-			});
-
-
 			function save( blob, filename ) {
 
 				link.href = URL.createObjectURL( blob );
@@ -408,19 +399,20 @@
 
 			}
 
-			function exportBinary() {
-
-				var result = exporter.parse( mesh, { binary: true } );
-				saveArrayBuffer( result, 'box.stl' );
-
-			}
-
 			function saveArrayBuffer( buffer, filename ) {
 
 				save( new Blob( [ buffer ], { type: 'application/octet-stream' } ), filename );
 
 			}
 
+			var link = document.createElement( 'a' );
+			link.style.display = 'none';
+			document.body.appendChild( link );
+
+			var savecolladabutton = document.getElementById("savecolladabutton");
+			savecolladabutton.addEventListener('click', function(){
+				saveColladaFile();
+			});
 
 		</script>