示例#1
0
        public Rhino.Commands.Result delete(Rhino.RhinoDoc doc)
        {
            // Input incomplate
            double _incomplate = 0.1;

            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input incomplate(0.0 ~ 1.0)<0.1>");
            Rhino.Input.GetResult res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _incomplate = input.Number();
            }
            if (_incomplate == 0.0)
            {
                _incomplate = 0.1;
            }

            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select elements");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
            res = go.GetMultiple(1, 1024 * 10);
            if (res == Rhino.Input.GetResult.Nothing)
            {
                return(Rhino.Commands.Result.Failure);
            }

            System.Collections.Generic.List <Guid> list = new System.Collections.Generic.List <Guid>();
            for (int i = 0; i < go.ObjectCount; i++)
            {
                Guid guid = go.Object(i).ObjectId;
                list.Add(guid);
            }

            int deleteCount = (int)((double)(list.Count) * _incomplate);

            Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;
            for (int i = 0; i < deleteCount; i++)
            {
                Guid guid = list[i];
                ot.Delete(guid, true);
            }

            return(Rhino.Commands.Result.Success);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Geometry.MeshingParameters mp = doc.GetMeshingParameters(Rhino.Geometry.MeshingParameterStyle.Custom);
            double relativeTolerance            = mp.RelativeTolerance;

            Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
            gn.SetCommandPrompt("Custom render mesh density");
            gn.SetDefaultNumber(relativeTolerance);
            gn.SetLowerLimit(0.0, false);
            gn.SetUpperLimit(1.0, false);
            gn.AcceptNothing(true);
            gn.Get();
            if (gn.CommandResult() != Result.Success)
            {
                return(gn.CommandResult());
            }

            double newTolerance = gn.Number();

            if (newTolerance == relativeTolerance)
            {
                return(Result.Nothing);
            }

            Rhino.Geometry.MeshingParameters new_mp = new Rhino.Geometry.MeshingParameters();
            new_mp = mp;
            new_mp.RelativeTolerance = newTolerance;

            doc.SetCustomMeshingParameters(new_mp);

            // Toggling the meshing parameter style will destroy existing render meshes,
            // which will be recreated when the scene is redrawn.
            if (doc.MeshingParameterStyle == Rhino.Geometry.MeshingParameterStyle.Custom)
            {
                doc.MeshingParameterStyle = Rhino.Geometry.MeshingParameterStyle.Fast;
            }
            doc.MeshingParameterStyle = Rhino.Geometry.MeshingParameterStyle.Custom;

            doc.Views.Redraw();

            return(Result.Success);
        }
