public static Result ProjectPointsToBreps(RhinoDoc doc)
    {
        var gs = new GetObject();
        gs.SetCommandPrompt("select surface");
        gs.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.Get();
        if (gs.CommandResult() != Result.Success)
          return gs.CommandResult();
        var brep = gs.Object(0).Brep();
        if (brep == null)
          return Result.Failure;

        var points = Intersection.ProjectPointsToBreps(
                 new List<Brep> {brep}, // brep on which to project
                 new List<Point3d> {new Point3d(0, 0, 0), new Point3d(3,0,3), new Point3d(-2,0,-2)}, // some random points to project
                 new Vector3d(0, 1, 0), // project on Y axis
                 doc.ModelAbsoluteTolerance);

        if (points != null && points.Length > 0)
        {
          foreach (var point in points)
          {
        doc.Objects.AddPoint(point);
          }
        }
        doc.Views.Redraw();
        return Result.Success;
    }
예제 #2
0
    public static Result DrawMesh(RhinoDoc doc)
    {
        var gs = new GetObject();
        gs.SetCommandPrompt("select sphere");
        gs.GeometryFilter = ObjectType.Surface;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.Get();
        if (gs.CommandResult() != Result.Success)
          return gs.CommandResult();

        Sphere sphere;
        gs.Object(0).Surface().TryGetSphere(out sphere);
        if (sphere.IsValid)
        {
          var mesh = Mesh.CreateFromSphere(sphere, 10, 10);
          if (mesh == null)
        return Result.Failure;

          var conduit = new DrawBlueMeshConduit(mesh) {Enabled = true};
          doc.Views.Redraw();

          var in_str = "";
          Rhino.Input.RhinoGet.GetString("press <Enter> to continue", true, ref in_str);

          conduit.Enabled = false;
          doc.Views.Redraw();
          return Result.Success;
        }
        else
          return Result.Failure;
    }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      m_tolerance = doc.ModelAbsoluteTolerance;
      
      // only use a custom geometry filter if no simpler filter does the job

      // only curves
      var gc = new GetObject();
      gc.SetCommandPrompt("select curve");
      gc.GeometryFilter = ObjectType.Curve;
      gc.DisablePreSelect();
      gc.SubObjectSelect = false;
      gc.Get();
      if (gc.CommandResult() != Result.Success)
        return gc.CommandResult();
      if (null == gc.Object(0).Curve())
        return Result.Failure;
      Rhino.RhinoApp.WriteLine("curve was selected");

      // only closed curves
      var gcc = new GetObject();
      gcc.SetCommandPrompt("select closed curve");
      gcc.GeometryFilter = ObjectType.Curve;
      gcc.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve;
      gcc.DisablePreSelect();
      gcc.SubObjectSelect = false;
      gcc.Get();
      if (gcc.CommandResult() != Result.Success)
        return gcc.CommandResult();
      if (null == gcc.Object(0).Curve())
        return Result.Failure;
      Rhino.RhinoApp.WriteLine("closed curve was selected");

      // only circles with a radius of 10
      var gcc10 = new GetObject();
      gcc10.SetCommandPrompt("select circle with radius of 10");
      gc.GeometryFilter = ObjectType.Curve;
      gcc10.SetCustomGeometryFilter(CircleWithRadiusOf10GeometryFilter); // custom geometry filter
      gcc10.DisablePreSelect();
      gcc10.SubObjectSelect = false;
      gcc10.Get();
      if (gcc10.CommandResult() != Result.Success)
        return gcc10.CommandResult();
      if (null == gcc10.Object(0).Curve())
        return Result.Failure;
      RhinoApp.WriteLine("circle with radius of 10 was selected");

      return Result.Success;
    }
    public static Result FilletCurves(RhinoDoc doc)
    {
        var gc1 = new GetObject();
        gc1.DisablePreSelect();
        gc1.SetCommandPrompt("Select first curve to fillet (close to the end you want to fillet)");
        gc1.GeometryFilter = ObjectType.Curve;
        gc1.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
        gc1.Get();
        if (gc1.CommandResult() != Result.Success)
          return gc1.CommandResult();
        var curve1_obj_ref = gc1.Object(0);
        var curve1 = curve1_obj_ref.Curve();
        if (curve1 == null) return Result.Failure;
        var curve1_point_near_end = curve1_obj_ref.SelectionPoint();
        if (curve1_point_near_end == Point3d.Unset)
          return Result.Failure;

        var gc2 = new GetObject();
        gc2.DisablePreSelect();
        gc2.SetCommandPrompt("Select second curve to fillet (close to the end you want to fillet)");
        gc2.GeometryFilter = ObjectType.Curve;
        gc2.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
        gc2.Get();
        if (gc2.CommandResult() != Result.Success)
          return gc2.CommandResult();
        var curve2_obj_ref = gc2.Object(0);
        var curve2 = curve2_obj_ref.Curve();
        if (curve2 == null) return Result.Failure;
        var curve2_point_near_end = curve2_obj_ref.SelectionPoint();
        if (curve2_point_near_end == Point3d.Unset)
          return Result.Failure;

        double radius = 0;
        var rc = RhinoGet.GetNumber("fillet radius", false, ref radius);
        if (rc != Result.Success) return rc;

        var join = false;
        var trim = true;
        var arc_extension = true;
        var fillet_curves = Curve.CreateFilletCurves(curve1, curve1_point_near_end, curve2, curve2_point_near_end, radius,
          join, trim, arc_extension, doc.ModelAbsoluteTolerance, doc.ModelAngleToleranceDegrees);
        if (fillet_curves == null /*|| fillet_curves.Length != 3*/)
          return Result.Failure;

        foreach(var fillet_curve in fillet_curves)
          doc.Objects.AddCurve(fillet_curve);
        doc.Views.Redraw();
        return rc;
    }
    public static Result CurveSurfaceIntersect(RhinoDoc doc)
    {
        var gs = new GetObject();
        gs.SetCommandPrompt("select brep");
        gs.GeometryFilter = ObjectType.Brep;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.Get();
        if (gs.CommandResult() != Result.Success)
          return gs.CommandResult();
        var brep = gs.Object(0).Brep();

        var gc = new GetObject();
        gc.SetCommandPrompt("select curve");
        gc.GeometryFilter = ObjectType.Curve;
        gc.DisablePreSelect();
        gc.SubObjectSelect = false;
        gc.Get();
        if (gc.CommandResult() != Result.Success)
          return gc.CommandResult();
        var curve = gc.Object(0).Curve();

        if (brep == null || curve == null)
          return Result.Failure;

        var tolerance = doc.ModelAbsoluteTolerance;

        Point3d[] intersection_points;
        Curve[] overlap_curves;
        if (!Intersection.CurveBrep(curve, brep, tolerance, out overlap_curves, out intersection_points))
        {
          RhinoApp.WriteLine("curve brep intersection failed");
          return Result.Nothing;
        }

        foreach (var overlap_curve in overlap_curves)
          doc.Objects.AddCurve(overlap_curve);
        foreach (var intersection_point in intersection_points)
          doc.Objects.AddPoint(intersection_point);

        RhinoApp.WriteLine("{0} overlap curves, and {1} intersection points", overlap_curves.Length, intersection_points.Length);
        doc.Views.Redraw();

        return Result.Success;
    }
    public static Result FurthestZOnSurfaceGivenXY(RhinoDoc doc)
    {
        #region user input
        // select a surface
        var gs = new GetObject();
        gs.SetCommandPrompt("select surface");
        gs.GeometryFilter = ObjectType.Surface;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.Get();
        if (gs.CommandResult() != Result.Success)
          return gs.CommandResult();
        // get the brep
        var brep = gs.Object(0).Brep();
        if (brep == null)
          return Result.Failure;

        // get X and Y
        double x = 0.0, y = 0.0;
        var rc = RhinoGet.GetNumber("value of X coordinate", true, ref x);
        if (rc != Result.Success)
          return rc;
        rc = RhinoGet.GetNumber("value of Y coordinate", true, ref y);
        if (rc != Result.Success)
          return rc;
        #endregion

        // an earlier version of this sample used a curve-brep intersection to find Z
        //var maxZ = maxZIntersectionMethod(brep, x, y, doc.ModelAbsoluteTolerance);

        // projecting points is another way to find Z
        var max_z = MaxZProjectionMethod(brep, x, y, doc.ModelAbsoluteTolerance);

        if (max_z != null)
        {
          RhinoApp.WriteLine("Maximum surface Z coordinate at X={0}, Y={1} is {2}", x, y, max_z);
          doc.Objects.AddPoint(new Point3d(x, y, max_z.Value));
          doc.Views.Redraw();
        }
        else
          RhinoApp.WriteLine("no maximum surface Z coordinate at X={0}, Y={1} found.", x, y);

        return Result.Success;
    }
    public static Result ExtendCurve(RhinoDoc doc)
    {
        ObjRef[] boundary_obj_refs;
        var rc = RhinoGet.GetMultipleObjects("Select boundary objects", false, ObjectType.AnyObject, out boundary_obj_refs);
        if (rc != Result.Success)
          return rc;
        if (boundary_obj_refs == null || boundary_obj_refs.Length == 0)
          return Result.Nothing;

        var gc = new GetObject();
        gc.SetCommandPrompt("Select curve to extend");
        gc.GeometryFilter = ObjectType.Curve;
        gc.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
        gc.DisablePreSelect ();
        gc.Get();
        if (gc.CommandResult() != Result.Success)
          return gc.CommandResult();
        var curve_obj_ref = gc.Object(0);

        var curve = curve_obj_ref.Curve();
        if (curve == null) return Result.Failure;
        double t;
        if (!curve.ClosestPoint(curve_obj_ref.SelectionPoint(), out t))
          return Result.Failure;
        var curve_end = t <= curve.Domain.Mid ? CurveEnd.Start : CurveEnd.End;

        var geometry = boundary_obj_refs.Select(obj=> obj.Geometry());
        var extended_curve = curve.Extend(curve_end, CurveExtensionStyle.Line, geometry);
        if (extended_curve != null && extended_curve.IsValid)
        {
          if (!doc.Objects.Replace(curve_obj_ref.ObjectId, extended_curve))
        return Result.Failure;
          doc.Views.Redraw();
        }
        else
        {
          RhinoApp.WriteLine("No boundary object was intersected so curve not extended");
          return Result.Nothing;
        }

        return Result.Success;
    }
