Question about naming in OBJ imports

Hi, I am trying to retain my object names from 3DS over to JME so I can more easily reference and manipulate parts of a mesh through code. However it seems the OBJ importer renames all the individual geometries as it comes across them, ref. this line from OBJLoader (line 395):

Geometry geom = new Geometry(objName + "-geom-" + (geomIndex++), mesh);

As a simple example, say I have a file named MyModel with two cylinders, Cylinder1 and Cylinder2. I want to write something like

MyModel = (Node)assetManager.loadModel("MyModel.obj");
Spatial cyl1 = MyModel.getChild("Cylinder1");
Spatial cyl2 = MyModel.getChild("Cylinder2");
manipulate(cyl1, cyl2);

Of course, with Cylinder1 and Cylinder2 having been renamed MyModel-geom-01 and MyModel-geom-02 respectively this does not work.

My model has well over 50 individual geometries and it’s not the only one. I don’t want to have to manually reference and manipulate MyModel-geom-01 through MyModel-geom-57 before I find the geometry I want to reference.

The .OBJ file itself retains object names by starting every new geometry with the line

g Cylinder1

It’s a bit weird that the filename is substituted for the objName instead of the actual object name - I’d think the “correct” result here would be to end up with Cylinder1-geom-01 and Cylinder2-geom-01 instead of MyModel-geom-01 and MyModel-geom-02?

Yes, it is known behaviour of ObjLoader. It renames the groups because it tries to merge everything sharing common material, regardless of how many separate object groups were in original obj file.

I had to modify it to play around with Sponza geometry. You can get fixed version of ObjLoader at

2 Likes

Thanks, that looks useful. Have you considered adding this patch to the nightly build?

This is breaking change - certain object files are going to work a slower with it applied. It could be possibly introduced as an option, but I’m not sure how you can parametrize loaders, given how asset manager instantiates them.

2 Likes

A crappy workaround for parametrize loader, I used static variable of the loader class.

I see. I guess the need for referencing objects by names may be a niche functionality that should not affect everyone.

Anyway, I implemented your changes locally and it works, so thank you for the fix!