Hi,
I need to perform a simple task but I struggle to find how to do it.
I have a 3D mesh that is saved in a USD file.
I have no problem adding it to the stage manually but I want to do it with Python in an extension as I need to add lots of these objects and script the positions.
The examples use “CreateMeshPrimCommand”. I found some documentation about this but it is very limited:
https://docs.omniverse.nvidia.com/kit/docs/omni.kit.usd_docs/latest/index.html#prims
Could you point me towards a more precise documentation or give an example of that ?
Thanks
My current draft:
def create_mesh(
x: float = 0.0,
y: float = 0.0,
z: float = 0.0,
Rx: float = 0.0,
Ry: float = 1.0,
Rz: float = 0.0,
angle: float = 0.0,
source_file: str = "./exts_user/my_ext/usd/my_mesh.usd",
name: str = "my_name",
):
"""Create a mesh"""
usd_path = f"/World/physicsScene/{name}",
# Get the stage
stage = omni.usd.get_context().get_stage()
# Create the mesh
result, path = omni.kit.commands.execute("CreateMeshPrimCommand", prim_type="Mesh")
# TODO
# How to load the mesh from a USD file?
# Get the prim
my_prim = stage.GetPrimAtPath("/Mesh")
# Enable physics on prim
# To account for the hole, we use convexDecomposition instead of convexHull
utils.setRigidBody(my_prim, "convexDecomposition", False)
# Add a mass
mass_api = UsdPhysics.MassAPI.Apply(my_prim)
# If we know the mass:
# mass_api.CreateMassAttr(10)
# Or set the density instead:
mass_api.CreateDensityAttr(1000)
# Add a transform
xform = UsdGeom.Xformable(my_prim)
transform = xform.AddTransformOp()
mat = Gf.Matrix4d()
mat.SetTranslateOnly(Gf.Vec3d(x,y,z))
mat.SetRotateOnly(Gf.Rotation(Gf.Vec3d(Rx,Ry,Rz), angle))
transform.Set(mat)
return my_prim