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"); }
public static VoxelModel ToModel(this MagicaFile magicaFile, Vector3Int volumeSize) { var magicaChunks = magicaFile.Chunks; var volume = new VoxelModel(volumeSize, magicaFile.Palette); var minPosition = new Vector3Int(int.MaxValue, int.MaxValue, int.MaxValue); var maxPosition = new Vector3Int(int.MinValue, int.MinValue, int.MinValue); var magicaSize = new Vector3(); for (var chunkIndex = 0; chunkIndex < magicaChunks.Length; chunkIndex++) { var magicaChunk = magicaChunks[chunkIndex]; var defaultPosition = magicaChunk.position; var chunkSize = magicaChunk.size; var chunkPosition = defaultPosition - chunkSize / 2; magicaChunk.position = chunkPosition; for (var i = 0; i < 3; i++) { if (chunkPosition[i] < minPosition[i]) { minPosition[i] = chunkPosition[i]; } } for (var i = 0; i < 3; i++) { if (chunkPosition[i] + chunkSize[i] > maxPosition[i]) { maxPosition[i] = chunkPosition[i] + chunkSize[i]; } } for (var i = 0; i < 3; i++) { magicaSize[i] = maxPosition[i] - minPosition[i]; } magicaChunks[chunkIndex] = magicaChunk; } foreach (var chunk in magicaChunks) { var voxels = chunk.voxels; var chunkPosition = new Vector3Int(chunk.position.x, chunk.position.y, chunk.position.z); var positionAdjustment = chunkPosition - minPosition; var rotation = chunk.rotation; var size = chunk.size; foreach (var magicaVoxel in voxels) { var voxelPosition = new Vector3Int(magicaVoxel.x, magicaVoxel.y, magicaVoxel.z); for (var i = 0; i < 3; i++) { var multiplier = rotation[i]; if (multiplier != 1) { var value = voxelPosition[i] * multiplier; voxelPosition[i] = size[i] + value - 1; } } var position = voxelPosition + positionAdjustment; var index = VoxelUtility.GetVoxelIndex(position, volumeSize); var voxel = new VoxelEntity { colorIndex = magicaVoxel.colorIndex, data = 100 }; volume.SetVoxel(index, voxel); } } return(volume); }
static void SimpleLoad2() { var voxels = MagicaFile.Load(@"..\..\..\Assets\Vox\StoneBedroom.vox")[0]; }