Mesh Methods

The following methods provide advanced access to the Mesh, affecting multiple faces at a time.

Methods:

Create Polygon

meshop.createPolygon <Mesh mesh> <vertIndex array> smGroup:<int=0> matID:<int=1>

Creates a set of faces using the specified vertices. The order of the vertices in the faces is the order in the vertex array. The polygon may be nonconvex, but should be (roughly) coplanar.

smGroup: and matID: specify the smoothing group data and material ID number assigned to the new faces.

Note: It is possible to build a mesh polygon by polygon using multiple meshop.createPolygon calls. In such case, an undo record containing a copy of the complete mesh would be created internally for every single polygon created which in turn can lead to problems. To avoid this, it is advisable to enclose the polygon creating code in an undo off context. If the undo of the object creation itself is necessary, the undo can be enabled in an additional context.

FOR EXAMPLE

vertArray = #();
vertArray.count=5800
for i = 1 to 5800 do
vertArray[i]=random [-100,-100,-100] [100,100,100]
faceArray=#()
faceArray.count=11300
for i = 1 to 11300 do
faceArray[i]=random [1,1,1] [5800,5800,5800]
undo on -- Turn ON Undo for mesh object creation
(
mm = mesh numverts:5800 numfaces:11300
undo off -- Turn OFF Undo for polygon creation
(
for i = 1 to 5800 do
meshop.setvert mm i vertArray[i]
for i = 1 to 11299 do
meshop.createPolygon mm #(faceArray[i].x,faceArray[i].y,faceArray[i].z)
) --End Undo OFF for polygon creation
meshop.createPolygon mm #(faceArray[11300].x,faceArray[11300].y,faceArray[11300].z)
update mm
) -- End Undo ON for mesh object creation

Cut And Slice Mesh

meshop.cut <Mesh mesh> <int edge1Index> <float edge1f> <int edge2Index> <float edge2f> <point3 normal> fixNeighbors:<boolean=true> split:<boolean=true> node:<node=unsupplied>

Cuts the mesh from a point on one edge to a point on another, along a line drawn by looking at the mesh from a particular viewpoint.

<edge1Index> specifies the edge that the cut starts on.

<edge1f> specifies the fractional distance along the edge to start the cut from.

<edge2Index> specifies the edge that the cut ends on.

<edge2f> specifies the fractional distance along the edge to finish the cut on.

<normal> specifies the direction of view. The cut will take place on this "side" of the mesh, in the plane formed by this vector and the direction from the start to the end.

If fixNeighbors: is true , the faces on the other side of each end of the cut should be split to prevent splits at the ends. If split: is true , the cut will split the mesh apart. If false , the cut will just refine the mesh by adding geometry. If <mesh> is a node, or if <mesh> is an Editable Mesh or a Mesh value and node: is specified, the normal is in the current coordinate system context. If <mesh> is an Editable Mesh or a Mesh value and node: is not specified, the normal is in the mesh's local coordinate system.

meshop.slice <Mesh mesh> <facelist> <point3 normal> <float offset> separate:<boolean=false> delete:<boolean=false> node:<node=unsupplied>

Slices the mesh along the specified slicing plane. The slicing plane is defined as all points which, when DotProd'd with <normal>, return <offset>. <normal> should be normalized.

separate: specifies whether the slice should separate the mesh into two separate elements ( true ) or just refine the existing mesh by splitting faces ( false ).

delete: specifies whether the slice should remove the portion of the mesh "below" the slicing plane, where "below" is defined as the area where DotProd (p, ) - < 0. If delete: is true , separate: is ignored. If <mesh> is a node, or if <mesh> is an Editable Mesh or a Mesh value and <node> is specified, the normal is in the current coordinate system context. If <mesh> is an Editable Mesh or a Mesh value and node: is not specified, the normal is in the mesh's local coordinate system.

Get Polygons Using Vertex

meshop.getPolysUsingVert <Mesh mesh> <vertlist> ignoreVisEdges:<boolean=false> threshhold:<float=45.>

