/// <summary> /// Given a PrimMap, finds all instanced objects and their respective master objects and /// instantiates Unity clones using GameObject.Instantiate. Note that this does not result /// in GPU instancing. /// </summary> public static void BuildSceneInstances(PrimMap primMap, SceneImportOptions options) { if (options.enableGpuInstancing) { foreach (var masterPath in primMap.GetMasterRootPaths()) { EnableGpuInstancing(primMap[masterPath]); } } foreach (var instance in primMap.GetInstanceRoots()) { GameObject goInstance = instance.gameObject; GameObject goMaster = primMap[instance.masterPath]; foreach (Transform child in goMaster.transform) { Transform newChild = goInstance.transform.Find(child.name); if (newChild == null) { newChild = GameObject.Instantiate(child.gameObject).transform; newChild.name = child.name; newChild.transform.SetParent(goInstance.transform, worldPositionStays: false); } primMap.AddInstance(newChild.gameObject); } } }