Example #1
0
        public void TessellatorProducesCorrectVertexNormals()
        {
            Name = nameof(TessellatorProducesCorrectVertexNormals);
            var shape = new Polygon((4.96243, 50.58403), (5.78472, 50.58403), (5.78472, 65.83403), (-7.05727, 65.83403), (-7.05727, 50.57403), (4.96243, 50.57403));

            var geoElem = new GeometricElement(representation: new Extrude(shape, 1, Vector3.ZAxis, false));

            Model.AddElement(geoElem);
            var solid  = geoElem.GetFinalCsgFromSolids();
            var mgb    = new MockGraphicsBuffer();
            var arrows = new ModelArrows();

            Tessellation.Tessellate(new Csg.Solid[] { solid }.Select(s => new CsgTessellationTargetProvider(solid)), mgb);
            for (int i = 0; i < mgb.Indices.Count; i += 3)
            {
                var a     = mgb.Indices[i];
                var b     = mgb.Indices[i + 1];
                var c     = mgb.Indices[i + 2];
                var verts = new[] { mgb.Vertices[a], mgb.Vertices[b], mgb.Vertices[c] };
                verts.ToList().ForEach((v) =>
                {
                    arrows.Vectors.Add((v.position, v.normal, 0.2, Colors.Blue));
                });
                var triangle = new Polygon(verts.Select(v => v.position).ToList());
                var normal   = verts[0].normal;
                Assert.True(triangle.Normal().Dot(normal.Unitized()) > 0, "The vertex normals are pointing in the opposite direction as their triangles' winding should suggest");
                Model.AddElement(triangle.TransformedPolygon(new Transform(normal * 0.2)));
            }
            Model.AddElement(arrows);
        }
Example #2
0
        public void UnionWithProblematicPolygons()
        {
            var profile1 = JsonConvert.DeserializeObject <Polygon>(
                @"{
                ""Vertices"": [
                    {
                        ""X"": -348.82036858497275,
                        ""Y"": 246.02759072077453,
                        ""Z"": 30.25
                    },
                    {
                        ""X"": -348.85572392403208,
                        ""Y"": 246.06294605983385,
                        ""Z"": 30.25
                    },
                    {
                        ""X"": -350.60244308413706,
                        ""Y"": 244.31622689972886,
                        ""Z"": 30.25
                    },
                    {
                        ""X"": -350.56708774507774,
                        ""Y"": 244.28087156066954,
                        ""Z"": 30.25
                    },
                    {
                        ""X"": -350.53173240601842,
                        ""Y"": 244.24551622161022,
                        ""Z"": 30.25
                    },
                    {
                        ""X"": -348.78501324591343,
                        ""Y"": 245.9922353817152,
                        ""Z"": 30.25
                    }
                ]}
                ");
            var profile2 = JsonConvert.DeserializeObject <Polygon>(
                @"{
                ""Vertices"": [
                    {
                        ""X"": -350.56708774507774,
                        ""Y"": 244.28087156066954,
                        ""Z"": 30.25
                    },
                    {
                        ""X"": -350.51708774507773,
                        ""Y"": 244.28087156066954,
                        ""Z"": 30.25
                    },
                    {
                        ""X"": -350.51708774507773,
                        ""Y"": 247.77430988087954,
                        ""Z"": 30.25
                    },
                    {
                        ""X"": -350.56708774507774,
                        ""Y"": 247.77430988087954,
                        ""Z"": 30.25
                    },
                    {
                        ""X"": -350.61708774507775,
                        ""Y"": 247.77430988087954,
                        ""Z"": 30.25
                    },
                    {
                        ""X"": -350.61708774507775,
                        ""Y"": 244.28087156066954,
                        ""Z"": 30.25
                    }
                    ]}"
                );
            var element = new GeometricElement();

            element.Representation = new Representation(new List <SolidOperation> {
                new Extrude(profile1, 1, Vector3.ZAxis, false),
                new Extrude(profile2, 1, Vector3.ZAxis, false)
            });

            element.UpdateRepresentations();
            var solid = element.GetFinalCsgFromSolids();
        }