void OnDestroy() { if (SurfExtractor != null) { SurfExtractor.Reset(); } if (_dataLoader != null) { _dataLoader.Close(); } c_fWaterLvl = 97.0f; // reset to default Debug.Log("Mem size before vfTerrain destroyed all chunks :" + GC.GetTotalMemory(true)); // If something is left over... (in the editor) if (gameObject.transform.childCount > 0) { // Clean up chunks for (int i = gameObject.transform.childCount - 1; i >= 0; --i) { var child = gameObject.transform.GetChild(i).gameObject; DestroyImmediate(child); } } Resources.UnloadUnusedAssets(); self = null; VFVoxelSave.Clean(); }
private void OnChunkDataLoad(VFVoxelChunkData chunkData, byte[] chunkDataVT, bool bFromPool) { chunkData.SetDataVT(chunkDataVT, bFromPool); if (chunkData.IsHollow) { if (chunkData.DataVT[0] == 128) { VFVoxelWater.ExpandSurfaceChunkData(chunkData); } else { VFVoxelChunkData.ExpandHollowChunkData(chunkData); } } }
void Awake() { self = this; s_bSeaInSight = false; s_layer = Pathea.Layer.Water; }
public void GenRiverVoxels(AttachedRiverScript riverScript) { MeshCollider mc = riverScript.GetComponent <MeshCollider>(); if (mc == null) { riverScript.CreateMesh(riverScript.riverSmooth); mc = riverScript.GetComponent <MeshCollider>(); } if (mc == null || mc.sharedMesh == null) { Debug.LogError("Can not find mesh collider"); return; } VFVoxelWater.InitSufaceChunkData(); Bounds meshBound = mc.sharedMesh.bounds; #if UNITY_EDITOR EditorUtility.DisplayProgressBar("RiverVoxels...", "Starting gen...", 0); #endif Vector3 boundMin = meshBound.min; Vector3 boundMax = meshBound.max; IntVector4 cpos = new IntVector4(); if (!System.IO.Directory.Exists(outputDir)) { System.IO.Directory.CreateDirectory(outputDir); } curOutputDir = outputDir + "/" + riverScript.name; if (!System.IO.Directory.Exists(curOutputDir)) { System.IO.Directory.CreateDirectory(curOutputDir); } string filePrefix = curOutputDir + "/water"; #if false //test GenARiverChunk(ref boundMin, ref boundMax, mc, new IntVector4(310, 2, 221, 0), filePrefix); #else //float prev = VoxelTerrainConstants._numVoxelsPrefix /(float)VoxelTerrainConstants._numVoxelsPerAxis; //float post = VoxelTerrainConstants._numVoxelsPostfix/(float)VoxelTerrainConstants._numVoxelsPerAxis; for (cpos.w = 0; cpos.w <= LODOctreeMan.MaxLod; cpos.w++) { int step = 1 << cpos.w; int lodPrefix = VoxelTerrainConstants._numVoxelsPrefix << cpos.w; int lodpostfix = VoxelTerrainConstants._numVoxelsPostfix << cpos.w; int sx = (((int)(boundMin.x) - lodPrefix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w; int sy = (((int)(boundMin.y) - lodPrefix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w; int sz = (((int)(boundMin.z) - lodPrefix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w; int ex = (((int)(boundMax.x) + lodpostfix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w; int ey = (((int)(boundMax.y) + lodpostfix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w; int ez = (((int)(boundMax.z) + lodpostfix) >> (VoxelTerrainConstants._shift + cpos.w)) << cpos.w; if (sy < 0) { sy = 0; } int n = (((ex - sx) >> cpos.w) + 1) * (((ey - sy) >> cpos.w) + 1) * (((ez - sz) >> cpos.w) + 1); float progressStep = 1.0f / n; float progress = 0.0f; for (cpos.x = sx; cpos.x <= ex; cpos.x += step) { for (cpos.z = sz; cpos.z <= ez; cpos.z += step) { for (cpos.y = sy; cpos.y <= ey; cpos.y += step) { #if UNITY_EDITOR EditorUtility.DisplayProgressBar("RiverVoxels..." + cpos.w, "Gen " + cpos + "...", progress); progress += progressStep; #endif GenARiverChunk(ref boundMin, ref boundMax, mc, new IntVector4(cpos), filePrefix); } } } } #endif #if UNITY_EDITOR EditorUtility.ClearProgressBar(); #endif }