Scripted Plug-in Methods
The addPluginRollouts() is used within scripted plug-in create tools, specifically for level 1 plug-ins that
don't create instances of themselves in the scene but might create other objects within
their create tool. This method lets you install rollouts for a specified object in
the Create panel, typically one of the objects being created in the create tool, so
that its parameters can be adjusted directly during creation.
The form is:
In the following example, a variation of the three light mouse tool example presented
in Mouse Tool Clauses is set into permanent, editable classes. It defines two new classes. The helper class
lightMaster is used as a master object for the light system. The light class threeLights is what you create to layout the initial system. It also creates a lightMaster and sets its parameters to point at the lights. The lightMaster rollout allows subsequent editing of the system in the Modifier panel, and storing
the lights in a parameter block makes the setup persistent over scene saves and loads.
SCRIPT
|
plugin helper lightMaster
name:"Light Master"
classID:#(12345,54321)
extends:Dummy
replaceUI:true
invisible:true
(
parameters main rollout:params
(
key type:#node subAnim:true
fill type:#node subAnim:true
back type:#node subAnim:true
height type:#worldUnits default:0 ui:height
spread type:#worldUnits default:0 ui:spread
angle type:#angle default:90 ui:angle
-- check value of key since lights don't exist at initial creation
on height set val do if key != undefined then coordsys key.target
(
key.pos.z = val
back.pos.z = val * 1.5
fill.pos.z = val * 0.5
)
on spread set val do if key != undefined then coordsys key.target
(
-- compute normal vector pointing at key in the target's XY plane -- (kuv) and reposition everything based on that and the current -- spread and angle values
local kuv = normalize ([key.pos.x, key.pos.y, 0])
key.pos = [kuv.x * spread, kuv.y * spread, height]
back.pos = [kuv.x * -spread, kuv.y * -spread, height * 1.5]
-- position fill by placing it under the key and then rotating in -- about the target
fill.pos = [kuv.x * spread, kuv.y * spread, height * 0.5]
about key.target rotate fill angle z_axis
)
on angle set val do if key != undefined then coordsys key.target
(
fill.pos = [key.pos.x, key.pos.y, height * 0.5]
about key.target rotate fill angle z_axis
)
)
rollout params "Light Parameters"
(
spinner height "Height" type:#worldUnits range:[-1e32, 1e32, 0]
spinner spread "Spread" type:#worldUnits range:[0, 1e32, 0]
spinner angle "Angle" range:[-180, 180, 30]
on params open do flagForeGround #(key, back, fill) true
on params close do
if key != undefined and back != undefined and fill != undefined then
flagForeGround #(key, back, fill) false
)
)
|
SCRIPT
|
plugin light searchlights
name:"Three Lights"
(
local master
tool create
(
on mousePoint click do
(
if click == 1 then -- create key, back & fill lights at mousedown
(
coordsys grid
(
master = lightMaster pos:gridPoint
master.dummy.boxsize = [10,10,10]
in master
(
local targObj=targetobject pos:gridPoint
master.key = targetspot pos:gridPoint name:"key" \
target:targObj
master.back = targetspot pos:gridPoint name:"back" \
target:targObj
master.fill = targetspot pos:gridPoint name:"fill" \
target:targObj
)
)
addPluginRollouts master
)
if click == 3 then
(
select master
master = undefined
#stop
)
)
on mouseMove click do
(
if click == 2 then -- drag out & round on x-y plane
(
-- place the key on the grid then set the spread and the -- 'on set spread' handler will -- move the lights to the correct heights
master.key.pos = worldPoint
master.spread = distance master.key master.key.target
)
else if click == 3 then -- drag up to elevate lights
master.height = gridDist.z
)
on mouseAbort click do
(
if master != undefined then
(
if master.fill != undefined then delete master.fill
if master.back != undefined then delete master.back
if master.key != undefined then delete master.key
delete master
)
)
)
)
|