Mesh Vertex Methods

 

   

Editable Mesh - Quick Navigation

The following methods provide basic access the to Mesh vertices and vertex normals.

Topic Navigation:  

Mesh Vertex Access

Mesh Vertex Normals

Mesh Vertex Selection

 

Methods:

Mesh VertexAccess:

getNumVerts <mesh>

Returns number of vertices as an integer, equivalent to using <mesh>.numverts.

   

setNumVerts <mesh> <vert_index_integer> [ <boolean> ]

Set the number of vertices as specified. If the optional boolean argument is true , the existing topology remains intact. If it is false or left off, the topology is lost.

When setting the number of vertices using the numVerts property or the setNumVerts method, the new vertices are initialized to [0.,0.,0.]

   

getVert <mesh> <vert_index_integer>

Returns the position (in the current working coordinate system) of the indexed vertex as a point3

   

setVert <mesh> <vert_index_integer> ( <point3> | <float> <float> <float> )

Sets the position coordinates of the indexed vertex as a point3 value, or 3 floats - X,Y,Z

WARNING!

This low-level mesh method does NOT handle creation of vertex animation, even if the vertices have been prepared using animateVertex theMesh #all and the method is called within an animate on context!

To operate on animated meshes, use the meshop.setVert() method instead.

EXAMPLE

obj = sphere() --create a Sphere
convertToMesh obj --collapse to EditableMesh
for v = 1 to getNumVerts obj do --loop through all vertices
(
vert = getVert obj v --get the v-th vertex
vert.z = 0.0 --change the Z coordinate to 0.0
setVert obj v vert --assign back to the v-thvertex
)
update obj --update the mesh - the sphere should be flattened
 

deleteVert <mesh> <vert_index_integer>

Deletes the indexed vertex from the mesh and all faces that share the vertex. Renumbers vertices and faces to account for the deletions. Also adjusts face vertex indexes as necessary.

EXAMPLE

p = plane() --create a Plane
convertToMesh p --collapse toEditable_Mesh
deleteVert p 13 --delete vertex 13 (the middle vertex)
update p --update the mesh

MeshVertex Normal

getNormal <mesh> <vert_index_integer>

Returns the normal at the indexed vertex's position as a point3. The normal is based on the faces that use the vertex and the smoothing groups assigned to those faces.

EXAMPLE

obj = geosphere() --create a GeoSphere
convertToMesh obj --collapse to Editable_Mesh
--Count backwards from the last vertex to the first.
--This is necessary because we intend to deletevertices
--and this will renumber the remaining ones. Counting backwards
--ensures the renumbering does not affect the loop:
for v = obj.numVerts to 1 by -1 do
(
--get the vertex normal and get the dot product with the +Z vector
--If the result is less than the specifiedthreshold,
--then delete the vertex the normal belongs to
if dot (getNormal obj v) [0,0,1] <= -0.25 do deleteVert obj v
)
update obj --update the mesh
 

setNormal <mesh> <vert_index_integer> <point3>

Sets the indexed vertex's normal vector.

Since 3ds Max 2015, setting a vertex normal sets the normal as Explicit, so it will retain its value when the mesh gets updated. In versions prior to 3ds Max 2015, setting the vertex normal using MAXScript had only a very short lasting effect because the data would be easily overwritten by the Smoothing Group-based implicit normal recalculation on viewport redraw or scene rendering.

MeshVertex Selection:

getVertSelection <node> [ <modifier_or_index> ] [ name:<name> ]
getVertSelection <mesh>

Returns the current vertex selection set, or the specified named selection set if the optional name: parameter is specified, as a BitArray. The optional <modifier_or_index> identifies the Edit Mesh, Mesh Select, or Poly Select modifier on the given scene object from which the selection BitArray is obtained.

FOR EXAMPLE

getVertSelection $foo $foo.modifiers[3]

If the optional <modifier_or_index> argument is not supplied, the <node> must be an Editable Mesh object and the selection is taken from the top of the modifier stack. If <modifier_or_index> is supplied, it must be either a modifier on the node or a number. If it is a modifier, it must be either an Edit Mesh or a Mesh Select modifier. If it is a number, it is used as an index into the Edit Mesh/Select Modifiers on the <node> starting from the top of the stack.

NOTE:

The index does not count any other types of modifier present! So, an index of 1 will always get the selection currently active at the top of the stack.

The function returns a BitArray with bits set for the 1-based indices of the currently selected vertices, or the vertices specified by the named selection set, in the object by the given modifier.

FOR EXAMPLE

getVertSelection $foo $foo.modifiers[3]

RETURNS

#{2..5,9,25..27}

This is a snapshot of the selection—the BitArray doesn't change automatically as you make different selections. Further, it reflects the current vertex selection whether or not the modifier is in vertex sub-object selection mode (this selection is remembered and re-established whenever you go back into vertex subobject mode). So, for example, if you select some vertices then click out of vertex subobject mode, the whole object rather than the selection is passed up the stack to the next modifier, but getVertSelection() returns the selected vertices at the time the subobject mode was exited.

You might use the modifiers modifier array accessing scheme here if you've got many edit mesh modifiers with non-unique names. You can also use a constructed string as an index into the modifiers array,

FOR EXAMPLE

$foo.modifiers["edit mesh"+ i as string]

assuming the variable 'i' had some indexing value and the names were set up thusly. '+' on strings concatenates.

To access the selection from the EditableMesh base object when there are modifiers present on the stack, you should access the TriMesh value of the base object,

FOR EXAMPLE

getVertSelection $foo.baseobject.mesh
setVertSelection <node> [<modifier_or_index>]( <sel_bitarray> | <sel_array> ) [name:<name>] [keep:<boolean>]
setVertSelection <mesh> ( <sel_bitarray> | <sel_array> )[keep:<boolean>]

Sets the vertex selections in an Editable Mesh base object, Mesh Select modifier, Edit Mesh Modifier, Poly Select Modifier, or TriMesh. This mirrors the selection getting method above.

The <modifier_or_index> argument is interpreted as for the get- form above, except that only the Mesh Select and Poly Select modifiers are supported for set operations.

FOR EXAMPLE

setVertSelection $foo #{1..4,100..102}
setFaceSelection $foo (getFaceSelection $baz) keep:true

If the optional name: argument is specified, the vertices in the specified named selection set in the Editable Mesh or Mesh Select modifier are selected. If the name: argument is not specified, the selection index argument gives the indexes of the sub-object items to be selected as either a BitArray or an array of integers. If the optional keep: keyword argument is false or not supplied, any current selection will be replaced by the new one. If the keep: keyword argument is true , the new selection is added to the current selection. The name: argument is not applicable to TriMeshes.

Use the mesh update() function after making a group of selection changes in order to make them visible to any modifiers on the object.

   

averageSelVertCenter <node>

Returns the average position (center) of the selected vertices in the given mesh as a Point3. If the object is not a mesh this method returns undefined. If no vertices are selected in the mesh, a value of [0,0,0] is returned. This method is not applicable to TriMeshes.

   

averageSelVertNormal <node>

Returns the normalized average of the normals of the selected vertices in the given mesh as a Point3. If the given node is not a mesh, it returns undefined. If no vertices are selected in the mesh, or the averaged normal is [0,0,0], a value of [1,0,0] is returned. This method is not applicable to TriMeshes.

The vertex normals used in this method do not consider smoothing group data of the faces that use the vertex.

   

For more mesh-related methods, see

Editable Mesh - Topics Index

Editable_Mesh : GeometryClass and TriMesh : Value

See Also