Dad72 Posted November 19, 2013 Share Posted November 19, 2013 Hello, How can we change the material of a model that was being loaded which has already a material.I would like to replace the existing material by another material in wireframe mode.Thank You Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 19, 2013 Share Posted November 19, 2013 Just call mesh.material = myNewMaterial Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 19, 2013 Author Share Posted November 19, 2013 It does not work.I fact:BABYLON.SceneLoader.ImportMesh(Name, CheminModeles, Fichier, scene, function (newMeshes, particleSystems, skeletons){ if(newMeshes[0]) { modele = newMeshes[0]; var myNewMaterial = new BABYLON.StandardMaterial("wireframe", scene); myNewMaterial.wireframe = true; modele.material = myNewMaterial; scene.activeCamera.attachControl(container); }});The model has always its textures by default to display. Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 19, 2013 Share Posted November 19, 2013 It should work with your code. Is there anything in the javascript console ? Can you share more of your code please ? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 19, 2013 Author Share Posted November 19, 2013 In the console i have constantly: UnknownError (5 error babylon.js (ligne 20)) ...terialsIds .push(subMatId);parseMaterialById(subMatId,parseData,scene,rootURL);}... More codefunction init(CheminModeles, Fichier, Name) { var engine = new BABYLON.Engine(container, true); scene = new BABYLON.Scene(engine); BABYLON.SceneLoader.ImportMesh(Name, CheminModeles, Fichier, scene, function (newMeshes, particleSystems, skeletons) { if(newMeshes[0]) { modele = newMeshes[0]; modele.rotation.y = 0; modele.position = new BABYLON.Vector3(0, 0, 0); var myNewMaterial = new BABYLON.StandardMaterial("wireframe", scene); myNewMaterial.wireframe = true; modele.material = myNewMaterial; scene.activeCamera.attachControl(container); } }); camera = new BABYLON.ArcRotateCamera("Camera", 1.52, 1.52, 150, new BABYLON.Vector3(0, 35, 0), scene); light = new BABYLON.HemisphericLight("Hemi0", new BABYLON.Vector3(0, 1, 0), scene); light.diffuse = new BABYLON.Color3(1, 1, 1); light.specular = new BABYLON.Color3(1, 1, 1); light.groundColor = new BABYLON.Color3(0, 0, 0); engine.runRenderLoop(function () { scene.render(); }); } Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 19, 2013 Share Posted November 19, 2013 This code should work correctly. I just tested it quickly and everything is correct for me. The function Importmesh import the mesh called "Name" and all its submeshes. Are you sure the material is updated on the correct mesh and not one of its children ? You can display the updated mesh name to be sure (console.log(modele.id)) in your callback function. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 19, 2013 Author Share Posted November 19, 2013 In console.log (modele.id) return:a67642f6-d8e2-405c-ac73-deab1df21da5 I used the models 'Dude' of samples project and I rename the file name by him.Babylonfor the 'name' of the function init(), i retrieves the name of the file. I have not understood this:Are you sure the material is updated on the correct mesh and not one of its children ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 19, 2013 Share Posted November 19, 2013 newMeshes[0] is a dummy object. It is the parent of the visual mesh. Just change to newMeshes[1] Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 19, 2013 Author Share Posted November 19, 2013 Thank You Deltakosh, it works. By contrast I have always these errors in the console that has no effect, but is on each load models. UnknownError (5 error babylon.js (ligne 20))...terialsIds .push(subMatId);parseMaterialById(subMatId,parseData,scene,rootURL);}... Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 20, 2013 Share Posted November 20, 2013 newMeshes[0] is a dummy object. It is the parent of the visual mesh. Just change to newMeshes[1] I knew it !! Gj guys ! Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 20, 2013 Author Share Posted November 20, 2013 And for the error line 20 in Babylon.js what is this error? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 20, 2013 Share Posted November 20, 2013 Do you have a site where we can see the error occuring? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 20, 2013 Author Share Posted November 20, 2013 No, I work locally on this project.But I will see if i can not make a small version of this part of the program and put it on my server. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 20, 2013 Author Share Posted November 20, 2013 Do you have a site where we can see the error occuring? No error online ??? I note that online, the error does not appear.Therefore, the error is when one is in local and not online. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 21, 2013 Share Posted November 21, 2013 This is due to CORS (cross origin security). babylon.js (and almost all 3D engine) must be used online to get rid of this security issue Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 21, 2013 Author Share Posted November 21, 2013 OK, I did not know this. Thank you.resolved 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.