-
Notifications
You must be signed in to change notification settings - Fork 3
/
fbxExporterControler.py
150 lines (115 loc) · 3.94 KB
/
fbxExporterControler.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
# todo: add the start and end frame layout
# todo : run the export function through button
import maya.cmds as cmd
import maya.OpenMaya as api
import fbxExporterUI
import maya.OpenMaya as OpenMaya
import fbxExporterUtil
import os
winSelectCallback = None
sceneUpdateSelectCallback = None
#initialize Scene
#todo 1. select event 2.scene type 3.export Info
def initializeFile():
global isAnimation
global endFrame
global fileInfo
global fbxPreset
# path
fileInfo = fbxExporterUtil.getFileInfo()
savedPath = win.loadPath()
if savedPath == '':
targetPath = fileInfo[2]
else:
targetPath = savedPath + fileInfo[2].split('/')[-1]
print targetPath
endFrame = 0
win.setTargetPath(targetPath)
fbxPreset = geometryFBXPreset
isAnimation = False
def initializeWin():
cleanSlectCallback()
initializeFile()
cmd.button(win.fbxExExportBtn, edit = True, c = export)
def cleanSlectCallback():
global winSelectCallback
global sceneUpdateSelectCallback
global fileOpenCallback
if winSelectCallback != None:
OpenMaya.MMessage.removeCallback(winSelectCallback)
winSelectCallback = None
if sceneUpdateSelectCallback != None:
OpenMaya.MMessage.removeCallback(sceneUpdateSelectCallback)
sceneUpdateSelectCallback = None
if fileOpenCallback != None:
api.MSceneMessage.removeCallback(fileOpenCallback)
fileOpenCallback = None
def updateExportSelection():
global root
global fbxPreset
global isAnimation
global endFrame
root = fbxExporterUtil.getSceneRootFromSel()
if root !=None:
isAnimation = fbxExporterUtil.getSceneType(root)[0]
if isAnimation:
fbxPreset = animationFBXPreset
endFrame = fbxExporterUtil.getSceneType(root)[1]
print endFrame
win.setSceneType(isAnimation)
def export(*args):
global fileInfo
global isAnimation
global fbxPreset
global endFrame
global fileInfo
global root
# get export path
userPath = win.getTargetPath()
checkPath = os.path.dirname(userPath)
if root == None:
win.setFbxExInfoContent('please select one object to enable exporting')
elif not os.path.exists(checkPath):
win.setFbxExInfoContent('path does not exist')
else:
win.setFbxExInfoContent('exporting...')
# save temp File
fbxExporterUtil.fileSaveAsCopy(fileInfo[1])
# export
fbxExporterUtil.exportSceneFromRoot(root, isAnimation, fbxPreset, 0, endFrame, userPath)
# restore original file
fbxExporterUtil.fileRestoreOrigi(fileInfo[0], fileInfo[1])
# win.setFbxExInfoContent('exported')
def updateSceneSelectCallback(*args, **kwargs):
updateExportSelection()
def openFileCallback(*args):
initializeFile()
# window instance for the
def main():
global win
global winSelectCallback
global sceneUpdateSelectCallback
global fileOpenCallback
global root
global animationFBXPreset
global geometryFBXPreset
root = None
winSelectCallback = None
sceneUpdateSelectCallback = None
fileOpenCallback = None
localToolPath = fbxExporterUtil.getLocalToolPath()
animationFBXPreset = localToolPath +'/presets/IOFBXExportAnimation.fbxexportpreset'
geometryFBXPreset = localToolPath +'/presets/IOFBXExportGeometry.fbxexportpreset'
win = fbxExporterUI.fbxExporterWinUI()
initializeWin()
cmd.showWindow(win.window)
cleanSlectCallback()
cmd.scriptJob( uid = ['fbxExWindow',cleanSlectCallback])
winSelectCallback = OpenMaya.MEventMessage.addEventCallback("SelectionChanged", win.selectCallback)
sceneUpdateSelectCallback = OpenMaya.MEventMessage.addEventCallback("SelectionChanged", updateSceneSelectCallback)
fileOpenCallback = api.MSceneMessage.addCallback(api.MSceneMessage.kAfterOpen, openFileCallback)
reload(fbxExporterUtil)
reload(fbxExporterUI)
reload(fbxExporterUI)
# only for debug
main()