Skip to content

Commit b53ea2e

Browse files
authored
Merge branch 'master' into Uni-35304-UnitTestsForExportingTimelineClip
2 parents 032c4e4 + 47d0050 commit b53ea2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+5155
-486
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ public static GameObject Convert (
117117
string directoryFullPath = null,
118118
string fbxFullPath = null)
119119
{
120+
// Only create the prefab (no FBX export) if we have selected the root of a model prefab instance.
121+
// Children of model prefab instances will also have "model prefab instance"
122+
// as their prefab type, so it is important that it is the root that is selected.
123+
//
124+
// e.g. If I have the following hierarchy:
125+
// Cube
126+
// -- Sphere
127+
//
128+
// Both the Cube and Sphere will have ModelPrefabInstance as their prefab type.
129+
// However, when selecting the Sphere to convert, we don't want to connect it to the
130+
// existing FBX but create a new FBX containing just the sphere.
131+
PrefabType unityPrefabType = PrefabUtility.GetPrefabType(toConvert);
132+
if (unityPrefabType == PrefabType.ModelPrefabInstance && toConvert.Equals(PrefabUtility.FindPrefabRoot(toConvert))) {
133+
// don't re-export fbx
134+
// create prefab out of model instance in scene, link to existing fbx
135+
var mainAsset = PrefabUtility.GetPrefabParent(toConvert) as GameObject;
136+
var mainAssetRelPath = AssetDatabase.GetAssetPath(mainAsset);
137+
var mainAssetAbsPath = Directory.GetParent(Application.dataPath) + "/" + mainAssetRelPath;
138+
SetupFbxPrefab(toConvert, mainAsset, mainAssetRelPath, mainAssetAbsPath);
139+
140+
return toConvert;
141+
}
142+
120143
if (string.IsNullOrEmpty(fbxFullPath)) {
121144
// Generate a unique filename.
122145
if (string.IsNullOrEmpty (directoryFullPath)) {
@@ -145,7 +168,7 @@ public static GameObject Convert (
145168

146169
// Export to FBX. It refreshes the database.
147170
{
148-
var fbxActualPath = ModelExporter.ExportObject (fbxFullPath, toConvert);
171+
var fbxActualPath = ModelExporter.ExportObject (fbxFullPath, toConvert, lodExportType: EditorTools.ExportSettings.LODExportType.All);
149172
if (fbxActualPath != fbxFullPath) {
150173
throw new System.Exception ("Failed to convert " + toConvert.name);
151174
}
@@ -155,12 +178,27 @@ public static GameObject Convert (
155178
// relative to the project, not relative to the assets folder.
156179
var unityMainAsset = AssetDatabase.LoadMainAssetAtPath (projectRelativePath) as GameObject;
157180
if (!unityMainAsset) {
158-
throw new System.Exception ("Failed to convert " + toConvert.name);;
181+
throw new System.Exception ("Failed to convert " + toConvert.name);
159182
}
160183

161184
// Copy the mesh/materials from the FBX
162185
UpdateFromSourceRecursive (toConvert, unityMainAsset);
163186

187+
SetupFbxPrefab (toConvert, unityMainAsset, projectRelativePath, fbxFullPath);
188+
189+
toConvert.name = Path.GetFileNameWithoutExtension (fbxFullPath);
190+
return toConvert;
191+
}
192+
193+
194+
/// <summary>
195+
/// Create the prefab and connect it to the given fbx asset.
196+
/// </summary>
197+
/// <param name="toConvert">Hierarchy to convert.</param>
198+
/// <param name="unityMainAsset">Main asset in the FBX.</param>
199+
/// <param name="projectRelativePath">Fbx project relative path.</param>
200+
/// <param name="fbxFullPath">Fbx full path.</param>
201+
public static void SetupFbxPrefab(GameObject toConvert, GameObject unityMainAsset, string projectRelativePath, string fbxFullPath){
164202
// Set up the FbxPrefab component so it will auto-update.
165203
// Make sure to delete whatever FbxPrefab history we had.
166204
var fbxPrefab = toConvert.GetComponent<FbxPrefab>();
@@ -179,9 +217,6 @@ public static GameObject Convert (
179217
string.Format("Failed to create prefab asset in [{0}] from fbx [{1}]",
180218
prefabFileName, fbxFullPath));
181219
}
182-
183-
toConvert.name = Path.GetFileNameWithoutExtension (fbxFullPath);
184-
return toConvert;
185220
}
186221

187222
/// <summary>

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,23 @@ public override void OnInspectorGUI() {
5656
exportSettings.autoUpdaterEnabled
5757
);
5858

59+
exportSettings.exportMeshNoRenderer = EditorGUILayout.Toggle(
60+
new GUIContent("Export Meshes with no Renderers:",
61+
"If unchecked, meshes that don't have renderers won't be exported."),
62+
exportSettings.exportMeshNoRenderer
63+
);
64+
5965
GUILayout.BeginHorizontal();
6066
EditorGUILayout.LabelField(new GUIContent("Export Format:", "Export the FBX file in the standard binary format." +
6167
" Select ASCII to export the FBX file in ASCII format."), GUILayout.Width(LabelWidth - FieldOffset));
6268
exportSettings.ExportFormatSelection = EditorGUILayout.Popup(exportSettings.ExportFormatSelection, new string[]{"Binary", "ASCII"});
6369
GUILayout.EndHorizontal();
6470

71+
GUILayout.BeginHorizontal();
72+
EditorGUILayout.LabelField(new GUIContent("LOD Export:", "Select which LOD to export."), GUILayout.Width(LabelWidth - FieldOffset));
73+
exportSettings.lodExportType = (ExportSettings.LODExportType)EditorGUILayout.Popup((int)exportSettings.lodExportType, new string[]{"All", "Highest", "Lowest"});
74+
GUILayout.EndHorizontal();
75+
6576
GUILayout.BeginHorizontal();
6677
EditorGUILayout.LabelField(new GUIContent(
6778
"Export Path:",
@@ -289,6 +300,8 @@ public class ExportSettings : ScriptableSingleton<ExportSettings>
289300
public const string kMayaOptionName = "Maya ";
290301
public const string kMayaLtOptionName = "Maya LT";
291302

303+
public bool Verbose = false;
304+
292305
private static string DefaultIntegrationSavePath {
293306
get{
294307
return Path.GetDirectoryName(Application.dataPath);
@@ -429,17 +442,27 @@ public static string[] DCCVendorLocations
429442

430443
// Note: default values are set in LoadDefaults().
431444
public bool mayaCompatibleNames = true;
432-
public bool centerObjects = true;
445+
public bool centerObjects = false;
433446
public bool autoUpdaterEnabled = true;
434447
public bool launchAfterInstallation = true;
435448
public bool HideSendToUnityMenu = true;
436449
public int ExportFormatSelection;
437450
public bool BakeAnimation = true;
451+
public bool exportMeshNoRenderer = false;
438452

439453
public string IntegrationSavePath;
440454

441455
public int selectedDCCApp = 0;
442456

457+
[SerializeField]
458+
public LODExportType lodExportType = LODExportType.All;
459+
460+
public enum LODExportType {
461+
All = 0,
462+
Highest = 1,
463+
Lowest = 2
464+
}
465+
443466
/// <summary>
444467
/// The path where Convert To Model will save the new fbx and prefab.
445468
///

0 commit comments

Comments
 (0)