/// <summary> /// Intersects two Brep objects and returns the intersection curves. /// </summary> /// <param name="header">The header.</param> /// <param name="inBrep0">The first Brep.</param> /// <param name="inBrep1">The second Brep.</param> /// <param name="tolerance">The intersection tolerance.</param> /// <returns>The intersection curves if successful.</returns> public RockfishGeometry[] IntersectBreps(RockfishHeader header, RockfishGeometry inBrep0, RockfishGeometry inBrep1, double tolerance) { if (null == header) { throw new FaultException("RockfishHeader is null"); } header.Method = nameof(IntersectBreps); RhinoApp.WriteLine("{0} request received from {1}.", header.Method, header.ClientId); using (var item = new RockfishRecord(header)) { if (null == inBrep0?.Brep || null == inBrep1?.Brep) { throw new FaultException("Brep is null"); } var rc = Intersection.BrepBrep(inBrep0.Brep, inBrep1.Brep, tolerance, out Curve[] curves, out Point3d[] points);
/// <summary> /// Called by Rhino when the user wants to run the command. /// </summary> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var rc = RockfishClientPlugIn.VerifyServerHostName(); if (rc != Result.Success) { return(rc); } var go = new GetObject(); go.SetCommandPrompt("Select two surfaces or polysurfaces to intersect"); go.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter; go.SubObjectSelect = false; go.GetMultiple(2, 2); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var brep0 = go.Object(0).Brep(); var brep1 = go.Object(1).Brep(); if (null == brep0 || null == brep1) { return(Result.Failure); } var in_brep0 = new RockfishGeometry(brep0); var in_brep1 = new RockfishGeometry(brep1); RockfishGeometry[] out_curves; try { RockfishClientPlugIn.ServerHostName(); using (var channel = new RockfishClientChannel()) { channel.Create(); out_curves = channel.IntersectBreps(in_brep0, in_brep1, doc.ModelAbsoluteTolerance); } } catch (Exception ex) { RhinoApp.WriteLine(ex.Message); return(Result.Failure); } foreach (var out_curve in out_curves) { if (null != out_curve?.Curve) { var object_id = doc.Objects.AddCurve(out_curve.Curve); var rhino_object = doc.Objects.Find(object_id); rhino_object?.Select(true); } } doc.Views.Redraw(); return(Result.Success); }
/// <summary> /// Main function /// </summary> private static int Main(string[] args) { if (2 != args.Length) { Console.WriteLine("Usage: RockfishConsole <hostname> <filename>"); return(1); } var host_name = LookupHostName(args[0]); if (string.IsNullOrEmpty(host_name)) { Console.WriteLine("Unable to lookup host name: \"{0}\".", args[0]); return(1); } var path = Path.GetFullPath(args[1]); if (!File.Exists(path)) { Console.WriteLine("File not found: \"{0}\".", path); return(1); } var in_file = File3dm.Read(path); if (null == in_file) { Console.WriteLine("Unable to read file: \"{0}\".", path); return(1); } var breps = new List <Brep>(); foreach (var obj in in_file.Objects) { if (obj.Geometry.ObjectType == ObjectType.Brep) { var brep = obj.Geometry as Brep; if (null != brep) { breps.Add(brep); } } else if (obj.Geometry.ObjectType == ObjectType.Extrusion) { var extrusion = obj.Geometry as Extrusion; var brep = extrusion?.ToBrep(true); if (brep != null) { breps.Add(brep); } } } if (0 == breps.Count) { Console.WriteLine("No Breps found in file:: \"{0}\".", path); return(1); } var out_file = new File3dm(); var filename = Path.GetFileNameWithoutExtension(path); var new_filename = $"{filename}_mesh"; var out_path = path.Replace(filename, new_filename); try { using (var channel = new ConsoleChannel(host_name)) { channel.Create(); foreach (var brep in breps) { if (brep.IsValid) { var in_brep = new RockfishGeometry(brep); var out_mesh = channel.CreateMeshFromBrep(in_brep, false); if (null != out_mesh?.Mesh) { out_file.Objects.AddMesh(out_mesh.Mesh); } } } } } catch (Exception ex) { Console.WriteLine(ex.Message); return(1); } out_file.Polish(); out_file.Write(out_path, 5); return(0); }
/// <summary> /// Called by Rhino when the user wants to run the command. /// </summary> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var rc = RockfishClientPlugIn.VerifyServerHostName(); if (rc != Result.Success) { return(rc); } var go = new GetObject(); go.SetCommandPrompt("Select surfaces or polysurfaces mesh"); go.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter; go.SubObjectSelect = false; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var breps = new List <Brep>(); foreach (var obj_ref in go.Objects()) { if (ObjectType.Brep == obj_ref.Geometry().ObjectType) { var brep = obj_ref.Brep(); if (null != brep) { breps.Add(brep); } } else if (ObjectType.Extrusion == obj_ref.Geometry().ObjectType) { var extrusion = obj_ref.Geometry() as Extrusion; var brep = extrusion?.ToBrep(true); if (null != brep) { breps.Add(brep); } } } if (0 == breps.Count) { return(Result.Cancel); } try { using (var channel = new RockfishClientChannel()) { channel.Create(); foreach (var brep in breps) { var in_brep = new RockfishGeometry(brep); var out_mesh = channel.CreateMeshFromBrep(in_brep, false); if (null != out_mesh?.Mesh) { var object_id = doc.Objects.AddMesh(out_mesh.Mesh); var rhino_object = doc.Objects.Find(object_id); rhino_object?.Select(true); } } } } catch (Exception ex) { RhinoApp.WriteLine(ex.Message); return(Result.Failure); } doc.Views.Redraw(); return(Result.Success); }