private static ModelVisual3D Planar(IFeature basePath)
        {
            TongJi.Geometry.Polyline curve = new TongJi.Geometry.Polyline(basePath.GeoData);
            if (curve.AlgebraicArea < 0)
            {
                curve = curve.ReversePoints();
            }
            var points = curve.Points.ToList();

            if (points.Last() == points.First())
            {
                points.RemoveAt(points.Count - 1);
            }
            var triangles = DelaunayOfPolygon(points);

            MeshBuilder mb = new MeshBuilder();

            foreach (var tri in triangles)
            {
                var a = new Point3D(tri.A.x, tri.A.y, 0);
                var b = new Point3D(tri.B.x, tri.B.y, 0);
                var c = new Point3D(tri.C.x, tri.C.y, 0);
                mb.AddTriangle(a, b, c);
            }
            ModelVisual3D visual = new ModelVisual3D();

            visual.Content = new GeometryModel3D(mb.ToMesh(), MaterialHelper.CreateMaterial(Colors.Blue));
            return(visual);
        }
Exemple #2
0
        public static MeshBuilder Planar(TongJi.Geometry.Polyline curve)
        {
            const double epsilon = 0.001;

            curve.ReducePoints(epsilon);
            var points = curve.Points.ToList();

            if (points.Last().DistTo(points.First()) < epsilon)
            {
                points.RemoveAt(points.Count - 1);
            }
            var triIndices = CuttingEarsTriangulator.Triangulate(points.Select(p => new System.Windows.Point(p.x, p.y)).ToList());

            if (triIndices == null)
            {
                return(null);
            }
            MeshBuilder mb = new MeshBuilder();

            for (int i = 0; i < triIndices.Count; i += 3)
            {
                var a = new Point3D(points[triIndices[i]].x, points[triIndices[i]].y, 0);
                var b = new Point3D(points[triIndices[i + 1]].x, points[triIndices[i + 1]].y, 0);
                var c = new Point3D(points[triIndices[i + 2]].x, points[triIndices[i + 2]].y, 0);
                mb.AddTriangle(a, b, c);
            }
            return(mb);
        }
        public static MeshBuilder Planar(TongJi.Geometry.Polyline curve)
        {
            if (curve.AlgebraicArea < 0)
            {
                curve = curve.ReversePoints();
            }
            var points = curve.Points.ToList();

            if (points.Last() == points.First())
            {
                points.RemoveAt(points.Count - 1);
            }
            var triangles = DelaunayOfPointSet(points);

            //var vertices = new FarseerPhysics.Common.Vertices(curve.Points.Select(p => new Microsoft.Xna.Framework.Vector2((float)p.x, (float)p.y)).ToArray());
            //var triangles = FarseerPhysics.Common.Decomposition.EarclipDecomposer.TriangulatePolygon(vertices);

            //var vertices = new TongJi.Geometry.Computational.Vertices(curve.Points.Select(p => new TongJi.Geometry.Computational.Vector2((float)p.x, (float)p.y)));
            //var decomp = new TongJi.Geometry.Computational.Decompose();
            //var triangles = decomp.Run(vertices);

            //int index0 = 0;

            //var points = curve.Points.Select(p => new Point3D((float)p.x, (float)p.y, 0)).ToList();
            //int pointCount = curve.Count;

            MeshBuilder mb = new MeshBuilder();

            //points.ForEach(p => mb.Vertices.Add(p));

            //Vector3D normal = Vector3D.Zero;
            //if (pointCount > 2)
            //{
            //    normal = (points[1] - points[0]).Cross(points[2] - points[0]).Normalize();
            //}
            //points.ForEach(p => mb.Normals.Add(normal));

            //mb.MakePlanarFaces(index0, pointCount);

            foreach (var tri in triangles)
            {
                var a = tri.A.ToPoint3D();
                var b = tri.B.ToPoint3D();
                var c = tri.C.ToPoint3D();
                mb.AddTriangle(a, b, c);
                //if ((b - a).Cross(c - a).z > 0)
                //{
                //    mb.AddTriangle(a, b, c);
                //}
                //else
                //{
                //    mb.AddTriangle(a, c, b);
                //}
            }
            return(mb);
        }
        public static MeshBuilder ExtrudeSmooth(TongJi.Geometry.Polyline curve, double height)
        {
            var points0    = curve.Points.Select(p => new Point3D(p.x, p.y, 0)).ToList();
            var points1    = curve.Points.Select(p => new Point3D(p.x, p.y, height)).ToList();
            int pointCount = curve.Count;

            Point3D[,] points = new Point3D[pointCount, 2];
            Enumerable.Range(0, pointCount).ToList().ForEach(i => points[i, 0] = points0[i]);
            Enumerable.Range(0, pointCount).ToList().ForEach(i => points[i, 1] = points1[i]);

            return(MeshBuilder.RectGrid(points));
        }
        public static MeshBuilder ExtrudeWithCaps(TongJi.Geometry.Polyline curve, double height)
        {
            MeshBuilder mb          = MeshBuilder.Extrude(curve, height);
            MeshBuilder cap0        = MeshBuilder.Planar(curve); // mod 20120727
            MeshBuilder cap1        = MeshBuilder.Planar(curve);
            Matrix4     translation = Matrix4.Translation(0, 0, height);

            cap1.Transform(translation);

            mb.Append(cap0);
            mb.Append(cap1);

            return(mb);
        }
        public static MeshBuilder Extrude(TongJi.Geometry.Polyline curve, double height)
        {
            var points0    = curve.Points.Select(p => new Point3D(p.x, p.y, 0)).ToList();
            var points1    = curve.Points.Select(p => new Point3D(p.x, p.y, height)).ToList();
            int pointCount = curve.Count;

            MeshBuilder mb = new MeshBuilder();

            for (int i = 0; i < pointCount - 1; i++)
            {
                mb.AddQuad(points0[i], points1[i], points1[i + 1], points0[i + 1]);
            }
            return(mb);
        }
Exemple #7
0
        public static MeshBuilder ExtrudeWithCaps(TongJi.Geometry.Polyline curve, double height)
        {
            MeshBuilder mb   = MeshBuilder.Extrude(curve, height);
            MeshBuilder cap0 = MeshBuilder.Planar(curve);
            MeshBuilder cap1 = MeshBuilder.Planar(curve);

            if (cap0 != null)
            {
                cap0.FlipFaces();
                cap1.Transform(Matrix4.Translation(0, 0, height));
                mb.Append(cap0);
                mb.Append(cap1);
            }
            return(mb);
        }