Class Mesh

The Mesh Data object

This object gives access to mesh data in Blender.

Note:
the verts, edges and faces attributes are implemented as sequences.
The operator[] and len() are defined for these sequences. You
cannot assign to an item in the sequence, but you can assign to
most of the attributes of individual items.

vertexShade(object)
Colors vertices based on the current lighting setup, like when there
are no vertex colors and no textured faces and a user enters Vertex
Paint Mode in Blender (only lamps in visible layers account).

getFromObject(object,
cage=0,
render=0)

Replace the mesh's existing data with the raw mesh data from a Blender
Object. This method supports all the geometry based objects (mesh, text,
curve, surface, and meta). If the object has modifiers, they will be
applied before to the object before extracting the vertex data unless the
cage parameter is 1.

Parameters:

object (blender object or string) - The Blender object or its name, which contains the geometry data.

render (int) - determines whether the render setting for modifiers will be used
or not. (for objects with modifiers) are used. The default is
derived vertices.

Notes:

The mesh coordinates are in local space, not the world space
of its object. For world space vertex coordinates, each vertex
location must be multiplied by the object's 4x4 transform matrix
(see transform).

The objects materials will not be copied into the existing mesh,
however the face material indices will match the material list of
the original data.

pointInside(point,
selected_only=False)

Parameters:

point (vector) - Test if this point is inside the mesh

selected_only (bool) - if True or 1, only the selected faces are taken into account.
Returns true if vector is inside the mesh.

Notes:

Only returns a valid result for mesh data that has no holes.

Bubbles in the mesh work as expect.

getTangents()

Calculates tangents for this mesh, returning a list of tuples, each
with 3 or 4 tangent vectors, these are alligned with the meshes
faces.

Note:
The tangents are computed using the active UV layer, if there are
no UV layers, orco coords are used.

transform(matrix,
recalc_normals=False,
selected_only=False)

Transforms the mesh by the specified 4x4 matrix (such as returned by
Object.Object.getMatrix). The matrix should be
invertible. Ideal usage for this is exporting to an external file where
global vertex locations are required for each object. Sometimes external
renderers or file formats do not use vertex normals. In this case, you
can skip transforming the vertex normals by leaving the optional
parameter recalc_normals as False or 0 (the default value).

selected_only (bool) - if True or 1, only the selected verts will be transformed.

Warning:
unlike NMesh.transform(), this method will immediately
modify the mesh data when it is used. If you transform the
mesh using the object's matrix to get the vertices' world
positions, the result will be a "double transform". To
avoid this you either need to set the object's matrix to the
identity matrix, perform the inverse transform after outputting the
transformed vertices, or make a copy of the vertices prior to using
this method and restore them after outputting the transformed
vertices (as shown in the example).

vertexShade(object)

Colors vertices based on the current lighting setup, like when there
are no vertex colors and no textured faces and a user enters Vertex Paint
Mode in Blender (only lamps in visible layers account). An exception is
thrown if called while in EditMode.

Parameters:

object (Object) - The Blender Object linked to the mesh.

update(key=None)

Update display lists after changes to mesh. Note: with changes
taking place for using a directed acyclic graph (DAG) for scene and
object updating, this method may be only temporary and may be removed in
future releases.

Warning:
Since Blender 2.42 this function has changed; now it won't
recalculate vertex normals (seen when faces are smooth). See Mesh.calcNormals().

findEdges(edges)

Quickly search for the location of an edges.

Parameters:

edges (sequence(s) of ints or MVerts) - can be tuples of MVerts or integer indexes (note: will not
work with PVerts) or a sequence (list or tuple) containing two or
more sequences.

Returns: int, None or list

if an edge is found, its index is returned; otherwise None is
returned. If a sequence of edges is passed, a list is returned.

addVertGroup(group)

Add a named and empty vertex (deform) group to the object this mesh is
linked to. The mesh must first be linked to an object (with
object.link() or object.getData() ) so the method knows which object to
update. This is because vertex groups in Blender are stored in the
object -- not in the mesh, which may be linked to more than one
object.

Parameters:

group (string) - the name for the new group.

removeVertGroup(group)

Remove a named vertex (deform) group from the object linked to this
mesh. All vertices assigned to the group will be removed (just from the
group, not deleted from the mesh), if any. If this mesh was newly
created, it must first be linked to an object (read the comment in addVertGroup
for more info).

Parameters:

group (string) - the name of a vertex group.

assignVertsToGroup(group,
vertList,
weight,
assignmode)

Adds an array (a Python list) of vertex points to a named vertex group
associated with a mesh. The vertex list is a list of vertex indices from
the mesh. You should assign vertex points to groups only when the mesh
has all its vertex points added to it and is already linked to an
object.

Example: The example here adds a new set of vertex
indices to a sphere primitive:

weight (float) - the deform weight for (which means: the amount of influence the
group has over) the given vertices. It should be in the range
[0.0, 1.0]. If weight <= 0, the given vertices are removed
from the group. If weight > 1, it is clamped.

assignmode (module constant) - Three choices: REPLACE, ADD or SUBTRACT. See AssignModes
for a complete description.

removeVertsFromGroup(group,
vertList=None)

Remove a list of vertices from the given group. If this mesh was
newly created, it must first be linked to an object (check addVertGroup).

Parameters:

group (string) - the name of a vertex group

vertList (list of ints) - a list of vertex indices to be removed from group. If
None, all vertices are removed -- the group is emptied.

