Generating images of obj files at different camera angles

Hi Panda3D Community!

I’m planning to use Panda3D as part of a machine learning project, but I’ve been struggling to get to grips with how to use it.

Fundamentally, what I am trying to create is a python method through which I can pass the file path of an obj file, a file path of a folder, and then receive out a set of images of the object taken at different angles by the camera.

I’ve had a crack through the manual and tutorials, trying to get to grips with how panda works and I’ve managed to get obj files loaded into a scene by using p3assimp to load the file, but with a few problems that are preventing progress:

  1. .obj file textures don’t seem to be loaded, while other programs such as Windows’s 3D Viewer seem to discover the textures? How can I ensure that textures are loaded with the object? I load the objects using loadModel and giving a file path of an obj.
  2. I need to ensure that the object is in the middle of the scene so that the camera can take hardcoded positions around each object to generate the output images, however when I load objects into the scene they seem to be placed at different offsets dependent on the world origin for that obj file, how can I recalculate and move the object to 0,0,0 in the panda3d scene?
  3. Some objects may be bigger than others, and such I may need to zoom the camera out further for some objects than others, whats the best method for me to use to identify the size of the given object and move the camera outwards as appropriate?

Any help would be greatly appreciated,


.obj files do not contain any informations about the texture, you need a .mtl file alongside it, I’m not sure assimp will pick them up automagically, but I can use pview to open any obj file and it shows the right texture if there’s also a .mtl file with the same name next to it, so the native obj loader knows what to do (unless it’s assimp under the hood, in that case ignore this sentence).

You can place the model at the zero point and scale it to fit in a unit sphere using something like:

model = loader.load_model('...')
model_bounds = model.get_bounds()
model_size = model_bounds.get_radius()
model_center = model_bounds.get_center()*(1.0/model_size)

Sorry, I forgot to include in my original post, I have the relevant mtl and texture files in the same directory. Right now I’m using p3assimp to load files, but is there a better method to use that supports objs and deals with the textures for me?

Thanks btw for the information on how to set up the model in the world centre! I’ll give it a go!

Have you tried just using loader.load_model() without setting load-file-type p3assimp in your prc? Panda should do just fine loading a obj without assimp, and if that fail - .mtl are just simple text files, the (diffuse/color) texture path should be on a line that starts with either map_Ka or map_Kd

For the record, it’s actually the Assimp loader that can correctly import the materials and textures, whereas the fallback obj2egg-based one doesn’t.