1

I working on a thermal tool using OptiX. I started with the "meshviewer" example which uses syoyo's tinygltf loader. Basically I want to import a file, get the number of primitives and then add up the intersections.

Now I imported a file containing two cubes, which should consist of 12 triangles each, so 24 in total. When I start my program the loader only recognizes 12 triangles, but it renders 2 seperate cubes. The primitive IDs seem to be identical for both cubes.

Is there a workaround when I export from blender? If I understood the documentation directly the separate cubes are treated as two "identical" instances of the same mesh and thus share the primitive IDs. I am using the v2.81 of Blender with the gltf exporter.

Do I understand the problem correctly? And is there an easy workaround? If not it seems I will have to modify the tinygltf loader.

Thank you for help in advance!

brgalo
  • 37
  • 5

1 Answers1

0

It's possible the two cubes share the same mesh. In the screenshot below, there are two Blender "objects", Left-Cube and Right-Cube. Both objects use the same Blender mesh, called Shared-Cube-Mesh.

The glTF exporter recognizes this pattern and mirrors it in the glTF file. There will be two glTF nodes, corresponding to the two Blender objects that use the mesh. But there will only be a single glTF mesh, with a single cube.

You can click the "number of users" button, shown below with a white arrow pointing to it, to make the second object use its own unique mesh. But be warned, this doubles the amount of mesh data being exported to glTF in this simple example. A complete copy of the mesh would be made in both Blender and the glTF binary payload.

Blender Screenshot

emackey
  • 11,818
  • 2
  • 38
  • 58
  • Thank you! Sadly OptiX (or the tinygltfloader), starts indexing all seperate meshes at 0 again. Is it possible to somehow include both cubes in one mesh, even if they are not physically one mesh? I will also try to figure out if i can somehow not start indexing at 0 when I process a new node. – brgalo Jan 28 '20 at 10:18
  • So, glTF meshes contain things called "primitives", and the Blender exporter will make a separate primitive per material used by a Blender mesh. In the above screenshot you could multi-select and press CTRL-J to join the two cubes into a single mesh with the pair, and then set one of them to use a different material. The exported glTF would then have a single glTF node and single glTF mesh with two Primitives in it. Would that help? – emackey Jan 28 '20 at 14:27
  • I followed your instructions: I added two cubes to a new scenes, I select both, hit CTR-J and export them. Now I import them and have a mesh with two primitive groups. In OptiX the triangles still share the same ID. Is there a way to combine the two cubes to the same primitive? – brgalo Jan 28 '20 at 16:10
  • If the two cubes are in the same Blender mesh with the same material assigned, they'll be in the same primitive. – emackey Jan 28 '20 at 19:41
  • Yeah! Seems to work now! Don't know what was the problem earlier. If I want to use different materials, I can't have them in the same primitive? – brgalo Jan 29 '20 at 11:12
  • Not in the same primitive, no. glTF is a GPU-ready format, and a "material" in this case means a shader program and texture stack. So a "primitive" happens in a single draw call, with a single shader program and one set of texturemaps. You need Optix to tell you more than which polygon ID within a single draw call, you need it to tell you which draw call you picked. – emackey Jan 29 '20 at 16:04
  • Thank you for the clarification. So on the long run I will have to modify the tinygltfloader and fix the indexing in OptiX. Right now the workaround is good enough! – brgalo Jan 29 '20 at 16:18