Beispiel #1
0
        public Path3DNode(Cad2D.Polygon poly2d, Vector3 position, Vector3 direction, Vector2 scale)
        {
            Polygons = new List <Cad2D.Polygon>();

            this.Polygons.Add(poly2d);
            this.Position  = position;
            this.Direction = direction;
            this.Scale     = scale;
        }
Beispiel #2
0
        public Path3DNode(Cad2D.Polygon poly2d, Vector3 position)
        {
            Polygons = new List <Cad2D.Polygon>();

            this.Polygons.Add(poly2d);
            this.Position  = position;
            this.Direction = new Vector3(0, 0, 0);
            this.Scale     = new Vector2(1, 1);
        }
Beispiel #3
0
        public fp_polygon(Cad2D.Polygon poly, string layer, float width)
        {
            this.layer = layer;
            this.width = width;

            Polygon = new List <PointF>();
            for (int j = 0; j < poly.Vertices.Count; j++)
            {
                Polygon.Add(poly.GetPoint(j));
            }
        }
Beispiel #4
0
        public Polygon(Cad2D.Polygon polygon, float z)
        {
            this.Attributes = new Attributes();
            this.vertices   = new Vector3Ext[polygon.Vertices.Count];

            for (int index = 0; index < polygon.Vertices.Count; index++)
            {
                Vector2 vector = polygon.Vertices[index];
                this.vertices[index] = new Vector3Ext(vector.X, vector.Y, z);
            }
        }
Beispiel #5
0
        public void AddBorderPolygon(Cad2D.Polygon Polygon, string Layer, float Width)
        {
            //PointF last_pos;

            for (int j = 0; j < Polygon.Vertices.Count; j++) //? -1
            {
                PointF p0  = new PointF(Polygon.Vertices[j].X, Polygon.Vertices[j].Y);
                int    jp1 = (j + 1) % Polygon.Vertices.Count;
                PointF p1  = new PointF(Polygon.Vertices[jp1].X, Polygon.Vertices[jp1].Y);

                Borders.Add(new fp_line(p0, p1, Layer, Width));
            }
        }
Beispiel #6
0
        public void AddBorderBox(string Layer, RectangleF box, float Width)
        {
            Cad2D.Polygon poly = new Cad2D.Polygon();

            poly.Vertices.Add(new Vector2(box.Left, box.Top));
            poly.Vertices.Add(new Vector2(box.Right, box.Top));
            poly.Vertices.Add(new Vector2(box.Right, box.Bottom));
            poly.Vertices.Add(new Vector2(box.Left, box.Bottom));

            //poly.Translate(new Vector2(-x / 2, -y / 2));

            AddBorderPolygon(poly, Layer, Width);
        }
Beispiel #7
0
        public static void Bend(float angle, float radius, Cad2D.Polygon poly2d, List <Path3DNode> Nodes)
        {
            float c = (float)(Math.PI * 2 * radius);

            c = c * Math.Abs(angle) / 360;

            //float ang = 0;
            for (int step = 0; step < 9; step++)
            //for (float ang = 0; ang < angle; ang += 10)
            {
                //poly2d = Square(diam);
                Nodes.Add(new Path3DNode(poly2d, new Vector3(0, 0, c / (Math.Abs(angle) / 10)), new Vector3(angle / 9, 0, 0)));
            }
        }
Beispiel #8
0
        public static MeshIndexed StitchPolygons2D(List <Path3DNode> NodeList)
        {
            MeshIndexed result = new MeshIndexed();
            Path3DNode  Current;

            int index = 0;

            Current = new Path3DNode(null, new Vector3(0, 0, 0), new Vector3(0, 0, 0));

            CadCommon.Polygon poly0 = null;
            CadCommon.Polygon poly1 = null;

            for (index = 0; index < NodeList.Count; index++)
            {
                Path3DNode CurNode = NodeList[index];

                // update current
                Matrix4 rot = Matrix4.CreateRotationX(MathUtil.DegToRad(Current.Direction.X));

                //Quaternion q = Quaternion.FromAxisAngle(Vector3.UnitZ, Current.Direction.X);

                Vector3 vec = Vector3.Transform(CurNode.Position, rot);

                Current.Position.Add(vec);

                Current.Direction.Add(CurNode.Direction);

                // triangulate first and last
                if ((index == 0) || (index == NodeList.Count - 1))
                {
                    //Cad2D.Polygon poly = CurNode.Poly2d;
                    //poly.Triangulate();

                    Cad2D.Polygon poly = PolygonTesselator.Tesselate(CurNode.Polygons);

                    foreach (Cad2D.Triangle triangle in poly.Triangles)
                    {
                        TriangleExt tri3d = new TriangleExt(
                            new Vector3(triangle.A.X, triangle.A.Y, 0),
                            new Vector3(triangle.B.X, triangle.B.Y, 0),
                            new Vector3(triangle.C.X, triangle.C.Y, 0)
                            );

                        if (index == 0)
                        {
                            tri3d.ReverseOrder();
                        }

                        tri3d.RotateX(Current.Direction.X);
                        tri3d.RotateX(Current.Direction.Y);

                        tri3d.Translate(Current.Position);

                        result.AddTriangle(tri3d);
                    }
                }


                poly1 = new CadCommon.Polygon(CurNode.Poly2d);

                poly1.RotateX(Current.Direction.X);
                poly1.RotateX(Current.Direction.Y);
                poly1.Translate(Current.Position);

                // intermediates
                if (index > 0)
                {
                    //
                    for (int k = 0; k < poly0.vertices.Length; k++)
                    {
                        int kp1 = (k + 1) % poly0.vertices.Length;

                        TriangleExt triangle = new TriangleExt(
                            new Vector3(poly1.vertices[kp1].Position.X, poly1.vertices[kp1].Position.Y, poly1.vertices[kp1].Position.Z),
                            new Vector3(poly0.vertices[kp1].Position.X, poly0.vertices[kp1].Position.Y, poly0.vertices[kp1].Position.Z),
                            new Vector3(poly0.vertices[k].Position.X, poly0.vertices[k].Position.Y, poly0.vertices[k].Position.Z)
                            );
                        result.AddTriangle(triangle);

                        triangle = new TriangleExt(
                            new Vector3(poly0.vertices[k].Position.X, poly0.vertices[k].Position.Y, poly0.vertices[k].Position.Z),
                            new Vector3(poly1.vertices[k].Position.X, poly1.vertices[k].Position.Y, poly1.vertices[k].Position.Z),
                            new Vector3(poly1.vertices[kp1].Position.X, poly1.vertices[kp1].Position.Y, poly1.vertices[kp1].Position.Z)
                            );
                        result.AddTriangle(triangle);
                    }
                }

                poly0 = poly1;
            }

            return(result);
        }