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

Previous Table of Contents Next



LISTING 18.9: The Hand plug-in script (plugin_hand.ms)

plugin geometry Hand_2
 name:”Hand”
 category:”Mastering 3D Studio MAX”
 (
 tool create
 (
 on mousePoint clickNo do
 (
 if clickNo == 1 do
 (
 hand = dummy pos:worldPoint name:(uniquename “Hand”)
 a1 = dummy pos:worldPoint name:(hand.name + “A_01”)
 a2 = dummy pos:worldPoint name:(hand.name + “A_02”)
 b1 = dummy pos:worldPoint name:(hand.name + “B_01”)
 b2 = dummy pos:worldPoint name:(hand.name + “B_02”)
 b3 = dummy pos:worldPoint name:(hand.name + “B_03”)
 c1 = dummy pos:worldPoint name:(hand.name + “C_01”)
 c2 = dummy pos:worldPoint name:(hand.name + “C_02”)
 c3 = dummy pos:worldPoint name:(hand.name + “C_03”)
 d1 = dummy pos:worldPoint name:(hand.name + “D_01”)
 d2 = dummy pos:worldPoint name:(hand.name + “D_02”)
 d3 = dummy pos:worldPoint name:(hand.name + “D_03”)
 e1 = dummy pos:worldPoint name:(hand.name + “E_01”)
 e2 = dummy pos:worldPoint name:(hand.name + “E_02”)
 e3 = dummy pos:worldPoint name:(hand.name + “E_03”)
 a1.parent = b1.parent = c1.parent = d1.parent = e1.parent = hand
 a2.parent = a1
 b2.parent = b1
 d2.parent = d1
 e2.parent = e1
 c2.parent = c1
 b3.parent = b2
 d3.parent = d2
 e3.parent = e2
 c3.parent = c2
 )
 if clickNo == 2 then
 (
 b1.pivot.y = b1.pos.y - b1.boxsize.y/2
 c1.pivot.y = c1.pos.y - c1.boxsize.y/2
 d1.pivot.y = d1.pos.y - d1.boxsize.y/2
 e1.pivot.y = e1.pos.y - e1.boxsize.y/2
 b2.pivot.y = b2.pos.y - b2.boxsize.y/2
 c2.pivot.y = c2.pos.y - c2.boxsize.y/2
 d2.pivot.y = d2.pos.y - d2.boxsize.y/2
 e2.pivot.y = e2.pos.y - e2.boxsize.y/2
 b3.pivot.y = b3.pos.y - b3.boxsize.y/2
 c3.pivot.y = c3.pos.y - c3.boxsize.y/2
 d3.pivot.y = d3.pos.y - d3.boxsize.y/2
 e3.pivot.y = e3.pos.y - e3.boxsize.y/2
 a1.pivot.y = a1.pos.y - a1.boxsize.y/2
 a2.pivot.y = a2.pos.y - a2.boxsize.y/2
 rotate a1 -90 Z_axis
 #stop
 )
 )
 on MouseMove clickNo do
 (
 if clickNo == 2 do
 (
 hand.boxsize.x = abs(worldDist.x*2)
 hand.boxsize.y = abs(worldDist.y*2)
 hand.boxsize.z = (hand.boxsize.x + hand.boxsize.y)/15
 newsize = [hand.boxsize.x/5, hand.boxsize.y/3, hand.boxsize.z*0.8]
 a1.boxsize = a2.boxsize = newsize
 b1.boxsize = b2.boxsize = b3.boxsize = newsize
 c1.boxsize = c2.boxsize = c3.boxsize = newsize
 d1.boxsize = d2.boxsize = d3.boxsize = newsize
 e1.boxsize = e2.boxsize = e3.boxsize = newsize
 b1.pos = hand.pos + \
 [hand.boxsize.x*3/8, hand.boxsize.y/2 + b1.boxsize.y*0.55,0]
 c1.pos = hand.pos + \
 [hand.boxsize.x*1/8, hand.boxsize.y/2 + c1.boxsize.y*0.55,0]
 d1.pos = hand.pos + \
 [-hand.boxsize.x*1/8, hand.boxsize.y/2 + d1.boxsize.y*0.55,0]
 e1.pos = hand.pos + \
 [-hand.boxsize.x*3/8, hand.boxsize.y/2 + e1.boxsize.y*0.55,0]
 b2.pos = b1.pos + [0, b1.boxsize.y*1.1,0]
 c2.pos = c1.pos + [0, c1.boxsize.y*1.1,0]
 d2.pos = d1.pos + [0, d1.boxsize.y*1.1,0]
 e2.pos = e1.pos + [0, e1.boxsize.y*1.1,0]
 b3.pos = b2.pos + [0, b1.boxsize.y*1.1,0]
 c3.pos = c2.pos + [0, c1.boxsize.y*1.1,0]
 d3.pos = d2.pos + [0, d1.boxsize.y*1.1,0]
 e3.pos = e2.pos + [0, e1.boxsize.y*1.1,0]
 a1.pos = hand.pos + [hand.boxsize.x/2 + a1.boxsize.y*0.05, 0, 0]
 a2.pos = a1.pos + [0, b1.boxsize.y*1.1, 0]
 )
 )
 )
 )


