Exemplo n.º 1
0
        public void Tesselate_WithSingleTriangle_ProducesSameTriangle()
        {
            string data            = "0,0,0\n0,1,0\n1,1,0";
            var    indices         = new List <int>();
            var    expectedIndices = new int[] { 0, 1, 2 };

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
            {
                var pset = DataLoader.LoadDat(stream);
                var tess = new Tess();

                PolyConvert.ToTess(pset, tess);
                tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3);

                indices.Clear();
                for (int i = 0; i < tess.ElementCount; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        int index = tess.Elements[i * 3 + j];
                        indices.Add(index);
                    }
                }

                Assert.AreEqual(expectedIndices, indices.ToArray());
            }
        }
Exemplo n.º 2
0
        public static void GenerateTestData()
        {
            foreach (var name in _loader.AssetNames)
            {
                var pset = _loader.GetAsset(name).Polygons;

                var lines   = new List <string>();
                var indices = new List <int>();

                foreach (WindingRule winding in Enum.GetValues(typeof(WindingRule)))
                {
                    var tess = new Tess();
                    PolyConvert.ToTess(pset, tess);
                    tess.Tessellate(winding, ElementType.Polygons, 3);

                    lines.Add(string.Format("{0} {1}", winding, 3));
                    for (int i = 0; i < tess.ElementCount; i++)
                    {
                        indices.Clear();
                        for (int j = 0; j < 3; j++)
                        {
                            int index = tess.Elements[i * 3 + j];
                            indices.Add(index);
                        }
                        lines.Add(string.Join(" ", indices));
                    }
                    lines.Add("");
                }

                File.WriteAllLines(Path.Combine(TestDataPath, name + ".testdat"), lines);
            }
        }
Exemplo n.º 3
0
        public void Tessellate_WithAsset_ReturnsExpectedTriangulation(TestCaseData data)
        {
            var pset = _loader.GetAsset(data.AssetName).Polygons;
            var tess = new Tess();

            PolyConvert.ToTess(pset, tess);
            tess.Tessellate(data.Winding, ElementType.Polygons, data.ElementSize);

            var resourceName = Assembly.GetExecutingAssembly().GetName().Name + ".TestData." + data.AssetName + ".testdat";
            var testData     = ParseTestData(data.Winding, data.ElementSize, Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName));

            Assert.IsNotNull(testData);
            Assert.AreEqual(testData.ElementSize, data.ElementSize);

            var indices = new List <int>();

            for (int i = 0; i < tess.ElementCount; i++)
            {
                for (int j = 0; j < data.ElementSize; j++)
                {
                    int index = tess.Elements[i * data.ElementSize + j];
                    indices.Add(index);
                }
            }

            Assert.AreEqual(testData.Indices, indices.ToArray());
        }
Exemplo n.º 4
0
        // From https://github.com/speps/LibTessDotNet/issues/1
        public void Tesselate_WithNoEmptyPolygonsTrue_RemovesEmptyPolygons()
        {
            string data            = "2,0,4\n2,0,2\n4,0,2\n4,0,0\n0,0,0\n0,0,4";
            var    indices         = new List <int>();
            var    expectedIndices = new int[] { 0, 1, 2, 2, 3, 4, 3, 1, 5 };

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
            {
                var pset = DataLoader.LoadDat(stream);
                var tess = new Tess();
                PolyConvert.ToTess(pset, tess);
                tess.NoEmptyPolygons = true;
                tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3);
                indices.Clear();
                for (int i = 0; i < tess.ElementCount; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        int index = tess.Elements[i * 3 + j];
                        indices.Add(index);
                    }
                }
                Assert.AreEqual(expectedIndices, indices.ToArray());
            }
        }
Exemplo n.º 5
0
        // From https://github.com/memononen/libtess2/issues/14
        public void Tesselate_WithThinQuad_DoesNotCrash()
        {
            string data = "9.5,7.5,-0.5\n9.5,2,-0.5\n9.5,2,-0.4999999701976776123\n9.5,7.5,-0.4999999701976776123";

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
            {
                var pset = DataLoader.LoadDat(stream);
                var tess = new Tess();
                PolyConvert.ToTess(pset, tess);
                tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3);
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            if (args.Length >= 1)
            {
                if (string.Equals(args[0], "gentestdat", StringComparison.OrdinalIgnoreCase))
                {
                    UnitTests.GenerateTestData();
                }
                if (args.Length == 2 && string.Equals(args[0], "profile", StringComparison.OrdinalIgnoreCase))
                {
                    int count = 0;
                    if (!int.TryParse(args[1], out count))
                    {
                        return;
                    }
                    var stopwatch = new Stopwatch();
                    var loader    = new DataLoader();
                    stopwatch.Start();
                    for (int i = 0; i < count; i++)
                    {
                        foreach (var name in loader.AssetNames)
                        {
                            var pset = loader.GetAsset(name).Polygons;

                            var lines   = new List <string>();
                            var indices = new List <int>();

                            foreach (WindingRule winding in Enum.GetValues(typeof(WindingRule)))
                            {
                                var tess = new Tess();
                                PolyConvert.ToTess(pset, tess);
                                tess.Tessellate(winding, ElementType.Polygons, 3);
                            }
                        }
                    }
                    stopwatch.Stop();
                    Console.WriteLine("{0:F3}ms", stopwatch.Elapsed.TotalMilliseconds);
                }
                return;
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
Exemplo n.º 7
0
        // From https://github.com/speps/LibTessDotNet/issues/1
        public void Tesselate_WithIssue1Quad_ReturnsSameResultAsLibtess2()
        {
            string data            = "50,50\n300,50\n300,200\n50,200";
            var    indices         = new List <int>();
            var    expectedIndices = new int[] { 0, 1, 2, 1, 0, 3 };

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
            {
                var pset = DataLoader.LoadDat(stream);
                var tess = new Tess();
                PolyConvert.ToTess(pset, tess);
                tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3);
                indices.Clear();
                for (int i = 0; i < tess.ElementCount; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        int index = tess.Elements[i * 3 + j];
                        indices.Add(index);
                    }
                }
                Assert.AreEqual(expectedIndices, indices.ToArray());
            }
        }