Alex10 Posted March 22, 2016 Share Posted March 22, 2016 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. Am I doing something wrong or this may be a problem with the mesh ? Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted March 22, 2016 Share Posted March 22, 2016 can i see your .obj file? Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 22, 2016 Author Share Posted March 22, 2016 https://www.dropbox.com/s/7a7ilsn2t7u2lkl/mesh.obj?dl=0 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 22, 2016 Share Posted March 22, 2016 Hello! are you sure your mesh is the first in the list of loaded meshes? Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 22, 2016 Author Share Posted March 22, 2016 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. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 22, 2016 Share Posted March 22, 2016 yes but are you sure that the mesh you want to reach is task.loadedMeshes[0] ? Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted March 22, 2016 Share Posted March 22, 2016 i see two mesh in your obj Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 22, 2016 Author Share Posted March 22, 2016 @Deltakosh In this case, I'm not sure, but I do not know how best to do. Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 22, 2016 Author Share Posted March 22, 2016 But sketchfab this texture to this model can be easily adjusted.. Quote Link to comment Share on other sites More sharing options...
adam Posted March 22, 2016 Share Posted March 22, 2016 try: mesh.onSuccess = function (task) { m = task.loadedMeshes[1]; 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); }; Alex10 1 Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 23, 2016 Author Share Posted March 23, 2016 @adam No, this option is also does not work. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 23, 2016 Share Posted March 23, 2016 Can you please share your page on internet so we can see it live? Alex10 1 Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 25, 2016 Author Share Posted March 25, 2016 @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/ 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.