public bool EditorCreateDataUpdate() { if (mCreateDataJob == null) { return(true); } mCreateDataJob.Update(); return(mCreateDataJob.IsDone); }
// private void OnGUI() { Terrain curentTarget = EditorGUILayout.ObjectField("Convert Target", terrainTarget, typeof(Terrain), true) as Terrain; if (curentTarget != terrainTarget) { ClearAll(); terrainTarget = curentTarget; } int curSliceCount = Mathf.FloorToInt(Mathf.Pow(2, QuadTreeDepth)); int sliceCount = EditorGUILayout.IntField("Slice Count(NxN)", curSliceCount); if (sliceCount != curSliceCount) { curSliceCount = Mathf.NextPowerOfTwo(sliceCount); QuadTreeDepth = Mathf.FloorToInt(Mathf.Log(curSliceCount, 2)); } int lodCount = EditorGUILayout.IntField("LOD Count", LODSettings.Length); if (lodCount != LODSettings.Length) { MTLODSetting[] old = LODSettings; LODSettings = new MTLODSetting[lodCount]; for (int i = 0; i < Mathf.Min(lodCount, old.Length); ++i) { LODSettings[i] = old[i]; } for (int i = Mathf.Min(lodCount, old.Length); i < Mathf.Max(lodCount, old.Length); ++i) { LODSettings[i] = new MTLODSetting(); } } if (LODSettings.Length > 0) { for (int i = 0; i < LODSettings.Length; ++i) { LODSettings[i].OnGUIDraw(i); } } BakeMaterial = EditorGUILayout.ToggleLeft("Bake Material", BakeMaterial); if (BakeMaterial) { BakeTexRes = EditorGUILayout.IntField("Bake Texture Resolution", BakeTexRes); BakeTexRes = Mathf.Min(2048, Mathf.NextPowerOfTwo(BakeTexRes)); } if (GUILayout.Button("Generate")) { if (LODSettings == null || LODSettings.Length == 0) { MTLog.LogError("no lod setting"); return; } if (terrainTarget == null) { MTLog.LogError("no target terrain"); return; } string[] lodFolder = new string[LODSettings.Length]; for (int i = 0; i < LODSettings.Length; ++i) { string guid = AssetDatabase.CreateFolder("Assets", string.Format("{0}_LOD{1}", terrainTarget.name, i)); lodFolder[i] = AssetDatabase.GUIDToAssetPath(guid); } int gridMax = 1 << QuadTreeDepth; dataCreateJob = new CreateDataJob(terrainTarget.terrainData.bounds, gridMax, gridMax, LODSettings); for (int i = 0; i < int.MaxValue; ++i) { dataCreateJob.Update(); EditorUtility.DisplayProgressBar("creating data", "scaning volumn", dataCreateJob.progress); if (dataCreateJob.IsDone) { break; } } dataCreateJob.EndProcess(); tessellationJob = new TessellationJob(dataCreateJob.LODs); for (int i = 0; i < int.MaxValue; ++i) { tessellationJob.Update(); EditorUtility.DisplayProgressBar("creating data", "tessellation", tessellationJob.progress); if (tessellationJob.IsDone) { break; } } for (int i = 0; i < tessellationJob.mesh.Length; ++i) { EditorUtility.DisplayProgressBar("saving data", "processing", (float)i / tessellationJob.mesh.Length); MTMeshData data = tessellationJob.mesh[i]; for (int lod = 0; lod < data.lods.Length; ++lod) { SaveMesh(lodFolder[lod], data.meshId, data.lods[lod], sliceCount); if (!BakeMaterial) { MTMatUtils.SaveMaterials(lodFolder[lod], terrainTarget.name, terrainTarget); } } } if (BakeMaterial) { string guid = AssetDatabase.CreateFolder("Assets", string.Format("{0}_BakedMats", terrainTarget.name)); AssetDatabase.Refresh(); RunBakeMaterial(AssetDatabase.GUIDToAssetPath(guid), terrainTarget, BakeTexRes); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); } }