示例#1
0
        //TODO: host railings, where possible
        private RevitRailing RailingToSpeckle(Railing revitRailing)
        {
            var railingType    = Doc.GetElement(revitRailing.GetTypeId()) as RailingType;
            var speckleRailing = new RevitRailing();

            //speckleRailing.family = railingType.FamilyName;
            speckleRailing.type  = railingType.Name;
            speckleRailing.level = ConvertAndCacheLevel(revitRailing, BuiltInParameter.STAIRS_RAILING_BASE_LEVEL_PARAM);
            speckleRailing.path  = CurveListToSpeckle(revitRailing.GetPath());

            GetAllRevitParamsAndIds(speckleRailing, revitRailing, new List <string> {
                "STAIRS_RAILING_BASE_LEVEL_PARAM"
            });

            var mesh = new Geometry.Mesh();

            (mesh.faces, mesh.vertices) = GetFaceVertexArrayFromElement(revitRailing, new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false
            });

            speckleRailing["@displayMesh"] = mesh;

            return(speckleRailing);
        }
示例#2
0
        public BuiltElements.Room RoomToSpeckle(DB.Room revitRoom)
        {
            var profiles = GetProfiles(revitRoom);

            var speckleRoom = new Room();

            speckleRoom.name    = revitRoom.get_Parameter(BuiltInParameter.ROOM_NAME).AsString();
            speckleRoom.number  = revitRoom.Number;
            speckleRoom.center  = (Point)LocationToSpeckle(revitRoom);
            speckleRoom.level   = ConvertAndCacheLevel(revitRoom, BuiltInParameter.ROOM_LEVEL_ID);
            speckleRoom.outline = profiles[0];
            if (profiles.Count > 1)
            {
                speckleRoom.voids = profiles.Skip(1).ToList();
            }

            GetAllRevitParamsAndIds(speckleRoom, revitRoom);

            var displayMesh = new Geometry.Mesh();

            (displayMesh.faces, displayMesh.vertices) = GetFaceVertexArrayFromElement(revitRoom);
            speckleRoom["@displayMesh"] = displayMesh;

            return(speckleRoom);
        }
        //NOTE: BuildingPad cannot be created from the API AFAIK
        private BuildingPad BuildingPadToSpeckle(DB.BuildingPad revitPad)
        {
            var profiles = GetProfiles(revitPad);

            var specklePad = new BuildingPad();

            specklePad.type    = Doc.GetElement(revitPad.GetTypeId()).Name;
            specklePad.outline = profiles[0];
            if (profiles.Count > 1)
            {
                specklePad.voids = profiles.Skip(1).ToList();
            }

            specklePad.level = ConvertAndCacheLevel(revitPad, BuiltInParameter.LEVEL_PARAM);

            GetAllRevitParamsAndIds(specklePad, revitPad, new List <string> {
                "LEVEL_PARAM"
            });

            var mesh = new Geometry.Mesh();

            (mesh.faces, mesh.vertices) = GetFaceVertexArrayFromElement(revitPad, new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false
            });

            specklePad["@displayMesh"] = mesh;

            return(specklePad);
        }
示例#4
0
        //NOTE: there is not API method to create new ceiling
        //a possible workaround is to duplicate an existing one and edit its profile

        private RevitCeiling CeilingToSpeckle(DB.Ceiling revitCeiling)
        {
            var profiles = GetProfiles(revitCeiling);

            var speckleCeiling = new RevitCeiling();

            speckleCeiling.type    = Doc.GetElement(revitCeiling.GetTypeId()).Name;
            speckleCeiling.outline = profiles[0];
            if (profiles.Count > 1)
            {
                speckleCeiling.voids = profiles.Skip(1).ToList();
            }
            speckleCeiling.offset = GetParamValue <double>(revitCeiling, BuiltInParameter.CEILING_HEIGHTABOVELEVEL_PARAM);
            speckleCeiling.level  = ConvertAndCacheLevel(revitCeiling, BuiltInParameter.LEVEL_PARAM);

            GetAllRevitParamsAndIds(speckleCeiling, revitCeiling, new List <string> {
                "LEVEL_PARAM", "CEILING_HEIGHTABOVELEVEL_PARAM"
            });

            GetHostedElements(speckleCeiling, revitCeiling);

            var mesh = new Geometry.Mesh();

            (mesh.faces, mesh.vertices) = GetFaceVertexArrayFromElement(revitCeiling, new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false
            });

            speckleCeiling["@displayMesh"] = mesh;

            return(speckleCeiling);
        }
