@@ -248,18 +248,8 @@ public IExportableMaterial GetExportableMaterial(Material material)
248
248
EnsureCollectorExists ( ) ;
249
249
return m_ImportMaterialCollector . GetExportableMaterial ( material ) ;
250
250
}
251
+
251
252
252
- public struct UidToNodeMapItem
253
- {
254
- public Transform nodeTransform ;
255
- public string nodeRealName ;
256
- }
257
-
258
- // initialized when model is loaded
259
- // - initialization uses GetInstanceID() to get unique id for each node in the model
260
- // - this dictionary is currently used for finding subtrees when breaking models apart, in ModelWidget.cs
261
- // - unique identifiers for nodes are needed because node names in e.g., glTF aren't unique
262
- public Dictionary < int , UidToNodeMapItem > UidToNodeMap ;
263
253
264
254
public Model ( Location location )
265
255
{
@@ -854,8 +844,6 @@ private void CalcBoundsNonGltf(GameObject go)
854
844
855
845
}
856
846
857
- static ProfilerMarker _endCreatePrefabPerfMarker = new ProfilerMarker ( "Model.EndCreatePrefab" ) ;
858
-
859
847
public void EndCreatePrefab ( GameObject go , List < string > warnings )
860
848
{
861
849
@@ -875,53 +863,46 @@ public void EndCreatePrefab(GameObject go, List<string> warnings)
875
863
}
876
864
m_ModelParent = go . transform ;
877
865
878
- _endCreatePrefabPerfMarker . Begin ( ) ;
879
-
880
- InitializeUidToNodeMap ( m_ModelParent ) ;
866
+ #if DEVELOPMENT_BUILD || UNITY_EDITOR
867
+ ProfilerMarker generateUniqueNamesPerfMarker = new ProfilerMarker ( "Model.GenerateUniqueNames" ) ;
868
+ generateUniqueNamesPerfMarker . Begin ( ) ;
869
+ #endif
870
+
871
+ GenerateUniqueNames ( m_ModelParent ) ;
881
872
882
- _endCreatePrefabPerfMarker . End ( ) ;
873
+ #if DEVELOPMENT_BUILD || UNITY_EDITOR
874
+ generateUniqueNamesPerfMarker . End ( ) ;
875
+ #endif
883
876
884
877
// !!! Add to material dictionary here?
885
878
886
879
m_Valid = true ;
887
880
DisplayWarnings ( warnings ) ;
888
881
889
882
}
890
-
891
-
892
883
893
- public string GetNodeRealNameFromID ( int uid )
894
- {
895
- if ( UidToNodeMap . ContainsKey ( uid ) )
896
- {
897
- return UidToNodeMap [ uid ] . nodeRealName ;
898
- }
899
- return null ;
900
- }
884
+
901
885
902
- private void InitializeUidToNodeMap ( Transform rootNode )
886
+ // This method is called when the model has been loaded and the node tree is available
887
+ // This method is necessary because (1) nodes in e.g glTF files don't need to have unique names
888
+ // and (2) there's code in at least ModelWidget that searches for specific nodes using node names
889
+ private static void GenerateUniqueNames ( Transform rootNode )
903
890
{
904
- // the immediate children of rootNode are the root nodes of the model
905
-
906
- UidToNodeMap = new Dictionary < int , UidToNodeMapItem > ( ) ;
907
891
908
- void ProcessNode ( Transform node )
892
+ void SetUniqueNameForNode ( Transform node )
909
893
{
910
- UidToNodeMapItem uidToNodeMapItem = new UidToNodeMapItem ( ) ;
911
- uidToNodeMapItem . nodeTransform = node ;
912
- uidToNodeMapItem . nodeRealName = node . name ;
913
- node . name = node . gameObject . GetInstanceID ( ) . ToString ( ) ;
914
- UidToNodeMap [ node . gameObject . GetInstanceID ( ) ] = uidToNodeMapItem ;
915
-
894
+ // GetInstanceID returns a unique ID for every GameObject during a runtime session
895
+ node . name += " uid: " + node . gameObject . GetInstanceID ( ) ;
896
+
916
897
foreach ( Transform child in node )
917
898
{
918
- ProcessNode ( child ) ;
899
+ SetUniqueNameForNode ( child ) ;
919
900
}
920
901
}
921
902
922
903
foreach ( Transform child in rootNode )
923
904
{
924
- ProcessNode ( child ) ;
905
+ SetUniqueNameForNode ( child ) ;
925
906
}
926
907
}
927
908
0 commit comments