コード例 #1
0
        //This is used in subselection, in which need to replace entire geometry after property changes
        public static FaceEntity TryGetFrom(ObjRef roomHostObjRef, ComponentIndex componentIndex)
        {
            var roomHostObject = roomHostObjRef.Brep();
            var rc             = new FaceEntity();

            if (roomHostObject == null)
            {
                return(rc);
            }
            if (componentIndex.ComponentIndexType != ComponentIndexType.BrepFace)
            {
                return(rc);
            }

            var face = roomHostObject.Faces[componentIndex.Index];
            var ent  = face.TryGetFaceEntity();

            if (!ent.IsValid)
            {
                return(rc);
            }

            //updates hostObjRef to its room's host
            ent.RoomHostObjRef = roomHostObjRef;
            ent.ComponentIndex = componentIndex;
            return(ent);
        }
コード例 #2
0
ファイル: CreateNetCommand.cs プロジェクト: jhaazpr/rocky
        private ObjRef shrinkBoxObj(ObjRef boxObjRef, double preShrinkValue)
        {
            Brep        brep        = boxObjRef.Brep();
            BoundingBox boundingBox = brep.GetBoundingBox(accurate: false);
            Point3d     bboxCenter  = boundingBox.Center;


            Transform scale = Transform.Scale(bboxCenter, preShrinkValue);

            brep.Transform(scale);
            return(boxObjRef);
        }
コード例 #3
0
ファイル: UserInput.cs プロジェクト: jmorrison150/RhinoVR
        public static void FloorOrientPosition(Point3d startPos, ref List <double> zPositions, RhinoDoc rhinoDocument)
        {
            RhinoObject[] byLayer = rhinoDocument.Objects.FindByLayer("#VR User Defined Floors");
            if (byLayer == null || byLayer.Length < 1)
            {
                return;
            }
            List <Brep> brepList1 = new List <Brep>();

            for (int index = 0; index < byLayer.Length; ++index)
            {
                ObjRef objRef = new ObjRef(byLayer[index]);
                if (objRef != null)
                {
                    Brep brep = objRef.Brep();
                    if (brep != null)
                    {
                        brepList1.Add(brep);
                    }
                }
            }
            List <Brep>    brepList2    = brepList1;
            List <Point3d> point3dList1 = new List <Point3d>();

            point3dList1.Add(startPos);
            List <Point3d> point3dList2      = point3dList1;
            Vector3d       vector3d          = new Vector3d(0.0, 0.0, -1.0);
            double         absoluteTolerance = rhinoDocument.ModelAbsoluteTolerance;

            Point3d[] breps = Intersection.ProjectPointsToBreps((IEnumerable <Brep>)brepList2, (IEnumerable <Point3d>)point3dList2, vector3d, absoluteTolerance);
            if (breps != null && breps.Length > 0)
            {
                foreach (Point3d point3d in breps)
                {
                    // ISSUE: explicit reference operation
                    double z = ((Point3d)@point3d).Z;
                    zPositions.Add(z + VR_PANEL.EyeHeight);
                }
            }
            else
            {
                // ISSUE: explicit reference operation
                zPositions.Add(((Point3d)@startPos).Z);
            }
        }
コード例 #4
0
        bool Split()
        {
            Intersection.BrepPlane(m_objref.Surface().ToBrep(), m_plane, m_tolerance, out var curves, out var pts);
            if (curves.Length == 0)
            {
                return(false);
            }

            var index = m_objref.GeometryComponentIndex.Index;

            if (index == -1)
            {
                index = 0;
            }

            m_brep = m_objref.Brep();
            var faceCount = m_brep.Faces.Count;

            m_brep = m_brep.Faces[index].Split(curves, m_tolerance);

            if (m_brep.Faces.Count != faceCount + 1) //TODO: Case m_brep.Faces.Count > faceCount + 1
            {
                return(false);
            }

            foreach (var e1 in m_brep.Faces[index].AdjacentEdges())
            {
                foreach (var e2 in m_brep.Faces[faceCount].AdjacentEdges())
                {
                    if (e1 != e2)
                    {
                        continue;
                    }

                    m_ridgepole = m_brep.Edges[e1].ComponentIndex();

                    return(true);
                }
            }

            return(false);
        }
