I want to annotate some labels relative to the geometry on the USD model in IsaacSim, so I need to get the surface normals on the mesh, but the function UsdGeom.Mesh.GetNormalsAttr().Get()
seems only return the normal vectors without their position, and the number of the normals are neither the same as the number of faces or the number of vertexs. The interpolation method got from GetNormalsInterpolation()
is “faceVarying”, in such condition how can I get the correspounding position of the normals?
The code I used is as follows:
dest_path = 'bottle.usd'
omni.usd.get_context().open_stage(dest_path)
while is_stage_loading():
simulation_app.update()
stage = get_current_stage()
root_prim = stage.GetDefaultPrim()
if not root_prim.HasProperty('physics:rigidBodyEnabled'):
omni.kit.commands.execute('AddPhysicsComponent', usd_prim=root_prim, component='PhysicsRigidBodyAPI')
for prim in stage.Traverse():
prim: Usd.Prim
if prim.GetTypeName() == 'Mesh':
if prim.GetAttribute('visibility').Get() == 'invisible':
continue
omni.kit.commands.execute('SetStaticCollider', path=prim.GetPath(), approximationShape='convexDecomposition')
mesh = UsdGeom.Mesh(prim)
points = np.array(mesh.GetPointsAttr().Get())
normals = np.array(mesh.GetNormalsAttr().Get())
print(points.shape) # [2564, 3]
print(normals.shape) # [14058, 3]
print(mesh.GetPrim().GetAttribute("primvars:normals").Get()) # None