[Bf-python] Thinmesh module

Ken Hughes khughes at pacific.edu
Mon Sep 19 18:28:36 CEST 2005


Joseph Gilbert wrote:
> 
>>> Since other use meshes much more than I, suggestions for the API will 
>>> really be needed.  My current plan would be to use the existing NMesh 
>>> API as a template as far as access to vert/faces/edges and their 
>>> data, but can use more guidance.
>>
> The current NMesh creates python objects from the struct Mesh and the 
> rebuilding the struct Mesh later. Using NMesh as a template may not be 
> what you want to do. The idea behind Mesh (aka thinmesh) is that you 
> access the data directly by address and modify it.
> 
> However as willian (always on target :)) has said there needs to be a 
> 'pythonic' way of accessing the struct Mesh data for script users. 
> Willian (and i think he is right on) mentioned this should be a python 
> list. Something similiar may need to exist for access to edges, dverts, 
> etc. etc.

OK, let me rephrase that; from the script writer's standpoint, the 
thinmesh API would appear very much like the NMesh API:

mesh = Blender.TMesh.Get('Cube')

for v in mesh.verts: # get all vertices
   v.co[0] += 1.0     # move 1 unit in x direction
   v.sel = 1          # select the vertex
   print v.no         # display the normal

Internally "v" is a thin wrapper around a mesh vertex, but to the script 
writer looks like the current NMVert object (it has the same attributes).

(BTW, as Willian pointed out, the first goal should be pretty easy to 
reach.  Took about an hour to brew up a Thinmesh API which wrapped 
vertices; the code shown above works  Don't think it would take much 
longer to wrap edges, faces and colors).

An implementation question (for Stephen, Willian and Joseph):  What type 
should mesh.verts be?  Since mesh.verts[0] is a vertex, seems like then 
it should either be a list or tuple or sequence.  My question is, should 
it be some new BPython sequence type or just a Python list/tuple?  If 
it's a Python type, I'd vote for a tuple since lists are mutable and 
users might expect that editing the list would also edit the mesh's 
vertex list.

> Correct me if I'm wrong here but if editmesh is like editarmature, they 
> are 2 halves of the same whole.  Blender most likely uses editmesh to 
> manipulate mesh data by putting creating an editmesh from a mesh, 
> manipulating the editmesh, and rebuilding the mesh from the editmesh.
> 
> I guess the question that Cam could be asking is whether you will use 
> the edimode code for manipulations. It might be a good idea.

I'm open to advice.  My first instinct is it would be overkill to 
convert a mesh to an editmesh just to change object attributes like a 
vertex's coordinate or a face's material index, but editmode might be 
very helpful or even crucial when deleting a face (in order to find any 
other faces sharing the same edges).

>>    * Would using EditMesh data for the thin wrapper limit you to
>>      modifying 1 mesh at a time?
> 
> It depends on how Ken you want to make this. For Armatures it has not, 
> through a little bit of manipulation and avoidance of any global 
> structures. Remember that Blender has a '1 object can be in editmode at 
> 1 time' policy which may hamper your abilities to use editmode code 
> effectively. It something to think about because python is a bit more 
> flexible than blender in what it will allow.

Good point; does anyone know offhand if the editmode code would support 
editing more than one object at a time?

Ken



More information about the Bf-python mailing list