Import .OBJ to Optix

Hi.
I want to import a .OBJ (or .POV) that comes from a .OSM, to Optix 7.2, so I can use raytracing over it. Since its the first time I’m using this technology, I’m following ingowalds tutorials to familiarize with it right now, but I have to do this in the future. I’ve found people who tried it but it was with older versions of optix, such as 5.1 and 4.x, so I feel like I need some guidance on the task since I don’t even know where to start or have any examples.

How would you approach this task for CUDA 11.1 and Optix 7.2? I’m using VS 2019.

Thanks!

1 Like

Since OptiX is not a renderer but a ray casting SDK, it doesn’t know anything about file formats, and it’s your responsibility to convert any model data (vertex attributes, geometric primitives, and materials) to a format that you define in your OptiX-based renderer.

There are many different ways to structure your OptiX render graph contents and even more ways to implement a material system. If you first learn how to do that in OptiX, loading data from model files becomes pretty straightforward.
Materials can still be a pain. It’s of course possible to program a material system which exactly handles the associated MTL material files of an OBJ model.

With that said, you basically need some way to load *.obj files into host memory which you can convert into whatever data you require for your renderer implementation using OptiX.
For the fist step older OptiX SDK examples have been using tinyobjloader for that: https://github.com/tinyobjloader/tinyobjloader
The newer OptiX SDK 7 versions are loading the more modern Khronos glTF format instead and use the tinygltf loader for that.

Actually Ingo Wald’s SIGGRAPH OptiX 7 course contains at least two examples loading OBJ models, so you can keep studying these.
(I would be wary of the vector class used in that code though because that is not GPU friendly enough.https://forums.developer.nvidia.com/t/optix-7-and-msvs-2017-hello-world-on-windows-10/141711/9 )

My more advanced OptiX 7 apps are using the ASSIMP library to load triangle data of any format supported by that library. I do not handle the materials or textures of that at all, except for the diffuse color. That would require quite some changes to the material system in there and those examples are meant to show other features like multi-GPU and NVLINK resource sharing.
There is an example scene description file named scene_rtigo3_instances.txt for the rtigo3 and nvlink_shared examples which loads the cow.obj as multiple instances. The scene_rtigo3_models.txt shows how to load a single model.
I use a very simple host side scene graph which is then flattened to an OptiX render graph with single-instancing structure which is fully hardware accelerated by RTX boards.

Please have a look into all sticky threads of this OptiX sub-forum containing the links to these resources.

4 Likes

Thank you! I’ve been able to succesfully import the .obj with tinyobjloader! It seems to be good enough for what I want to do, but thank you for taking the time to reference some alternatives, I’m sure it will be usefull for someone else.

1 Like