This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import omni.usd | |
from pxr import UsdGeom, Usd, UsdGeom | |
def get_prims_startswith(stage, root_path, starts_with): | |
matching_prims = [] | |
root_prim = stage.GetPrimAtPath(root_path) | |
for prim in Usd.PrimRange(root_prim): | |
if prim.GetName().startswith(starts_with): | |
matching_prims.append(prim) | |
return matching_prims |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# def _get_cameras(stage, filter) -> typing.List: | |
# """ Get all cameras in the scene except for the ones that are excluded (ie: Perspective, Top, Left, Right cameras) | |
# """ | |
# cameras = {} | |
# for prim in Usd.PrimRange(stage.GetPseudoRoot()): | |
# if prim.IsA(UsdGeom.Camera) and prim.GetName(): | |
# if filter in prim.GetPath().pathString: | |
# cameras[prim.GetName()] = prim.GetPath().pathString | |
# return cameras |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xform = UsdGeom.Xform.Define(stage, '/my_prim') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pxr import UsdGeom, Usd | |
stage_path = "D:\\Source\\internal\\projects\\example_simgen\\input\\stage_xxx2usd.usda" | |
stage = Usd.Stage.Open(stage_path) | |
prim_path = "/stage/Device_rig" | |
tx_prop = UsdGeom.Xform.Get(stage, prim_path) | |
times = tx_prop.GetTimeSamples() | |
transforms = [] | |
for time in times: | |
transforms.append(tx_prop.GetLocalTransformation(time=time)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pxr import UsdGeom, Usd, UsdGeom | |
stage = Usd.Stage.Open('stage.usda') | |
device_prim = stage.GetPrimAtPath('/world/device') | |
for prim in Usd.PrimRange(device_prim): | |
if prim.IsA(UsdGeom.Camera): | |
print(prim.GetName()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Not sure what I have here | |
# from pxr import Gf, Usd, UsdGeom | |
# pose = Gf.Matrix4d(0.10028808960009783, 1.0899614544257474e-13, -0.9949584408830167, 0, -0.2896496895839791, 0.9566873438849783, -0.02919560539207469, 0, 0.9518641480843092, 0.29111737504021507, 0.09594434606284785, 0, 170.13235291094, 118.33856922920114, -26.433392816374774, 1) | |
# rotateAroundX = Gf.Matrix3d(1, 0, 0, 0, 0, -1, 0, 1, 0) | |
# rotation = pose.ExtractRotation() | |
# print(f'rotation={rotation}') | |
# print(f'type(rotation)={type(rotation)}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import omni.kit.app as _app | |
# import omni.usd as _usd | |
# import omni.client | |
# import omni.renderer_capture | |
# import omni.timeline | |
# from omni.kit import app | |
# USD setting viewport | |
width = 640 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# procedural variants | |
import omni.usd as _usd | |
stage = _usd.get_context().get_stage() | |
rootPrim = stage.GetPrimAtPath('/base_stage') | |
#rootPrim = stage.GetPseudoRoot() | |
vset = rootPrim.GetVariantSets() | |
print(vset.GetNames()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# USD get transform property at path | |
import omni.usd | |
prim_path = '/Motions/traj_' | |
stage = omni.usd.get_context().get_stage() | |
prop = stage.GetPropertyAtPath(f"{prim_path}.xformOp:transform") | |
value = prop.Get() | |
print(value) | |
# or |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# USD get prim | |
import omni.usd | |
from pxr import UsdGeom | |
stage = omni.usd.get_context().get_stage() | |
prim = stage.GetPrimAtPath('/Motions') | |
# look at children of prim and print path as string | |
target_prim_path = prim.GetAllChildren()[0].GetPath().pathString |
NewerOlder