예제 #8
0
    public static Result Loft(RhinoDoc doc)
    {
        // select curves to loft
        var gs = new GetObject();
        gs.SetCommandPrompt("select curves to loft");
        gs.GeometryFilter = ObjectType.Curve;
        gs.DisablePreSelect();
        gs.SubObjectSelect = false;
        gs.GetMultiple(2, 0);
        if (gs.CommandResult() != Result.Success)
          return gs.CommandResult();

        var curves = gs.Objects().Select(obj => obj.Curve()).ToList();

        var breps = Brep.CreateFromLoft(curves, Point3d.Unset, Point3d.Unset, LoftType.Tight, false);
        foreach (var brep in breps)
          doc.Objects.AddBrep(brep);

        doc.Views.Redraw();
        return Result.Success;
    }
예제 #9
0
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // select a surface
      var gs = new GetObject();
      gs.SetCommandPrompt("select surface");
      gs.GeometryFilter = ObjectType.Surface;
      gs.DisablePreSelect();
      gs.SubObjectSelect = false;
      gs.Get();
      if (gs.CommandResult() != Result.Success)
        return gs.CommandResult();
      // get the selected face
      var face = gs.Object(0).Face();
      if (face == null)
        return Result.Failure;

      // pick a point on the surface.  Constain
      // picking to the face.
      var gp = new GetPoint();
      gp.SetCommandPrompt("select point on surface");
      gp.Constrain(face, false);
      gp.Get();
      if (gp.CommandResult() != Result.Success)
        return gp.CommandResult();

      // get the parameters of the point on the
      // surface that is clesest to gp.Point()
      double u, v;
      if (face.ClosestPoint(gp.Point(), out u, out v))
      {
        var direction = face.NormalAt(u, v);
        if (face.OrientationIsReversed)
          direction.Reverse();
        RhinoApp.WriteLine(
          string.Format(
            "Surface normal at uv({0:f},{1:f}) = ({2:f},{3:f},{4:f})", 
            u, v, direction.X, direction.Y, direction.Z));
      }
      return Result.Success;
    }