Module NMesh
[frames | no frames]

Module NMesh

The Blender.NMesh submodule.

New: NMesh.NMesh.addEdgesData, etc.);

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.
NMEdge This object holds mesh edge data.
NMesh This object gives access to mesh data in Blender.
NMFace This object holds mesh face data.
NMVert This object holds mesh vertex data.

Function Summary
NMCol Col(col)
Get a new mesh rgba color.
NMFace Face(vertexList)
Get a new face object.
list of strings GetNames()
Get a list with the names of all available meshes in Blender.
NMesh GetRaw(name)
Get the mesh data object called name from Blender.
NMesh GetRawFromObject(name)
Get the raw mesh data object from the Object in Blender called name.
  New(name)
Create a new mesh object.
None or Object PutRaw(nmesh, name, recalc_normals, store_edges)
Put a BPython NMesh object as a mesh data object in Blender.
NMVert Vert(x, y, z)
Get a new vertex object.

Variable Summary
  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])

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

Face(vertexList=None)

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

GetNames()

Get a list with the names of all available meshes in Blender.
Returns:
a list of mesh names.
           (type=list of strings)

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

GetRaw(name=None)

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

           (type=NMesh)

GetRawFromObject(name)

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 - The name of an Object.
           (type=string)
Returns:
The NMesh wrapper of the mesh data from the Object called name.
           (type=NMesh)

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).

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.

New(name='Mesh')

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

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

Put a BPython NMesh object as a mesh data object in Blender.
Parameters:
nmesh
           (type=NMesh)
name - 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.
           (type=string)
recalc_normals - If non-zero, the vertex normals for the mesh will be recalculated.
           (type=int)
store_edges - deprecated, edges are always stored now.
           (type=int)
Returns:
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.

           (type=None or Object)

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).

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

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

Variable 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.
  • HIDE - hidden.
  • 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 (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".
Type:
readonly dictionary

Generated by Epydoc 2.1 on Thu Jul 13 16:50:05 2006 http://epydoc.sf.net