简体   繁体   English

meshbuilder AddPolygon() 方法出现奇怪行为的原因是什么?

[英]What is the reason for the strange behavior of meshbuilder AddPolygon() method?

For a counter-clockwise ordered list of points like this:对于逆时针排序的点列表,如下所示:

        var points = new[]
        {
            new Point3D(-2, -4, 8), //a
            new Point3D(6,  -1, 8), //b
            new Point3D(6,  5,  8), //c
            new Point3D(0,  8,  8), //d
            new Point3D(1,  3,  8), //e
        }.ToList();

I want to add a polygon to my HelixViewPort3D view:我想在我的 HelixViewPort3D 视图中添加一个多边形:

        var meshBuilder = new MeshBuilder(false, false, false);

        meshBuilder.AddPolygon(points);

        var geometryModel = new GeometryModel3D
        {
            Material = Materials.Red,
            BackMaterial = Materials.Blue,
            Geometry = meshBuilder.ToMesh()
        };
        var modelVisual = new ModelVisual3D { Content = geometryModel };
        view.Children.Add(modelVisual);

        int index = 0;
        foreach (var point in points)
        {
            view.Children.Add(new BillboardTextVisual3D
            {
                DepthOffset = 1e-3,
                Position = point,
                Text = string.Format("[{0}] : {1}, {2}", index++, point.X, point.Y)
            });
        }

        view.ZoomExtents();

showing each point's x and y coordinate along side with them using BillboardTextVisual3D, I'm getting this: default list使用 BillboardTextVisual3D 显示每个点的 x 和 y 坐标,我得到这个:默认列表

which is not right, somehow the d:(0, 8) is being connected to a:(-2, -4).这是不对的,不知何故 d:(0, 8) 被连接到 a:(-2, -4)。 and the back material (blue) is showing on top of face material (red).背面材料(蓝色)显示在面材料(红色)的顶部。

changing the order of the list though fixes the problem: ordered list更改列表的顺序虽然解决了问题:有序列表

var points = new[]
    {
        new Point3D(1,  3,  8), //e
        new Point3D(-2, -4, 8), //a
        new Point3D(6,  -1, 8), //b
        new Point3D(6,  5,  8), //c
        new Point3D(0,  8,  8), //d
    }.ToList();

the second list is still counter-clockwise ordered the only difference is the starting point (which is now e:(1, 3)).第二个列表仍然是逆时针排序,唯一的区别是起点(现在是 e:(1, 3))。 is there any reason why should this effect the outcome?有什么理由会影响结果吗?

PS I think it should have something to do with the points distance to the origin (0,0,0), starting with the nearest point to the origin somehow do the job. PS我认为它应该与到原点的点距离(0,0,0)有关,从离原点最近的点开始以某种方式完成工作。 is it a bug or I'm missing something here?这是一个错误还是我在这里遗漏了什么?

PS#2 This problem seems to occur only in the case of concave polygons and has no effect on the convex polygons. PS#2 这个问题好像只出现在凹多边形的情况下,对凸多边形没有影响。

AddPolygon() use a triangle fan when positions count is greater than 4, so your last triangle is:当位置计数大于 4 时, AddPolygon()使用三角形扇形,因此您的最后一个三角形是:

-2, -4, 8
0, 8, 8
1, 3, 8

It turns in clockwise direction, the back material is then in front of the camera.顺时针方向转动,背面材料就在相机前面。 It's the expected behavior.这是预期的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM