Skip to content

SOLARISでXformからUsdSkeletonを作る

ipynbFile usdskel_01__SOLARISでXformからUsdSkeletonを作る.ipynb

In [44]:

1
2
3
4
5
6
from pxr import Usd, UsdGeom, Sdf, UsdSkel
import re

stage = Usd.Stage.Open("D:/work/usd_py36/usd/char_base.usda")

hipRoot = "/xbot_fbx/mixamorig_Hips"

In [45]:

1
2
3
# Skelを作る
skelRoot = UsdSkel.Root.Define(stage, "/SkelRoot")
skel = UsdSkel.Skeleton.Define(stage, "/SkelRoot/Skeleton")

In [46]:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# XformになってるFbxのJoint階層をUsdSkel.Skeletoににするために
# 必要な情報取得

joints = []
jointsName = []
jointTransforms = []

ns = "mixamorig"

for prim in stage.Traverse():
    primStr = prim.GetPath().pathString
    if re.search("^" + hipRoot, primStr) is None:
        continue
    # NSなくす
    joint = re.sub(f"{ns}_", "", primStr.replace("/xbot_fbx/", ""))
    jointName = joint.split("/")[-1]
    transformMatrix = UsdGeom.Xform.Get(stage, prim.GetPath()).GetLocalTransformation(True)
    joints.append(joint)
    jointsName.append(jointName)
    jointTransforms.append(transformMatrix)

In [47]:

1
2
3
4
5
# SKelに値をセット
skel.CreateJointsAttr().Set(joints)
skel.CreateJointNamesAttr().Set(jointsName)
skel.CreateRestTransformsAttr(jointTransforms)
skel.CreateBindTransformsAttr(jointTransforms)

Success

1
Usd.Prim(</SkelRoot/Skeleton>).GetAttribute('bindTransforms')

In [48]:

1
stage.GetRootLayer().Export("D:/work/usd_py36/usd/createSkel.usda")

Success

1
True