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 ?
- 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() ) );
- 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() ) );
- 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 ) );