|
Mastering
3D Studio MAX R3 |
This tool will need the following mouse movements: the first click, mouse
drag, and release. The first click will define the objects position.
Within plug-in scripts, this is done using nodeTM.translation.
You will not need to use in coordsys grid also.
The drag movement will define the size of the cube. It is done using
delegate .parameter. When you need to define any parameter
of the object thats being extended, use DELEGATE. In our example,
the width, height, and length are all equal, and are defined by the distance
between the first click and the mouse drag position. Its specified
using GRIDDIST. Here we used a formula that calculates the distance between
two points in XYZ, which is the square root of ((distance in X)2
+ (distance in Y)2 + (distance in Z)2).
When the mouse is released, the plug-in stops. Note that the Box rollout
appears on the screen, and if you select Modify, it will continue appearing
there. If you open the Track View and expand the object tracks, you will
see that the box is now a subanim of the cube. This is how extended plug-ins
work.
|
|
| WARNING Once
you add a plug-in script to a scene, it will behave just like a regular
plug-in, which means that you will need to have the plug-in loaded
to open the scene again.
|
|
|
| TIP Placing
the .ms file in any plug-in folder will load it as
a regular plug-in.
|
Adding Rollouts
You can still add more options and flexibility to this plug-in. A plug-in
script can also have a rollout, which will define the properties you want
to give to the object. For instance, it would be nice to have a size
option in our cube.
To add a rollout in a plug-in script, simply add it before the tool.
If the plug-in script extends another plug-in, you need to specify whether
this rollout will or will not replace the objects user interface
(UI). This is specified in the PLUGIN command, using replaceUI:true
or false.
Edit your script, adding replaceUI:true in the PLUGIN
command (this script is named plugin_cube1.ms on the CD).
plugin geometry cube
name:”Cube”
category:”Mastering 3D Studio MAX”
classID:#(0x36b2b15a, 0x60b9a9bb)
extends:Box
replaceUI:true
Then, add the rollout clause before the tool:
rollout params “Parameters”
(
spinner size “Size: “ range:[0,10000,0]
on size changed val do
delegate.width = delegate.height = delegate.length = val
on params open do size.value = delegate.width
)
You will also need to modify the MouseMove action so that it updates
the spinner value, when dragging the mouse:
if clickNo == 2 do
(
val = sqrt(gridDist.x^2 + gridDist.y^2 + gridDist.z^2)
delegate.width = delegate.height = delegate.length = val
params.size.value = val
)
Now you have the script ready. Evaluate and play with it.
Notice that now your object has a new rollout, as seen in Figure 18.2.
When creating a new object, this rollout sometimes appears below the objects
rollouts, sometimes alone. In the Modify tab, only this rollout will appear,
unless you have specified replaceUI:false, in which case
all rollouts will appear.
FIGURE
18.2 Cube rollout
Adding Parameters in Track View
If you check the Track View, you still do not have any parameters for
this object, even though it now has an interface. This is because you
will need to create a parameter block.
Parameter blocks are special parameters that are saved with the object
and allow direct animation of their values. Parameter blocks will create
tracks in Track View for each property you want to animate, making animation
easier to edit and visualize. Parameter blocks are essential for creation
plug-ins, since they do not extend any plug-in that already has parameters.
A parameter block can be linked to a rollout, automatically linking the
variables with the UI items, making it easier for you to write the script,
since you will not need to write any event handler code for the UI item.
Add a parameter block to your cube plug-in by adding the following lines
before the rollout clause:
parameter pblock rollout:params
(
cube_size animatable:true type:#worldunits ui:size
on cube_size set val do
delegate.width = delegate.height = delegate.length = val
)
The parameter block is linked to the params rollout. Then,
the variable cube_size will be linked to the size spinner
in this rollout, because you used ui:size.
The parameter can have a series of properties, but the most important
is the type. This defines which kind of variable the parameter isinteger,
float, color, point3, Boolean, etc. (The complete list is shown in Table
18.2.) In the cube example, we used worldunits, which will allow users
to specify this value using any configured unit in their system. This
makes the script usable for all different measuring systems.
Table 18.2: REPRESENTING PARAMETER
TYPES IN THE UI
Parameter Type
| UI Item
|
#float
|
|
#integer
|
|
#time
|
|
#angle
| Spinner or slider
|
#percent
|
|
#colorchannel
|
|
#worldunits
|
|
#integer
| Radio button
|
#radiobtnindex
|
|
#integer
| Check box or checkbutton
|
#boolean
|
|
#color
| Colorpicker
|
#node
| Pickbutton
|
#texturemap
| Mapbutton
|
#material
| Materialbutton
|
You can also specify whether or not the parameter is animatable. If its
not animatable, it will not be displayed in the Track View.
All parameters in a parameter block can be accessed using MAXScript,
and they are accessed just like any object property, using object.property.
Now that you defined the parameter block, you can adjust the rest of
the script so it uses the parameter block. Replace the code in the rollout
with the following:
rollout params “Parameters”
(
spinner size “Size: “ range:[0,10000,0]
)
Now edit the MouseMove event:
on MouseMove clickNo do
(
if clickNo == 2 do
size = sqrt(gridDist.x^2 + gridDist.y^2 + gridDist.z^2)
)
Evaluate the script now, and play with it. Notice the Size parameter
also appears in the Track View (Figure 18.3). This script can be found
on the CD as plugin_cube2.ms.
FIGURE
18.3 Cube properties in Track View
© 2000, Frol (selection,
edition, publication)
|