コード例 #5
0
ファイル: CreateNetCommand.cs プロジェクト: jhaazpr/rocky
        private Curve generatePolyBottomCurve(ObjRef objRef, Point3d origin,
                                              double thickness, bool shrinkToDimensions = false)
        {
            // First get the section curve (not poly) and use built-in
            // offset, not a scale transform, to increment
            Brep     brep         = objRef.Brep();
            Vector3d zNorm        = new Vector3d(0, 0, 1);
            Plane    worldXYPlane = new Plane(ORIGIN, zNorm);

            Curve[] contours     = Brep.CreateContourCurves(brep, worldXYPlane);
            Curve   sectionCurve = contours[0];

            if (!shrinkToDimensions)
            {
                Curve[] offsetCurves = sectionCurve.Offset(worldXYPlane, thickness,
                                                           0, CurveOffsetCornerStyle.Sharp);
                if (offsetCurves.Length != 1)
                {
                    throw new Exception("Could not properly offset curve.");
                }

                sectionCurve = offsetCurves[0];
            }

            // Place our curve to have concentric alignment with a bounding box
            // anchored at the provided origin, which we first need to offset
            // from being a bottom corner to "center"
            BoundingBox boundingBox = sectionCurve.GetBoundingBox(worldXYPlane);
            double      bboxHeight  = boundingBox.Max.X - boundingBox.Min.X;
            double      bboxWidth   = boundingBox.Max.Y - boundingBox.Min.Y;

            origin += new Vector3d(bboxHeight / 2, bboxWidth / 2, 0);
            origin += new Vector3d(thickness, 0, 0);
            double    xDiff       = origin.X - boundingBox.Center.X;
            double    yDiff       = origin.Y - boundingBox.Center.Y;
            Transform translation = Transform.Translation(new Vector3d(xDiff, yDiff, 0));

            sectionCurve.Transform(translation);

            return(sectionCurve);
        }
コード例 #6
0
ファイル: CreateNetCommand.cs プロジェクト: jhaazpr/rocky
        private Polyline getSectionPolyline(ObjRef objRef)
        {
            Brep brep = objRef.Brep();

            Vector3d zNorm        = new Vector3d(0, 0, 1);
            Plane    worldXYPlane = new Plane(ORIGIN, zNorm);

            Curve[] contours     = Brep.CreateContourCurves(brep, worldXYPlane);
            Curve   sectionCurve = contours[0];

            Polyline sectionPolyline;

            double[] sectionPolylineConversionResults;
            bool     success = sectionCurve.TryGetPolyline(out sectionPolyline, out sectionPolylineConversionResults);

            if (!success)
            {
                throw new Exception("Cannot find section curve of polygon.");
            }

            return(sectionPolyline);
        }
コード例 #7
0
        //ObjRef to ObjRef
        public static Brep ToRoomBrepObj(ObjRef roomBrepObj, double maxRoofFloorAngle = 30, double tolerance = 0.0001)
        {
            //check if Null, valid, solid
            if (!CheckIfBrepObjectValid(roomBrepObj))
            {
                throw new ArgumentException("Input geometry is not a valid object to convert to honeybee room!");
            }

            //create new room
            //Create honeybee room object here.
            var closedBrep = roomBrepObj.Brep().DuplicateBrep();
            var dupBrep    = closedBrep.ToAllPlaneBrep(tolerance);
            var subFaces   = dupBrep.Faces;

            var hbFaces = subFaces.Select(_ => _.ToHBFace(maxRoofFloorAngle)).ToList();

            for (int i = 0; i < hbFaces.Count; i++)
            {
                var faceEnt = new FaceEntity(hbFaces[i]);
                var bFace   = dupBrep.Surfaces[i];
                bFace.UserData.Add(faceEnt);
            }

            var id        = roomBrepObj.ObjectId;
            var newObjRef = new ObjRef(id);
            var room      = new HoneybeeSchema.Room($"Room_{id}", hbFaces, new HoneybeeSchema.RoomPropertiesAbridged());

            room.DisplayName = $"My Room {id.ToString().Substring(0, 5)}";
            var ent = new RoomEntity(room, newObjRef);

            //Add this RoomEntity to brep's userdata at the end.
            dupBrep.UserData.Add(ent);


#if DEBUG
            if (!dupBrep.TryGetRoomEntity().IsValid)
            {
                throw new ArgumentException("Failed to convert to honeybee room!");
            }
#endif

            return(dupBrep);


            //Local method
            bool CheckIfBrepObjectValid(ObjRef roomObj)
            {
                if (roomObj == null)
                {
                    throw new NullReferenceException();
                }

                var brep = roomObj.Brep();

                if (brep == null)
                {
                    throw new NullReferenceException();
                }
                if (!brep.IsValid)
                {
                    throw new ArgumentException("Input geometry is not a valid object to convert to honeybee room!");
                }

                if (!brep.IsSolid)
                {
                    throw new ArgumentException("This rhino object is not a water-tight solid!");
                }

                brep.DeleteHBEntity(duplicate: false);

                return(true);
            }
        }
