Skip to content

Commit eaca519

Browse files
author
Benoit Hudson
committed
Improve comments and remove a debug log.
1 parent 6c2f5f2 commit eaca519

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,13 @@ public static GameObject[] CreateInstantiatedModelPrefab (GameObject [] unityGam
104104
/// </summary>
105105
/// <returns>The instance that replaces 'toConvert' in the scene.</returns>
106106
/// <param name="toConvert">GameObject hierarchy to replace with a prefab.</param>
107-
/// <param name="fbxFullPath">Absolute platform-specific path to the fbx file. May be null, in which case we construct a path from the object name and the directoryFullPath.</param>
108-
/// <param name="directoryFullPath">Absolute platform-specific path to a directory in which to put the fbx file. Ignored if fbxFullPath is specified. May be null, in which case we use the export settings.</param>
107+
/// <param name="fbxFullPath">Absolute platform-specific path to
108+
/// the fbx file. May be null, in which case we construct a path from
109+
/// the object name and the directoryFullPath.</param>
110+
/// <param name="directoryFullPath">Absolute platform-specific path
111+
/// to a directory in which to put the fbx file. Ignored if
112+
/// fbxFullPath is specified. May be null, in which case we use the
113+
/// export settings.</param>
109114
/// <param name="keepOriginal">If set to <c>true</c>, keep the original in the scene.</param>
110115
public static GameObject CreateInstantiatedModelPrefab (
111116
GameObject toConvert,
@@ -134,7 +139,9 @@ public static GameObject CreateInstantiatedModelPrefab (
134139
}
135140

136141
// Make sure that the object names in the hierarchy are unique.
137-
// The import back in to Unity would do this automatically but we prefer to control it so that the Maya artist can see the same names as exist in Unity.
142+
// The import back in to Unity would do this automatically but
143+
// we prefer to control it so that the Maya artist can see the
144+
// same names as exist in Unity.
138145
EnforceUniqueNames (new GameObject[] {toConvert});
139146

140147
// Export to FBX. It refreshes the database.
@@ -145,13 +152,8 @@ public static GameObject CreateInstantiatedModelPrefab (
145152
}
146153
}
147154

148-
// Munge the path: we'll be using APIs that need a path relative to the assets folder.
149-
150-
151155
// Replace w Model asset. LoadMainAssetAtPath wants a path
152-
// relative to the project, not relative to the assets
153-
// folder.
154-
Debug.Log(projectRelativePath);
156+
// relative to the project, not relative to the assets folder.
155157
var unityMainAsset = AssetDatabase.LoadMainAssetAtPath (projectRelativePath) as GameObject;
156158
if (!unityMainAsset) {
157159
throw new System.Exception ("Failed to convert " + toConvert.name);;
@@ -182,6 +184,7 @@ public static GameObject CreateInstantiatedModelPrefab (
182184
string.Format("Failed to create prefab asset in [{0}] from fbx [{1}]",
183185
prefabFileName, fbxFullPath));
184186
}
187+
185188
// Connect to the prefab file.
186189
unityGO = PrefabUtility.ConnectGameObjectToPrefab(unityGO, prefab);
187190

@@ -292,6 +295,13 @@ public static void SetupImportedGameObject(GameObject orig, GameObject imported)
292295
CopyComponentsRecursive (orig, imported, namesExpectedMatch:false);
293296
}
294297

298+
/// <summary>
299+
/// Given two hierarchies of nodes whose names match up,
300+
/// make the 'imported' hierarchy have its children be in the same
301+
/// order as the 'orig' hierarchy.
302+
///
303+
/// The 'orig' hierarchy is not modified.
304+
/// </summary>
295305
public static void FixSiblingOrder(Transform orig, Transform imported){
296306
foreach (Transform origChild in orig) {
297307
Transform importedChild = imported.Find (origChild.name);
@@ -319,6 +329,16 @@ private static void CopyComponentsRecursive(GameObject from, GameObject to, bool
319329
}
320330
}
321331

332+
/// <summary>
333+
/// Copy components on the 'from' object which is the object in the
334+
/// scene we exported, over to the 'to' object which is the object
335+
/// in the scene that we imported from the FBX.
336+
///
337+
/// Exception: don't copy the references to assets in the scene that
338+
/// were also exported, in particular the meshes and materials.
339+
///
340+
/// The 'from' hierarchy is not modified.
341+
/// </summary>
322342
public static void CopyComponents(GameObject from, GameObject to){
323343
var originalComponents = new List<Component>(to.GetComponents<Component> ());
324344
foreach(var component in from.GetComponents<Component> ()) {
@@ -346,7 +366,9 @@ public static void CopyComponents(GameObject from, GameObject to){
346366
// It exists => copy.
347367
// But we want to override that behaviour in a few
348368
// cases, to avoid clobbering references to the new FBX
349-
// TODO: just modify the json directly.
369+
// TODO: interpret the object or the json more directly
370+
// TODO: be more generic
371+
// TODO: handle references to other objects in the same hierarchy
350372

351373
if (toComponent is MeshFilter) {
352374
// Don't copy the mesh. But there's nothing else to

0 commit comments

Comments
 (0)