Skip to content

Commit 25c281f

Browse files
author
Benoit Hudson
committed
Merge branch 'master' into uni-23392-maya-versions
Conflict in InstallIntegration, Namespace change to ReviewLastSavedModel, New test in the IntegrationsTest for the new functionality from the merge.
2 parents bad29e6 + ed81925 commit 25c281f

File tree

6 files changed

+88
-6
lines changed

6 files changed

+88
-6
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ static string AskVersion(string exePath) {
175175
#endif
176176

177177
private static string MAYA_COMMANDS { get {
178-
return string.Format("configureUnityOneClick {3}{0}{3} {3}{1}{3} {2}; scriptJob -idleEvent quit;",
179-
GetProjectPath(), GetAppPath(), (IsHeadlessInstall()?1:0), ESCAPED_QUOTE);
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));
180180
}}
181181
private static Char[] FIELD_SEPARATORS = new Char[] {':'};
182182

@@ -244,6 +244,11 @@ public static string GetPackagePath()
244244
return System.IO.Path.Combine(Application.dataPath, PACKAGE_NAME);
245245
}
246246

247+
public static string GetTempSavePath()
248+
{
249+
return System.IO.Path.Combine(Application.dataPath, FbxExporters.Review.TurnTable.TempSavePath).Replace("\\", "/");
250+
}
251+
247252
public static string GetPackageVersion()
248253
{
249254
string result = null;

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class TurnTable
1212
const string ScenesPath = "Assets";
1313
const string SceneName = "FbxExporters_TurnTableReview";
1414

15+
public const string TempSavePath = "_safe_to_delete";
16+
1517
static string LastFilePath = null;
1618
static Object LastModel = null;
1719

@@ -50,7 +52,7 @@ private static string GetSceneFilePath ()
5052

5153
private static string GetLastSavedFilePath ()
5254
{
53-
string modelPath = FbxExporters.EditorTools.ExportSettings.GetAbsoluteSavePath ();
55+
string modelPath = FbxExporters.Editor.Integrations.GetTempSavePath ();
5456
System.IO.FileInfo fileInfo = GetLastSavedFile (modelPath);
5557

5658
return (fileInfo != null) ? fileInfo.FullName : null;
@@ -81,15 +83,32 @@ private static Object LoadModel (string fbxFileName)
8183
modelGO = UnityEditor.PrefabUtility.InstantiatePrefab (unityMainAsset) as GameObject;
8284

8385
GameObject turntableGO = GameObject.Find ("TurnTable");
84-
if (turntableGO!=null)
85-
{
86+
if (turntableGO != null) {
8687
modelGO.transform.parent = turntableGO.transform;
88+
turntableGO.AddComponent<RotateModel> ();
89+
} else {
90+
modelGO.AddComponent<RotateModel> ();
8791
}
8892
}
8993

94+
FrameCameraOnModel (modelGO);
95+
9096
return modelGO as Object;
9197
}
9298

99+
private static void FrameCameraOnModel(GameObject modelGO)
100+
{
101+
// Set so camera frames model
102+
// Note: this code assumes the model is at 0,0,0
103+
Vector3 boundsSize = modelGO.GetComponent<Renderer>().bounds.size;
104+
float distance = Mathf.Max(boundsSize.x, boundsSize.y, boundsSize.z);
105+
distance /= (2.0f * Mathf.Tan(0.5f * Camera.main.fieldOfView * Mathf.Deg2Rad));
106+
Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, -distance * 2.0f);
107+
108+
// rotate camera towards model
109+
Camera.main.transform.LookAt(modelGO.transform.position);
110+
}
111+
93112
private static void LoadLastSavedModel ()
94113
{
95114
string fbxFileName = GetLastSavedFilePath ();
@@ -179,13 +198,46 @@ public static void LastSavedModel ()
179198
// make turntable the active scene
180199
UnityEngine.SceneManagement.SceneManager.SetActiveScene (scene);
181200

201+
// create camera and light if none
202+
if (Camera.main == null) {
203+
GameObject camera = new GameObject ("MainCamera");
204+
camera.AddComponent<Camera> ();
205+
camera.tag = "MainCamera";
206+
}
207+
208+
if(!Object.FindObjectOfType<Light>()){
209+
GameObject light = new GameObject ("Light");
210+
light.transform.localEulerAngles = new Vector3 (50, -30, 0);
211+
Light lightComp = light.AddComponent<Light> ();
212+
lightComp.type = LightType.Directional;
213+
lightComp.intensity = 1;
214+
lightComp.shadows = LightShadows.Soft;
215+
}
216+
217+
// maximize game window and start playing
218+
var gameWindow = GetMainGameView();
219+
if (gameWindow) {
220+
gameWindow.maximized = true;
221+
UnityEditor.EditorApplication.isPlaying = true;
222+
} else {
223+
Debug.LogWarning ("Failed to access Game Window, please restart Unity to try again.");
224+
}
225+
182226
if (AutoUpdateEnabled ()) {
183227
LoadLastSavedModel ();
184228

185229
SubscribeToEvents ();
186230
}
187231
}
188232

