[Bf-python] Mesh Module

Ken Hughes khughes at pacific.edu
Thu Oct 6 18:28:23 CEST 2005


Willian Padovani Germano wrote:
> This is where the pure Python types could come in. Example for verts:
> 
> Add to Mesh a PyVert type, similar to NMVert.
> 
> Add function to create it: Mesh.Vert(arg), where arg could be a list of 
> coordinates or a vector.
> 
> Then assignment can be made with these pyverts:
> 
> newvert = Mesh.Vert([x,y,z])
> mesh.verts[n] = newvert

OK, have something ready to commit for this, but wanted feedback before 
that in case someone has better ideas:

Mesh.MVert() creates a "thick" (not wrapped) MVert object, same type as 
returned from mesh.verts[].  Arguments to Mesh.MVert() are a 3d vector 
(from Mathutils.vector) or three floats.

Also three new sequence operators:
(1) assign item: allows you to use "mesh.vert[0] = v", where v is an 
MVert object (thin or thick).  Copies all the Blender MVert data to an 
existing mesh vertex.
(2) slice: returns a list of thick MVerts, created from the mesh's 
existing vertices.  Copies all the Blender MVert data from an existing 
set of Blender MVerts; index attribute of each MVert is set to -1 
(indicating a thick object).  Use: "l = mesh.verts[2:4]"
(3) assign slice: like assign item, except assigns a list of thick or 
thin MVerts to the mesh's existing vertex list.  Conditions are the 
slice indices must map into the existing vertex list and the size of the 
slice must be equal to the size of the list (you cannot use slice 
assignment to add or delete vertices from the mesh's vertex list). 
Also, no checking is done to assure that thin MVerts in the input list 
are not also in the assignment range: so users must be sure they do not 
overwrite the data being copies (this is similar to the use oe memcpy())

As an aside, I also added support for meshs with keys.  Using 
mesh.verts.extend() to add vertices to a mesh will also extend all 
existing keys to include new vertices appended to the vertex list. 
Seems to work as far as I can tell; would be nice if someone has some 
example .blends using meshs with vertex keys that they've be willing to 
send, or would be willing to try a patch before I commit.

Ken



More information about the Bf-python mailing list