Aerion Posted November 27, 2014 Share Posted November 27, 2014 Hi all. I've been working on this function for the last month, slowly trying to debug it. I have now found out the main cause to my problem. For some reason, this function is only returning 1 of the 2 materials, in this case, it is only returning the THREE.MeshBasicMaterial, and not THREE.MeshBasicMaterial AND THREE.MeshLambertMaterial. Can someone please help me make this function return BOTH materials at once?//EntityMaterial(0, 0, 0xFF44CFFC, 1, 0xFF000000, 4, 4, 0, 1.0, 0.8, "LambertBasicMaterial", 1)//The above line is the correct way to call this function.//The only 3 parameters in this function that matter when checking this code are 0xFF44CFFC, 0x00000000, //And "LambertBasicMaterial"function EntityMaterial(ptex, side, color, wire, wirecolor, col_type, col_wire_type, shading, transparent, opacity, mat_type, overdraw){ ptex = ptex || 0; side = side || 0; color = color || 0xFF006400; wire = wire || 0; wirecolor = wirecolor || 0xFF006400; col_type = col_type || 4; col_wire_type = col_wire_type || 4; shading = shading || false; transparent = transparent || 0.0; opacity = opacity || 1.0; mat_type = mat_type || "BasicMaterial"; overdraw = overdraw || true; color = decToHex(color.toString()); wirecolor = decToHex(wirecolor.toString()); var gRGBA1 = Get_RGBA(color, col_type); var gRGBA2 = Get_RGBA(wirecolor, col_wire_type); var mat = 0; if(mat_type === 'BasicMaterial') { this.materials = new THREE.MeshBasicMaterial ( { color: parseInt(gRGBA1, 16), } ) } else if(mat_type === 'LambertMaterial') { this.materials = new THREE.MeshLambertMaterial ( { color: parseInt(gRGBA2, 16), opacity: opacity, wireframe: wire, transparent: transparent } ) } else if(mat_type === 'LambertBasicMaterial') { this.materials = [ new THREE.MeshBasicMaterial ( { color: parseInt(gRGBA1, 16) } ), new THREE.MeshLambertMaterial ( { color: parseInt(gRGBA2, 16), opacity: opacity, wireframe: wire, transparent: transparent } ) ] } return this.materials;}Thank You! Sincerely, ~Mythros Quote Link to comment Share on other sites More sharing options...
Aerion Posted November 27, 2014 Author Share Posted November 27, 2014 Can someone please help me? Quote Link to comment Share on other sites More sharing options...
jpdev Posted November 27, 2014 Share Posted November 27, 2014 After quickly reading through it, this might be what you need:this.materials = []; //new empty array.. could also be written as this.materials = new Array();var basicMat = new THREE.MeshBasicMaterial ....var lamberMat = new THREE.MeshLambertMaterial ....this.materials.push(basicMat);this.materials.push(lambertMat);This results in: materials[0] is the basic Material and materials[1] is the lambert mat. Also I think you might want do this even if you only want to use one material."materials" as a vairable name (because of the plurar) implies, that it is an array. Quote Link to comment Share on other sites More sharing options...
Aerion Posted November 27, 2014 Author Share Posted November 27, 2014 Like this? Also, it's still not returning the 2nd array... else if(mat_type === 'LambertBasicMaterial') { //new empty array.. could also be written as this.materials = new Array(); this.materials = []; var mats = this.materials; var basicMat = new THREE.MeshBasicMaterial( { color: parseInt(gRGBA1, 16) } ); var lambertMat = new THREE.MeshLambertMaterial( { color: parseInt(gRGBA2, 16), opacity: opacity, wireframe: wire, transparent: transparent } ); mats.push(basicMat); mats.push(lambertMat); return mats; } Quote Link to comment Share on other sites More sharing options...
jpdev Posted November 27, 2014 Share Posted November 27, 2014 That function should definitely return an array containing the two materials. Please have a look at this fiddle (containing a very simplified version of your function) http://jsfiddle.net/rv1btjmp/ Any actually your function in the first post should return that array two.(You are creating and filling the array in one long statement instead of using push there, but it should work too.) Maybe the function itself isn't the problem? Quote Link to comment Share on other sites More sharing options...
Aerion Posted November 27, 2014 Author Share Posted November 27, 2014 Well, here's how it gets called in the HTML file: function addTube() { var value = document.getElementById('dropdown').value; var segments = parseInt(document.getElementById('segments').value); closed2 = document.getElementById('closed').checked; var radiusSegments = parseInt(document.getElementById('radiusSegments').value); console.log('adding tube', value, closed2, radiusSegments); if (mesh) parent.remove(mesh); extrudePath = splines[value]; tube = new THREE.TubeGeometry(extrudePath, segments, 2, radiusSegments, closed2); addGeometry(tube); setScale(tube); } function addGeometry( geometry ) { this.materials = EntityMaterial(0, 0, 0xFF44CFFC, 1, 0xFF000000, 4, 4, 0, 1.0, 0.8, "LambertBasicMaterial", 1) this.mesh = THREE.SceneUtils.createMultiMaterialObject ( geometry, this.materials ) parent.add( this.mesh ); return this.mesh; } Quote Link to comment Share on other sites More sharing options...
Aerion Posted November 28, 2014 Author Share Posted November 28, 2014 Can someone please help? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.