コード例 #8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            if (p.if_painted_object_set_ == false)
            {
                RhinoApp.WriteLine("No mesh");
                return(Result.Failure);
            }
            Mesh my_mesh = p.painted_object_;

            GetObject gbrep = new GetObject();

            gbrep.SetCommandPrompt("get the brep");
            gbrep.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep.SubObjectSelect = false;
            gbrep.Get();
            if (gbrep.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep.CommandResult());
            }
            ObjRef      my_objref = gbrep.Object(0);
            RhinoObject my_obj    = my_objref.Object();

            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep = my_objref.Brep();

            if (brep == null)
            {
                return(Result.Failure);
            }
            my_obj.Select(false);

            int brep_number = 0;

            for (int i = 0; i < p.my_objects_list.Count; i++)
            {
                Brep an_object = p.my_objects_list[i];
                if (My_object_functions.GetComponentID(brep) == My_object_functions.GetComponentID(an_object))
                {
                    brep_number = i;
                    break;
                }
            }

            Point3d  position         = My_object_functions.GetPosition(brep);
            Vector3d normal_direction = My_object_functions.GetZ(brep);
            Plane    plane            = new Plane(position, normal_direction);

            /*
             * GetPoint gp = new GetPoint();
             * gp.Constrain(plane, false);
             * gp.Get();
             * if (gp.CommandResult() != Result.Success)
             *  return gp.CommandResult();
             * var start_point = gp.Point();
             * if (start_point == Point3d.Unset)
             *  return Result.Failure;
             */

            Vector3d horizontal_direction = My_object_functions.GetY(brep);
            Point3d  start_point          = position + 10 * horizontal_direction;

            GetRotationAngle gr = new GetRotationAngle(brep, my_mesh, start_point);

            gr.SetCommandPrompt("Get the rotation angle");
            gr.Constrain(plane, false);
            gr.Get();
            if (gr.CommandResult() != Result.Success)
            {
                return(gr.CommandResult());
            }

            Point3d end_point = gr.Point();
            Brep    new_brep  = GetRotationAngle.RotateBrep(brep, my_mesh, end_point, start_point);

            ObjectAttributes path_attributes = new ObjectAttributes();

            path_attributes.ObjectColor      = Color.Yellow;
            path_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
            path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
            path_attributes.PlotWeight       = 2.0;

            ObjectAttributes my_attributes = new ObjectAttributes();

            my_attributes.ObjectColor = My_object_functions.GetColor(new_brep);
            my_attributes.ColorSource = ObjectColorSource.ColorFromObject;

            int new_pin_number = My_object_functions.GetPinQuantity(new_brep);
            List <NurbsCurve> new_path_list = new List <NurbsCurve>();

            for (int i = 0; i < new_pin_number; i++)
            {
                Guid      pin_id       = My_object_functions.GetPinGuid(new_brep, i);
                Point3d   pin_position = My_object_functions.GetPinPosition(new_brep, i);
                MeshPoint pin_on_mesh  = my_mesh.ClosestMeshPoint(pin_position, 0);
                new_path_list = p.graph.DijkstraPath_Change(pin_id, pin_on_mesh);
            }

            IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve);

            foreach (RhinoObject path in path_objref)
            {
                doc.Objects.Delete(path, true);
            }

            for (int i = 0; i < new_path_list.Count; i++)
            {
                Guid path_id = new_path_list[i].UserDictionary.GetGuid("PathID");
                path_attributes.ObjectId = path_id;
                doc.Objects.AddCurve(new_path_list[i], path_attributes);
            }

            doc.Objects.Delete(my_objref, true);
            doc.Objects.AddBrep(new_brep, my_attributes);
            p.my_objects_list[brep_number] = new_brep;
            doc.Views.Redraw();


            return(Result.Success);
        }
