Jump to content

Not added textures for loaded obj mesh


Alex10
 Share

Recommended Posts

I load the mesh .obj, does not have .mtl, and then assign texture.
 

var mesh = loader.addMeshTask("mesh1", "", "/file/", "mesh.obj");
mesh.onSuccess = function (task) {
         var m = task.loadedMeshes[0];
         m.position = new BABYLON.Vector3(100, 500, 100);
         m.material = new BABYLON.StandardMaterial("texture1", scene);
         m.material.diffuseTexture  = new BABYLON.Texture( "/file/diffuse.png",  scene);
         m.material.specularTexture = new BABYLON.Texture( "/file/specular.png", scene);
         m.material.ambientTexture  = new BABYLON.Texture( "/file/ambient.png",  scene);
         m.material.bumpTexture     = new BABYLON.Texture( "/file/bump.png",     scene);
}

But the texture is not assigned to an object.

mesh.png

Am I doing something wrong or this may be a problem with the mesh ?

Link to comment
Share on other sites

window.addEventListener('DOMContentLoaded', function() {
    var cam;
    var canvas = document.getElementById('renderCanvas');
    var engine = new BABYLON.Engine(canvas, true);
    var scene = new BABYLON.Scene(engine);
    var loader = new BABYLON.AssetsManager(scene);
    var createScene = function() {
        new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
        cam = new BABYLON.ArcRotateCamera("ArcRotateCamera", 0, 0, 5, new BABYLON.Vector3(0, 3, 0), scene);
        cam.attachControl(canvas);

        var mesh = loader.addMeshTask("mesh1", "", "/file/", "mesh.obj");
        mesh.onSuccess = function (task) {
            m = task.loadedMeshes[0];
            m.position = new BABYLON.Vector3(100, 500, 100);
            m.material = new BABYLON.StandardMaterial("mat", scene);
            m.material.diffuseTexture  = new BABYLON.Texture( "/file/diffuse.png",  scene);
        };

        return scene;
    };

    var scene = createScene();

    loader.onFinish = function(){
        engine.runRenderLoop(function(){
            scene.render();
        });
    };

    loader.load();
});

This is the code for which there is now.

Link to comment
Share on other sites

 @Deltakosh I like it to assign the texture mesh.
 

mesh.onSuccess = function (task) {
   m = task.loadedMeshes;
   for(var i = 1; i < m.length; i++) {
        m[i].material = new BABYLON.StandardMaterial("mat", scene);
        m[i].material.diffuseTexture  = new BABYLON.Texture("/file/diffuse.png", scene);
   }
};

But if I change the position of the mesh or the camera I can't the mouse to rotate the mesh. I created a new question for this. http://www.html5gamedevs.com/topic/21444-imported-obj-mesh-when-changing-positions-becomes-unmanageable/

 

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