Skip to content

Commit 331e5c7

Browse files
committed
communicate between maya and unity with a file
Maya creates file on review, Unity checks if file exists, reviews if it does, then deletes the file.
1 parent 5219dac commit 331e5c7

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class Integrations
1616

1717
private const string FBX_EXPORT_SETTINGS_PATH = "Integrations/Autodesk/maya/scripts/unityFbxExportSettings.mel";
1818

19+
private const string MAYA_INSTRUCTION_FILENAME = "_safe_to_delete/_temp.txt";
20+
1921
public class MayaException : System.Exception {
2022
public MayaException() { }
2123
public MayaException(string message) : base(message) { }
@@ -177,8 +179,9 @@ static string AskVersion(string exePath) {
177179
#endif
178180

179181
private static string MAYA_COMMANDS { get {
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));
182+
return string.Format("configureUnityOneClick {0}{1}{0} {0}{2}{0} {0}{3}{0} {0}{4}{0} {0}{5}{0} {6}; scriptJob -idleEvent quit;",
183+
ESCAPED_QUOTE, GetProjectPath(), GetAppPath(), GetTempSavePath(),
184+
GetExportSettingsPath(), GetMayaInstructionPath(), (IsHeadlessInstall()?1:0));
182185
}}
183186
private static Char[] FIELD_SEPARATORS = new Char[] {':'};
184187

@@ -251,6 +254,20 @@ public static string GetTempSavePath()
251254
return FbxExporters.Review.TurnTable.TempSavePath.Replace("\\", "/");
252255
}
253256

257+
public static string GetMayaInstructionPath()
258+
{
259+
return MAYA_INSTRUCTION_FILENAME;
260+
}
261+
262+
/// <summary>
263+
/// Gets the full maya instruction path as an absolute Unity path.
264+
/// </summary>
265+
/// <returns>The full maya instruction path.</returns>
266+
public static string GetFullMayaInstructionPath()
267+
{
268+
return Application.dataPath + "/" + FbxExporters.Editor.Integrations.GetMayaInstructionPath ();
269+
}
270+
254271
/// <summary>
255272
/// Gets the path to the export settings file.
256273
/// Returns a relative path with forward slashes as path separators.

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ public class TurnTable
2424
static string LastFilePath = null;
2525
static Object LastModel = null;
2626

27+
static TurnTable(){
28+
UnityEditor.EditorApplication.update -= OnEditorUpdate;
29+
UnityEditor.EditorApplication.update += OnEditorUpdate;
30+
}
31+
32+
private static void OnEditorUpdate()
33+
{
34+
string instructionFile = FbxExporters.Editor.Integrations.GetFullMayaInstructionPath ();
35+
if(System.IO.File.Exists(instructionFile)){
36+
LastSavedModel ();
37+
System.IO.File.Delete (instructionFile);
38+
}
39+
}
40+
2741
private static System.IO.FileInfo GetLastSavedFile (string directoryPath, string ext = ".fbx")
2842
{
2943
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo (directoryPath);
@@ -100,12 +114,8 @@ private static Object LoadModel (string fbxFileName)
100114
}
101115

102116
modelGO.transform.parent = turntableGO.transform;
103-
104-
UnityEditor.Selection.objects = new GameObject[]{ turntableGO };
105117
}
106118

107-
FrameCameraOnModel (modelGO);
108-
109119
return modelGO as Object;
110120
}
111121

@@ -124,6 +134,10 @@ private static Bounds GetRendererBounds(GameObject modelGO)
124134

125135
private static void FrameCameraOnModel(GameObject modelGO)
126136
{
137+
if (modelGO == null) {
138+
return;
139+
}
140+
127141
// Set so camera frames model
128142
// Note: this code assumes the model is at 0,0,0
129143
Vector3 boundsSize = GetRendererBounds(modelGO).size;
@@ -155,6 +169,14 @@ private static void LoadLastSavedModel ()
155169
Debug.LogWarning (string.Format ("failed to load model : {0}", fbxFileName));
156170
}
157171
}
172+
if (LastModel != null) {
173+
var model = LastModel as GameObject;
174+
if (model != null) {
175+
var turntable = model.transform.parent.gameObject;
176+
UnityEditor.Selection.objects = new GameObject[]{ turntable };
177+
FrameCameraOnModel (turntable);
178+
}
179+
}
158180
}
159181

160182
public static void LastSavedModel ()

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
global proc configureUnityOneClick(
22
string $unityProject, string $unityApp,
3-
string $unityTempSavePath, string $unityFbxExportSettings, int $headless)
3+
string $unityTempSavePath, string $unityFbxExportSettings,
4+
string $mayaInstructionPath, int $headless)
45
{
56
// configure plugin settings
67
optionVar -stringValue "UnityApp" $unityApp;
78
optionVar -stringValue "UnityProject" $unityProject;
89
optionVar -stringValue "UnityTempSavePath" $unityTempSavePath;
910
optionVar -stringValue "UnityFbxExportSettings" $unityFbxExportSettings;
11+
optionVar -stringValue "UnityInstructionPath" $mayaInstructionPath;
1012
optionVar -intValue "UnityOneClick_Headless" $headless;
1113

1214
// configure auto load of plugin

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def doIt(self, args):
269269
unityProjectPath = maya.cmds.optionVar(q='UnityProject')
270270
unityTempSavePath = os.path.join(unityProjectPath, "Assets", maya.cmds.optionVar(q='UnityTempSavePath'))
271271
unityCommand = "FbxExporters.Review.TurnTable.LastSavedModel"
272+
instructionFile = os.path.join(unityProjectPath, "Assets", maya.cmds.optionVar(q='UnityInstructionPath'))
272273

273274
if not self.loadUnityFbxExportSettings():
274275
return
@@ -290,6 +291,10 @@ def doIt(self, args):
290291

291292
maya.cmds.file(savePath, force=True, options="", typ="FBX export", pr=True, es=True)
292293

294+
# create temp file in _safe_to_delete/
295+
with open(instructionFile,"w+") as f:
296+
pass
297+
293298
if maya.cmds.about(macOS=True):
294299
# Use 'open -a' to bring app to front if it has already been started.
295300
# Note that the unity command will not get called.

0 commit comments

Comments
 (0)