Jump to content

Problems with a color


mout99
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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