示例#5
0
        private RevitFloor FloorToSpeckle(DB.Floor revitFloor)
        {
            var profiles = GetProfiles(revitFloor);

            var speckleFloor = new RevitFloor();

            speckleFloor.type    = Doc.GetElement(revitFloor.GetTypeId()).Name;
            speckleFloor.outline = profiles[0];
            if (profiles.Count > 1)
            {
                speckleFloor.voids = profiles.Skip(1).ToList();
            }

            speckleFloor.level      = ConvertAndCacheLevel(revitFloor, BuiltInParameter.LEVEL_PARAM);
            speckleFloor.structural = GetParamValue <bool>(revitFloor, BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL);

            GetAllRevitParamsAndIds(speckleFloor, revitFloor, new List <string> {
                "LEVEL_PARAM", "FLOOR_PARAM_IS_STRUCTURAL"
            });

            var mesh = new Geometry.Mesh();

            (mesh.faces, mesh.vertices) = GetFaceVertexArrayFromElement(revitFloor, new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false
            });

            speckleFloor["@displayMesh"] = mesh;

            GetHostedElements(speckleFloor, revitFloor);

            return(speckleFloor);
        }
示例#6
0
        public List <ApplicationPlaceholderObject> FreeformElementToNativeFamily(Geometry.Mesh mesh)
        {
            var solids = new List <DB.Solid>();

            var revitMmesh = MeshToNative(mesh, DB.TessellatedShapeBuilderTarget.Solid)
                             .Select(m => (m as DB.Solid));

            solids.AddRange(revitMmesh);


            var applicationPlaceholders = new List <ApplicationPlaceholderObject>();

            foreach (var s in solids)
            {
                var form = DB.FreeFormElement.Create(Doc, s);
                applicationPlaceholders.Add(new ApplicationPlaceholderObject
                {
                    ApplicationGeneratedId = form.UniqueId,
                    NativeObject           = s
                });
                Report.Log($"Created FreeformElement {form.Id}");
            }

            return(applicationPlaceholders);
        }
        /// <summary>
        /// Prompt for the getting of a mesh ellipsoid.
        /// </summary>
        /// <param name="verticalFaces">The number of faces in the vertical direction.</param>
        /// <param name="aroundFaces">The number of faces in the around direction</param>
        /// <param name="ellipsoid">The ellipsoid in Mesh form.</param>
        /// <returns>The result of the getting operation.</returns>
        public Commands.Result GetMesh(ref int verticalFaces, ref int aroundFaces, out Geometry.Mesh ellipsoid)
        {
            IntPtr ptr_this = NonConstPointer();

            ellipsoid = new Geometry.Mesh();
            IntPtr ptr_ellipsoid = ellipsoid.NonConstPointer();
            uint   rc            = UnsafeNativeMethods.RHC_RhinoGetMeshEllipsoid(ptr_ellipsoid, ref verticalFaces, ref aroundFaces, ptr_this);

            return((Commands.Result)rc);
        }
