objFileLoader passes the files as Content-Type XML - Were is babylon.objFileLoader.js to patch?

Using BABYLON.SceneLoader.ImportMesh to load a model by the OBJ & MTL files, I get

XML Parsing Error: not well-formed
Location: http://osmgo.org/o2w/models/car.obj

The loader passes the file as XML. I assume, the Content-Type is wrong/not set with setRequestHeader.

Times ago I used the extra OBJ/MTL loader from BJS and edited the .js file! Now I use BABYLON.SceneLoader.ImportMesh with
babylon.objFileLoader.min.js but I can’t find a
babylon.objFileLoader.js to edit (except an outdated version some were on the Web)

Could one show me the file or add the Content-Type in BJS?

You should not load the .obj file as a XML file but as a plain text file: .obj files are simply texts.

Actually, it’s the server that is serving the file that must set the content-type header with the right value, the loader is simply doing a GET request to retrieve the file.

What you can try to do is to set “.obj” as the 8th parameter of ImportMesh call and see if that helps. But the right fix would be to configure the server to correctly serve the .obj files.

2 Likes

Babylon doesn’t set the content type, it is the server that decides how to serve it. Babylon will take the content type and use it to parse the file.

If you do want to change the custom headers, you can use WebRequest.CustomRequestHeaders to set cutom headers to each request

A file
.htaccess
with this line did help:
AddType text/plain .obj .mtl

Thank you!