/// <summary>Utility for picking 3d point</summary> /// <param name="point"></param> /// <param name="depth"> /// depth returned here for point picks. /// LARGER values are NEARER to the camera. /// SMALLER values are FARTHER from the camera. /// </param> /// <param name="distance"> /// planar distance returned here for point picks. /// SMALLER values are CLOSER to the pick point /// </param> /// <returns>true if there is a hit</returns> /// <since>5.0</since> public bool PickFrustumTest(Geometry.Point3d point, out double depth, out double distance) { depth = -1; distance = -1; IntPtr const_ptr_this = ConstPointer(); return(UnsafeNativeMethods.CRhinoPickContext_PickPoint(const_ptr_this, point, ref depth, ref distance)); }
/// <summary> /// Returns a bounding box for the custom render meshes for the given object. /// </summary> /// <param name="vp">The viewport being rendered.</param> /// <param name="obj">The Rhino object of interest.</param> /// <param name="requestingPlugIn">UUID of the RDK plug-in requesting the meshes.</param> /// <param name="meshType">Type of mesh to build.</param> /// <returns>A bounding box value.</returns> public virtual Rhino.Geometry.BoundingBox BoundingBox(Rhino.DocObjects.ViewportInfo vp, Rhino.DocObjects.RhinoObject obj, Guid requestingPlugIn, MeshTypes meshType) { Geometry.Point3d min = new Geometry.Point3d(); Geometry.Point3d max = new Geometry.Point3d(); if (UnsafeNativeMethods.Rdk_RMPBoundingBoxImpl(m_runtime_serial_number, vp.ConstPointer(), obj.ConstPointer(), requestingPlugIn, (int)meshType, ref min, ref max)) { return(new Rhino.Geometry.BoundingBox(min, max)); } return(new Rhino.Geometry.BoundingBox()); }
/// <summary> /// Returns a bounding box for the custom render meshes for the given object. /// </summary> /// <param name="vp"> the viewport being rendered.</param> /// <param name="obj">Rhino object of interest.</param> /// <param name="requestingPlugIn">UUID of the RDK plug-in requesting the meshes.</param> /// <param name="meshType"> type of mesh(es) to build the bounding box for.</param> /// <param name="soleProviderId">the sole provider to call.</param> /// <returns>ON_BoundingBox for the meshes.</returns> public static Rhino.Geometry.BoundingBox BoundingBox(Rhino.DocObjects.ViewportInfo vp, Rhino.DocObjects.RhinoObject obj, Guid requestingPlugIn, MeshTypes meshType, Guid soleProviderId) { Geometry.Point3d min = new Geometry.Point3d(); Geometry.Point3d max = new Geometry.Point3d(); if (UnsafeNativeMethods.Rdk_CRMManager_BoundingBoxSole(vp.ConstPointer(), obj.ConstPointer(), requestingPlugIn, (int)meshType, soleProviderId, ref min, ref max)) { Rhino.Geometry.BoundingBox bb = new Geometry.BoundingBox(); return(bb); } return(new Geometry.BoundingBox()); }
/// <summary>Utility for picking meshes</summary> /// <param name="mesh">mesh to test</param> /// <param name="pickStyle">mode used for pick test</param> /// <param name="hitPoint">location returned here for point picks</param> /// <param name="depth"> /// depth returned here for point picks /// LARGER values are NEARER to the camera. /// SMALLER values are FARTHER from the camera. /// </param> /// <param name="distance"> /// planar distance returned here for point picks. /// SMALLER values are CLOSER to the pick point /// </param> /// <param name="hitFlag"> /// For point picks, How to interpret the hitIndex (vertex hit, edge hit, or face hit) /// </param> /// <param name="hitIndex"> /// index of vertex/edge/face that was hit. Use hitFlag to determine what this index /// corresponds to /// </param> /// <returns></returns> /// <since>5.0</since> public bool PickFrustumTest(Geometry.Mesh mesh, MeshPickStyle pickStyle, out Geometry.Point3d hitPoint, out double depth, out double distance, out MeshHitFlag hitFlag, out int hitIndex) { hitPoint = Geometry.Point3d.Unset; depth = -1; distance = -1; hitIndex = -1; IntPtr const_ptr_this = ConstPointer(); IntPtr const_ptr_mesh = mesh.ConstPointer(); int vef_flag = -1; bool rc = UnsafeNativeMethods.CRhinoPickContext_PickMesh2(const_ptr_this, const_ptr_mesh, (int)pickStyle, ref hitPoint, ref depth, ref distance, ref vef_flag, ref hitIndex); hitFlag = (MeshHitFlag)vef_flag; return(rc); }
/// <summary> /// Returns a bounding box for the custom render meshes for the given object. /// </summary> /// <param name="vp"> the viewport being rendered.</param> /// <param name="obj">Rhino object of interest.</param> /// <param name="requestingPlugIn">UUID of the RDK plug-in requesting the meshes.</param> /// <param name="meshType"> type of mesh(es) to build the bounding box for.</param> /// <returns>ON_BoundingBox for the meshes.</returns> public static Rhino.Geometry.BoundingBox BoundingBox(Rhino.DocObjects.ViewportInfo vp, Rhino.DocObjects.RhinoObject obj, Guid requestingPlugIn, MeshTypes meshType) { Rhino.Geometry.Point3d min = new Geometry.Point3d(); Rhino.Geometry.Point3d max = new Geometry.Point3d(); Rhino.Geometry.BoundingBox bb = new Geometry.BoundingBox(); if (UnsafeNativeMethods.Rdk_CRMManager_BoundingBox(vp.ConstPointer(), obj.ConstPointer(), requestingPlugIn, (int)meshType, ref min, ref max)) { bb.Min = min; bb.Max = max; } return(bb); }
internal static void WriteIntoSerializationInfo(IntPtr pRhCmnProfileContext, System.Runtime.Serialization.SerializationInfo info, string prefixStrip) { const int _string = 1; const int _multistring = 2; const int _uuid = 3; const int _color = 4; const int _int = 5; const int _double = 6; const int _rect = 7; const int _point = 8; const int _3dpoint = 9; const int _xform = 10; const int _3dvector = 11; const int _meshparams = 12; const int _buffer = 13; const int _bool = 14; int count = UnsafeNativeMethods.CRhCmnProfileContext_Count(pRhCmnProfileContext); using (StringHolder sectionholder = new StringHolder()) using (StringHolder entryholder = new StringHolder()) { IntPtr pStringSection = sectionholder.NonConstPointer(); IntPtr pStringEntry = entryholder.NonConstPointer(); for (int i = 0; i < count; i++) { int pctype = 0; UnsafeNativeMethods.CRhCmnProfileContext_Item(pRhCmnProfileContext, i, pStringSection, pStringEntry, ref pctype); string section = sectionholder.ToString(); string entry = entryholder.ToString(); if (string.IsNullOrEmpty(entry)) continue; string name = string.IsNullOrEmpty(section) ? entry : section + "\\" + entry; if (name.StartsWith(prefixStrip + "\\")) name = name.Substring(prefixStrip.Length + 1); name = name.Replace("\\", "::"); switch (pctype) { case _string: { UnsafeNativeMethods.CRhinoProfileContext_LoadString(pRhCmnProfileContext, section, entry, pStringEntry); string val = entryholder.ToString(); info.AddValue(name, val); } break; case _multistring: { IntPtr pStrings = UnsafeNativeMethods.ON_StringArray_New(); int array_count = UnsafeNativeMethods.CRhinoProfileContext_LoadStrings(pRhCmnProfileContext, section, entry, pStrings); string[] s = new string[array_count]; for( int j=0; j<array_count; j++ ) { UnsafeNativeMethods.ON_StringArray_Get(pStrings, j, pStringEntry); s[j] = entryholder.ToString(); } info.AddValue(name, s); } break; case _uuid: { Guid id = Guid.Empty; UnsafeNativeMethods.CRhinoProfileContext_LoadGuid(pRhCmnProfileContext, section, entry, ref id); info.AddValue(name, id); } break; case _color: { int abgr = 0; UnsafeNativeMethods.CRhinoProfileContext_LoadColor(pRhCmnProfileContext, section, entry, ref abgr); System.Drawing.Color c = System.Drawing.ColorTranslator.FromWin32(abgr); //string s = System.Drawing.ColorTranslator.ToHtml(c); info.AddValue(name, c); } break; case _int: { int ival = 0; UnsafeNativeMethods.CRhinoProfileContext_LoadInt(pRhCmnProfileContext, section, entry, ref ival); info.AddValue(name, ival); } break; case _double: { double dval = 0; UnsafeNativeMethods.CRhinoProfileContext_LoadDouble(pRhCmnProfileContext, section, entry, ref dval); info.AddValue(name, dval); } break; case _rect: { int left = 0, top = 0, right = 0, bottom = 0; UnsafeNativeMethods.CRhinoProfileContext_LoadRect(pRhCmnProfileContext, section, entry, ref left, ref top, ref right, ref bottom); System.Drawing.Rectangle r = System.Drawing.Rectangle.FromLTRB(left, top, right, bottom); info.AddValue(name, r); } break; case _point: { int x = 0, y = 0; UnsafeNativeMethods.CRhinoProfileContext_LoadPoint(pRhCmnProfileContext, section, entry, ref x, ref y); System.Drawing.Point pt = new System.Drawing.Point(x, y); info.AddValue(name, pt); } break; case _3dpoint: { Rhino.Geometry.Point3d pt = new Geometry.Point3d(); UnsafeNativeMethods.CRhinoProfileContext_LoadPoint3d(pRhCmnProfileContext, section, entry, ref pt); info.AddValue(name, pt); } break; case _xform: { Rhino.Geometry.Transform xf = new Geometry.Transform(); UnsafeNativeMethods.CRhinoProfileContext_LoadXform(pRhCmnProfileContext, section, entry, ref xf); info.AddValue(name, xf); } break; case _3dvector: { Rhino.Geometry.Vector3d vec = new Geometry.Vector3d(); UnsafeNativeMethods.CRhinoProfileContext_LoadVector3d(pRhCmnProfileContext, section, entry, ref vec); info.AddValue(name, vec); } break; case _meshparams: { Rhino.Geometry.MeshingParameters mp = new Geometry.MeshingParameters(); UnsafeNativeMethods.CRhinoProfileContext_LoadMeshParameters(pRhCmnProfileContext, section, entry, mp.NonConstPointer()); info.AddValue(name, mp); mp.Dispose(); } break; case _buffer: { //not supported yet //int buffer_length = UnsafeNativeMethods.CRhinoProfileContext_BufferLength(pRhCmnProfileContext, section, entry); //byte[] buffer = new byte[buffer_length]; //UnsafeNativeMethods.CRhinoProfileContext_LoadBuffer(pRhCmnProfileContext, section, entry, buffer_length, buffer); //info.AddValue(name, buffer); } break; case _bool: { bool b = false; UnsafeNativeMethods.CRhinoProfileContext_LoadBool(pRhCmnProfileContext, section, entry, ref b); info.AddValue(name, b); } break; } } } }
public bool TryGetPoint3d(int id, out Geometry.Point3d value) { value = new Geometry.Point3d(); return UnsafeNativeMethods.CRhinoHistoryRecord_GetPoint3d(m_pConstRhinoHistoryRecord, id, ref value); }
internal static void WriteIntoSerializationInfo(IntPtr pRhCmnProfileContext, System.Runtime.Serialization.SerializationInfo info, string prefixStrip) { const int _string = 1; const int _multistring = 2; const int _uuid = 3; const int _color = 4; const int _int = 5; const int _double = 6; const int _rect = 7; const int _point = 8; const int _3dpoint = 9; const int _xform = 10; const int _3dvector = 11; const int _meshparams = 12; const int _buffer = 13; const int _bool = 14; int count = UnsafeNativeMethods.CRhCmnProfileContext_Count(pRhCmnProfileContext); using (StringHolder sectionholder = new StringHolder()) using (StringHolder entryholder = new StringHolder()) { IntPtr pStringSection = sectionholder.NonConstPointer(); IntPtr pStringEntry = entryholder.NonConstPointer(); for (int i = 0; i < count; i++) { int pctype = 0; UnsafeNativeMethods.CRhCmnProfileContext_Item(pRhCmnProfileContext, i, pStringSection, pStringEntry, ref pctype); string section = sectionholder.ToString(); string entry = entryholder.ToString(); if (string.IsNullOrEmpty(entry)) continue; string name = string.IsNullOrEmpty(section) ? entry : section + "\\" + entry; if (name.StartsWith(prefixStrip + "\\")) name = name.Substring(prefixStrip.Length + 1); name = name.Replace("\\", "::"); switch (pctype) { case _string: { UnsafeNativeMethods.CRhinoProfileContext_LoadString(pRhCmnProfileContext, section, entry, pStringEntry); string val = entryholder.ToString(); info.AddValue(name, val); } break; case _multistring: { IntPtr pStrings = UnsafeNativeMethods.ON_StringArray_New(); int array_count = UnsafeNativeMethods.CRhinoProfileContext_LoadStrings(pRhCmnProfileContext, section, entry, pStrings); string[] s = new string[array_count]; for( int j=0; j<array_count; j++ ) { UnsafeNativeMethods.ON_StringArray_Get(pStrings, j, pStringEntry); s[j] = entryholder.ToString(); } info.AddValue(name, s); } break; case _uuid: { Guid id = Guid.Empty; UnsafeNativeMethods.CRhinoProfileContext_LoadGuid(pRhCmnProfileContext, section, entry, ref id); info.AddValue(name, id); } break; case _color: { int abgr = 0; UnsafeNativeMethods.CRhinoProfileContext_LoadColor(pRhCmnProfileContext, section, entry, ref abgr); System.Drawing.Color c = Interop.ColorFromWin32(abgr); //string s = System.Drawing.ColorTranslator.ToHtml(c); info.AddValue(name, c); } break; case _int: { int ival = 0; UnsafeNativeMethods.CRhinoProfileContext_LoadInt(pRhCmnProfileContext, section, entry, ref ival); info.AddValue(name, ival); } break; case _double: { double dval = 0; UnsafeNativeMethods.CRhinoProfileContext_LoadDouble(pRhCmnProfileContext, section, entry, ref dval); info.AddValue(name, dval); } break; case _rect: { int left = 0, top = 0, right = 0, bottom = 0; UnsafeNativeMethods.CRhinoProfileContext_LoadRect(pRhCmnProfileContext, section, entry, ref left, ref top, ref right, ref bottom); System.Drawing.Rectangle r = System.Drawing.Rectangle.FromLTRB(left, top, right, bottom); info.AddValue(name, r); } break; case _point: { int x = 0, y = 0; UnsafeNativeMethods.CRhinoProfileContext_LoadPoint(pRhCmnProfileContext, section, entry, ref x, ref y); System.Drawing.Point pt = new System.Drawing.Point(x, y); info.AddValue(name, pt); } break; case _3dpoint: { Rhino.Geometry.Point3d pt = new Geometry.Point3d(); UnsafeNativeMethods.CRhinoProfileContext_LoadPoint3d(pRhCmnProfileContext, section, entry, ref pt); info.AddValue(name, pt); } break; case _xform: { Rhino.Geometry.Transform xf = new Geometry.Transform(); UnsafeNativeMethods.CRhinoProfileContext_LoadXform(pRhCmnProfileContext, section, entry, ref xf); info.AddValue(name, xf); } break; case _3dvector: { Rhino.Geometry.Vector3d vec = new Geometry.Vector3d(); UnsafeNativeMethods.CRhinoProfileContext_LoadVector3d(pRhCmnProfileContext, section, entry, ref vec); info.AddValue(name, vec); } break; case _meshparams: { Rhino.Geometry.MeshingParameters mp = new Geometry.MeshingParameters(); UnsafeNativeMethods.CRhinoProfileContext_LoadMeshParameters(pRhCmnProfileContext, section, entry, mp.NonConstPointer()); info.AddValue(name, mp); mp.Dispose(); } break; case _buffer: { //not supported yet //int buffer_length = UnsafeNativeMethods.CRhinoProfileContext_BufferLength(pRhCmnProfileContext, section, entry); //byte[] buffer = new byte[buffer_length]; //UnsafeNativeMethods.CRhinoProfileContext_LoadBuffer(pRhCmnProfileContext, section, entry, buffer_length, buffer); //info.AddValue(name, buffer); } break; case _bool: { bool b = false; UnsafeNativeMethods.CRhinoProfileContext_LoadBool(pRhCmnProfileContext, section, entry, ref b); info.AddValue(name, b); } break; } } } }
static int OnBBox(int serialNumber, IntPtr pViewport, IntPtr pObject, Guid plugInId, int type, ref Geometry.Point3d min, ref Geometry.Point3d max) { try { Provider p = Provider.FromSerialNumber(serialNumber); if (p != null) { Geometry.BoundingBox bbox = p.BoundingBox(new Rhino.DocObjects.ViewportInfo(pViewport), DocObjects.RhinoObject.CreateRhinoObjectHelper(pObject), plugInId, (MeshTypes)type); min = bbox.Min; max = bbox.Max; return(1); } } catch (Exception ex) { Rhino.Runtime.HostUtils.ExceptionReport(ex); } return(0); }
/// <summary> /// Use SetFirstPoint to specify the line's starting point and skip /// the start point interactive picking /// </summary> /// <param name="point"></param> /// <since>6.0</since> public void SetFirstPoint(Geometry.Point3d point) { IntPtr ptr_this = NonConstPointer(); UnsafeNativeMethods.CArgsRhinoGetPolyline_SetFirstPoint(ptr_this, point); }
/// <summary> /// Returns a bounding box for the custom render meshes for the given object. /// </summary> /// <param name="vp">The viewport being rendered.</param> /// <param name="obj">The Rhino object of interest.</param> /// <param name="requestingPlugIn">UUID of the RDK plug-in requesting the meshes.</param> /// <param name="meshType">Type of mesh to build.</param> /// <returns>A bounding box value.</returns> public virtual Rhino.Geometry.BoundingBox BoundingBox(Rhino.DocObjects.ViewportInfo vp, Rhino.DocObjects.RhinoObject obj, Guid requestingPlugIn, MeshTypes meshType) { Geometry.Point3d min = new Geometry.Point3d(); Geometry.Point3d max = new Geometry.Point3d(); if (UnsafeNativeMethods.Rdk_RMPBoundingBoxImpl(m_runtime_serial_number, vp.ConstPointer(), obj.ConstPointer(), requestingPlugIn, (int)meshType, ref min, ref max)) return new Rhino.Geometry.BoundingBox(min, max); return new Rhino.Geometry.BoundingBox(); }
/// <summary> /// Returns a bounding box for the custom render meshes for the given object. /// </summary> /// <param name="vp"> the viewport being rendered.</param> /// <param name="obj">Rhino object of interest.</param> /// <param name="requestingPlugIn">UUID of the RDK plug-in requesting the meshes.</param> /// <param name="meshType"> type of mesh(es) to build the bounding box for.</param> /// <returns>ON_BoundingBox for the meshes.</returns> public static Rhino.Geometry.BoundingBox BoundingBox(Rhino.DocObjects.ViewportInfo vp, Rhino.DocObjects.RhinoObject obj, Guid requestingPlugIn, MeshTypes meshType) { Rhino.Geometry.Point3d min = new Geometry.Point3d(); Rhino.Geometry.Point3d max = new Geometry.Point3d(); Rhino.Geometry.BoundingBox bb = new Geometry.BoundingBox(); if (UnsafeNativeMethods.Rdk_CRMManager_BoundingBox(vp.ConstPointer(), obj.ConstPointer(), requestingPlugIn, (int)meshType, ref min, ref max)) { bb.Min = min; bb.Max = max; } return bb; }
/// <summary> /// Returns a bounding box for the custom render meshes for the given object. /// </summary> /// <param name="vp"> the viewport being rendered.</param> /// <param name="obj">Rhino object of interest.</param> /// <param name="requestingPlugIn">UUID of the RDK plug-in requesting the meshes.</param> /// <param name="meshType"> type of mesh(es) to build the bounding box for.</param> /// <param name="soleProviderId">the sole provider to call.</param> /// <returns>ON_BoundingBox for the meshes.</returns> public static Rhino.Geometry.BoundingBox BoundingBox(Rhino.DocObjects.ViewportInfo vp, Rhino.DocObjects.RhinoObject obj, Guid requestingPlugIn, MeshTypes meshType, Guid soleProviderId) { Geometry.Point3d min = new Geometry.Point3d(); Geometry.Point3d max = new Geometry.Point3d(); if (UnsafeNativeMethods.Rdk_CRMManager_BoundingBoxSole(vp.ConstPointer(), obj.ConstPointer(), requestingPlugIn, (int)meshType, soleProviderId, ref min, ref max)) { Rhino.Geometry.BoundingBox bb = new Geometry.BoundingBox(); return bb; } return new Geometry.BoundingBox(); }