Jump to content

Clone method for MultiMaterial doesn't work


3Dlove
 Share

Recommended Posts

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

Link to comment
Share on other sites

Hello,

 

Thanks for your correction with subMaterials

but 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 :)

Link to comment
Share on other sites

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;
Link to comment
Share on other sites

  • 2 years later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...