Import triangle

Good Morning,

I have successfully created an OptiX 7 “hello world” whereby a simple triangle is saved back as a PPM file. This code uses Geometry Accelerated Structure (GAS) for a single triangle that is rendered to output buffer. This is a good first step, but I would like to know how to render a triangle using an data read from an input file. Is the solution as simple as replacing the vertices hardcoded in the GAS with data parsed from an input file? The idea is to be able to read in a mesh of triangles and save the results of Ray-Trace to an external PPM file.

Thank you very much for any hints/help.

Is the solution as simple as replacing the vertices hardcoded in the GAS with data parsed from an input file?

Yep, it’s that simple. :) Read the vertices and indices from a file into arrays instead of hard-coding your arrays, pass the arrays to OptiX, and you’re done.

We provide an SDK sample that does exactly what you describe, specifically to give you a complete source code example to see how to read a mesh from a file, render it, and save the result to an image file. Build the optixMeshViewer sample. It loads a water bottle mesh by default, but it has command line flags to read a different mesh from a file, and to save the rendered output to an image.

For example, the command line > bin/optixMeshViewer --model ../samples_exp/data/Duck/Duck.gltf --no-gl-interop -f duck.ppm produces a PPM file that looks like this: (you can also use the .png extension to write a PNG format file.)


David.

Nice.

Thanks

1 Like