static void TestMagicaFile() { var m = MagicaFile.Load(@"..\..\..\..\Assets\VoxModels\Twist.vox"); Console.WriteLine("Loaded {0} models", m.Length); for (int z = 0; z < 126; z++) { for (int y = 0; y < 126; y++) { for (int x = 0; x < 126; x++) { if (m[0].IsValid(x, y, z) && m[0][x, y, z].w > 0) { Console.Write("#"); } else { Console.Write(" "); } } Console.WriteLine(); } Console.Write("\nPress any key to continue ... "); Console.ReadKey(); Console.WriteLine(); } Console.WriteLine("Size: <{0}, {1}, {2}>", m[0].Size.x, m[0].Size.y, m[0].Size.z); Console.WriteLine("Valid: {0}", m[0].IsValid(new Vec3i(64, 64, 64))); Console.Write("\nPress any key to continue ... "); Console.ReadKey(); }
static void TestVoxelSimplify() { var m = MagicaFile.Load(@"..\..\..\..\Assets\VoxModels\cathedral-2.vox"); var ms = Mesher.VoxelsToMesh(m[0]); ms.PrintStats(); ms.SaveToObj("voxels_simplified.obj"); }
static TimeSpan SimpleLoad1() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < 32; ++i) { var voxels = MagicaFile.Load(@"..\..\..\Assets\VoxModels\cathedral-2.vox")[0]; } stopwatch.Stop(); return(stopwatch.Elapsed); }
static void TestLowPassFilter() { var voxels = MagicaFile.Load(@"..\..\..\..\Assets\VoxModels\cathedral-2.vox")[0]; //var voxels = MagicaFile.Load(@"..\..\..\..\Assets\VoxModels\Twist.vox")[0]; Console.WriteLine("Raw boxes: {0}", BoxMaker.MakeBoxes(voxels).Count); for (int i = 0; i <= 20; ++i) { float transference = i / 20.0f; var shape = BoxMaker.LowPassFilter(voxels, transference, 0.25f); Console.WriteLine("{0,3}: {1:F2} {2,6}", i, transference, BoxMaker.MakeBoxes(shape).Count); } }
static void TestSimplify5() { var voxels = MagicaFile.Load(@"..\..\..\..\Assets\Vox\tt3.vox"); int transCount = 0; voxels[0].Apply((Vec4b v, Vec3i idx) => { if (v.w > 0 && v.w < 255) { transCount++; } }); Console.WriteLine("\nTransparent count: {0}\n", transCount); }
static void TestVoxelSimplify2() { var m = MagicaFile.Load(@"..\..\..\..\Assets\VoxModels\Wall_07.vox"); var ms = Mesher.VoxelsToMeshFull(m[0]); ms.SaveToObj("voxels_pre_91.obj"); ms.Collapse(43); ms.Collapse(54); ms.Collapse(61); ms.Collapse(91); ms.Compact(); ms.PrintStats(); ms.SaveToObj("voxels_post_91.obj"); }
static void TestSimplify4() { //var voxels = MagicaFile.Load(@"C:\Projects\FloofBox\uRogue\Assets\VoxModels\cathedral-2.vox"); var voxels = MagicaFile.Load(@"..\..\..\..\Assets\Vox\TransparencyTest.vox"); var boxes = BoxMaker.MakeBoxes(voxels[0]); Console.WriteLine("{0} boxes made", boxes.Count); MeshSimplifier ms = Mesher.VoxelsToMeshFull(voxels[0]); Console.WriteLine("Triangles before reduction: " + (ms.Edges.Length / 3)); ms.Simplify(); ms.Compact(); Console.WriteLine("Triangles after reduction: " + (ms.Edges.Length / 3)); int[] tris; Vec3f[] rawPos; Vec3f[] rawNormals; Vec2f[] rawUvs; VoxelSet <Vec4b> atlas; ms.GetMesh(voxels[0], out tris, out rawPos, out rawNormals, out rawUvs, out atlas); Bitmap bmp = new Bitmap(atlas.Size.x, atlas.Size.y); for (int y = 0; y < atlas.Size.y; ++y) { for (int x = 0; x < atlas.Size.x; ++x) { bmp.SetPixel(x, y, Color.FromArgb( atlas[x, y, 0].x, atlas[x, y, 0].y, atlas[x, y, 0].z )); } } bmp.Save("Atlas.png"); }
static void SimpleLoad2() { var voxels = MagicaFile.Load(@"..\..\..\Assets\Vox\StoneBedroom.vox")[0]; }