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

Previous Table of Contents Next


To change a modifier name, simply add .name to the end of it and change its name. You can access any object modifier in several ways:

  obj.modifier[index], where index is the number of the modifier in the stack, counting downwards as they appear in the stack list
  obj.modifier[“name”], obj.modifier[#name], or obj.name, where name is the modifier name

To enable or disable the modifier, type obj.modifier.enabled = true or false. This will enable/disable the object in both the viewport and the renderer. To enable/ disable the modifier in viewports only, you can use .enabledinviews.


TIP It’s useful to disable, in viewports, modifiers that take time to process. This will make your work in MAX faster. Some examples are Optimize or MeshSmooth.

To remove a modifier from an object, you can use DELETEMODIFIER, which works the same way as ADDMODIFIER. For instance, deletemodifier c c.bend will remove the bend modifier applied to our cylinder.

If you want to collapse the stack, as if you were using the Edit Stack button, you can use the COLLAPSESTACK command. The statement collapsestack c will collapse all modifiers applied to the cylinder.

Working in Sub-Object Level

Most of the modifiers have sub-objects. You can access them and change their parameters through MAXScript.

For instance, the Bend modifier has two sub-objects: Gizmo and Center. You can change their position, rotation, and scale through MAXScript by simply accessing object.bend.gizmo or object.bend.center. All position, rotation, and scale information of the modifiers is calculated in object space, which means that the X, Y, Z coordinates’ origins are the object’s local coordinate system.

Usually, gizmo sub-objects allow you to change their position, rotation, and scale. Center sub-objects will only allow position changes.

Some modifiers have different sub-objects, and will require different methods to access their properties.

Space Warps

You can create space warps as normal 3D objects; all their properties are easily adjustable, as with any 3D object.

You cannot add a space warp the way you add a modifier, and you cannot link one to an object, because a space warp requires the Bind tool. To do so, you can use the BINDSPACEWARP command to associate objects and space warps.

Some space warps—Path Follow, for instance—require several adjustments to be made not on the space warp object itself, but on the binding. These options can be accessed as a normal modifier.

For instance, let’s create a rippled surface, using two space warps:

 c = cylinder radius:300 height:1 capsegs:40 sides:80
 sw1 = spaceripple pos:[200,200,0]
 sw2 = spaceripple pos:[100,-50,0]
 bindspacewarp c sw1
 c.ripple_binding.name = “Ripple1”
 bindspacewarp c sw2
 c.ripple_binding.name = “Ripple2”
 c.ripple1.flexibility = 0.25
 c.ripple2.flexibility = 0.4

This script creates a surface and two Ripple space warps. Then it associates each of them to the surface and renames them. At the end, the code adjusts their flexibility, which is a property that exists when this space warp is associated to a object. You can see it selecting the cylinder and selecting the space warp in the Modify tab.

Hands-On MAXScript: Creating a Material and Applying It to a Selected Object

Let’s create a script that will create a brick material and apply it automatically to the selected object, such as the wall in Figure 14.10. Since it’s brick, the object will need UVW mapping coordinates. The only parameter that will be requested from the user is the size of the brick. This script has no requirements, except that an object needs to be selected.

Start a new script and type the commands shown in Listing 14.3. (This code is available as brick_exercise.ms on the CD-ROM that accompanies this book.)


FIGURE 14.10  Brick Wall script results


LISTING 14.3: The Brick Wall script (brick_exercise.ms)
 if selection.count == 0 then format “Select an object first.\n” else
 (
 obj = $
 m = standardmaterial()
 bmp = bricks()
 m.diffusemap = bmp
 showtexturemap m bmp on
 obj.material = m
 max modify mode
 brick_size = getkbvalue prompt:”Enter Brick Length:”
 brick_height = getkbvalue prompt:”Enter Brick Height:”
 addmodifier obj (uvwmap name:”UVW”)
 obj.uvw.maptype = 4
 obj.uvw.length = brick_size * 3
 obj.uvw.width = brick_size * 3
 obj.uvw.height = brick_height * 8
 )

You will notice that you’ve created a standard material and a default brick map. Then this material was assigned to the selected objects and the Show Map in Viewport option was turned on.


NOTE MAX MODIFY MODE is a command that will switch to the Modify tab. It’s just a cosmetic option in the script, one that will make it easier for the user to adjust the brick size later.

You asked the user to enter the brick size, applied a UVW map modifier, specified Box type, and then defined the length, width, and height of the UVW map according to the values specified by the user.


TIP You can enter information when adding a modifier. We didn’t need to separate the UVW command in 4 lines; it could have been done the same way as with the name:“UVW” property, but it’s better to split the command into several lines, because it’s easier to organize and debug the script.

Creating and Managing a Hierarchy

You can create and manage hierarchies in MAXScript. It’s the same as using the Link and Unlink tools, but you can also list and check the object relations in MAXScript.

You can link objects the same way you do manually in the viewports, selecting the children and linking them to a parent. It’s done using the .parent property that is valid for all objects.

For example, let’s create two objects and link them:

 b = box pos:[100,0,0]
 c = cylinder pos:[50,0,0]
 c.parent = b

In this example, b is the parent and c is the child. Of course you could use any means you wish to specify the objects: $name, selection[index], etc.

You can use .children to see which objects are linked to one object, and you can also append child objects. For example, let’s create a sphere and link it to the box, continuing the previous example:

 s = sphere()
 append b.children s

To simply list the child objects, use b.children. If you want to know how many child objects you have, use b.children.count. Since the index of children is an array, you can also use b.children[index] to access each child object.


Previous Table of Contents Next

© 2000, Frol (selection, edition, publication)

 
Rambler's Top100