I needed a way to export meshes with bone deformations and I came across the BPyMesh script that is included with Blender and can be imported. I didn’t immediately see how to use the Mesh class to return the deformed mesh but the BPyMesh script makes it quite clear. The less said about the NMesh monstrosity the better. It returns the deformed mesh and although that thing doesn’t leak memory, it sucks up a lot and boy is it slow. I know that some people wanted NMesh to stay around but does it offer any extra functionality? If not and it’s for script compatibility, can the functions be mapped internally? I hate to think if there are any people still using it and it’s seriously affecting their export script performance.
Anyway, the leak in BPyMesh happens when calling the getMeshFromObject function. The default is set to apply vgroups by default. In this function, there are three lines of code:
if tempob==None:
____tempob= Blender.Object.New(‘Mesh’)
tempob.link(mesh)
I don’t know why it leaks so much given that it’s just a link so maybe it’s a deeper issue in Blender. The variable tempob is never used again so these lines can be removed and they are what’s causing the problem because it doesn’t leak after removing them.
I tested it on a smallish scene and every export increased Blender’s Ram usage by 10MB. Like I say, this was on a scene with low poly objects (maybe 3000 verts total) so it would be a big problem for higher scenes.
Incidentally, is the preferred method for getting deformed data to do this:
mesh = Blender.Mesh.New()
try: mesh.getFromObject(obj)
except: # raise some error
This works fast and it doesn’t leak memory. Like I say, why can’t NMesh.getRawFromObject just be mapped to doing that?