Esempio n. 1
0
        public void AddMesh(MeshIndexed sourceMesh, Color color)
        {
            int vertIndex = Vertices.Count;

            foreach (Vector3Ext point in sourceMesh.Vertices)
            {
                //
                Vector3Ext vector = new Vector3Ext(point.Position);

                vector.Position = Mult(ref rotationMatrix, point.Position);
                Vertices.Add(vector);
            }

            foreach (GlPolyIndex poly in sourceMesh.Polygons)
            {
                GlPolyIndex polyIndex = new GlPolyIndex();

                polyIndex.PointIndex = new int[poly.VertexCount];
                for (int j = 0; j < poly.VertexCount; j++)
                {
                    polyIndex.PointIndex[j] = vertIndex + poly.PointIndex[j];
                }

                if (poly.Attributes.HasColor)
                {
                    polyIndex.Attributes.Color = poly.Attributes.Color;
                }
                else
                {
                    polyIndex.Attributes.Color = color;
                }

                Polygons.Add(polyIndex);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        // 3d shapes

        public static MeshIndexed MakeCube(float x, float y, float z, Color color)
        {
            MeshIndexed result = new MeshIndexed();

            Point3DF[] points = new Point3DF[8];

            // create vertexes
            points[0] = new Point3DF(0, 0, 0);
            points[1] = new Point3DF(0, y, 0);
            points[2] = new Point3DF(x, y, 0);
            points[3] = new Point3DF(x, 0, 0);

            points[4] = new Point3DF(0, 0, z);
            points[5] = new Point3DF(0, y, z);
            points[6] = new Point3DF(x, y, z);
            points[7] = new Point3DF(x, 0, z);

            foreach (Point3DF point in points)
            {
                result.Vertices.Add(new Vector3Ext(point));
            }

            // base
            result.AddFacet(new Facet(points[0], points[3], points[2]), color);
            result.AddFacet(new Facet(points[2], points[1], points[0]), color);

            // sides
            result.AddFacet(new Facet(points[0], points[4], points[3]), color);
            result.AddFacet(new Facet(points[3], points[4], points[7]), color);

            result.AddFacet(new Facet(points[0], points[1], points[5]), color);
            result.AddFacet(new Facet(points[5], points[4], points[0]), color);

            result.AddFacet(new Facet(points[2], points[6], points[5]), color);
            result.AddFacet(new Facet(points[5], points[1], points[2]), color);

            result.AddFacet(new Facet(points[7], points[6], points[2]), color);
            result.AddFacet(new Facet(points[2], points[3], points[7]), color);

            // top
            result.AddFacet(new Facet(points[4], points[5], points[6]), color);
            result.AddFacet(new Facet(points[6], points[7], points[4]), color);

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

            return(result);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }