// Write sample material to .sample file (only bool values ) public override bool Write(string pathToFile, RenderContent renderContent, CreatePreviewEventArgs previewArgs) { List <string> lines = new List <string>(); foreach (Field field in renderContent.Fields) { Type type = field.GetType(); // Bool fields if (type == typeof(BoolField)) { string key = field.Name; string prompt = field.Name; bool bool_value = false; renderContent.Fields.TryGetValue(key, out bool_value); string value = bool_value.ToString(); lines.Add("type=bool," + "key=" + key + ",value=" + value + "," + "prompt=" + prompt); } } // Write all lines to .sample file using (System.IO.StreamWriter file = new System.IO.StreamWriter(pathToFile)) { foreach (string line in lines) { file.WriteLine(line); } file.Close(); } return(true); }
void UpdateRenderedSpriteInner(CPos cell) { if (RenderContent.Contains(cell)) { UpdateRenderedSpriteInner(cell, RenderContent[cell]); } }
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); }
// You can override methods here to change the plug-in behavior on // loading and shut down, add options pages to the Rhino _Option command // and mantain plug-in wide options in a document. protected override LoadReturnCode OnLoad(ref string errorMessage) { base.OnLoad(ref errorMessage); RenderContent.RegisterContent(this); return(LoadReturnCode.Success); }
protected override LoadReturnCode OnLoad(ref string errorMessage) { RhinoApp.Initialized += RhinoApp_Initialized; RcCore.It.InitializeResourceManager(); // code got moved to separate DLL so use that to register from. var rccoreass = typeof(RcCore).Assembly; RenderContent.RegisterContent(rccoreass, Id); RenderContent.ContentFieldChanged += RenderContentOnContentFieldChanged; var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? ""; RcCore.It.PluginPath = path; var kernelPath = Path.Combine(path, "RhinoCycles"); RcCore.It.KernelPath = kernelPath; var appPath = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location); RcCore.It.AppPath = appPath; kernelPath = RcCore.GetRelativePath(appPath, kernelPath); RcCore.It.KernelPathRelative = kernelPath; var dataPath = SettingsDirectory; var userPath = Path.Combine(dataPath, "..", "data"); userPath = RcCore.GetCanonicalizedPath(userPath); RcCore.It.DataUserPath = userPath; CSycles.path_init(RcCore.It.KernelPath, RcCore.It.DataUserPath); if (RhinoApp.RunningOnVMWare()) { CSycles.debug_set_opencl_device_type(0); } else { CSycles.debug_set_opencl_device_type(RcCore.It.EngineSettings.OpenClDeviceType); } CSycles.debug_set_opencl_kernel(RcCore.It.EngineSettings.OpenClKernelType); CSycles.debug_set_opencl_single_program(RcCore.It.EngineSettings.OpenClSingleProgram); CSycles.debug_set_cpu_kernel(RcCore.It.EngineSettings.CPUSplitKernel); RcCore.It.Initialised = false; AsyncInitialise(); m_page = new ViewportPropertiesPage(); RhinoView.SetActive += RhinoView_SetActive; return(LoadReturnCode.Success); }
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> /// This method checks if there are Ground Plane enabled and reproduces it in Mitsuba. /// </summary> private void CreateGround() { var groundPlane = RhinoDoc.ActiveDoc.GroundPlane; if (groundPlane.Enabled) { var id = RhinoDoc.ActiveDoc.GroundPlane.MaterialInstanceId; var material = RenderContent.FromId(RhinoDoc.ActiveDoc, id); var mitsubaMaterial = material as MitsubaMaterial; _mitsubaXml.CreateGround(mitsubaMaterial, groundPlane.Altitude); } }
/// <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); }
static void AddDefaultCustomEnvironment(RhinoDoc rhinoDoc) { // There is no default environment so add one now var type = typeof(CustomEnvironment); var content = RenderContent.Create(type, RenderContent.ShowContentChooserFlags.None, rhinoDoc) as CustomEnvironment; if (content == null) { return; } rhinoDoc.CurrentEnvironment.ForBackground = content; rhinoDoc.RenderSettings.BackgroundStyle = BackgroundStyle.Environment; }
protected override Rhino.PlugIns.LoadReturnCode OnLoad(ref string errorMessage) { // Tell Rhino about our custom render content RenderContent.RegisterContent(this); RealtimeDisplayMode.RegisterDisplayModes(this); //Rhino.Render.IOPlugIn.RegisterContentIo(this.Assembly, this.Id); // Tell Rhino about our custom mesh provider CustomRenderMeshProvider2.RegisterProviders(GetType().Assembly, Id); RhinoDoc.NewDocument += g_rhino_doc_new_doc; return(Rhino.PlugIns.LoadReturnCode.Success); }
bool CellContainsMaxDensity(CPos c, ResourceType t) { if (!RenderContent.Contains(c)) { return(false); } if (FindClearSides(t, c) != ClearSides.None) { return(false); } var tile = RenderContent[c]; return(tile.Density > tile.Type.Info.MaxDensity / 2); }
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 UpdateRenderedTileInner(CPos p) { if (!RenderContent.Contains(p)) { return; } var t = RenderContent[p]; if (t.Density > 0) { var clear = FindClearSides(t.Type, p); int index; if (clear == ClearSides.None && CellContainsMaxDensity(p, t.Type)) { var maxDensityClear = FindMaxDensityClearSides(t.Type, p); if (SpriteMap.TryGetValue(maxDensityClear, out index)) { t.Sprite = t.Type.Variants.First().Value[16 + index]; } else { t.Sprite = null; //ресурс закончился. ничего не рендерим } } else if (SpriteMap.TryGetValue(clear, out index)) { t.Sprite = t.Type.Variants.First().Value[index]; } else { t.Sprite = null; //ресурс закончился. ничего не рендерим } } else { t.Sprite = null; //ресурс закончился. ничего не рендерим } int temp = RenderContent.Index(p); RenderContent.entries[temp].Sprite = t.Sprite; }
static void OnTextureChildSlotName(int serial_number, int which, IntPtr pON_wString) { try { var material = RenderContent.FromSerialNumber(serial_number) as RenderMaterial; if (material != null) { String str = material.TextureChildSlotName((StandardChildSlots)which); if (!String.IsNullOrEmpty(str)) { UnsafeNativeMethods.ON_wString_Set(pON_wString, str); } } } catch (Exception exception) { Runtime.HostUtils.ExceptionReport(exception); } }
protected override LoadReturnCode OnLoad(ref string errorMessage) { RenderContent.RegisterContent(this); var pluginPath = Assembly.GetExecutingAssembly().Location; MitsubaSettings.ApplicationPath = Path.GetDirectoryName(pluginPath); MitsubaSettings.MitsubaPath = Path.Combine(MitsubaSettings.ApplicationPath, "Mitsuba\\mtsgui.exe"); var docFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); MitsubaSettings.WorkingDirectory = Path.Combine(docFolder, "Mitsuba"); if (!Directory.Exists(MitsubaSettings.WorkingDirectory)) { Directory.CreateDirectory(MitsubaSettings.WorkingDirectory); } return(base.OnLoad(ref errorMessage)); }
void UpdateRenderedTileInner(CPos p) { if (!RenderContent.Contains(p)) { return; } var t = RenderContent[p]; if (t.Density > 0) { var clear = FindClearSides(t.Type, p); int index; if (clear == ClearSides.None && CellContainsMaxDensity(p, t.Type)) { var maxDensityClear = FindMaxDensityClearSides(t.Type, p); if (SpriteMap.TryGetValue(maxDensityClear, out index)) { t.Sprite = t.Type.Variants.First().Value[16 + index]; } else { t.Sprite = null; } } else if (SpriteMap.TryGetValue(clear, out index)) { t.Sprite = t.Type.Variants.First().Value[index]; } else { t.Sprite = null; } } else { t.Sprite = null; } RenderContent[p] = t; }
static int OnLoad(int serial_number, IntPtr filename) { try { RenderContentSerializer io = RenderContentSerializer.FromSerialNumber(serial_number) as RenderContentSerializer; if (io != null) { string _filename = Marshal.PtrToStringUni(filename); RenderContent content = io.Read(_filename); if (content != null) { return(content.m_runtime_serial_number); } } } catch { } return(0); }
static void OnSimulateMaterial(int serial_number, IntPtr pSim, int bDataOnly) { try { RenderMaterial material = RenderContent.FromSerialNumber(serial_number) as RenderMaterial; if (material != null && pSim != IntPtr.Zero) { Rhino.DocObjects.Material temp_material = Rhino.DocObjects.Material.NewTemporaryMaterial(pSim); if (temp_material != null) { material.SimulateMaterial(ref temp_material, bDataOnly != 0); temp_material.ReleaseNonConstPointer(); } } } catch (Exception ex) { Rhino.Runtime.HostUtils.ExceptionReport(ex); } }
void UpdateRenderedTileInner(CPos p) { if (!RenderContent.Contains(p)) { return; } var t = RenderContent[p]; if (t.Density > 0) { var clear = FindClearSides(t.Type, p); int index; if (clear == ClearSides.None) { var sprites = Variants[t.Variant]; var frame = t.Density > t.Type.Info.MaxDensity / 2 ? 1 : 0; t.Sprite = t.Type.Variants.First().Value[sprites[frame]]; } else if (SpriteMap.TryGetValue(clear, out index)) { t.Sprite = t.Type.Variants.First().Value[index]; } else { t.Sprite = null; } } else { t.Sprite = null; } RenderContent[p] = t; }
internal IntPtr ConstPointer() { return(UnsafeNativeMethods.Rdk_ContentList_ListFromKind(RenderContent.KindString(m_kind), m_doc.m_docId)); }
internal static bool ShowIncompatibleContent(RenderContentKind kind) { return(1 == UnsafeNativeMethods.Rdk_Globals_ShowIncompatibleContent(RenderContent.KindString(kind))); }
internal static void SetShowIncompatibleContent(RenderContentKind kind, bool bShow) { UnsafeNativeMethods.Rdk_Globals_SetShowIncompatbileContent(RenderContent.KindString(kind), bShow); }
/// <summary> /// Call this before tweaking a single content parameter. Undo will cause the parameter to be restored. /// </summary> /// <param name="content">The render content</param> /// <param name="parameterName">The parameter name you are about to change.</param> /// <returns>true if the content was tweaked.</returns> public bool TweakContent(RenderContent content, String parameterName) { return(1 == UnsafeNativeMethods.Rdk_ContentUndo_TweakContent(ConstPointer(), content.ConstPointer(), parameterName)); }
/// <summary> /// Call this before modifying or deleting a content. Undo will cause the content to be restored. /// </summary> /// <param name="content">Content you are about to modify.</param> /// <returns>true if the content was modified.</returns> public bool ModifyContent(RenderContent content) { return(1 == UnsafeNativeMethods.Rdk_ContentUndo_ModifyContent(ConstPointer(), content.ConstPointer())); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // A properties of a Rhino material define what is required to draw an // object using OpenGL. Most rendering plug-ins require a much richer // defintion than this. And, not all rendering plug-ins support the // same material properties. This is where Render materials come in. // An Render material is an abstract material - one that is defined // by the the owning render plug-in. But a basic Render material does // share some properties with a Rhino material. // This example demonstrates how to create a basic Render material. // This material will appear in Rhino's Materials panel. It it called // basic material because it does not target any particular rendering // plug-in. // 1.) Create some Rhino materials var red_material = new Material { DiffuseColor = Color.Red, Name = "Red" }; var green_material = new Material { DiffuseColor = Color.Green, Name = "Green" }; var blue_material = new Material { DiffuseColor = Color.Blue, Name = "Blue" }; // 2.) Create basic Render materials from Rhino materials var red_render_material = RenderMaterial.CreateBasicMaterial(red_material); var green_render_material = RenderMaterial.CreateBasicMaterial(green_material); var blue_render_material = RenderMaterial.CreateBasicMaterial(blue_material); // 3.) Add basic Render materials to the RDK document RenderContent.AddPersistentRenderContent(red_render_material); RenderContent.AddPersistentRenderContent(green_render_material); RenderContent.AddPersistentRenderContent(blue_render_material); // At this point, you will see render materials show up in Rhino's // Materials panel. Note, doc.Materials.Count will equal 0. This is // because we have not added any Rhino materials. We've only added // Render materials. When you assign a Render material to an object // or a layer, a compatible Rhino material will be added doc.Materials, // and this materiall will be referenced by the Render material. // Note, it is possible to add Rhino materials to the document. However, // they will not appear in the Materials panel until they are assigned // to objects or layers. Here is an example of this. // 1.) Create a Rhino material var magenta_material = new Material { DiffuseColor = Color.Magenta, Name = "Magenta" }; // 2.) Add the Rhino material to the document var magenta_material_index = doc.Materials.Add(magenta_material); // 3.) Create an object and assign the Rhino material to it. var sphere = new Sphere(Plane.WorldXY, 5); var attributes = doc.CreateDefaultAttributes(); attributes.MaterialSource = ObjectMaterialSource.MaterialFromObject; attributes.MaterialIndex = magenta_material_index; doc.Objects.AddSphere(sphere, attributes); doc.Views.Redraw(); return(Result.Success); }
bool CellContains(CPos c, ResourceType t) { return(RenderContent.Contains(c) && RenderContent[c].Type == t); }
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> /// Called to save a custom RenderContent object as an external file. /// </summary> /// <param name="pathToFile"> /// Full path of file to write /// </param> /// <param name="renderContent"> /// Render content to save /// </param> /// <param name="previewArgs"> /// Parameters used to generate a preview image which may be embedded in /// the exported file. /// </param> /// <returns></returns> public abstract bool Write(String pathToFile, RenderContent renderContent, CreatePreviewEventArgs previewArgs);