コード例 #9
0
        public static (Brep room, Guid roomId, List <(Brep brep, Guid id)> apertures) AddApertureDoor(this ObjRef roomObjRef, List <ObjRef> apertureObjRefs, bool isDoor = false)
        {
            //Only add to valid room obj
            if (!roomObjRef.IsRoom())
            {
                throw new ArgumentException("Cannot assign aperture to non-room object!");
            }


            var apertures = new List <(Brep brep, Guid id)>();

            //var tol = 0.0001;
            var roomBrep             = roomObjRef.Brep().DuplicateBrep();
            var checkedApertureBreps = CheckApertureBreps(roomBrep, apertureObjRefs);

            //return empty aperture list;
            if (!checkedApertureBreps.Any())
            {
                return(roomBrep, roomObjRef.ObjectId, apertures);
            }

            var roomSrfs = roomBrep.Faces;

            foreach (var roomSrf in roomSrfs)
            {
                //Get intersected-coplanar matched aperture for this room face
                var matchedAptertures = GetMatchedBreps(roomSrf, checkedApertureBreps);

                if (!matchedAptertures.Any())
                {
                    continue;
                }

                var roomSrfEnt = roomSrf.TryGetFaceEntity();

                //Install all matched apertures to this room.
                foreach (var matchedApterture in matchedAptertures)
                {
                    (Brep brep, Guid id)processed;
                    if (isDoor)
                    {
                        processed = AddDoor(matchedApterture, roomSrfEnt);
                    }
                    else
                    {
                        processed = AddAperture(matchedApterture, roomSrfEnt);
                    }
                    apertures.Add(processed);
                }
            }

            return(roomBrep, roomObjRef.ObjectId, apertures);

            (Brep brep, Guid id) AddAperture((Brep brep, Guid id) matchedFace, FaceEntity roomFaceEnt)
            {
                var hostId  = matchedFace.id;
                var aptBrep = matchedFace.brep;

                var newObjRef = new ObjRef(hostId);

                //Convert to Aperture Brep, and replace current rhino object
                aptBrep = EntityHelper.ToApertureBrep(aptBrep, hostId);

                //add to room face brep
                roomFaceEnt.AddAperture(newObjRef, aptBrep);

                //link host room objref to aperture entity
                aptBrep.TryGetApertureEntity().HostRoomObjRef = new ObjRef(roomObjRef.ObjectId);
                return(aptBrep, hostId);
            }

            (Brep brep, Guid id) AddDoor((Brep brep, Guid id) matchedFace, FaceEntity roomFaceEnt)
            {
                var hostId   = matchedFace.id;
                var doorBrep = matchedFace.brep;

                var newObjRef = new ObjRef(hostId);

                //Convert to Aperture Brep, and replace current rhino object
                doorBrep = EntityHelper.ToDoorBrep(doorBrep, hostId);

                //add to room face brep
                roomFaceEnt.AddDoor(newObjRef, doorBrep);

                //link host room objref to aperture entity
                doorBrep.TryGetDoorEntity().HostRoomObjRef = new ObjRef(roomObjRef.ObjectId);
                return(doorBrep, hostId);
            }

            //Local method ===========================================================================================================
            IEnumerable <(Brep brep, Guid id)> CheckApertureBreps(Brep _roomBrep, List <ObjRef> _apertureObjRefs)
            {
                var tol = 0.001;
                //Duplicate
                var roomBbox         = _roomBrep.GetBoundingBox(false);
                var checkedApertures = new List <(Brep, Guid)>();

                //Check if is intersected with room.
                foreach (var objRef in _apertureObjRefs)
                {
                    var apt = objRef.Brep().DuplicateBrep();
                    apt.Faces.ShrinkFaces();
                    var isInterseted = roomBbox.isIntersected(apt.GetBoundingBox(false), tol);
                    if (isInterseted)
                    {
                        checkedApertures.Add((apt, objRef.ObjectId));
                    }
                }

                return(checkedApertures);
            }

            IEnumerable <(Brep brep, Guid id)> GetMatchedBreps(BrepFace _bFace, IEnumerable <(Brep brep, Guid id)> _apertureBreps)
            {
                //Check intersection, maybe provide an option for use to split window surfaces for zones.
                //TODO: do this later

                var tol         = 0.001;
                var srfBBox     = _bFace.GetBoundingBox(false);
                var intersected = _apertureBreps.Where(_ => _.brep.GetBoundingBox(false).isIntersected(srfBBox, tol));
                var coplanared  = intersected.Where(_ => _.brep.Faces[0].IsCoplanar(_bFace, tol));

                //TODO: Check if inside

                return(coplanared);
            }
        }
