コード例 #1
0
 void CalMat(RhinoDoc doc, double spezWeight, Rhino.DocObjects.ObjectType objType, Rhino.DocObjects.ObjRef objref, List <string> matList, String[] matName, int pos, string g_ct)
 {
     if ((objType == Rhino.DocObjects.ObjectType.Surface | objType == Rhino.DocObjects.ObjectType.PolysrfFilter | objType == Rhino.DocObjects.ObjectType.Brep | objType == Rhino.DocObjects.ObjectType.Extrusion))
     {
         Brep objrefBrep = objref.Brep();
         bool bc         = objrefBrep.IsSolid;
         if (bc == false)
         {
             open++;
         }
         double volObj = objrefBrep.GetVolume();
         double weight = Math.Round(volObj * spezWeight, 3, MidpointRounding.AwayFromZero);
         materials[pos] += weight;
         //matList.Add(matName[pos] + " " + weight + g_ct);
     }
     else if (objType == Rhino.DocObjects.ObjectType.Mesh)
     {
         Mesh objrefMesh = objref.Mesh();
         bool bc         = objrefMesh.IsClosed;
         if (bc == false)
         {
             open++;
         }
         double volObj = objrefMesh.Volume();
         double weight = Math.Round(volObj * spezWeight, 3, MidpointRounding.AwayFromZero);
         materials[pos] += weight;
         //matList.Add(matName[pos] + " " + weight + g_ct);
     }
 }
コード例 #2
0
ファイル: Get_mesh.cs プロジェクト: TianyiWang3259/Overpaint
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            RhinoApp.WriteLine("The {0} command is under construction.", EnglishName);

            Rhino.Input.Custom.GetObject gmesh = new Rhino.Input.Custom.GetObject();
            gmesh.SetCommandPrompt("Get the Mesh");
            gmesh.GeometryFilter  = Rhino.DocObjects.ObjectType.Mesh;
            gmesh.SubObjectSelect = true;
            gmesh.Get();
            if (gmesh.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gmesh.CommandResult());
            }
            Rhino.DocObjects.ObjRef      objref = gmesh.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Rhino.Geometry.Mesh mesh = objref.Mesh();
            if (mesh == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            obj.Select(false);

            MeshTextureCoordinateList texture_list = mesh.TextureCoordinates;

            for (int i = 0; i < texture_list.Count - 1; i++)
            {
                Point2f f1 = texture_list[i];
                Point2f f2 = texture_list[i + 1];
                Point3d t1 = new Point3d(f1.X, f1.Y, 0);
                Point3d t2 = new Point3d(f2.X, f2.Y, 0);
                Line    l  = new Line(t1, t2);
                doc.Objects.AddLine(l);
                RhinoApp.WriteLine("Line added");
            }
            doc.Views.Redraw();
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            p.painted_object_        = mesh;
            p.if_painted_object_set_ = true;
            mesh.UserDictionary.Set("name", "myMesh");
            mesh.UserDictionary.Set("isMovable", false);
            p.graph = new DijkstraGraph(10);
            RhinoApp.WriteLine("Mesh Got");
            return(Result.Success);
        }
コード例 #3
0
    public static Rhino.Commands.Result ExtractRenderMesh(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef objRef = null;
        Rhino.Commands.Result   rc     = Rhino.Input.RhinoGet.GetOneObject("Select surface or polysurface", false, Rhino.DocObjects.ObjectType.Brep, out objRef);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.DocObjects.RhinoObject obj = objRef.Object();
        if (null == obj)
        {
            return(Rhino.Commands.Result.Failure);
        }

        System.Collections.Generic.List <Rhino.DocObjects.RhinoObject> objList = new System.Collections.Generic.List <Rhino.DocObjects.RhinoObject>(1);
        objList.Add(obj);

        Rhino.DocObjects.ObjRef[] meshObjRefs = Rhino.DocObjects.RhinoObject.GetRenderMeshes(objList, true, false);
        if (null != meshObjRefs)
        {
            for (int i = 0; i < meshObjRefs.Length; i++)
            {
                Rhino.DocObjects.ObjRef meshObjRef = meshObjRefs[i];
                if (null != meshObjRef)
                {
                    Rhino.Geometry.Mesh mesh = meshObjRef.Mesh();
                    if (null != mesh)
                    {
                        doc.Objects.AddMesh(mesh);
                    }
                }
            }
            doc.Views.Redraw();
        }

        return(Rhino.Commands.Result.Success);
    }