示例#3
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select sphere");
            go.GeometryFilter          = Rhino.DocObjects.ObjectType.Surface;
            go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedSurface;
            go.SubObjectSelect         = false;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Brep brep = go.Object(0).Brep();
            if (null == brep || 1 != brep.Faces.Count)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.Surface srf = brep.Faces[0].UnderlyingSurface();
            if (null == srf)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.Sphere sphere;
            if (!srf.TryGetSphere(out sphere))
            {
                RhinoApp.WriteLine("Surface is not a sphere");
                return(Result.Nothing);
            }

            Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
            gn.SetCommandPrompt("New radius");
            gn.SetDefaultNumber(sphere.Radius);
            gn.SetLowerLimit(1.0, false); // or whatever you deem appripriate...
            gn.Get();
            if (gn.CommandResult() != Result.Success)
            {
                return(gn.CommandResult());
            }

            sphere.Radius = gn.Number();

            // Sometimes, Surface.TryGetSphere() will return a sphere with a left-handed
            // plane. So, ensure the plane is right-handed.
            Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(
                sphere.EquitorialPlane.Origin,
                sphere.EquitorialPlane.XAxis,
                sphere.EquitorialPlane.YAxis
                );

            sphere.EquitorialPlane = plane;

            Rhino.Geometry.RevSurface rev_srf = sphere.ToRevSurface();
            if (null != rev_srf)
            {
                doc.Objects.Replace(go.Object(0).ObjectId, rev_srf);
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
    public static Rhino.Commands.Result AddBackgroundBitmap(Rhino.RhinoDoc doc)
    {
        Rhino.RhinoApp.WriteLine("hey");
        // Allow the user to select a bitmap file
        Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog();
        fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg";
        if (!fd.ShowDialog())
        {
            return(Rhino.Commands.Result.Cancel);
        }

        // Verify the file that was selected
        System.Drawing.Image image;
        try
        {
            image = System.Drawing.Image.FromFile(fd.FileName);
        }
        catch (Exception)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Allow the user to pick the bitmap origin
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Bitmap Origin");
        gp.ConstrainToConstructionPlane(true);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Get the view that the point was picked in.
        // This will be the view that the bitmap appears in.
        Rhino.Display.RhinoView view = gp.View();
        if (view == null)
        {
            view = doc.Views.ActiveView;
            if (view == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
        }

        // Allow the user to specify the bitmap with in model units
        Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
        gn.SetCommandPrompt("Bitmap width");
        gn.SetLowerLimit(1.0, false);
        gn.Get();
        if (gn.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gn.CommandResult());
        }

        // Cook up some scale factors
        double w            = gn.Number();
        double image_width  = image.Width;
        double image_height = image.Height;
        double h            = w * (image_height / image_width);

        Rhino.Geometry.Plane plane = view.ActiveViewport.ConstructionPlane();
        plane.Origin = gp.Point();
        view.ActiveViewport.SetTraceImage(fd.FileName, plane, w, h, false, false);
        view.Redraw();
        return(Rhino.Commands.Result.Success);
    }
示例#5
0
        public Rhino.Commands.Result IntersectBrep(Rhino.RhinoDoc doc)
        {
            // Input interval
            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input slicing interval");
            input.Get();
            if (input.CommandResult() != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("Can't obtain interval number");
                return(input.CommandResult());
            }
            double SlicingInterval = input.Number();

            // Select two curves to intersect
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select Brep");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Brep;
            go.GetMultiple(1, 1);

            Rhino.Geometry.Brep    brepA    = null;
            Rhino.Geometry.Surface surfaceB = null;
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("Can't obtain objects");
                return(input.CommandResult());
            }
            brepA = go.Object(0).Brep();

            var go2 = new Rhino.Input.Custom.GetObject();

            go2.SetCommandPrompt("Select surface");
            go2.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            go2.GetMultiple(1, 1);
            if (go2.CommandResult() != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("Can't obtain objects");
                return(input.CommandResult());
            }
            surfaceB = go2.Object(0).Surface();

            // Calculate the intersection
            RhinoApp.WriteLine("Executing the intersection between surfaces");
            const double intersection_tolerance = 0.001;

            Rhino.Geometry.Curve[]   intersectionCurves = null;
            Rhino.Geometry.Point3d[] intersectionPoints = null;
            bool ret = Rhino.Geometry.Intersect.Intersection.BrepSurface(brepA, surfaceB, intersection_tolerance, out intersectionCurves, out intersectionPoints);

            if (ret)
            {
                List <PlanePoint> PlanePoints = new List <PlanePoint>();
                RhinoApp.WriteLine("Success - {0} curves", intersectionCurves.Length);
                for (int i = 0; i < intersectionCurves.Length; i++)
                {
                    Rhino.Geometry.Curve curve = intersectionCurves[i];
                    doc.Objects.AddCurve(curve);
                    RhinoApp.WriteLine("Curve is added");

                    Utility.CreateSections(doc, brepA, surfaceB, curve, SlicingInterval, ref PlanePoints);
                }

                RhinoApp.WriteLine("Success - {0} points", intersectionPoints.Length);
                for (int i = 0; i < intersectionPoints.Length; i++)
                {
                    Rhino.Geometry.Point3d point = intersectionPoints[i];
                    doc.Objects.AddPoint(point);
                    RhinoApp.WriteLine("Point is added");
                }

                if (Utility.SavePlanePoints(@"c:\SlicerPlanePoints.csv", PlanePoints))
                {
                    RhinoApp.WriteLine("Saved SlicerPlanePoints.csv");
                }
            }

            return(Rhino.Commands.Result.Success);
        }
示例#6
0
        public Rhino.Commands.Result AddPoints(Rhino.RhinoDoc doc)
        {
            // Input interval
            double _interval = 0.1;
            double _noise    = 1; // 1% noise

            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input interval(0.0 ~ 1.0)<0.1>");
            Rhino.Input.GetResult res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _interval = input.Number();
            }
            if (_interval == 0.0)
            {
                _interval = 0.1;
            }

            input.SetCommandPrompt("Noise factor(0.0 ~ 100.0)");
            res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _noise = input.Number();
            }

            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select surface");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            res = go.GetMultiple(1, 1024);
            if (res == Rhino.Input.GetResult.Nothing)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Utility.SetOutputCount(10);
            for (int i = 0; i < go.ObjectCount; i++)
            {
                Rhino.Geometry.Surface surfaceA = go.Object(i).Surface();
                if (surfaceA == null)
                {
                    return(Rhino.Commands.Result.Failure);
                }

                Rhino.Geometry.Interval domU = surfaceA.Domain(0);
                Rhino.Geometry.Interval domV = surfaceA.Domain(1);

                double u, v;
                u = v = 0.0;
                for (u = domU.Min; u <= domU.Max; u += _interval)
                {
                    for (v = domV.Min; v <= domV.Max; v += _interval)
                    {
                        Rhino.Geometry.Point3d  pt  = surfaceA.PointAt(u, v);
                        Rhino.Geometry.Vector3d n   = surfaceA.NormalAt(u, v);
                        Rhino.Geometry.Point3d  pt2 = randomPoint(surfaceA, u, v, _interval, _noise);
                        doc.Objects.AddPoint(pt2);
                    }
                }
            }
            return(Rhino.Commands.Result.Success);
        }