@@ -3,6 +3,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
3
3
(
4
4
origObjects = #()
5
5
currSetName = " "
6
+ rootDummyName = " UnityFbxRootDummy"
6
7
7
8
persistent global unityFbxFilePathAttr
8
9
persistent global unityFbxFileNameAttr
@@ -32,7 +33,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
32
33
);
33
34
34
35
-- allow multiple files to be selected for import
35
- fn GetMultiOpenFilenames caption: " Open" filename: " " types: " All Files (*.*)|*.*" default: 1 =
36
+ fn getMultiOpenFilenames caption: " Open" filename: " " types: " All Files (*.*)|*.*" default: 1 =
36
37
(
37
38
local dialog = DotNetObject " System.Windows.Forms.OpenFileDialog"
38
39
dialog.multiSelect = true
@@ -51,6 +52,42 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
51
52
undefined
52
53
)
53
54
55
+ fn getOrCreateRootDummy = (
56
+ unityDummy = getNodeByName (rootDummyName)
57
+ if (unityDummy == undefined ) do (
58
+ unityDummy = Dummy()
59
+ unityDummy.name = rootDummyName
60
+ unityDummy.boxsize = [1 ,1 ,1 ]
61
+ )
62
+ unityDummy -- return dummy
63
+ )
64
+
65
+ fn getOrCreateSettingsDummy name = (
66
+ unityDummy = getNodeByName (name)
67
+ if (unityDummy == undefined ) do (
68
+ unityDummy = Dummy()
69
+ unityDummy.name = name
70
+ unityDummy.boxsize = [1 ,1 ,1 ]
71
+ )
72
+
73
+ if not (isProperty unityDummy " filePath" ) do (
74
+ unitySetData = attributes unityData
75
+ (
76
+ parameters main rollout: params
77
+ (
78
+ filePath type: #string ui: filep default: " "
79
+ fileName type: #string ui: filen default: " "
80
+ )
81
+ rollout params " Unity Export Parameters"
82
+ (
83
+ edittext filep " File Path:" text: filePath readOnly: false
84
+ edittext filen " File Name:" text: fileName readOnly: false
85
+ )
86
+ )
87
+ custAttributes.add unityDummy unitySetData #unique
88
+ )
89
+ unityDummy -- return dummy
90
+ )
54
91
55
92
-- Make sure the FbxImporter plugin is loaded
56
93
pluginManager.loadClass FbxImporter
@@ -81,11 +118,12 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
81
118
)
82
119
)
83
120
121
+ local unityFbxFilePathAttr = " "
84
122
for fbxFileName in fbxFileNames do (
85
123
-- Get all objects in scene before importAction
86
124
origObjects = objects as array
87
125
88
- local unityFbxFilePathAttr = getFilenamePath fbxFileName
126
+ unityFbxFilePathAttr = getFilenamePath fbxFileName
89
127
local unityFbxFileNameAttr = filenameFromPath fbxFileName
90
128
local unityFbxFileName = getFilenameFile fbxFileName
91
129
@@ -97,54 +135,34 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
97
135
98
136
-- check if dummy already exists in scene
99
137
currSetName = unityFbxFileName + " _UnityExportSet"
100
- unityDummy = getNodeByName (currSetName)
101
- if (unityDummy == undefined ) do (
102
- unityDummy = Dummy()
103
- unityDummy.name = currSetName
104
- unityDummy.boxsize = [1 ,1 ,1 ]
105
- )
106
-
107
- if not (isProperty unityDummy " filePath" ) do (
108
- unitySetData = attributes unityData
109
- (
110
- parameters main rollout: params
111
- (
112
- filePath type: #string ui: filep default: " "
113
- fileName type: #string ui: filen default: " "
114
- )
115
- rollout params " Unity Export Parameters"
116
- (
117
- edittext filep " File Path:" text: filePath readOnly: false
118
- edittext filen " File Name:" text: fileName readOnly: false
119
- )
120
- )
121
-
122
- custAttributes.add unityDummy unitySetData #unique
123
- )
138
+ unityDummy = getOrCreateSettingsDummy currSetName
124
139
125
140
unityDummy.unityData.filePath = unityFbxFilePathAttr
126
141
unityDummy.unityData.fileName = unityFbxFileNameAttr
127
142
128
- -- Change Unity project if fbx is from a different Unity project.
129
- -- Get the project based on the folder structure (i.e. folder above Assets)
130
- local head = unityFbxFilePathAttr
131
- head = trimRight head " \\ /"
132
- -- Check that we are not at the root directory.
133
- while head != " " and not (pathConfig.isRootPath head) do (
134
- if (pathConfig.stripPathToLeaf head) == " Assets" do (
135
- -- this is a valid Unity project, so set it
136
- unityProject = pathConfig.removePathLeaf head
137
- maxIniFile = (GetMAXIniFile())
138
- setINISetting maxIniFile " Unity" " UnityProject" unityProject
139
-
140
- -- in order to break out of loop without calling break (because "break" is slow)
141
- head = " "
142
- )
143
- head = pathConfig.removePathLeaf head
144
- )
143
+ unityRootDummy = getOrCreateRootDummy()
144
+ unityDummy.parent = unityRootDummy
145
145
146
146
callbacks.removeScripts #postImport id: #unityPlugin
147
147
)
148
+
149
+ -- Change Unity project if fbx is from a different Unity project.
150
+ -- Get the project based on the folder structure (i.e. folder above Assets)
151
+ local head = unityFbxFilePathAttr
152
+ head = trimRight head " \\ /"
153
+ -- Check that we are not at the root directory.
154
+ while head != " " and not (pathConfig.isRootPath head) do (
155
+ if (pathConfig.stripPathToLeaf head) == " Assets" do (
156
+ -- this is a valid Unity project, so set it
157
+ unityProject = pathConfig.removePathLeaf head
158
+ maxIniFile = (GetMAXIniFile())
159
+ setINISetting maxIniFile " Unity" " UnityProject" unityProject
160
+
161
+ -- in order to break out of loop without calling break (because "break" is slow)
162
+ head = " "
163
+ )
164
+ head = pathConfig.removePathLeaf head
165
+ )
148
166
)
149
167
)
150
168
macroScript UnityExport category: " Unity" tooltip: " Export a model to Unity"
0 commit comments