Jump to content

problem to apply diffuse color to imported mesh


vahith
 Share

Recommended Posts

hi all;
i am trying to apply diffuse color to imported mesh. actually i am importing same meshes two time, Here i am applying first mesh is red color, second imported mesh is blue color. but here it applied all the meshes in blue color. so how i can achieve this. kindly suggest me
here i attached my playground what i tried

http://www.babylonjs-playground.com/#VMFNH#24

Link to comment
Share on other sites

Hi again, Vahith!

 

http://www.babylonjs-playground.com/#VMFNH#27

 

I just replaced the .materials on both skulls with new StandardMaterials, and now each can have a separate .diffuseColor more easily. 

 

If you want to know WHY your method didn't work, I don't have a good answer.  It SEEMS as if skull2 material was an "instance" of skull1 material, even though both skulls were imported with separate importMesh commands.  I tried some material cloning and binding operations, too, but I failed at those attempts. 

 

Strange, but maybe it's normal.  It might have something to do with both skulls using materials with identical names.  *shrug*

 

There are much more experienced mesh importers than I, nearby.  They will know what the story is, and hopefully tell us.  :)

 

As a last note, you might want to check-on the existence of camera.ellipsoid.  If it ever did exist, it now appears to have been replaced by camera.collisionRadius which you have properly set.  Be well!

Link to comment
Share on other sites

hi wingnut tanks for your response..

but imported mesh contains more then one material how i can apply..?
for eg

i am having like this

"materials":[{"name":"dc_1.body_color","id":"dc_1.body_color","ambient":[1,1,1],"diffuse":[0.8,0.8,0.8],"specular":[0.1647,0.1647,0.1647],"emissive":[0,0,0],"specularPower":50,"alpha":1,"backFaceCulling":true},{"name":"dc_1.door_color","id":"dc_1.door_color","ambient":[0.8,0.8,0.8],"diffuse":[0.64,0.64,0.64],"specular":[0.5,0.5,0.5],"emissive":[0,0,0],"specularPower":50,"alpha":1,"backFaceCulling":true},{"name":"dc_1.handle_color","id":"dc_1.handle_color","ambient":[0.8,0.8,0.8],"diffuse":[0.64,0.64,0.64],"specular":[0.5,0.5,0.5],"emissive":[0,0,0],"specularPower":50,"alpha":1,"backFaceCulling":true},{"name":"dc_1.leg_color","id":"dc_1.leg_color","ambient":[0.3176,0.3176,0.3176],"diffuse":[0.2541,0.2541,0.2541],"specular":[0.1647,0.1647,0.1647],"emissive":[0,0,0],"specularPower":50,"alpha":1,"backFaceCulling":true},{"name":"dc_1.skirting_color","id":"dc_1.skirting_color","ambient":[0.8,0.8,0.8],"diffuse":[0.64,0.64,0.64],"specular":[0.5,0.5,0.5],"emissive":[0,0,0],"specularPower":50,"alpha":1,"backFaceCulling":true}],

you mean each material i can store into new StandardMaterials..?


 

Link to comment
Share on other sites

Hi

 

In your first example, two materials had the same name.

 

After you loaded skull1, you did...

newMeshes[0].getScene().getMaterialByID("default material").diffuseColor=new BABYLON.Color3(1,0,0);

Essentially the same as...

scene.getMaterialByID("default material").diffuseColor=new BABYLON.Color3(1,0,0);

Then you loaded skull2, and then did this...

newMeshes[0].getScene().getMaterialByID("default material").diffuseColor=new BABYLON.Color3(0,0,1);

Both materials turned blue because they are the SAME material, I suspect.

 

In your latest post/example, none of your materials have identical names  (unless you are trying to import 2 or more of them).

 

So, all of these will work fine:

newMeshes[0].getScene().getMaterialByID("dc_1.body_color").diffuseColor=new BABYLON.Color3(1,0,0);newMeshes[0].getScene().getMaterialByID("dc_1.door_color").diffuseColor=new BABYLON.Color3(1,1,0);newMeshes[0].getScene().getMaterialByID("dc_1.handle_color").diffuseColor=new BABYLON.Color3(0,1,0);newMeshes[0].getScene().getMaterialByID(dc_1.leg_color").diffuseColor=new BABYLON.Color3(0,1,1);newMeshes[0].getScene().getMaterialByID("dc_1.skirting_color").diffuseColor=new BABYLON.Color3(1,0,1);

There are no name collisions, in that.  In the 2-skull example, there is a name collision/issue, I suspect.

 

IF you are trying to load multiple identical mesh (using multiple ImportMesh commands)... each with multiple materials (and then you want to make each one a different color)... it might be wiser to only load the first one, and then use mesh.clone() or mesh.instance() to create the others.  Even then, you might have problems with repeated material names.

 

IF you are loading the same mesh over and over, there is another possible way.  After you load the first mesh, change the ID of all of its materials before you load the next mesh.

newMeshes[0].getScene().getMaterialByID("dc_1.body_color").id = "dc_1.body_color_1";newMeshes[0].getScene().getMaterialByID("dc_1.door_color").id = "dc_1.door_color_1";newMeshes[0].getScene().getMaterialByID("dc_1.handle_color").id = "dc_1.handle_color_1";[...]

I added _1 to all the id's.  Then load mesh #2, and do the same thing to all of ITS id's... add _2.  Then load mesh #3 and re-ID all its materials, etc.  When you get done loading all your repeat models, each will have "personalized" their material names.  Then you should be able to change any diffuseColor on any material, because each has a collision-safe name.

 

I don't promise anything.  These are just ideas, and likely not very good ones. I'm no pro.  I'm only someone to hang around-with until the experts arrive.  :)  Possibly-useful playground

Link to comment
Share on other sites

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...