getVertsFromGroup(group,
weightsFlag=0,
vertList=None)

Return a list of vertex indices associated with the passed group. This
method can be used to test whether a vertex index is part of a group and
if so, what its weight is.

weightsFlag (bool) - if 1, each item in the list returned contains a tuple pair
(index, weight), the weight is a float between 0.0 and 1.0.

vertList (list of ints) - if given, only those vertex points that are both in the list and
group passed in are returned.

renameVertGroup(groupName,
newName)

Renames a vertex group.

Parameters:

groupName (string) - the vertex group name to be renamed.

newName (string) - the name to replace the old name.

getVertGroupNames()

Return a list of all vertex group names.

Returns: list of strings

returns a list of strings representing all vertex group
associated with the mesh's object

getUVLayerNames()

Return a list of all UV layer names

Returns: list of strings

returns a list of strings representing all UV layers associated
with the mesh's object

getColorLayerNames()

Return a list of all color layer names

Returns: list of strings

returns a list of strings representing all color layers
associated with the mesh's object

getVertexInfluences(index)

Get the bone influences for a specific vertex.

Parameters:

index (int) - The index of a vertex.

Returns: list of lists

List of pairs [name, weight], where name is the bone name
(string) and weight is a float value.

removeAllKeys()

Remove all mesh keys stored in this mesh.

Returns: bool

True if successful or False if the Mesh has no keys.

insertKey(frame=None,
type='relative')

Insert a mesh key at the given frame.

Parameters:

frame (int) - The Scene frame where the mesh key should be inserted. If None
or the arg is not given, the current frame is used.

type (string) - The mesh key type: 'relative' or 'absolute'. This is only
relevant on meshes with no keys.

Warnings:

This and removeAllKeys were included in this release only
to make accessing vertex keys possible, but may not be a proper
solution and may be substituted by something better later. For
example, it seems that 'frame' should be kept in the range [1, 100]
(the curves can be manually tweaked in the Ipo Curve Editor window
in Blender itself later).

renameColorLayer(name,
newname)

newname (string) - The new name of the Color layer, will be made unique.

smooth()

Flattens angle of selected faces. Experimental mesh tool. An exception
is thrown if called while in EditMode.

flipNormals()

Toggles the direction of selected face's normals. Experimental mesh
tool. An exception is thrown if called while in EditMode.

toSphere()

Moves selected vertices outward in a spherical shape. Experimental
mesh tool. An exception is thrown if called while in EditMode.

fill()

Scan fill a closed selected edge loop. Experimental mesh tool. An
exception is thrown if called while in EditMode.

triangleToQuad()

Convert selected triangles to quads. Experimental mesh tool. An
exception is thrown if called while in EditMode.

quadToTriangle(mode=0)

Convert selected quads to triangles. Experimental mesh tool. An
exception is thrown if called while in EditMode.

Parameters:

mode (int) - specifies whether a to add the new edge between the closest (=0)
or farthest(=1) vertices.

subdivide(beauty=0)

Subdivide selected edges in a mesh. Experimental mesh tool. An
exception is thrown if called while in EditMode.

Parameters:

beauty (int) - specifies whether a "beauty" subdivide should be
enabled (disabled is default). Value must be in the range [0,1].

remDoubles(limit)

Removes duplicates from selected vertices. Experimental mesh tool. An
exception is thrown if called while in EditMode.

Parameters:

limit (float) - specifies the maximum distance considered for vertices to be
"doubles". Value is clamped to the range [0.0,1.0].

Returns: int

the number of vertices deleted

recalcNormals(direction=0)

Recalculates inside or outside normals for selected faces.
Experimental mesh tool. An exception is thrown if called while in
EditMode.

Parameters:

direction (int) - specifies outward (0) or inward (1) normals. Outward is the
default. Value must be in the range [0,1].

__copy__()

Make a copy of this mesh

Returns: Mesh

a copy of this mesh

Instance Variable Details

activeColorLayer

The mesh's active Vertex Color layer. None if there is no UV/Image
layers.

Note: After setting this value, call update so the result
can be seen the the 3d view.

Type:

string

activeFace

Index of the mesh's active face in UV Face Select and Paint modes. Only
one face can be active at a time. Note that this is independent of the
selected faces in Face Select and Edit modes. Will throw an exception if
the mesh does not have UV faces; use faceUV to test.

Type:

int

activeGroup

The mesh's active vertex group. The mesh must be linked to an object
(read the comment in addVertGroup for more info).

Type:

string or None

activeUVLayer

The mesh's active UV/Image layer. None if there is no UV/Image layers.

Note: After setting this value, call update so the result
can be seen the the 3d view.

Type:

string

fakeUser

When set to True, this datablock wont be removed, even if nothing is
using it. All data has this disabled by default except for Actions.

Type:

bool

lib

path to the blend file this datablock is stored in (readonly).

lib will be None unless you are using external blend files with (File,
Append/Link)

materials

The mesh's materials. Each mesh can reference up to 16 materials. Empty
slots in the mesh's list are represented by None. Note: Object.colbits
needs to be set correctly for each object in order for these materials to
be used instead of the object's materials. Note: Making the
material list shorter does not change the face's material indices. Take
care when using the face's material indices to reference a material in
this list. Note: The list that's returned is not linked to
the original mesh. mesh.materials.append(material) won't do anything. Use
mesh.materials += [material] instead.