Madclaws Posted November 16, 2018 Share Posted November 16, 2018 Hi guys, I am new to babylon .So i was trying to import an obj file ,but i am getting error(screenshot attached).Any idea guys? Quote Link to comment Share on other sites More sharing options...
ssaket Posted November 16, 2018 Share Posted November 16, 2018 Hello, welcome to the forum The first error is not an issue. Second is a the real problem, need to see the code, a PG would be best. Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted November 16, 2018 Share Posted November 16, 2018 Well.. 404 (not found), Generally, path or file name is incorrect, or you are not using a webserver ( fileloader requires a webserver, apache, etc ) Quote Link to comment Share on other sites More sharing options...
Madclaws Posted November 16, 2018 Author Share Posted November 16, 2018 @ssaket Thanks. https://gist.github.com/madclaws/53b75bef8931398def054b52bc522e59 Above is the gist for asset loading function.And do we need a .mtl file also? @aWeirdo I don't know what is this manifest file.I'm running code on web server(webpack). Quote Link to comment Share on other sites More sharing options...
ssaket Posted November 16, 2018 Share Posted November 16, 2018 Relative links won't work in webpack (has to be relative to dist not src )... I don't think you need to specifically provide .mtl file, loader will take care of it. Posting one prev. thread- you can checkout the sample directory structure here, - https://codesandbox.io/s/moql7m0l39 Quote Link to comment Share on other sites More sharing options...
Madclaws Posted November 16, 2018 Author Share Posted November 16, 2018 @ssaket I changed "..Assets/" to "Assets/" and now both Assets folder and index.html are in root.But still the same error,with minor change.(screenshot attached).? Quote Link to comment Share on other sites More sharing options...
ssaket Posted November 16, 2018 Share Posted November 16, 2018 pinging @bghgary @kcoley Quote Link to comment Share on other sites More sharing options...
dbawel Posted November 16, 2018 Share Posted November 16, 2018 @Madclaws - Firstly, your file names don't match, so unless you have edited the OBJ and MTL files yourself, the loader is looking for the same name MTL file. Start by opening your OBJ file in any text editor, and verify the name of the .mtl file the .obj file is looking for. This will be in one of the first few lines of the OBJ file. As it appears the OBJ file is looking for a different MTL file name, this is not normal. It;s always best to keep your OBJ, MTL, and JPG (texture file) the same name as every exporter I've ever used writes these as the same name; and looks for the same name files on import - definitely the Babylon OBJ file importer. And your OBJ manifest file and MTL file are of different names. So I might assume your other files are not matching the names precisely. Upper case and lower case must match also. You don't need a manifest file... however, if you want to get rid of the 404 error for the manifest file, simply create an empty file with the same name as your OBJ file, and give it the extension .manifest. Example 'obj_name.babylon.manifest'. However, this is not important as others have already stated. If you're loading multiple OBJ files, then I recommend editing your OBJ file and remove the reference to the .manifest file. Then it won't look for the file. As for the .mtl file, this must also have the same name as the obj file. Example 'obj_name.mtl'. This is your material file with all your material attributes (settings.) This will work the same way if your mesh has a texture which will also have the same name as your obj file with an extension for the texture such as 'obj_name,jpg'. I work with OBJ files every day, and almost always edit the OBJ and MTL files as they are self explanatory once you open in a text editor. If you don't want a MTL file on your mesh, then simply remove the reference to the MTL file in your OBJ file. Then it will simply use a default material or none at all depending on your OBJ file edit. However, I find that different applications such as Blender often write odd values to the MTL file which is completely dependent on the user who has set up the material and texture. So I almost always edit my OBJ and MTL files as I can get the desired material editing the ambient, diffuse, specular values, etc. directly in the ascii files themselves. It's so very easy to read and edit. 2 minutes experimenting with no prior knowledge is more time than anyone needs to learn everything there is to know about the OBJ format - including editing normals, vertices, etc. It's simple for a single OBJ file, but if you work with real time scans producing hundreds of unique OBJ files to load in real time, then I write simple scripts to edit each OBJ file as needed. The .babylon format has many attributes which is far more advanced if you want to export scenes. However, if you are only importing meshes, the the OBJ format is by far the most reliable format and provides a level of flexibility in being able to edit the ascii files directly. Once you open the OBJ and MTL files and spend a couple minutes editing these and learning what values represent the different attributes, this will become your format of choice for meshes. I can't imagine otherwise, as there is little to nothing which will cause you problems once you understand the format. Remember that you can always apply Babylon materials and textures (and other attributes such as shaders) after import - which I do often. I hope this info helps, as you're definitely on the right path to the ease of importing OBJ files. If you read this and follow the advice to test a few edits to the files, I can't imagine you won't have a firm grasp of the OBJ format. However, if you still have issues, then post an OBJ, MTL, and JPG file all with the same name before the extension, and I'll be happy to walk you through the key lines to edit to gain full control over the resulting mesh(s) import. FYI - I introduced the other software engineers at Sony Electronics to the OBJ format, and it is now the format of choice for practically all mesh content due to it's simplicity and flexibility. This is after they spent several months working will every other format and exporter. No need to over complicate simple tasks - which often happens due to the OBJ format being decades old now; so people assume newer formats are better. But there's a reason why the OBJ format continues to be the most widely used in export/import between most applications. Cheers, DB GameMonetize, bghgary, Madclaws and 1 other 4 Quote Link to comment Share on other sites More sharing options...
Madclaws Posted November 19, 2018 Author Share Posted November 19, 2018 @dbawel Thanks for giving us a deep insight into OBJ and MTL.Right now i downloaded an OBJ model from internet and tried to load it.But There were no errors (got success callback).But loadedMeshes array is empty.Any idea? Quote Link to comment Share on other sites More sharing options...
dbawel Posted November 19, 2018 Share Posted November 19, 2018 @Madclaws - I would have to look at your code and how you're using the loader and the Babylon Assets Manager in order to understand where you're having problems. However, do you need to access the loadedMeshes array? What about using the Babylon Assets Manager as follows: let assetsManager = new BABYLON.AssetsManager(scene); let meshTask = assetsManager.addMeshTask("loading", "", "path to files", mesh_name.obj); meshTask.onSuccess = function(task) { 'Do stuff here, if necessary' }; assetsManager.load(); You'll find several methods on the forum and PG to load a mesh. But if you're simply loading an OBJ file as a test; and no bones, children, etc. then you shouldn't need to access the meshes array. DB Quote Link to comment Share on other sites More sharing options...
Madclaws Posted November 19, 2018 Author Share Posted November 19, 2018 @dbawel https://gist.github.com/madclaws/1d0faab86095df1cf66c89106b9374fa above gist have the function for loading model.After loading assets i have to assign it to some variable for future use ,So i tried to access loadedMeshes[0].Here i tried to assign a position vector for the mesh. Quote Link to comment Share on other sites More sharing options...
Madclaws Posted November 19, 2018 Author Share Posted November 19, 2018 Following the above topic,that issue is solved now.Now i can see the model info in debug UI,but cannot actually see the model(model attached) Skull.obj Quote Link to comment Share on other sites More sharing options...
dbawel Posted November 19, 2018 Share Posted November 19, 2018 @Madclaws- Take a look at the following PG scene. I quickly modified a scene @Wingnut posted last year - which I believe now accomplishes what you're trying to do. It's as simple as it gets. Look at your console to read the loaded mesh in the meshes array for the scene. Also, change the value on line 24 to see that you're able to affect the mesh in the array; and or modify the mesh any way you like. https://www.babylonjs-playground.com/#3FV2X#28 DB Quote Link to comment Share on other sites More sharing options...
Madclaws Posted November 19, 2018 Author Share Posted November 19, 2018 @dbawel please read my reply above you recent reply.I mean now the model is already there,but not visible Quote Link to comment Share on other sites More sharing options...
ssaket Posted November 19, 2018 Share Posted November 19, 2018 Well, that's really strange. Have a look at this, I copy-pasted your code and it's working fine. https://playground.babylonjs.com/ts.html#26K4VM May be you should check the url again; Would be great if you could repo the same on PG, if it's still not working for you Quote Link to comment Share on other sites More sharing options...
Madclaws Posted November 19, 2018 Author Share Posted November 19, 2018 @ssaket @dbawel @aWeirdo Thanks for your help.Finally i am able to see my model(after adjusting coordinates).I have one more doubt.The model i loaded have 4 mesh,So if i pass " " (empty string) as argument for meshNames then all meshes in model will be loaded ,can you point out any examples for grouping them to one or this parent-child relation should be done in blender itself. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 19, 2018 Share Posted November 19, 2018 You can use the setParent() method to modify the hierarchy after loading: https://www.babylonjs-playground.com/#QY1WYT#40 Now the meshes are under the "GROUPME" node and not "him" anymore: Madclaws and ssaket 1 1 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.