Skip to content

ipynbFile animation__USDでアニメーション.ipynb

USDでTransform/Rotateのアニメーション

In [39]:

1
from pxr import Usd,UsdGeom,Gf,Sdf

In [18]:

1
2
3
stage = Usd.Stage.CreateInMemory()
stage.SetStartTimeCode(1)
stage.SetEndTimeCode(30)

In [19]:

1
2
UsdGeom.Xform.Define(stage,"/sampleXform")
UsdGeom.Cube.Define(stage,"/sampleXform/Cube")

Success

1
UsdGeom.Cube(Usd.Prim(</sampleXform/Cube>))

In [20]:

1
prim = stage.GetPrimAtPath("/sampleXform")

In [21]:

1
api = UsdGeom.XformCommonAPI(prim)

In [35]:

1
UsdGeom.XformCommonAPI.RotationOrderXYZ

Success

1
UsdGeom.XformCommonAPI.RotationOrderXYZ

In [36]:

1
2
3
4
5
# アニメーションのキーを作る
api.SetTranslate(Gf.Vec3d(0,0,0),1)
api.SetTranslate(Gf.Vec3d(0,10,0),30)
api.SetRotate(Gf.Vec3f(0,0,0),UsdGeom.XformCommonAPI.RotationOrderXYZ,1)
api.SetRotate(Gf.Vec3f(0,0,360),UsdGeom.XformCommonAPI.RotationOrderXYZ,30)

Success

1
True

In [52]:

1
2
3
4
# 自分で作ったアトリビュート
attr = prim.CreateAttribute("sample",Sdf.ValueTypeNames.Int)
for i in range(1,30):
    attr.Set(i,i)

In [53]:

1
print(stage.GetRootLayer().ExportToString())

Success

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#usda 1.0
(
    endTimeCode = 30
    startTimeCode = 1
)

def Xform "sampleXform"
{
    custom int sample
    int sample.timeSamples = {
        1: 1,
        2: 2,
        3: 3,
        4: 4,
        5: 5,
        6: 6,
        7: 7,
        8: 8,
        9: 9,
        10: 10,
        11: 11,
        12: 12,
        13: 13,
        14: 14,
        15: 15,
        16: 16,
        17: 17,
        18: 18,
        19: 19,
        20: 20,
        21: 21,
        22: 22,
        23: 23,
        24: 24,
        25: 25,
        26: 26,
        27: 27,
        28: 28,
        29: 29,
        30: 30,
    }
    float3 xformOp:rotateXYZ.timeSamples = {
        1: (0, 0, 0),
        30: (0, 0, 360),
    }
    double3 xformOp:translate.timeSamples = {
        1: (0, 0, 0),
        30: (0, 10, 0),
    }
    uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ"]

    def Cube "Cube"
    {
    }
}

In [54]:

1
stage.GetRootLayer().Export("D:/animSample.usda")

Success

1
True