コード例 #1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Mesh;
            Rhino.DocObjects.ObjRef     objref = null;
            Rhino.Commands.Result       rc     = Rhino.Input.RhinoGet.GetOneObject("Select mesh to contour", false, filter, out objref);
            if (rc != Rhino.Commands.Result.Success || objref == null)
            {
                return(rc);
            }

            Rhino.Geometry.Mesh mesh = objref.Geometry() as Rhino.Geometry.Mesh;
            if (null == mesh)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Geometry.BoundingBox bbox     = mesh.GetBoundingBox(false);
            Rhino.Geometry.Point3d     start_pt = bbox.Corner(true, true, true);
            Rhino.Geometry.Point3d     end_pt   = bbox.Corner(false, true, true);
            double interval = start_pt.DistanceTo(end_pt) / 10;

            Rhino.Geometry.Curve[] curves = Rhino.Geometry.Mesh.CreateContourCurves(mesh, start_pt, end_pt, interval);
            if (null != curves && curves.Length > 0)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    doc.Objects.AddCurve(curves[i]);
                }
                doc.Views.Redraw();
            }

            return(Result.Success);
        }
コード例 #2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Select objects to define block
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select surface or polysurface to box morph");
            go.GeometryFilter  = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Brep;
            go.SubObjectSelect = false;
            go.Get();
            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            Rhino.Geometry.Brep brep = go.Object(0).Brep();
            if (null == brep)
            {
                return(Result.Failure);
            }

            Rhino.Geometry.BoundingBox bbox = brep.GetBoundingBox(true);

            // The original box points
            Rhino.Geometry.Point3d[] box = new Rhino.Geometry.Point3d[8];
            box[0] = bbox.Corner(true, true, true);
            box[1] = bbox.Corner(false, true, true);
            box[2] = bbox.Corner(false, false, true);
            box[3] = bbox.Corner(true, false, true);
            box[4] = bbox.Corner(true, true, false);
            box[5] = bbox.Corner(false, true, false);
            box[6] = bbox.Corner(false, false, false);
            box[7] = bbox.Corner(true, false, false);

            // The modified box points
            Rhino.Geometry.Point3d[] corners = new Rhino.Geometry.Point3d[8];
            corners[0] = box[0];
            corners[1] = box[1];
            corners[2] = box[2];
            corners[3] = box[3];
            corners[4] = box[4];
            corners[5] = box[5];
            corners[6] = box[6] * 2; // some goofy point
            corners[7] = box[7];

            BoxMorph box_morph = new BoxMorph(box, corners);

            if (box_morph.IsValid() && !box_morph.IsIdentity())
            {
                if (box_morph.Morph(brep))
                {
                    doc.Objects.Add(brep);
                    doc.Views.Redraw();
                }
            }

            return(Result.Success);
        }