Returns a bitarray of size=(#faces in mesh) with bits set for all faces that are in 'polygons' containing the specified vertices. The definition of a polygon is all faces sharing invisible edges with edge angles below the threshold angle. The default threshold angle is 45 degrees. If ignoreVisEdges is set to true, the edge visibility is ignored but the threshold is still relevant.

Note:

the threshhold parameter is spelled incorrectly.

Optimize Mesh

meshop.optimize <Mesh mesh> <float normalThreshold> <float edgeThreshold> <float bias> <float maxEdge> saveMatBoundries:<boolean=true> saveSmoothBoundries:<boolean=true> autoEdge:<boolean=true>

Reduces the mesh in complexity by reducing the number of faces based on a surface normal threshold. Adjacent faces whose difference in surface normal angle falls below <normalThreshold> will be collapsed into a single triangle. If autoEdge: is true, when the angle between adjacent surface normals is less than <edgeThreshold> the edge will be invisible. When optimizing mesh objects, as the optimization increases, you can get lots of long skinny 'degenerate' triangles (that cause rendering artifacts). Increasing <bias> keeps triangles from becoming degenerate. The range of values is from 0 to 1 (where 0 turns bias off). Values close to 1 reduce the amount of optimization in favor of maintaining equilateral triangles. A <maxEdge> value > 0 will prevent the optimize function from creating edges longer than this value. If this parameter is <=0 no limit is placed on the length of the edges. If saveMatBoundries: is true, faces won't be collapsed across a material boundary. If saveSmoothBoundries: is true, faces won't be collapsed across a dissimilar smoothing group boundary.

Copy and Delete TriMesh

copy <trimesh>

Yields a copy of the source TriMesh.

delete <trimesh>

Clears out the TriMesh's geometry and topology, effectively freeing its memory.

Animate Vertices

animateVertex <mesh> <vertex_spec>

Applies controllers to the specified vertices of the Editable_Mesh, where <vertex_spec> is one of:

<integer_index>
<integer_index_array>
#all

By assigning controllers to the vertices, the vertices are added to the Driver subAnim and appear as animatables in the Track View, allowing further scripting of the vertices.

FOR EXAMPLE,

animateVertex $Sphere01 #all

The vertices to be animated are specified by index number or with the keyword #all to animate all vertices.

See also Class and Object Inspector Functions and Scripting Vertex and Control Point Animation for details on accessing the Editable_Mesh vertices. The controller values assigned to the vertices is in object space. See Using Node Transform Properties for information on converting between world space to object space.

Note: The above method is not applicable to TriMeshes!

SetMesh Methods

The setMesh() method enables bulk changes to a mesh via arrays of vertices, faces, tverts, etc. setMesh() has the following forms:

setMesh <mesh> [ numverts:<integer> ] [ numfaces:<integer> ]

Resets the mesh to the given geometry but with no topology (i.e., no faces or edges). Any current mesh data is lost. You have to individually place the vertices and create the faces from the vertices. The default number of vertices and faces are 36 and 50, respectively.

setMesh <mesh> [ vertices:<array_of_point3s> ] [ faces:<array_of_point3s> ] [ materialIDs:<array_of_integers> ] [ tverts:<array_of_point3s> ]

Resets the mesh based on the given arrays. Only those portions of the mesh that are specified are reset. For example, if only the vertices: parameter is specified, the existing face data is retained. Each Point3 value in the vertices array specifies the position of the vertex in the current coordinate system. Each Point3 value in the faces array specifies the 3 vertex indices that form the face. The materialIDs array specifies the material ID to be assigned to each face. Each Point3 value in the tverts array specifies the UVW coordinates of the texture vertices. See Texture Mapping in the methods section for more information on texture vertices.

setMesh <mesh> [ length:<integer> ] [ width:<integer> ] [ lengthsegs:<integer> ] [ widthhsegs:<integer> ]

Resets the mesh with a flat rectangular mesh with the given size and number of segments. The default length and width are 50, the default number of segments is 5.

setMesh <mesh> <trimesh>

Sets the mesh to a copy of the source TriMesh.

For more mesh-related methods, see

Editable_Mesh : GeometryClass and TriMesh : Value