Example #1
0
        internal Dyn.Mesh ToDynamoMesh(sMesh sm, out List <Color> vcols)
        {
            List <Dyn.Point>      pts    = new List <Autodesk.DesignScript.Geometry.Point>();
            List <Dyn.IndexGroup> indice = new List <Autodesk.DesignScript.Geometry.IndexGroup>();
            List <Color>          cols   = new List <Color>();

            for (int i = 0; i < sm.vertices.Count; ++i)
            {
                pts.Add(ToDynamoPoint(sm.vertices[i].location));
                if (sm.vertices[i].color != null)
                {
                    cols.Add(sm.vertices[i].color.ToWinColor());
                }
            }

            for (int i = 0; i < sm.faces.Count; ++i)
            {
                Dyn.IndexGroup faceIDs = Dyn.IndexGroup.ByIndices((uint)sm.faces[i].A, (uint)sm.faces[i].B, (uint)sm.faces[i].C);
                indice.Add(faceIDs);
            }

            vcols = cols;

            return(Dyn.Mesh.ByPointsFaceIndices(pts, indice));
        }
        public static Dictionary <string, object> Draw(hMember member)
        {
            Geo.Point OP1 = member._webAxis.StartPoint;
            Geo.Point OP2 = member._webAxis.EndPoint;

            Geo.Vector webAxis = Geo.Vector.ByTwoPoints(OP1, OP2);
            Geo.Vector normal  = member._webNormal;
            Geo.Vector lateral = webAxis.Cross(normal);
            lateral = lateral.Normalized();
            lateral = lateral.Scale(1.75);
            normal  = normal.Normalized();
            normal  = normal.Scale(1.5);
            Geo.Vector lateralR = Geo.Vector.ByCoordinates(lateral.X * -1, lateral.Y * -1, lateral.Z * -1);

            Geo.Point p0 = OP1.Add(normal.Add(lateral));
            Geo.Point p1 = OP2.Add(normal.Add(lateral));
            Geo.Point p2 = OP1.Add(lateral);
            Geo.Point p3 = OP2.Add(lateral);
            Geo.Point p6 = OP1.Add(normal.Add(lateralR));
            Geo.Point p7 = OP2.Add(normal.Add(lateralR));
            Geo.Point p4 = OP1.Add(lateralR);
            Geo.Point p5 = OP2.Add(lateralR);

            Geo.Point[] pts = { p0, p1, p2, p1, p2, p3, p2, p3, p4, p3, p4, p5, p4, p5, p6, p5, p6, p7 };

            Geo.IndexGroup g0 = Geo.IndexGroup.ByIndices(0, 1, 2);
            Geo.IndexGroup g1 = Geo.IndexGroup.ByIndices(3, 4, 5);
            Geo.IndexGroup g2 = Geo.IndexGroup.ByIndices(6, 7, 8);
            Geo.IndexGroup g3 = Geo.IndexGroup.ByIndices(9, 10, 11);
            Geo.IndexGroup g4 = Geo.IndexGroup.ByIndices(12, 13, 14);
            Geo.IndexGroup g5 = Geo.IndexGroup.ByIndices(15, 16, 17);

            Geo.IndexGroup[] ig = { g0, g1, g2, g3, g4, g5 };

            Geo.Mesh mesh = Geo.Mesh.ByPointsFaceIndices(pts, ig);

            var points = new List <Geo.Point>();

            foreach (hOperation op in member.operations)
            {
                points.Add(member._webAxis.PointAtParameter(op._loc / member._webAxis.Length));
            }

            return(new Dictionary <string, object>
            {
                { "member", mesh },
                { "operations", points }
            });
        }
Example #3
0
        /// <summary>
        /// This is another private method, so Dynamo won't show it when it loads the library as a Zero Touch plugin.
        /// This method takes an Autodesk.Revit.DB.Solid from the Revit element and tessellates it to get an
        /// Autodesk.Revit.DB.Mesh from it. This mesh is then converted using the Revit.GeometryConversion referance
        /// to go from the Autodesk.Revit.DB.Mesh to an Autodesk.DesignScript.Geometry.Mesh.
        /// </summary>
        /// <param name="solid">Autodesk.Revit.DB.Solid geometry object to mesh.</param>
        /// <returns>An Autodesk.DesignScript.Geometry.Mesh from the solid.</returns>
        private static dsGeo.Mesh SolidToMesh(Solid solid)
        {
            dsGeo.Mesh mesh = null;

            // Each face of a solid is tessellated separately into a unique mesh, so we first
            // Collect all of the meshes that represent a solid's face.
            List <dsGeo.Mesh> unjoinedMeshes = new List <dsGeo.Mesh>();

            foreach (Face f in solid.Faces)
            {
                // call the Triangulate method for the Autodesk.Revit.DB.Face
                Mesh rMesh = f.Triangulate();

                // Use Revit.GeometryConversion.RevitToProtoMesh.ToProtoType method to convert the
                // Autodesk.Revit.DB.Mesh to an Autodesk.DesignScript.Geometry.Mesh
                dsGeo.Mesh dMesh = RevitToProtoMesh.ToProtoType(rMesh, true);

                unjoinedMeshes.Add(dMesh);
            }

            // Join meshes
            if (unjoinedMeshes.Count == 1)
            {
                mesh = unjoinedMeshes[0];
            }
            else
            {
                // Join all of the meshes into a single mesh representing the input solid.
                List <dsGeo.Point>      vertices    = new List <dsGeo.Point>();
                List <dsGeo.IndexGroup> indexGroups = new List <dsGeo.IndexGroup>();

                foreach (dsGeo.Mesh m in unjoinedMeshes)
                {
                    if (m == null)
                    {
                        continue;
                    }
                    // A count of the verticies that exist at the start of adding the current mesh.
                    // This is the base index for specifying the vertex index for each mesh face.
                    int baseCount = vertices.Count;

                    // Then add the vertices of this current mesh to the list.
                    vertices.AddRange(m.VertexPositions);

                    // Build the Mesh Faces (Autodesk.DesignScript.Geometry.IndexGroup) for this mesh and add it to
                    // the list of Autodesk.DesignScript.Geometry.IndexGroups.
                    foreach (dsGeo.IndexGroup ig in m.FaceIndices)
                    {
                        // Three vertices for the face
                        if (ig.Count == 3)
                        {
                            // The current meshes vertex indices starts at 0, but the new one will start at baseCount.
                            dsGeo.IndexGroup iGroup = dsGeo.IndexGroup.ByIndices((uint)(ig.A + baseCount), (uint)(ig.B + baseCount), (uint)(ig.C + baseCount));
                            indexGroups.Add(iGroup);
                        }
                        // Four vertices for the face.
                        else
                        {
                            // The current meshes vertex indices starts at 0, but the new one will start at baseCount.
                            dsGeo.IndexGroup iGroup = dsGeo.IndexGroup.ByIndices((uint)(ig.A + baseCount), (uint)(ig.B + baseCount), (uint)(ig.C + baseCount), (uint)(ig.D + baseCount));
                            indexGroups.Add(iGroup);
                        }
                    }
                }

                // Create a new Autodesk.DesignScript.Geometry.Mesh based on the new list of Vertices and IndexGroups (mesh faces)
                dsGeo.Mesh joinedMesh = dsGeo.Mesh.ByPointsFaceIndices(vertices, indexGroups);
                if (joinedMesh != null)
                {
                    mesh = joinedMesh;
                }
            }

            return(mesh);
        }