コード例 #10
0
        /// <summary>
        /// read meta data from one doc object
        /// </summary>
        /// <param name="oref">object reference</param>
        /// <param name="propkeys">query keys</param>
        /// <returns>array of properties</returns>
        private string[] GetProp(ObjRef oref, string[] propkeys)
        {
            string[]    line = new string[propkeys.Length];
            RhinoObject obj  = oref.Object();

            for (int i = 0; i < propkeys.Length; i++)
            {
                string k = propkeys[i];
                if (popup.cun != "" && popup.cun != null)
                {
                    docunit = popup.cun;
                }
                else
                {
                    docunit = parent.GetUnitSystemName(true, false, true, true);
                }
                switch (k)
                {
                case "GUID":
                    line.SetValue(oref.ObjectId.ToString(), i);
                    break;

                case "Type":
                    line.SetValue(obj.ObjectType.ToString(), i);
                    break;

                case "Name":
                    line.SetValue(obj.Name, i);
                    break;

                case "Layer":
                    var li    = obj.Attributes.LayerIndex;
                    var layer = parent.Layers.FindIndex(li);
                    line.SetValue(layer.Name, i);
                    break;

                case "Color":
                    var c = obj.Attributes.DrawColor(parent);
                    if (popup.cf == 0)
                    {
                        line.SetValue(c.ToString(), i);
                    }
                    else if (popup.cf == 1)
                    {
                        line.SetValue(string.Format("{0}-{1}-{2}", c.R, c.G, c.B), i);
                    }
                    else
                    {
                        line.SetValue(string.Format("{0} {1} {2}", c.R, c.G, c.B), i);
                    }
                    break;

                case "LineType":
                    var lti = parent.Linetypes.LinetypeIndexForObject(obj);
                    var lt  = parent.Linetypes[lti].Name;
                    line.SetValue(lt, i);
                    break;

                case "PrintColor":
                    Color pc;
                    var   pcs = obj.Attributes.PlotColorSource;
                    if (pcs == ObjectPlotColorSource.PlotColorFromLayer)
                    {
                        li    = obj.Attributes.LayerIndex;
                        layer = parent.Layers.FindIndex(li);
                        pc    = layer.PlotColor;
                    }
                    else
                    {
                        pc = obj.Attributes.PlotColor;
                    }
                    if (popup.cf == 0)
                    {
                        line.SetValue(pc.ToString(), i);
                    }
                    else if (popup.cf == 1)
                    {
                        line.SetValue(string.Format("{0}-{1}-{2}", pc.R, pc.G, pc.B), i);
                    }
                    else
                    {
                        line.SetValue(string.Format("{0} {1} {2}", pc.R, pc.G, pc.B), i);
                    }
                    break;

                case "PrintWidth":
                    double pw;
                    var    pws = obj.Attributes.PlotWeightSource;
                    if (pws == ObjectPlotWeightSource.PlotWeightFromLayer)
                    {
                        li    = obj.Attributes.LayerIndex;
                        layer = parent.Layers.FindIndex(li);
                        pw    = layer.PlotWeight;
                    }
                    else
                    {
                        pw = obj.Attributes.PlotWeight;
                    }
                    if (options[0])
                    {
                        line.SetValue(pw.ToString() + "pt", i);                 // with unit
                    }
                    else
                    {
                        line.SetValue(pw.ToString(), i);
                    }
                    break;

                case "Material":
                    var mti = obj.Attributes.MaterialIndex;
                    var mt  = parent.Materials.FindIndex(mti);
                    if (mt == null)
                    {
                        line.SetValue(null, i);
                    }
                    else
                    {
                        line.SetValue(mt.Name, i);
                    }
                    break;

                case "Length":
                    string len = null;
                    if (obj.ObjectType == ObjectType.Curve)
                    {
                        var len_num = Math.Round(oref.Curve().GetLength(), popup.dp); //decimal
                        len_num *= popup.su;                                          //custom scale
                        if (popup.ts == ",")
                        {
                            len = len_num.ToString("#,##0.00");
                        }
                        else if (popup.ts == ".")
                        {
                            len = len_num.ToString("#.##0.00");
                        }
                        else if (popup.ts == " ")
                        {
                            len = len_num.ToString("# ##0.00");
                        }
                        else
                        {
                            len = len_num.ToString();
                        }
                    }
                    if (options[0] && len != null)
                    {
                        len += docunit;                              // with unit
                    }
                    line.SetValue(len, i);
                    break;

                case "Area":
                    AreaMassProperties amp = null;
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        amp = AreaMassProperties.Compute(oref.Brep());
                    }
                    else if (obj.ObjectType == ObjectType.Curve)
                    {
                        if (oref.Curve().IsClosed)
                        {
                            amp = AreaMassProperties.Compute(oref.Curve());
                        }
                        else
                        {
                            amp = null;
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        if (obj.Geometry.HasBrepForm)
                        {
                            amp = AreaMassProperties.Compute(Brep.TryConvertBrep(obj.Geometry));
                        }
                        else
                        {
                            amp = null;
                        }
                    }

                    if (amp != null)
                    {
                        double area_num = Math.Round(amp.Area, popup.dp);
                        area_num *= popup.su;
                        string area;
                        if (popup.ts == ",")
                        {
                            area = area_num.ToString("#,##0.00");
                        }
                        else if (popup.ts == ".")
                        {
                            area = area_num.ToString("#.##0.00");
                        }
                        else if (popup.ts == " ")
                        {
                            area = area_num.ToString("# ##0.00");
                        }
                        else
                        {
                            area = area_num.ToString();
                        }

                        if (options[0])
                        {
                            if (popup.cun != "" && popup.cun != null)
                            {
                                line.SetValue(area + popup.cun + "sq", i);
                            }
                            else
                            {
                                line.SetValue(area + docunit + "sq", i);
                            }
                        }
                        else
                        {
                            line.SetValue(area, i);
                        }
                    }
                    else
                    {
                        line.SetValue(null, i);
                    }
                    break;

                case "Volume":
                    string vol = null;
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        if (oref.Brep().IsSolid)
                        {
                            double vol_num = oref.Brep().GetVolume(rtol, tol);
                            vol_num  = Math.Round(vol_num, popup.dp);
                            vol_num *= popup.su;
                            if (popup.ts == ",")
                            {
                                vol = vol_num.ToString("#,##0.00");
                            }
                            else if (popup.ts == ".")
                            {
                                vol = vol_num.ToString("#.##0.00");
                            }
                            else if (popup.ts == " ")
                            {
                                vol = vol_num.ToString("# ##0.00");
                            }
                            else
                            {
                                vol = vol_num.ToString();
                            }
                        }
                        else
                        {
                            vol = "open brep";
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        Brep b = Brep.TryConvertBrep(obj.Geometry);
                        if (b == null)
                        {
                            vol = "invalid extrusion";
                        }
                        else
                        {
                            if (b.IsSolid)
                            {
                                double vol_num = b.GetVolume(rtol, tol);
                                vol_num  = Math.Round(vol_num, popup.dp);
                                vol_num *= popup.su;
                                if (popup.ts == ",")
                                {
                                    vol = vol_num.ToString("#,##0.00");
                                }
                                else if (popup.ts == ".")
                                {
                                    vol = vol_num.ToString("#.##0.00");
                                }
                                else if (popup.ts == " ")
                                {
                                    vol = vol_num.ToString("# ##0.00");
                                }
                                else
                                {
                                    vol = vol_num.ToString();
                                }
                            }
                            else
                            {
                                vol = "open brep";
                            }
                        }
                    }

                    if (!options[0] || vol == null)
                    {
                        line.SetValue(vol, i);
                    }
                    else if (vol != "open brep" && vol != "invalid extrusion")
                    {
                        if (popup.cun != "" && popup.cun != null)
                        {
                            line.SetValue(vol + popup.cun + "cu", i);
                        }
                        else
                        {
                            line.SetValue(vol + docunit + "cu", i);
                        }
                    }
                    break;

                case "NumPts":
                    if (obj.ObjectType == ObjectType.Curve)
                    {
                        line.SetValue(oref.Curve().ToNurbsCurve().Points.Count.ToString(), i);
                    }
                    else
                    {
                        line.SetValue(null, i);
                    }
                    break;

                case "NumEdges":
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        line.SetValue(oref.Brep().Edges.Count.ToString(), i);
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        if (obj.Geometry.HasBrepForm)
                        {
                            line.SetValue(Brep.TryConvertBrep(obj.Geometry).Edges.Count.ToString(), i);
                        }
                        else
                        {
                            line.SetValue("invalid extrusion", i);
                        }
                    }
                    else
                    {
                        line.SetValue(null, i);
                    }
                    break;

                case "NumFaces":
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        line.SetValue(oref.Brep().Faces.Count.ToString(), i);
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        if (obj.Geometry.HasBrepForm)
                        {
                            line.SetValue(Brep.TryConvertBrep(obj.Geometry).Faces.Count.ToString(), i);
                        }
                        else
                        {
                            line.SetValue("invalid extrusion", i);
                        }
                    }
                    else
                    {
                        line.SetValue(null, i);
                    }
                    break;

                case "Degree":
                    if (obj.ObjectType == ObjectType.Curve)
                    {
                        line.SetValue(oref.Curve().Degree.ToString(), i);
                    }
                    else
                    {
                        line.SetValue(null, i);
                    }
                    break;

                case "CenterX":
                    var num = obj.Geometry.GetBoundingBox(false).Center.X;
                    num  = Math.Round(num, popup.dp);
                    num *= popup.su;
                    line.SetValue(num.ToString(), i);
                    break;

                case "CenterY":
                    num  = obj.Geometry.GetBoundingBox(false).Center.Y;
                    num  = Math.Round(num, popup.dp);
                    num *= popup.su;
                    line.SetValue(num.ToString(), i);
                    break;

                case "CenterZ":
                    num  = obj.Geometry.GetBoundingBox(false).Center.Z;
                    num  = Math.Round(num, popup.dp);
                    num *= popup.su;
                    line.SetValue(num.ToString(), i);
                    break;

                case "IsPlanar":
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        Brep brep = oref.Brep();
                        if (brep.IsSurface)
                        {
                            if (brep.Faces[0].IsPlanar())
                            {
                                line.SetValue("yes", i);
                            }
                            else
                            {
                                line.SetValue("no", i);
                            }
                        }
                        else
                        {
                            line.SetValue("polysrf", i);
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Curve)
                    {
                        if (oref.Curve().IsPlanar())
                        {
                            line.SetValue("yes", i);
                        }
                        else
                        {
                            line.SetValue("no", i);
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        if (obj.Geometry.HasBrepForm)
                        {
                            Brep brep = Brep.TryConvertBrep(obj.Geometry);
                            if (brep.IsSurface)
                            {
                                if (brep.Faces[0].IsPlanar())
                                {
                                    line.SetValue("yes", i);
                                }
                                else
                                {
                                    line.SetValue("no", i);
                                }
                            }
                            else
                            {
                                line.SetValue("polysrf", i);
                            }
                        }
                        else
                        {
                            line.SetValue("invalid extrusion", i);
                        }
                    }
                    else
                    {
                        line.SetValue("irrelevant", i);
                    }
                    break;

                case "IsClosed":
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        Brep brep = oref.Brep();
                        if (brep.IsSolid)
                        {
                            line.SetValue("yes", i);
                        }
                        else
                        {
                            line.SetValue("no", i);
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Curve)
                    {
                        if (oref.Curve().IsClosed)
                        {
                            line.SetValue("yes", i);
                        }
                        else
                        {
                            line.SetValue("no", i);
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        if (obj.Geometry.HasBrepForm)
                        {
                            Brep brep = Brep.TryConvertBrep(obj.Geometry);
                            if (brep.IsSolid)
                            {
                                line.SetValue("yes", i);
                            }
                            else
                            {
                                line.SetValue("no", i);
                            }
                        }
                        else
                        {
                            line.SetValue("invalid extrusion", i);
                        }
                    }
                    else
                    {
                        line.SetValue("irrelevant", i);
                    }
                    break;

                case "Comments":
                    var    usertxts = obj.Attributes.GetUserStrings();
                    string txt      = null;
                    if (usertxts.Count == 1)
                    {
                        txt = usertxts[0];
                    }
                    else
                    {
                        txt = string.Join(";", usertxts.AllKeys);
                    }
                    line.SetValue("keys_" + txt, i);
                    break;

                default:
                    break;
                }
            }
            return(line);
        }
