-
Notifications
You must be signed in to change notification settings - Fork 0
/
Load_fbx_test.py
192 lines (159 loc) · 7.88 KB
/
Load_fbx_test.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import os
import numpy as np
import json
import wave
import librosa
import fbx
from fbx import FbxTime
from fbx_scene import FBX_Class
# from fbx import *
import samples
# from samples.ImportScene.DisplayCommon import *
from fbx import FbxNodeAttribute
from samples import FbxCommon
from samples.ImportScene import DisplayAnimation
from show import list_format, show_attribute
if __name__ == '__main__':
fbxManager, fbxScene = FbxCommon.InitializeSdkObjects()
filename = "[email protected]"
result = FbxCommon.LoadScene(fbxManager, fbxScene, filename) # 加载到了scene和manager里
# dir(scene)
root_node = fbxScene.GetRootNode()
show_attribute.print_node(root_node) # EType.eSkeleton
pNode = root_node.GetChild(0) # 不能是root
# pNode1 = root_node.GetChild(1) # 不能是root
# a = FBX_Class(filename)
# node = a.get_node_by_name('Spine')
# node_property = a.get_property(node, 'no_export')
# node_property_value = a.get_property_value(node, 'no_export')
# remove_property = a.remove_node_property(node, 'no_anim_export')
# remove_property = a.remove_node_property(node, 'no_export')
# remove_node = a.remove_nodes_by_names('hair_a_01')
# save_file = a.save(filename=r'd:\temp.fbx')
# dir(pNode)
camera = pNode.GetCamera()
# dir(camera)
# 就一个class
for i in range(fbxScene.GetSrcObjectCount(fbx.FbxCriteria.ObjectType(fbx.FbxAnimStack.ClassId))):
# Take 001 遍历 take
lAnimStack = fbxScene.GetSrcObject(fbx.FbxCriteria.ObjectType(fbx.FbxAnimStack.ClassId), i)
print("Take: %s" % lAnimStack.GetName())
lAnimLayer = lAnimStack.GetSrcObject(fbx.FbxCriteria.ObjectType(fbx.FbxAnimLayer.ClassId), i)
translation = pNode.LclTranslation.Get()
t_l = [translation[0], translation[1], translation[2]]
rotation = pNode.LclRotation.Get()
r_l = [rotation[0], rotation[1], rotation[2]]
scaling = pNode.LclScaling.Get()
s_l = [scaling[0], scaling[1], scaling[2]]
# 位移曲线
lAnimCurve1 = pNode.LclRotation.GetCurve(lAnimLayer, "X") # 不能是根节点, 必须是有实例的节点
if (lAnimCurve1 is not None):
lKeyCount1 = lAnimCurve1.KeyGetCount()
for lCount1 in range(lKeyCount1):
lKeyValue1 = lAnimCurve1.KeyGetValue(lCount1)
lKeyTime1 = lAnimCurve1.KeyGetTime(lCount1).GetSecondDouble()
# 旋转曲线
lAnimCurve2 = pNode.LclRotation.GetCurve(lAnimLayer, "Y")
if (lAnimCurve2 is not None):
lKeyCount2 = lAnimCurve2.KeyGetCount()
for lCount2 in range(lKeyCount2):
lKeyValue2 = lAnimCurve2.KeyGetValue(lCount2)
lKeyTime2 = lAnimCurve2.KeyGetTime(lCount2).GetSecondDouble()
# 缩放曲线
lAnimCurve3 = pNode.LclRotation.GetCurve(lAnimLayer, "Z")
if (lAnimCurve3 is not None):
lKeyCount3 = lAnimCurve3.KeyGetCount()
for lCount3 in range(lKeyCount3):
lKeyValue3 = lAnimCurve3.KeyGetValue(lCount3)
lKeyTime3 = lAnimCurve3.KeyGetTime(lCount3).GetSecondDouble()
role_KeyCount = lAnimCurve1.KeyGetCount()
for lCount in range(role_KeyCount):
lKeyValue = lAnimCurve1.KeyGetValue(lCount)
if lCount == 0:
start_key_value = lKeyValue
lKeyTime = lAnimCurve1.KeyGetTime(lCount)
new_value = lKeyValue - start_key_value
lAnimCurve1.KeySetValue(lCount, start_key_value)
thetime = fbx.FbxTime()
thetime.SetFrame(20)
glTm = pNode.EvaluateGlobalTransform(thetime) # 全局变换矩阵:节点坐标系的坐标转换到世界坐标系的变换矩阵。
lcTm = pNode.EvaluateLocalTransform(thetime) # 本地变换矩阵:节点坐标系的坐标转换到父节点坐标系的变换矩阵。
glTm_T = glTm.GetT()
glTm_R = glTm.GetR()
glTm_S = glTm.GetS()
glTm_TL = [glTm_T[0], glTm_T[1], glTm_T[2]]
glTm_RL = [glTm_R[0], glTm_R[1], glTm_R[2]]
glTm_SL = [glTm_S[0], glTm_S[1], glTm_S[2]]
geTm_1 = pNode.GetGeometricRotation(pNode.EPivotSet.eSourcePivot)
geTm_2 = pNode.GetGeometricRotation(pNode.EPivotSet.eDestinationPivot)
# 0 root_node
# 1 hips
# 2 spine
# 3 spine1
# 4 spine2
# 5 neck
# 6 neck1
# 7 head
# 8 headtop_end
# 9 leftshoulder
# 10 leftarm
# 11 leftforearm
# 12 lefthand
# 13 lefthandthumb1
# 14 lefthandthumb2
# 15 lefthandthumb3
# 16 lefthandthumb4
# 17 lefthandmiddle1
# 18 lefthandmiddle2
# 19 lefthandmiddle3
# 20 lefthandmiddle4
# 21 lefthandindex1
# 22 lefthandindex2
# 23 lefthandindex3
# 24 lefthandindex4
# 25 lefthandring1
# 26 lefthandring2
# 27 lefthandring3
# 28 lefthandring4
# 29 lefthandpinky1
# 30 lefthandpinky2
# 31 lefthandpinky3
# 32 lefthandpinky4
# 33 rightshoulder
# 34 righttarm
# 35 rightforearm
# 36 righthand
# 37 righthandthumb1
# 38 righthandthumb2
# 39 righthandthumb3
# 40 righthandthumb4
# 41 righthandmiddle1
# 42 righthandmiddle2
# 43 righthandmiddle3
# 44 righthandmiddle4
# 45 righthandindex1
# 46 righthandindex2
# 47 righthandindex3
# 48 righthandindex4
# 49 righthandring1
# 50 righthandring2
# 51 righthandring3
# 52 righthandring4
# 53 righthandpinky1
# 54 righthandpinky2
# 55 righthandpinky3
# 56 righthandpinky4
# 57 leftupleg
# 58 leftleg
# 59 leftfoot
# 60 lefttoebase
# 61 leftfoottoebase_end
# 62 rightupleg
# 63 rightleg
# 64 rightfoot
# 65 righttoebase
# 66 rightfoottoebase_end
# 67 BetaHighResMeshes
# 68 Beta_HighLimbsGeo
# 69 Beta_HighTorsoGeo
# 70 Beta_HighJointsGeo