In this example, you did not create a rollout, but if you did so, this rollout would have to manipulate the objects the same way you did here, directly addressing and adjusting their properties.

As you might have noticed, this script is basically a tool. It creates a series of objects and links them, when the mouse is first clicked. Then, when the mouse is dragged, the objects are resized and repositioned, according to certain rules. When finished dragging, the pivot point of the objects is adjusted, and the thumb is rotated.

You could not have adjusted the pivot during the dragging phase, because it would change the object’s position, making us recalculate everything. In addition, when the object changes size, the pivot would have to be relocated.

In addition, notice you didn’t use gridPoint, but worldPoint. The user then can create the hand in any viewport, but it will be aligned to the top view. This allows you to move the pivot of the objects, and more code would be needed to allow this creation in any view, because of the pivot realignment at the end of the script. You can reposition the hand at any time, and manipulate its fingers with the Hand controller script that you wrote in Chapter 15.

Creating Modifiers

You can write simple modifiers, like Bend, Twist, and Taper, using MAXScript. These modifiers will change the position of vertices based on their original position, but in a parametric form, which means you will not have access to the vertex position, but will change it using a math formula.

You will now write a modifier that will deform an object like a sine wave, allowing you to define the axis, amount of deformity, and number of curves, as seen in Figure 18.11.


FIGURE 18.11  ZigZag modifier

Start a new script and type the Listing 18.10, or open the file named plugin_zigzag .ms on the CD.


LISTING 18.10: The Zigzag modifier plug-in script (plugin_zigzag.ms)

plugin simpleMod Zigzag
 name:”Zig Zag”
 classID:#(0xa8eba5be, 0x89ff7eab)
 (
 parameters main rollout:params
 (
 amount type:#worldunits ui:amtSpin default:20
 cycles type:#float ui:times default:0.5
 z_axis type:#radiobtnindex ui:zaxis default:1
 )
 rollout params “ZigZag Parameters”
 (
 spinner amtSpin “Amount: “ type:#float range:[-1000,1000,20]
 spinner times “Cycles: “ type:#float range:[0,100,1]
 radiobuttons zaxis labels:#(“X”,”Y”,”Z”) coluns:3
 )
 on map i p do
 (
 case z_axis of
 (
 1: p.x += amount*sin((p.z-(center.z))*pi*cycles)
 2: p.y += amount*sin((p.z-(center.z))*pi*cycles)
 3: p.z += amount*sin((sqrt(p.x^2+p.y^2)-\
 sqrt(center.x^2+center.y^2))*pi*cycles)
 )
 p
 )
 )


As you can see, the modifier plug-in doesn’t need a tool to be created. However, it has a rollout and a parameter block like any other plug-in script.

This type of modifier plug-in works through the on map i p event. This event will be called for each vertex in the object, and will copy its position in the p variable. Then, the plug-in will modify the position and will output the new p value.


Previous Table of Contents Next

© 2000, Frol (selection, edition, publication)

 
Rambler's Top100