コード例 #11
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            if (p.if_painted_object_set_ == false)
            {
                RhinoApp.WriteLine("No mesh");
                return(Result.Failure);
            }
            Mesh my_mesh = p.painted_object_;

            GetObject gbrep = new GetObject();

            gbrep.SetCommandPrompt("get the brep");
            gbrep.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep.SubObjectSelect = false;
            gbrep.Get();
            if (gbrep.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep.CommandResult());
            }
            ObjRef      my_objref = gbrep.Object(0);
            RhinoObject my_obj    = my_objref.Object();

            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep = my_objref.Brep();

            if (brep == null)
            {
                return(Result.Failure);
            }
            my_obj.Select(false);

            int brep_number = 0;

            for (int i = 0; i < p.my_objects_list.Count; i++)
            {
                Brep an_object = p.my_objects_list[i];
                if (My_object_functions.GetComponentID(brep) == My_object_functions.GetComponentID(an_object))
                {
                    brep_number = i;
                    break;
                }
            }

            GetComponentPosition gp = new GetComponentPosition(brep, my_mesh);

            gp.SetCommandPrompt("Get the object position on mesh: ");
            gp.Constrain(my_mesh, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d       n_p = gp.Point();
            List <Sphere> pin_ball_list;
            Brep          new_brep = GetComponentPosition.MoveBrep(brep, my_mesh, n_p, out pin_ball_list);

            /*
             * Point3d position = My_object_functions.GetPosition(new_brep);
             * Vector3d d_x = My_object_functions.GetX(new_brep);
             * Vector3d d_y = My_object_functions.GetY(new_brep);
             * Vector3d d_z = My_object_functions.GetZ(new_brep);
             * Line l_x = new Line(position, 10 * d_x);
             * Line l_y = new Line(position, 10 * d_y);
             * Line l_z = new Line(position, 10 * d_z);
             */

            ObjectAttributes path_attributes = new ObjectAttributes();

            path_attributes.ObjectColor      = Color.Yellow;
            path_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
            path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
            path_attributes.PlotWeight       = 2.0;

            ObjectAttributes my_attributes = new ObjectAttributes();

            my_attributes.ObjectColor = My_object_functions.GetColor(new_brep);
            my_attributes.ColorSource = ObjectColorSource.ColorFromObject;

            int new_pin_number = My_object_functions.GetPinQuantity(new_brep);
            List <NurbsCurve> new_path_list = new List <NurbsCurve>();

            for (int i = 0; i < new_pin_number; i++)
            {
                Guid      pin_id       = My_object_functions.GetPinGuid(new_brep, i);
                Point3d   pin_position = My_object_functions.GetPinPosition(new_brep, i);
                MeshPoint pin_on_mesh  = my_mesh.ClosestMeshPoint(pin_position, 0);
                new_path_list = p.graph.DijkstraPath_Change(pin_id, pin_on_mesh);
            }

            IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve);

            foreach (RhinoObject path in path_objref)
            {
                doc.Objects.Delete(path, true);
            }

            for (int i = 0; i < new_path_list.Count; i++)
            {
                Guid path_id = new_path_list[i].UserDictionary.GetGuid("PathID");
                path_attributes.ObjectId = path_id;
                doc.Objects.AddCurve(new_path_list[i], path_attributes);
            }

            doc.Objects.Delete(my_objref, true);

            /*
             * IEnumerable<RhinoObject> rhino_objects = doc.Objects.GetObjectList(ObjectType.Brep);
             * foreach (RhinoObject r_o in rhino_objects) { doc.Objects.Delete(r_o, true); }
             *
             * IEnumerable<RhinoObject> lines = doc.Objects.GetObjectList(ObjectType.Curve);
             * foreach (RhinoObject r_o in lines) { doc.Objects.Delete(r_o, true); }
             */
            doc.Objects.AddBrep(new_brep, my_attributes);
            p.my_objects_list[brep_number] = new_brep;

            /*
             * foreach (Sphere s in pin_ball_list)
             * { doc.Objects.AddSphere(s); }
             * doc.Objects.AddLine(l_x, path_attributes);
             * doc.Objects.AddLine(l_y, path_attributes);
             * doc.Objects.AddLine(l_z, path_attributes);
             */
            doc.Views.Redraw();

            return(Result.Success);
        }
