static void ProcessPaths(HierInfo[] infos, Scene scene, GameObject unityRoot, SdfPath usdRoot, PrimMap map, SceneImportOptions options) { Profiler.BeginSample("Process all paths"); foreach (var info in infos) { var prim = info.prim; var path = info.prim.GetPath(); if (info.skelBindings != null) { // Collect all discovered skelBindings back into the PrimMap. map.SkelBindings.Add(info.prim.GetPath(), info.skelBindings); } GameObject go; if (path == usdRoot) { go = unityRoot; } else { GameObject parentGo = null; CreateAncestors(path, map, unityRoot, usdRoot, options, out parentGo); if (!parentGo) { Debug.LogWarning("Parent path not found for child: " + path.ToString()); continue; } var parent = parentGo ? parentGo.transform : null; if (!map.TryGetValue(path, out go)) { go = FindOrCreateGameObject(parent, path, unityRoot.transform, map, options); } } if (options.importSceneInstances) { Profiler.BeginSample("Add Scene Instance Root"); if (prim.IsInstance()) { map.AddInstanceRoot(prim.GetPath(), go, prim.GetMaster().GetPath()); } Profiler.EndSample(); } if (!options.importHierarchy) { continue; } ApplySelfVisibility(go, prim); try { Profiler.BeginSample("Add Model Root"); AddModelRoot(go, info); Profiler.EndSample(); Profiler.BeginSample("Add Variant Set"); AddVariantSet(go, prim); Profiler.EndSample(); Profiler.BeginSample("Add Payload"); AddPayload(go, info, options); Profiler.EndSample(); } catch (Exception ex) { Debug.LogException(new Exception("Error processing " + prim.GetPath(), ex)); } } Profiler.EndSample(); }
/// <summary> /// Map all UsdPrims and build Unity GameObjects, reconstructing the parent relationship. /// </summary> /// <remarks> /// When forceRebuild is true, game objects will be destroyed and recreated. If buildHierarchy /// is false, the primMap will be populated, but missing game objects will not be created. /// </remarks> static public PrimMap BuildGameObjects(Scene scene, GameObject unityRoot, SdfPath usdRoot, IEnumerable <SdfPath> paths, PrimMap map, SceneImportOptions options) { map[usdRoot] = unityRoot; // Like all GameObjects imported from USD, ensure the root has a UsdPrimSource. if (unityRoot.GetComponent <UsdPrimSource>() == null) { var ua = unityRoot.AddComponent <UsdPrimSource>(); ua.m_usdPrimPath = usdRoot.ToString(); } Profiler.BeginSample("Build Object Lists"); var hierInfo = BuildObjectLists(scene, unityRoot, usdRoot, map, options); Profiler.EndSample(); // TODO: Should recurse to discover deeply nested instancing. // TODO: Generates garbage for every prim, but we expect few masters. if (options.importPointInstances || options.importSceneInstances) { Profiler.BeginSample("Build Masters"); foreach (var masterRootPrim in scene.Stage.GetMasters()) { var goMaster = FindOrCreateGameObject(unityRoot.transform, masterRootPrim.GetPath(), unityRoot.transform, map, options); goMaster.hideFlags = HideFlags.HideInHierarchy; goMaster.SetActive(false); map.AddMasterRoot(masterRootPrim.GetPath(), goMaster); try { var info = new HierInfo(); info.prim = masterRootPrim; ReadModelInfo(ref info); AddModelRoot(goMaster, info); AddVariantSet(goMaster, masterRootPrim); } catch (Exception ex) { Debug.LogException(new Exception("Error processing " + masterRootPrim.GetPath(), ex)); } foreach (var usdPrim in masterRootPrim.GetDescendants()) { var parentPath = usdPrim.GetPath().GetParentPath(); Transform parentXf = null; if (parentPath == masterRootPrim.GetPath()) { parentXf = goMaster.transform; } else { parentXf = map[parentPath].transform; } var goPrim = FindOrCreateGameObject(parentXf, usdPrim.GetPath(), unityRoot.transform, map, options); ApplySelfVisibility(goPrim, usdPrim); if (usdPrim.IsInstance()) { map.AddInstanceRoot(usdPrim.GetPath(), goPrim, usdPrim.GetMaster().GetPath()); } try { var info = new HierInfo(); info.prim = usdPrim; ReadModelInfo(ref info); AddModelRoot(goPrim, info); AddVariantSet(goPrim, usdPrim); } catch (Exception ex) { Debug.LogException(new Exception("Error processing " + usdPrim.GetPath(), ex)); continue; } } } Profiler.EndSample(); } if (options.importSkinning) { Profiler.BeginSample("Expand Skeletons"); foreach (var info in hierInfo) { if (info.skelJoints == null || info.skelJoints.Length == 0) { continue; } try { ExpandSkeleton(info, unityRoot, usdRoot, info.prim, map, options); } catch (Exception ex) { Debug.LogException(new Exception("Error expanding skeleton at " + info.prim.GetPath(), ex)); } } Profiler.EndSample(); } return(map); }