KOSME Example2 - SmartX-Team/Omniverse GitHub Wiki
๊ธฐ์กด WIKI ์ ์๋ ์๋ฃ๋ค์ ์ค์ต์ฉ ์ฝ๋๋ก ์ฌ๊ตฌ์ฑํ ์์ ๋ค ์ ๋๋ค.
Prim Create ๋ฐ ์กฐ์ ์์
Prim Create
import omni.usd
from pxr import Usd, UsdGeom
# ์คํ
์ด์ง ๊ฐ์ ธ์ค๊ธฐ
stage = omni.usd.get_context().get_stage()
# ์๋ก์ด Xform Prim ์์ฑ
prim_path = "/World/my_prim"
xform = UsdGeom.Xform.Define(stage, prim_path)
# Cube ์์ฑ
cube = UsdGeom.Cube.Define(stage, f"{prim_path}/cube")
cube.CreateSizeAttr(100)
print(f"Prim created at {prim_path}")
[์คํ ๊ฒฐ๊ณผ]
Prim Attribute ์์
import omni.usd
from pxr import Usd, UsdGeom, Gf
# ์คํ
์ด์ง ๊ฐ์ ธ์ค๊ธฐ
stage = omni.usd.get_context().get_stage()
# ์ด์ ์ ์์ฑํ Prim ๊ฐ์ ธ์ค๊ธฐ
prim_path = "/World/my_prim/cube"
cube = stage.GetPrimAtPath(prim_path)
# ํฌ๊ธฐ ์์ฑ ์์
size_attr = UsdGeom.Cube(cube).GetSizeAttr()
size_attr.Set(200)
# ์์ ์์ฑ ์ถ๊ฐ
cube_gprim = UsdGeom.Gprim(cube)
color_attr = cube_gprim.CreateDisplayColorAttr()
color_attr.Set([Gf.Vec3f(1.0, 0.0, 0.0)]) # ๋นจ๊ฐ์
print(f"Prim at {prim_path} updated with new size and color")
ํน์ prim์ ํ์ฌ ์์น ๊ด๋ จ ์์ฑ๊ฐ ์กฐํ
from pxr import Usd, UsdGeom, Sdf, Gf
from omni.usd import get_context
obj_name = "/World/HUSKY_01" # prim ์ฃผ์ ์ํฉ์ ๋ฐ๋ผ ๋ณ๊ฒฝ
stage = get_context().get_stage()
prim = stage.GetPrimAtPath(obj_name)
# ํ์ฌ ์์น ์กฐํ
translate_attr = prim.GetAttribute("xformOp:translate")
translation_value = translate_attr.Get()
print(f"translation: {translation_value }")
# ํ์ ์์ฑ ์กฐํ
rotation_attr = prim.GetAttribute('xformOp:rotateXYZ')
rotation_value = rotation_attr.Get()
print(f"Rotation: {rotation_value}")
# ํ์ฌ ์ค์ผ์ผ ์์ฑ ์กฐํ
scale_attr = prim.GetAttribute("xformOp:scale")
scale_value = scale_attr.Get()
print(f"Rotation: {scale_value}")
ํน์ prim์ ํ์ฌ ์์น ๊ด๋ จ ์์ฑ๊ฐ ๋ณ๊ฒฝ
from pxr import Usd, UsdGeom, Sdf, Gf
from omni.usd import get_context
obj_name = "/World/HUSKY_01" # prim ์ฃผ์ ์ํฉ์ ๋ฐ๋ผ ๋ณ๊ฒฝ
stage = get_context().get_stage()
prim = stage.GetPrimAtPath(obj_name)
TRANSLATION = Gf.Vec3d(100.0,50.0,0)
ROTATION = Gf.Vec3d(0,180.0,0)
SCALE = Gf.Vec3d(2.0,2.0,2.0)
# pirm ์์น ๋ณ๊ฒฝ
prim.GetAttribute("xformOp:translate").Set(Gf.Vec3d(TRANSLATION), 0)
# pirm ํ์
rotation_attr = prim.GetAttribute('xformOp:rotateXYZ').Set(Gf.Vec3d(ROTATION), 0)
# prim ์ค์ผ์ผ ๋ณ๊ฒฝ
scale_attr = prim.GetAttribute("xformOp:scale").Set(Gf.Vec3d(SCALE), 0)