@@ -5,6 +5,7 @@ macroScript UnityImport category:"Unity"
5
5
6
6
persistent global unityFbxFilePathAttr
7
7
persistent global unityFbxFileNameAttr
8
+ persistent global unityAskSetUnits
8
9
9
10
global afterImport
10
11
fn afterImport = (
@@ -29,6 +30,24 @@ macroScript UnityImport category:"Unity"
29
30
fbxFileName = getOpenFileName caption: " Import FBX from Unity" filename: (unityProjectPath + " /Assets/" ) types: " FBX (*.fbx)|*.fbx|"
30
31
if fbxFileName != undefined then
31
32
(
33
+ -- ask to set units to cm if not already
34
+ if (unityAskSetUnits == undefined or not unityAskSetUnits) and units.SystemType != #Centimeters then (
35
+ result = false
36
+ message = (" Detected system units set to " + units.SystemType+ " .\n\n " +
37
+ " Using system units other than centimeters is not recommended for the Unity FBX " +
38
+ " workflow and may result in unexpected scaling on export.\n\n " +
39
+ " Would you like to change the system units to centimeters?" )
40
+ (
41
+ result = queryBox message title: " Warning, system units not set to centimeters"
42
+ )
43
+ if result then (
44
+ units.SystemType = #Centimeters
45
+ )
46
+ else (
47
+ unityAskSetUnits = true
48
+ )
49
+ )
50
+
32
51
-- reset persistent values, in case import fails
33
52
unityFbxFilePathAttr = " "
34
53
unityFbxFileNameAttr = " "
@@ -65,12 +84,25 @@ macroScript UnityImport category:"Unity"
65
84
)
66
85
macroScript UnityExport category: " Unity"
67
86
(
87
+ fn unitToScaleFactor unit = (
88
+ case unit of (
89
+ #Inches : 2.54
90
+ #Feet : 30.48
91
+ #Miles : 160934
92
+ #Millimeters : 0.1
93
+ #Kilometers : 100000
94
+ #Meters : 100
95
+ default: 1
96
+ )
97
+ );
98
+
68
99
fn loadUnityFbxExportSettings = (
69
100
fbxExportSettings = getINISetting (GetMAXIniFile()) " Unity" " UnityFbxExportSettings"
70
101
if fbxExportSettings != undefined and doesFileExist fbxExportSettings then (
71
102
filein fbxExportSettings
72
103
)
73
- )
104
+ FbxExporterSetParam " ScaleFactor" (unitToScaleFactor units.SystemType)
105
+ );
74
106
75
107
-- Make sure the FbxExporter plugin is loaded
76
108
pluginManager.loadClass FbxExporter
@@ -83,6 +115,9 @@ macroScript UnityExport category:"Unity"
83
115
select exportSet
84
116
)
85
117
118
+ local origUnits = units.SystemType
119
+ units.SystemType = #Centimeters
120
+
86
121
exportFileName = undefined
87
122
if unityFbxFilePathAttr != undefined and unityFbxFileNameAttr != undefined then (
88
123
exportFileName = unityFbxFilePathAttr + unityFbxFileNameAttr
@@ -96,6 +131,8 @@ macroScript UnityExport category:"Unity"
96
131
exportFile exportFileName #noPrompt selectedOnly: true using: FBXEXP
97
132
)
98
133
134
+ units.SystemType = origUnits
135
+
99
136
if origSelection != undefined then (
100
137
select origSelection
101
138
)
0 commit comments