glTF to stl (or obj)

Do you have any recommendation about the best C++ workflow to convert a .glTF file to .stl or .obj. there are few projects on Github with really few starts. I am not sure where I can start my journey.

I’m not sure this is a good journey to go on. OBJ files aren’t a good file format to begin with. If at all possible, the destination application should just consume glTF directly; that’s what it is made for, after all. It’s not really an interchange format.

1 Like

Thanks a lot for the prompt reply Alfonse. Much appreciated.

The application, already process .stl and .obj file, but currently doesn’t support glTF.

I thought it would be easier to create a file conversion instead of modify the current application in C++,

Note that many key features of glTF cannot be represented in either of these formats: PBR materials, animation, lights, etc. But if you’re OK with only keeping the geometry and basic material properties and textures, then the only C++ workflow I’m aware of to do the conversion would be https://www.assimp.org/. Otherwise I think you’d need to choose a library like cgltf to load the model, and find another library to write as OBJ, doing the conversion in custom code. OBJ is a pretty basic format so this might not be that hard.

1 Like

We have one, but it’s not in a very clean state for consumption yet. Use at your own risk.

BabylonJS/BabylonPolymorph (github.com)

1 Like

Thanks @donmccurdy and @bghgary for the great references. I saw there are some other SDK online available for C++ for this conversion, but they are not opensource unfortunately. I will try also yours as well. Futhermore, I am sure in the future I will have to convert also .stl and .obj to .gltf, any good reference for that?!

It’s not C++, but the most common library for OBJ → glTF is GitHub - CesiumGS/obj2gltf: Convert OBJ assets to glTF. If you need to support arbitary format->format conversions down the road, assimp (or maybe Polymorph - that one is new to me!) would probably be the way to go.

1 Like