Пример #1
0
        public static Mesh ToRhino(DB.Mesh mesh)
        {
            if (mesh.NumTriangles < 1)
            {
                return(null);
            }

            var result = new Mesh();

            result.Vertices.AddVertices(mesh.Vertices.Select(x => ToRhino(x)));

            for (int t = 0; t < mesh.NumTriangles; ++t)
            {
                var triangle = mesh.get_Triangle(t);

                var meshFace = new MeshFace
                               (
                    (int)triangle.get_Index(0),
                    (int)triangle.get_Index(1),
                    (int)triangle.get_Index(2)
                               );

                result.Faces.AddFace(meshFace);
            }

            return(result);
        }
Пример #2
0
        public static Mesh ToRhino(DB.Mesh mesh)
        {
            if (mesh is null)
            {
                return(null);
            }

            var result = new Mesh();

            result.Vertices.Capacity = mesh.Vertices.Count;
            result.Vertices.AddVertices(mesh.Vertices.Convert(AsPoint3d));

            var faceCount = mesh.NumTriangles;

            result.Faces.Capacity = faceCount;

            for (int t = 0; t < faceCount; ++t)
            {
                var triangle = mesh.get_Triangle(t);

                result.Faces.AddFace
                (
                    (int)triangle.get_Index(0),
                    (int)triangle.get_Index(1),
                    (int)triangle.get_Index(2)
                );
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Replaces <see cref="Raw.RawDecoder.ToRhino(DB.Mesh)"/> to unweld vertices and recreate Ngons
        /// </summary>
        /// <param name="mesh"></param>
        /// <returns></returns>
        internal static Mesh ToRhino(DB.Mesh mesh)
        {
            var result = Raw.RawDecoder.ToRhino(mesh);

            result.Ngons.AddPlanarNgons(Revit.VertexTolerance, 4, 2, true);

            return(result);
        }
Пример #4
0
        // must return an array to make mesh double sided
        public static Mesh3D[] RevitMeshToHelixMesh(Autodesk.Revit.DB.Mesh rmesh)
        {
            List <int>     indices_front = new List <int>();
            List <int>     indices_back  = new List <int>();
            List <Point3D> vertices      = new List <Point3D>();

            for (int i = 0; i < rmesh.NumTriangles; ++i)
            {
                MeshTriangle tri = rmesh.get_Triangle(i);

                for (int k = 0; k < 3; ++k)
                {
                    Point3D new_point = RevitPointToWindowsPoint(tri.get_Vertex(k));

                    bool new_point_exists = false;
                    for (int l = 0; l < vertices.Count; ++l)
                    {
                        Point3D p = vertices[l];
                        if ((p.X == new_point.X) && (p.Y == new_point.Y) && (p.Z == new_point.Z))
                        {
                            indices_front.Add(l);
                            new_point_exists = true;
                            break;
                        }
                    }

                    if (new_point_exists)
                    {
                        continue;
                    }

                    indices_front.Add(vertices.Count);
                    vertices.Add(new_point);
                }

                int a = indices_front[indices_front.Count - 3];
                int b = indices_front[indices_front.Count - 2];
                int c = indices_front[indices_front.Count - 1];

                indices_back.Add(c);
                indices_back.Add(b);
                indices_back.Add(a);
            }

            List <Mesh3D> meshes = new List <Mesh3D>();

            meshes.Add(new Mesh3D(vertices, indices_front));
            meshes.Add(new Mesh3D(vertices, indices_back));

            return(meshes.ToArray());
        }
        /// <summary>
        /// Draws a mesh in Dynamo representing an analysis surface.  Useful when trying to identify a surface to modify.
        /// </summary>
        /// <param name="SurfaceId">The ElementId of the surface to draw.  Get this from AnalysisZones > CreateFrom* > SurfaceIds output list</param>
        /// <returns></returns>
        public static Autodesk.DesignScript.Geometry.Mesh DrawAnalysisSurface(ElementId SurfaceId)
        {
            //local varaibles
            Document        RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document;
            MassSurfaceData surf   = null;

            Autodesk.Revit.DB.ElementId myEnergyModelId = null;

            //try to get the MassSurfaceData object from the document
            try
            {
                surf = (MassSurfaceData)RvtDoc.GetElement(new Autodesk.Revit.DB.ElementId(SurfaceId.InternalId));
                if (surf == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a MassSurfaceData object with Id #: " + SurfaceId.ToString());
            }

            //try to get the element id of the MassEnergyAnalyticalModel - we need this to pull faces from
            try
            {
                myEnergyModelId = surf.ReferenceElementId;
                if (myEnergyModelId == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                throw new Exception("Couldn't find a MassEnergyAnalyticalModel object belonging to the Mass instance with Id #: " + surf.ReferenceElementId.ToString());
            }


            //get the smallest face
            Autodesk.Revit.DB.Face smallFace = GetSmallestFace(RvtDoc, surf, myEnergyModelId);

            Autodesk.Revit.DB.Mesh prettyMesh = smallFace.Triangulate();
            return(Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(prettyMesh));
        }
Пример #6
0
        static Rhino.Geometry.Mesh ToRhino(this Autodesk.Revit.DB.Mesh mesh)
        {
            var result = new Rhino.Geometry.Mesh();

            result.Vertices.AddVertices(mesh.Vertices.ToRhino());

            for (int t = 0; t < mesh.NumTriangles; ++t)
            {
                var triangle = mesh.get_Triangle(t);

                var meshFace = new MeshFace
                               (
                    (int)triangle.get_Index(0),
                    (int)triangle.get_Index(1),
                    (int)triangle.get_Index(2)
                               );

                result.Faces.AddFace(meshFace);
            }

            return(result);
        }
Пример #7
0
 private static Autodesk.DesignScript.Geometry.Mesh InternalConvert(Autodesk.Revit.DB.Mesh geom)
 {
     return(geom.ToProtoType());
 }
Пример #8
0
 public static Mesh ToMesh(this DB.Mesh value) =>
 MeshDecoder.FromRawMesh(MeshDecoder.ToRhino(value), UnitConverter.ToRhinoUnits);
Пример #9
0
 internal static Mesh ToRhino(DB.Mesh mesh)
 {
     return(Raw.RawDecoder.ToRhino(mesh));
 }
 public static Mesh ToMesh(this DB.Mesh value)
 {
     var rhino = MeshDecoder.ToRhino(value); UnitConverter.Scale(rhino, UnitConverter.ToRhinoUnits); return(rhino);
 }
Пример #11
0
 public static Mesh ToRhino(this DB.Mesh mesh) => RawDecoder.ToRhino(mesh);
Пример #12
0
        private static Autodesk.DesignScript.Geometry.Mesh SolidToMesh(Autodesk.Revit.DB.Solid solid)
        {
            Autodesk.DesignScript.Geometry.Mesh mesh = null;

            List <Autodesk.DesignScript.Geometry.Mesh> unjoinedMeshes = new List <Autodesk.DesignScript.Geometry.Mesh>();

            foreach (Autodesk.Revit.DB.Face f in solid.Faces)
            {
                Autodesk.Revit.DB.Mesh rMesh = f.Triangulate();
                Autodesk.DesignScript.Geometry.Mesh dMesh = RevitToProtoMesh.ToProtoType(rMesh, true);
                unjoinedMeshes.Add(dMesh);
            }

            // Join meshes
            if (unjoinedMeshes.Count == 0)
            {
                mesh = unjoinedMeshes[0];
            }
            else
            {
                // Join all of the meshes?
                List <Autodesk.DesignScript.Geometry.Point>      vertices    = new List <Autodesk.DesignScript.Geometry.Point>();
                List <Autodesk.DesignScript.Geometry.IndexGroup> indexGroups = new List <Autodesk.DesignScript.Geometry.IndexGroup>();

                foreach (Autodesk.DesignScript.Geometry.Mesh m in unjoinedMeshes)
                {
                    if (m == null)
                    {
                        continue;
                    }
                    int baseCount = vertices.Count;
                    foreach (Autodesk.DesignScript.Geometry.Point pt in m.VertexPositions)
                    {
                        vertices.Add(pt);
                    }
                    foreach (Autodesk.DesignScript.Geometry.IndexGroup ig in m.FaceIndices)
                    {
                        if (ig.Count == 3)
                        {
                            Autodesk.DesignScript.Geometry.IndexGroup iGroup = Autodesk.DesignScript.Geometry.IndexGroup.ByIndices((uint)(ig.A + baseCount), (uint)(ig.B + baseCount), (uint)(ig.C + baseCount));
                            indexGroups.Add(iGroup);
                        }
                        else
                        {
                            Autodesk.DesignScript.Geometry.IndexGroup iGroup = Autodesk.DesignScript.Geometry.IndexGroup.ByIndices((uint)(ig.A + baseCount), (uint)(ig.B + baseCount), (uint)(ig.C + baseCount), (uint)(ig.D + baseCount));
                            indexGroups.Add(iGroup);
                        }
                    }
                }
                try
                {
                    Autodesk.DesignScript.Geometry.Mesh joinedMesh = Autodesk.DesignScript.Geometry.Mesh.ByPointsFaceIndices(vertices, indexGroups);
                    if (joinedMesh != null)
                    {
                        mesh = joinedMesh;
                        simpleMeshes.Add(joinedMesh);
                    }
                }
                catch
                {
                    // For now just add them all as is
                }
            }

            return(mesh);
        }