public static IEnumerator Create(HLOD hlod) { try { Stopwatch sw = new Stopwatch(); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); sw.Reset(); sw.Start(); hlod.ConvertedPrefabObjects.Clear(); hlod.GeneratedObjects.Clear(); Bounds bounds = hlod.GetBounds(); List <GameObject> hlodTargets = ObjectUtils.HLODTargets(hlod.gameObject); ISpaceSplitter spliter = new QuadTreeSpaceSplitter(5.0f); SpaceNode rootNode = spliter.CreateSpaceTree(bounds, hlod.ChunkSize, hlod.transform.position, hlodTargets, progress => { EditorUtility.DisplayProgressBar("Bake HLOD", "Splitting space", progress * 0.25f); }); if (hlodTargets.Count == 0) { EditorUtility.DisplayDialog("Empty HLOD sources.", "There are no objects to be included in the HLOD.", "Ok"); yield break; } using (DisposableList <HLODBuildInfo> buildInfos = CreateBuildInfo(rootNode, hlod.MinObjectSize)) { if (buildInfos.Count == 0 || buildInfos[0].WorkingObjects.Count == 0) { EditorUtility.DisplayDialog("Empty HLOD sources.", "There are no objects to be included in the HLOD.", "Ok"); yield break; } Debug.Log("[HLOD] Splite space: " + sw.Elapsed.ToString("g")); sw.Reset(); sw.Start(); ISimplifier simplifier = (ISimplifier)Activator.CreateInstance(hlod.SimplifierType, new object[] { hlod.SimplifierOptions }); for (int i = 0; i < buildInfos.Count; ++i) { yield return(new BranchCoroutine(simplifier.Simplify(buildInfos[i]))); } yield return(new WaitForBranches(progress => { EditorUtility.DisplayProgressBar("Bake HLOD", "Simplify meshes", 0.25f + progress * 0.25f); })); Debug.Log("[HLOD] Simplify: " + sw.Elapsed.ToString("g")); sw.Reset(); sw.Start(); using (IBatcher batcher = (IBatcher)Activator.CreateInstance(hlod.BatcherType, new object[] { hlod.BatcherOptions })) { batcher.Batch(hlod.transform.position, buildInfos, progress => { EditorUtility.DisplayProgressBar("Bake HLOD", "Generating combined static meshes.", 0.5f + progress * 0.25f); }); } Debug.Log("[HLOD] Batch: " + sw.Elapsed.ToString("g")); sw.Reset(); sw.Start(); IStreamingBuilder builder = (IStreamingBuilder)Activator.CreateInstance(hlod.StreamingType, new object[] { hlod, hlod.StreamingOptions }); builder.Build(rootNode, buildInfos, hlod.gameObject, hlod.CullDistance, hlod.LODDistance, false, true, progress => { EditorUtility.DisplayProgressBar("Bake HLOD", "Storing results.", 0.75f + progress * 0.25f); }); Debug.Log("[HLOD] Build: " + sw.Elapsed.ToString("g")); sw.Reset(); sw.Start(); EditorUtility.SetDirty(hlod.gameObject); } } finally { EditorUtility.ClearProgressBar(); } }
private void DoBatch(DisposableList <HLODBuildInfo> infos) { IBatcher batcher = (IBatcher)Activator.CreateInstance(m_batcherType, new object[] { m_hlodComponent.BatcherOptions }); batcher.Batch(m_hlodComponent.transform.position, infos, null); }
public static IEnumerator Create(HLOD hlod) { try { Stopwatch sw = new Stopwatch(); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); sw.Reset(); sw.Start(); Bounds bounds = hlod.GetBounds(); List <GameObject> hlodTargets = ObjectUtils.HLODTargets(hlod.gameObject); ISpaceSplitter spliter = new QuadTreeSpaceSplitter(hlod.transform.position, 5.0f, hlod.MinSize); SpaceNode rootNode = spliter.CreateSpaceTree(bounds, hlodTargets, progress => { EditorUtility.DisplayProgressBar("Bake HLOD", "Splitting space", progress * 0.25f); }); List <HLODBuildInfo> buildInfos = CreateBuildInfo(rootNode, hlod.ThresholdSize); Debug.Log("[HLOD] Splite space: " + sw.Elapsed.ToString("g")); sw.Reset(); sw.Start(); ISimplifier simplifier = (ISimplifier)Activator.CreateInstance(hlod.SimplifierType, new object[] { hlod }); for (int i = 0; i < buildInfos.Count; ++i) { yield return(new BranchCoroutine(simplifier.Simplify(buildInfos[i]))); } yield return(new WaitForBranches(progress => { EditorUtility.DisplayProgressBar("Bake HLOD", "Simplify meshes", 0.25f + progress * 0.25f); })); Debug.Log("[HLOD] Simplify: " + sw.Elapsed.ToString("g")); sw.Reset(); sw.Start(); IBatcher batcher = (IBatcher)Activator.CreateInstance(hlod.BatcherType, new object[] { hlod }); batcher.Batch(buildInfos, progress => { EditorUtility.DisplayProgressBar("Bake HLOD", "Generating combined static meshes.", 0.5f + progress * 0.25f); }); Debug.Log("[HLOD] Batch: " + sw.Elapsed.ToString("g")); sw.Reset(); sw.Start(); try { AssetDatabase.StartAssetEditing(); IStreamingBuilder builder = (IStreamingBuilder)Activator.CreateInstance(hlod.StreamingType, new object[] { hlod }); builder.Build(rootNode, buildInfos, progress => { EditorUtility.DisplayProgressBar("Bake HLOD", "Storing results.", 0.75f + progress * 0.25f); }); Debug.Log("[HLOD] Build: " + sw.Elapsed.ToString("g")); sw.Reset(); sw.Start(); } finally { AssetDatabase.StopAssetEditing(); Debug.Log("[HLOD] Importing: " + sw.Elapsed.ToString("g")); } } finally { EditorUtility.ClearProgressBar(); } //hlod.Root = rootNode; }