Skip to content

Commit 6ca639a

Browse files
committed
Added function to remove duplicate selections
if you select the parent and its child, then the child is removed from the export set and all the parent's children are exported
1 parent 98f18b2 commit 6ca639a

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -486,16 +486,52 @@ protected int ExportComponents (GameObject unityGo, FbxScene fbxScene, FbxNode
486486
/// </summary>
487487
/// <returns>The object count.</returns>
488488
/// <param name="exportSet">Export set.</param>
489-
public int GetGameObjectCount (IEnumerable<UnityEngine.Object> exportSet)
489+
public int GetGameObjectCount (HashSet<GameObject> exportSet)
490490
{
491491
int count = 0;
492492
foreach (var obj in exportSet) {
493+
count += obj.transform.hierarchyCount;
494+
}
495+
return count;
496+
}
497+
498+
/// <summary>
499+
/// Removes objects that will already be exported anyway.
500+
/// E.g. if a parent and its child are both selected, then the child
501+
/// will be removed from the export set.
502+
/// </summary>
503+
/// <returns>The revised export set</returns>
504+
/// <param name="unityExportSet">Unity export set.</param>
505+
protected HashSet<GameObject> RemoveDuplicateObjects(IEnumerable<UnityEngine.Object> unityExportSet)
506+
{
507+
// basically just remove the descendents from the unity export set
508+
HashSet<GameObject> toExport = new HashSet<GameObject> ();
509+
HashSet<UnityEngine.Object> hashedExportSet = new HashSet<Object> (unityExportSet);
510+
511+
Queue<UnityEngine.Object> queue = new Queue<Object> (unityExportSet);
512+
while(queue.Count > 0) {
513+
var obj = queue.Dequeue();
493514
var unityGo = GetGameObject (obj);
515+
494516
if (unityGo) {
495-
count += unityGo.transform.hierarchyCount;
517+
// if any of this nodes ancestors is already in the export set,
518+
// then ignore it, it will get exported already
519+
bool parentInSet = false;
520+
var parent = unityGo.transform.parent;
521+
while (parent != null) {
522+
if (hashedExportSet.Contains (parent.gameObject)) {
523+
parentInSet = true;
524+
break;
525+
}
526+
parent = parent.parent;
527+
}
528+
529+
if (!parentInSet) {
530+
toExport.Add (unityGo);
531+
}
496532
}
497533
}
498-
return count;
534+
return toExport;
499535
}
500536

501537
/// <summary>
@@ -561,16 +597,13 @@ public int ExportAll (IEnumerable<UnityEngine.Object> unityExportSet)
561597
// export set of object
562598
FbxNode fbxRootNode = fbxScene.GetRootNode ();
563599
int i = 0;
564-
int count = GetGameObjectCount (unityExportSet);
565-
foreach (var obj in unityExportSet) {
566-
var unityGo = GetGameObject (obj);
567-
568-
if (unityGo) {
569-
i = this.ExportComponents (unityGo, fbxScene, fbxRootNode, i, count);
570-
if (i < 0) {
571-
Debug.LogWarning ("Export Cancelled");
572-
return 0;
573-
}
600+
var revisedExportSet = RemoveDuplicateObjects(unityExportSet);
601+
int count = GetGameObjectCount (revisedExportSet);
602+
foreach (var unityGo in revisedExportSet) {
603+
i = this.ExportComponents (unityGo, fbxScene, fbxRootNode, i, count);
604+
if (i < 0) {
605+
Debug.LogWarning ("Export Cancelled");
606+
return 0;
574607
}
575608
}
576609

0 commit comments

Comments
 (0)