Exemple #1
0
        /// <summary>
        /// Tessellate the topography.
        /// </summary>
        /// <param name="mesh">The mesh into which the topography's facets will be added.</param>
        public void Tessellate(ref Mesh mesh)
        {
            foreach (var t in this._mesh.Triangles)
            {
                var c = this._colorizer(t);
                t.Vertices[0].Color = c;
                t.Vertices[1].Color = c;
                t.Vertices[2].Color = c;
            }

            mesh.AddMesh(this._mesh);
        }
Exemple #2
0
        /// <summary>
        /// Create a topography from a custom mesh. It is assumed that the mesh is an open mesh that's roughly parallel to the XY plane.
        /// </summary>
        /// <param name="mesh">The mesh geometry of the topography.</param>
        /// <param name="material">The topography's material.</param>
        /// <param name="transform">The topography's transform.</param>
        /// <param name="id">The topography's id.</param>
        /// <param name="name">The topography's name.</param>
        /// <returns></returns>
        public Topography(Mesh mesh, Material material, Transform transform, Guid id, string name) : base(material,
                                                                                                          transform,
                                                                                                          false,
                                                                                                          id,
                                                                                                          name)
        {
            var newMesh = new Mesh(mesh);
            var bbox    = new BBox3(mesh.Vertices.Select(v => v.Position));

            this._minElevation = bbox.Min.Z;
            this._maxElevation = bbox.Max.Z;
            double absoluteMinimumElevation = this.AbsoluteMinimumElevation ?? this.MinElevation - this.DepthBelowMinimumElevation;
            var    nakedBoundaries          = mesh.GetNakedBoundaries();
            var    basePlane = new Plane((0, 0, absoluteMinimumElevation), (0, 0, 1));

            foreach (var polygon in nakedBoundaries)
            {
                // construct bottom
                var bottomPolygon = polygon.Project(basePlane);
                var tess          = new Tess
                {
                    NoEmptyPolygons = true
                };
                tess.AddContour(bottomPolygon.Reversed().ToContourVertexArray());
                tess.Tessellate(WindingRule.Positive, ElementType.Polygons, 3);
                var faceMesh = tess.ToMesh(normal: (0, 0, -1));
                this._baseVerts = new List <Vertex>(faceMesh.Vertices);
                newMesh.AddMesh(faceMesh);
                // construct sides
                var upperSegments = polygon.Segments();
                var lowerSegments = bottomPolygon.Segments();
                for (int i = 0; i < upperSegments.Count(); i++)
                {
                    var topEdge    = upperSegments[i];
                    var bottomEdge = lowerSegments[i];
                    var normal     = topEdge.Direction().Cross(Vector3.ZAxis).Unitized();
                    var a          = newMesh.AddVertex(topEdge.Start, normal: normal);
                    var b          = newMesh.AddVertex(topEdge.End, normal: normal);
                    var c          = newMesh.AddVertex(bottomEdge.End, normal: normal);
                    var d          = newMesh.AddVertex(bottomEdge.Start, normal: normal);
                    newMesh.AddTriangle(a, c, b);
                    newMesh.AddTriangle(a, d, c);
                }
            }
            this.Mesh = newMesh;
        }
Exemple #3
0
 /// <summary>
 /// Tessellate the topography.
 /// </summary>
 /// <param name="mesh">The mesh into which the topography's facets will be added.</param>
 public void Tessellate(ref Mesh mesh)
 {
     mesh.AddMesh(this._mesh);
 }