/// <summary> /// Determines if two objects are respectively shallow copies, /// new managed instantiations of the same geometry, or similar /// internal references to the exact same geometry, both in managed and in unmanaged code. /// </summary> /// <param name="one">The first object</param> /// <param name="other">The other object</param> /// <returns>True if indeed the objects are really the same. False otherwise.</returns> public static bool GeometryReferenceEquals(GeometryBase one, GeometryBase other) { if (object.ReferenceEquals(one, other)) { return(true); } if (object.ReferenceEquals(one, null)) { return(false); } if (object.ReferenceEquals(other, null)) { return(false); } if (one.ConstPointer() != IntPtr.Zero && one.ConstPointer() == other.ConstPointer()) { return(true); } if (one.m_shallow_parent != null && other.ConstPointer() != IntPtr.Zero && one.m_shallow_parent.ConstPointer() == other.ConstPointer()) { return(true); } if (other.m_shallow_parent != null && one.ConstPointer() != IntPtr.Zero && other.m_shallow_parent.ConstPointer() == one.ConstPointer()) { return(true); } if (one.m_shallow_parent != null && other.m_shallow_parent != null && other.m_shallow_parent.ConstPointer() != IntPtr.Zero && one.m_shallow_parent.ConstPointer() == one.m_shallow_parent.ConstPointer()) { return(true); } return(false); }
/// <summary> /// Gets the line-like curve that is the conceptual axis of the extrusion. /// </summary> /// <returns>The path as a line curve.</returns> public LineCurve PathLineCurve() { IntPtr pConstThis = ConstPointer(); IntPtr pLineCurve = UnsafeNativeMethods.ON_Extrusion_PathLineCurve(pConstThis); return(GeometryBase.CreateGeometryHelper(pLineCurve, null) as LineCurve); }
public NurbsSurface ToNurbsSurface() { IntPtr constPtrThis = ConstPointer(); IntPtr ptrNurbsSurface = UnsafeNativeMethods.ON_BezierSurface_GetNurbForm(constPtrThis); return(GeometryBase.CreateGeometryHelper(ptrNurbsSurface, null) as NurbsSurface); }
//[skipping] //ProfileParamter //Profile /// <summary> /// Gets a transversal isocurve of the extruded profile. /// </summary> /// <param name="profileIndex"> /// 0 <= profileIndex < ProfileCount /// The outer profile has index 0. /// </param> /// <param name="s"> /// 0.0 <= s <= 1.0 /// A relative parameter controling which profile is returned. /// 0 = bottom profile and 1 = top profile. /// </param> /// <returns>The profile.</returns> public Curve Profile3d(int profileIndex, double s) { IntPtr pConstThis = ConstPointer(); IntPtr pCurve = UnsafeNativeMethods.ON_Extrusion_Profile3d(pConstThis, profileIndex, s); return(GeometryBase.CreateGeometryHelper(pCurve, null) as Curve); }
public static Rhino.Commands.Result Stretch(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to stretch", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); Rhino.Geometry.Line axis; rc = Rhino.Input.RhinoGet.GetLine(out axis); if (rc != Rhino.Commands.Result.Success || axis == null) { return(rc); } Rhino.Geometry.Morphs.StretchSpaceMorph morph = new Rhino.Geometry.Morphs.StretchSpaceMorph(axis.From, axis.To, axis.Length * 1.5); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
/// <summary> /// Gets one of the longitudinal surfaces of the extrusion. /// </summary> /// <param name="ci">The index specifying which precise item to retrieve.</param> /// <returns>The surface.</returns> public Surface WallSurface(ComponentIndex ci) { IntPtr pConstThis = ConstPointer(); IntPtr pSurface = UnsafeNativeMethods.ON_Extrusion_WallSurface(pConstThis, ci); return(GeometryBase.CreateGeometryHelper(pSurface, null) as Surface); }
/// <summary> /// Gets one of the longitudinal curves along the beam or extrusion. /// </summary> /// <param name="ci">The index of this profile.</param> /// <returns>The profile.</returns> public Curve WallEdge(ComponentIndex ci) { IntPtr pConstThis = ConstPointer(); IntPtr pCurve = UnsafeNativeMethods.ON_Extrusion_WallEdge(pConstThis, ci); return(GeometryBase.CreateGeometryHelper(pCurve, null) as Curve); }
/// <summary> /// Convert RhinoCommon geometry to Nucleus geometry /// </summary> /// <param name="geometry"></param> /// <returns></returns> public static VertexGeometry Convert(RC.GeometryBase geometry) { if (geometry is RC.Curve) { return(Convert((RC.Curve)geometry)); } else if (geometry is RC.Point) { return(Convert((RC.Point)geometry)); } else if (geometry is RC.Surface) { return(Convert((RC.Surface)geometry)); } else if (geometry is RC.Mesh) { return(Convert((RC.Mesh)geometry)); } else if (geometry is RC.Brep) { return(Convert(((RC.Brep)geometry))); } else { throw new NotImplementedException(); } }
/// <summary> /// Removes any nesting of polycurves. If this polycurve has just a single segment, the segment is returned. /// If, after nest removal, there are adjacent segments which are polylines, they are combined into a single polyline. /// The new curve may have a different domain from this polycurve. If the start and end segments of a closed input are polylines, /// the result may have a different seam location since the start and end segments will be combined. /// </summary> /// <returns>A new curve that is not necessarily a polycurve if successful, null otherwise. </returns> /// <seealso cref="RemoveNesting"/> /// <since>7.0</since> public Curve CleanUp() { IntPtr ptr_const_this = ConstPointer(); IntPtr ptr = UnsafeNativeMethods.RHC_RhinoCleanUpPolyCurve(ptr_const_this); return(GeometryBase.CreateGeometryHelper(ptr, null) as Curve); }
/// <summary> /// Get a cubic, uniform, non-rational, NURBS curve that is on the /// edge's limit curve. /// </summary> /// <param name="clampEnds"> /// If true, the end knots are clamped. /// Otherwise the end knots are(-2,-1,0,...., k1, k1+1, k1+2). /// </param> /// <returns></returns> /// <since>7.0</since> public NurbsCurve ToNurbsCurve(bool clampEnds) { IntPtr const_ptr_this = ConstPointer(); IntPtr ptr_nurbscurve = UnsafeNativeMethods.ON_SubDEdge_LimitCurve(const_ptr_this, clampEnds); return(GeometryBase.CreateGeometryHelper(ptr_nurbscurve, null) as NurbsCurve); }
/// <summary> /// Computes draft curve silhouettes of a shape. /// </summary> /// <param name="geometry">Geometry whose silhouettes need to be computed. Can be Brep, BrepFace, Mesh, or Extrusion.</param> /// <param name="draftAngle">The draft angle in radians. Draft angle can be a positive or negative value.</param> /// <param name="pullDirection">3d direction for the mold to be pulled in, directed away from the object.</param> /// <param name="tolerance"> /// Tolerance to use for determining projecting relationships. /// Surfaces and curves that are closer than tolerance, may be treated as projecting. /// When in doubt use RhinoDoc.ModelAbsoluteTolerance. /// </param> /// <param name="angleToleranceRadians"> /// Angular tolerance to use for determining projecting relationships. /// A surface normal N that satisfies N o cameraDirection < Sin(angleToleranceRadians) may be considered projecting. /// When in doubt use RhinoDoc.ModelAngleToleranceRadians. /// </param> /// <param name="cancelToken">Computation cancellation token.</param> /// <returns>Array of silhouette curves.</returns> /// <since>7.0</since> public static Silhouette[] ComputeDraftCurve( GeometryBase geometry, double draftAngle, Vector3d pullDirection, double tolerance, double angleToleranceRadians, System.Threading.CancellationToken cancelToken ) { IntPtr const_ptr_geometry = geometry.ConstPointer(); ThreadTerminator terminator = null; if (cancelToken != System.Threading.CancellationToken.None) { terminator = new ThreadTerminator(); cancelToken.Register(terminator.RequestCancel); } IntPtr ptr_terminator = terminator == null ? IntPtr.Zero : terminator.NonConstPointer(); IntPtr ptr_silhouettes = UnsafeNativeMethods.TLC_Sillhouette3(const_ptr_geometry, draftAngle, pullDirection, tolerance, angleToleranceRadians, ptr_terminator); Silhouette[] rc = FromClassArray(ptr_silhouettes); UnsafeNativeMethods.TLC_SilhouetteArrayDelete(ptr_silhouettes); if (terminator != null) { terminator.Dispose(); } GC.KeepAlive(geometry); return(rc); }
/// <summary> /// Constructs a NURBS curve representation of this curve. /// </summary> /// <returns>NURBS representation of the curve on success, null on failure.</returns> public NurbsCurve ToNurbsCurve() { IntPtr pConstThis = ConstPointer(); IntPtr pNurbsCurve = UnsafeNativeMethods.ON_BezierCurve_GetNurbForm(pConstThis); return(GeometryBase.CreateGeometryHelper(pNurbsCurve, null) as NurbsCurve); }
/// <summary> /// Gets the segment curve at the given index. /// </summary> /// <param name="index">Index of segment to retrieve.</param> /// <returns>The segment at the given index or null on failure.</returns> public Curve SegmentCurve(int index) { IntPtr ptr = ConstPointer(); IntPtr pCurve = UnsafeNativeMethods.ON_PolyCurve_SegmentCurve(ptr, index); return(GeometryBase.CreateGeometryHelper(pCurve, this, index) as Curve); }
/// <summary> /// The timer used to defer replacement processing operations /// </summary> //private Timer _ObjectReplacedWaitTimer = null; private void ProcessObjectReplacedWaitingList(object sender, EventArgs args) { if (_ReplacedElements.Count > 0 || _ReplacedNodesWaitingList.Count > 0) { foreach (KeyValuePair <Node, RhinoReplaceObjectEventArgs> kvp in _ReplacedNodesWaitingList) { Node node = kvp.Key; RC.GeometryBase geometry = kvp.Value.NewRhinoObject.Geometry; if (geometry is RC.Point) { RC.Point rPt = (RC.Point)geometry; Vector pos = FromRC.Convert(rPt.Location); node.MoveTo(pos, true, _ReplacedElements); } } _ReplacedElements.GenerateNodes(new NodeGenerationParameters()); _ReplacedElements.Clear(); _ReplacedNodesWaitingList.Clear(); //_ObjectReplacedWaitTimer.Stop(); Core.Instance.Host.Refresh(); } }
/// <summary> /// Constructs a brep form of the extrusion. The outer profile is always the first face of the brep. /// If there are inner profiles, additional brep faces are created for each profile. If the /// outer profile is closed, then end caps are added as the last two faces of the brep. /// </summary> /// <param name="splitKinkyFaces"> /// If true and the profiles have kinks, then the faces corresponding to those profiles are split /// so they will be G1. /// </param> /// <returns>A brep with a similar shape like this extrustion, or null on error.</returns> public Brep ToBrep(bool splitKinkyFaces) { IntPtr pConstThis = ConstPointer(); IntPtr pBrep = UnsafeNativeMethods.ON_Extrusion_BrepForm(pConstThis, splitKinkyFaces); return(GeometryBase.CreateGeometryHelper(pBrep, null) as Brep); }
public NurbsCurve ToNurbsCurve() { IntPtr const_ptr_this = ConstPointer(); IntPtr ptr_nurbs_crv = UnsafeNativeMethods.ON_BezierCurve_GetNurbForm(const_ptr_this); return(GeometryBase.CreateGeometryHelper(ptr_nurbs_crv, null) as NurbsCurve); }
/// <summary> /// Bake a piece of Rhino geometry in the active document /// </summary> /// <param name="geometry"></param> /// <returns></returns> public static Guid Bake(RC.GeometryBase geometry) { if (geometry != null) { return(RhinoDoc.ActiveDoc.Objects.Add(geometry)); } return(Guid.Empty); }
private void HandlesReplaceRhinoObject(object sender, RhinoReplaceObjectEventArgs e) { if (!RhinoOutput.Writing) { ModelObject mObj = LinkedModelObject(e.ObjectId); if (mObj != null) { RC.GeometryBase geometry = e.NewRhinoObject.Geometry; if (mObj is Element) { Element element = (Element)mObj; VertexGeometry vG = FromRC.Convert(geometry); if (vG == null && geometry is RC.Curve) { // If curve not convertable, reduce to straight line: RC.Curve rCrv = (RC.Curve)geometry; vG = new Line(FromRC.Convert(rCrv.PointAtStart), FromRC.Convert(rCrv.PointAtEnd)); } if (vG != null) { _Replacing = true; if (element is LinearElement && vG is Curve) { ((LinearElement)element).ReplaceGeometry((Curve)vG); } else if (element is PanelElement && vG is Surface) { ((PanelElement)element).ReplaceGeometry((Surface)vG); } _Replacing = false; _ReplacedElements.TryAdd(element); } } else if (mObj is Node) { _ReplacedNodesWaitingList[(Node)mObj] = e; /*RC.GeometryBase geometry = e.NewRhinoObject.Geometry; * if (geometry is RC.Point) * { * Node node = (Node)mObj; * node.Position = RCtoFB.Convert(((RC.Point)geometry).Location); * }*/ /*if (_ObjectReplacedWaitTimer == null) * { * _ObjectReplacedWaitTimer = new Timer(100); * _ObjectReplacedWaitTimer.AutoReset = false; * _ObjectReplacedWaitTimer.Elapsed += ProcessObjectReplacedWaitingList; * }*/ //if (!_ObjectReplacedWaitTimer.Enabled) } //if (_ObjectReplacedWaitTimer != null) _ObjectReplacedWaitTimer.Start(); } } _LastReplaced = e.ObjectId; }
private bool CircleWithRadiusOf10GeometryFilter (Rhino.DocObjects.RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex) { bool is_circle_with_radius_of10 = false; Circle circle; if (geometry is Curve && (geometry as Curve).TryGetCircle(out circle)) is_circle_with_radius_of10 = circle.Radius <= 10.0 + m_tolerance && circle.Radius >= 10.0 - m_tolerance; return is_circle_with_radius_of10; }
/// <summary> /// Compute silhouettes of a shape for a parallel projection. /// </summary> /// <param name="geometry">Geometry whose silhouettes need to be computed. Can be Brep, BrepFace, Mesh, or Extrusion.</param> /// <param name="silhouetteType">Types of silhouette to compute.</param> /// <param name="parallelCameraDirection">Direction of parallel camera.</param> /// <param name="tolerance">Tolerance to use for determining projecting relationships. /// Surfaces and curves that are closer than tolerance, may be treated as projecting. /// When in doubt use RhinoDoc.ModelAbsoluteTolerance.</param> /// <param name="angleToleranceRadians">Angular tolerance to use for determining projecting relationships. /// A surface normal N that satisfies N o cameraDirection < Sin(angleToleranceRadians) may be considered projecting. /// When in doubt use RhinoDoc.ModelAngleToleranceRadians.</param> /// <returns>Array of silhouette curves.</returns> public static Silhouette[] Compute( GeometryBase geometry, SilhouetteType silhouetteType, Vector3d parallelCameraDirection, double tolerance, double angleToleranceRadians) { return(Compute(geometry, silhouetteType, parallelCameraDirection, tolerance, angleToleranceRadians, null, System.Threading.CancellationToken.None)); }
/// <summary> /// Compute silhouettes of a shape for a perspective projection. /// </summary> /// <param name="geometry">Geometry whose silhouettes need to be computed. Can be Brep, BrepFace, Mesh, or Extrusion.</param> /// <param name="silhouetteType">Types of silhouette to compute.</param> /// <param name="perspectiveCameraLocation">Location of perspective camera.</param> /// <param name="tolerance">Tolerance to use for determining projecting relationships. /// Surfaces and curves that are closer than tolerance, may be treated as projecting. /// When in doubt use RhinoDoc.ModelAbsoluteTolerance.</param> /// <param name="angleToleranceRadians">Angular tolerance to use for determining projecting relationships. /// A surface normal N that satisfies N o cameraDirection < Sin(angleToleranceRadians) may be considered projecting. /// When in doubt use RhinoDoc.ModelAngleToleranceRadians.</param> /// <returns>Array of silhouette curves.</returns> public static Silhouette[] Compute( GeometryBase geometry, SilhouetteType silhouetteType, Point3d perspectiveCameraLocation, double tolerance, double angleToleranceRadians) { return(Compute(geometry, silhouetteType, perspectiveCameraLocation, tolerance, angleToleranceRadians, null, System.Threading.CancellationToken.None)); }
/// <summary> /// Compute silhouettes of a shape for a specified projection. /// </summary> /// <param name="geometry">Geometry whose silhouettes need to be computed. Can be Brep, BrepFace, Mesh, or Extrusion.</param> /// <param name="silhouetteType">Types of silhouette to compute.</param> /// <param name="viewport">Projection.</param> /// <param name="tolerance">Tolerance to use for determining projecting relationships. /// Surfaces and curves that are closer than tolerance, may be treated as projecting. /// When in doubt use RhinoDoc.ModelAbsoluteTolerance.</param> /// <param name="angleToleranceRadians">Angular tolerance to use for determining projecting relationships. /// A surface normal N that satisfies N o cameraDirection < Sin(angleToleranceRadians) may be considered projecting. /// When in doubt use RhinoDoc.ModelAngleToleranceRadians.</param> /// <returns>Array of silhouette curves.</returns> public static Silhouette[] Compute( GeometryBase geometry, SilhouetteType silhouetteType, ViewportInfo viewport, double tolerance, double angleToleranceRadians) { return(Compute(geometry, silhouetteType, viewport, tolerance, angleToleranceRadians, null, System.Threading.CancellationToken.None)); }
/***************************************************/ public static void RenderWires(BHG.NurbsSurface surface, Rhino.Display.DisplayPipeline pipeline, Color bhColour) { RHG.GeometryBase geometry = surface.ToRhino(); if (geometry is RHG.Surface) { geometry = RHG.Brep.CreateFromSurface((RHG.Surface)geometry); } pipeline.DrawBrepWires((RHG.Brep)geometry, bhColour, 2); }
/***************************************************/ public static void RenderMeshes(BHG.NurbsSurface surface, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material) { RHG.GeometryBase geometry = surface.ToRhino(); if (geometry is RHG.Surface) { geometry = RHG.Brep.CreateFromSurface((RHG.Surface)geometry); } pipeline.DrawBrepShaded((RHG.Brep)geometry, material); }
/// <summary> /// true if the geometry can be morphed by calling SpaceMorph.Morph(geometry) /// </summary> public static bool IsMorphable(GeometryBase geometry) { if (null == geometry) { return(false); } IntPtr pGeometry = geometry.ConstPointer(); return(UnsafeNativeMethods.ON_Geometry_GetBool(pGeometry, GeometryBase.idxIsMorphable)); }
/// <summary> /// Constructs a light copy of this object. By "light", it is meant that the same /// underlying data is used until something is done to attempt to change it. For example, /// you could have a shallow copy of a very heavy mesh object and the same underlying /// data will be used when doing things like inspecting the number of faces on the mesh. /// If you modify the location of one of the mesh vertices, the shallow copy will create /// a full duplicate of the underlying mesh data and the shallow copy will become a /// deep copy. /// </summary> /// <returns>An object of the same type as this object. /// <para>This behavior is overridden by implementing classes.</para></returns> public GeometryBase DuplicateShallow() { GeometryBase rc = DuplicateShallowHelper(); if (null != rc) { rc.m_shallow_parent = this; } return(rc); }
/// <summary> /// Computes draft curve silhouettes of a shape. /// </summary> /// <param name="geometry">Geometry whose silhouettes need to be computed. Can be Brep, BrepFace, Mesh, or Extrusion.</param> /// <param name="draftAngle">The draft angle in radians. Draft angle can be a positive or negative value.</param> /// <param name="pullDirection">3d direction for the mold to be pulled in, directed away from the object.</param> /// <param name="tolerance"> /// Tolerance to use for determining projecting relationships. /// Surfaces and curves that are closer than tolerance, may be treated as projecting. /// When in doubt use RhinoDoc.ModelAbsoluteTolerance. /// </param> /// <param name="angleToleranceRadians"> /// Angular tolerance to use for determining projecting relationships. /// A surface normal N that satisfies N o cameraDirection < Sin(angleToleranceRadians) may be considered projecting. /// When in doubt use RhinoDoc.ModelAngleToleranceRadians. /// </param> /// <returns>Array of silhouette curves.</returns> /// <since>7.0</since> public static Silhouette[] ComputeDraftCurve( GeometryBase geometry, double draftAngle, Vector3d pullDirection, double tolerance, double angleToleranceRadians ) { return(ComputeDraftCurve(geometry, draftAngle, pullDirection, tolerance, angleToleranceRadians, System.Threading.CancellationToken.None)); }
public static bool TryGetUserString(this GeometryBase geometry, string key, out Autodesk.Revit.DB.ElementId value, Autodesk.Revit.DB.ElementId def) { if (geometry.TryGetUserString(key, out int id, def.IntegerValue)) { value = new Autodesk.Revit.DB.ElementId(id); return(true); } value = def; return(false); }
public static bool TrySetUserString <T>(this GeometryBase geometry, string key, T value, T def) where T : IConvertible { if (value.Equals(def)) { return(geometry.SetUserString(key, null)); } var stringValue = (string)System.Convert.ChangeType(value, typeof(string), System.Globalization.CultureInfo.InvariantCulture); return(geometry.SetUserString(key, stringValue)); }
public static bool TryGetUserString <T>(this GeometryBase geometry, string key, out T value, T def) where T : IConvertible { if (geometry.GetUserString(key) is string stringValue) { value = (T)System.Convert.ChangeType(stringValue, typeof(T), System.Globalization.CultureInfo.InvariantCulture); return(true); } value = def; return(false); }
/// <summary> /// Gets a rational degree 2 NURBS curve representation /// of the circle. Note that the parameterization of NURBS curve /// does not match circle's transcendental paramaterization. /// Use GetRadianFromNurbFormParameter() and /// GetParameterFromRadian() to convert between the NURBS curve /// parameter and the transcendental parameter. /// </summary> /// <returns>Curve on success, null on failure.</returns> public static NurbsCurve CreateFromCircle(Circle circle) { IntPtr pNC = UnsafeNativeMethods.ON_NurbsCurve_New(IntPtr.Zero); int success = UnsafeNativeMethods.ON_Circle_GetNurbForm(ref circle, pNC); if (0 == success) { UnsafeNativeMethods.ON_Object_Delete(pNC); return(null); } return(GeometryBase.CreateGeometryHelper(pNC, null) as NurbsCurve); }
/// <summary> /// Verifies some geometry is a rectangle /// </summary> public static bool IsRectangle(GeometryBase geometry) { var polyline_curve = geometry as PolylineCurve; return polyline_curve != null && IsRectangle(polyline_curve); }
private void MoveBlades(bool down, GeometryBase geo) { //Left Blade if (geo == _bladeLeft) { //Margin Down if (down && _bladeLeftPosition.Y - Settings.BladeSizeHalf.Y < -Settings.GameBoardHalfSizeY + Settings.BladeSize.X) { _bladeLeftPosition.Y = -Settings.GameBoardHalfSizeY + Settings.BladeSizeHalf.X + Settings.BladeSizeHalf.Y; _bladeTransformLetft = Transform.Translation(_bladeLeftPosition - _bladeLeftInitialPosition); return; } //Margin Up if (!down && _bladeLeftPosition.Y + Settings.BladeSizeHalf.Y > Settings.GameBoardHalfSizeY - Settings.BladeSize.X) { _bladeLeftPosition.Y = Settings.GameBoardHalfSizeY - Settings.BladeSizeHalf.X - Settings.BladeSizeHalf.Y; _bladeTransformLetft = Transform.Translation(_bladeLeftPosition - _bladeLeftInitialPosition); return; } var motion = (_frameRenderMilliseconds * Settings.SpeedBladePlayer); if (down) _bladeLeftPosition.Y -= motion; else _bladeLeftPosition.Y += motion; _bladeTransformLetft = Transform.Translation(_bladeLeftPosition - _bladeLeftInitialPosition); } //Right Blade else if (geo == _bladeRight) { //Margin Down if (down && _bladeRightPosition.Y - Settings.BladeSizeHalf.Y < -Settings.GameBoardHalfSizeY + Settings.BladeSize.X) { _bladeRightPosition.Y = -Settings.GameBoardHalfSizeY + Settings.BladeSizeHalf.X + Settings.BladeSizeHalf.Y; _bladeTransformRight = Transform.Translation(_bladeRightPosition - _bladeRightInitialPosition); return; } //Margin Up if (!down && _bladeRightPosition.Y + Settings.BladeSizeHalf.Y > Settings.GameBoardHalfSizeY - Settings.BladeSize.X) { _bladeRightPosition.Y = Settings.GameBoardHalfSizeY - Settings.BladeSizeHalf.X - Settings.BladeSizeHalf.Y; _bladeTransformRight = Transform.Translation(_bladeRightPosition - _bladeRightInitialPosition); return; } var motion = (_frameRenderMilliseconds * Settings.IALevel.SpeedBladeIA); if (down) _bladeRightPosition.Y -= motion; else _bladeRightPosition.Y += motion; _bladeTransformRight = Transform.Translation(_bladeRightPosition - _bladeRightInitialPosition); } }
/// <summary> /// This procedure contains the user code. Input parameters are provided as regular arguments, /// Output parameters as ref arguments. You don't have to assign output parameters, /// they will have a default value. /// </summary> private void RunScript(GeometryBase obj, List<Color> color, string layer, bool bake) { try{ var objAttr = new ObjectAttributes(); if(color.Count() != 0){ objAttr.ColorSource = ObjectColorSource.ColorFromObject; objAttr.ObjectColor = color[0]; } if(layer != ""){ objAttr.LayerIndex = GetLayerNumber(RhinoDocument, layer); } if(bake){ RhinoDocument.Objects.Add(obj, objAttr); } }catch(Exception e){ Print(e.ToString()); } }
/// <summary> /// Computes the distance of a point to a given geometry. (Brep, Mesh or closed Surface) /// </summary> public static double DistanceTo(GeometryBase geometry, Point3d testPoint, int spaceType) { double distanceTo = 0; Point3d closestPoint; switch (spaceType) { // Brep design space case 1: closestPoint = ((Brep)geometry).ClosestPoint(testPoint); distanceTo = testPoint.DistanceTo(closestPoint); break; // Mesh design space case 2: closestPoint = ((Mesh)geometry).ClosestPoint(testPoint); distanceTo = testPoint.DistanceTo(closestPoint); break; // Solid surface design space (must be converted to brep) case 3: closestPoint = ((Surface)geometry).ToBrep().ClosestPoint(testPoint); distanceTo = testPoint.DistanceTo(closestPoint); break; } return distanceTo; }
/// <summary> /// Determines if a point is inside a geometry. (Brep, Mesh or closed Surface) /// </summary> public static bool IsPointInside(GeometryBase geometry, Point3d testPoint, int spaceType, double tol, bool strictlyIn) { bool isInside = false; switch (spaceType) { // Brep design space case 1: isInside = ((Brep)geometry).IsPointInside(testPoint, tol, strictlyIn); break; // Mesh design space case 2: isInside = ((Mesh)geometry).IsPointInside(testPoint, tol, strictlyIn); break; // Solid surface design space (must be converted to brep) case 3: isInside = ((Surface)geometry).ToBrep().IsPointInside(testPoint, tol, strictlyIn); break; } return isInside; }
/// <summary> /// Unions the entire ObjectTable BBox with the geo BBox and, if layerIndex is less than the count of layerBBox, /// unions the LayerBBoxes list at the layerIndex provided with the geo BBox. /// </summary> protected virtual void AddObjectBoundingBox (GeometryBase geo, int layerIndex) { ModelFile.Objects.GetBoundingBox().Union (geo.GetBoundingBox (false)); if ((layerIndex >= 0) && (layerIndex < LayerBBoxes.Count ())) LayerBBoxes [layerIndex].Union (geo.GetBoundingBox (false)); }
/// <summary> /// Maps cell topology to the node grid and trims to the design space. /// </summary> public void UniformMapping(UnitCell cell, GeometryBase designSpace, int spaceType, float[] N, double minStrutLength, double maxStrutLength) { double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; for (int u = 0; u <= N[0]; u++) { for (int v = 0; v <= N[1]; v++) { for (int w = 0; w <= N[2]; w++) { // We're inside a unit cell // Loop through all pairs of nodes that make up struts foreach (IndexPair nodePair in cell.NodePairs) { // Prepare the path of the nodes (path in tree) // First, get relative paths of nodes (with respect to current unit cell) int[] IRel = cell.NodePaths[nodePair.I]; int[] JRel = cell.NodePaths[nodePair.J]; // Next, compute absolute paths GH_Path IPath = new GH_Path(u + IRel[0], v + IRel[1], w + IRel[2]); GH_Path JPath = new GH_Path(u + JRel[0], v + JRel[1], w + JRel[2]); // Make sure the cell exists if (Nodes.PathExists(IPath) && Nodes.PathExists(JPath)) { LatticeNode node1 = Nodes[IPath, IRel[3]]; LatticeNode node2 = Nodes[JPath, JRel[3]]; // Make sure both nodes exist: // Null nodes either belong to other cells, or are beyond the upper uvw boundary if (node1 != null && node2 != null) { Curve fullCurve = new LineCurve(node1.Point3d, node2.Point3d); // If both nodes are inside, add full strut if (node1.IsInside && node2.IsInside) { Struts.Add(fullCurve); } // If neither node is inside, skip to next loop else if (!node1.IsInside && !node2.IsInside) { continue; } // Else, strut requires trimming else { // We are going to find the intersection point with the design space Point3d[] intersectionPts = null; Curve[] overlapCurves = null; LineCurve strutToTrim = null; switch (spaceType) { // Brep design space case 1: strutToTrim = new LineCurve(node1.Point3d, node2.Point3d); // Find intersection point Intersection.CurveBrep(strutToTrim, (Brep)designSpace, tol, out overlapCurves, out intersectionPts); break; // Mesh design space case 2: // Dummy faceIds variable for MeshLine call int[] faceIds; strutToTrim = new LineCurve(node1.Point3d, node2.Point3d); // Find intersection point intersectionPts = Intersection.MeshLine((Mesh)designSpace, strutToTrim.Line, out faceIds); break; // Solid surface design space case 3: // Dummy overlapCurves variable for CurveBrep call overlapCurves = null; strutToTrim = new LineCurve(node1.Point3d, node2.Point3d); // Find intersection point Intersection.CurveBrep(strutToTrim, ((Surface)designSpace).ToBrep(), tol, out overlapCurves, out intersectionPts); break; } LineCurve testLine = null; // Now, if an intersection point was found, trim the strut if (intersectionPts.Length > 0) { testLine = AddTrimmedStrut(node1, node2, intersectionPts[0], minStrutLength, maxStrutLength); // If the strut was succesfully trimmed, add it to the list if (testLine != null) { Struts.Add(testLine); } } else if (overlapCurves != null && overlapCurves.Length > 0) { Struts.Add(overlapCurves[0]); } } } } } } } } }
/// <summary> /// Checks geometry to see if it can be selected. /// Override to provide fancy filtering. /// </summary> /// <param name="rhObject">parent object being considered.</param> /// <param name="geometry">geometry being considered.</param> /// <param name="componentIndex"> /// if >= 0, geometry is a proper sub-part of object->Geometry() with componentIndex. /// </param> /// <returns> /// The default returns true unless you've set a custom geometry filter. If a custom /// filter has been set, that delegate is called /// </returns> public virtual bool CustomGeometryFilter( DocObjects.RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex ) { if (m_filter != null) return m_filter(rhObject, geometry, componentIndex); return true; }
/// <summary> /// Is called when a non-const operation occurs. /// </summary> protected override void OnSwitchToNonConst() { m_shallow_parent = null; base.OnSwitchToNonConst(); }
/// <summary> /// Gets closest points between this and another curves. /// </summary> /// <param name="otherCurve">The other curve.</param> /// <param name="pointOnThisCurve">The point on this curve. This out parameter is assigned during this call.</param> /// <param name="pointOnOtherCurve">The point on other curve. This out parameter is assigned during this call.</param> /// <returns>true on success; false on error.</returns> public bool ClosestPoints(Curve otherCurve, out Point3d pointOnThisCurve, out Point3d pointOnOtherCurve) { GeometryBase[] a = new GeometryBase[] { otherCurve }; int which; return ClosestPoints(a, out pointOnThisCurve, out pointOnOtherCurve, out which, 0.0); }
/// <summary> /// Validates a GeometryBase design space as a brep or a mesh. /// </summary> public static int ValidateSpace(ref GeometryBase designSpace) { // Types: 0-invalid, 1-brep, 2-mesh, 3-solid surface int type = 0; if (designSpace.ObjectType == ObjectType.Brep) { type = 1; } else if (designSpace.ObjectType == ObjectType.Mesh && ((Mesh)designSpace).IsClosed) { type = 2; } else if (designSpace.ObjectType == ObjectType.Surface && ((Surface)designSpace).IsSolid) { type = 3; } return type; }
/// <summary> /// Moves changes made to this RhinoObject into the RhinoDoc. /// </summary> /// <returns> /// true if changes were made. /// </returns> /// <example> /// <code source='examples\vbnet\ex_addlayout.vb' lang='vbnet'/> /// <code source='examples\cs\ex_addlayout.cs' lang='cs'/> /// <code source='examples\py\ex_addlayout.py' lang='py'/> /// </example> public bool CommitChanges() { bool rc = false; if (null != m_edited_geometry) { CommitGeometryChangesFunc func = GetCommitFunc(); if (null == func) return false; IntPtr pConstGeometry = m_edited_geometry.ConstPointer(); uint serial_number = func(m_rhinoobject_serial_number, pConstGeometry); if (serial_number > 0) { rc = true; m_rhinoobject_serial_number = serial_number; m_edited_geometry = null; } else return false; } if (null != m_edited_attributes) { rc = Document.Objects.ModifyAttributes(this, m_edited_attributes, false); if (rc) m_edited_attributes = null; } return rc; }
/// <summary> /// We create a DisplayMesh object for each render mesh object we find. If we encounter an Mesh object, /// we create a DisplayMesh object from the Mesh. For any Brep objects, we create Displaymesh objects /// from the render mesh. For any Extrusion objects, we create a DisplayMesh from the RenderMesh. For /// InstanceReference objects, _____ /// </summary> protected virtual void PrepareObject (GeometryBase pObject, ObjectAttributes attr) { while (LayerBBoxes.Count < ModelFile.Layers.Count) { BoundingBox invalidBBox = BoundingBox.Empty; LayerBBoxes.Add (invalidBBox); } // Geometry sorting... // Meshes-------------------------------------------------------------------------------------------- if (pObject.ObjectType == ObjectType.Mesh /*&& attr.Mode != ObjectMode.InstanceDefinitionObject*/) { if (!(pObject as Mesh).IsValid) { (pObject as Mesh).Compact (); (pObject as Mesh).Normals.ComputeNormals (); } // Check to see if any of the vertices are hidden...if they are, remove them from the list for (int i = 0; i < (pObject as Mesh).Vertices.Count; i++) { bool vertexIsHidden = (pObject as Mesh).Vertices.IsHidden (i); if (vertexIsHidden) { (pObject as Mesh).Vertices.Remove (i, true); } } // Some 3dm files have meshes with no normals and this messes up the shading code... if (((pObject as Mesh).Normals.Count == 0) && ((pObject as Mesh).Vertices.Count > 0) && ((pObject as Mesh).Faces.Count > 0)) { (pObject as Mesh).Normals.ComputeNormals (); } GeometryCount++; AddModelMesh ((pObject as Mesh), attr); // Breps ------------------------------------------------------------------------------------------- } else if (pObject.ObjectType == ObjectType.Brep) { BRepCount++; List<Mesh> meshes = new List<Mesh> (); //Loop through each BrepFace in the BRep and GetMesh, adding it to meshes int count = 0; foreach (BrepFace face in (pObject as Brep).Faces) { var renderMesh = face.GetMesh (MeshType.Render); if (renderMesh != null) { meshes.Add (face.GetMesh (MeshType.Render)); count++; } } if (count > 0) BRepWithMeshCount++; if (count == 1) { if ((meshes [0] != null) && (meshes [0].Vertices.Count > 0)) { GeometryCount++; AddModelMesh (meshes [0], attr); } } else if (count > 0) { Mesh meshCandidate = new Mesh (); // Sometimes it's possible to have lists of NULL ON_Meshes...Rhino // can put them there as placeholders for badly formed/meshed breps. // Therefore, we need to always make sure we're actually looking at // a mesh that contains something and/or is not NULL. for (int i = 0; i < count; i++) { // If we have a valid pointer, append the mesh to our accumulator mesh... if (meshes [i] != null) { meshCandidate.Append (meshes [i]); } } // See if the end result actually contains anything and add it to our model if it does... if (meshCandidate.Vertices.Count > 0) { GeometryCount++; AddModelMesh (meshCandidate, attr); } } // Extrusions -------------------------------------------------------------------------------------- } else if (pObject.ObjectType == ObjectType.Extrusion) { ExtrusionCount++; Rhino.Geometry.Mesh meshCandidate = (pObject as Extrusion).GetMesh (Rhino.Geometry.MeshType.Render); // See if the end result actually contains anything and add it to our model if it does... if (meshCandidate != null) { if (meshCandidate.Vertices.Count > 0) { GeometryCount++; AddModelMesh(meshCandidate, attr); } } // Instance References ----------------------------------------------------------------------------- } else if (pObject.ObjectType == ObjectType.InstanceReference) { Rhino.Geometry.InstanceReferenceGeometry instanceRef = (InstanceReferenceGeometry)pObject; ModelInstanceRef iRef = new ModelInstanceRef(attr.ObjectId, instanceRef.ParentIdefId, instanceRef.Xform); if (iRef != null) { iRef.LayerIndex = attr.LayerIndex; GeometryCount++; AddModelObject (iRef, attr); } } }
/// <summary> /// Checks geometry to see if it can be selected. /// Override to provide fancy filtering. /// </summary> /// <param name="rhObject">parent object being considered.</param> /// <param name="geometry">geometry being considered.</param> /// <param name="componentIndex"> /// if >= 0, geometry is a proper sub-part of object->Geometry() with componentIndex. /// </param> /// <returns>The default always returns true.</returns> public virtual bool CustomGeometryFilter( DocObjects.RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex ) { return true; }
/// <summary> /// Checks geometry to see if it passes the basic GeometryAttributeFilter. /// </summary> /// <param name="rhObject">parent object being considered.</param> /// <param name="geometry">geometry being considered.</param> /// <param name="componentIndex">if >= 0, geometry is a proper sub-part of object->Geometry() with componentIndex.</param> /// <returns> /// true if the geometry passes the filter returned by GeometryAttributeFilter(). /// </returns> public bool PassesGeometryAttributeFilter(DocObjects.RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex) { IntPtr pRhinoObject = IntPtr.Zero; if (rhObject != null) pRhinoObject = rhObject.ConstPointer(); IntPtr pGeometry = IntPtr.Zero; if (geometry != null) pGeometry = geometry.ConstPointer(); IntPtr ptr = NonConstPointer(); return UnsafeNativeMethods.CRhinoGetObject_PassesGeometryAttributeFilter(ptr, pRhinoObject, pGeometry, componentIndex); }
/// <summary> /// Initializes a box that contains a generic piece of geometry. /// This box will be aligned with an arbitrary plane. /// </summary> /// <param name="basePlane">Base plane for aligned bounding box.</param> /// <param name="geometry">Geometry to box.</param> public Box(Plane basePlane, GeometryBase geometry) { // David: this code is untested. m_dx = new Interval(+1, -1); m_dy = new Interval(0, 0); m_dz = new Interval(0, 0); m_plane = basePlane; if (!m_plane.IsValid) { return; } Transform mapping = Geometry.Transform.ChangeBasis(Plane.WorldXY, m_plane); BoundingBox bbox = geometry.GetBoundingBox(mapping); m_dx = new Interval(bbox.Min.m_x, bbox.Max.m_x); m_dy = new Interval(bbox.Min.m_y, bbox.Max.m_y); m_dz = new Interval(bbox.Min.m_z, bbox.Max.m_z); MakeValid(); }
/// <summary> /// Copies the unmanaged array to a managed counterpart. /// </summary> /// <returns>The managed array.</returns> public GeometryBase[] ToNonConstArray() { int count = UnsafeNativeMethods.ON_GeometryArray_Count(m_ptr); GeometryBase[] rc = new GeometryBase[count]; for (int i = 0; i < count; i++) { IntPtr pGeometry = UnsafeNativeMethods.ON_GeometryArray_Get(m_ptr, i); rc[i] = GeometryBase.CreateGeometryHelper(pGeometry, null); } return rc; }
/// <summary> /// Override to provide fancy object filtering /// </summary> public override bool CustomGeometryFilter(RhinoObject rhObject, GeometryBase geometry, ComponentIndex componentIndex) { return SampleCsRectangleHelper.IsRectangle(geometry); }