Exemple #1
0
        public static void StitchPolygons3D(MeshIndexed mesh, List <CadCommon.Polygon> PolyList)
        {
            // add first
            CadCommon.Polygon poly3d;

            //poly3d = PolyList[0];
            //result.AddPolygon (poly3d);

            // join
            for (int j = 0; j < PolyList.Count - 1; j++)
            {
                CadCommon.Polygon poly0 = PolyList[j];
                CadCommon.Polygon poly1 = PolyList[j + 1];

                // --
                for (int k = 0; k < poly0.vertices.Length; k++)
                {
                    int kp1 = (k + 1) % poly0.vertices.Length;

                    TriangleExt triangle = new TriangleExt(poly1.vertices[kp1].Position, poly0.vertices[kp1].Position, poly0.vertices[k].Position);
                    mesh.AddTriangle(triangle);

                    triangle = new TriangleExt(poly0.vertices[k].Position, poly1.vertices[k].Position, poly1.vertices[kp1].Position);
                    mesh.AddTriangle(triangle);
                }
            }

            // add last
            //poly3d = PolyList[PolyList.Count - 1];
            //result.AddPolygon(poly3d);
        }
Exemple #2
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);
        }
Exemple #3
0
        // cuboid with hole
        //
        //      _   _
        //     | \ / |
        //     | | | |
        //     | |_| |
        //     |_____|
        //
        public static MeshIndexed MakeBucket(float x, float y, float z)
        {
            MeshIndexed result = new MeshIndexed();

            float hole  = 1f;
            float bevel = 0.3f;

            List <CadCommon.Polygon> PolyList = new List <CadCommon.Polygon>();

            CadCommon.Polygon poly0 = new CadCommon.Polygon(new List <Point3DF> {
                new Point3DF(0, 0, 0),
                new Point3DF(0, y, 0),
                new Point3DF(x, y, 0),
                new Point3DF(x, 0, 0)
            });

            //PolyList.Add ();
            CadCommon.Polygon poly1 = new CadCommon.Polygon(new List <Point3DF> {
                new Point3DF(0, 0, z),
                new Point3DF(0, y, z),
                new Point3DF(x, y, z),
                new Point3DF(x, 0, z)
            });

            float d1 = x / 2 - hole / 2 - bevel;

            CadCommon.Polygon poly2 = new CadCommon.Polygon(new List <Point3DF> {
                new Point3DF(d1, d1, z),
                new Point3DF(d1, y - d1, z),
                new Point3DF(x - d1, y - d1, z),
                new Point3DF(x - d1, d1, z)
            });

            d1 = x / 2 - hole / 2;

            CadCommon.Polygon poly3 = new CadCommon.Polygon(new List <Point3DF> {
                new Point3DF(d1, d1, z - bevel),
                new Point3DF(d1, y - d1, z - bevel),
                new Point3DF(x - d1, y - d1, z - bevel),
                new Point3DF(x - d1, d1, z - bevel)
            });

            float z1 = 2;

            CadCommon.Polygon poly4 = new CadCommon.Polygon(new List <Point3DF> {
                new Point3DF(d1, d1, z1),
                new Point3DF(d1, y - d1, z1),
                new Point3DF(x - d1, y - d1, z1),
                new Point3DF(x - d1, d1, z1)
            });

            // base
            result.AddPolygon(poly0);

            // sides
            Functions3D.StitchPolygons3D(result, new List <CadCommon.Polygon> {
                poly0, poly1, poly2, poly3, poly4
            });

            result.Translate(-x / 2, -y / 2, 0);

            return(result);
        }