Importing meshes into Optix

I’m starting a small Optix project, that will eventually have to import meshes, and found the function rtuCreateClusteredMesh(). However, when I try to use it, I get an error code of -1, with no further information. What am i missing?

(Also: is there a best practice regarding importing meshes into Optix that i should be aware of?)

int raytracer::testGeometry() {
	o::Geometry mesh = _context->createGeometry();
	float verts[] = {0.0f, 0.0f, 0.0f, 
		0.5f, 0.5f, 0.5f,
		0.5f, 0.0f, 0.0f,
		0.3f, 0.0f, 0.7f
	};
	unsigned int primitive_count = 2; 
	unsigned int indices[] = { 0, 1, 2, 1, 2, 3 };
	unsigned int mat_ind[] = { 0, 0, 0, 0, 0, 0 };
	RTgeometry mesh_c = (mesh->get());
	mesh->setPrimitiveCount(primitive_count);
	RT_CHECK_ERROR(rtuCreateClusteredMesh(_context->get(), 1, &mesh_c, 4, verts, primitive_count, indices,  mat_ind));
	
	_geometry.push_back(mesh);
	return 1;
}

It seems this thread answers my original question; https://devtalk.nvidia.com/default/topic/965791/?comment=4977336

Assuming there’s no fix out, is there some convenient way of importing meshes, or do i have to implement my own mesh intersection test?

Kind Regards,

Erik

The “mesh” talked about in that thread is something different than loading model data from some file format into OptiX.

The OptiX 4.0.2 examples come with a loader for OBJ files which does a lot of other things to setup programs and materials. All code is present, so it’s simple to step through inside the debugger to see what it’s doing exactly.
[url]https://devtalk.nvidia.com/default/topic/983955/?comment=5048357[/url]

In general I strongly recommend to learn how to create Geometry nodes from scratch and write bounding box and intersection programs that match your data layout. Maybe start with a one or two triangles. All code for that can be found inside the OptiX examples.
How to start learning OptiX (version info is outdated in that old post):
[url]https://devtalk.nvidia.com/default/topic/915251/?comment=4801716[/url]

Hi,

I have some experience using Optix, I know how the API work, and I am aware of what rtuCreateClusteredMesh() is supposed to do. I was hoping I wouldn’t have to do it myself, since ray tracing algorithms are not central to my work.

The “how to start learning Optix” link doesn’t really apply that well to me, since what I’m lacking is specifically a triangle mesh-ray intersection algorithm, with all the details that come with it. I guess I’ll have to look into that. Do you know of a good place to start?

Thank you for you help
Kind regards,
Erik

Hi Erik. Building on what Detlef said above, in particular the OptiX 4 SDK has a sample called ‘optixMeshViewer’, which uses utility classes (Mesh, OptiXMesh, tinyobjloader) in the ‘sutil’ directory to import a triangle mesh from an OBJ file. That sample also shows a ray-triangle intersection function. That’s where I would start.