Example #1
0
 /// <summary>
 /// Returns the underlying const CRhinoObject* for a RhinoCommon class. You should only
 /// be interested in using this function if you are writing C++ code.
 /// </summary>
 /// <param name="rhinoObject">A Rhino object.</param>
 /// <returns>A pointer to the Rhino const object.</returns>
 public static IntPtr RhinoObjectConstPointer(Rhino.DocObjects.RhinoObject rhinoObject)
 {
   IntPtr rc = IntPtr.Zero;
   if (rhinoObject != null)
     rc = rhinoObject.ConstPointer();
   return rc;
 }
Example #2
0
 /// <summary>
 /// Constructs a new basic material from a <see cref="Rhino.DocObjects.Material">Material</see>.
 /// </summary>
 /// <param name="material">(optional)The material to create the basic material from.</param>
 /// <returns>A new basic material.</returns>
 public static RenderMaterial CreateBasicMaterial(Rhino.DocObjects.Material material)
 {
   IntPtr pConstSourceMaterial = (material == null ? IntPtr.Zero : material.ConstPointer());
   IntPtr pNewMaterial = UnsafeNativeMethods.Rdk_Globals_NewBasicMaterial(pConstSourceMaterial);
   NativeRenderMaterial newMaterial = RenderContent.FromPointer(pNewMaterial) as NativeRenderMaterial;
   if (newMaterial != null)
     newMaterial.AutoDelete = true;
   return newMaterial;
 }
Example #3
0
    /// <summary>
    /// Constructs a light which simulates a <see cref="Rhino.Render.Sun"/>.
    /// </summary>
    /// <param name="sun">A Sun object from the Rhino.Render namespace.</param>
    /// <returns>A light.</returns>
    public static Light CreateSunLight(Rhino.Render.Sun sun)
    {
      Rhino.Runtime.HostUtils.CheckForRdk(true, true);

      Rhino.Geometry.Light rc = new Rhino.Geometry.Light();
      IntPtr pLight = rc.NonConstPointer();
      IntPtr pConstSun = sun.ConstPointer();
      UnsafeNativeMethods.Rdk_Sun_Light(pConstSun, pLight);

      return rc;
    }
 /// <summary>
 /// Capture View contents to a bitmap using display attributes to define how
 /// drawing is performed.
 /// </summary>
 /// <param name="size">The width and height of the returned bitmap.</param>
 /// <param name="attributes">The specific display mode attributes.</param>
 /// <returns>A new bitmap.</returns>
 public System.Drawing.Bitmap CaptureToBitmap(System.Drawing.Size size, Rhino.Display.DisplayPipelineAttributes attributes)
 {
   IntPtr pConstView = ConstPointer();
   IntPtr pAttributes = attributes.ConstPointer();
   IntPtr pRhinoDib = UnsafeNativeMethods.CRhinoDib_New();
   System.Drawing.Bitmap rc = null;
   if (UnsafeNativeMethods.CRhinoView_CaptureToBitmap(pConstView, pRhinoDib, size.Width, size.Height, pAttributes))
   {
     IntPtr hBmp = UnsafeNativeMethods.CRhinoDib_Bitmap(pRhinoDib);
     if (IntPtr.Zero != hBmp)
       rc = System.Drawing.Image.FromHbitmap(hBmp);
   }
   UnsafeNativeMethods.CRhinoDib_Delete(pRhinoDib);
   return rc;
 }
 public bool PickGumball(Rhino.Input.Custom.PickContext pickContext, Rhino.Input.Custom.GetPoint getPoint)
 {
   IntPtr pThis = NonConstPointer();
   IntPtr pConstPickContext = pickContext.ConstPointer();
   IntPtr pGetPoint = IntPtr.Zero;
   if( getPoint!=null)
     getPoint.NonConstPointer();
   return UnsafeNativeMethods.CRhinoGumballDisplayConduit_PickGumball(pThis, pConstPickContext, pGetPoint);
 }
 /// <summary>
 /// Copies all of the ViewportInfo data from an existing RhinoViewport.
 /// </summary>
 /// <param name="rhinoViewport">A viewport to copy.</param>
 public ViewportInfo(Rhino.Display.RhinoViewport rhinoViewport)
 {
   IntPtr pRhinoViewport = rhinoViewport.ConstPointer();
   m_pViewportPointer = UnsafeNativeMethods.ON_Viewport_New2(pRhinoViewport);
 }
 public static void ForceObjectIntoPreviewCache(Rhino.DocObjects.RhinoObject obj)
 {
   UnsafeNativeMethods.Rdk_CRMManager_EVF("ForceObjectIntoPreviewCache", obj.ConstPointer());
 }
 /// <summary>
 /// If Style==Wireframe, then the default decomposes the curve object into
 /// nurbs curve segments and calls the virtual DrawNurbsCurve for each segment.
 /// </summary>
 /// <param name="curve">A document curve object.</param>
 /// <param name="pipeline">The drawing pipeline.</param>
 protected virtual void DrawCurveObject(Rhino.DocObjects.CurveObject curve, DisplayPipeline pipeline )
 {
   IntPtr pConstThis = ConstPointer();
   IntPtr pConstCurve = curve.ConstPointer();
   IntPtr pPipeline = pipeline.NonConstPointer();
   UnsafeNativeMethods.CRhinoVisualAnalysisMode_DrawCurveObject(pConstThis, pConstCurve, pPipeline);
 }
