Skip to content

Commit 0f3f945

Browse files
author
Benoit Hudson
committed
Merge remote-tracking branch 'origin/master' into uni-40523-convert-from-asset
2 parents 1fc24b3 + cb017dd commit 0f3f945

12 files changed

+543
-234
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static GameObject Convert (
113113
string fbxFullPath = null,
114114
string prefabDirectoryFullPath = null,
115115
string prefabFullPath = null,
116-
EditorTools.IExportOptions exportOptions = null)
116+
EditorTools.ConvertToPrefabSettingsSerialize exportOptions = null)
117117
{
118118
// If we selected the something that's already backed by an FBX, don't export.
119119
var mainAsset = GetOrCreateFbxAsset (toConvert, fbxDirectoryFullPath, fbxFullPath, exportOptions);
@@ -166,7 +166,7 @@ public static bool WillExportFbx(GameObject go) {
166166
public static GameObject GetOrCreateFbxAsset(GameObject toConvert,
167167
string fbxDirectoryFullPath = null,
168168
string fbxFullPath = null,
169-
EditorTools.IExportOptions exportOptions = null)
169+
EditorTools.ConvertToPrefabSettingsSerialize exportOptions = null)
170170
{
171171
var mainAsset = GetFbxAssetOrNull(toConvert);
172172
if (mainAsset) {
@@ -193,7 +193,7 @@ public static GameObject GetOrCreateFbxAsset(GameObject toConvert,
193193
// The import back in to Unity would do this automatically but
194194
// we prefer to control it so that the Maya artist can see the
195195
// same names as exist in Unity.
196-
EnforceUniqueNames (new GameObject[] {toConvert});
196+
EnforceUniqueNames(new GameObject[] { toConvert });
197197

198198
// Export to FBX. It refreshes the database.
199199
{
@@ -392,23 +392,28 @@ public static string IncrementFileName(string path, string filename)
392392
/// <param name="exportSet">Export set.</param>
393393
public static void EnforceUniqueNames(IEnumerable<GameObject> exportSet)
394394
{
395-
Dictionary<string, int> NameToIndexMap = new Dictionary<string, int> ();
395+
Dictionary<string, int> NameToIndexMap = new Dictionary<string, int>();
396396
string format = "{0} {1}";
397397

398-
Queue<GameObject> queue = new Queue<GameObject> (exportSet);
398+
Queue<GameObject> queue = new Queue<GameObject>(exportSet);
399399

400-
while(queue.Count > 0){
401-
var go = queue.Dequeue ();
400+
while (queue.Count > 0)
401+
{
402+
var go = queue.Dequeue();
402403
var name = go.name;
403-
if (NameToIndexMap.ContainsKey (name)) {
404-
go.name = string.Format (format, name, NameToIndexMap [name]);
405-
NameToIndexMap [name]++;
406-
} else {
407-
NameToIndexMap [name] = 1;
404+
if (NameToIndexMap.ContainsKey(name))
405+
{
406+
go.name = string.Format(format, name, NameToIndexMap[name]);
407+
NameToIndexMap[name]++;
408+
}
409+
else
410+
{
411+
NameToIndexMap[name] = 1;
408412
}
409413

410-
foreach (Transform child in go.transform) {
411-
queue.Enqueue (child.gameObject);
414+
foreach (Transform child in go.transform)
415+
{
416+
queue.Enqueue(child.gameObject);
412417
}
413418
}
414419
}
@@ -493,6 +498,22 @@ public static Dictionary<string,GameObject> MapNameToSourceRecursive(GameObject
493498
/// </summary>
494499
public static void CopyComponents(GameObject to, GameObject from){
495500
var originalComponents = new List<Component>(to.GetComponents<Component> ());
501+
502+
// UNI-27534: This fixes the issue where the mesh collider would not update to point to the mesh in the fbx after export
503+
// Point the mesh included in the mesh collider to the mesh in the FBX file, which is the same as the one in mesh filter
504+
var toMeshCollider = to.GetComponent<MeshCollider>();
505+
var toMeshFilter = to.GetComponent<MeshFilter>();
506+
// if the mesh collider isn't pointing to the same mesh as in the current mesh filter then don't
507+
// do anything as it's probably pointing to a mesh in a different fbx
508+
if (toMeshCollider && toMeshFilter && toMeshCollider.sharedMesh == toMeshFilter.sharedMesh)
509+
{
510+
var fromFilter = from.GetComponent<MeshFilter>();
511+
if (fromFilter)
512+
{
513+
toMeshCollider.sharedMesh = fromFilter.sharedMesh;
514+
}
515+
}
516+
496517
// copy over meshes, materials, and nothing else
497518
foreach (var component in from.GetComponents<Component>()) {
498519
// ignore missing components

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ protected override void OnEnable ()
8383
m_prefabExtLabelWidth = m_fbxExtLabelStyle.CalcSize (new GUIContent (".prefab")).x;
8484
}
8585

86+
protected bool ExportSetContainsAnimation ()
87+
{
88+
foreach(var obj in ToExport)
89+
{
90+
var go = ModelExporter.GetGameObject(obj);
91+
if(go.GetComponentInChildren<Animation>() || go.GetComponentInChildren<Animator>())
92+
{
93+
return true;
94+
}
95+
}
96+
return false;
97+
}
98+
8699
protected override bool Export ()
87100
{
88101
if (string.IsNullOrEmpty (m_exportFileName)) {
@@ -106,6 +119,29 @@ protected override bool Export ()
106119
return false;
107120
}
108121

122+
if (SettingsObject.UseMayaCompatibleNames && SettingsObject.AllowSceneModification)
123+
{
124+
string warning = "Names of objects in the hierarchy may change with the Compatible Naming option turned on";
125+
if (ExportSetContainsAnimation())
126+
{
127+
warning = "Compatible Naming option turned on. Names of objects in hierarchy may change and break animations.";
128+
}
129+
130+
// give a warning dialog that indicates that names in the scene may change
131+
int result = UnityEditor.EditorUtility.DisplayDialogComplex(
132+
string.Format("{0} Warning", ModelExporter.PACKAGE_UI_NAME), warning, "OK", "Turn off and continue", "Cancel"
133+
);
134+
if (result == 1)
135+
{
136+
// turn compatible naming off
137+
SettingsObject.SetUseMayaCompatibleNames(false);
138+
}
139+
else if (result == 2)
140+
{
141+
return false;
142+
}
143+
}
144+
109145
if (ToExport.Length == 1) {
110146
var go = ModelExporter.GetGameObject (ToExport [0]);
111147

Assets/FbxExporters/Editor/ConvertToPrefabSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@ public class ConvertToPrefabSettingsSerialize : ExportOptionsSettingsSerializeBa
7676
public override ExportSettings.LODExportType LODExportType { get { return ExportSettings.LODExportType.All; } }
7777
public override ExportSettings.ObjectPosition ObjectPosition { get { return ExportSettings.ObjectPosition.Reset; } }
7878
public override bool ExportUnrendered { get { return true; } }
79+
public override bool AllowSceneModification { get { return true; } }
7980
}
8081
}

Assets/FbxExporters/Editor/ExportModelSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public interface IExportOptions {
105105
ExportSettings.ObjectPosition ObjectPosition { get; }
106106
bool AnimateSkinnedMesh { get; }
107107
bool UseMayaCompatibleNames { get; }
108+
bool AllowSceneModification { get; }
108109
bool ExportUnrendered { get; }
109110
Transform AnimationSource { get; }
110111
Transform AnimationDest { get; }
@@ -145,6 +146,7 @@ public abstract class ExportOptionsSettingsSerializeBase : IExportOptions
145146
public abstract ExportSettings.LODExportType LODExportType { get; }
146147
public abstract ExportSettings.ObjectPosition ObjectPosition { get; }
147148
public abstract bool ExportUnrendered { get; }
149+
public abstract bool AllowSceneModification { get; }
148150
}
149151

150152
[System.Serializable]
@@ -163,5 +165,6 @@ public class ExportModelSettingsSerialize : ExportOptionsSettingsSerializeBase
163165
public void SetObjectPosition(ExportSettings.ObjectPosition objPos){ this.objectPosition = objPos; }
164166
public override bool ExportUnrendered { get { return exportUnrendered; } }
165167
public void SetExportUnredererd(bool exportUnrendered){ this.exportUnrendered = exportUnrendered; }
168+
public override bool AllowSceneModification { get { return false; } }
166169
}
167170
}

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,12 +2209,17 @@ protected int ExportTransformHierarchy(
22092209
{
22102210
int numObjectsExported = exportProgress;
22112211

2212+
string fbxName = unityGo.name;
22122213
if (ExportOptions.UseMayaCompatibleNames) {
2213-
unityGo.name = ConvertToMayaCompatibleName (unityGo.name);
2214+
fbxName = ConvertToMayaCompatibleName (unityGo.name);
2215+
if (ExportOptions.AllowSceneModification)
2216+
{
2217+
unityGo.name = fbxName;
2218+
}
22142219
}
22152220

22162221
// create an FbxNode and add it as a child of parent
2217-
FbxNode fbxNode = FbxNode.Create (fbxScene, GetUniqueName (unityGo.name));
2222+
FbxNode fbxNode = FbxNode.Create (fbxScene, GetUniqueName (fbxName));
22182223
MapUnityObjectToFbxNode [unityGo] = fbxNode;
22192224

22202225
if (Verbose)
@@ -2481,12 +2486,13 @@ private bool ExportGameObjectAndParents(
24812486
return true;
24822487
}
24832488

2489+
string fbxName = unityGo.name;
24842490
if (ExportOptions.UseMayaCompatibleNames) {
2485-
unityGo.name = ConvertToMayaCompatibleName (unityGo.name);
2491+
fbxName = ConvertToMayaCompatibleName (unityGo.name);
24862492
}
24872493

24882494
// create an FbxNode and add it as a child of parent
2489-
fbxNode = FbxNode.Create (fbxScene, GetUniqueName (unityGo.name));
2495+
fbxNode = FbxNode.Create (fbxScene, GetUniqueName (fbxName));
24902496
MapUnityObjectToFbxNode [unityGo] = fbxNode;
24912497

24922498
exportProgress++;
Binary file not shown.

Assets/FbxExporters/FBX_Exporter_User_Guide.pdf.meta

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)