[Resolved] Multiple Meshes

Hi, I’m pretty new to Optix but I’ve spent the last week reading through the guides and SDK examples and I think I have a decent understanding of it.

However I’m trying to modify the mesh viewer example to load and render two separate meshes, but it only ever seems to render the last mesh that I load.

So essentially I’ve modified the code so that the load mesh function takes a transform as a parameter, the mesh is loaded and set as the child of the transform:

void loadMesh( const std::string& filename, Transform& trans )
{
    OptiXMesh mesh;
    mesh.context = context;
    loadMesh( filename, mesh ); 

    aabb.set( mesh.bbox_min, mesh.bbox_max );

    GeometryGroup geometry_group = context->createGeometryGroup();
    geometry_group->addChild( mesh.geom_instance );
    geometry_group->setAcceleration( context->createAcceleration( "Trbvh" ) );
    trans->setChild( geometry_group );
}

In main I then create two separate transforms, call load_mesh twice with the different transforms and add them to a group object which I set as the “top_object” on the context:

createContext();
Group top_group = context->createGroup();
top_group->setAcceleration( context->createAcceleration( "Trbvh" ) );

Transform trans = context->createTransform();
trans->setMatrix( false, Matrix4x4::translate( make_float3( 10.0f, 5.0f, 10.0f ) ).getData(), 0 );
		
loadMesh( mesh_file, trans );
top_group->addChild( trans );

Transform trans2 = context->createTransform();
trans2->setMatrix( false, Matrix4x4::translate( make_float3( -10.0f, -5.0f, -10.0f ) ).getData(), 0 );

loadMesh( mesh_file2, trans2 );
top_group->addChild( trans2 );

context[ "top_object" ]->set( top_group );
context[ "top_shadower" ]->set( top_group );

Is there something I’m just not getting ? Any help would be greatly appreciated, thanks.

Looks ok on first sight except for the aabb.set(). Check what that does. (I don’t have the code at hand right now.)
It probably focused the camera only on that space. You would need to take both meshes and their transforms into account to get the whole scene’s bounding box.

Yeah, this looks fine. To test, I made a similar mod to optixMeshViewer in the 4.0.2 SDK and it worked – I’m able to load multiple meshes. Send me mail directly (dlacewell @ nvidia ) and I’ll send you the source for comparison.

Thanks for the replies, the fact that you were able to confirm I wasn’t doing anything crazy helped as I was able to focus on more trivial reason for it not to be working.

It turns out that one of the models I was loading wasn’t made to scale at all so the other model was actually in the scene, it was just so small I could barely see it. All working now, thanks !

Excellent. FWIW, we plan to add more logging features for some upcoming release to indicate, for example, how many triangles are in the scene. That could have been helpful for debugging this.