233+
public static UnityEditor.EditorWindow GetMainGameView()
234+
{
235+
System.Reflection.Assembly assembly = typeof(UnityEditor.EditorWindow).Assembly;
236+
System.Type type = assembly.GetType("UnityEditor.GameView");
237+
UnityEditor.EditorWindow gameview = UnityEditor.EditorWindow.GetWindow(type, false, null, true);
238+
return gameview;
239+
}
240+
189241
private static void SubscribeToEvents ()
190242
{
191243
// ensure we only subscribe once

Assets/FbxExporters/Editor/UnitTests/IntegrationsTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public void BasicTest() {
4747
LogNonEmptyString("project path", Editor.Integrations.GetProjectPath());
4848
LogNonEmptyString("package path", Editor.Integrations.GetPackagePath());
4949
LogNonEmptyString("package version", Editor.Integrations.GetPackageVersion());
50+
LogNonEmptyString("temp path", Editor.Integrations.GetTempSavePath());
5051
}
5152
}
5253
}

Assets/FbxExporters/RotateModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class RotateModel : MonoBehaviour {
6+
7+
[Tooltip("Rotation speed in degrees/second")]
8+
[SerializeField]
9+
private float speed = 10f;
10+
11+
void Update () {
12+
transform.Rotate (Vector3.up, speed * Time.deltaTime, Space.World);
13+
}
14+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
global proc configureUnityOneClick(string $unityProject, string $unityApp, int $headless)
1+
global proc configureUnityOneClick(string $unityProject, string $unityApp, string $unityTempSavePath, int $headless)
22
{
33
// configure plugin settings
44
optionVar -stringValue "UnityApp" $unityApp;
55
optionVar -stringValue "UnityProject" $unityProject;
6+
optionVar -stringValue "UnityTempSavePath" $unityTempSavePath;
67
optionVar -intValue "UnityOneClick_Headless" $headless;
78

89
// configure auto load of plugin

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,17 @@ def doIt(self, args):
129129

130130
unityAppPath = maya.cmds.optionVar(q='UnityApp')
131131
unityProjectPath = maya.cmds.optionVar(q='UnityProject')
132+
unityTempSavePath = maya.cmds.optionVar(q='UnityTempSavePath')
132133
unityCommand = "FbxExporters.Review.TurnTable.LastSavedModel"
133134

135+
# make sure the GamePipeline and fbxmaya plugins are loaded
136+
if self.loadDependencies() and self.loadPlugin('fbxmaya.mll'):
137+
# save fbx to Assets/_safe_to_delete/
138+
savePath = unityTempSavePath
139+
maya.cmds.sysFile(savePath, makeDir=True)
140+
savePath = savePath + "/TurnTableModel.fbx"
141+
maya.mel.eval(r'file -force -options "" -typ "FBX export" -pr -es "{0}"'.format(savePath));
142+
134143
if maya.cmds.about(macOS=True):
135144
# Use 'open -a' to bring app to front if it has already been started.
136145
# Note that the unity command will not get called.

0 commit comments

Comments
 (0)