Custom Objects

Like Item Animation, Custom Object can take an optional argument to its create() UDF that is an Object Agent for the object to which this script is assigned. Custom Object also supports the init(), newtime() and cleanup() UDFs.

The Custom Object process() UDF takes a single argument which is a Custom Object Agent that provides an interface to the underlying Custom Object functionality. It exports the following data and methods:


The Custom Object create() UDF can also take an optional argument which provides an interface to the object which the script is applied to, as below

@warnings
@version 2.4
@script custom
@name objectID


myobjid;

create: obj
{
    myobjid = obj.id;
    setdesc("internal lscript id: " + myobjid + " scene id:" + strsub(hex(myobjid),3,size(hex(myobjid))));
}

Data Members

view
a read-only data member that indicates which view drawing will effect. It will contain one of the following:

VIEW_ZY
VIEW_XZ
VIEW_XY
VIEW_PERSP
VIEW_LIGHT
VIEW_CAMERA
VIEW_SCHEMA

flags[]
Read-only array of settings for the current Custom instance. it only has a single element right now (flags[1]) which will be 'true' if the Custom object should be drawn in a selected state, or 'false' otherwise.
In addition to SCHEMA, the Custom Object flags() function can now also return the following values:

VPINDEX
indicates that the value in the view data member should correspond to the viewport number instead of its type.

NODEPTH
causes drawing of the object to occur in front of all other OpenGL elements, regardless of Z position.

Methods

setColor(|r,g,b[,a])
Sets the color for subsequent drawing actions.

setPattern(pat)
Sets the drawing pattern. Solid by default, or can be one of the following:

    PATTERN_SOLID (or "SOLID")
    PATTERN_DOT (or "DOT")
    PATTERN_DASH (or "DASH")
    PATTERN_LONGDOT (or "LONGDOT")

drawPoint(<pos>[,coord])
Draw a point into the current view at the vector location <pos> using the previously set color and line pattern. The coord parameter is optional (SYS_OBJECT is the default), and can be one of the following:

    SYS_WORLD (or "WORLD" or "GLOBAL")
    SYS_OBJECT (or "OBJECT" or "LOCAL")
    SYS_ICON (or "ICON")

drawLine(<pos1>,<pos2>[,coord])
Draws a line segment from vector <pos1> to vector <pos2>.

drawTriangle(<pos1>,<pos2>,<pos3>[,coord])
draws a triangle whose end points are vector <pos1>, vector <pos2>, and vector <pos3>.

drawCircle(<pos>,rad[,coord])
draws a circle whose center point is vector <pos>, with a radius of rad.

drawText(<pos>,text[,coord,[align]])
draws the provided text string at the vector location <pos>. the align argument can be one of the following:

    LEFT (or "LEFT")
    CENTER (or "CENTER")
    RIGHT (or "RIGHT")

The plug-in API does not maintain state information between evaluations, and neither does LScript. This means that every time the process() UDF is called, the color is set back to that established for the object in the Layout interface, and the drawing pattern is always PATTERN_SOLID.

Here is a short Custom Object LScript that duplicates the "barn" sample provided by Ernie in the LightWave SDK:

  @warnings
  @script custom

  vert = @ <0.0, 0.0, 0.0>, <1.0, 0.0, 0.0>, <1.0, 1.0, 0.0>,
     <0.5, 1.5, 0.0>, <0.0, 1.0, 0.0>, <0.0, 0.0, -1.0>,
     <1.0, 0.0, -1.0>, <1.0, 1.0, -1.0>, <0.5, 1.5, -1.0>,
     <0.0, 1.0, -1.0> @;

  edge = @ 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 6, 7,
     7, 8, 8, 9, 9, 10, 10, 6, 1, 6, 2, 7,
     3, 8, 4, 9, 5, 10, 2, 5, 1, 3 @;

   process: ca
   {
      for(x = 1;x < 31;x += 2)
          ca.drawLine(vert[edge[x]],vert[edge[x+1]]);
      ca.setPattern("dot");
      for(x = 31; x < 35;x += 2)
          ca.drawLine(vert[edge[x]],vert[edge[x+1]]);
   }