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

Previous Table of Contents Next


Working with Meshes

As you did with 2D objects, you will also need to manipulate 3D objects using the Editable Mesh object. It is the only way to access and manipulate vertex and face information.

Converting Objects to Editable Meshes

Unlike 2D shapes, 3D objects cannot be created directly as editable meshes. Some importers, like the 3DS Importer, will import geometry as editable meshes, but the user cannot start creating faces and vertices. Geometry must come from a converted Object.

You can convert objects to editable mesh in two ways: using the COLLAPSESTACK or the CONVERTTOMESH commands.

When you convert an object to editable mesh, either using MAXScript or the Edit Stack button, if the object was modified by space warps or world space modifiers, their effects will be discarded. To convert an object to editable mesh and consider the effects of the space warps, you can use the Snapshot tool or the SNAPSHOT command in MAXScript.

Let’s say you have b = box(); these are the three ways you can convert it to an editable mesh:

 b = converttomesh b
 b = snapshot b
 b = collapsestack b

NOTE The COLLAPSESTACK command only converts the object to an editable mesh if the object has modifiers applied to it.

Mesh Properties

It’s important to know certain information about meshes (such as the number of faces and vertices, which ones are selected, etc.) so you can manipulate a series of vertices, edges, or faces. Some of these properties are:

Property Description
.numverts Number of vertices
.numfaces Number of faces
.numtverts Number of texture vertices
.numcpvverts Number of vertices that have Color per Vertex applied
.selectedverts Vertices that are selected
.selectededges Edges that are selected
.selectedfaces Faces that are selected

You can use simple commands to attach objects, create Booleans, and adjust simple parameters in editable meshes.

To attach objects, use the ATTACH command; you need an editable mesh and any other object. If it’s a 2D object, NURBS, or patch, it will be converted to editable mesh and attached. For instance, to create two objects and attach them:

 a = sphere()
 b = box pos:[30,0,0]
 c = converttomesh a
 attach c b

Creating Simple Booleans

You create simple Booleans using simple math formulas (addition, subtraction, and intersection) on nodes, but the resulting object will be an editable mesh, as seen in Figure 14.16. To use the Boolean compound object and retain all sub-objects, use BOOLOBJ.CREATEBOOLEANOBJECT.


TIP BOOLOBJ has lots of commands. Take a look at the MAX Online Help to learn more about them.


FIGURE 14.16  An editable mesh created from Boolean examples

To use simple Booleans, treat objects as part of a math operation. For instance:

 a = box pos:[-10,10,0]
 b = sphere radius:20
 c = a + b
 delete b

When the Boolean is processed, the first operand is deleted and any others remain. That’s why we’ve deleted b.

The other two operations, subtraction and intersection, can be made with the use of the minus (-) and the multiply (*) symbols. You can perform more than one operation in a single command:

 a = box pos:[-10,0,0]
 b = sphere radius:15
 c = box pos:[0,15,0]
 d = a * b - c
 delete b
 delete c

You can also create compound Booleans using MAXScript:

 a = box pos:[-10,0,0]
 b = sphere radius:15
 c = boolobj.createbooleanobject a b 1 1
 boolobj.setboolop c 1
 delete b

In createbooleanobject, you need to specify two objects:

  How the second operand—here, b—will be treated (1–instance, 2–reference, 3–copy, 4–move)
  How the materials will be treated (1–combine, 2–match ID, 3–match materials, 4–use new node, 5–use original)

In setboolop, you specify which Boolean operation will occur (1–Union, 2–Inter-section, 3–A-B, 4–B-A, 5–Cut).


NOTE After changing the Boolean operator, the object will only update on screen when you click it, or when it redraws.


TIP You can use MAX VIEWS REDRAW to force a redraw.

Accessing Vertex, Face, and Edge Information

Sometimes it’s useful to have access to and manipulate Vertex, Face, and Edge information. Let’s look at some of these commands and some examples.

Getting Vertex Data

Some vertex commands are replicated from properties in an editable mesh. These commands are: GETNUMVERTS, GETVERTSELECTION, and GETNUMTVERTS. You can use either object.numverts or getnumverts obj. You can read several other types of information from vertices, including these:

Command Description
getvert Returns the vertex position
getnormal Returns the normal related to the vertex
gettvert Returns the UVW coordinate of the vertex
getvertcolor Returns the color of the vertex
getvertselection Returns an array of the selected vertices

This information is very useful for writing scripts. All these commands have a SET command related to them that will write new data to each property. For instance, if you want to move a certain vertex [10,2,4], you can do it this way:

 s = sphere()
 s1 = converttomesh s
 pt = getvert s1 1
 setvert s1 1 (pt + [10,2,4])
 update s1

NOTE Mesh operations also require an update to be seen on screen.


Previous Table of Contents Next

© 2000, Frol (selection, edition, publication)

 
Rambler's Top100