Layout Tools

Lightwave has been given the ability to create interactive tools with handles through Lscript. Examples of this are Plugins\Lscripts\utility\tool\SplitBone.ls or MergeBone.ls included with 9.6. MergeBones.ls has comments on the functions called.

@script layouttool

This pragma indicates an lscript is a tool.
It then consists of a number of preset functions and UDFs. The preset functions are:

tooldraw: coa { }

This tells the script how to draw the handles in the viewport. The coa is an object agent for the 'cursor' handle for the script.

Methods

setCSysItem(itemOA)
Sets the drawing Coordinate system to the item object agent's local coordinate system.

setDrawMode(drawmode)
This sets an number of toggles using the sum of the toggle constants. These are:
DRAWMODE_DEPTHTEST
DRAWMODE_DEPTHWRITE
DRAWMODE_OUTLINE

So to set Depthtest and depthwrite you would write
coa.setDrawMode(DRAWMODE_DEPTHTEST + DRAWMODE_DEPTHWRITE);

setColor(r,g,b,a)
This sets the colour to be drawn next, values being percentages.

setPattern(pattern)
This sets the type of line to be drawn next, values being:
PATTERN_DASH
PATTERN_SOLID

drawLine(vec1,vec2, coordsys)

drawQuad(vec1,vec2,vec3,vec4, coordsys)
These two draw in the viewport using the Coordinate system and colour specified previously. The coordsys determines which plane to draw in and can be:
SYS_VIEWPORT or "viewport"
SYS_OBJECT or "object"


tooldown: te
toolmove: te
toolup: te

These UDFs tell the script what to do in the event of a button press by the user. tooldown is called on a mouse button down event. toolmove is called when the mouse is moved with a mousebutton down. toolup is called when the mouse button is released. te is the object agent for the mouse information. It will be useful in your script to have variables to keep track of when a handle has been moved or not, and which handle this was, as te does not have a member for this value.It has the following members.

posRaw[index]
Returns a value containing the @x,y,z@ of the mouse.

axis[index]
Returns a value containing the @x,y,z@ of the mouse click axis vector.

viewNumber
Returns a value containing the viewport id

In addition, a method has been added to the Scene() object to transform a position to a viewport position.

viewportProject(viewnumber,position)
Returns the given position as a position in the given viewport eg.
mousepos = scene.viewportProject(te.viewNumber, mousepos);