public override bool CanDecode(Chunks.Chunk chunk) { SRFile file = chunk.File; file.Position = chunk.Offset; return(file.ReadFourCC() == "5VSM"); }
public static void Run(int resolution, UtilFuncs.Sampler samp, Chunks.Chunk chunk) { resolution += 1; chunk.State = Chunks.ChunkState.Meshing; Resolution = resolution; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); List <Vector3> vertices = new List <Vector3>(); List <Vector3> normals = new List <Vector3>(); //List<Vector3> lod1vertices = new List<Vector3>(); //List<Vector3> lod1normals = new List<Vector3>(); List <int> indices = new List <int>(); CellInfo[,,] drawInfos = GenVertices(resolution, samp); long genVertsTime = sw.ElapsedMilliseconds; sw.Restart(); //GenVerticesLOD1(resolution, drawInfos, samp); //long genVertsLod1Time = sw.ElapsedMilliseconds; sw.Restart(); GenIndices(drawInfos, indices, vertices, normals); long genIndicesTime = sw.ElapsedMilliseconds; chunk.Vertices = vertices; chunk.Triangles = indices.ToArray(); chunk.Normals = normals; //chunk.LOD1Vertices = lod1vertices; //chunk.LOD1Normals = lod1normals; chunk.State = Chunks.ChunkState.Blank; sw.Stop(); //Debug.Log("Uniform dual contouring time for " + resolution + "^3 mesh: " + (genVertsTime + genVertsLod1Time + genIndicesTime) + "ms" + "(GenVerts: " + genVertsTime + ", GenVertsLOD1: " + genVertsLod1Time + ", GenIndices: " + genIndicesTime + ")"); }
public static bool PolygonizeArea(int resolution, UtilFuncs.Sampler samp, Chunks.Chunk chunk) { int res2 = resolution + 2; float[] data = new float[res2 * res2 * res2]; return(PolygonizeArea(resolution, samp, chunk, data)); }
public override uint GetCount(Chunks.Chunk chunk) { using (var stream = chunk.GetStream()) { var ddsImage = new DDSImage(stream); return((uint)ddsImage.MipMapCount); } }
public override byte[] Decode(Chunks.Chunk chunk, uint index) { using (var stream = chunk.GetStream()) { var ddsImage = new DDSImage(stream); ddsImage.Decode(stream); return(ddsImage.images[0].Bitmap); } }
public static void FillData(int resolution, Chunks.Chunk chunk, float[] data) { noise.FillNoiseSet(data, chunk.Position.x, chunk.Position.y, chunk.Position.z, resolution + 2, resolution + 2, resolution + 2); /*string noiseStr = "Noise: {"; * for(int i = 0; i < resolution * resolution; i++) { * noiseStr += data[i] + ", "; * } * noiseStr += "}"; * Debug.Log(noiseStr);*/ }
public override void Execute(BasePaletteDecoder decoder, Chunks.Chunk chunk, string filename) { if (String.IsNullOrEmpty(filename)) { return; } Palette pal = decoder.Decode(chunk); Save(filename, pal); }
public override ImageInfo GetInfo(Chunks.Chunk chunk, uint index) { using (var stream = chunk.GetStream()) { var ddsImage = new DDSImage(stream); return(new ImageInfo { X = 0, Y = 0, Height = ddsImage.Height, Width = ddsImage.Width, PixelFormat = PixelDepth.Depth32 }); } }
public static BenchmarkResult PolygonizeAreaBenchmarked(int resolution, UtilFuncs.Sampler samp, Chunks.Chunk chunk, float[] data) { BenchmarkResult result = new BenchmarkResult(); double fillDataMs, createVerticesMs, triangulateMs, transitionCellMs = 0; int res1 = resolution + 1; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); FillData(resolution, chunk, data); sw.Stop(); fillDataMs = sw.Elapsed.TotalMilliseconds; sw.Restart(); int resm1 = resolution - 1; int resm2 = resolution - 2; List <Vector3> vertices = new List <Vector3>(); List <Vector3> normals = new List <Vector3>(); List <int> triangles = new List <int>(); ushort[] edges = new ushort[res1 * res1 * res1 * 3]; Vector3Int begin = new Vector3Int(0, 0, 0); Vector3Int end = new Vector3Int(res1, res1, res1); byte lod = (byte)chunk.LODCode; if ((lod & 1) == 1) { begin.x += 1; } if ((lod & 2) == 2) { end.x -= 1; } if ((lod & 4) == 4) { begin.y += 1; } if ((lod & 8) == 8) { end.y -= 1; } if ((lod & 16) == 16) { begin.z += 1; } if ((lod & 32) == 32) { end.z -= 1; } CreateVertices(edges, begin, end, vertices, normals, res1, data); sw.Stop(); createVerticesMs = sw.Elapsed.TotalMilliseconds; sw.Restart(); end -= Vector3Int.one; Triangulate(edges, begin, end, triangles, resolution, data); sw.Stop(); triangulateMs = sw.Elapsed.TotalMilliseconds; sw.Restart(); //Debug.Log("Phase 1 of surface extraction took " + sw.ElapsedMilliseconds + " ms."); if (lod != 0) { GenerateTransitionCells(vertices, normals, triangles, resolution, data, lod); } sw.Stop(); transitionCellMs = sw.Elapsed.TotalMilliseconds; sw.Restart(); //Debug.Log("Phase 2 of surface extraction took " + sw.ElapsedMilliseconds + " ms."); //MCVT(vertices, triangles, normals, resolution, lod, data); result.createVerticesMs = createVerticesMs; result.fillDataMs = fillDataMs; result.transitionCellMs = transitionCellMs; result.triangulateMs = triangulateMs; chunk.Vertices = vertices; chunk.Triangles = triangles.ToArray(); chunk.Normals = normals; return(result); }
public static bool PolygonizeAreaDecked(int resolution, Chunks.Chunk chunk, float[] data) { GenModifiedTriTable(resolution + 1); double fillDataMs, createVerticesMs, triangulateMs, transitionCellMs = 0; int res1 = resolution + 1; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); FillData(resolution, chunk, data); sw.Stop(); fillDataMs = sw.Elapsed.TotalMilliseconds; sw.Restart(); int resm1 = resolution - 1; int resm2 = resolution - 2; List <Vector3> vertices = new List <Vector3>(); List <Vector3> normals = new List <Vector3>(); List <int> triangles = new List <int>(); ushort[] edges = new ushort[res1 * res1 * res1 * 3]; Vector3Int begin = new Vector3Int(0, 0, 0); Vector3Int end = new Vector3Int(res1, res1, res1); byte lod = (byte)chunk.LODCode; if ((lod & 1) == 1) { begin.x += 1; } if ((lod & 2) == 2) { end.x -= 1; } if ((lod & 4) == 4) { begin.y += 1; } if ((lod & 8) == 8) { end.y -= 1; } if ((lod & 16) == 16) { begin.z += 1; } if ((lod & 32) == 32) { end.z -= 1; } DeckMC(begin, end, vertices, normals, triangles, resolution, data); sw.Stop(); createVerticesMs = sw.Elapsed.TotalMilliseconds; sw.Restart(); /*if(lod != 0) { * GenerateTransitionCells(vertices, normals, triangles, resolution, data, lod); * }*/ sw.Stop(); transitionCellMs = sw.Elapsed.TotalMilliseconds; sw.Restart(); //Debug.Log("Phase 2 of surface extraction took " + sw.ElapsedMilliseconds + " ms."); //MCVT(vertices, triangles, normals, resolution, lod, data); Debug.Log("Done meshing decked " + resolution + "^3 chunk. " + "FillData ms: " + fillDataMs + ", CreateVertices ms: " + createVerticesMs + ", TransitionCell ms: " + transitionCellMs + " (Total: " + (fillDataMs + createVerticesMs + transitionCellMs) + "ms. )"); chunk.Vertices = vertices; chunk.Triangles = triangles.ToArray(); chunk.Normals = normals; return(true); }
public override List <FileTypeInfo> GetFileTypes(BasePaletteDecoder decoder, Chunks.Chunk chunk) { return(filetypes); }