Module Mesh
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 *
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 = Mesh.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
ob = Object.New('Mesh','myObj') # link mesh to an object
ob.link(me)
sc = Scene.GetCurrent() # link object to current scene
sc.link(ob)
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 |
MCol |
This object is four ints representing an RGBA color. |
MEdge |
This object holds mesh edge data. |
MEdgeSeq |
This object provides sequence and iterator access to the mesh's
edges. |
Mesh |
This object gives access to mesh data in Blender. |
MFace |
This object holds mesh face data. |
MFaceSeq |
This object provides sequence and iterator access to the mesh's
faces. |
MVert |
This object holds mesh vertex data. |
MVertSeq |
This object provides sequence and iterator access to the mesh's
vertices. |
Function Summary |
Mesh
|
Get (name)
Get the mesh data object called name from Blender. |
int
|
Mode (mode)
Get and/or set the selection modes for mesh editing. |
Mesh
|
New (name)
Create a new mesh data object called name. |
None
|
Unlink (name)
Delete an unused mesh from Blender's database. |
Variable Summary |
readonly dictionary. |
AssignModes : 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. |
Get(name=None)
Get the mesh data object called name from Blender.
-
- Parameters:
name -
The name of the mesh data object.
(type=string)
- Returns:
-
If a name is given, it returns either the requested mesh or
None. If no parameter is given, it returns all the meshs in the
current scene.
(type=Mesh)
|
Mode(mode=0)
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 -
The desired selection mode. See SelectModes for values. Modes can
be combined. If omitted, the selection mode is not changed.
(type=int)
- Returns:
-
the current selection mode.
(type=int)
Note: The selection mode is an attribute of the current scene. If the scene
is changed, the selection mode may not be the same.
|
New(name='Mesh')
Create a new mesh data object called name.
-
- Parameters:
name -
The name of the mesh data object.
(type=string)
- Returns:
-
a new Blender mesh.
(type=Mesh)
Note: if the mesh is not linked to an object, its datablock will be deleted
when the object is deallocated.
|
Unlink(name)
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 -
The name of the mesh data object.
(type=string)
- 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.
|
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:
|
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)
|
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.
-
HIDE - hidden.
-
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.
-
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 (and'ed, or'ed, 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.
|