示例#8
0
        /// <summary>
        /// Prompt for the getting of a mesh truncated cone.
        /// </summary>
        /// <param name="verticalFaces">The number of faces in the vertical direction.</param>
        /// <param name="aroundFaces">The number of faces in the around direction</param>
        /// <param name="capStyle">Set to 0 if you don't want the prompt, 3 is tris, 4 is quads.</param>
        ///
        /// <param name="truncatedCone">The truncated cone in Mesh form.</param>
        /// <returns>The result of the getting operation.</returns>
        /// <remarks>The prompt for capStyle will only be seen if it's not zero, aroundFaces is even
        ///          and the solid option is on.
        /// </remarks>
        public Commands.Result GetMesh(ref int verticalFaces, ref int aroundFaces, ref int capStyle, out Geometry.Mesh truncatedCone)
        {
            IntPtr ptr_this = NonConstPointer();

            truncatedCone = new Geometry.Mesh();
            IntPtr ptr_truncated_cone = truncatedCone.NonConstPointer();
            uint   rc = UnsafeNativeMethods.RHC_RhinoGetMeshTconeWithCapStyle(ptr_truncated_cone, ref verticalFaces, ref capStyle, ref aroundFaces, ptr_this);

            return((Commands.Result)rc);
        }
 /// <summary>
 /// Utility for picking mesh vertices
 /// </summary>
 /// <param name="mesh"></param>
 /// <returns>indices of mesh topology vertices that were picked</returns>
 /// <since>5.0</since>
 public int[] PickMeshTopologyVertices(Geometry.Mesh mesh)
 {
     using (var indices = new Runtime.InteropWrappers.SimpleArrayInt())
     {
         IntPtr const_ptr_this = ConstPointer();
         IntPtr const_ptr_mesh = mesh.ConstPointer();
         IntPtr ptr_indices    = indices.NonConstPointer();
         int    rc             = UnsafeNativeMethods.CRhinoPickContext_PickMeshTopologyVertices(const_ptr_this, const_ptr_mesh, ptr_indices);
         return(rc < 1 ? new int[0] : indices.ToArray());
     }
 }
示例#10
0
 /// <summary>
 /// Adds a mesh to the list.
 /// </summary>
 /// <param name="mesh">A mesh to add.</param>
 /// <param name="asConst">Whether this mesh should be treated as non-modifiable.</param>
 public void Add(Geometry.Mesh mesh, bool asConst)
 {
     if (null != mesh)
     {
         IntPtr pMesh = mesh.ConstPointer();
         if (!asConst)
         {
             pMesh = mesh.NonConstPointer();
         }
         IntPtr ptr = NonConstPointer();
         UnsafeNativeMethods.ON_MeshArray_Append(ptr, pMesh);
     }
 }
示例#11
0
        /// <summary>
        /// Constructs a Rhino_DotNet OnMesh that is a copy of a given mesh.
        /// </summary>
        /// <param name="source">A source brep.</param>
        /// <returns>
        /// Rhino_DotNet object on success. This will be an independent copy.
        /// </returns>
        /// <since>5.0</since>
        public static object ToOnMesh(Geometry.Mesh source)
        {
            object rc = null;
            IntPtr const_ptr_source = source.ConstPointer();
            Type   on_type          = GetRhinoDotNetType("RMA.OpenNURBS.OnMesh");

            if (IntPtr.Zero != const_ptr_source && null != on_type)
            {
                System.Reflection.MethodInfo mi = on_type.GetMethod("WrapNativePointer", new[] { typeof(IntPtr), typeof(bool), typeof(bool) });
                IntPtr ptr_new_mesh             = UnsafeNativeMethods.ON_Mesh_New(const_ptr_source);
                rc = mi.Invoke(null, new object[] { ptr_new_mesh, false, true });
            }
            return(rc);
        }
示例#12
0
        /// <summary>Utility for picking meshes</summary>
        /// <param name="mesh">mesh to test</param>
        /// <param name="pickStyle">mode used for pick test</param>
        /// <param name="hitPoint">location returned here for point picks</param>
        /// <param name="depth">
        /// depth returned here for point picks
        /// LARGER values are NEARER to the camera.
        /// SMALLER values are FARTHER from the camera.
        /// </param>
        /// <param name="distance">
        /// planar distance returned here for point picks.
        /// SMALLER values are CLOSER to the pick point
        /// </param>
        /// <param name="hitFlag">
        /// For point picks, How to interpret the hitIndex (vertex hit, edge hit, or face hit)
        /// </param>
        /// <param name="hitIndex">
        /// index of vertex/edge/face that was hit. Use hitFlag to determine what this index
        /// corresponds to
        /// </param>
        /// <returns></returns>
        /// <since>5.0</since>
        public bool PickFrustumTest(Geometry.Mesh mesh, MeshPickStyle pickStyle, out Geometry.Point3d hitPoint, out double depth, out double distance, out MeshHitFlag hitFlag, out int hitIndex)
        {
            hitPoint = Geometry.Point3d.Unset;
            depth    = -1;
            distance = -1;
            hitIndex = -1;
            IntPtr const_ptr_this = ConstPointer();
            IntPtr const_ptr_mesh = mesh.ConstPointer();
            int    vef_flag       = -1;
            bool   rc             = UnsafeNativeMethods.CRhinoPickContext_PickMesh2(const_ptr_this, const_ptr_mesh, (int)pickStyle, ref hitPoint, ref depth, ref distance, ref vef_flag, ref hitIndex);

            hitFlag = (MeshHitFlag)vef_flag;
            return(rc);
        }