コード例 #4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            bool allBrepSolid = true;
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Mesh;

            GetObject wro = new Rhino.Input.Custom.GetObject();

            wro.SetCommandPrompt("Select objects to weight.");
            wro.GeometryFilter = geometryFilter;

            wro.SubObjectSelect             = true;
            wro.DeselectAllBeforePostSelect = false;
            wro.OneByOnePostSelect          = true;
            wro.GetMultiple(1, 0);

            double volObj3 = 0;


            for (int i = 0; i < wro.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = wro.Object(i);
                // get selected surface object
                Rhino.DocObjects.RhinoObject obj = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                // get selected surface (face)

                Brep refcr = objref.Brep();
                if (refcr != null)
                {
                    var    volObj  = VolumeMassProperties.Compute(refcr);
                    double volObj2 = refcr.GetVolume();
                    volObj3 = volObj3 + volObj2;
                    bool brepSolid = refcr.IsSolid;
                    if (brepSolid == false)
                    {
                        allBrepSolid = false;
                    }
                }
                if (refcr == null)
                {
                    Mesh   refcm   = objref.Mesh();
                    Brep   refmb   = Brep.CreateFromMesh(refcm, false);
                    var    volOb   = VolumeMassProperties.Compute(refmb);
                    double volObj4 = refmb.GetVolume();
                    volObj3 = volObj3 + volObj4;
                    bool brepSolid = refmb.IsSolid;
                    if (brepSolid == false)
                    {
                        allBrepSolid = false;
                    }
                }
            }

            double gold18k   = Math.Round(volObj3 * 0.0158, 2, MidpointRounding.AwayFromZero);
            double gold14k   = Math.Round(volObj3 * 0.0146, 2, MidpointRounding.AwayFromZero);
            double platinum  = Math.Round(volObj3 * 0.0214, 2, MidpointRounding.AwayFromZero);
            double palladium = Math.Round(volObj3 * 0.012, 2, MidpointRounding.AwayFromZero);
            double silver925 = Math.Round(volObj3 * 0.0102, 2, MidpointRounding.AwayFromZero);
            double diaCt     = Math.Round(volObj3 * 0.01755, 2, MidpointRounding.AwayFromZero);

            if (allBrepSolid)
            {
                RhinoApp.WriteLine("The weight is: Gold 18k " + gold18k + "g, Gold 14k " + gold14k + "g, Platinum " + platinum + "g, Palladium " + palladium + "g, Silver 925 " + silver925 + "g, Diamond" + diaCt + "Ct");
            }
            else
            {
                RhinoApp.WriteLine("AT LEAST ONE OBJECT IS OPEN! Result might be false!" + "The weight is: Gold 18k " + gold18k + "g, Gold 14k " + gold14k + "g, Platinum " + platinum + "g, Palladium " + palladium + "g, Silver 925 " + silver925 + "g, Diamond" + diaCt + "Ct");
            }



            return(Result.Success);
        }
