예제 #1
0
        static void TestMeshWithHole()
        {
            int width          = 3;
            int verticesPerRow = width + 1;

            Func <int, int, int> VertIdx = (x, y) => verticesPerRow * y + x;

            List <Vec3f> vertices = new List <Vec3f>();
            List <int>   indices  = new List <int>();

            for (int y = 0; y < verticesPerRow; ++y)
            {
                for (int x = 0; x < verticesPerRow; ++x)
                {
                    Vec3f v = new Vec3f();
                    v.x = x;
                    v.y = y;
                    v.z = 0;
                    vertices.Add(v);
                }
            }

            for (int y = 0; y < width; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    if (x == 1 && y == 1)
                    {
                        // Make a hole
                        continue;
                    }

                    indices.Add(VertIdx(x, y));
                    indices.Add(VertIdx(x + 1, y));
                    indices.Add(VertIdx(x + 1, y + 1));

                    indices.Add(VertIdx(x, y));
                    indices.Add(VertIdx(x + 1, y + 1));
                    indices.Add(VertIdx(x, y + 1));
                }
            }

            MeshSimplifier m = new MeshSimplifier(vertices.ToArray(), indices.ToArray());

            m.SaveToObj("out_full.obj");
            Console.WriteLine("Triangle count: {0}", m.Edges.Length / 3);

            m.Simplify();
            m.SaveToObj("out_simple.obj");
            m.Compact();

            Console.WriteLine("Triangle count: {0}", m.Edges.Length / 3);
            Console.Write("\nPress any key to continue ... ");
            Console.ReadKey();
        }
예제 #2
0
        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");
        }
예제 #3
0
        static void TestMesh()
        {
            int width          = 16;
            int verticesPerRow = width + 1;

            Func <int, int, int> VertIdx = (x, y) => verticesPerRow * y + x;

            List <Vec3f> vertices = new List <Vec3f>();
            List <int>   indices  = new List <int>();

            for (int y = 0; y < verticesPerRow; ++y)
            {
                for (int x = 0; x < verticesPerRow; ++x)
                {
                    Vec3f v = new Vec3f();
                    v.x = x;
                    v.y = y;
                    v.z = 0;
                    vertices.Add(v);
                }
            }

            for (int y = 0; y < width; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    indices.Add(VertIdx(x, y));
                    indices.Add(VertIdx(x + 1, y));
                    indices.Add(VertIdx(x + 1, y + 1));

                    indices.Add(VertIdx(x, y));
                    indices.Add(VertIdx(x + 1, y + 1));
                    indices.Add(VertIdx(x, y + 1));
                }
            }

            MeshSimplifier m = new MeshSimplifier(vertices.ToArray(), indices.ToArray());

            m.SaveToObj("out_full.obj");
            int triangleCount = 0;

            for (int i = 0; i < m.Edges.Length; i += 3)
            {
                if (m.Edges[i].vertexIdx >= 0)
                {
                    triangleCount++;
                }
                else
                {
                    Console.WriteLine("Bad edge at index: {0}", i);
                }
            }

            m.Compact();

            Console.WriteLine("Triangle count: {0}", triangleCount);

            m.Simplify();

            triangleCount = 0;
            for (int i = 0; i < m.Edges.Length; i += 3)
            {
                if (m.Edges[i].vertexIdx >= 0)
                {
                    triangleCount++;

                    for (int j = 0; j < 3; ++j)
                    {
                        Vec3f p = m.Points[m.Edges[i + j].vertexIdx];
                        Console.WriteLine("<{0}, {1}, {2}>", p.x, p.y, p.z);
                    }
                    Console.WriteLine();
                }
            }
            m.SaveToObj("out_simple.obj");
            m.Compact();

            Console.WriteLine("Triangle count: {0}", triangleCount);
            Console.Write("\nPress any key to continue ... ");
            Console.ReadKey();
        }