Grasshopper

algorithmic modeling for Rhino

Has anyone attempted placing and directing light objects from a script component? If so, can you help by providing methods (in either language)? I'm guessing that in GH the lights could be visually represented by lines with some sort of heads that indicate direction (say for spotlights), and then there would be some way to bake them as light objects when they are ready to bake. I keep making designs in GH, but then having to light them by hand in Rhino, so this would be very helpful.
Thanks, Chris Wilkins

Views: 2585

Replies to This Discussion

hey Chris,
nice idea...

Attached a ghx file to create a bunch of directional lights from a list of lines with a vb component...
Just insert a list of lines into "LineLIst" and whenever you want to add (bake) them to the scene toggle the boolean "addLights" to true.

Is that what you meant?

Marc

sorry... forgot to attach the ghx file...
here you go
Attachments:
Hi Chris, Marc, this ghz is quite useful. Placing lights is kind of headache.
I just added to define number of lights Y direction and Z direction separately.
Also rotate whole lights.
Marc, is it possible to add function to find duplicated lights and delete them?
Thanks!

Attachments:
Hey Atsuo,
If you replace the code by the following you will give the lights a Name that you can then find back in the scene and delete the next time the vb component get's active. This way you make sure that you don't keep pushing new lights into your scene... (you might also just keep the booleanSwitch away and let it update automatically then...

another way is of course the good old manual "SelDup" command which deletes all duplicate objects ;o)

'/// the code starts here///
If AddLights Then

Dim nLights As Int32 = 0
Dim strLightName As String = "GH_Light"

'first delete Lights created before

'construct a new object iterator
Dim it As New MRhinoObjectIterator( _
IRhinoObjectIterator.object_state.normal_objects, _
IRhinoObjectIterator.object_category.active_objects)
it.IncludeLights(True)

'loop through each object found and delete if objectName= strLightName
For Each obj As MRhinoObject In it
Dim attr As MRhinoObjectAttributes = obj.Attributes
If attr.m_name = strLightName Then
doc.DeleteObject(New MRhinoobjref(obj))
End If
Next




For Each Line As onLine In LinesList

Dim newlight As New OnLight
newlight.SetLocation(New On3dPoint(Line.PointAt(0)))
newlight.SetDirection(Line.Direction)
newlight.SetStyle(IOn.light_style.world_directional_light)
newLight.m_light_name = strLightName
doc.m_light_table.AddLight(newlight)

nLights = nlights + 1

Next
doc.Redraw()
print(nLights & " lights created")
End If


End Sub
'--------------------------
Thanks very much guys! This will be a major timesaver for lighting my Grasshopper creations.
now that you are placing them with code you might aswell add some lines for the light_settings itself like:

newLight.m_diffuse = New OnColor(clr) ' add a color input to the script
newLight.m_shadow_intensity = shadowInt ' to control the shadow

just an idea for a usage:

Thank you.
I have not tried VBScript yet, but I will play with it.
Wow, that's a cool solution! But what if I'm just making a grasshopper animation, and I also want to change my cam, and here's my code:

Dim viewport As MRhinoViewport = app.ActiveView.activeviewport
viewport.SetTargetAndCameraLocation(targetPoint, cameraLocation)

and it's working and my final object is attached to a Preview component (it is very important for me, cause my viewport settings has to be true to my object) but when the camera is changing all my lights are gone and the "problem" with your solultion is that it can only bake the light and can not add it to the active area.
Am I explain myself clearly? Sorry for my bad english, it is very difficult to tell these things, hope you understand it.

ps: maybe there's something else went wrong, I don't know..
Originally, I posted this under the general topics forum, and David Rutten replied that there are no light objects available in GH. He said that baking them was the only option currently. Here's the thread:

http://grasshopper3d.ning.com/forum/topics/placing-light-objects-with

-Chris
But when you attach the GH generated object to a Preview component all the viewport settings will be shown on the object, for example the stereo mode what i switched on in the "rendered" view - which in my case is the point! So basicly I think the light is not a GH object but an active viewport thing, which can be controlled by rhino's .net framework. Am I right?

Well, I have to be right :):) because I dont want to adjust 4000 frames in photoshop for the 3D anaglyph mode.. PLEASE! VB and C# masters, help me from the timeless s*cks of editing photos one by one :)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2022   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service