示例#13
0
        //NOTE: we are currently only converting Stairs ToSpeckle
        //a ToNative method might come later on!
        private RevitStair StairToSpeckle(Stairs revitStair)
        {
            var stairType    = Doc.GetElement(revitStair.GetTypeId()) as StairsType;
            var speckleStair = new RevitStair();

            speckleStair.family          = stairType.FamilyName;
            speckleStair.type            = stairType.Name;
            speckleStair.level           = ConvertAndCacheLevel(revitStair, BuiltInParameter.STAIRS_BASE_LEVEL_PARAM);
            speckleStair.topLevel        = ConvertAndCacheLevel(revitStair, BuiltInParameter.STAIRS_TOP_LEVEL_PARAM);
            speckleStair.riserHeight     = ScaleToSpeckle(revitStair.ActualRiserHeight);
            speckleStair.risersNumber    = revitStair.ActualRisersNumber;
            speckleStair.treradDepth     = ScaleToSpeckle(revitStair.ActualTreadDepth);
            speckleStair.treadsNumber    = revitStair.ActualTreadsNumber;
            speckleStair.baseElevation   = ScaleToSpeckle(revitStair.BaseElevation);
            speckleStair.topElevation    = ScaleToSpeckle(revitStair.TopElevation);
            speckleStair.height          = ScaleToSpeckle(revitStair.Height);
            speckleStair.numberOfStories = revitStair.NumberOfStories;

            speckleStair.runs     = revitStair.GetStairsRuns().Select(x => StairRunToSpeckle(Doc.GetElement(x) as StairsRun)).ToList();
            speckleStair.landings = revitStair.GetStairsLandings().Select(x => StairLandingToSpeckle(Doc.GetElement(x) as StairsLanding)).ToList();
            speckleStair.supports = revitStair.GetStairsSupports().Select(x => StairSupportToSpeckle(Doc.GetElement(x))).ToList();

            GetAllRevitParamsAndIds(speckleStair, revitStair, new List <string> {
                "STAIRS_BASE_LEVEL_PARAM", "STAIRS_TOP_LEVEL_PARAM"
            });

            var mesh = new Geometry.Mesh();

            (mesh.faces, mesh.vertices) = GetFaceVertexArrayFromElement(revitStair, new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false
            });

            speckleStair["@displayMesh"] = mesh;

            return(speckleStair);
        }
示例#14
0
        static void OnUpdateVertexColorsProc(Guid am_id, IntPtr pConstRhinoObject, IntPtr pSimpleArrayConstMeshes, int meshCount)
        {
            VisualAnalysisMode mode = FindLocal(am_id);

            if (mode != null)
            {
                var rhobj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pConstRhinoObject);
                Rhino.Geometry.Mesh[] meshes = new Geometry.Mesh[meshCount];
                for (int i = 0; i < meshCount; i++)
                {
                    IntPtr pMesh = UnsafeNativeMethods.ON_MeshArray_Get(pSimpleArrayConstMeshes, i);
                    if (IntPtr.Zero != pMesh)
                    {
                        meshes[i] = new Geometry.Mesh(pMesh, null);
                        meshes[i].DoNotDestructOnDispose();
                    }
                }
                try
                {
                    mode.UpdateVertexColors(rhobj, meshes);
                }
                catch (Exception) { }
            }
        }
 static void OnUpdateVertexColorsProc(Guid am_id, IntPtr pConstRhinoObject, IntPtr pSimpleArrayConstMeshes, int meshCount)
 {
   VisualAnalysisMode mode = FindLocal(am_id);
   if (mode != null)
   {
     var rhobj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pConstRhinoObject);
     Rhino.Geometry.Mesh[] meshes = new Geometry.Mesh[meshCount];
     for( int i=0; i<meshCount; i++ )
     {
       IntPtr pMesh = UnsafeNativeMethods.ON_MeshArray_Get(pSimpleArrayConstMeshes, i);
       if (IntPtr.Zero != pMesh)
       {
         meshes[i] = new Geometry.Mesh(pMesh, null);
         meshes[i].DoNotDestructOnDispose();
       }
     }
     try
     {
       mode.UpdateVertexColors(rhobj, meshes);
     }
     catch (Exception) { }
   }
 }
