mout99 Posted July 5, 2017 Share Posted July 5, 2017 Hello, I have a .obj and I'm trying to change the color of it with the material, but this color change works only when I take the .mtl file, what can it be? I noticed that I change the color below .obj // Get the canvas element from our HTML below var canvas = document.querySelector("#renderCanvas"); // Load the BABYLON 3D engine var engine = new BABYLON.Engine(canvas, false); // ------------------------------------------------------------- // Here begins a function that we will 'call' just after it's built var createScene = function () { var scene = new BABYLON.Scene(engine); //Adding a light var light = new BABYLON.HemisphericLight("Hemi0", new BABYLON.Vector3(0, 1, 0), scene); light.diffuse = new BABYLON.Color3(1, 1, 1); light.intensity = 0.8; light.groundColor = new BABYLON.Color3(1, 1, 1); light.direction = new BABYLON.Vector3(0, -1, 0); //Adding an Arc Rotate Camera var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene); camera.attachControl(canvas, false); // The first parameter can be used to specify which mesh to import. Here we import all meshes BABYLON.SceneLoader.ImportMesh("", "js/novo/", "edifício sem texturaas.obj", scene, function (newMeshes) { BABYLON.OBJFileLoader.OPTIMIZE_WITH_UV = true; var zeromat = new BABYLON.StandardMaterial("zeromat", scene); zeromat.diffuseColor = new BABYLON.Color3(1,1,1); zeromat.wireframe = false; zeromat.backFaceCulling = true; scene.meshes[0].material = zeromat; // var alltextura = new BABYLON.StandardMaterial("alltextura", scene); // alltextura.backFaceCulling = false; // scene.meshes.material = alltextura; var meiomat = new BABYLON.StandardMaterial("meiomat", scene); meiomat.diffuseColor = new BABYLON.Color3(0.2, 0.2, 0.2); scene.meshes[1].material = meiomat; // Set the target of the camera to the first imported mesh camera.setPosition(new BABYLON.Vector3(8000,8000,8000)); // camera.target = newMeshes[0]; camera.wheelPrecision = 0.1; camera.maxZ= 45000; }); // Move the light with the camera scene.registerBeforeRender(function () { }); return scene; } var scene = createScene(); // Register a render loop to repeatedly render the scene engine.runRenderLoop(function () { scene.render(); }); // Watch for browser/canvas resize events window.addEventListener("resize", function () { engine.resize(); }); edifício sem texturaas.obj edifício_sem_texturaas.mtl Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 6, 2017 Share Posted July 6, 2017 // The first parameter can be used to specify which mesh to import. Here we import all meshes BABYLON.OBJFileLoader.OPTIMIZE_WITH_UV = true; BABYLON.SceneLoader.ImportMesh("", "js/novo/", "edifício sem texturaas.obj", scene, function (newMeshes) { var zeromat = new BABYLON.StandardMaterial("zeromat", scene); zeromat.diffuseColor = new BABYLON.Color3(1,1,1); zeromat.wireframe = false; zeromat.backFaceCulling = true; newMeshes[0].material = zeromat; var meiomat = new BABYLON.StandardMaterial("meiomat", scene); meiomat.diffuseColor = new BABYLON.Color3(0.2, 0.2, 0.2); newMeshes[1].material = meiomat; // Set the target of the camera to the first imported mesh camera.setPosition(new BABYLON.Vector3(8000,8000,8000)); camera.wheelPrecision = 0.1; camera.maxZ= 45000; }); give that a shot. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
mout99 Posted July 6, 2017 Author Share Posted July 6, 2017 Hello, thanks for your reply but it is still not showing the color, I can notice that the color is under my mesh, Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 6, 2017 Share Posted July 6, 2017 Then there is prolly something wrong with your model. Quote Link to comment Share on other sites More sharing options...
gryff Posted July 6, 2017 Share Posted July 6, 2017 @mout99 and @Pryme8 : When I load the object model posted above and load it into Blender there is only one mesh with 6 materials. So what is the line scene.meshes[1].material = meiomat; or newMeshes[1].material = meiomat; going to do - fail quietly? cheers, gryff Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 6, 2017 Share Posted July 6, 2017 I never looked at the mesh (or the scene), good catch @gryff. I was starting to assume there was a structure problem on the model. @mout99 fix your model and it will work. And while your at it export it at a smaller scale so you don't have to do all the large numbers with the camera. Quote Link to comment Share on other sites More sharing options...
mout99 Posted July 7, 2017 Author Share Posted July 7, 2017 I still can not solve it, I can only put a material when it has no .mtl file, I need help 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.