Exemplo n.º 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();
        }
Exemplo n.º 2
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();
        }