public override bool ExecConduit(ref MRhinoDisplayPipeline dp, uint nChannel, ref bool bTerminate) { if (nChannel == MSupportChannels.SC_DRAWOVERLAY) { if (null != m_brep) { MRhinoViewport vp = dp.GetRhinoVP(); OnColor saved_color = vp.SetDrawColor(RhUtil.RhinoApp().AppSettings().TrackingColor()); for (int i = 0; i < m_points.Count(); i++) { if (i % 100 == 0 && vp.InterruptDrawing()) { break; } On3dPoint pt = m_points[i]; On3dVector dir = new On3dVector(m_normals[i]); if (m_bFlip) { dir.Reverse(); } vp.DrawDirectionArrow(pt, dir); } vp.SetDrawColor(saved_color); } } return(true); }
/// <summary> /// Convert an object to an On3dPoint /// </summary> static public bool ConvertToOn3dPoint(object pointObj, ref On3dPoint point) { bool rc = false; Array pointArr = pointObj as Array; if (null != pointArr && 3 == pointArr.Length) { try { if (2 == pointArr.Length) { point.x = Convert.ToDouble(pointArr.GetValue(0)); point.y = Convert.ToDouble(pointArr.GetValue(1)); point.z = 0.0; } else if (3 == pointArr.Length) { point.x = Convert.ToDouble(pointArr.GetValue(0)); point.y = Convert.ToDouble(pointArr.GetValue(1)); point.z = Convert.ToDouble(pointArr.GetValue(2)); } rc = point.IsValid(); } catch { // Suppress System.InvalidCastException } } return(rc); }
private static OnSurface CreateNurbsSurface(On3dPoint SW, On3dPoint SE, On3dPoint NE, On3dPoint NW) { OnNurbsSurface pNurbsSurface = new OnNurbsSurface( 3, // dimension (>= 1) false, // not rational 2, // "u" order (>= 2) 2, // "v" order (>= 2) 2, // number of control vertices in "u" dir (>= order) 2 // number of control vertices in "v" dir (>= order) ); // corner CVs in counter clockwise order starting in the south west pNurbsSurface.SetCV(0, 0, SW); pNurbsSurface.SetCV(1, 0, SE); pNurbsSurface.SetCV(1, 1, NE); pNurbsSurface.SetCV(0, 1, NW); // "u" knots pNurbsSurface.SetKnot(0, 0, 0.0); pNurbsSurface.SetKnot(0, 1, 1.0); // "v" knots pNurbsSurface.SetKnot(1, 0, 0.0); pNurbsSurface.SetKnot(1, 1, 1.0); return(pNurbsSurface); }
/// <summary> /// Convert an object to an On3dPoint /// </summary> public static bool ConvertToOn3dPoint(object pointObj, ref On3dPoint point) { bool rc = false; Array pointArr = pointObj as Array; if (null != pointArr && 3 == pointArr.Length) { try { if (2 == pointArr.Length) { point.x = Convert.ToDouble(pointArr.GetValue(0)); point.y = Convert.ToDouble(pointArr.GetValue(1)); point.z = 0.0; } else if (3 == pointArr.Length) { point.x = Convert.ToDouble(pointArr.GetValue(0)); point.y = Convert.ToDouble(pointArr.GetValue(1)); point.z = Convert.ToDouble(pointArr.GetValue(2)); } rc = point.IsValid(); } catch { // Suppress System.InvalidCastException } } return rc; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select solid meshes for volume calculation"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object); go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh); go.EnableSubObjectSelect(false); go.EnableGroupSelect(); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } List <IOnMesh> meshes = new List <IOnMesh>(); for (int i = 0; i < go.ObjectCount(); i++) { IOnMesh mesh = go.Object(i).Mesh(); if (mesh != null) { meshes.Add(mesh); } } if (meshes.Count == 0) { return(IRhinoCommand.result.nothing); } OnBoundingBox bbox = new OnBoundingBox(); for (int i = 0; i < meshes.Count; i++) { meshes[i].GetBoundingBox(ref bbox, 1); } On3dPoint base_point = bbox.Center(); double total_volume = 0.0; double total_error_estimate = 0.0; string msg; for (int i = 0; i < meshes.Count; i++) { double error_estimate = 0.0; double volume = meshes[i].Volume(base_point, ref error_estimate); msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n", i, volume, error_estimate); RhUtil.RhinoApp().Print(msg); total_volume += volume; total_error_estimate += error_estimate; } msg = string.Format("Total volume = {0:f} (+/- {1:f})\n", total_volume, total_error_estimate); RhUtil.RhinoApp().Print(msg); return(IRhinoCommand.result.success); }
public RhinoGetTransform() : base() { m_list = new MRhinoXformObjectList(); m_xform = new OnXform(); m_xform.Identity(); m_bHaveXform = false; m_base = new On3dPoint(); m_base.Set(0, 0, 0); }
public RhinoGetTransform() : base() { m_list = new MRhinoXformObjectList(); m_xform = new OnXform(); m_xform.Identity(); m_bHaveXform = false; m_base = new On3dPoint(); m_base.Set(0,0,0); }
private static OnCurve CreateLinearCurve(On3dPoint from, On3dPoint to) { // creates a 3d line segment to be used as a 3d curve in a ON_Brep OnCurve c3d = new OnLineCurve(from, to); if (c3d != null) { c3d.SetDomain(0.0, 10.0); } return(c3d); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select object to move"); go.EnableSubObjectSelect(false); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } MRhinoGetPoint gp = new MRhinoGetPoint(); gp.SetCommandPrompt("Point to move from"); gp.GetPoint(); if (gp.CommandResult() != IRhinoCommand.result.success) { return(gp.CommandResult()); } On3dPoint pointFrom = gp.Point(); gp.SetCommandPrompt("Point to move to"); gp.SetBasePoint(pointFrom); gp.DrawLineFromPoint(pointFrom, true); gp.GetPoint(); if (gp.CommandResult() != IRhinoCommand.result.success) { return(gp.CommandResult()); } On3dPoint pointTo = gp.Point(); On3dVector dir = new On3dVector(pointTo - pointFrom); if (dir.IsTiny()) { return(IRhinoCommand.result.nothing); } OnXform xform = new OnXform(); xform.Translation(dir); MRhinoObjRef objectRef = go.Object(0); context.m_doc.TransformObject(ref objectRef, xform); context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
public VoxelGrid(RhCommon_Scene ModelSurfaces, List<IOn3dPoint> Pts, int VG_Domain) { VoxelCT = VG_Domain; VoxelInventory = new List<int>[VoxelCT, VoxelCT, VoxelCT]; Voxel = new List<On3dPoint>[VoxelCT, VoxelCT, VoxelCT]; IRhinoObject[] Surfaces = new IRhinoObject[ModelSurfaces.Count()]; OnBoundingBox TightOBox = new OnBoundingBox(); On3dPoint BoxMin = new On3dPoint(); On3dPoint BoxMax = new On3dPoint(); ArrayOn3dPoint Points = new ArrayOn3dPoint(); for (int i = 0; i < Pts.Count; i++) { Points.Append(Pts[i]); } RhUtil.RhinoGetTightBoundingBox(Surfaces, ref TightOBox, false, null); TightOBox.Set(Points, true); OverallBBox = new OnBoundingBox(new On3dPoint(TightOBox.Min().x - 1, TightOBox.Min().y - 1, TightOBox.Min().z - 1), new On3dPoint(TightOBox.Max().x + 1, TightOBox.Max().y + 1, TightOBox.Max().z + 1)); this.X_Incr = (OverallBBox.Max().x - OverallBBox.Min().x) / VoxelCT; this.Y_Incr = (OverallBBox.Max().y - OverallBBox.Min().y) / VoxelCT; this.Z_Incr = (OverallBBox.Max().z - OverallBBox.Min().z) / VoxelCT; //For((int XBox = 0; XBox < VoxelCT; XBox++) Parallel.For(0, VoxelCT, XBox => { RhUtil.RhinoApp().SetStatusBarMessagePane(string.Format("Voxelizing: {0}%", Math.Round((double)XBox / VoxelCT-1, 2) * 100)); for (int YBox = 0; YBox < VoxelCT; YBox++) { for (int ZBox = 0; ZBox < VoxelCT; ZBox++) { BoxMin = new On3dPoint((OverallBBox.Min().x + this.X_Incr * XBox) - X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * YBox) - Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * ZBox) - Z_Incr / 10); BoxMax = new On3dPoint((OverallBBox.Min().x + this.X_Incr * (XBox + 1)) + X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * (YBox + 1)) + Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * (ZBox + 1)) + X_Incr / 10); this.Voxel[XBox, YBox, ZBox] = new List<On3dPoint>(); this.Voxel[XBox, YBox, ZBox].Add(BoxMin); this.Voxel[XBox, YBox, ZBox].Add(BoxMax); this.VoxelInventory[XBox, YBox, ZBox] = new List<int>(); for (int Index = 0; Index < ModelSurfaces.Count(); Index++) { OnBoundingBox TestBox = new OnBoundingBox(); TestBox = new OnBoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]); if (BoxIntersection(ModelSurfaces, TestBox, Index)) { this.VoxelInventory[XBox, YBox, ZBox].Add(Index); } } } } }); }
public VoxelGrid(RhCommon_Scene ModelSurfaces, List <IOn3dPoint> Pts, int VG_Domain) { VoxelCT = VG_Domain; VoxelInventory = new List <int> [VoxelCT, VoxelCT, VoxelCT]; Voxel = new List <On3dPoint> [VoxelCT, VoxelCT, VoxelCT]; IRhinoObject[] Surfaces = new IRhinoObject[ModelSurfaces.Count()]; OnBoundingBox TightOBox = new OnBoundingBox(); On3dPoint BoxMin = new On3dPoint(); On3dPoint BoxMax = new On3dPoint(); ArrayOn3dPoint Points = new ArrayOn3dPoint(); for (int i = 0; i < Pts.Count; i++) { Points.Append(Pts[i]); } RhUtil.RhinoGetTightBoundingBox(Surfaces, ref TightOBox, false, null); TightOBox.Set(Points, true); OverallBBox = new OnBoundingBox(new On3dPoint(TightOBox.Min().x - 1, TightOBox.Min().y - 1, TightOBox.Min().z - 1), new On3dPoint(TightOBox.Max().x + 1, TightOBox.Max().y + 1, TightOBox.Max().z + 1)); this.X_Incr = (OverallBBox.Max().x - OverallBBox.Min().x) / VoxelCT; this.Y_Incr = (OverallBBox.Max().y - OverallBBox.Min().y) / VoxelCT; this.Z_Incr = (OverallBBox.Max().z - OverallBBox.Min().z) / VoxelCT; //For((int XBox = 0; XBox < VoxelCT; XBox++) Parallel.For(0, VoxelCT, XBox => { RhUtil.RhinoApp().SetStatusBarMessagePane(string.Format("Voxelizing: {0}%", Math.Round((double)XBox / VoxelCT - 1, 2) * 100)); for (int YBox = 0; YBox < VoxelCT; YBox++) { for (int ZBox = 0; ZBox < VoxelCT; ZBox++) { BoxMin = new On3dPoint((OverallBBox.Min().x + this.X_Incr * XBox) - X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * YBox) - Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * ZBox) - Z_Incr / 10); BoxMax = new On3dPoint((OverallBBox.Min().x + this.X_Incr * (XBox + 1)) + X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * (YBox + 1)) + Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * (ZBox + 1)) + X_Incr / 10); this.Voxel[XBox, YBox, ZBox] = new List <On3dPoint>(); this.Voxel[XBox, YBox, ZBox].Add(BoxMin); this.Voxel[XBox, YBox, ZBox].Add(BoxMax); this.VoxelInventory[XBox, YBox, ZBox] = new List <int>(); for (int Index = 0; Index < ModelSurfaces.Count(); Index++) { OnBoundingBox TestBox = new OnBoundingBox(); TestBox = new OnBoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]); if (BoxIntersection(ModelSurfaces, TestBox, Index)) { this.VoxelInventory[XBox, YBox, ZBox].Add(Index); } } } } }); }
public override bool CalculateTransform(MRhinoViewport vp, IOn3dPoint point, ref OnXform xform) { bool bResult = false; On3dVector v = new On3dVector(); On3dPoint pt = new On3dPoint(point); v = pt - m_base; if (!v.IsZero()) { xform.Translation(v); bResult = xform.IsValid(); } return(bResult); }
/// <summary> /// Intesects all NURBS Surfaces with Voxels. /// </summary> /// <param name="Model">the scene.</param> /// <param name="Box">the voxel</param> /// <param name="Index">the index of the surface to test.</param> /// <returns></returns> private bool BoxIntersection(RhCommon_Scene Model, OnBoundingBox Box, int Index) { On3dPoint Center = Box.Center(); double Radius = Center.DistanceTo(Box.Min()); double s = 0; double t = 0; On3dPoint point = new On3dPoint(); if (RhUtil.RhinoBrepClosestPoint(Model.Brep(Index), Center, new OnCOMPONENT_INDEX(), ref s, ref t, point, Radius)) //if (Center.DistanceTo(point) < Radius) { return(true); } return(false); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select surface"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object); go.EnableSubObjectSelect(false); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } IOnSurface srf = go.Object(0).Surface(); if (null == srf) { return(IRhinoCommand.result.failure); } IOnNurbsSurface ns = srf.NurbsSurface(); if (null == ns) { RhUtil.RhinoApp().Print("Not a NURBS surface.\n"); return(IRhinoCommand.result.nothing); } On3dPoint cv = new On3dPoint(); string str = string.Empty; for (int u = 0; u < ns.CVCount(0); u++) { for (int v = 0; v < ns.CVCount(1); v++) { if (ns.GetCV(u, v, ref cv)) { str = string.Empty; RhUtil.RhinoFormatPoint(cv, ref str); RhUtil.RhinoApp().Print(string.Format("CV({0},{1}) = {2}\n", u, v, str)); } } } return(IRhinoCommand.result.success); }
/// <summary> /// Convert an object to an On3dPointArray /// </summary> public static bool ConvertToOn3dPointArray(object pointsObj, ref On3dPointArray points) { bool rc = false; int pointsCount = points.Count(); Array pointsArr = pointsObj as Array; if (null != pointsArr) { for (int i = 0; i < pointsArr.Length; i++) { On3dPoint point = new On3dPoint(); if (SampleCsRhinoScriptUtils.ConvertToOn3dPoint(pointsArr.GetValue(i), ref point)) points.Append(point); } rc = (points.Count() - pointsCount > 0); } return rc; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { On3dPoint center = new On3dPoint(OnUtil.On_origin); OnSphere sphere = new OnSphere(center, 5.0); OnMesh mesh = RhUtil.RhinoMeshSphere(sphere, 10, 10); MRhinoMeshObject mesh_obj = context.m_doc.AddMeshObject(mesh); context.m_doc.Redraw(); MRhinoGetString gs = new MRhinoGetString(); gs.SetCommandPrompt("Press <Enter> to continue"); gs.AcceptNothing(); gs.GetString(); context.m_doc.DeleteObject(new MRhinoObjRef(mesh_obj)); context.m_doc.Redraw(); return IRhinoCommand.result.success; }
private void button1_Click(object sender, EventArgs e) { // Since our form is modeless, the user can run commands // while our form is visible, including the Open command, // which closes the current document and opens a new one. // Thus, it's best to always ask for the active document // instead of maintaining a reference to the document passed // to the command that created this form. MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc(); if (null != doc) { On3dPoint a = new On3dPoint(0.0, 0.0, 0.0); On3dPoint b = new On3dPoint(5.0, 5.0, 5.0); OnLine line = new OnLine(a, b); doc.AddCurveObject(line); doc.Redraw(); } }
/// <summary> /// Add a 3-D point to the document /// </summary> public object AddPoint(object pointObj) { On3dPoint point = new On3dPoint(); if (SampleCsRhinoScriptUtils.ConvertToOn3dPoint(pointObj, ref point)) { MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc(); if (null != doc) { MRhinoObject rhinoObj = doc.AddPointObject(point); if (null != rhinoObj) { doc.Redraw(); return rhinoObj.ModelObjectId().ToString(); } } } return null; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select rectangular light"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } IOnLight light = go.Object(0).Light(); if (null == light) { return(IRhinoCommand.result.failure); } if (!light.IsRectangularLight()) { RhUtil.RhinoApp().Print("Not a rectangular light.\n"); return(IRhinoCommand.result.nothing); } On3dPoint origin = light.Location(); On3dVector xaxis = light.Length(); On3dVector yaxis = light.Width(); OnPlane plane = new OnPlane(origin, xaxis, yaxis); OnInterval x_interval = new OnInterval(0.0, xaxis.Length()); OnInterval y_interval = new OnInterval(0.0, yaxis.Length()); OnMesh mesh = RhUtil.RhinoMeshPlane(plane, x_interval, y_interval, 2, 2); if (null != mesh) { mesh.ConvertQuadsToTriangles(); context.m_doc.AddMeshObject(mesh); context.m_doc.Redraw(); } return(IRhinoCommand.result.cancel); }
private void button1_Click(object sender, EventArgs e) { // Since our form is modeless, the user can run commands // while our form is visible, including the Open command, // which closes the current document and opens a new one. // Thus, it's best to always ask for the active document // instead of maintaining a reference to the document passed // to the command that created this form. MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc(); if (null != doc) { On3dPoint a = new On3dPoint(0.0, 0.0, 0.0); On3dPoint b = new On3dPoint(5.0, 5.0, 5.0); OnLine line = new OnLine(a, b); doc.AddCurveObject(line); doc.Redraw(); } }
/// <summary> /// Add a 3-D point to the document /// </summary> public object AddPoint(object pointObj) { On3dPoint point = new On3dPoint(); if (SampleCsRhinoScriptUtils.ConvertToOn3dPoint(pointObj, ref point)) { MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc(); if (null != doc) { MRhinoObject rhinoObj = doc.AddPointObject(point); if (null != rhinoObj) { doc.Redraw(); return(rhinoObj.ModelObjectId().ToString()); } } } return(null); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { On3dPoint center = new On3dPoint(OnUtil.On_origin); OnSphere sphere = new OnSphere(center, 5.0); OnMesh mesh = RhUtil.RhinoMeshSphere(sphere, 10, 10); MRhinoMeshObject mesh_obj = context.m_doc.AddMeshObject(mesh); context.m_doc.Redraw(); MRhinoGetString gs = new MRhinoGetString(); gs.SetCommandPrompt("Press <Enter> to continue"); gs.AcceptNothing(); gs.GetString(); context.m_doc.DeleteObject(new MRhinoObjRef(mesh_obj)); context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
private static double GetCurveArea(IOnCurve crv, double tol) { double area = 0.0; if (null != crv && crv.IsClosed()) { OnPlane plane = new OnPlane(); if (crv.IsPlanar(plane, tol)) { OnBoundingBox bbox = crv.BoundingBox(); On3dPoint point = plane.ClosestPointTo(bbox.Center()); OnMassProperties mp = new OnMassProperties(); if (crv.AreaMassProperties(point, plane.Normal(), ref mp)) { area = Math.Abs(mp.Area()); } } } return(area); }
/// <summary> /// Convert an object to an On3dPointArray /// </summary> static public bool ConvertToOn3dPointArray(object pointsObj, ref On3dPointArray points) { bool rc = false; int pointsCount = points.Count(); Array pointsArr = pointsObj as Array; if (null != pointsArr) { for (int i = 0; i < pointsArr.Length; i++) { On3dPoint point = new On3dPoint(); if (SampleCsRhinoScriptUtils.ConvertToOn3dPoint(pointsArr.GetValue(i), ref point)) { points.Append(point); } } rc = (points.Count() - pointsCount > 0); } return(rc); }
///<summary> /// This gets called when when the user runs this command. ///</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetFileDialog dlg = new MRhinoGetFileDialog(); if (dlg.DisplayFileDialog(IRhinoGetFileDialog.file_dialog_type.open_text_file_dialog)) { string filename = dlg.FileName(); string line = ""; RhUtil.RhinoApp().Print(string.Format("Opening file {0}.\n", filename)); char[] delim = new char[2]; delim[0] = ','; delim[1] = '\0'; On3dPointArray points = new On3dPointArray(8); StreamReader reader = new StreamReader(filename); line = reader.ReadLine(); while (line != null && line.Length > 0) { string[] substrs = line.Split(delim); if (substrs.Length == 3) { On3dPoint p = new On3dPoint(); p.x = double.Parse(substrs[0]); p.y = double.Parse(substrs[1]); p.z = double.Parse(substrs[2]); points.Append(p); } line = reader.ReadLine(); } OnNurbsCurve curve = RhUtil.RhinoInterpCurve(3, points, null, null, 1); context.m_doc.AddCurveObject(curve); reader.Close(); } context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
///<summary> /// This gets called when when the user runs this command. ///</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetFileDialog dlg = new MRhinoGetFileDialog(); if (dlg.DisplayFileDialog(IRhinoGetFileDialog.file_dialog_type.open_text_file_dialog)) { string filename = dlg.FileName(); string line = ""; RhUtil.RhinoApp().Print(string.Format("Opening file {0}.\n", filename)); char[] delim = new char[2]; delim[0] = ','; delim[1] = '\0'; On3dPointArray points = new On3dPointArray(8); StreamReader reader = new StreamReader(filename); line = reader.ReadLine(); while(line != null && line.Length > 0) { string[] substrs = line.Split(delim); if(substrs.Length == 3) { On3dPoint p = new On3dPoint(); p.x = double.Parse(substrs[0]); p.y = double.Parse(substrs[1]); p.z = double.Parse(substrs[2]); points.Append(p); } line = reader.ReadLine(); } OnNurbsCurve curve = RhUtil.RhinoInterpCurve(3, points, null, null, 1); context.m_doc.AddCurveObject(curve); reader.Close(); } context.m_doc.Redraw(); return IRhinoCommand.result.success; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select surface"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object); go.EnableSubObjectSelect(false); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); IOnSurface srf = go.Object(0).Surface(); if (null == srf) return IRhinoCommand.result.failure; IOnNurbsSurface ns = srf.NurbsSurface(); if (null == ns) { RhUtil.RhinoApp().Print("Not a NURBS surface.\n"); return IRhinoCommand.result.nothing; } On3dPoint cv = new On3dPoint(); string str = string.Empty; for (int u = 0; u < ns.CVCount(0); u++) { for (int v = 0; v < ns.CVCount(1); v++) { if (ns.GetCV(u, v, ref cv)) { str = string.Empty; RhUtil.RhinoFormatPoint(cv, ref str); RhUtil.RhinoApp().Print(string.Format("CV({0},{1}) = {2}\n", u, v, str)); } } } return IRhinoCommand.result.success; }
private static OnSurface CreateNurbsSurface(On3dPoint SW, On3dPoint SE, On3dPoint NE, On3dPoint NW) { OnNurbsSurface pNurbsSurface = new OnNurbsSurface( 3, // dimension (>= 1) false, // not rational 2, // "u" order (>= 2) 2, // "v" order (>= 2) 2, // number of control vertices in "u" dir (>= order) 2 // number of control vertices in "v" dir (>= order) ); // corner CVs in counter clockwise order starting in the south west pNurbsSurface.SetCV(0, 0, SW); pNurbsSurface.SetCV(1, 0, SE); pNurbsSurface.SetCV(1, 1, NE); pNurbsSurface.SetCV(0, 1, NW); // "u" knots pNurbsSurface.SetKnot(0, 0, 0.0); pNurbsSurface.SetKnot(0, 1, 1.0); // "v" knots pNurbsSurface.SetKnot(1, 0, 0.0); pNurbsSurface.SetKnot(1, 1, 1.0); return pNurbsSurface; }
private static OnCurve CreateLinearCurve(On3dPoint from, On3dPoint to) { // creates a 3d line segment to be used as a 3d curve in a ON_Brep OnCurve c3d = new OnLineCurve(from, to); if (c3d != null) c3d.SetDomain(0.0, 10.0); return c3d; }
/// <summary> /// This gets called when when the user runs this command. /// </summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Select objects to animate MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects to animate"); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); // Select path curve MRhinoGetObject gc = new MRhinoGetObject(); gc.SetCommandPrompt("Select path curve"); gc.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); gc.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve); gc.EnableDeselectAllBeforePostSelect(false); gc.GetObjects(1, 1); if (gc.CommandResult() != IRhinoCommand.result.success) return gc.CommandResult(); // Get the curve IOnCurve crv = gc.Object(0).Curve(); if (null == crv ) return IRhinoCommand.result.failure; // Create an array of normalized curve parameters List<double> slist = new List<double>(m_max_steps); for (int i = 0; i < m_max_steps; i++ ) { double s = (double)i / ( (double)m_max_steps - 1 ); slist.Add(s); } // Get the real parameters along the curve double[] tlist = new double[m_max_steps]; if (!crv.GetNormalizedArcLengthPoints(slist.ToArray(), ref tlist)) return IRhinoCommand.result.failure; // Create the display conduit SampleCsAnimatorConduit conduit = new SampleCsAnimatorConduit(); // Get points along curve On3dPoint start = new On3dPoint(crv.PointAtStart()); List<On3dPoint> plist = new List<On3dPoint>(tlist.Length); for (int i = 0; i < m_max_steps; i++) { On3dPoint pt = new On3dPoint(crv.PointAt(tlist[i])); plist.Add(pt); } // Hide objects and add them to conduit's object array for (int i = 0; i < go.ObjectCount(); i++ ) { MRhinoObjRef objref = go.Object(i); context.m_doc.HideObject(objref); conduit.m_objects.Add(objref.Object()); } // Do animation... conduit.Enable(); for (int i = 0; i < m_max_steps; i++) { On3dVector v = plist[i] - start; conduit.m_xform.Translation(v); context.m_doc.Redraw(); Thread.Sleep(100); } for (int i = m_max_steps - 1; i >= 0; i--) { On3dVector v = plist[i] - start; conduit.m_xform.Translation(v); if (0 != i) { context.m_doc.Redraw(); Thread.Sleep(100); } } conduit.Disable(); // Show hidden objects for (int i = 0; i < go.ObjectCount(); i++) { MRhinoObjRef objref = go.Object(i); context.m_doc.ShowObject(objref); } context.m_doc.Redraw(); return IRhinoCommand.result.success; }
/// <summary> /// The one and only MakeTwistedCube /// </summary> static OnBrep MakeTwistedCube() { /* This example demonstrates how to construct a OnBrep with the topology shown below. H-------e6-------G / /| / | / | / e7 / e5 / | / | / e10 | / | / | e11 E- - e4- -/- - - F / / / / / / / D---------e2-----C e9 | / | / | e8 | / e3 / e1 / | | / | / | / | |/ A-------e0-------B */ On3dPoint[] points = new On3dPoint[8]; points[0] = new On3dPoint(0.0, 0.0, 0.0); // point A = geometry for vertex 0 points[1] = new On3dPoint(10.0, 0.0, 0.0); // point B = geometry for vertex 1 points[2] = new On3dPoint(10.0, 8.0, -1.0); // point C = geometry for vertex 2 points[3] = new On3dPoint(0.0, 6.0, 0.0); // point D = geometry for vertex 3 points[4] = new On3dPoint(1.0, 2.0, 11.0); // point E = geometry for vertex 4 points[5] = new On3dPoint(10.0, 0.0, 12.0); // point F = geometry for vertex 5 points[6] = new On3dPoint(10.0, 7.0, 13.0); // point G = geometry for vertex 6 points[7] = new On3dPoint(0.0, 6.0, 12.0); // point H = geometry for vertex 7 OnBrep brep = new OnBrep(); // Create eight vertices located at the eight points int vi; for (vi = 0; vi < 8; vi++) { OnBrepVertex v = brep.NewVertex(points[vi]); v.m_tolerance = 0.0; } // Create 3d curve geometry - the orientations are arbitrarily chosen // so that the end vertices are in alphabetical order. brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[B])); // line AB brep.m_C3.Append(TwistedCubeEdgeCurve(points[B], points[C])); // line BC brep.m_C3.Append(TwistedCubeEdgeCurve(points[C], points[D])); // line CD brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[D])); // line AD brep.m_C3.Append(TwistedCubeEdgeCurve(points[E], points[F])); // line EF brep.m_C3.Append(TwistedCubeEdgeCurve(points[F], points[G])); // line FG brep.m_C3.Append(TwistedCubeEdgeCurve(points[G], points[H])); // line GH brep.m_C3.Append(TwistedCubeEdgeCurve(points[E], points[H])); // line EH brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[E])); // line AE brep.m_C3.Append(TwistedCubeEdgeCurve(points[B], points[F])); // line BF brep.m_C3.Append(TwistedCubeEdgeCurve(points[C], points[G])); // line CG brep.m_C3.Append(TwistedCubeEdgeCurve(points[D], points[H])); // line DH // Create the 12 edges that connect the corners of the cube. MakeTwistedCubeEdges(ref brep); // Create 3d surface geometry - the orientations are arbitrarily chosen so // that some normals point into the cube and others point out of the cube. brep.m_S.Append(TwistedCubeSideSurface(points[A], points[B], points[C], points[D])); // ABCD brep.m_S.Append(TwistedCubeSideSurface(points[B], points[C], points[G], points[F])); // BCGF brep.m_S.Append(TwistedCubeSideSurface(points[C], points[D], points[H], points[G])); // CDHG brep.m_S.Append(TwistedCubeSideSurface(points[A], points[D], points[H], points[E])); // ADHE brep.m_S.Append(TwistedCubeSideSurface(points[A], points[B], points[F], points[E])); // ABFE brep.m_S.Append(TwistedCubeSideSurface(points[E], points[F], points[G], points[H])); // EFGH // Create the CRhinoBrepFaces MakeTwistedCubeFaces(ref brep); if (!brep.IsValid()) return null; return brep; }
/// <summary> /// The one and only MakeTwistedCube /// </summary> static OnBrep MakeTwistedCube() { /* * This example demonstrates how to construct a OnBrep * with the topology shown below. * * H-------e6-------G * / /| * / | / | * / e7 / e5 * / | / | * / e10 | * / | / | * e11 E- - e4- -/- - - F * / / / * / / / / * D---------e2-----C e9 | / | / | e8 | / | e3 / e1 / | | / | / | / | |/ | A-------e0-------B | */ On3dPoint[] points = new On3dPoint[8]; points[0] = new On3dPoint(0.0, 0.0, 0.0); // point A = geometry for vertex 0 points[1] = new On3dPoint(10.0, 0.0, 0.0); // point B = geometry for vertex 1 points[2] = new On3dPoint(10.0, 8.0, -1.0); // point C = geometry for vertex 2 points[3] = new On3dPoint(0.0, 6.0, 0.0); // point D = geometry for vertex 3 points[4] = new On3dPoint(1.0, 2.0, 11.0); // point E = geometry for vertex 4 points[5] = new On3dPoint(10.0, 0.0, 12.0); // point F = geometry for vertex 5 points[6] = new On3dPoint(10.0, 7.0, 13.0); // point G = geometry for vertex 6 points[7] = new On3dPoint(0.0, 6.0, 12.0); // point H = geometry for vertex 7 OnBrep brep = new OnBrep(); // Create eight vertices located at the eight points int vi; for (vi = 0; vi < 8; vi++) { OnBrepVertex v = brep.NewVertex(points[vi]); v.m_tolerance = 0.0; } // Create 3d curve geometry - the orientations are arbitrarily chosen // so that the end vertices are in alphabetical order. brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[B])); // line AB brep.m_C3.Append(TwistedCubeEdgeCurve(points[B], points[C])); // line BC brep.m_C3.Append(TwistedCubeEdgeCurve(points[C], points[D])); // line CD brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[D])); // line AD brep.m_C3.Append(TwistedCubeEdgeCurve(points[E], points[F])); // line EF brep.m_C3.Append(TwistedCubeEdgeCurve(points[F], points[G])); // line FG brep.m_C3.Append(TwistedCubeEdgeCurve(points[G], points[H])); // line GH brep.m_C3.Append(TwistedCubeEdgeCurve(points[E], points[H])); // line EH brep.m_C3.Append(TwistedCubeEdgeCurve(points[A], points[E])); // line AE brep.m_C3.Append(TwistedCubeEdgeCurve(points[B], points[F])); // line BF brep.m_C3.Append(TwistedCubeEdgeCurve(points[C], points[G])); // line CG brep.m_C3.Append(TwistedCubeEdgeCurve(points[D], points[H])); // line DH // Create the 12 edges that connect the corners of the cube. MakeTwistedCubeEdges(ref brep); // Create 3d surface geometry - the orientations are arbitrarily chosen so // that some normals point into the cube and others point out of the cube. brep.m_S.Append(TwistedCubeSideSurface(points[A], points[B], points[C], points[D])); // ABCD brep.m_S.Append(TwistedCubeSideSurface(points[B], points[C], points[G], points[F])); // BCGF brep.m_S.Append(TwistedCubeSideSurface(points[C], points[D], points[H], points[G])); // CDHG brep.m_S.Append(TwistedCubeSideSurface(points[A], points[D], points[H], points[E])); // ADHE brep.m_S.Append(TwistedCubeSideSurface(points[A], points[B], points[F], points[E])); // ABFE brep.m_S.Append(TwistedCubeSideSurface(points[E], points[F], points[G], points[H])); // EFGH // Create the CRhinoBrepFaces MakeTwistedCubeFaces(ref brep); if (!brep.IsValid()) { return(null); } return(brep); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Select a curve object MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select curve"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } // Validate the selection IRhinoObject obj = go.Object(0).Object(); if (null == obj) { return(IRhinoCommand.result.failure); } // Get the active view MRhinoView view = RhUtil.RhinoApp().ActiveView(); if (null == view) { return(IRhinoCommand.result.failure); } // Get the construction plane from the active view OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane); // Create a construction plane aligned bounding box OnBoundingBox bbox = new OnBoundingBox(); IRhinoObject[] objs = new IRhinoObject[1] { obj }; bool rc = RhUtil.RhinoGetTightBoundingBox(objs, ref bbox, false, plane); if (rc == false) { return(IRhinoCommand.result.failure); } // Validate bounding box if (0 != bbox.IsDegenerate()) { RhUtil.RhinoApp().Print("Curve's tight bounding box is degenerate.\n"); return(IRhinoCommand.result.nothing); } // ON_BrepBox wants 8 points defining the box corners // arranged in this order: // // v7______________v6 // |\ |\ // | \ | \ // | \ _____________\ // | v4 | v5 // | | | | // | | | | // v3---|---------v2 | // \ | \ | // \ | \ | // \ | \ | // \v0____________\v1 // On3dPoint[] box_corners = new On3dPoint[8]; box_corners[0] = bbox.Corner(0, 0, 0); box_corners[1] = bbox.Corner(1, 0, 0); box_corners[2] = bbox.Corner(1, 1, 0); box_corners[3] = bbox.Corner(0, 1, 0); box_corners[4] = bbox.Corner(0, 0, 1); box_corners[5] = bbox.Corner(1, 0, 1); box_corners[6] = bbox.Corner(1, 1, 1); box_corners[7] = bbox.Corner(0, 1, 1); // Transform points to the world-xy plane OnXform p2w = new OnXform(); p2w.ChangeBasis(plane, OnUtil.On_xy_plane); for (int i = 0; i < 8; i++) { box_corners[i].Transform(p2w); } // Make a brep box OnBrep brep = OnUtil.ON_BrepBox(box_corners); if (null != brep) { context.m_doc.AddBrepObject(brep); context.m_doc.Redraw(); } return(IRhinoCommand.result.success); }
///////////////////////////////////////////////////////////////////////// // Overridden MRhinoGetPoint::SetBasePoint public new void SetBasePoint(IOn3dPoint base_point) { m_base = (On3dPoint)base_point; base.SetBasePoint(base_point); }
/// <summary> /// The one and only MakeBox /// </summary> static OnBrep MakeBox() { /* This example demonstrates how to construct a OnBrep with the topology shown below. v7_______e6_____v6 |\ |\ | e7 | e5 | \ ______e4_____\ e11 v4 | v5 | | e10 | | | | | v3---|---e2----v2 e9 \ e8 \ | e3 | e1 | \ | \ | \v0_____e0_____\v1 */ On3dPoint[] points = new On3dPoint[8]; points[0] = new On3dPoint(0.0, 0.0, 0.0); points[1] = new On3dPoint(10.0, 0.0, 0.0); points[2] = new On3dPoint(10.0, 10.0, 0.0); points[3] = new On3dPoint(0.0, 10.0, 0.0); points[4] = new On3dPoint(0.0, 0.0, 10.0); points[5] = new On3dPoint(10.0, 0.0, 10.0); points[6] = new On3dPoint(10.0, 10.0, 10.0); points[7] = new On3dPoint(0.0, 10.0, 10.0); OnBrep brep = new OnBrep(); int vi = 0, ei = 0, fi = 0, si = 0, c2i = 0; for (vi = 0; vi < 8; vi++) brep.NewVertex(points[vi], 0.0); for (ei = 0; ei < 4; ei++) { OnBrepVertex v0 = brep.m_V[ei]; OnBrepVertex v1 = brep.m_V[(ei + 1) % 4]; brep.m_C3.Append(new OnLineCurve(v0.point, v1.point)); brep.NewEdge(ref v0, ref v1, ei, null, 0.0); } for (ei = 4; ei < 8; ei++) { OnBrepVertex v0 = brep.m_V[ei]; OnBrepVertex v1 = brep.m_V[ei == 7 ? 4 : (ei + 1)]; brep.m_C3.Append(new OnLineCurve(v0.point, v1.point)); brep.NewEdge(ref v0, ref v1, ei, null, 0.0); } for (ei = 8; ei < 12; ei++) { OnBrepVertex v0 = brep.m_V[ei - 8]; OnBrepVertex v1 = brep.m_V[ei - 4]; brep.m_C3.Append(new OnLineCurve(v0.point, v1.point)); brep.NewEdge(ref v0, ref v1, ei, null, 0.0); } OnBrepBoxFaceInfo[] f = new OnBrepBoxFaceInfo[6]; f[0] = new OnBrepBoxFaceInfo(0, 9, 4, 8, false, false, true, true); f[1] = new OnBrepBoxFaceInfo(1, 10, 5, 9, false, false, true, true); f[2] = new OnBrepBoxFaceInfo(2, 11, 6, 10, false, false, true, true); f[3] = new OnBrepBoxFaceInfo(3, 8, 7, 11, false, false, true, true); f[4] = new OnBrepBoxFaceInfo(3, 2, 1, 0, true, true, true, true); f[5] = new OnBrepBoxFaceInfo(4, 5, 6, 7, false, false, false, false); for (fi = 0; fi < 6; fi++ ) { OnBrepEdge e0 = brep.m_E[f[fi].e[0]]; OnBrepEdge e1 = brep.m_E[f[fi].e[1]]; OnBrepEdge e2 = brep.m_E[f[fi].e[2]]; OnBrepEdge e3 = brep.m_E[f[fi].e[3]]; OnBrepVertex v0 = brep.m_V[e0.get_m_vi(f[fi].bRev[0] ? 1 : 0)]; OnBrepVertex v1 = brep.m_V[e1.get_m_vi(f[fi].bRev[1] ? 1 : 0)]; OnBrepVertex v2 = brep.m_V[e2.get_m_vi(f[fi].bRev[2] ? 1 : 0)]; OnBrepVertex v3 = brep.m_V[e3.get_m_vi(f[fi].bRev[3] ? 1 : 0)]; si = brep.AddSurface(OnUtil.ON_NurbsSurfaceQuadrilateral(v0.point, v1.point, v2.point, v3.point)); OnInterval s = brep.m_S[si].Domain(0); OnInterval t = brep.m_S[si].Domain(1); On2dPoint p0 = new On2dPoint(s[0], t[0]); On2dPoint p1 = new On2dPoint(s[1], t[0]); On2dPoint p2 = new On2dPoint(s[1], t[1]); On2dPoint p3 = new On2dPoint(s[0], t[1]); OnBrepFace face = brep.NewFace(si); OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.outer, ref face); loop.m_pbox.m_min.x = s[0]; loop.m_pbox.m_min.y = t[0]; loop.m_pbox.m_min.z = 0.0; loop.m_pbox.m_max.x = s[1]; loop.m_pbox.m_max.y = t[1]; loop.m_pbox.m_max.z = 0.0; // south side of surface c2i = brep.AddTrimCurve(new OnLineCurve(p0, p1)); OnBrepTrim trim0 = brep.NewTrim(ref e0, f[fi].bRev[0], ref loop, c2i); trim0.set_m_tolerance(0, 0.0); trim0.set_m_tolerance(1, 0.0); trim0.m_type = (trim0.get_m_vi(0) != trim0.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular; trim0.m_iso = IOnSurface.ISO.S_iso; // east side of surface c2i = brep.AddTrimCurve(new OnLineCurve(p1, p2)); OnBrepTrim trim1 = brep.NewTrim(ref e1, f[fi].bRev[1], ref loop, c2i); trim1.set_m_tolerance(0, 0.0); trim1.set_m_tolerance(1, 0.0); trim1.m_type = (trim1.get_m_vi(0) != trim1.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular; trim1.m_iso = IOnSurface.ISO.E_iso; // north side of surface c2i = brep.AddTrimCurve(new OnLineCurve(p2, p3)); OnBrepTrim trim2 = brep.NewTrim(ref e2, f[fi].bRev[2], ref loop, c2i); trim2.set_m_tolerance(0, 0.0); trim2.set_m_tolerance(1, 0.0); trim2.m_type = (trim2.get_m_vi(0) != trim2.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular; trim2.m_iso = IOnSurface.ISO.N_iso; // west side of surface c2i = brep.AddTrimCurve(new OnLineCurve(p3, p0)); OnBrepTrim trim3 = brep.NewTrim(ref e3, f[fi].bRev[3], ref loop, c2i); trim3.set_m_tolerance(0, 0.0); trim3.set_m_tolerance(1, 0.0); trim3.m_type = (trim3.get_m_vi(0) != trim3.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular; trim3.m_iso = IOnSurface.ISO.W_iso; } if (!brep.IsValid()) return null; return brep; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Define geometry for rail and shape curves On3dPoint start_point = new On3dPoint(0, 0, 0); On3dPoint end_point = new On3dPoint(10, 0, 0); OnPlane plane = new OnPlane(OnUtil.On_yz_plane); plane.SetOrigin(start_point); OnCircle circle0 = new OnCircle(plane, 5); plane.SetOrigin(end_point); OnCircle circle1 = new OnCircle(plane, 2); // Build rail and shape curves OnLineCurve line_curve = new OnLineCurve(start_point, end_point); OnArcCurve arc_curve0 = new OnArcCurve(circle0); OnArcCurve arc_curve1 = new OnArcCurve(circle1); // Build poly edge curve MRhinoPolyEdge rail_curve = new MRhinoPolyEdge(); rail_curve.Create(line_curve); // Create sweep arguments MArgsRhinoSweep1 args = new MArgsRhinoSweep1(); // Add rail curve and related settings args.m_rail_curve = rail_curve; args.m_bHaveRailPickPoint = false; args.m_bClosed = false; args.m_bUsePivotPoint = false; // Add shape curves List <OnCurve> shape_curves = new List <OnCurve>(); shape_curves.Add(arc_curve0); shape_curves.Add(arc_curve1); args.m_shape_curves = shape_curves.ToArray(); // Specify parameters on rail closest to shapes args.m_rail_params.Append(rail_curve.Domain()[0]); args.m_rail_params.Append(rail_curve.Domain()[1]); // No starting sweep point args.set_m_bUsePoints(0, 0); // No ending sweep point args.set_m_bUsePoints(1, 0); // 0 = Freeform args.m_style = 0; // 0 = Do Not Simplify args.m_simplify = 0; // Sample point count for rebuilding shapes args.m_rebuild_count = -1; // 0 = don't miter args.m_miter_type = 0; // Standard tolerances args.m_refit_tolerance = context.m_doc.AbsoluteTolerance(); args.m_sweep_tolerance = context.m_doc.AbsoluteTolerance(); args.m_angle_tolerance = context.m_doc.AngleToleranceRadians(); OnBrep[] breps = null; if (RhUtil.RhinoSweep1(ref args, out breps)) { for (int i = 0; i < breps.Length; i++) { context.m_doc.AddBrepObject(breps[i]); } context.m_doc.Redraw(); } return(IRhinoCommand.result.success); }
///////////////////////////////////////////////////////////////////////// // Overridden MRhinoGetPoint::SetBasePoint public new void SetBasePoint(IOn3dPoint base_point) { m_base = (On3dPoint)base_point; base.SetBasePoint(base_point); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Define geometry for rail and shape curves On3dPoint start_point = new On3dPoint(0, 0, 0); On3dPoint end_point = new On3dPoint(10, 0, 0); OnPlane plane = new OnPlane(OnUtil.On_yz_plane); plane.SetOrigin(start_point); OnCircle circle0 = new OnCircle(plane, 5); plane.SetOrigin(end_point); OnCircle circle1 = new OnCircle(plane, 2); // Build rail and shape curves OnLineCurve line_curve = new OnLineCurve(start_point, end_point); OnArcCurve arc_curve0 = new OnArcCurve(circle0); OnArcCurve arc_curve1 = new OnArcCurve(circle1); // Build poly edge curve MRhinoPolyEdge rail_curve = new MRhinoPolyEdge(); rail_curve.Create(line_curve); // Create sweep arguments MArgsRhinoSweep1 args = new MArgsRhinoSweep1(); // Add rail curve and related settings args.m_rail_curve = rail_curve; args.m_bHaveRailPickPoint = false; args.m_bClosed = false; args.m_bUsePivotPoint = false; // Add shape curves List<OnCurve> shape_curves = new List<OnCurve>(); shape_curves.Add(arc_curve0); shape_curves.Add(arc_curve1); args.m_shape_curves = shape_curves.ToArray(); // Specify parameters on rail closest to shapes args.m_rail_params.Append(rail_curve.Domain()[0]); args.m_rail_params.Append(rail_curve.Domain()[1]); // No starting sweep point args.set_m_bUsePoints(0, 0); // No ending sweep point args.set_m_bUsePoints(1, 0); // 0 = Freeform args.m_style = 0; // 0 = Do Not Simplify args.m_simplify = 0; // Sample point count for rebuilding shapes args.m_rebuild_count = -1; // 0 = don't miter args.m_miter_type = 0; // Standard tolerances args.m_refit_tolerance = context.m_doc.AbsoluteTolerance(); args.m_sweep_tolerance = context.m_doc.AbsoluteTolerance(); args.m_angle_tolerance = context.m_doc.AngleToleranceRadians(); OnBrep[] breps = null; if (RhUtil.RhinoSweep1(ref args, out breps)) { for (int i = 0; i < breps.Length; i++) context.m_doc.AddBrepObject(breps[i]); context.m_doc.Redraw(); } return IRhinoCommand.result.success; }
public void SetBrep(IOnBrep brep) { if (null == brep || !brep.IsValid()) return; m_brep = brep; int face_count = m_brep.m_F.Count(); m_points.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT); m_normals.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT); m_points.SetCount(0); m_normals.SetCount(0); for (int i = 0; i < face_count; i++) { IOnBrepFace face = m_brep.m_F[i]; IOnBrepLoop loop = face.OuterLoop(); if (null == loop) continue; OnInterval udomain = face.Domain(0); OnInterval vdomain = face.Domain(1); if (loop.m_pbox.IsValid()) { OnInterval domain = new OnInterval(); domain.Set(loop.m_pbox.m_min.x, loop.m_pbox.m_max.x); domain.Intersection(udomain); if (domain.IsIncreasing()) udomain.Set(domain.Min(), domain.Max()); domain.Set(loop.m_pbox.m_min.y, loop.m_pbox.m_max.y); domain.Intersection(vdomain); if (domain.IsIncreasing()) vdomain.Set(domain.Min(), domain.Max()); } bool bUntrimmed = m_brep.FaceIsSurface(i); ArrayOnInterval intervals = new ArrayOnInterval(); bool bRev = face.m_bRev; for (double u = 0.0; u < SURFACE_ARROW_COUNT; u += 1.0) { double d = u / (SURFACE_ARROW_COUNT - 1.0); double s = udomain.ParameterAt(d); intervals.SetCount(0); if (bUntrimmed || RhUtil.RhinoGetIsoIntervals(face, 1, s, intervals) > 0) { for (double v = 0.0; v < SURFACE_ARROW_COUNT; v += 1.0) { d = v / (SURFACE_ARROW_COUNT - 1.0); double t = vdomain.ParameterAt(d); bool bAdd = bUntrimmed; for (int k = 0; !bAdd && k < intervals.Count(); k++) { if (intervals[k].Includes(t)) bAdd = true; } if (bAdd) { On3dPoint pt = new On3dPoint(); On3dVector du = new On3dVector(); On3dVector dv = new On3dVector(); On3dVector dir = new On3dVector(); if (face.EvNormal(s, t, ref pt, ref du, ref dv, ref dir)) { m_points.Append(pt); if (bRev) dir.Reverse(); m_normals.Append(dir); } } } } } } }
public static OnBrep MakeTrimmedBrepFace() { // This example demonstrates how to construct a ON_Brep // with the topology shown below. // // // E-------C--------D // | /\ | // | / \ | // | / \ | // | e2 e1 | // | / \ | // | / \ | // | / \ | // A-----e0-------->B // // // Things need to be defined in a valid brep: // 1- Vertices // 2- 3D Curves (geometry) // 3- Edges (topology - reference curve geometry) // 4- Surface (geometry) // 5- Faces (topology - reference surface geometry) // 6- Loops (2D parameter space of faces) // 4- Trims and 2D curves (2D parameter space of edges) // //Vertex points // define the corners of the face with hole On3dPoint[] point = new On3dPoint[5]; point[0] = new On3dPoint(0.0, 0.0, 0.0); //point A = geometry for vertex 0 (and surface SW corner) point[1] = new On3dPoint(10.0, 0.0, 0.0); // point B = geometry for vertex 1 (and surface SE corner) point[2] = new On3dPoint(5.0, 10.0, 0.0); // point C = geometry for vertex 2 point[3] = new On3dPoint(10.0, 10.0, 0.0);// point D (surface NE corner) point[4] = new On3dPoint(0.0, 10.0, 0.0); // point E (surface NW corner) // Build the brep OnBrep brep = new OnBrep(); // create four vertices of the outer edges int vi; for (vi = 0; vi < 3; vi++) { OnBrepVertex v = brep.NewVertex(point[vi]); v.m_tolerance = 0.0;// this simple example is exact - for models with // non-exact data, set tolerance as explained in // definition of ON_BrepVertex. } // Create 3d curve geometry - the orientations are arbitrarily chosen // so that the end vertices are in alphabetical order. brep.m_C3.Append(CreateLinearCurve(point[A], point[B])); // line AB brep.m_C3.Append(CreateLinearCurve(point[B], point[C])); // line BC brep.m_C3.Append(CreateLinearCurve(point[A], point[C])); // line CD // Create edge topology for each curve in the brep. CreateEdges(ref brep); // Create 3d surface geometry - the orientations are arbitrarily chosen so // that some normals point into the cube and others point out of the cube. brep.m_S.Append(CreateNurbsSurface(point[A], point[B], point[D], point[E])); // ABCD // Create face topology and 2d parameter space loops and trims. CreateFace(ref brep, ABC_i); return brep; }
public static OnBrep MakeTrimmedBrepFace() { // This example demonstrates how to construct a ON_Brep // with the topology shown below. // // // E-------C--------D // | /\ | // | / \ | // | / \ | // | e2 e1 | // | / \ | // | / \ | // | / \ | // A-----e0-------->B // // // Things need to be defined in a valid brep: // 1- Vertices // 2- 3D Curves (geometry) // 3- Edges (topology - reference curve geometry) // 4- Surface (geometry) // 5- Faces (topology - reference surface geometry) // 6- Loops (2D parameter space of faces) // 4- Trims and 2D curves (2D parameter space of edges) // //Vertex points // define the corners of the face with hole On3dPoint[] point = new On3dPoint[5]; point[0] = new On3dPoint(0.0, 0.0, 0.0); //point A = geometry for vertex 0 (and surface SW corner) point[1] = new On3dPoint(10.0, 0.0, 0.0); // point B = geometry for vertex 1 (and surface SE corner) point[2] = new On3dPoint(5.0, 10.0, 0.0); // point C = geometry for vertex 2 point[3] = new On3dPoint(10.0, 10.0, 0.0); // point D (surface NE corner) point[4] = new On3dPoint(0.0, 10.0, 0.0); // point E (surface NW corner) // Build the brep OnBrep brep = new OnBrep(); // create four vertices of the outer edges int vi; for (vi = 0; vi < 3; vi++) { OnBrepVertex v = brep.NewVertex(point[vi]); v.m_tolerance = 0.0;// this simple example is exact - for models with // non-exact data, set tolerance as explained in // definition of ON_BrepVertex. } // Create 3d curve geometry - the orientations are arbitrarily chosen // so that the end vertices are in alphabetical order. brep.m_C3.Append(CreateLinearCurve(point[A], point[B])); // line AB brep.m_C3.Append(CreateLinearCurve(point[B], point[C])); // line BC brep.m_C3.Append(CreateLinearCurve(point[A], point[C])); // line CD // Create edge topology for each curve in the brep. CreateEdges(ref brep); // Create 3d surface geometry - the orientations are arbitrarily chosen so // that some normals point into the cube and others point out of the cube. brep.m_S.Append(CreateNurbsSurface(point[A], point[B], point[D], point[E])); // ABCD // Create face topology and 2d parameter space loops and trims. CreateFace(ref brep, ABC_i); return(brep); }
// Adds a point from a RMA.OpenNURBS.On3dPoint object public void Add(On3dPoint pt) { Add(pt.x, pt.y, pt.z); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Step 1, select objects to include in the instance definition MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects to define block"); go.EnableReferenceObjectSelect(false); go.EnableSubObjectSelect(false); go.EnableGroupSelect(true); // Phantoms, grips, lights, etc., cannot be in instance definitions. uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object ); uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object; go.SetGeometryFilter(geometry_filter); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } // Step 2, select base point MRhinoGetPoint gp = new MRhinoGetPoint(); gp.SetCommandPrompt("Block base point"); gp.GetPoint(); if (gp.CommandResult() != IRhinoCommand.result.success) { return(gp.CommandResult()); } On3dPoint base_point = gp.Point(); // Step 3, get instance definition name MRhinoGetString gs = new MRhinoGetString(); gs.SetCommandPrompt("Block definition name"); gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc)); gs.GetString(); if (gs.CommandResult() != IRhinoCommand.result.success) { return(gs.CommandResult()); } string idef_name = gs.String().Trim(); if (string.IsNullOrEmpty(idef_name)) { return(IRhinoCommand.result.nothing); } // Step 4, verify objects int found_index = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name); List <IRhinoObject> objects = new List <IRhinoObject>(); bool bQuietly = context.IsInteractive() ? false : true; for (int i = 0; i < go.ObjectCount(); i++) { IRhinoObject obj = go.Object(i).Object(); if (obj == null) { continue; } // Probably don't need to do this... if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType())) { continue; } if (obj.ObjectType() == IOn.object_type.instance_reference) { IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj); if (iref_obj != null) { if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0) { if (!bQuietly) { RhUtil.RhinoApp().Print("Unable to create block.\n"); } return(IRhinoCommand.result.failure); } } } objects.Add(obj); } // Step 5, create instance definition OnInstanceDefinition idef = new OnInstanceDefinition(); idef.SetName(idef_name); int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly); if (idef_index < 0) { return(IRhinoCommand.result.failure); } // Step 6, create the instance reference OnXform xform = new OnXform(); xform.Translation(base_point - new On3dPoint(OnUtil.On_origin)); IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform); if (inst_obj != null) { inst_obj.Select(true); } else { if (!bQuietly) { RhUtil.RhinoApp().Print("Error creating block.\n"); } return(IRhinoCommand.result.failure); } // Step 7, delete existing geometry for (int i = 0; i < objects.Count; i++) { context.m_doc.DeleteObject(new MRhinoObjRef(objects[i])); } context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
public override bool CalculateTransform(MRhinoViewport vp, IOn3dPoint point, ref OnXform xform) { bool bResult = false; On3dVector v = new On3dVector(); On3dPoint pt = new On3dPoint(point); v = pt - m_base; if (!v.IsZero()) { xform.Translation(v); bResult = xform.IsValid(); } return bResult; }
/// <summary> /// Intesects all NURBS Surfaces with Voxels. /// </summary> /// <param name="Model">the scene.</param> /// <param name="Box">the voxel</param> /// <param name="Index">the index of the surface to test.</param> /// <returns></returns> private bool BoxIntersection(RhCommon_Scene Model, OnBoundingBox Box, int Index) { On3dPoint Center = Box.Center(); double Radius = Center.DistanceTo(Box.Min()); double s = 0; double t = 0; On3dPoint point = new On3dPoint(); if (RhUtil.RhinoBrepClosestPoint(Model.Brep(Index), Center, new OnCOMPONENT_INDEX(), ref s, ref t, point, Radius)) //if (Center.DistanceTo(point) < Radius) { return true; } return false; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Select a curve object MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select curve"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); // Validate the selection IRhinoObject obj = go.Object(0).Object(); if (null == obj) return IRhinoCommand.result.failure; // Get the active view MRhinoView view = RhUtil.RhinoApp().ActiveView(); if (null == view) return IRhinoCommand.result.failure; // Get the construction plane from the active view OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane); // Create a construction plane aligned bounding box OnBoundingBox bbox = new OnBoundingBox(); IRhinoObject[] objs = new IRhinoObject[1] { obj }; bool rc = RhUtil.RhinoGetTightBoundingBox(objs, ref bbox, false, plane); if (rc == false) return IRhinoCommand.result.failure; // Validate bounding box if (0 != bbox.IsDegenerate()) { RhUtil.RhinoApp().Print("Curve's tight bounding box is degenerate.\n"); return IRhinoCommand.result.nothing; } // ON_BrepBox wants 8 points defining the box corners // arranged in this order: // // v7______________v6 // |\ |\ // | \ | \ // | \ _____________\ // | v4 | v5 // | | | | // | | | | // v3---|---------v2 | // \ | \ | // \ | \ | // \ | \ | // \v0____________\v1 // On3dPoint[] box_corners = new On3dPoint[8]; box_corners[0] = bbox.Corner(0, 0, 0); box_corners[1] = bbox.Corner(1, 0, 0); box_corners[2] = bbox.Corner(1, 1, 0); box_corners[3] = bbox.Corner(0, 1, 0); box_corners[4] = bbox.Corner(0, 0, 1); box_corners[5] = bbox.Corner(1, 0, 1); box_corners[6] = bbox.Corner(1, 1, 1); box_corners[7] = bbox.Corner(0, 1, 1); // Transform points to the world-xy plane OnXform p2w = new OnXform(); p2w.ChangeBasis(plane, OnUtil.On_xy_plane); for (int i = 0; i < 8; i++) box_corners[i].Transform(p2w); // Make a brep box OnBrep brep = OnUtil.ON_BrepBox(box_corners); if (null != brep) { context.m_doc.AddBrepObject(brep); context.m_doc.Redraw(); } return IRhinoCommand.result.success; }
public void SetBrep(IOnBrep brep) { if (null == brep || !brep.IsValid()) { return; } m_brep = brep; int face_count = m_brep.m_F.Count(); m_points.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT); m_normals.Reserve(face_count * SURFACE_ARROW_COUNT * SURFACE_ARROW_COUNT); m_points.SetCount(0); m_normals.SetCount(0); for (int i = 0; i < face_count; i++) { IOnBrepFace face = m_brep.m_F[i]; IOnBrepLoop loop = face.OuterLoop(); if (null == loop) { continue; } OnInterval udomain = face.Domain(0); OnInterval vdomain = face.Domain(1); if (loop.m_pbox.IsValid()) { OnInterval domain = new OnInterval(); domain.Set(loop.m_pbox.m_min.x, loop.m_pbox.m_max.x); domain.Intersection(udomain); if (domain.IsIncreasing()) { udomain.Set(domain.Min(), domain.Max()); } domain.Set(loop.m_pbox.m_min.y, loop.m_pbox.m_max.y); domain.Intersection(vdomain); if (domain.IsIncreasing()) { vdomain.Set(domain.Min(), domain.Max()); } } bool bUntrimmed = m_brep.FaceIsSurface(i); ArrayOnInterval intervals = new ArrayOnInterval(); bool bRev = face.m_bRev; for (double u = 0.0; u < SURFACE_ARROW_COUNT; u += 1.0) { double d = u / (SURFACE_ARROW_COUNT - 1.0); double s = udomain.ParameterAt(d); intervals.SetCount(0); if (bUntrimmed || RhUtil.RhinoGetIsoIntervals(face, 1, s, intervals) > 0) { for (double v = 0.0; v < SURFACE_ARROW_COUNT; v += 1.0) { d = v / (SURFACE_ARROW_COUNT - 1.0); double t = vdomain.ParameterAt(d); bool bAdd = bUntrimmed; for (int k = 0; !bAdd && k < intervals.Count(); k++) { if (intervals[k].Includes(t)) { bAdd = true; } } if (bAdd) { On3dPoint pt = new On3dPoint(); On3dVector du = new On3dVector(); On3dVector dv = new On3dVector(); On3dVector dir = new On3dVector(); if (face.EvNormal(s, t, ref pt, ref du, ref dv, ref dir)) { m_points.Append(pt); if (bRev) { dir.Reverse(); } m_normals.Append(dir); } } } } } } }
/// <summary> /// This gets called when when the user runs this command. /// </summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Select objects to animate MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects to animate"); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } // Select path curve MRhinoGetObject gc = new MRhinoGetObject(); gc.SetCommandPrompt("Select path curve"); gc.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); gc.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve); gc.EnableDeselectAllBeforePostSelect(false); gc.GetObjects(1, 1); if (gc.CommandResult() != IRhinoCommand.result.success) { return(gc.CommandResult()); } // Get the curve IOnCurve crv = gc.Object(0).Curve(); if (null == crv) { return(IRhinoCommand.result.failure); } // Create an array of normalized curve parameters List <double> slist = new List <double>(m_max_steps); for (int i = 0; i < m_max_steps; i++) { double s = (double)i / ((double)m_max_steps - 1); slist.Add(s); } // Get the real parameters along the curve double[] tlist = new double[m_max_steps]; if (!crv.GetNormalizedArcLengthPoints(slist.ToArray(), ref tlist)) { return(IRhinoCommand.result.failure); } // Create the display conduit SampleCsAnimatorConduit conduit = new SampleCsAnimatorConduit(); // Get points along curve On3dPoint start = new On3dPoint(crv.PointAtStart()); List <On3dPoint> plist = new List <On3dPoint>(tlist.Length); for (int i = 0; i < m_max_steps; i++) { On3dPoint pt = new On3dPoint(crv.PointAt(tlist[i])); plist.Add(pt); } // Hide objects and add them to conduit's object array for (int i = 0; i < go.ObjectCount(); i++) { MRhinoObjRef objref = go.Object(i); context.m_doc.HideObject(objref); conduit.m_objects.Add(objref.Object()); } // Do animation... conduit.Enable(); for (int i = 0; i < m_max_steps; i++) { On3dVector v = plist[i] - start; conduit.m_xform.Translation(v); context.m_doc.Redraw(); Thread.Sleep(100); } for (int i = m_max_steps - 1; i >= 0; i--) { On3dVector v = plist[i] - start; conduit.m_xform.Translation(v); if (0 != i) { context.m_doc.Redraw(); Thread.Sleep(100); } } conduit.Disable(); // Show hidden objects for (int i = 0; i < go.ObjectCount(); i++) { MRhinoObjRef objref = go.Object(i); context.m_doc.ShowObject(objref); } context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
public static OnBrep MakeBrepFace() { // This example demonstrates how to construct a ON_Brep // with the topology shown below. // // // D---------e2-----C // | | // | G----e6---H | // | | | | // e3 e5 e7 | // | | | | // | F<---e4---E | // | | // A-------e0------>B // // Things need to be defined in a valid brep: // 1- Vertices // 2- 3D Curves (geometry) // 3- Edges (topology - reference curve geometry) // 4- Surface (geometry) // 5- Faces (topology - reference surface geometry) // 6- Loops (2D parameter space of faces) // 4- Trims and 2D curves (2D parameter space of edges) // //Vertex points // define the corners of the face with hole On3dPoint[] point = new On3dPoint[8]; point[0] = new On3dPoint(0.0, 0.0, 0.0); point[1] = new On3dPoint(10.0, 0.0, 0.0); point[2] = new On3dPoint(10.0, 10.0, 0.0); point[3] = new On3dPoint(0.0, 10.0, 0.0); point[4] = new On3dPoint(8.0, 2.0, 0.0); point[5] = new On3dPoint(2.0, 2.0, 0.0); point[6] = new On3dPoint(2.0, 8.0, 0.0); point[7] = new On3dPoint(8.0, 8.0, 0.0); // Build the brep OnBrep brep = new OnBrep(); // create four vertices of the outer edges int vi; for (vi = 0; vi < 8; vi++) { OnBrepVertex v = brep.NewVertex(point[vi]); v.m_tolerance = 0.0; // this simple example is exact - for models with // non-exact data, set tolerance as explained in // definition of ON_BrepVertex. } // Create 3d curve geometry of the outer boundary // The orientations are arbitrarily chosen // so that the end vertices are in alphabetical order. brep.m_C3.Append(CreateLinearCurve(point[A], point[B])); // line AB brep.m_C3.Append(CreateLinearCurve(point[B], point[C])); // line BC brep.m_C3.Append(CreateLinearCurve(point[C], point[D])); // line CD brep.m_C3.Append(CreateLinearCurve(point[A], point[D])); // line AD // Create 3d curve geometry of the hole brep.m_C3.Append(CreateLinearCurve(point[E], point[F])); // line EF brep.m_C3.Append(CreateLinearCurve(point[F], point[G])); // line GH brep.m_C3.Append(CreateLinearCurve(point[G], point[H])); // line HI brep.m_C3.Append(CreateLinearCurve(point[E], point[H])); // line EI // Create edge topology for each curve in the brep. CreateEdges(ref brep); // Create 3d surface geometry - the orientations are arbitrarily chosen so // that some normals point into the cube and others point out of the cube. brep.m_S.Append(CreateNurbsSurface(point[A], point[B], point[C], point[D])); // ABCD // Create face topology and 2d parameter space loops and trims. CreateFace(ref brep, ABCD); return brep; }
public static OnBrep MakeBrepFace() { // This example demonstrates how to construct a ON_Brep // with the topology shown below. // // // D---------e2-----C // | | // | G----e6---H | // | | | | // e3 e5 e7 | // | | | | // | F<---e4---E | // | | // A-------e0------>B // // Things need to be defined in a valid brep: // 1- Vertices // 2- 3D Curves (geometry) // 3- Edges (topology - reference curve geometry) // 4- Surface (geometry) // 5- Faces (topology - reference surface geometry) // 6- Loops (2D parameter space of faces) // 4- Trims and 2D curves (2D parameter space of edges) // //Vertex points // define the corners of the face with hole On3dPoint[] point = new On3dPoint[8]; point[0] = new On3dPoint(0.0, 0.0, 0.0); point[1] = new On3dPoint(10.0, 0.0, 0.0); point[2] = new On3dPoint(10.0, 10.0, 0.0); point[3] = new On3dPoint(0.0, 10.0, 0.0); point[4] = new On3dPoint(8.0, 2.0, 0.0); point[5] = new On3dPoint(2.0, 2.0, 0.0); point[6] = new On3dPoint(2.0, 8.0, 0.0); point[7] = new On3dPoint(8.0, 8.0, 0.0); // Build the brep OnBrep brep = new OnBrep(); // create four vertices of the outer edges int vi; for (vi = 0; vi < 8; vi++) { OnBrepVertex v = brep.NewVertex(point[vi]); v.m_tolerance = 0.0; // this simple example is exact - for models with // non-exact data, set tolerance as explained in // definition of ON_BrepVertex. } // Create 3d curve geometry of the outer boundary // The orientations are arbitrarily chosen // so that the end vertices are in alphabetical order. brep.m_C3.Append(CreateLinearCurve(point[A], point[B])); // line AB brep.m_C3.Append(CreateLinearCurve(point[B], point[C])); // line BC brep.m_C3.Append(CreateLinearCurve(point[C], point[D])); // line CD brep.m_C3.Append(CreateLinearCurve(point[A], point[D])); // line AD // Create 3d curve geometry of the hole brep.m_C3.Append(CreateLinearCurve(point[E], point[F])); // line EF brep.m_C3.Append(CreateLinearCurve(point[F], point[G])); // line GH brep.m_C3.Append(CreateLinearCurve(point[G], point[H])); // line HI brep.m_C3.Append(CreateLinearCurve(point[E], point[H])); // line EI // Create edge topology for each curve in the brep. CreateEdges(ref brep); // Create 3d surface geometry - the orientations are arbitrarily chosen so // that some normals point into the cube and others point out of the cube. brep.m_S.Append(CreateNurbsSurface(point[A], point[B], point[C], point[D])); // ABCD // Create face topology and 2d parameter space loops and trims. CreateFace(ref brep, ABCD); return(brep); }
/// <summary> /// The one and only MakeBox /// </summary> static OnBrep MakeBox() { /* * This example demonstrates how to construct a OnBrep * with the topology shown below. * * v7_______e6_____v6 |\ |\ | e7 | e5 | \ ______e4_____\ | e11 v4 | v5 | | e10 | | | | | | v3---|---e2----v2 e9 \ e8 \ | \ e3 | e1 | \ | \ | \ \v0_____e0_____\v1 \ */ On3dPoint[] points = new On3dPoint[8]; points[0] = new On3dPoint(0.0, 0.0, 0.0); points[1] = new On3dPoint(10.0, 0.0, 0.0); points[2] = new On3dPoint(10.0, 10.0, 0.0); points[3] = new On3dPoint(0.0, 10.0, 0.0); points[4] = new On3dPoint(0.0, 0.0, 10.0); points[5] = new On3dPoint(10.0, 0.0, 10.0); points[6] = new On3dPoint(10.0, 10.0, 10.0); points[7] = new On3dPoint(0.0, 10.0, 10.0); OnBrep brep = new OnBrep(); int vi = 0, ei = 0, fi = 0, si = 0, c2i = 0; for (vi = 0; vi < 8; vi++) { brep.NewVertex(points[vi], 0.0); } for (ei = 0; ei < 4; ei++) { OnBrepVertex v0 = brep.m_V[ei]; OnBrepVertex v1 = brep.m_V[(ei + 1) % 4]; brep.m_C3.Append(new OnLineCurve(v0.point, v1.point)); brep.NewEdge(ref v0, ref v1, ei, null, 0.0); } for (ei = 4; ei < 8; ei++) { OnBrepVertex v0 = brep.m_V[ei]; OnBrepVertex v1 = brep.m_V[ei == 7 ? 4 : (ei + 1)]; brep.m_C3.Append(new OnLineCurve(v0.point, v1.point)); brep.NewEdge(ref v0, ref v1, ei, null, 0.0); } for (ei = 8; ei < 12; ei++) { OnBrepVertex v0 = brep.m_V[ei - 8]; OnBrepVertex v1 = brep.m_V[ei - 4]; brep.m_C3.Append(new OnLineCurve(v0.point, v1.point)); brep.NewEdge(ref v0, ref v1, ei, null, 0.0); } OnBrepBoxFaceInfo[] f = new OnBrepBoxFaceInfo[6]; f[0] = new OnBrepBoxFaceInfo(0, 9, 4, 8, false, false, true, true); f[1] = new OnBrepBoxFaceInfo(1, 10, 5, 9, false, false, true, true); f[2] = new OnBrepBoxFaceInfo(2, 11, 6, 10, false, false, true, true); f[3] = new OnBrepBoxFaceInfo(3, 8, 7, 11, false, false, true, true); f[4] = new OnBrepBoxFaceInfo(3, 2, 1, 0, true, true, true, true); f[5] = new OnBrepBoxFaceInfo(4, 5, 6, 7, false, false, false, false); for (fi = 0; fi < 6; fi++) { OnBrepEdge e0 = brep.m_E[f[fi].e[0]]; OnBrepEdge e1 = brep.m_E[f[fi].e[1]]; OnBrepEdge e2 = brep.m_E[f[fi].e[2]]; OnBrepEdge e3 = brep.m_E[f[fi].e[3]]; OnBrepVertex v0 = brep.m_V[e0.get_m_vi(f[fi].bRev[0] ? 1 : 0)]; OnBrepVertex v1 = brep.m_V[e1.get_m_vi(f[fi].bRev[1] ? 1 : 0)]; OnBrepVertex v2 = brep.m_V[e2.get_m_vi(f[fi].bRev[2] ? 1 : 0)]; OnBrepVertex v3 = brep.m_V[e3.get_m_vi(f[fi].bRev[3] ? 1 : 0)]; si = brep.AddSurface(OnUtil.ON_NurbsSurfaceQuadrilateral(v0.point, v1.point, v2.point, v3.point)); OnInterval s = brep.m_S[si].Domain(0); OnInterval t = brep.m_S[si].Domain(1); On2dPoint p0 = new On2dPoint(s[0], t[0]); On2dPoint p1 = new On2dPoint(s[1], t[0]); On2dPoint p2 = new On2dPoint(s[1], t[1]); On2dPoint p3 = new On2dPoint(s[0], t[1]); OnBrepFace face = brep.NewFace(si); OnBrepLoop loop = brep.NewLoop(IOnBrepLoop.TYPE.outer, ref face); loop.m_pbox.m_min.x = s[0]; loop.m_pbox.m_min.y = t[0]; loop.m_pbox.m_min.z = 0.0; loop.m_pbox.m_max.x = s[1]; loop.m_pbox.m_max.y = t[1]; loop.m_pbox.m_max.z = 0.0; // south side of surface c2i = brep.AddTrimCurve(new OnLineCurve(p0, p1)); OnBrepTrim trim0 = brep.NewTrim(ref e0, f[fi].bRev[0], ref loop, c2i); trim0.set_m_tolerance(0, 0.0); trim0.set_m_tolerance(1, 0.0); trim0.m_type = (trim0.get_m_vi(0) != trim0.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular; trim0.m_iso = IOnSurface.ISO.S_iso; // east side of surface c2i = brep.AddTrimCurve(new OnLineCurve(p1, p2)); OnBrepTrim trim1 = brep.NewTrim(ref e1, f[fi].bRev[1], ref loop, c2i); trim1.set_m_tolerance(0, 0.0); trim1.set_m_tolerance(1, 0.0); trim1.m_type = (trim1.get_m_vi(0) != trim1.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular; trim1.m_iso = IOnSurface.ISO.E_iso; // north side of surface c2i = brep.AddTrimCurve(new OnLineCurve(p2, p3)); OnBrepTrim trim2 = brep.NewTrim(ref e2, f[fi].bRev[2], ref loop, c2i); trim2.set_m_tolerance(0, 0.0); trim2.set_m_tolerance(1, 0.0); trim2.m_type = (trim2.get_m_vi(0) != trim2.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular; trim2.m_iso = IOnSurface.ISO.N_iso; // west side of surface c2i = brep.AddTrimCurve(new OnLineCurve(p3, p0)); OnBrepTrim trim3 = brep.NewTrim(ref e3, f[fi].bRev[3], ref loop, c2i); trim3.set_m_tolerance(0, 0.0); trim3.set_m_tolerance(1, 0.0); trim3.m_type = (trim3.get_m_vi(0) != trim3.get_m_vi(1)) ? IOnBrepTrim.TYPE.mated : IOnBrepTrim.TYPE.singular; trim3.m_iso = IOnSurface.ISO.W_iso; } if (!brep.IsValid()) { return(null); } return(brep); }