Example #9
0
 /// <summary>
 /// Convert a Rhino.Display.Viewport to an RMA.Rhino.IRhinoViewport.
 /// </summary>
 /// <param name="source">A RhinoCommon viewport.</param>
 /// <returns>
 /// Rhino_DotNet IRhinoViewport object on success. This will be an independent copy.
 /// </returns>
 public static object ToIRhinoViewport(Rhino.Display.RhinoViewport source)
 {
   object rc = null;
   IntPtr pSource = source.ConstPointer();
   Type rhType = GetRhinoDotNetType("RMA.Rhino.MRhinoViewport");
   if (IntPtr.Zero != pSource && null != rhType)
   {
     System.Reflection.MethodInfo mi = rhType.GetMethod("WrapNativePointer", new Type[] { typeof(IntPtr), typeof(bool), typeof(bool) });
     const bool isConst = true;
     const bool doDelete = false;
     rc = mi.Invoke(null, new object[] { pSource, isConst, doDelete });
   }
   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">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();
    }
Example #11
0
 /// <summary>
 /// A wireframe channel will not be added if none of the document properties settings
 /// indicate that one is needed. In other words, Rhino will not generate an empty wireframe channel
 /// just for the fun of it.
 /// </summary>
 /// <param name="doc">The document to display</param>
 /// <param name="viewport">The view to display</param>
 /// <param name="size">The size of the image without clipping (ie - if you have a region, it was the
 /// size of the image before you cut the region out.</param>
 /// <param name="region">The area of the rendering you want to display.  This should match the size
 /// of the render window itself (ie - the one set using SetSize)</param>
 /// <returns>Returns true if the wireframe channel was successfully added.</returns>
 public bool AddWireframeChannel(Rhino.RhinoDoc doc, Rhino.DocObjects.ViewportInfo viewport, System.Drawing.Size size, System.Drawing.Rectangle region)
 {
   int[] xy = { size.Width, size.Height };
   int[] lrtb = { region.Left, region.Right, region.Top, region.Bottom };
   return UnsafeNativeMethods.Rdk_RenderWindow_AddWireframeChannel(ConstPointer(), doc.DocumentId, viewport.ConstPointer(), ref xy[0], ref lrtb[0]);
 }
 public void Add(Rhino.Geometry.Mesh mesh, RenderMaterial material)
 {
   UnsafeNativeMethods.Rdk_CustomMeshes_AddMesh(NonConstPointer(), mesh.ConstPointer(), material.ConstPointer());
 }
 /// <summary>
 /// Build custom render mesh(es) for the given object.
 /// </summary>
 /// <param name="vp">the viewport being rendered.</param>
 /// <param name="objMeshes">The meshes object to fill with custom meshes - the Object property will already be set.</param>
 /// <param name="requestingPlugIn">the UUID of the RDK plug-in requesting the meshes.</param>
 /// <param name="meshType"> type of mesh(es) to build.</param>
 /// <returns>true if successful.</returns>
 public static bool BuildCustomMeshes(Rhino.DocObjects.ViewportInfo vp, ObjectMeshes objMeshes, Guid requestingPlugIn, MeshTypes meshType)
 {
   return UnsafeNativeMethods.Rdk_CRMManager_BuildCustomMeshes(vp.ConstPointer(), objMeshes.NonConstPointer(), requestingPlugIn, (int)meshType);
 }
    /// <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();
    }
 /// <summary>
 /// Determines if custom render meshes will be built for a particular object.
 /// </summary>
 /// <param name="vp">the viewport being rendered.</param>
 /// <param name="obj">the Rhino object of interest.</param>
 /// <param name="requestingPlugIn">type of mesh to build.</param>
 /// <param name="meshType">UUID of the plug-in requesting the meshes.</param>
 /// <param name="soleProviderId">the UUID of the sole provider to call.</param>
 /// <returns>true if BuildCustomMeshes() will build custom render mesh(es) for the given object.</returns>
 public static bool WillBuildCustomMeshes(Rhino.DocObjects.ViewportInfo vp, Rhino.DocObjects.RhinoObject obj, Guid requestingPlugIn, MeshTypes meshType, Guid soleProviderId)
 {
   return UnsafeNativeMethods.Rdk_CRMManager_WillBuildCustomMeshSole(vp.ConstPointer(), obj.ConstPointer(), requestingPlugIn, (int)meshType, soleProviderId);
 }
