3Dlove Posted June 24, 2015 Share Posted June 24, 2015 Hello I try to import a mesh and clone it and change diffuseColor of each clone but all mesh have the same color. Here is a code :var meh = newMeshes[0];for (var i = 0; i < 10; i++) { var clone = mesh.clone("clone"+i) //new material for each clone clone.material = mesh.material.clone('newMat'+i); clone.material.diffuseColor = new BABYLON.Color3(Math.random(), Math.random(), Math.random());}(mesh.material is a MultiMaterial I think because there are subMaterials[0] and subMaterials[1]) Thanks for your help Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted June 24, 2015 Share Posted June 24, 2015 var color = new BABYLON.Color3(Math.random(), Math.random(), Math.random()); clone.material.subMaterials[0].diffuseColor = color; clone.material.subMaterials[1].diffuseColor = color; Quote Link to comment Share on other sites More sharing options...
3Dlove Posted June 25, 2015 Author Share Posted June 25, 2015 Hello, Thanks for your correction with subMaterialsbut that is not the problem : when I clone :var mat = scene.getMeshByName('clone1').material.clone('mat');mat.subMaterials[0].diffuseColor = BABYLON.Color3.Black();all cloned meshes change their color, like if mat was a link of the material and not a clone, any ideas ? Thank you Quote Link to comment Share on other sites More sharing options...
3Dlove Posted June 25, 2015 Author Share Posted June 25, 2015 I think there is a problem with the clone function : I found the error :var subMaterial = this.subMaterials[index]; should be :var subMaterial = this.subMaterials[index].clone(this.subMaterials[index].name); =) How to report a bug for doing the correction ? Quote Link to comment Share on other sites More sharing options...
Temechon Posted June 25, 2015 Share Posted June 25, 2015 When cloning a multimaterial, it doesn't clone each submaterial : https://github.com/BabylonJS/Babylon.js/blob/master/src/Materials/babylon.multiMaterial.ts#L39 In your case, you are updating the color of a submaterial that is affected on all multimaterial. Quote Link to comment Share on other sites More sharing options...
3Dlove Posted June 25, 2015 Author Share Posted June 25, 2015 Okay, I answered just before you at 8:37 thanks Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted June 29, 2015 Share Posted June 29, 2015 I fail to see how not cloning each submaterial of a multimaterial is an expected behavior. The only member multimaterial has is the submaterial array. Seems to me that this is a bug. Otherwise, why not just copy the reference, it would do the same thing, e.g.var myCloneMulti = originalMulti; Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 30, 2015 Share Posted June 30, 2015 You can clone it in order to add new submaterials that the original does not have Quote Link to comment Share on other sites More sharing options...
pichou Posted September 25, 2017 Share Posted September 25, 2017 I had the same issue and to solve it I had to clone every material and submaterial of every mesh. So it works but I am worried it will really slow down the performance? Regards, Pichou Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 25, 2017 Share Posted September 25, 2017 Not really but it always depend on your scene 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.