Skip to content

Commit 4be9458

Browse files
author
Benoit Hudson
committed
Merge branch 'master' into uni-22029-prefab-redux
2 parents a1846c2 + 64f98d9 commit 4be9458

File tree

14 files changed

+401
-53
lines changed

14 files changed

+401
-53
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
132132
}
133133

134134
// Instantiate the FBX file.
135-
Object unityObj = PrefabUtility.InstantiatePrefab (unityMainAsset);
135+
Object unityObj = PrefabUtility.InstantiatePrefab (unityMainAsset, gosToExport[i].scene);
136136
GameObject unityGO = unityObj as GameObject;
137137
if (!unityGO) {
138138
continue;

Assets/FbxExporters/Editor/EditorRotate.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
namespace FbxExporters.Review
1515
{
16-
[CustomEditor (typeof(RotateModel))]
16+
[CustomEditor (typeof(FbxTurnTableBase))]
1717
public class EditorRotate : UnityEditor.Editor
1818
{
19-
RotateModel model;
19+
FbxTurnTableBase model;
2020

2121
public void OnEnable ()
2222
{
23-
model = (RotateModel)target;
23+
model = (FbxTurnTableBase)target;
2424
EditorApplication.update += Update;
2525
}
2626

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,24 @@ public override void OnInspectorGUI() {
6565
Debug.LogWarning ("Please select a location in the Assets folder");
6666
} else {
6767
ExportSettings.SetRelativeSavePath(relativePath);
68+
69+
// Make sure focus is removed from the selectable label
70+
// otherwise it won't update
71+
GUIUtility.hotControl = 0;
72+
GUIUtility.keyboardControl = 0;
6873
}
6974
}
7075
}
76+
GUILayout.EndHorizontal ();
77+
GUILayout.BeginHorizontal ();
78+
79+
GUILayout.Label (new GUIContent (
80+
"Turn Table Scene:",
81+
"Scene to use for reviewing models. If none, a scene will be created on review."));
82+
83+
exportSettings.turntableScene = EditorGUILayout.ObjectField (
84+
exportSettings.turntableScene, typeof(SceneAsset), false
85+
);
7186

7287
GUILayout.EndHorizontal ();
7388
GUILayout.FlexibleSpace ();
@@ -92,6 +107,9 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
92107
public bool mayaCompatibleNames;
93108
public bool centerObjects;
94109

110+
[SerializeField]
111+
public UnityEngine.Object turntableScene;
112+
95113
/// <summary>
96114
/// The path where Convert To Model will save the new fbx and prefab.
97115
///
@@ -112,6 +130,21 @@ protected override void LoadDefaults()
112130
mayaCompatibleNames = true;
113131
centerObjects = true;
114132
convertToModelSavePath = kDefaultSavePath;
133+
turntableScene = null;
134+
}
135+
136+
public static string GetTurnTableSceneName(){
137+
if (instance.turntableScene) {
138+
return instance.turntableScene.name;
139+
}
140+
return null;
141+
}
142+
143+
public static string GetTurnTableScenePath(){
144+
if (instance.turntableScene) {
145+
return AssetDatabase.GetAssetPath (instance.turntableScene);
146+
}
147+
return null;
115148
}
116149

117150
/// <summary>

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 14 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,16 @@ public static string GetTempSavePath()
249251
return System.IO.Path.Combine(Application.dataPath, FbxExporters.Review.TurnTable.TempSavePath).Replace("\\", "/");
250252
}
251253