コード例 #12
0
ファイル: RhinoManagement.cs プロジェクト: vnoves/BIMSocket
        private static void ExportToJson(List <string> guids)
        {
            var doc = Rhino.RhinoDoc.ActiveDoc;
            ObjectEnumeratorSettings settings = new ObjectEnumeratorSettings();

            settings.ActiveObjects = true;
            List <Guid> ids     = new List <Guid>();
            var         objrefs = doc.Objects.GetObjectList(settings);


            List <Element> allElements = new List <Element>();


            foreach (var rhinoobj in objrefs)
            {
                var  obj            = new ObjRef(rhinoobj.Id);
                var  material       = rhinoobj.GetMaterial(true);
                var  mesh           = new va3c_Mesh();
                Mesh finalMesh      = new Mesh();
                var  parameterNames = new List <string> {
                    "objectId"
                };
                var parameterValues = new List <string> {
                    obj.ObjectId.ToString()
                };
                RCva3c.Material mat;
                if (material != null)
                {
                    mat = new va3c_MeshPhongMaterial().GeneratePhongMaterial(material.Id, material.DiffuseColor, material.AmbientColor, material.EmissionColor, material.SpecularColor, material.Shine, 1 - material.Transparency);
                }
                else
                {
                    mat = new va3c_MeshBasicMaterial().GenerateMaterial(System.Drawing.Color.White, 1);
                }

                switch (obj.Geometry().ObjectType)
                {
                case ObjectType.None:
                    break;

                case ObjectType.Point:
                    break;

                case ObjectType.PointSet:
                    break;

                case ObjectType.Curve:
                    break;

                case ObjectType.Surface:
                    var srf     = obj.Surface();
                    var meshSrf = Mesh.CreateFromBrep(srf.ToBrep());
                    if (meshSrf?.Length > 0)
                    {
                        foreach (var m in meshSrf)
                        {
                            finalMesh.Append(m);
                        }
                    }
                    allElements.Add(mesh.GenerateMeshElement(finalMesh, mat, obj.ObjectId, parameterNames, parameterValues));
                    break;

                case ObjectType.Brep:
                    var brep     = obj.Brep();
                    var meshBrep = Mesh.CreateFromBrep(brep);
                    if (meshBrep?.Length > 0)
                    {
                        foreach (var m in meshBrep)
                        {
                            finalMesh.Append(m);
                        }
                    }
                    allElements.Add(mesh.GenerateMeshElement(finalMesh, mat, obj.ObjectId, parameterNames, parameterValues));
                    break;

                case ObjectType.Mesh:
                    var msh = obj.Mesh();
                    allElements.Add(mesh.GenerateMeshElement(msh, mat, obj.ObjectId, parameterNames, parameterValues));
                    break;

                case ObjectType.Light:
                    break;

                case ObjectType.Annotation:
                    break;

                case ObjectType.InstanceDefinition:
                    break;

                case ObjectType.InstanceReference:
                    break;

                case ObjectType.TextDot:
                    break;

                case ObjectType.Grip:
                    break;

                case ObjectType.Detail:
                    break;

                case ObjectType.Hatch:
                    break;

                case ObjectType.MorphControl:
                    break;

                case ObjectType.BrepLoop:
                    break;

                case ObjectType.PolysrfFilter:
                    break;

                case ObjectType.EdgeFilter:
                    break;

                case ObjectType.PolyedgeFilter:
                    break;

                case ObjectType.MeshVertex:
                    break;

                case ObjectType.MeshEdge:
                    break;

                case ObjectType.MeshFace:
                    break;

                case ObjectType.Cage:
                    break;

                case ObjectType.Phantom:
                    break;

                case ObjectType.ClipPlane:
                    break;

                case ObjectType.Extrusion:

                    var extruction     = obj.Brep();
                    var meshExtruction = Mesh.CreateFromBrep(extruction);
                    if (meshExtruction?.Length > 0)
                    {
                        foreach (var m in meshExtruction)
                        {
                            finalMesh.Append(m);
                        }
                    }
                    allElements.Add(mesh.GenerateMeshElement(finalMesh, mat, obj.ObjectId, parameterNames, parameterValues));
                    break;

                case ObjectType.AnyObject:
                    break;

                default:
                    break;
                }
            }


            var         scenecompiler = new va3c_SceneCompiler();
            string      resultatas    = scenecompiler.GenerateSceneJson(doc.Name.Replace(".3dm", ""), allElements);
            FileManager writer        = new FileManager();

            writer.SaveFileTo(new List <string> {
                resultatas
            });
        }