Using USDRT with UsdGeomPoints

Hello,

I am running the following script on the script editor (Kit 106.0.2) to visualize a set of UsdGeomPoints data generated from a NumPy array.

import omni.usd
import usdrt
import numpy as np

stage_id = omni.usd.get_context().get_stage_id()
stage = usdrt.Usd.Stage.Attach(stage_id)

prim = stage.DefinePrim("/Points", "Points")
pts = usdrt.UsdGeom.Points(prim)

arr = np.linspace(0, 300, 3000000)
pts.CreatePointsAttr().Set(usdrt.Vt.Vec3fArray(arr.reshape(-1,3)))

pts_boundable = usdrt.Rt.Boundable(prim)
pts_world_ext = pts_boundable.CreateWorldExtentAttr()
pts_world_ext.Set(
    usdrt.Gf.Range3d(usdrt.Gf.Vec3d(0, 0, 0), usdrt.Gf.Vec3d(300, 300, 300))
)

This script won’t throw any error and creates the UsdGeomPoints object. However, it won’t show anything on the viewport. Fabric Scene Delegate is enabled as instructed on the documentation.

To test if any UsdGeomPoints are generated on the scene, I use the following snippet

print(type(pts))  # output: <class 'usdrt.UsdGeom._UsdGeom.Points'>
for item in stage.Traverse():
  print(item)

However, I can’t see /Pointsas the output of the stage traversing.

What could be the problem here?

Thanks,

The missing pieces here are transform attributes, visibility, and purpose. Our documentation is a bit behind. We’ll make a point to update it. This will generate points:

import omni.usd
import usdrt
import numpy as np

stage_id = omni.usd.get_context().get_stage_id()
stage = usdrt.Usd.Stage.Attach(stage_id)

prim = stage.DefinePrim("/Points", "Points")
pts = usdrt.UsdGeom.Points(prim)

arr = np.linspace(0, 300, 3000000, dtype=np.float32)
vtarr = usdrt.Vt.Vec3fArray(arr.reshape(-1,3))
widths = np.full((len(vtarr), 1), 1.0, dtype=np.float32)
vtwidths = usdrt.Vt.FloatArray(widths)
pts.CreatePointsAttr().Set(vtarr)
pts.CreateWidthsAttr().Set(vtwidths)

pts_boundable = usdrt.Rt.Boundable(prim)
pts_world_ext = pts_boundable.CreateWorldExtentAttr()
pts_world_ext.Set(
    usdrt.Gf.Range3d(usdrt.Gf.Vec3d(0, 0, 0), usdrt.Gf.Vec3d(300, 300, 300))
)
pts_boundable.CreateFabricHierarchyLocalMatrixAttr()
pts_boundable.CreateFabricHierarchyWorldMatrixAttr()
prim.CreateAttribute("_worldVisibility", usdrt.Sdf.ValueTypeNames.Bool, True).Set(True)
prim.CreateAttribute("purpose", usdrt.Sdf.ValueTypeNames.Token, False).Set("default")
1 Like

Thank you very much @Richard3D! I really appreciate the help!

Just as a reference to the users who might be reading this topic, the above script also works without the following lines:

widths = np.full((len(vtarr), 1), 1.0, dtype=np.float32)
vtwidths = usdrt.Vt.FloatArray(widths)
pts.CreateWidthsAttr().Set(vtwidths)

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