[solved]multiple objects with optix prime:

I want to load multiple object.

I base my example on prime simple.

I load 2 objects: the cow and a sphere (much bigger but similar triangle size) that splits the cow in the oX direction.

I trace ray from at each triangle centroid in the oX direction of the cow and check if they intersect with anything: I basically want to check if faces of the triangle are “exposed to the wind”

Whit the following method described below I get:
-A the cow alone gives me expected results
-B the sphere alone gives me expected results
-C when using the 2 objects, the cow being first, all the triangles of the cow located inside the bounded box delimited by the sphere are intersecting something (this make sense), but all the other triangles of the cow local outside the sphere does not intersect with anything (this is wrong)

From this I thought that was a bounding box problem being updated to the last object, but I did another test

-D when using the 2 objects, this time the sphere being first, I get the same exact results as A ! meaning that the sphere is not taken into account during the hit process.

So my question is: it the following way to handle multiple file object correct ? I guess it is not entirely. What Am I missing ?

  1. I Read the cow file set up the buffer
std::string objFilename = std::string( sutilSamplesDir() ) + "/simpleAnimation/cow.obj";

	//
	// Load model file
	//
	PrimeMesh mesh;
	mesh.loadModel( objFilename );

	//
	// Create buffers for geometry data 
	//
	RTPbufferdesc indicesDesc;
	CHK_PRIME( rtpBufferDescCreate(
			context,
			RTP_BUFFER_FORMAT_INDICES_INT3,
			RTP_BUFFER_TYPE_HOST,
			mesh.getVertexIndices(),
			&indicesDesc)
	);
	// index range : FROM 0 (begin) to end
	CHK_PRIME( rtpBufferDescSetRange( indicesDesc, 0, mesh.getNumTriangles() ) );

	RTPbufferdesc verticesDesc;
	CHK_PRIME( rtpBufferDescCreate(
			context,
			RTP_BUFFER_FORMAT_VERTEX_FLOAT3,
			RTP_BUFFER_TYPE_HOST,
			mesh.getVertexData(),
			&verticesDesc )
	);
	CHK_PRIME( rtpBufferDescSetRange( verticesDesc, 0, mesh.getNumVertices() ) );
  1. I Read the sphere file set up the buffer
std::string objFilename2 = std::string( sutilSamplesDir() ) + "/simpleAnimation/sphere.obj";
	//
	// Load model file
	//
	PrimeMesh mesh2;
	mesh2.loadModel( objFilename2 );

	//
	// Create buffers for geometry data
	//
	RTPbufferdesc indicesDesc2;
	CHK_PRIME( rtpBufferDescCreate(
			context,
			RTP_BUFFER_FORMAT_INDICES_INT3,
			RTP_BUFFER_TYPE_HOST,
			mesh2.getVertexIndices(),
			&indicesDesc2)
	);
	// index range : FROM 0 (begin) to end
	CHK_PRIME( rtpBufferDescSetRange( indicesDesc2, 0, mesh2.getNumTriangles() ) );

	RTPbufferdesc verticesDesc2;
	CHK_PRIME( rtpBufferDescCreate(
			context,
			RTP_BUFFER_FORMAT_VERTEX_FLOAT3,
			RTP_BUFFER_TYPE_HOST,
			mesh2.getVertexData(),
			&verticesDesc2 )
	);
	CHK_PRIME( rtpBufferDescSetRange( verticesDesc2, 0, mesh2.getNumVertices() ) );
  1. I create the model and update them with the geometry, the cow being first
RTPmodel model;
	CHK_PRIME( rtpModelCreate( context, &model ) );

	CHK_PRIME( rtpModelSetTriangles( model, indicesDesc, verticesDesc ) );
	CHK_PRIME( rtpModelUpdate( model, 0 ) );

	CHK_PRIME( rtpModelSetTriangles( model, indicesDesc2, verticesDesc2 ) );
	CHK_PRIME( rtpModelUpdate( model, 0 ) );

The 3rd code block is the problem.
You specify one model, attach triangles, update the model, then attach other triangles replacing the original ones and update it again. Means only the second set of triangles is actually present in the scene.

You either need to combine the triangles from the cow and the sphere to one set of data, or look at the primeInstancing example which is using multiple models by instancing them many times.

By “set of data”, do you mean that all my data should be contained in the object file before I use:

mesh.loadModel( objFilename );

OK, thanks. I will dig into that

I meant if you append the data in indicesDesc2 and verticesDesc2 to the indicesDesc and verticesDesc manually and would only do the first rtpModelSetTriangles( model, indicesDesc, verticesDesc ) call, then all data would be in the one model used inside your scene. That would be similar to loading only one OBJ file.

OK, from my understanding, I would need to create a structure to increment the vertexes and triangles ids accordingly as well as the corresponding reverse table (since I am interesting in setting different proprieties for each files) in order to apply different operation based on the interesting triangle (using the triId)
Since that is already set up with in the primeInstancing structure (thanks to instId), it looks more straightforward to use it, so I will use that last option. Thank you for the clarification.