Module NMesh

Module NMesh

source code

The Blender.NMesh submodule.

Deprecated: This module is now maintained but not actively developed.

Access to data such as properties, library, UVLayers and ColorLayers is not available further more, a mesh modified with NMesh will destroy inactive UV and Color layers so writing tools that use NMesh is discouraged.

Use Mesh instead.

Mesh Data

This module provides access to Mesh Data objects in Blender.

Example:
 import Blender
 from Blender import NMesh, Material, Window

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

 me = NMesh.GetRaw("Plane")       # get the mesh data called "Plane"

 if not me.materials:             # if there are no materials ...
   newmat = Material.New()        # create one ...
   me.materials.append(newmat)    # and append it to the mesh's list of mats

 print me.materials               # print the list of materials
 mat = me.materials[0]            # grab the first material in the list
 mat.R = 1.0                      # redefine its red component
 for v in me.verts:               # loop the list of vertices
   v.co[0] *= 2.5                 # multiply the coordinates
   v.co[1] *= 5.0
   v.co[2] *= 2.5
 me.update()                      # update the real mesh in Blender

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


Classes
  NMCol
This object is a list of ints: [r, g, b, a] representing an rgba color.
  NMVert
This object holds mesh vertex data.
  NMEdge
This object holds mesh edge data.
  NMFace
This object holds mesh face data.
  NMesh
This object gives access to mesh data in Blender.
Functions
NMCol
Col(col=[255, 255, 255, 255])
Get a new mesh rgba color.
source code
NMVert
Vert(x=0, y=0, z=0)
Get a new vertex object.
source code
NMFace
Face(vertexList=None)
Get a new face object.
source code
 
New(name='Mesh')
Create a new mesh object.
source code
NMesh
GetRaw(name=None)
Get the mesh data object called name from Blender.
source code
list of strings
GetNames()
Get a list with the names of all available meshes in Blender.
source code
NMesh
GetRawFromObject(name)
Get the raw mesh data object from the Object in Blender called name.
source code
None or Object
PutRaw(nmesh, name=None, recalc_normals=1, store_edges=0)
Put a BPython NMesh object as a mesh data object in Blender.
source code
Variables
  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.
Function Details

Col(col=[255, 255, 255, 255])

source code 
Get a new mesh rgba color.
Parameters:
  • col (list) - A list [red, green, blue, alpha] of integer values in [0, 255].
Returns: NMCol
A new NMCol (mesh rgba color) object.

Vert(x=0, y=0, z=0)

source code 
Get a new vertex object.
Parameters:
  • x (float) - The x coordinate of the vertex.
  • y (float) - The y coordinate of the vertex.
  • z (float) - The z coordinate of the vertex.
Returns: NMVert
A new NMVert object.

Face(vertexList=None)

source code 
Get a new face object.
Parameters:
  • vertexList (list) - A list of up to 4 NMVerts (mesh vertex objects).
Returns: NMFace
A new NMFace object.

New(name='Mesh')

source code 
Create a new mesh object.
Parameters:
  • name (string) - An optional name for the created mesh. rtype: NMesh
Returns:
A new (empty) NMesh object.

GetRaw(name=None)

source code 
Get the mesh data object called name from Blender.
Parameters:
  • name (string) - The name of the mesh data object.
Returns: NMesh
It depends on the 'name' parameter:
  • (name) - The NMesh wrapper of the mesh called name, None if not found.
  • () - A new (empty) NMesh object.

GetNames()

source code 
Get a list with the names of all available meshes in Blender.
Returns: list of strings
a list of mesh names.

Note: to get actual mesh data, pass a mesh name to GetRaw.

GetRawFromObject(name)

source code 

Get the raw mesh data object from the Object in Blender called name.

Note: 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 matrix. This function support all the geometry based objects: Mesh, Text, Surface, Curve, Meta.
Parameters:
  • name (string) - The name of an Object.
Returns: NMesh
The NMesh wrapper of the mesh data from the Object called name.
Notes:
  • For "subsurfed" meshes, it's the display level of subdivision that matters, the rendering one is only processed at the rendering pre-stage and is not available for scripts. This is not a problem at all, since you can get and set the subdivision levels via scripting, too (see NMesh.NMesh.getSubDivLevels, NMesh.NMesh.setSubDivLevels).
  • Meshes extracted from curve based objects (Font/2D filled curves) contain both the filled surfaces and the outlines of the shapes.
Warnings:
  • This function gets deformed mesh data, already modified for displaying (think "display list"). It also doesn't let you overwrite the original mesh in Blender, so if you try to update it, a new mesh will be created.
  • For Meta Object's, this function will only return a NMesh with some geometry when called on the base element (the one with the shortest name).

PutRaw(nmesh, name=None, recalc_normals=1, store_edges=0)

source code 
Put a BPython NMesh object as a mesh data object in Blender.
Parameters:
  • name (string) - The name of the mesh data object in Blender which will receive this nmesh data. It can be an existing mesh data object or a new one.
  • recalc_normals (int) - If non-zero, the vertex normals for the mesh will be recalculated.
  • store_edges (int) - deprecated, edges are always stored now.
Returns: None or Object
It depends on the 'name' parameter:
  • name refers to an existing mesh data obj already linked to an object: return None.
  • name refers to a new mesh data obj or an unlinked (no users) one: return the created Blender Object wrapper.

Note: if there is already a mesh with the given 'name', its contents are freed and the new data is put in it. Also, if this mesh is not linked to any object, a new object for it is created. Reminder: in Blender an object is composed of the base object and linked object data (mesh, metaball, camera, etc. etc).


Variables Details

EdgeFlags

The available edge flags.
  • SELECT - selected.
  • EDGEDRAW - edge is drawn out of edition mode.
  • SEAM - edge is a seam for UV unwrapping
  • FGON - edge is part of a F-Gon.

FaceFlags

The available *texture face* (uv face select mode) selection flags. Note: these refer to TexFace faces, available if nmesh.hasFaceUV() returns true.
  • SELECT - selected (deprecated after 2.43 release, use face.sel).
  • HIDE - hidden (deprecated after 2.43 release, use face.sel).
  • ACTIVE - the active face.
Type:
readonly dictionary

FaceModes

The available *texture face* modes. Note: these are only meaningful if nmesh.hasFaceUV() 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 (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".
Type:
readonly dictionary