コード例 #5
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Mesh        meshSurf;
            List <Guid> ids       = new List <Guid>();
            double      tolerance = doc.ModelAbsoluteTolerance;
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface |
                                                               Rhino.DocObjects.ObjectType.PolysrfFilter |
                                                               Rhino.DocObjects.ObjectType.Mesh;

            GetObject gs = new Rhino.Input.Custom.GetObject();

            gs.SetCommandPrompt("Surface to orient on");
            gs.GeometryFilter              = geometryFilter;
            gs.SubObjectSelect             = true;
            gs.DeselectAllBeforePostSelect = true;
            gs.OneByOnePostSelect          = true;
            gs.Get();
            if (gs.CommandResult() != Result.Success)
            {
                return(gs.CommandResult());
            }

            Rhino.DocObjects.ObjRef      objref = gs.Object(0);
            Rhino.DocObjects.RhinoObject obj    = objref.Object();
            if (obj == null)
            {
                return(Result.Failure);
            }

            brepSurf = objref.Brep();
            if (brepSurf == null)
            {
                meshSurf = objref.Mesh();
                brepSurf = Brep.CreateFromMesh(meshSurf, true);
            }
            if (brepSurf == null)
            {
                return(Result.Failure);
            }
            obj.Select(false);


            while (true)
            {
                w_key_pressed = false;
                s_key_pressed = false;
                a_key_pressed = false;
                d_key_pressed = false;

                m_escape_key_pressed = false;

                RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;
                RhinoApp.KeyboardEvent    += OnRhinoKeyboardEvent;

                Point3d  pt0;
                GetPoint getPointAction = new GetPoint();
                getPointAction.SetCommandPrompt("Please select insert point(s) on surface.");
                getPointAction.Constrain(brepSurf, -1, -1, false);

                var stoneDiam  = new Rhino.Input.Custom.OptionDouble(diamStone);
                var stoneOff   = new Rhino.Input.Custom.OptionDouble(offSetStone);
                var boolOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");
                var moveOption = new Rhino.Input.Custom.OptionToggle(false, "Off", "On");

                getPointAction.AddOptionDouble("StoneDiam", ref stoneDiam);
                getPointAction.AddOptionDouble("Offset", ref stoneOff);
                getPointAction.AddOptionToggle("Delete", ref boolOption);
                getPointAction.AddOptionToggle("Move", ref moveOption);
                getPointAction.DynamicDraw += RefCircleDraw;
                getPointAction.Tag          = obj;
                getPointAction.AcceptString(false);
                getPointAction.AcceptNothing(true);
                var res = getPointAction.Get();


                if (w_key_pressed || s_key_pressed)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    w_key_pressed           = false;
                    s_key_pressed           = false;
                    stoneDiam.CurrentValue  = diamStone;
                }
                if (a_key_pressed || d_key_pressed)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    a_key_pressed           = false;
                    d_key_pressed           = false;
                    stoneOff.CurrentValue   = offSetStone;
                }

                if (res == GetResult.Nothing)
                {
                    break;
                }
                if (m_escape_key_pressed)
                {
                    break;
                }

                diamStone   = stoneDiam.CurrentValue;
                offSetStone = stoneOff.CurrentValue;
                optionBool  = boolOption.CurrentValue;
                moveBool    = moveOption.CurrentValue;

                RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;

                if (moveBool == true)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    while (true)
                    {
                        GetObject gcd = new Rhino.Input.Custom.GetObject();
                        gcd.SetCommandPrompt("Select circle(s) to move. Press enter when done");
                        gcd.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
                        gcd.SubObjectSelect             = false;
                        gcd.DeselectAllBeforePostSelect = true;
                        gcd.AcceptNothing(true);
                        if (gcd.Get() == GetResult.Nothing)
                        {
                            break;
                        }
                        gcd.Get();
                        Rhino.DocObjects.ObjRef      delobjref = gcd.Object(0);
                        Rhino.DocObjects.RhinoObject delobj    = delobjref.Object();
                        Curve  curveRadius  = delobjref.Curve();
                        Circle circleRadius = new Circle();
                        curveRadius.TryGetCircle(out circleRadius, tolerance);
                        diamStone = circleRadius.Diameter;
                        doc.Objects.Delete(delobj, true);
                        doc.Views.Redraw();

                        getPointAction.Get();
                        pt0 = getPointAction.Point();
                        Point3d        closestPoint;
                        ComponentIndex compIndex;
                        double         u, v;
                        Vector3d       vt1;

                        brepSurf.ClosestPoint(pt0, out closestPoint, out compIndex, out u, out v, 0.01, out vt1);
                        Plane  pl1  = new Plane(pt0, vt1);
                        Circle cr1  = new Circle(pl1, pt0, diamStone / 2);
                        var    crgu = doc.Objects.AddCircle(cr1);
                        ids.Add(crgu);
                        doc.Views.Redraw();
                    }
                    moveBool = false;
                }
                if (optionBool == true)
                {
                    RhinoApp.KeyboardEvent -= OnRhinoKeyboardEvent;
                    while (true)
                    {
                        GetObject gcd = new Rhino.Input.Custom.GetObject();
                        gcd.SetCommandPrompt("Select circle(s) to delete. Press enter when done");
                        gcd.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
                        gcd.SubObjectSelect             = false;
                        gcd.DeselectAllBeforePostSelect = true;
                        gcd.AcceptNothing(true);
                        if (gcd.Get() == GetResult.Nothing)
                        {
                            break;
                        }
                        gcd.Get();
                        Rhino.DocObjects.ObjRef      delobjref = gcd.Object(0);
                        Rhino.DocObjects.RhinoObject delobj    = delobjref.Object();
                        Curve  curveRadius  = delobjref.Curve();
                        Circle circleRadius = new Circle();
                        curveRadius.TryGetCircle(out circleRadius, tolerance);
                        diamStone = circleRadius.Diameter;
                        doc.Objects.Delete(delobj, true);
                        doc.Views.Redraw();
                    }
                    optionBool = false;
                }

                if (res == GetResult.Point)
                {
                    pt0 = getPointAction.Point();
                    Point3d        closestPoint;
                    ComponentIndex compIndex;
                    double         u, v;
                    Vector3d       vt1;
                    brepSurf.ClosestPoint(pt0, out closestPoint, out compIndex, out u, out v, 0.01, out vt1);
                    Plane  pl1  = new Plane(pt0, vt1);
                    Circle cr1  = new Circle(pl1, pt0, diamStone / 2);
                    var    crgu = doc.Objects.AddCircle(cr1);
                    ids.Add(crgu);
                    doc.Views.Redraw();
                }
            }
            RhinoApp.KeyboardEvent    -= OnRhinoKeyboardEvent;
            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;
            doc.Groups.Add(ids);
            return(Result.Success);
        }