[Bf-python] Mesh Module

Ken Hughes khughes at pacific.edu
Wed Oct 5 02:35:42 CEST 2005


Willian Padovani Germano wrote:
> Ken Hughes wrote:
> 
>> I'm still trying to figure out the best way to handle sequence 
>> operators (assignments in particular) while still keeping things 
>> "thin" and not messing up how meshes are referred to elsewhere in 
>> Blender.
> 
> 
> Hi Ken, opening our discussion to the group.
> 
> 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
> 
> They can also be used when the coder needs more control of (a slice of) 
> mesh.verts, with a mesh.verts.get() or .copy() or simply 
> mesh.verts[start:end], if the code gets all updated to use pyverts. Ex:
> 
> myverts = mesh.verts.get() # gets a list with copies of the verts
> # now you can do whatever with myverts:
> # add or remove from anywhere in the list, append, extend, etc.
> # Then:
> mesh.verts = myverts # pass changes back to Blender
> 
> If the user forgets or doesn't want to pass the changes back to Blender, 
> no problem. Since it's a "pylist of pyverts", Python itself takes care 
> of getting rid of the data once its ref count reaches zero (otherwise 
> it's a buggy Python version).
> 
> Not thin as direct access, but with control of the quantity of data to 
> work on at a time and no need to grab/transform the whole mesh, but 
> simply the data you need at that time, it might be a good approach.

OK, I've been trying all day to mentally shift gears into thinking about 
meshes beyond just altering the existing values; specifically 
addition/deletion/modification and how things are done under the hood.

I've spend the better part of the last two hours tracing through vertex 
key stuff, and think I have some idea what's going on there now.  But 
I'm having trouble finding examples/tutorials/documentation on derived 
meshes, so I need some guidance there.

For the code example you give above, what should happen if the size of 
the list myverts is different than the current mesh verts list?  For 
example, should we prune edges and faces for deleted vertices?  Should 
ALL edge and face info be deleted?  Should the "fat" vert created by 
Mesh.MVert() retain info about it's original index so that later the 
sequence assign_item handler can try to "fix things up"?  Any 
suggestions out there?

Oh, and one of those "now that I know enough to be dangerous" ideas; 
supposing the mesh does have vertex keys, should we make them accessible 
through something like mesh.keys[]?

Ken




More information about the Bf-python mailing list