@@ -12,47 +12,6 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
12
12
13
13
persistent global unityAskSetUnits
14
14
15
- fn getOrCreateDummy name = (
16
- unityDummy = getNodeByName (name)
17
- if (unityDummy == undefined ) do (
18
- unityDummy = Dummy()
19
- unityDummy.name = name
20
- unityDummy.boxsize = [1 ,1 ,1 ]
21
- )
22
- unityDummy -- return dummy
23
- )
24
-
25
- fn getOrCreateRootDummy = (
26
- getOrCreateDummy rootDummyName
27
- )
28
-
29
- fn getOrCreateSettingsDummy name = (
30
- unityDummy = getOrCreateDummy name
31
-
32
- if not (isProperty unityDummy " modelFilePath" ) do (
33
- unitySetData = attributes unityData
34
- (
35
- parameters main rollout: params
36
- (
37
- modelFilePath type: #string ui: filep default: " "
38
- modelFileName type: #string ui: filen default: " "
39
- animFilePath type: #string ui: afilep default: " "
40
- animFileName type: #string ui: afilen default: " "
41
- )
42
- rollout params " Unity Export Parameters"
43
- (
44
- edittext filep " Model File Path:" text: modelFilePath readOnly: false labelOnTop: true
45
- edittext filen " Model File Name:" text: modelFileName readOnly: false labelOnTop: true
46
- edittext afilep " Animation File Path:" text: animFilePath readOnly: false labelOnTop: true
47
- edittext afilen " Animation File Name:" text: animFileName readOnly: false labelOnTop: true
48
- )
49
- )
50
- custAttributes.add unityDummy unitySetData
51
- )
52
-
53
- unityDummy -- return dummy
54
- )
55
-
56
15
global afterImport
57
16
fn afterImport = (
58
17
unityFbxExportSet = #()
@@ -69,7 +28,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
69
28
selectionSets[currSetName] = unityFbxExportSet
70
29
71
30
-- check if dummy already exists in scene
72
- unityDummy = getOrCreateSettingsDummy currSetName
31
+ unityDummy = UnityImportHelpers. getOrCreateSettingsDummy currSetName
73
32
74
33
if ((not isAnimFile) or unityDummy.unityData.modelFilePath == " " ) do (
75
34
unityDummy.unityData.modelFilePath = unityFbxFilePathAttr
@@ -80,46 +39,19 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
80
39
unityDummy.unityData.animFilePath = unityAnimFilePathAttr
81
40
unityDummy.unityData.animFileName = unityAnimFileNameAttr
82
41
83
- unityRootDummy = getOrCreateRootDummy()
42
+ unityRootDummy = UnityImportHelpers. getOrCreateRootDummy rootDummyName
84
43
unityDummy.parent = unityRootDummy
85
44
);
86
45
87
- fn loadUnityFbxImportSettings = (
88
- fbxImportSettings = getINISetting (GetMAXIniFile()) " Unity" " UnityFbxImportSettings"
89
- if fbxImportSettings != undefined and doesFileExist fbxImportSettings then (
90
- filein fbxImportSettings
91
- )
92
- );
93
-
94
- -- allow multiple files to be selected for import
95
- fn getMultiOpenFilenames caption: " Open" filename: " " types: " All Files (*.*)|*.*" default: 1 =
96
- (
97
- local dialog = DotNetObject " System.Windows.Forms.OpenFileDialog"
98
- dialog.multiSelect = true
99
- dialog.title = caption
100
-
101
- if doesFileExist filename then
102
- dialog.initialDirectory = filename
103
-
104
- dialog.filter = types
105
- dialog.filterIndex = default
106
-
107
- local result = dialog.ShowDialog()
108
- if (result.Equals result.OK) then
109
- dialog.filenames
110
- else
111
- undefined
112
- )
113
-
114
46
-- Make sure the FbxImporter plugin is loaded
115
47
pluginManager.loadClass FbxImporter
116
48
117
- loadUnityFbxImportSettings()
49
+ UnityImportHelpers. loadUnityFbxImportSettings()
118
50
119
51
unityProjectPath = getINISetting (GetMAXIniFile()) " Unity" " UnityProject"
120
52
local unityAssetsPath = (unityProjectPath + " /Assets/" )
121
53
unityAssetsPath = substituteString unityAssetsPath " /" " \\ " -- dot net class requires backspaces
122
- local fbxFileNames = getMultiOpenFilenames caption: " Import FBX from Unity" filename: unityAssetsPath types: " FBX (*.fbx)|*.fbx"
54
+ local fbxFileNames = UnityImportHelpers. getMultiOpenFilenames caption: " Import FBX from Unity" filename: unityAssetsPath types: " FBX (*.fbx)|*.fbx"
123
55
if fbxFileNames != undefined then
124
56
(
125
57
-- ask to set units to cm if not already
@@ -168,9 +100,51 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
168
100
callbacks.removeScripts #postImport id: #unityPlugin
169
101
)
170
102
103
+ UnityImportHelpers.switchProject unityFbxFilePathAttr
104
+ )
105
+ )
106
+ macroScript UnityExport category: " Unity" tooltip: " Export models and animation to Unity"
107
+ (
108
+ UnityExportHelpers.exportSelection modelOnly: false
109
+ )
110
+
111
+ macroScript UnityExportModel category: " Unity" tooltip: " Export models to Unity"
112
+ (
113
+ UnityExportHelpers.exportSelection modelOnly: true
114
+ )
115
+
116
+ struct UnityImportHelpers (
117
+ fn loadUnityFbxImportSettings = (
118
+ fbxImportSettings = getINISetting (GetMAXIniFile()) " Unity" " UnityFbxImportSettings"
119
+ if fbxImportSettings != undefined and doesFileExist fbxImportSettings then (
120
+ filein fbxImportSettings
121
+ )
122
+ ),
123
+
124
+ -- allow multiple files to be selected for import
125
+ fn getMultiOpenFilenames caption: " Open" filename: " " types: " All Files (*.*)|*.*" default: 1 =
126
+ (
127
+ local dialog = DotNetObject " System.Windows.Forms.OpenFileDialog"
128
+ dialog.multiSelect = true
129
+ dialog.title = caption
130
+
131
+ if doesFileExist filename then
132
+ dialog.initialDirectory = filename
133
+
134
+ dialog.filter = types
135
+ dialog.filterIndex = default
136
+
137
+ local result = dialog.ShowDialog()
138
+ if (result.Equals result.OK) then
139
+ dialog.filenames
140
+ else
141
+ undefined
142
+ ),
143
+
144
+ fn switchProject filePath = (
171
145
-- Change Unity project if fbx is from a different Unity project.
172
146
-- Get the project based on the folder structure (i.e. folder above Assets)
173
- local head = unityFbxFilePathAttr
147
+ local head = filePath
174
148
head = trimRight head " \\ /"
175
149
-- Check that we are not at the root directory.
176
150
while head != " " and not (pathConfig.isRootPath head) do (
@@ -185,17 +159,49 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
185
159
)
186
160
head = pathConfig.removePathLeaf head
187
161
)
162
+ ),
163
+
164
+ fn getOrCreateDummy name = (
165
+ unityDummy = getNodeByName (name)
166
+ if (unityDummy == undefined ) do (
167
+ unityDummy = Dummy()
168
+ unityDummy.name = name
169
+ unityDummy.boxsize = [1 ,1 ,1 ]
170
+ )
171
+ unityDummy -- return dummy
172
+ ),
173
+
174
+ fn getOrCreateRootDummy rootDummyName = (
175
+ UnityImportHelpers.getOrCreateDummy rootDummyName
176
+ ),
177
+
178
+ fn getOrCreateSettingsDummy name = (
179
+ unityDummy = UnityImportHelpers.getOrCreateDummy name
180
+
181
+ if not (isProperty unityDummy " modelFilePath" ) do (
182
+ unitySetData = attributes unityData
183
+ (
184
+ parameters main rollout: params
185
+ (
186
+ modelFilePath type: #string ui: filep default: " "
187
+ modelFileName type: #string ui: filen default: " "
188
+ animFilePath type: #string ui: afilep default: " "
189
+ animFileName type: #string ui: afilen default: " "
190
+ )
191
+ rollout params " Unity Export Parameters"
192
+ (
193
+ edittext filep " Model File Path:" text: modelFilePath readOnly: false labelOnTop: true
194
+ edittext filen " Model File Name:" text: modelFileName readOnly: false labelOnTop: true
195
+ edittext afilep " Animation File Path:" text: animFilePath readOnly: false labelOnTop: true
196
+ edittext afilen " Animation File Name:" text: animFileName readOnly: false labelOnTop: true
197
+ )
198
+ )
199
+ custAttributes.add unityDummy unitySetData
200
+ )
201
+
202
+ unityDummy -- return dummy
188
203
)
189
204
)
190
- macroScript UnityExport category: " Unity" tooltip: " Export models and animation to Unity"
191
- (
192
- UnityExportHelpers.exportSelection modelOnly: false
193
- )
194
-
195
- macroScript UnityExportModel category: " Unity" tooltip: " Export models to Unity"
196
- (
197
- UnityExportHelpers.exportSelection modelOnly: true
198
- )
199
205
200
206
struct UnityExportHelpers (
201
207
fn unitToScaleFactor unit = (
0 commit comments