duleaux Posted December 22, 2017 Share Posted December 22, 2017 I need to load an OBJ file from my local machine using ImportMesh or addMeshTask, but nothing I've tried so far works. I've read probably every posting on this topic on the internet, including those in this forum, over the past 24 hours and can't find a solution. Here is the basic code that fails and triggers the "loader.onTaskError" error handler, all within my createScene() function: var loader = new BABYLON.AssetsManager(scene); var pos = function (t) { t.loadedMeshes.forEach(function (m) { m.position.x += 10; m.position.y -= 5; m.material = material; }); }; var shelves = loader.addMeshTask("", "", "", "shelves.obj"); shelves.onSuccess = pos; loader.onTaskError = function (task) { alert('Error with loading by assetsManager...'); }; loader.onFinish = function () { engine.runRenderLoop(function () { scene.render(); }); }; BABYLON.OBJFileLoader.OPTIMIZE_WITH_UV = true; loader.load(); I know that my "shelves.obj" file is okay because I can load it using this Playground example: https://www.babylonjs-playground.com/#6N13NV#33. However, this Playground uses a file chooser and converts the selected file into a File object that is loaded using this command: loader.addMeshTask("", "", "file:", objectFileName). My understanding is Javascript File objects can't be directly instantiated, so this does not seem to be an option for what I am trying to accomplish. I also am not sure if the loader in my code is even able to find the "shelves.obj" file (I've placed it in virtually every location in my computer, but to no avail). If anyone has any ideas please let me know. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 24, 2017 Share Posted December 24, 2017 Hiya @duleaux, welcome to the forum. No success and no replies yet? Sorry. I don't have much experience with this subject, but often, people get a free github account, and publish their test-models... there. Here's my free account: https://github.com/Wingnutt Let's look inside my 'misc' folder. See the file 'mesh01.obj' ? Now, off to the playground. https://www.babylonjs-playground.com/#3FV2X#11 Notice the strange 'rawgit' URL domain? But, it works. Object loaded. And, I didn't need to create/find a web server to store my .obj upon. Github stored it for free, and allowed me to "drag'n'drop" the file into the misc folder (be sure to hit 'commit changes' button at bottom, after the drag-drop). But yeah, I THINK scene mesh are primarily loaded from web servers, and I'm not sure how well .addMeshTask works... using local or localHost files. Stay tuned - others will surely comment soon (and likely, they will have more experience than I have). Report thoughts/discoveries, please. (thx) I have 'featured' this thread, so it has a green star next to its title. That will surely get lots of attention, but we might need to wait until Christmas folk finish playing-with their new toys. Quote Link to comment Share on other sites More sharing options...
duleaux Posted December 24, 2017 Author Share Posted December 24, 2017 Hi Wingnut - this is great, thank you. I copied your playground code into my local app and all works well. Substituting your github-hosted file with my locally-stored file, however, yields the same result as before - i.e., nothing is displayed. loader.addMeshTask(...) seems unable or unwilling to allow access to local files, perhaps as a security measure. I will sign up for a github account and load my files at that location - seems to be the best solution. Thanks again for your help! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted December 24, 2017 Share Posted December 24, 2017 you may need to run a local webserver for local access (ie: http:// instead of file://). if you open your dev tools and go to network tab then you will likely have a 404 error (not found) and perhaps a CORS preflight error. it may just be a matter of adjusting the file location (correct folder and case). GameMonetize and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
mickmech Posted May 25, 2019 Share Posted May 25, 2019 check that you have http:// ( not https:// ) remove the "s" as your site is probably not secure. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 14, 2019 Share Posted June 14, 2019 We have a new forum: forum.babylonjs.com 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.