How to deactivate specific instances in PointInstancer?

I want to hide some instances of a point instancer so they are not rendered anymore. I created this minimal example which I run in the USD composer scrip editor to show what I am trying to do:

from omni.usd import get_context
from pxr import Sdf, UsdGeom, Gf

OBJ_ROOT_PATH = "/World/Foo"

NUM_OBJ = 5
OBJ_OFFSET = Gf.Vec3f(200,0,0)

def init_stage():
    context = get_context()
    stage = context.get_stage()

    prim_path = Sdf.Path(OBJ_ROOT_PATH)
    instancer: UsdGeom.PointInstancer = UsdGeom.PointInstancer.Define(stage, prim_path)

    # create prototype
    prototype_container = UsdGeom.Scope.Define(stage, prim_path.AppendPath("Prototypes"))
    shapes = []
    cone = UsdGeom.Cone.Define(stage, prototype_container.GetPath().AppendPath("Cone"))
    xformable = UsdGeom.XformCommonAPI(cone.GetPrim())
    xformable.SetScale(Gf.Vec3f(50,50,50),0)
    shapes.append(cone)

    # fill point instancer attributes
    positions = define_positions()
    instancer.CreatePrototypesRel().SetTargets([shape.GetPath() for shape in shapes])
    instancer.CreatePositionsAttr(positions)
    instancer.CreateProtoIndicesAttr([0] * NUM_OBJ)

    # deacticate one instance 
    instancer.DeactivateId(1)


def define_positions():
    positions = list()
    for i in range(0,NUM_OBJ):
        positions.append(Gf.Vec3f(0,0,0) + i * OBJ_OFFSET)
    return positions


init_stage()

I would assume to see only 4 cones because I deactivated the instance with index 1. But instead all 5 cones are rendered in the viewport of USD Composer.

Can someone please explain what is happening here? And what would be the correct way to prevent rendering of individual instances?

Not sure about doing it through code, but is it very simple to deactivate prims in Composer. Just find them in the tree and deactivate them there. Then there is no way they should render.

Just to be clear “hide” is not the same as “deactivate”

Here is a code I use all the time to run through my stage and DEACTIVATE all prims regardless: Maybe you can use this script to help you with deactivating:

from pxr import Sdf, Usd
import omni.usd

def iter_deactive_prims(root):
    for prim in Usd.PrimRange.AllPrims(root):
        if not prim.IsActive():
            yield prim

if __name__ == "__main__":
    stage = omni.usd.get_context().get_stage()
    with Sdf.ChangeBlock():
        for prim in iter_deactive_prims(stage.GetPrimAtPath("/")):
            prim.SetActive(False)

Thanks for the suggestion Richard. I had no issues with prims so far. But I am trying to hide individual instances of a point instancer. Is there an option to do that via the Composer UI as well so I could experiment with that?

Yes hiding things or deactivating things in the Composer UI, is very simply. Just use the “stage tree” to find the prim, and then click on the “eyeball” icon to hide or unhide. For Deactivating, you will need to be using at least kit 106, and then you need to add that specific column to your stage tree to toggle that on or off.

I think you did not understand the core of my question. I am wondering about the specifics of instances created by PointInstancers compared to “regular” prims.
Instances from a point instancer are not showing in the “stage tree” as prims do. Afaik I cannot select individual instances created by a point instancer.

Yes, that is correct. The point of a point instancer is to spawn many hundreds or thousands of points into a realtime viewport, without listing them all out in the stage tree. Otherwise, you may as well do it all manually.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.