Module Mesh
[hide private]
[frames] | no frames]

Module Mesh

source code

The Blender.Mesh submodule.

New:

Mesh Data

This module provides access to Mesh Data objects in Blender. It differs from the NMesh module by allowing direct access to the actual Blender data, so that changes are done immediately without need to update or put the data back into the original mesh. The result is faster operations with less memory usage. The example below creates a simple pyramid, and sets some of the face's attributes (the vertex color):

Example:

       from Blender import *
       import bpy

       editmode = Window.EditMode()    # are we in edit mode?  If so ...
       if editmode: Window.EditMode(0) # leave edit mode before getting the mesh

       # define vertices and faces for a pyramid
       coords=[ [-1,-1,-1], [1,-1,-1], [1,1,-1], [-1,1,-1], [0,0,1] ]  
       faces= [ [3,2,1,0], [0,1,4], [1,2,4], [2,3,4], [3,0,4] ]

       me = bpy.data.meshes.new('myMesh')          # create a new mesh

       me.verts.extend(coords)          # add vertices to mesh
       me.faces.extend(faces)           # add faces to the mesh (also adds edges)

       me.vertexColors = 1              # enable vertex colors 
       me.faces[1].col[0].r = 255       # make each vertex a different color
       me.faces[1].col[1].g = 255
       me.faces[1].col[2].b = 255

       scn = bpy.data.scenes.active     # link object to current scene
       ob = scn.objects.new(me, 'myObj')

       if editmode: Window.EditMode(1)  # optional, just being nice

Vertices, edges and faces are added to a mesh using the .extend() methods. For best speed and efficiency, gather all vertices, edges or faces into a list and call .extend() once as in the above example. Similarly, deleting from the mesh is done with the .delete() methods and are most efficient when done once.

Classes [hide private]
  MCol
This object is four ints representing an RGBA color.
  MVert
This object holds mesh vertex data.
  MVertSeq
This object provides sequence and iterator access to the mesh's vertices.
  MEdge
This object holds mesh edge data.
  MEdgeSeq
This object provides sequence and iterator access to the mesh's edges.
  MFace
This object holds mesh face data.
  MFaceSeq
This object provides sequence and iterator access to the mesh's faces.
  Mesh
This object gives access to mesh data in Blender.
Functions [hide private]
Mesh
Get(name=None)
Get the mesh data object called name from Blender.
source code
Mesh
New(name='Mesh')
Create a new mesh data object called name.
source code
int
Mode(mode=0)
Get and/or set the selection modes for mesh editing.
source code
None
Unlink(name)
Delete an unused mesh from Blender's database.
source code
Variables [hide private]
readonly dictionary. AssignModes = {'REPLACE': 1}
The available vertex group assignment modes, used by mesh.assignVertsToGroup().
  EdgeFlags
The available edge flags.
readonly dictionary FaceFlags
The available *texture face* (uv face select mode) selection flags.
readonly dictionary FaceModes
The available *texture face* modes.
readonly dictionary FaceTranspModes
The available face transparency modes.
readonly dictionary Modes
The available mesh modes.
readonly dictionary. SelectModes
The available edit select modes.
  __package__ = None
Function Details [hide private]

Get(name=None)

source code 

Get the mesh data object called name from Blender.

Parameters:
  • name (string) - The name of the mesh data object.
Returns: Mesh
If a name is given, it returns either the requested mesh or None. If no parameter is given, it returns all the meshes in the current scene.

New(name='Mesh')

source code 

Create a new mesh data object called name.

Parameters:
  • name (string) - The name of the mesh data object.
Returns: Mesh
a new Blender mesh.

Note: if the mesh is not linked to an object, its datablock will be deleted when the object is deallocated.

Mode(mode=0)

source code 

Get and/or set the selection modes for mesh editing. These are the modes visible in the 3D window when a mesh is in Edit Mode.

Parameters:
  • mode (int) - The desired selection mode. See SelectModes for values. Modes can be combined. If omitted, the selection mode is not changed.
Returns: int
the current selection mode.

Note: The selection mode is an attribute of the current scene. If the scene is changed, the selection mode may not be the same.

Unlink(name)

source code 

Delete an unused mesh from Blender's database. The mesh must not have any users (i.e., it must not be linked to any object).

Parameters:
  • name (string) - The name of the mesh data object.
Returns: None

Note: This function may be a temporary solution; it may be replaced in the future by a more general unlink function for many datablock types. Hopefully this will be decided prior to the 2.42 release of Blender.


Variables Details [hide private]

AssignModes

The available vertex group assignment modes, used by mesh.assignVertsToGroup().
  • ADD: if the vertex in the list is not assigned to the group already, this creates a new association between this vertex and the group with the weight specified, otherwise the weight given is added to the current weight of an existing association between the vertex and group.
  • SUBTRACT: will attempt to subtract the weight passed from a vertex already associated with a group, else it does nothing.
  • REPLACE: attempts to replace a weight with the new weight value for an already associated vertex/group, else it does nothing.
Type:
readonly dictionary.
Value:
{'REPLACE': 1}

EdgeFlags

The available edge flags.
  • SELECT - selected (deprecated). Use edge.sel attribute instead.
  • EDGEDRAW - edge is drawn out of edition mode.
  • EDGERENDER - edge is drawn out of edition mode.
  • SEAM - edge is a seam for UV unwrapping
  • FGON - edge is part of a F-Gon.
  • LOOSE - Edge is not a part of a face (only set on leaving editmode)
  • SHARP - Edge will be rendered sharp when used with the "Edge Split" modifier.

FaceFlags

The available *texture face* (uv face select mode) selection flags. Note: these refer to TexFace faces, available if mesh.faceUV returns true.
  • SELECT - selected (deprecated in versions after 2.43, use face.sel).
  • HIDE - hidden (deprecated in versions after 2.43, use face.hide).
  • ACTIVE - the active face, read only - Use mesh.activeFace to set.
Type:
readonly dictionary

FaceModes

The available *texture face* modes. Note: these are only meaningful if mesh.faceUV returns true, since in Blender this info is stored at the TexFace (TexFace button in Edit Mesh buttons) structure.
  • ALL - set all modes at once.
  • BILLBOARD - always orient after camera.
  • HALO - halo face, always point to camera.
  • DYNAMIC - respond to collisions.
  • ALPHASORT - game engine sorts these faces only.
  • INVISIBLE - invisible face.
  • LIGHT - dynamic lighting.
  • OBCOL - use object color instead of vertex colors.
  • SHADOW - shadow type.
  • SHAREDVERT - apparently unused in Blender.
  • SHAREDCOL - shared vertex colors (per vertex).
  • TEX - has texture image.
  • TILES - uses tiled image.
  • TWOSIDE - two-sided face.
Type:
readonly dictionary

FaceTranspModes

The available face transparency modes. Note: these are enumerated values (enums), they can't be combined (ANDed, ORed, etc) like a bit vector.
  • SOLID - draw solid.
  • ADD - add to background (halo).
  • ALPHA - draw with transparency.
  • SUB - subtract from background.
Type:
readonly dictionary

Modes

The available mesh modes.
  • NOVNORMALSFLIP - no flipping of vertex normals during render.
  • TWOSIDED - double sided mesh.
  • AUTOSMOOTH - turn auto smoothing of faces "on".
  • note: SUBSURF and OPTIMAL have been removed, use Modifiers to apply subsurf.
Type:
readonly dictionary

SelectModes

The available edit select modes.
  • VERTEX: vertex select mode.
  • EDGE: edge select mode.
  • FACE: face select mode.
Type:
readonly dictionary.