Madclaws

Error on loading .OBJ files

Recommended Posts

 

@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

Share this post


Link to post
Share on other sites

@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?

 

Share this post


Link to post
Share on other sites

@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

 

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.