Skip to content

Commit 4b6e259

Browse files
committed
store and load Fbx Export Settings from a mel script
mel script stored inside Unity project.
1 parent b38d799 commit 4b6e259

File tree

4 files changed

+112
-5
lines changed

4 files changed

+112
-5
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Integrations
1414
private const string VERSION_TAG = "{Version}";
1515
private const string PROJECT_TAG = "{UnityProject}";
1616

17+
private const string FBX_EXPORT_SETTINGS_PATH = "Integrations/Autodesk/maya2017/scripts/unityFbxExportSettings.mel";
18+
1719
public class MayaException : System.Exception {
1820
public MayaException() { }
1921
public MayaException(string message) : base(message) { }
@@ -175,8 +177,8 @@ static string AskVersion(string exePath) {
175177
#endif
176178

177179
private static string MAYA_COMMANDS { get {
178-
return string.Format("configureUnityOneClick {0}{1}{0} {0}{2}{0} {0}{3}{0} {4}; scriptJob -idleEvent quit;",
179-
ESCAPED_QUOTE, GetProjectPath(), GetAppPath(), GetTempSavePath(), (IsHeadlessInstall()?1:0));
180+
return string.Format("configureUnityOneClick {0}{1}{0} {0}{2}{0} {0}{3}{0} {0}{4}{0} {5}; scriptJob -idleEvent quit;",
181+
ESCAPED_QUOTE, GetProjectPath(), GetAppPath(), GetTempSavePath(), GetExportSettingsPath(), (IsHeadlessInstall()?1:0));
180182
}}
181183
private static Char[] FIELD_SEPARATORS = new Char[] {':'};
182184

@@ -249,6 +251,12 @@ public static string GetTempSavePath()
249251
return System.IO.Path.Combine(Application.dataPath, FbxExporters.Review.TurnTable.TempSavePath).Replace("\\", "/");
250252
}
251253

254+
public static string GetExportSettingsPath()
255+
{
256+
return System.IO.Path.Combine (Application.dataPath,
257+
FBX_EXPORT_SETTINGS_PATH).Replace ("\\", "/");
258+
}
259+
252260
public static string GetPackageVersion()
253261
{
254262
string result = null;

Assets/Integrations/Autodesk/maya2017/scripts/configureUnityOneClick.mel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
global proc configureUnityOneClick(string $unityProject, string $unityApp, string $unityTempSavePath, int $headless)
1+
global proc configureUnityOneClick(
2+
string $unityProject, string $unityApp,
3+
string $unityTempSavePath, string $unityFbxExportSettings, int $headless)
24
{
35
// configure plugin settings
46
optionVar -stringValue "UnityApp" $unityApp;
57
optionVar -stringValue "UnityProject" $unityProject;
68
optionVar -stringValue "UnityTempSavePath" $unityTempSavePath;
9+
optionVar -stringValue "UnityFbxExportSettings" $unityFbxExportSettings;
710
optionVar -intValue "UnityOneClick_Headless" $headless;
811

912
// configure auto load of plugin
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Geometry
2+
FBXExportSmoothingGroups -v false;
3+
FBXExportTangents -v false;
4+
FBXExportSmoothMesh -v false;
5+
FBXExportInstances -v true;
6+
FBXExportReferencedAssetsContent -v false;
7+
FBXExportTriangulate -v false;
8+
9+
// Animation
10+
FBXExportAnimationOnly -v false;
11+
12+
// Animation: Extra Options
13+
FBXExportUseSceneName -v false;
14+
FBXExportQuaternion -v resample;
15+
16+
// Animation: Bake Animation
17+
FBXExportBakeComplexAnimation -v true;
18+
FBXExportBakeComplexStart -v 1;
19+
FBXExportBakeComplexEnd -v 200;
20+
FBXExportBakeComplexStep -v 1;
21+
FBXExportBakeResampleAnimation -v false;
22+
23+
// Animation: Deformed Models
24+
FBXExportSkins -v true;
25+
FBXExportShapes -v true;
26+
27+
FBXExportApplyConstantKeyReducer -v false;
28+
29+
// Geometry Cache File(s)
30+
FBXExportCacheFile -v false;
31+
//FBXExportQuickSelectSetAsCache �v "";
32+
33+
// Constraints
34+
FBXExportConstraints -v false;
35+
FBXExportSkeletonDefinitions -v false;
36+
37+
FBXExportCameras -v false;
38+
FBXExportLights -v false;
39+
40+
FBXExportEmbeddedTextures -v false;
41+
FBXExportInputConnections -v true;
42+
43+
// Units
44+
FBXExportScaleFactor 1;
45+
FBXExportConvertUnitString cm;
46+
47+
// Axis Conversion
48+
FBXExportUpAxis y;
49+
50+
FBXExportGenerateLog -v true;
51+
52+
// FBX file format
53+
FBXExportInAscii -v false;
54+
FBXExportFileVersion -v FBX201600;
55+
56+
// Misc
57+
FBXExportHardEdges -v false;
58+
FBXExportAxisConversionMethod none;
59+
60+
FBXExportColladaFrameRate 30;
61+
FBXExportColladaSingleMatrix false;
62+
FBXExportColladaTriangulate false;
63+
64+
// Mac and Linux only
65+
if (`about -linux` || `about -macOS`){
66+
FBXExportDxfTriangulate false;
67+
FBXExportDxfDeformation false;
68+
}

Assets/Integrations/Autodesk/maya2017/scripts/unityOneClick/commands.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
ctypes.pythonapi.PyCObject_AsVoidPtr.restype = ctypes.c_void_p
3333
ctypes.pythonapi.PyCObject_AsVoidPtr.argtypes = [ctypes.py_object]
3434

35+
import os
36+
3537
UNITY_FBX_FILE_PATH = None
3638
UNITY_FBX_FILE_NAME = None
3739

@@ -57,7 +59,25 @@ def loadPlugin(self, plugin):
5759
return True
5860

5961
def loadDependencies(self):
60-
return self.loadPlugin('GamePipeline.mll')
62+
return self.loadPlugin('GamePipeline.mll') and self.loadPlugin('fbxmaya.mll')
63+
64+
def loadUnityFbxExportSettings(self):
65+
"""
66+
Load the Export Settings from file
67+
"""
68+
file = maya.cmds.optionVar(q="UnityFbxExportSettings")
69+
#unityProjectPath = maya.cmds.optionVar(q='UnityProject')
70+
#file = unityProjectPath + "/Integrations/Autodesk/maya2017/scripts/unityFbxExportSettings.mel"
71+
if not os.path.isfile(file):
72+
maya.cmds.error("Failed to find Unity Fbx Export Settings at: {0}".format(file))
73+
return False
74+
75+
with open(file) as f:
76+
contents = f.read()
77+
78+
maya.mel.eval(contents)
79+
return True
80+
6181

6282
class importCmd(BaseCommand):
6383
"""
@@ -103,6 +123,8 @@ def afterImport(self, *args, **kwargs):
103123
UNITY_FBX_FILE_NAME = self._tempName
104124

105125
def doIt(self, args):
126+
self.loadDependencies()
127+
106128
self._tempPath = None
107129
self._tempName = None
108130

@@ -174,9 +196,12 @@ def doIt(self, args):
174196
unityProjectPath = maya.cmds.optionVar(q='UnityProject')
175197
unityTempSavePath = maya.cmds.optionVar(q='UnityTempSavePath')
176198
unityCommand = "FbxExporters.Review.TurnTable.LastSavedModel"
199+
200+
if not self.loadUnityFbxExportSettings():
201+
return
177202

178203
# make sure the GamePipeline and fbxmaya plugins are loaded
179-
if self.loadDependencies() and self.loadPlugin('fbxmaya.mll'):
204+
if self.loadDependencies():
180205
# save fbx to Assets/_safe_to_delete/
181206
savePath = unityTempSavePath
182207
maya.cmds.sysFile(savePath, makeDir=True)
@@ -247,6 +272,9 @@ def doIt(self, args):
247272
if not self.loadDependencies():
248273
return
249274

275+
if not self.loadUnityFbxExportSettings():
276+
return
277+
250278
global UNITY_FBX_FILE_PATH
251279
global UNITY_FBX_FILE_NAME
252280
if UNITY_FBX_FILE_PATH and UNITY_FBX_FILE_NAME:

0 commit comments

Comments
 (0)