static bool OnSave(int serial_number, IntPtr filename, IntPtr content_ptr, IntPtr scene_server_ptr) { try { RenderContentSerializer io = RenderContentSerializer.FromSerialNumber(serial_number) as RenderContentSerializer; RenderContent content = RenderContent.FromPointer(content_ptr); CreatePreviewEventArgs pc = null; if (scene_server_ptr != IntPtr.Zero) { pc = new CreatePreviewEventArgs(scene_server_ptr, new System.Drawing.Size(100, 100), PreviewSceneQuality.RefineThirdPass); } if (io != null && content != null) { string _filename = Marshal.PtrToStringUni(filename); return(io.Write(_filename, content, pc)); } } catch { } return(false); }
public RenderMaterial Material(int index) { IntPtr pMaterial = UnsafeNativeMethods.Rdk_CustomMeshes_Material(ConstPointer(), index); if (pMaterial != IntPtr.Zero) { RenderMaterial material = RenderContent.FromPointer(pMaterial) as RenderMaterial; return(material); } return(null); }
/// <summary> /// Finds a content by its instance id. /// </summary> /// <param name="instanceId">Instance id of the content to find.</param> /// <param name="includeChildren">Specifies if children should be searched as well as top-level content.</param> /// <returns>The found content or null.</returns> public TContentType FindInstance(Guid instanceId, bool includeChildren) { var content_pointer = UnsafeNativeMethods.Rdk_ContentList_FindInstance(ConstPointer(), instanceId, includeChildren); if (IntPtr.Zero == content_pointer) { return(null); } var content = RenderContent.FromPointer(content_pointer); return(content as TContentType); }
/// <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); }
// 6 March 2012 - S. Baer // I don't think we need to export the Kind enum. .NET languages already have // runtime type information to determine what the case 'is' or cast it 'as' something // If we do need to make this enum public, I would like to find a less generic name // than 'Kind' // <summary> // Gets the kind of content that this type represents. // </summary> //public RenderContentKind Kind //{ // get // { // using (Rhino.Runtime.StringHolder sh = new Rhino.Runtime.StringHolder()) // { // IntPtr pString = sh.NonConstPointer(); // UnsafeNativeMethods.Rdk_Factory_Kind(ConstPointer(), pString); // return RenderContent.KindFromString(sh.ToString()); // } // } //} // <summary> // Determines if this type is of the specified kind. // </summary> // <param name="kind">The render content kind to check against.</param> // <returns>true if this instance is of the specified type.</returns> // public bool IsKind(RenderContentKind kind) { return Kind == kind; } /// <summary> /// Returns a new instance of the render content of this type. This content can be added to a persistant list. /// </summary> /// <returns>A new render content instance.</returns> public RenderContent NewRenderContent() { IntPtr pContent = UnsafeNativeMethods.Rdk_Factory_NewContent(ConstPointer()); if (pContent != IntPtr.Zero) { RenderContent content = RenderContent.FromPointer(pContent); content.AutoDelete = true; return(content); } return(null); }
public bool MoveNext() { if (m_pIterator == IntPtr.Zero) { m_pIterator = UnsafeNativeMethods.Rdk_ContentLists_NewIterator(ConstPointer()); } IntPtr pContent = UnsafeNativeMethods.Rdk_ContentLists_Next(m_pIterator); if (IntPtr.Zero == pContent) { m_content = null; return(false); } m_content = RenderContent.FromPointer(pContent); return(true); }
void Initialize() { IntPtr pSceneServer = m_pSceneServer; if (pSceneServer != IntPtr.Zero) { //Pull in the list of objects m_scene_objects = new List <SceneObject>(); UnsafeNativeMethods.Rdk_SceneServer_ResetObjectEnum(pSceneServer); IntPtr pObject = UnsafeNativeMethods.Rdk_SceneServer_NextObject(pSceneServer); while (pObject != IntPtr.Zero) { Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); IntPtr pMaterial = UnsafeNativeMethods.Rdk_SceneServer_ObjectDetails(pObject, mesh.NonConstPointer()); if (pMaterial != IntPtr.Zero) { SceneObject o = new SceneObject(mesh, RenderContent.FromPointer(pMaterial) as RenderMaterial); m_scene_objects.Add(o); } pObject = UnsafeNativeMethods.Rdk_SceneServer_NextObject(pSceneServer); } //Now get the lights m_scene_lights = new List <Rhino.Geometry.Light>(); UnsafeNativeMethods.Rdk_SceneServer_ResetLightEnum(pSceneServer); IntPtr pLight = UnsafeNativeMethods.Rdk_SceneServer_NextLight(pSceneServer); while (pLight != IntPtr.Zero) { Rhino.Geometry.Light light = new Rhino.Geometry.Light(); UnsafeNativeMethods.Rdk_SceneServer_LightDetails(pLight, light.NonConstPointer()); m_scene_lights.Add(light); pLight = UnsafeNativeMethods.Rdk_SceneServer_NextLight(pSceneServer); } //And then fill in the blanks IntPtr pEnvironment = UnsafeNativeMethods.Rdk_SceneServer_Environment(pSceneServer); if (pEnvironment != IntPtr.Zero) { m_environment = RenderContent.FromPointer(pEnvironment) as RenderEnvironment; } else { m_environment = null; } m_content_instance_id = UnsafeNativeMethods.Rdk_SceneServer_InstanceId(pSceneServer); m_sig = UnsafeNativeMethods.Rdk_SceneServer_Signature(pSceneServer); //Just the view left... m_viewport = new Rhino.DocObjects.ViewportInfo(); UnsafeNativeMethods.Rdk_SceneServer_View(pSceneServer, m_viewport.NonConstPointer()); } m_pSceneServer = IntPtr.Zero; }
/// <summary> /// Loads a content from a library file. Adds the content to the persistent content list. /// </summary> /// <param name="filename">is the full path to the file to be loaded.</param> /// <returns>The loaded content or null if an error occurred.</returns> public static RenderContent LoadPersistantRenderContentFromFile(String filename) { IntPtr pContent = UnsafeNativeMethods.Rdk_RenderContent_LoadPersistantContentFromFile(filename); return(IntPtr.Zero == pContent?RenderContent.FromPointer(pContent) : null); }
/* * public enum ChooseContentFlags : int * { * /// <summary> * /// Dialog will have [New...] button. * /// </summary> * NewButton = 1, * /// <summary> * /// Dialog will have [Edit...] button. * /// </summary> * EditButton = 2, * }; * * /// <summary> * /// Allows the user to choose a content by displaying the Content Chooser dialog. * /// The dialog will have OK, Cancel and Help buttons, and optional New and Edit buttons. * /// </summary> * /// <param name="instanceId">Sets the initially selected content and receives the instance id of the chosen content.</param> * /// <param name="kinds">Specifies the kind(s) of content that should be displayed in the chooser.</param> * /// <param name="flags">Specifies flags controlling the browser.</param> * /// <param name="doc">A Rhino document.</param> * /// <returns>true if the operation succeeded.</returns> * public static bool ChooseContent(ref Guid instanceId, RenderContentKind kinds, ChooseContentFlags flags, RhinoDoc doc) * { * return 1 == UnsafeNativeMethods.Rdk_Globals_ChooseContentEx(ref instanceId, RenderContent.KindString(kinds), (int)flags, doc.m_docId); * } */ /* * /// <summary> * /// Constructs a new content chosen by the user and add it to the persistent content list. * /// This function cannot be used to create temporary content that you delete after use. * /// Content created by this function is owned by RDK and appears in the content editor. * /// </summary> * /// <param name="defaultType">The default content type.</param> * /// <param name="defaultInstance">The default selected content instance.</param> * /// <param name="kinds">Determines which content kinds are allowed to be chosen from the dialog.</param> * /// <param name="flags">Options for the tab.</param> * /// <param name="doc">The current Rhino document.</param> * /// <returns>A new persistent render content.</returns> * public static RenderContent CreateContentByUser(Guid defaultType, Guid defaultInstance, RenderContentKind kinds, ChooseContentFlags flags, RhinoDoc doc) * { * IntPtr pContent = UnsafeNativeMethods.Rdk_Globals_CreateContentByUser(defaultType, defaultInstance, RenderContent.KindString(kinds), (int)flags, doc.m_docId); * return pContent == IntPtr.Zero ? null : RenderContent.FromPointer(pContent); * } */ /// <summary> /// Changes the type of a content. This deletes the content and creates a replacement /// of the specified type allowing the caller to decide about harvesting. /// </summary> /// <param name="oldContent">oldContent is the old content which is deleted.</param> /// <param name="newType">The type of content to replace pOldContent with.</param> /// <param name="harvestParameters">Determines whether or not parameter harvesting will be performed.</param> /// <returns>A new persistent render content.</returns> public static RenderContent ChangeContentType(RenderContent oldContent, Guid newType, bool harvestParameters) { IntPtr pContent = UnsafeNativeMethods.Rdk_Globals_ChangeContentType(oldContent.NonConstPointer(), newType, harvestParameters); return(IntPtr.Zero == pContent ? null : RenderContent.FromPointer(pContent)); }