254+
/// <summary>
255+
/// Gets the path to the export settings file.
256+
/// Returns an absolute path with forward slashes as path separators.
257+
/// </summary>
258+
/// <returns>The export settings path.</returns>
259+
public static string GetExportSettingsPath()
260+
{
261+
return Application.dataPath + '/' + FBX_EXPORT_SETTINGS_PATH;
262+
}
263+
252264
public static string GetPackageVersion()
253265
{
254266
string result = null;

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// ***********************************************************************
2+
// Copyright (c) 2017 Unity Technologies. All rights reserved.
3+
//
4+
// Licensed under the ##LICENSENAME##.
5+
// See LICENSE.md file in the project root for full license information.
6+
// ***********************************************************************
17

28
using UnityEngine;
39

@@ -10,8 +16,10 @@ public class TurnTable
1016
{
1117
const string MenuItemName = "FbxExporters/Turntable Review/Autoload Last Saved Prefab";
1218

13-
const string ScenesPath = "Assets";
14-
const string SceneName = "FbxExporters_TurnTableReview";
19+
const string DefaultScenesPath = "Assets";
20+
const string DefaultSceneName = "FbxExporters_TurnTableReview";
21+
22+
static string SceneName = "FbxExporters_TurnTableReview";
1523

1624
public const string TempSavePath = "_safe_to_delete";
1725

@@ -48,7 +56,7 @@ private static System.IO.FileInfo GetLastSavedFile (string directoryPath, string
4856

4957
private static string GetSceneFilePath ()
5058
{
51-
return System.IO.Path.Combine (ScenesPath, SceneName + ".unity");
59+
return System.IO.Path.Combine (DefaultScenesPath, DefaultSceneName + ".unity");
5260
}
5361

5462
private static string GetLastSavedFilePath ()
@@ -83,28 +91,45 @@ private static Object LoadModel (string fbxFileName)
8391
if (unityMainAsset) {
8492
modelGO = UnityEditor.PrefabUtility.InstantiatePrefab (unityMainAsset) as GameObject;
8593

86-
GameObject turntableGO = GameObject.Find ("TurnTable");
87-
if (turntableGO != null) {
88-
modelGO.transform.parent = turntableGO.transform;
89-
turntableGO.AddComponent<RotateModel> ();
94+
var turnTableBase = GameObject.FindObjectOfType<FbxTurnTableBase> ();
95+
GameObject turntableGO = null;
96+
if (turnTableBase != null) {
97+
turntableGO = turnTableBase.gameObject;
98+
}
9099

91-
UnityEditor.Selection.objects = new GameObject[]{ turntableGO };
92-
} else {
93-
modelGO.AddComponent<RotateModel> ();
94-
UnityEditor.Selection.objects = new GameObject[]{ modelGO };
100+
if (turntableGO == null) {
101+
turntableGO = new GameObject ("TurnTableBase");
102+
turntableGO.AddComponent<FbxTurnTableBase> ();
95103
}
104+
105+
modelGO.transform.parent = turntableGO.transform;
106+
107+
UnityEditor.Selection.objects = new GameObject[]{ turntableGO };
96108
}
97109

98110
FrameCameraOnModel (modelGO);
99111

100112
return modelGO as Object;
101113
}
102114

115+
private static Bounds GetRendererBounds(GameObject modelGO)
116+
{
117+
var renderers = modelGO.GetComponentsInChildren<Renderer> ();
118+
if (renderers.Length > 0) {
119+
var bounds = renderers [0].bounds;
120+
for (int i = 1; i < renderers.Length; i++) {
121+
bounds.Encapsulate (renderers [i].bounds);
122+
}
123+
return bounds;
124+
}
125+
return new Bounds ();
126+
}
127+
103128
private static void FrameCameraOnModel(GameObject modelGO)
104129
{
105130
// Set so camera frames model
106131
// Note: this code assumes the model is at 0,0,0
107-
Vector3 boundsSize = modelGO.GetComponent<Renderer>().bounds.size;
132+
Vector3 boundsSize = GetRendererBounds(modelGO).size;
108133
float distance = Mathf.Max(boundsSize.x, boundsSize.y, boundsSize.z);
109134
distance /= (2.0f * Mathf.Tan(0.5f * Camera.main.fieldOfView * Mathf.Deg2Rad));
110135
Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, -distance * 2.0f);
@@ -143,37 +168,47 @@ public static void LastSavedModel ()
143168
System.Collections.Generic.List<UnityEngine.SceneManagement.Scene> scenes
144169
= new System.Collections.Generic.List<UnityEngine.SceneManagement.Scene> ();
145170

171+
string desiredSceneName = FbxExporters.EditorTools.ExportSettings.GetTurnTableSceneName ();
172+
if (string.IsNullOrEmpty (desiredSceneName)) {
173+
desiredSceneName = DefaultSceneName;
174+
}
175+
146176
for (int i = 0; i < UnityEngine.SceneManagement.SceneManager.sceneCount; i++) {
147177
UnityEngine.SceneManagement.Scene toAdd = UnityEngine.SceneManagement.SceneManager.GetSceneAt (i);
148178

149179
// skip Untitled scene.
150180
// The Untitled scene cannot be unloaded, if modified, and we don't want to force the user to save it.
151181
if (toAdd.name == "") continue;
152182

153-
if (toAdd.name == SceneName)
154-
{
183+
if (toAdd.name == desiredSceneName) {
155184
scene = toAdd;
156185
continue;
157186
}
187+
158188
scenes.Add (toAdd);
159189
}
160190

161191
// if turntable scene not added to list of scenes
162-
if (!scene.IsValid ())
192+
if (!scene.IsValid () || !scene.isLoaded)
163193
{
164-
// and if for some reason the turntable scene is missing create an empty scene
165-
// NOTE: we cannot use NewScene because it will force me to save the modified Untitled scene
166-
if (!System.IO.File.Exists(GetSceneFilePath ()))
167-
{
168-
var writer = System.IO.File.CreateText (GetSceneFilePath ());
169-
writer.WriteLine ("%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:");
170-
writer.Close ();
171-
UnityEditor.AssetDatabase.Refresh ();
194+
string scenePath = FbxExporters.EditorTools.ExportSettings.GetTurnTableScenePath ();
195+
if (string.IsNullOrEmpty(scenePath)) {
196+
// and if for some reason the turntable scene is missing create an empty scene
197+
// NOTE: we cannot use NewScene because it will force me to save the modified Untitled scene
198+
if (!System.IO.File.Exists (GetSceneFilePath ())) {
199+
var writer = System.IO.File.CreateText (GetSceneFilePath ());
200+
writer.WriteLine ("%YAML 1.1\n%TAG !u! tag:unity3d.com,2011:");
201+
writer.Close ();
202+
UnityEditor.AssetDatabase.Refresh ();
203+
}
204+
scenePath = GetSceneFilePath ();
172205
}
173206

174-
scene = UnityEditor.SceneManagement.EditorSceneManager.OpenScene (GetSceneFilePath (), UnityEditor.SceneManagement.OpenSceneMode.Additive);
207+
scene = UnityEditor.SceneManagement.EditorSceneManager.OpenScene (scenePath, UnityEditor.SceneManagement.OpenSceneMode.Additive);
175208
}
176209

210+
SceneName = scene.name;
211+
177212
// save unmodified scenes (but not the untitled or turntable scene)
178213
if (UnityEditor.SceneManagement.EditorSceneManager.SaveModifiedScenesIfUserWantsTo (scenes.ToArray ()))
179214
{

Assets/FbxExporters/Editor/UnitTests/IntegrationsTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public void BasicTest() {
4848
LogNonEmptyString("package path", Editor.Integrations.GetPackagePath());
4949
LogNonEmptyString("package version", Editor.Integrations.GetPackageVersion());
5050
LogNonEmptyString("temp path", Editor.Integrations.GetTempSavePath());
51+
LogNonEmptyString("export settings path", Editor.Integrations.GetExportSettingsPath ());
52+
53+
// test that the paths don't contain backslashes
54+
Assert.IsFalse(Editor.Integrations.GetAppPath().Contains("\\"));
55+
Assert.IsFalse(Editor.Integrations.GetProjectPath().Contains("\\"));
56+
Assert.IsFalse(Editor.Integrations.GetTempSavePath().Contains("\\"));
57+
Assert.IsFalse(Editor.Integrations.GetExportSettingsPath ().Contains("\\"));
5158
}
5259
}
5360
}

Assets/FbxExporters/RotateModel.cs renamed to Assets/FbxExporters/FbxTurnTableBase.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace FbxExporters.Review
1313
{
14-
public class RotateModel : MonoBehaviour
14+
public class FbxTurnTableBase : MonoBehaviour
1515
{
1616

1717
[Tooltip ("Rotation speed in degrees/second")]
@@ -22,11 +22,6 @@ public class RotateModel : MonoBehaviour
2222
private float timeOfLastUpdate = float.MaxValue;
2323
#endif
2424

25-
public float GetSpeed()
26-
{
27-
return speed;
28-
}
29-
3025
public void Rotate()
3126
{
3227
float deltaTime = 0;
@@ -42,8 +37,7 @@ public void Rotate()
4237
transform.Rotate (Vector3.up, speed * deltaTime, Space.World);
4338
}
4439

45-
void Update ()
46-
{
40+
void Update () {
4741
Rotate ();
4842
}
4943
}

Assets/FbxExporters/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright (c) 2017 Unity Technologies. All rights reserved.
44

55
See LICENSE.txt file for full license information.
66

7-
**Version**: 0.0.9a
7+
**Version**: 0.0.11a
88

99
Requirements
1010
------------

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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FBXResetExport;
2+
3+
// FBX file format
4+
FBXExportInAscii -v false;
5+
FBXExportFileVersion -v FBX201600;
6+
7+
// Geometry
8+
FBXExportSmoothMesh -v false;
9+
FBXExportInstances -v true;
10+
FBXExportReferencedAssetsContent -v false;
11+
12+
// Animation
13+
FBXExportAnimationOnly -v false;
14+
15+
FBXExportCameras -v false;
16+
FBXExportLights -v false;
17+
18+
FBXExportEmbeddedTextures -v false;
19+
20+
// Units
21+
FBXExportScaleFactor 1;
22+
FBXExportConvertUnitString cm;
23+
24+
// Axis Conversion
25+
FBXExportUpAxis y;

0 commit comments

Comments
 (0)