USDView Not Rendering PointInstancer Instances Immediately After Creation

Hello everyone,

I’ve been experimenting with the Python API in usdview to dynamically create a PointInstancer and set up a few instances. After setting up the PointInstancer, I noticed that the instances aren’t immediately visible in the viewer. However, if I save the stage to a USD file and then reopen that file in usdview, the instances render as expected.

Has anyone else experienced this issue? Is there a step or refresh command I might be missing to update the usdview renderer immediately after making these changes?

Any insights or suggestions would be greatly appreciated!

Thank you!

Minimal code to recreate:

from pxr import Usd, UsdGeom, Gf

# Get the current stage from usdview
stage = usdviewApi.stage

# Create a new PointInstancer at the root of the stage
pointInstancer = UsdGeom.PointInstancer.Define(stage, '/myPointInstancer')

# Create a new Sphere as the prototype for the PointInstancer
sphereProto = UsdGeom.Sphere.Define(stage, '/myPointInstancer/sphereProto')

# Set the prototypes relationship on the PointInstancer to point to the Sphere

# Set the positions for three instances of the sphere
positions = [
    Gf.Vec3f(0, 0, 0),
    Gf.Vec3f(2, 0, 0),
    Gf.Vec3f(4, 0, 0)

# Set the protoIndices for the three instances (all pointing to the single sphere prototype)
protoIndices = [0, 0, 0]

# Edit/update
# Required to render the PointInstancer after populating attributes

I want to add that I am getting a user warning:

Point instancer /myPointInstancer does not have a valid 'prototypes' relationship. Not adding it to the render index.

This occurs at the line:

# Create a new PointInstancer at the root of the stage
pointInstancer = UsdGeom.PointInstancer.Define(stage, '/myPointInstancer')

How to add the point instancer to the render index after populating the required attributes?


Edit/Update: I found that simply adding ‘stage.GetEditTarget()’ after populating the required attributes is enough to trigger the updates to be rendered.

I think this is a plain old bug. An empty prototypes relationship should only be considered invalid if the protoIndices attribute is not empty. Could you file an Issue, please?

In terms of (ugly) workaround, when you are done with your configuration of the new prim, first SetActive(False), and then ClearActive(). That should kick Hydra, I think.

Thanks for the feedback Spiff. I created an issue, see link below.