-
Notifications
You must be signed in to change notification settings - Fork 2
/
fbxhana4c4d.py
218 lines (175 loc) · 6.52 KB
/
fbxhana4c4d.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# The MIT License (MIT)
#
# Copyright (c) <year> <copyright holders>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
###############################################################################
from __future__ import unicode_literals
from __future__ import division
import os
import sys
import re
import codecs
from FbxCommon import *
def checkFormat(fbx):
with open(fbx, 'rb') as f:
line = f.read(20)
if line.startswith(r'Kaydara FBX Binary'):
return('binary')
else:
return('ascii')
pass
def hana2unicode(text):
str_univalue = re.sub(r"u'(.*?)'", '\\1', repr(text).replace('\\\\', '\\'))
return(str_univalue)
def DisplayMetaData(pScene):
sceneInfo = pScene.GetSceneInfo()
if sceneInfo:
print("\n--------------------\nMeta-Data\n--------------------\n")
print(" Title : %s" % sceneInfo.mTitle.Buffer())
print(" Subject : %s" % sceneInfo.mSubject.Buffer())
print(" Author : %s" % sceneInfo.mAuthor.Buffer())
print(" Keywords : %s" % sceneInfo.mKeywords.Buffer())
print(" Revision : %s" % sceneInfo.mRevision.Buffer())
print(" Comment : %s" % sceneInfo.mComment.Buffer())
pass
def shape2unicode(pGeometry):
lBlendShapeCount = pGeometry.GetDeformerCount(FbxDeformer.eBlendShape)
for lBlendShapeIndex in range(lBlendShapeCount):
lBlendShape = pGeometry.GetDeformer(lBlendShapeIndex, FbxDeformer.eBlendShape)
name_old = lBlendShape.GetName()
name_new = hana2unicode(name_old)
lBlendShape.SetName(name_new)
# DisplayString(u" BlendShape ", name_old, name_new)
lBlendShapeChannelCount = lBlendShape.GetBlendShapeChannelCount()
for lBlendShapeChannelIndex in range(lBlendShapeChannelCount):
lBlendShapeChannel = lBlendShape.GetBlendShapeChannel(lBlendShapeChannelIndex)
name_old = lBlendShapeChannel.GetName()
name_new = hana2unicode(name_old)
lBlendShapeChannel.SetName(name_new)
lTargetShapeCount = lBlendShapeChannel.GetTargetShapeCount()
for lTargetShapeIndex in range(lTargetShapeCount):
lShape = lBlendShapeChannel.GetTargetShape(lTargetShapeIndex)
name_old = lShape.GetName()
name_new = hana2unicode(name_old)
lShape.SetName(name_new)
pass
def marker2unicode(pNode):
lMarker = pNode.GetNodeAttribute()
name_old = pNode.GetName()
name_new = hana2unicode(name_old)
# pNode.SetName(name_new)
pass
def skeleton2unicode(pNode):
lSkeleton = pNode.GetNodeAttribute()
name_old = pNode.GetName()
name_new = hana2unicode(name_old)
# pNode.SetName(name_new)
pass
def mesh2unicode(pNode):
lMesh = pNode.GetNodeAttribute ()
name_old = pNode.GetName()
name_new = hana2unicode(name_old)
pNode.SetName(name_new)
shape2unicode(lMesh)
pass
def scene2unicode(pScene):
lNode = pScene.GetRootNode()
if lNode:
for i in range(lNode.GetChildCount()):
node2unicode(lNode.GetChild(i))
pass
def node2unicode(pNode):
if pNode.GetNodeAttribute() == None:
print("NULL Node Attribute\n")
else:
lAttributeType = (pNode.GetNodeAttribute().GetAttributeType())
if lAttributeType == FbxNodeAttribute.eMarker:
marker2unicode(pNode)
elif lAttributeType == FbxNodeAttribute.eSkeleton:
skeleton2unicode(pNode)
elif lAttributeType == FbxNodeAttribute.eMesh:
mesh2unicode(pNode)
# elif lAttributeType == FbxNodeAttribute.eNurbs:
# DisplayNurb(pNode)
# elif lAttributeType == FbxNodeAttribute.ePatch:
# DisplayPatch(pNode)
# elif lAttributeType == FbxNodeAttribute.eCamera:
# DisplayCamera(pNode)
# elif lAttributeType == FbxNodeAttribute.eLight:
# DisplayLight(pNode)
# DisplayUserProperties(pNode)
# DisplayTarget(pNode)
# DisplayPivotsAndLimits(pNode)
# DisplayTransformPropagation(pNode)
# DisplayGeometricTransform(pNode)
nodeName_old = pNode.GetName()
nodeName_new = hana2unicode(nodeName_old)
# pNode.SetName(nodeName_new)
for i in range(pNode.GetChildCount()):
node2unicode(pNode.GetChild(i))
def sdkLoadFBX(fbx, formatFollowSource=True, format=0):
# Checing source file binary/ascii
if formatFollowSource:
if checkFormat(fbx).lower() == 'binary':
format = 0
else:
format = 1
# Prepare the FBX SDK.
lSdkManager, lScene = InitializeSdkObjects()
# Load the scene.
lResult = LoadScene(lSdkManager, lScene, fbx)
if not lResult:
print("\n\nAn error occurred while loading the scene...")
else :
DisplayMetaData(lScene)
scene2unicode(lScene)
fs = os.path.splitext(fbx)
SaveScene(lSdkManager, lScene, u'%s_unicode%s' % (fs[0], fs[1]), pFileFormat=format)
# Destroy all objects created by the FBX SDK.
lSdkManager.Destroy()
pass
def main():
# Prepare the FBX SDK.
lSdkManager, lScene = InitializeSdkObjects()
# Load the scene.
ff = lSdkManager.GetIOPluginRegistry().GetWriterFormatCount()
print(ff)
lFormatCount = lSdkManager.GetIOPluginRegistry().GetWriterFormatCount()
for lFormatIndex in range(lFormatCount):
if lSdkManager.GetIOPluginRegistry().WriterIsFBX(lFormatIndex):
lDesc = lSdkManager.GetIOPluginRegistry().GetWriterFormatDescription(lFormatIndex)
print(lDesc)
if "ascii" in lDesc:
pFileFormat = lFormatIndex
print(pFileFormat)
break
# Destroy all objects created by the FBX SDK.
lSdkManager.Destroy()
pass
if __name__=='__main__':
if len(sys.argv)>1:
fbx = sys.argv[1]
if os.path.isfile(fbx):
sdkLoadFBX(fbx)
else:
main()