Export scene into .obj

Hi,
I am working with Babylon exporters. They can perfectly export scene into gltf or glb, this is working almost everywhere, but I can not import this created gltf/glb via Blender.

My problem is that I want to have a scene in .obj . Is there any option how to convert exported gltf/glb or how to directly export Babylon scene into .obj?

Thanks.

You can import into Blender 2.80 with gltf. Never tried it though.

1 Like

Hi.
I don’t know if I understood your issue, but I exported meshes from babylonjs as obj and work well in 3dsMax, so I think they should work too in Blender, maybe you are doing something wrong on export. You can test your exported meshes on https://sandbox.babylonjs.com first.
here you find few examples about OBJexporter

Here is how I’m using it.

const obj = OBJExport.OBJ(array_Meshes, true, ‘material’, true)
const mtl = OBJExport.MTL(array_Meshes)

const names = [‘object.obj’, ‘material.mtl’]
const blobs = [new Blob([obj], { type: ‘octet/stream’ }), new Blob([mtl], { type: ‘octet/stream’ })]

If you are using gltf files into babylonjs scene then in array_Meshes you can put directly children of ‘root’ node.

1 Like

It is a bit ambiguous there where to get the meshes, for example all the meshes. gltf and glb export works with scene, maybe it even uses the meshes part of the scene.

Should we get the meshes to pass to obj exporter as scene.meshes (or this.scene.meshes), for exporting the whole scene?

1 Like

Yes exactly scene.meshes would do :slight_smile:

1 Like

Then how to download the files. Is there a downloadFiles() method on the returned object (as in gltf and glb exporters), or do we have to construct a file through Blob API or something like it?

Is OBJ and MTL methods asynchronous or sync? They look like sync from usage above and from source code.

1 Like

they are sync and yes:

const names = [‘object.obj’, ‘material.mtl’]
const blobs = [new Blob([obj], { type: ‘octet/stream’ }), new Blob([mtl], { type: ‘octet/stream’ })]

Then you could rely on Tools.Download to dl blobs

1 Like

In that method where does the textures come from if any?

1 Like

looking at the code the url used to create the material will be the one ending up in the exporter.

The obj exporter is an external contrib and could probably be enhanced if you wish to contribute.

1 Like

I would like to contribute once I get more fluency in webgl based programming. Yes the obj exporter code looks different in style than the others. Also kind of old but probably most compatible in terms of js and web features.

An async version would be cool.

How do I get the texture files. Obj as a blob, mtl as another blob. whatabout picture files?

1 Like

Additionally it looks like MTL method does take a single mesh as an argument oppesd to OBJ method taking an array of meshes.
So, I kind of need to map or forEach through my scene.meshes array and call MTL method in each ietration. And then hand this utput array to the Blob constructor.

Am I correct?

Maybe later I can turn this MTL method to an array passed method since babylonjs gives us that as an array.

1 Like