@ruben2048 From a high level, it sounds like you want to build a library from the obj assets. If I were to try and do this, I would convert the objs to usd and save those to a directory for loading later in a replicator script.
There’s probably a few approaches to adding the labels:
- First there’s the manual way, which would be going into each usd manually and adding the labels.
- Second you could write a script to iterate through the usds and label them automatically if you have a source of data (csv, json, etc) to pull the relevant labels to the obj/usd and apply them.
- Third is that in the replicator script when generating the data, you could apply the semantics at runtime.
Adding Semantics to a Scene — Omniverse Extensions latest documentation (nvidia.com)
This page details how to do this by hand (#1) and in a replicator script at runtime (#3).
If you wanted to do this in an automated script to batch through a bunch of assets (#2) you would probably want to use pure python and USD/Kit. I put together this example of spawning a cube and a cone, and applying semantics to them.
Pay special attention to add_prim_semantics() which comes from the import from semantics.schema.editor import add_prim_semantics, LabelWriteType
Full script here. Again the below is not a replicator script, but is suitable for batching with pure python.
I hope this helps!
from semantics.schema.editor import add_prim_semantics, LabelWriteType
import omni
from pxr import Gf, UsdGeom
def set_transform(mesh_prim, prim_pos, prim_rot, prim_scale):
stage = omni.usd.get_context().get_stage()
xform = UsdGeom.Xformable(mesh_prim)
xform_ops = {op.GetBaseName(): op for op in xform.GetOrderedXformOps()}
for op in xform.GetOrderedXformOps():
if "translate" in op.GetName():
translate_op = xform_ops["translate"]
translate_op.Set(Gf.Vec3d(prim_pos[0],prim_pos[1],prim_pos[2]))
elif "rotate" in op.GetName():
rotate_op = xform_ops["rotateXYZ"]
rotate_op.Set(Gf.Vec3d(prim_rot[0],prim_rot[1],prim_rot[2]))
elif "scale" in op.GetName():
scale_op = xform_ops["scale"]
scale_op.Set(Gf.Vec3d(prim_scale[0],prim_scale[1],prim_scale[2]))
def spawn_mesh(mesh_type, pos, rot, scale):
# I decided to make my own function to spawn basic meshes in this example. Using rep, its much simpler
# but I wanted to show an example that doesn't generate ANY omnigraph nodes.
stage = omni.usd.get_context().get_stage()
mesh_prim = []
if mesh_type == "Cube":
result, path = omni.kit.commands.execute("CreateMeshPrimCommand", prim_type="Cube")
mesh_prim = stage.GetPrimAtPath(path)
set_transform(mesh_prim, pos, rot, scale)
elif mesh_type == "Cone":
result, path = omni.kit.commands.execute("CreateMeshPrimCommand", prim_type="Cone")
mesh_prim = stage.GetPrimAtPath(path)
set_transform(mesh_prim, pos, rot, scale)
return mesh_prim
# Meshes too - cone, floor, wall1, and wall2
annot_cone = spawn_mesh("Cone",(-125,100,125), (0,0,0), (2,2,2))
annot_cube = spawn_mesh("Cube",(125,80,-125), (0,0,0), (2,2,2))
# Setup semantics
add_prim_semantics(prim=annot_cone, type="class", data="cone", write_type=LabelWriteType.OVERWRITE,)
add_prim_semantics(prim=annot_cube, type="class", data="cube", write_type=LabelWriteType.OVERWRITE,)