--------------------------------------------------------------------------- -- Scatter Light Plugin Script -- -- -- -- Alexander Esppeschit Bicalho -- -- Kinetix Training Specialist -- -- abicalho@brasilmail.com -- -- http://www.ktx.com/learning_center -- --------------------------------------------------------------------------- -- -- This macroscript creates instanced omnilights in each vertex of a selected object. -- It allows you to select the color and multiplier. Each light will have its multiplier set -- to area_multiplier/number of lights. -- Options are: -- Link lights to object -- Exclude object from light -- Change All Light's color -- Change overall multiplier -- Turn off Cast Shadows -- -- Shadows are turned on by default, as Raytraced. Since all lights are instances, select any of them -- and change the parameters manually, if you preffer. -- -- Requires AreaOmni2 Plugin Script for better performance. -- This file is to be installed in \ui\macroscripts folder macroscript Scatter_Light tooltip:"Scatter Light" Category:"Lights" ( global arealightrollout,latestlightcreated rollout areaL_rollout "Parameters" ( -- Function to be used by the pickbutton, to select only 3D Geometry fn check_for_3d obj = ( return_value = false if superclassof obj == GeometryClass then return_value = true return_value ) -- end check_for_3d local l_created = false group "Parent Object" ( pickbutton sel_obj "Select Object" filter:check_for_3d checkbox link_it "Link lights to Object" checked:true checkbox exclude_it "Exclude Object from Lights" checked:true ) -- end "Parent Object" group "Light Parameters" ( colorpicker col "Light Color" color:[255,255,255] spinner multi "Multiplier" align:#left range:[-10000,10000,1.0] checkbox cast "Cast Shadows" checked:true ) -- end "Light Parameters" label ab01 "Alexander Esppeschit Bicalho" label ab02 "Kinetix Training Specialist" label ab03 "http://www.origamy.com.br" -- When the object is selected, the engine starts creating the array of lights on sel_obj picked obj do ( local m = snapshot obj addmodifier m (mesh_select()) -- Creates a copy of the object, using the Snapshot command that reads -- spacewarps applied to the object local total_l = getnumverts m -- Reads the number of vertices in the object progressstart "Creating Lights..." latestlightcreated = #() local vt = getvert m 1 -- Reads the 1st vertex position if areaomni2 != undefined then ( latestlightcreated[1] = areaomni2 pos:vt name:(uniquename (obj.name + "Light")) total_lights:total_l area_multiplier:multi.value latestlightcreated[1].omnilight.color=col.color if exclude_it.checked then latestlightcreated[1].omnilight.excludelist = #(obj.name) if cast.checked then latestlightcreated[1].omnilight.castshadows = true latestlightcreated[1].omnilight.raytracedshadows = true ) else ( latestlightcreated[1] = Omnilight pos:vt name:(uniquename (obj.name + "Light")) multiplier:(multi.value/total_l) latestlightcreated[1].color=col.color if exclude_it.checked then latestlightcreated[1].excludelist = #(obj.name) if cast.checked then latestlightcreated[1].castshadows = true latestlightcreated[1].raytracedshadows = true ) -- Creates the first light, positioning it at the 1st vertex position -- Reads the Rollout information, and applies it to the light if link_it.checked then latestlightcreated[1].parent = obj for i in 2 to total_l do ( vt = getvert m i latestlightcreated[i] = instance latestlightcreated[1] latestlightcreated[i].pos = vt if link_it.checked then latestlightcreated[i].parent = obj progressupdate (i*100/total_l) ) -- end for i -- The FOR command repeats the steps above for each vertex in the object progressend() delete m l_created = true select latestlightcreated[1] max modify mode ) -- end sel_obj picked -- This action changes the color of the lights, if they have been created on col changed value do ( if l_created then ( if areaomni2 == undefined then latestlightcreated[1].color = value else latestlightcreated[1].omnilight.color = value ) -- end if l_created ) -- end col changed -- This action changes the multiplier of the lights, if they have been created on multi changed value do ( if l_created then ( if areaomni2 == undefined then latestlightcreated[1].multiplier = value/total_l else latestlightcreated[1].area_multiplier = value ) -- end if l_created ) -- end multi changed -- This action turns off the Cast Shadow of the lights, if they have been created on cast changed state do ( if l_created then ( if areaomni2 == undefined then latestlightcreated[1].castshadows = cast.checked else latestlightcreated[1].omnilight.castshadows = cast.checked ) -- end if l_created ) -- end cast changed ) -- end of rollout try(closerolloutfloater arealightrollout) catch() -- If the rollout is opened (try) closes it arealightrollout = newrolloutfloater "Area Light" 200 305 -- Creates the rolloutfloater addrollout areaL_rollout arealightrollout -- Adds the rollout to the floater ) -- end of macroscript