Zahir Junejo Posted September 6, 2016 Share Posted September 6, 2016 Hi fellow Babylonians, I tried to import a mesh of a boat, but i want to change the color of its material. I cannot change it for some reason. here is the part of code: let boat = new BABYLON.AbstractMesh("boat", scene); boatMaterial = new BABYLON.StandardMaterial("boatMat", scene); boatMaterial.diffuseColor = new BABYLON.Color3(1.0, 0.2, 0.5); BABYLON.SceneLoader.ImportMesh("", "assets/", "speedboat.babylon", scene, (meshes, particleSystems) => { meshes[0].material = boatMaterial; boat = meshes[0]; }); let boatSpeed = 1; boat.position = new BABYLON.Vector3(-10, 0, 100); But bright side, experience on babylon has been great so far. But just need help on this. Quote Link to comment Share on other sites More sharing options...
max123 Posted September 6, 2016 Share Posted September 6, 2016 Why not just use meshes[0].material.diffuseColor = new BABYLON.Color3(1.0, 0.2, 0.5); ? Unless, of course, the same material is used by other meshes. Also, why do you create an AbstractMesh variable and then reassign it to the loaded mesh? Quote Link to comment Share on other sites More sharing options...
Zahir Junejo Posted September 6, 2016 Author Share Posted September 6, 2016 I tried that but that also did not work the colour still remained grey but same thing done to skull.babylon file worked. Quote Link to comment Share on other sites More sharing options...
max123 Posted September 6, 2016 Share Posted September 6, 2016 is your meshes[0] definitely your boat mesh? I've been burnt by scene arrays' indices before Quote Link to comment Share on other sites More sharing options...
Zahir Junejo Posted September 6, 2016 Author Share Posted September 6, 2016 I guess i can relate to that. Yes meshes[0] is boat mesh because that is the only mesh in the blender version of this file. I have not done any splitting. Quote Link to comment Share on other sites More sharing options...
MarianG Posted September 6, 2016 Share Posted September 6, 2016 Maybe it has a multimaterial ? Zahir Junejo 1 Quote Link to comment Share on other sites More sharing options...
Zahir Junejo Posted September 7, 2016 Author Share Posted September 7, 2016 Yes how did you know that? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 7, 2016 Share Posted September 7, 2016 Can you call scene.debugLayer.show() ? this way you'll be able to see how many meshes are in your scene Quote Link to comment Share on other sites More sharing options...
Zahir Junejo Posted September 7, 2016 Author Share Posted September 7, 2016 Oh my god, are you David catuh? I will definitely look into scene.debuglayer.show but the problem has been solved for now. By using Meshes[0].getscene.getmaterialbyid... I was able to change colours for both materials. Thanks anyways everyone. But really, are you Mr Catuh? Quote Link to comment Share on other sites More sharing options...
jerome Posted September 8, 2016 Share Posted September 8, 2016 yes he is Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 8, 2016 Share Posted September 8, 2016 I am but why is it important? 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.