Титульная страница
ISO 9000 ISO 14000
GMP Consulting
 
Mastering 3D Studio MAX R3

Previous Table of Contents Next


You can now animate the script like any regular object. Save this plug-in in the Plugins folder.

You can now try another example, where you will extend a sphere to create a hemisphere object. It will have two parameters: Radius and Segments, as seen in Figure 18.4.

This example will also introduce you to some new concepts. Start a new script and type the code in Listing 18.2, or open the plugin_hemisphere.ms file from the CD.


FIGURE 18.4  Hemisphere plug-in script


LISTING 18.2: The Hemisphere plug-in script (plugin_hemisphere.ms)

 plugin geometry hemisphere
 name:”Hemisphere”
 category:”Mastering 3D Studio MAX”
 classid:#(0xce445e62, 0x42606fad)
 extends:Sphere
 replaceui:true
 (
parameters pblock rollout:params
 (
 radius animatable:true type:#worldunits ui:size
 segments animatable:true type:#integer ui:segs default:32
 on radius set val do delegate.radius = val
 on segments set val do delegate.segments = val
 )
rollout params “Parameters”
 (
 spinner size “Radius: “
 spinner segs “Segments: “ type:#integer range:[4,1000,32]
 )
on create do
 (
 delegate.hemisphere = 0.5
 delegate.chop = 1
 )
tool create
 (
 on mousePoint clickNo do
 (
 if clickNo == 1 do nodeTM.translation = gridPoint
 if clickNo == 2 then #stop
 )
 on MouseMove clickNo do
 (
 if clickNo == 2 do
 radius = sqrt(gridDist.x^2+gridDist.y^2+gridDist.z^2)
 )
 )
)


The segments variable in the parameter block has a default value of 32. This is done because the default value of any parameter block is zero, which would set an incorrect parameter to our sphere.

Notice you limited the spinner values to the actual limits of the parameters in the sphere object. You also used a new event: on create. It’s called when the object is created for the first time, and defines its basic configuration. In this example, it defines that the sphere is a hemisphere.

You can play with this script and add the slicing parameters to the extended version.

Extending Shapes

Extending shapes is pretty much all that plug-in scripts can do to shapes. There’s no way to create new shape objects other than the built-in shapes in MAX.

For instance, you can create a plug-in script that will extend the star shape and predefine some parameters. The inner radius will be 55% of the outer radius, and the fillet values will be 10% of it. Start a new script and type out Listing 18.3, or open the file plugin_newstar.ms from the CD.


LISTING 18.3: The New Star plug-in script (plugin_newstar.ms)

 plugin shape Star_2
 name:”New Star”
 category:”Mastering 3D Studio MAX”
 classID:#(0x4ca7c13d, 0x748bce49)
 extends:Star
 replaceui:true
 (
 parameters pblock rollout:params
 (
 radius animatable:true type:#worldunits ui:size
 points animatable:true type:#integer ui:pt default:6
 on radius set val do
 (
 delegate.radius1 = val
 delegate.radius2 = val*0.55
 delegate.filletradius1 = val/10
 delegate.filletradius2 = val/10
 )
 on points set val do delegate.points = val
 )
 rollout params “Parameters”
 (
 spinner size “Radius: “ range:[0,10000,0]
 spinner pt “Points: “ range:[3,100,6] type:#integer
 )
 tool create
 (
 on mousePoint clickNo do
 (
 if clickNo == 1 do nodeTM.translation = gridPoint
 if clickNo == 2 then #stop
 )
 on MouseMove clickNo do
 (
 if clickNo == 2 do
 radius = sqrt(gridDist.x^2+gridDist.y^2+gridDist.z^2)
 )
 )
)


Notice that this script works the same way as the previous scripts you have made, except that it is extending a Shape object, and it’s delegating values for several parameters all at once.

You can also add regular interface items that will adjust the parameters of the object. For instance, you can create a Helix shape and define its height by selecting the distance between two objects. This cannot be done during the creation process, but can be done in the Modify tab, as seen in Figure 18.5.


FIGURE 18.5  Helix2 plug-in script

Start a new script and type the statements in Listing 18.4, or open the file plugin_helix2.ms on the CD.


LISTING 18.4: The Helix2 plug-in script (plugin_helix2.ms)


 plugin shape Helix_2
 name:”New Helix”
 category:”Mastering 3D Studio MAX”
 classID:#(0xa13154cd, 0x6c485140)
 extends:Helix
 replaceui:true
 (
 parameters pblock rollout:params
 (
 radius animatable:true type:#worldunits ui:rd
 height animatable:true type:#worldunits ui:ht
 turns animatable:true type:#integer ui:pt default:6
 obj1 type:#node
 obj2 type:#node
 on radius set val do
 (
 delegate.radius1 = val
 delegate.radius2 = val
 )
 on turns set val do delegate.turns = val
 on height set val do delegate.height = val
 )
 rollout params “Parameters”
 (
 spinner rd “Radius: “ range:[0,10000,0]
 spinner ht “Height: “ range:[0,10000,0]
 spinner pt “Turns: “ range:[1,100,6] type:#integer
 pickbutton base_obj “Select Base Object” width:140
 pickbutton top_obj “Select Top Object” width:140 enabled:false
 on base_obj picked obj do
 (
 obj1 = obj
 pt1 = obj.pivot
 top_obj.enabled = true
 )
 on top_obj picked obj do
 (
 obj2 = obj
 height = distance pt1 obj.pivot
 )
 on params open do
 (
 if obj1 != undefined do base_obj.text = obj1.name
 if obj2 != undefined do
 (
 top_obj.text = obj2.name
 top_obj.enabled = true
 )
 )
 )
 tool create
 (
 on mousePoint clickNo do
 (
 if clickNo == 1 do nodeTM.translation = gridPoint
 if clickNo == 3 then #stop
 )
 on MouseMove clickNo do
 (
 if clickNo == 2 do
 radius = sqrt(gridDist.x^2 + gridDist.y^2 + gridDist.z^2)
 if clickNo == 3
 do height = sqrt(gridDist.x^2 + gridDist.y^2 + gridDist.z^2)
 )
 )
 )

This script makes use of a new parameter type: the node . Node refers to any object in the scene, and allows you to access any property of this node through the variable. In your example, you’re reading the nodes’ positions and calculating the distance between them.

This is done by the two pickbuttons in the rollout. They set the obj1 and obj2 variables, when selected; they also calculate the height of the helix. You are not moving the object and you are not linking it to the others; all you are doing is defining the height using two known objects. Once the objects have been selected, their names will appear in the pickbuttons. This will happen even if you are selecting the helix2 later, because both objects were stored in the parameter blocks.

Extending Helpers

Helpers can also be extended through plug-ins. Usually, there’s not too much that can be done with helpers, because most of them have very few options, but you can extend a dummy object and add the missing length, width, and height options.

The next plug-in script will access the .boxsize property of a dummy and allow the user to access the length, width, and height of the dummy like any other MAX object, as seen in Figure 18.6


FIGURE 18.6  Dummy2 plug-in script

Start a new script and type the lines found in Listing 18.5, or open the file plugin _dummybox.ms on the CD.


Previous Table of Contents Next

© 2000, Frol (selection, edition, publication)

 
Rambler's Top100