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

Previous Table of Contents Next


Getting Face Data

Basically, all Vertex commands have similar commands in Face. For instance, instead of GETVERT, you would use GETFACE for a face. (But of course, faces do not have Color per Vertex, and vertices do not have Material ID.) Some of these commands are:

Command Description
getface Returns the face’s adjacent vertex
getfacenormal Returns the face normal
getfacematid Returns the Material ID of the face
getfacesmoothgroup Returns the Smoothing Group index

Just like vertices, all GET* commands have a related SET* command. For instance, you can change the material ID of the faces of an object, setting it to 2 if the face is even, or 1 if it’s odd. Let’s continue using the previous example:

 for i in 1 to s1.numfaces do
 (
 if (mod i 2) == 0 then setfacematid s1 i 2 else setfacematid s1 i 1
 )
 update s1

You can now create a Multi/Sub-Object material with one submaterial red and the other green. Then, you can apply this material to the object, so you can see the material ID of the faces:

 meditMaterials[1] = Multimaterial ()
 meditMaterials[1].materialList.count = 2
 meditMaterials[1].materialList[2].diffuse = color 255 0 0
 meditMaterials[1].materialList[1].diffuse = color 30 255 0
 s1.material = meditMaterials[1]

Other Face and Vertex Commands

Other commands, beyond SET and GET, will also affect faces and vertices. You can extrude faces using EXTRUDEFACE. Let’s extrude the faces of the middle of the sphere:

 setfaceselection s1 #{81..144}
 extrudeface s1 #selection 20 80
 update s1

NOTE This demonstrates a new way of specifying an array. #{a..b} specifies all numbers in the interval of a and b as an array.

You can use DELETEFACE or DELETEVERT to delete a face or vertex in an editable mesh. You can also use COLLAPSEFACE, which will weld all three vertices of a face in one single point at its center.


NOTE All these commands will change the number of faces, therefore they will also change the faces’ numbers.

Getting Edge Data

You cannot set an edge’s position, or any other edge property except visibility and selection.

To read and set an edge’s visibility use GETEDGEVIS and SETEDGEVIS. For instance, you can check whether one of the three edges of one face are visible or not:

 getedgevis s1 40 1

You need to specify the face number (40) and the edge number (1, 2, or 3). The command will then return true or false. SETEDGEVIS works the same way.

Working with Edit Mesh, Edit Patch, and Edit Spline

It’s possible to work with Edit Mesh, Edit Patch, and Edit Spline in MAXScript. These commands are the same ones that are displayed for you when you right-click an object.

Working with Edit Mesh and Edit Patch is the same as working with Edit Spline. Edit Mesh commands will start with MESHOPS and Edit Patch commands will start with PATCHOPS.

Most of these commands will only start actions, but some of them will work automatically. All these commands require a previous sub-object selection. For instance, if you want to delete the selected faces of an object, you can use meshops.delete object. In this case, the script will display a dialog box to confirm whether it should delete the isolated vertices.

These commands require MAX to be in the Modify tab, with one of the sub-objects selected. To change to the Modify tab, type MAX MODIFY MODE; to select the sub-object you want, use SUBOBJECTLEVEL.

In an Editable Spline, sub-object levels are:

Sub-Object Level Level
1 Vertex
2 Segment
3 Spline

In an Editable Mesh, sub-object levels are:

Sub-Object Level Level
1 Vertex
2 Edge
3 Face
4 Polygon
5 Element

In an Editable Patch, sub-object levels are:

Sub-Object Level Level
1 Vertex
2 Edge
3 Patch

You can make some commands work directly, if you are in the correct sub-object level and if you have a selection. For instance, you can weld vertices using meshops.weld, but there’s no way to set the Threshold value through scripting.

Hands-On MAXScript: Creating a Scatter and Adjusting Vertex Color

This section features two exercises. In the first you will make a script that works similar to Scatter. The second script will adjust the hue, saturation, and value of the vertex color of an object.

Creating a Scatter

Scatter only allows 3D geometry to be selected. You will do a simple scatter that will copy any object and position each copy to the center of each face.

Start a new script and type the commands found in Listing 14.6. (You can access this code from the CD-ROM, in the file named scatter_exercise.ms.)


LISTING 14.6: The Scatter script (scatter_exercise.ms)
 if selection.count != 1 then format “Select an object first.\n” else
 if superclassof $ != GeometryClass
 then format “Select a 3D Object first.\n” else
 (
 scatterobj = omnilight()
 obj = $
 obj2 = snapshot obj
 nfaces = obj2.numfaces
 setvertselection obj2 #((getface obj2 1).x,(getface obj2 1).y, \
 (getface obj2 1).z)
 scatterobj.pos = averageselvertcenter obj2
 scatterobj.parent = obj
 for i in 2 to nfaces do
 (
 scat2 = instance scatterobj
 setvertselection obj2 #((getface obj2 i).x,(getface obj2 i).y, \
 (getface obj2 i).z)
 scat2.pos = averageselvertcenter obj2
 scat2.parent = obj
 )
 delete obj2
 )


Previous Table of Contents Next

© 2000, Frol (selection, edition, publication)

 
Rambler's Top100