Updating Transforms

I’m keeping track of my object transforms, and am trying to update like so:

auto it = _transforms.find(key);
if(it != std::end(_transforms))
it->second->setMatrix(false, m, nullptr);

It does not work, and I get garbage output.

Also, when constructing the scene, each instance gets its own Transform. Thus I had to create a GeometryGroup and Accelerator for each instance. This seems a little awkward. Is this the correct API usage?

I’m not sure what the code snippet is showing, I would need more context to judge that. Please be more specific than “does not work, and I get garbage output”. Just as a shot in the dark: if you update a transform and forget to call markDirty() on the top level accel for the top group, then you’ll probably get a bad image at launch time because the scene bounds won’t match the traversed scene.

As far as creating instanced geometry, you are free to have many Transform nodes pointing to a single GeometryGroup with a single Accel. There is no need for duplication unless you want to introduce variation at the GeometryInstance or Geometry level.

Regarding the transform bug, it was simply that I had to transpose the matrix. So setting the first flag to true fixed that issue. However, I seem to be able to update the transform matrix without calling markDirty() and it works correctly. Maybe because my scene is pretty simple (only root and one level of object instances).

For my other question, I have multiple different geometric model meshes, and just need the ability to update the mesh transforms for each one individually.

Yes, for multiple meshes with a unique transform over each mesh, this would be the scene layout per mesh:

Transform->GeometryGroup->GeometryInstance->{Geometry, Material}

The Material can be shared between multiple meshes, but the other nodes are unique per mesh, as you noted.

After updating the Transform above, you would only need to call markDirty() on the top level Acceleration (attached to whatever Group is above the Transform in the diagram above). The acceleration attached to the GeometryGroup above does not need to be dirtied.

However, there is another option: you can also bake the transform directly into the vertices of the mesh on every update, and place all meshes under a single GeometryGroup. The vertex update could be done on the host or even on the device (with an external CUDA kernel, for example) if there are enough vertices to make a device update worthwhile. The optixDynamicGeometry SDK sample shows these two options. A fully flattened scene is faster to trace, but requires the vertex update and a full acceleration rebuild or refit.