Ejemplo n.º 1
0
        public void Main(ref cSapModel Model)
        {
            if (rhinoCore == null)
            {             // Load Rhino
                try
                {
                    var schemeName = "SAP";
                    rhinoCore = new RhinoCore(new string[] { $"/scheme={schemeName}", "/nosplash" }, WindowStyle.Normal, Process.GetCurrentProcess().MainWindowHandle);
                }
                catch (Exception e)
                {
                    Debug.Fail(e.Source, e.Message);
                    return;
                }
            }


            // RhinoCommon code
            var sphere = new Rhino.Geometry.Sphere(Point3d.Origin, 12000);
            var brep   = sphere.ToBrep();
            var mp     = MeshingParameters.Default;
            var meshes = Rhino.Geometry.Mesh.CreateFromBrep(brep, mp);

            foreach (var mesh in meshes.ToList())
            {
                for (int i = 0; i < mesh.Faces.Count; i++)
                {
                    Point3f a;
                    Point3f b;
                    Point3f c;
                    Point3f d;

                    mesh.Faces.GetFaceVertices(i, out a, out b, out c, out d);

                    List <Point3f> vertices = new List <Point3f>();
                    vertices.Add(a); vertices.Add(b); vertices.Add(c);
                    if (c != d)
                    {
                        vertices.Add(d);
                    }

                    List <string> points = new List <string>();

                    foreach (var v in vertices)
                    {
                        string p = string.Empty;
                        Model.PointObj.AddCartesian(v.X, v.Y, v.Z, ref p);
                        points.Add(p);
                    }

                    string   area = string.Empty;
                    string[] pts  = points.ToArray();
                    Model.AreaObj.AddByPoint(points.Count, ref pts, ref area);
                }
            }
        }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // user input
      ObjRef[] obj_refs;
      var rc = RhinoGet.GetMultipleObjects("Select curve to divide", false, 
        ObjectType.Curve | ObjectType.EdgeFilter, out obj_refs);
      if (rc != Result.Success || obj_refs == null)
        return rc;
  
      double distance_between_divisions = 5;
      rc = RhinoGet.GetNumber("Distance between divisions", false, 
        ref distance_between_divisions, 1.0, Double.MaxValue);
      if (rc != Result.Success)
        return rc;


      // generate the points
      var points = new List<Point3d>();
      foreach (var obj_ref in obj_refs)
      {
        var curve = obj_ref.Curve();
        if (curve == null) return Result.Failure;

        var t0 = curve.Domain.Min;
        points.Add(curve.PointAt(t0));

        var sphere_center = curve.PointAt(t0);
        var t = t0;
        var rest_of_curve = curve;
        while (true)
        {
          var sphere = new Sphere(sphere_center, distance_between_divisions);
          Curve[] overlap_curves;
          Point3d[] intersect_points;
          var b = Intersection.CurveBrep(rest_of_curve, sphere.ToBrep(), 0.0, 
            out overlap_curves, out intersect_points);
          if (!b || (overlap_curves.Length == 0 && intersect_points.Length == 0))
            break;
          double intersect_param;
          Point3d intersect_point;
          NextintersectParamAndPoint(overlap_curves, intersect_points, rest_of_curve,
            out intersect_param, out intersect_point);
          points.Add(intersect_point);
          t = intersect_param;
          sphere_center = intersect_point;
          rest_of_curve = curve.Split(t)[1];
        }
      }
  
      foreach (var point in points)
        doc.Objects.AddPoint(point);
  
      doc.Views.Redraw();
      return Result.Success;
    }
Ejemplo n.º 3
0
        /***************************************************/

        public static void RenderRhinoMeshes(RHG.Sphere sphere, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material)
        {
            pipeline.DrawBrepShaded(sphere.ToBrep(), material);
        }
Ejemplo n.º 4
0
        /***************************************************/

        public static RHG.Mesh CreatePreviewMesh(RHG.Sphere sphere, RHG.MeshingParameters parameters)
        {
            return(CreatePreviewMesh(sphere.ToBrep(), parameters));
        }