Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing on simple example. #50

Open
Scrawk opened this issue Mar 14, 2022 · 1 comment
Open

Failing on simple example. #50

Scrawk opened this issue Mar 14, 2022 · 1 comment

Comments

@Scrawk
Copy link

Scrawk commented Mar 14, 2022

Failing on simple example. Any help?

Outputs 0,1,2 and 0, 1, 3

List<int> triangules = new List<int>();
int numPoints = 4;

            //var points = new Point2d[numPoints];
            //GetPoints(points, points.Length);

            var points = new Point2d[]
            {
                    new Point2d(- 1,-1),
                    new Point2d(1,-1),
                    new Point2d(1,1),
                    new Point2d(- 1,1)
            };

            // A polygon can be composed of multiple contours which are all tessellated at the same time.
            var contour = new ContourVertex[numPoints];
            for (int i = 0; i < numPoints; i++)
                contour[i].Position = new Vec3(points[i].x, points[i].y, 0);

            // Create an instance of the tessellator. Can be reused.
            var tess = new Tess();
            // Add the contour with a specific orientation, use "Original" if you want to keep the input orientation.
            tess.AddContour(contour, ContourOrientation.Clockwise);

            // The winding rule determines how the different contours are combined together.
            // See http://www.glprogramming.com/red/chapter11.html (section "Winding Numbers and Winding Rules") for more information.
            // If you want triangles as output, you need to use "Polygons" type as output and 3 vertices per polygon.
            tess.Tessellate(WindingRule.EvenOdd, ElementType.Polygons, 3);

            int numTriangles = tess.ElementCount;
            for (int i = 0; i < numTriangles; i++)
            {
                var a = tess.Elements[i * 3 + 0];
                var b = tess.Elements[i * 3 + 1];
                var c = tess.Elements[i * 3 + 2];

                Console.WriteLine(a);
                Console.WriteLine(b);
                Console.WriteLine(c);

                triangules.Add(a);
                triangules.Add(b);
                triangules.Add(c);
            }

square

@ambroiseRabier
Copy link

ambroiseRabier commented Mar 13, 2024

I have the same issue (or similar ?). When making a simple Square, it seems to re-order the "Contour" incorrectly.

// correct order
      Vector3[] init = new Vector3[] {
        new Vector3(0f, 0f),
        new Vector3(0f, 0.5f),
        new Vector3(0.5f, 0.5f),
        new Vector3(0.5f, 0f),
      };
      
// wrong order given by tess.Vertices (using CounterClockwise, but Original or Clockwise have the same issue)
      Vector3[] init = new Vector3[] {
        new Vector3(0f, 0f),
        new Vector3(0.5f, 0.5f),
        new Vector3(0.5f, 0f),
        new Vector3(0f, 0.5f),
      };

At first glance we can see that (0.5f, 0.5f) point should never be adjacent with (0f, 0f) point, or we get a diagonal in the square as "Contour".

Strangely, in my particular case, I still end up with a square by using Tess. But when I try to cut that square in two with Clipper2 I end up with very strange results. But results that make sense if I give Clipper2 that bow knot contour instead of a proper square contour.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants