コード例 #1
0
        /// <summary>
        /// Apply opening polygons on contour polygons, with triangulation
        /// </summary>
        private static void _cutOpenings(List <Point3DCollection> surfVertices,
                                         IEnumerable <List <Point3DCollection> > openingVertices,
                                         out Point3DCollection vertices,
                                         out Int32Collection indices)
        {
            vertices = new Point3DCollection();
            indices  = new Int32Collection();

            var tes = new LibTessDotNet.Double.Tess();

            foreach (var poly in surfVertices)
            {
                var cont = poly.Select(pt => new ContourVertex(new Vec3(pt.X, pt.Y, pt.Z))).ToArray();
                tes.AddContour(cont, ContourOrientation.CounterClockwise);
            }
            foreach (var opening in openingVertices)
            {
                foreach (var poly in opening)
                {
                    var hole = poly.Select(pt => new ContourVertex(new Vec3(pt.X, pt.Y, pt.Z))).ToArray();
                    tes.AddContour(hole, ContourOrientation.Clockwise);
                }
            }
            tes.Tessellate();

            vertices = new Point3DCollection(tes.Vertices.Select(i => new Point3D(i.Position.X, i.Position.Y, i.Position.Z)));
            indices  = new Int32Collection(tes.Elements);
        }
コード例 #2
0
        /// <summary>
        /// Create viewport geometry for the polygons (with tesselation)
        /// </summary>
        private static List <GeometryModel3D> _geometryFromPolygons(List <Point3DCollection> polyList)
        {
            var geomList = new List <GeometryModel3D>();

            foreach (var poly in polyList)
            {
                var tes = new LibTessDotNet.Double.Tess();
                tes.AddContour(poly.Select(pt => new ContourVertex(new Vec3(pt.X, pt.Y, pt.Z))).ToArray());
                tes.Tessellate();

                var positions       = new Point3DCollection(tes.Vertices.Select(i => new Point3D(i.Position.X, i.Position.Y, i.Position.Z)));
                var triangleIndices = new Int32Collection(tes.Elements);

                var material = MaterialHelper.CreateMaterial(Colors.LightGray); // Just in case, not to accidentally remain invisible (consequence of null)
                var mesh     = new MeshGeometry3D()
                {
                    Positions       = positions,
                    TriangleIndices = triangleIndices
                };
                var geom = new GeometryModel3D()
                {
                    Geometry     = mesh,
                    Material     = material,
                    BackMaterial = null
                };
                geomList.Add(geom);
            }

            return(geomList);
        }