Example #17
0
 public bool UpdateToPointCloud(Rhino.Geometry.PointCloud cloud, ObjectAttributes attributes)
 {
   IntPtr pCloud = cloud.ConstPointer();
   IntPtr pConstAttributes = (attributes == null) ? IntPtr.Zero : attributes.ConstPointer();
   return UnsafeNativeMethods.CRhinoObjectPairArray_UpdateResult2(m_parent.m_pObjectPairArray, m_index, pCloud, pConstAttributes);
 }
 public void Add(Rhino.Geometry.PlaneSurface plane, RenderMaterial material)
 {
   UnsafeNativeMethods.Rdk_CustomMeshes_AddPlane(NonConstPointer(), plane.ConstPointer(), material.ConstPointer());
 }
Example #19
0
 /// <summary>
 /// Sets the viewport camera projection.
 /// </summary>
 /// <param name="projection">The "standard" projection type.</param>
 /// <param name="updateTargetLocation">
 /// if true, the target location is changed so that the vector from the camera location to the target
 /// is parallel to the camera direction vector.  If false, the target location is not changed.
 /// </param>
 /// <returns>true on success.</returns>
 public bool SetViewProjection(Rhino.DocObjects.ViewportInfo projection, bool updateTargetLocation)
 {
   IntPtr pThis = NonConstPointer();
   IntPtr pConstViewport = projection.ConstPointer();
   return UnsafeNativeMethods.CRhinoViewport_SetVP(pThis, pConstViewport, updateTargetLocation);
 }
Example #20
0
 /// <summary>
 /// Call this function to render the scene in a view window. The function returns when rendering is complete (or cancelled).
 /// </summary>
 /// <param name="view">the view that the user selected a rectangle in.</param>
 /// <param name="rect">rectangle that the user selected.</param>
 /// <param name="inWindow">true to render directly into the view window.</param>
 /// <returns>A code that explains how rendering completed.</returns>
 /// //TODO - ViewInfo is wrong here
 public RenderReturnCode RenderWindow(Rhino.Display.RhinoView view, System.Drawing.Rectangle rect, bool inWindow)
 {
   m_ReturnCode = RenderReturnCode.InternalError;
   if (m_pSdkRender != IntPtr.Zero)
   {
     m_ReturnCode = (RenderReturnCode)UnsafeNativeMethods.Rdk_SdkRender_RenderWindow(m_pSdkRender, view.ConstPointer(), rect.Top, rect.Left, rect.Bottom, rect.Right, inWindow);
   }
   return m_ReturnCode;
 }
 /// <summary>
 /// Gets a value indicating if this visual analysis mode can be used on a given Rhino object.
 /// </summary>
 /// <param name="obj">The object to be tested.</param>
 /// <returns>true if this mode can indeed be used on the object; otherwise false.</returns>
 public virtual bool ObjectSupportsAnalysisMode(Rhino.DocObjects.RhinoObject obj)
 {
   IntPtr pConstPointer = ConstPointer();
   IntPtr pConstRhinoObject = obj.ConstPointer();
   return UnsafeNativeMethods.CRhinoVisualAnalysisMode_ObjectSupportsAnalysisMode(pConstPointer, pConstRhinoObject);
 }
 bool SetTexture(Rhino.DocObjects.Texture texture, int which, bool front)
 {
   IntPtr pMaterial = NonConstMaterialPointer(front);
   IntPtr pTexture = texture.ConstPointer();
   return UnsafeNativeMethods.ON_Material_SetTexture(pMaterial, pTexture, which);
 }
