ILNILEY Posted March 27, 2017 Share Posted March 27, 2017 Hey, guys. I want to use Babylon.js to import a .obj model . But I am not sure whether I am right or not. In my index.html , I have imported Babylon.ObjFileLoader.js, and after creating a scene, I coded "BABYLON.SceneLoader.Load("","pinecone.obj",engine,scene);". the model file is in the same project file with my index.html. I can't import my model successfully , error is "Failed to load resource: net ::ERR_FILE_NOT_FOUND" . I hope someone could tell me the steps to import a .obj model. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 27, 2017 Share Posted March 27, 2017 Hi @ILNILEY, welcome to the forum. Yeah, a file not found is interesting. Check your typing carefully. Can you grab this little zip package? http://webpages.charter.net/wingthing/webGL/objLoad.zip It's slightly different code (uses Append instead of Load)... but it worked fine for me, here, locally... loading a little .obj file (included in package). See if it works at your house, if you wish. Report back, if you would, thanks. This is likely a simple problem... so check carefully for those "hidden obvious things". Again, welcome, we'll talk more, be well. Hope this helps, somehow. Quote Link to comment Share on other sites More sharing options...
ILNILEY Posted March 27, 2017 Author Share Posted March 27, 2017 3 hours ago, Wingnut said: Hi @ILNILEY, welcome to the forum. Yeah, a file not found is interesting. Check your typing carefully. Can you grab this little zip package? http://webpages.charter.net/wingthing/webGL/objLoad.zip It's slightly different code (uses Append instead of Load)... but it worked fine for me, here, locally... loading a little .obj file (included in package). See if it works at your house, if you wish. Report back, if you would, thanks. This is likely a simple problem... so check carefully for those "hidden obvious things". Again, welcome, we'll talk more, be well. Hope this helps, somehow. Thank you for answer ,but your code doesn't work for me , the error is the same. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 27, 2017 Share Posted March 27, 2017 Well darn. Sorry, Ilniley. Are you browsing index.html from a web server / web site? Or perhaps double-clicking on index.html ... within a local hard drive folder? (better way for testing) This is puzzling. I'll keep thinking. Quote Link to comment Share on other sites More sharing options...
Nesh108 Posted March 27, 2017 Share Posted March 27, 2017 Hey @ILNILEY, What a coincidence! I was going to create a new thread exactly for this problem. Although I haven't fixed it myself, I can see already some obviously problems with your code. Take a look here: https://doc.babylonjs.com/extensions/obj Basically, you are not giving any path and the `Load(...)` method is for getting scenes, not objects. Here is how I am currently doing it and, although I am not getting any error and it gets loaded, I cannot access the `loadedMeshes` array: let loader = new BABYLON.AssetsManager(scene); loader.useDefaultLoadingScreen = true; // Set to false to remove the default loading let mesh_loaded_task = loader.addMeshTask(<TASK_NAME>, <MESHES_NAMES>, <PATH_TO_OBJ_FOLDER>, <FILENAME_DOT_OBJ>); mesh_loaded_task.onSuccess = function (task) { task.loadedMeshes.forEach(function(m) { console.log("Loaded!"); m.position = BABYLON.Vector3.Zero(); }); }; loader.onFinish = function() { engine.runRenderLoop(function () { scene.render(); }); }; loader.load(); Try this and enjoy. If anyone sees a problem with this, let me know EDIT: For some reason I was led to believe loadedMeshes was an array. Instead `forEach` needs to be used. 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.