示例#16
0
        /// <summary>
        /// Prompt for the getting of a mesh ellipsoid.
        /// </summary>
        /// <param name="verticalFaces">The number of faces in the vertical direction.</param>
        /// <param name="aroundFaces">The number of faces in the around direction</param>
        /// <param name="ellipsoid">The ellipsoid in Mesh form.</param>
        /// <returns>The result of the getting operation.</returns>
        /// <since>7.0</since>
        public Commands.Result GetMesh(ref int verticalFaces, ref int aroundFaces, out Geometry.Mesh ellipsoid)
        {
            bool quadCaps = false;

            return(GetMesh(ref verticalFaces, ref aroundFaces, ref quadCaps, out ellipsoid));
        }
示例#17
0
        private Roof RoofToSpeckle(DB.RoofBase revitRoof)
        {
            var profiles = GetProfiles(revitRoof);

            var speckleRoof = new RevitRoof();

            switch (revitRoof)
            {
            //assigning correct type for when going back in Revit
            case FootPrintRoof footPrintRoof:
            {
                var speckleFootprintRoof = new RevitFootprintRoof
                {
                    level       = ConvertAndCacheLevel(footPrintRoof, BuiltInParameter.ROOF_BASE_LEVEL_PARAM),
                    cutOffLevel = ConvertAndCacheLevel(footPrintRoof, BuiltInParameter.ROOF_UPTO_LEVEL_PARAM),
                    slope       = GetParamValue <double?>(footPrintRoof, BuiltInParameter.ROOF_SLOPE) //NOTE: can be null if the sides have different slopes
                };

                speckleRoof = speckleFootprintRoof;
                break;
            }

            case ExtrusionRoof revitExtrusionRoof:
            {
                var speckleExtrusionRoof = new RevitExtrusionRoof
                {
                    start = GetParamValue <double>(revitExtrusionRoof, BuiltInParameter.EXTRUSION_START_PARAM),

                    end = GetParamValue <double>(revitExtrusionRoof, BuiltInParameter.EXTRUSION_END_PARAM)
                };
                var plane = revitExtrusionRoof.GetProfile().get_Item(0).SketchPlane.GetPlane();
                speckleExtrusionRoof.referenceLine =
                    new Line(PointToSpeckle(plane.Origin.Add(plane.XVec.Normalize().Negate())), PointToSpeckle(plane.Origin), ModelUnits); //TODO: test!
                speckleExtrusionRoof.level = ConvertAndCacheLevel(revitExtrusionRoof, BuiltInParameter.ROOF_CONSTRAINT_LEVEL_PARAM);
                speckleRoof = speckleExtrusionRoof;
                break;
            }
            }

            speckleRoof.type = Doc.GetElement(revitRoof.GetTypeId()).Name;

            // TODO handle case if not one of our supported roofs
            if (profiles.Any())
            {
                speckleRoof.outline = profiles[0];
                if (profiles.Count > 1)
                {
                    speckleRoof.voids = profiles.Skip(1).ToList();
                }
            }

            GetAllRevitParamsAndIds(speckleRoof, revitRoof,
                                    new List <string> {
                "ROOF_CONSTRAINT_LEVEL_PARAM", "ROOF_BASE_LEVEL_PARAM", "ROOF_UPTO_LEVEL_PARAM", "EXTRUSION_START_PARAM", "EXTRUSION_END_PARAM"
            });

            var displayMesh = new Geometry.Mesh();

            (displayMesh.faces, displayMesh.vertices) = GetFaceVertexArrayFromElement(revitRoof, new Options()
            {
                DetailLevel = ViewDetailLevel.Fine, ComputeReferences = false
            });
            speckleRoof["@displayMesh"] = displayMesh;

            GetHostedElements(speckleRoof, revitRoof);

            return(speckleRoof);
        }