Example #23
0
 /// <summary>
 /// Constructs a Rhino_DotNet OnCurve that is a copy of a given curve.
 /// </summary>
 /// <param name="source">A RhinoCommon source curve.</param>
 /// <returns>
 /// Rhino_DotNet object on success. This will be an independent copy.
 /// </returns>
 public static object ToOnCurve(Rhino.Geometry.Curve source)
 {
   object rc = null;
   IntPtr pSource = source.ConstPointer();
   Type onType = GetRhinoDotNetType("RMA.OpenNURBS.OnCurve");
   if (IntPtr.Zero != pSource && null != onType)
   {
     System.Reflection.MethodInfo mi = onType.GetMethod("WrapNativePointer", new Type[] { typeof(IntPtr), typeof(bool), typeof(bool) });
     IntPtr pNewCurve = UnsafeNativeMethods.ON_Curve_DuplicateCurve(pSource);
     rc = mi.Invoke(null, new object[] { pNewCurve, false, true });
   }
   return rc;
 }
Example #24
0
 /// <summary>
 /// Gets the debug dumps. This is a text description of the geometric contents.
 /// DebugDump() is intended for debugging and is not suitable for creating high
 /// quality text descriptions of an object.
 /// </summary>
 /// <param name="bezierCurve">curve to evaluate</param>
 /// <returns>A debug dump text.</returns>
 public static string DebugDumpToString(Rhino.Geometry.BezierCurve bezierCurve)
 {
   IntPtr pConstThis = bezierCurve.ConstPointer();
   using (Rhino.Runtime.StringHolder sh = new StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     UnsafeNativeMethods.ON_BezierCurve_Dump(pConstThis, pString);
     return sh.ToString();
   }
 }
 public ObjectMeshes(Rhino.DocObjects.RhinoObject obj)
 {
   m_pRenderMeshes = UnsafeNativeMethods.Rdk_CustomMeshes_New(obj.ConstPointer());
   m_bAutoDelete = true;
 }
Example #26
0
 /// <summary>
 /// A new render mesh iterator.
 /// <para>The caller shall dispose the iterator.
 /// Meshes created by the iterator are accessible up till when the iterator is disposed.</para>
 /// </summary>
 /// <param name="forceTriMesh">true if quad meshes should be triangulated.</param>
 /// <param name="vp">The rendering view camera.</param>
 /// <returns>A render mesh iterator.</returns>
 /// //TODO - ON_Viewport
 public RenderMeshIterator NewRenderMeshIterator(Rhino.DocObjects.ViewportInfo vp, bool forceTriMesh)
 {
   IntPtr pIterator = UnsafeNativeMethods.Rdk_SdkRender_NewRenderMeshIterator(ConstPointer(), vp.ConstPointer(), forceTriMesh);
   if (pIterator != IntPtr.Zero)
   {
     return new RenderMeshIterator(pIterator);
   }
   return null;
 }
Example #27
0
 /// <summary>
 /// Gets the debug dumps. This is a text description of the geometric contents.
 /// DebugDump() is intended for debugging and is not suitable for creating high
 /// quality text descriptions of an object.
 /// </summary>
 /// <param name="geometry">Some geometry.</param>
 /// <returns>A debug dump text.</returns>
 public static string DebugDumpToString(Rhino.Geometry.GeometryBase geometry)
 {
   IntPtr pConstThis = geometry.ConstPointer();
   using (Rhino.Runtime.StringHolder sh = new Rhino.Runtime.StringHolder())
   {
     IntPtr pString = sh.NonConstPointer();
     UnsafeNativeMethods.ON_Object_Dump(pConstThis, pString);
     return sh.ToString();
   }
 }
 public static void ObjectChanged(Rhino.DocObjects.RhinoObject obj)
 {
   UnsafeNativeMethods.Rdk_CRMManager_EVF("ObjectChanged", obj.ConstPointer());
 }
Example #29
0
 /// <summary>
 /// Adds an ObjRef to the list.
 /// </summary>
 /// <param name="objref">An ObjRef to add.</param>
 public void Add(Rhino.DocObjects.ObjRef objref)
 {
   if (null != objref)
   {
     IntPtr pConstObjRef = objref.ConstPointer();
     IntPtr pThis = NonConstPointer();
     UnsafeNativeMethods.ON_ClassArrayCRhinoObjRef_Append(pThis, pConstObjRef);
   }
 }
Example #30
0
 /// <summary>
 /// Constructs a new basic material from a <see cref="Rhino.DocObjects.Material">Material</see>.
 /// </summary>
 /// <param name="material">The material to create the basic material from.</param>
 /// <returns>A new basic material.</returns>
 public static RenderMaterial NewBasicMaterial(Rhino.DocObjects.Material material)
 {
   NativeRenderMaterial newMaterial = RenderContent.FromPointer(UnsafeNativeMethods.Rdk_Globals_NewBasicMaterial(material == null ? IntPtr.Zero : material.ConstPointer())) as NativeRenderMaterial;
   newMaterial.AutoDelete = true;
   return newMaterial;
 }