/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Guid guid = new Guid(); Point3d loc = new Point3d(); Point3d tar = new Point3d(); double ins = 100; double angle = 90; double hot = 0.5; Color diffuse = Color.Aqua; Color spec = Color.Aqua; DA.GetData("Guid", ref guid); DA.GetData("Location", ref loc); DA.GetData("Target", ref tar); DA.GetData("Intensity", ref ins); DA.GetData("Radius", ref angle); DA.GetData("HotSpot", ref hot); DA.GetData("DiffuseColor", ref diffuse); Rhino.DocObjects.LightObject spotObj = null; foreach (Rhino.DocObjects.LightObject obj in Rhino.RhinoDoc.ActiveDoc.Lights) { if (obj.Id == guid) { spotObj = obj; break; } } if (((Param_Number)Params.Input[4]).UseDegrees) { angle = RhinoMath.ToRadians(angle); } if (angle <= 0 || angle >= Math.PI / 2) { angle = Math.PI / 4; this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Radius must be in 0-Pi/2."); } if (hot <= 0 || hot >= 1) { hot = 0.5; this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "HotSpot must be in 0-1."); } spotObj.LightGeometry.LightStyle = LightStyle.WorldSpot; spotObj.LightGeometry.Location = loc; spotObj.LightGeometry.Direction = tar - loc; spotObj.LightGeometry.Intensity = ins; spotObj.LightGeometry.SpotAngleRadians = angle; spotObj.LightGeometry.HotSpot = hot; spotObj.LightGeometry.Diffuse = diffuse; spotObj.LightGeometry.Specular = spec; Rhino.RhinoDoc.ActiveDoc.Lights.Modify(guid, spotObj.LightGeometry); }
/// <summary> /// Get the object serial number of the light /// </summary> public override int ObjectSerialNumberFromLight(RhinoDoc doc, ref Light light) { int index = doc.Lights.Find(light.Id, true); if (index > -1) { Rhino.DocObjects.LightObject light_obj = doc.Lights[index]; return((int)light_obj.RuntimeSerialNumber); } return(0); }
/// <summary> /// Selects the lights and opens the Light Properties page /// </summary> public override bool OnEditLight(RhinoDoc doc, ref LightArray light_array) { for (int i = 0; i < light_array.Count(); i++) { Rhino.Geometry.Light light = light_array.ElementAt(i); int index = doc.Lights.Find(light.Id, true); if (index > -1) { Rhino.DocObjects.LightObject light_obj = doc.Lights[index]; light_obj.Select(true); RhinoApp.RunScript("_-PropertiesPage _Light", true); } return(true); } return(false); }
/// <summary> /// Return all the lights in the lightmanager /// </summary> public override void GetLights(RhinoDoc doc, ref LightArray light_array) { // Append all lights in doc for (int i = 0; i < doc.Lights.Count; i++) { Rhino.DocObjects.LightObject light = doc.Lights[i]; if (!light.IsDeleted) { light_array.Append(light.LightGeometry); } } // Append also the custom light foreach (Rhino.Geometry.Light custom_light in m_light_array) { light_array.Append(custom_light); } }
static int OnReturnBoolGeneralCallback(int serial_number, int iVirtualFunction, IntPtr pObj, IntPtr pMat, IntPtr pMesh, IntPtr pView, int rectLeft, int rectTop, int rectRight, int rectBottom) { try { RenderPipeline pipe = RenderPipeline.FromSerialNumber(serial_number); if (pipe != null) { switch ((VirtualFunctions)iVirtualFunction) { case VirtualFunctions.StartRendering: return(pipe.OnRenderBegin() ? 1 : 0); case VirtualFunctions.StartRenderingInWindow: { Rhino.Display.RhinoView view = Rhino.Display.RhinoView.FromIntPtr(pView); System.Drawing.Rectangle rect = System.Drawing.Rectangle.FromLTRB(rectLeft, rectTop, rectRight, rectBottom); return(pipe.OnRenderWindowBegin(view, rect) ? 1 : 0); } case VirtualFunctions.StopRendering: pipe.OnRenderEnd(new RenderEndEventArgs()); return(1); case VirtualFunctions.NeedToProcessGeometryTable: return(pipe.NeedToProcessGeometryTable() ? 1 : 0); case VirtualFunctions.NeedToProcessLightTable: return(pipe.NeedToProcessLightTable() ? 1 : 0); case VirtualFunctions.RenderSceneWithNoMeshes: return(pipe.RenderSceneWithNoMeshes() ? 1 : 0); case VirtualFunctions.RenderPreCreateWindow: return(pipe.RenderPreCreateWindow() ? 1:0); case VirtualFunctions.RenderEnterModalLoop: return(pipe.RenderEnterModalLoop() ? 1 : 0); case VirtualFunctions.RenderExitModalLoop: return(pipe.RenderExitModalLoop() ? 1 : 0); case VirtualFunctions.RenderContinueModal: return(pipe.ContinueModal() ? 1 : 0); case VirtualFunctions.IgnoreRhinoObject: { if (pObj != IntPtr.Zero) { Rhino.DocObjects.RhinoObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj); if (obj != null) { return(pipe.IgnoreRhinoObject(obj) ? 1 : 0); } } } return(0); case VirtualFunctions.AddLightToScene: { if (pObj != IntPtr.Zero) { Rhino.DocObjects.LightObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj) as Rhino.DocObjects.LightObject; if (obj != null) { return(pipe.AddLightToScene(obj) ? 1 : 0); } } } return(0); case VirtualFunctions.AddRenderMeshToScene: { if (pObj != IntPtr.Zero && pMat != IntPtr.Zero && pMesh != IntPtr.Zero) { Rhino.DocObjects.RhinoObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj); Rhino.DocObjects.Material mat = Rhino.DocObjects.Material.NewTemporaryMaterial(pMat); //Steve....you need to look at this Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(pMesh, obj); return(pipe.AddRenderMeshToScene(obj, mat, mesh) ? 1:0); } } return(0); } } } catch (Exception ex) { Rhino.Runtime.HostUtils.ExceptionReport(ex); } Debug.Assert(false); return(0); }
protected virtual bool AddLightToScene(Rhino.DocObjects.LightObject light) { return(true); }