The question is whether it possible to write something like this:
class MyBMesh(bmesh.types.BMesh):
def move_x(self, x):
for vert in self.verts:
vert.co = (x, vert.co[1], vert.co[2])
bm = MyBMesh()
bm.from_mesh(bpy.data.meshes['My mesh'])
bm.move_x([1. for _ in range(verts_number)])
If not then why? It is awesome if it would be possible like with other Blender classes (Panels, Menus, Operators, …).
I would like to code in OOP style but don’t see how I can extend BMesh functionality.
I don’t know the direct answer to your question, but I do know that inheritance isn’t the only way too do OOP. You can also create classes by composition or aggregation.
In your __init__ method, create references to the object you need. If you are lazy (OOP joke!), you can always instantiate the objects later as needed.
I’m afraid that in this case API won’t be consistent. My example I should write then in next way:
bm = MyBMesh()
bm.bmesh.from_mesh(bpy.data.meshes['My mesh'])
bm.move_x([1. for _ in range(verts_number)])
In this case from mesh and move_x methods belongs to different objects and I have to remember was method in built in or custom class. I do not see reasons why they should not be in one class.
Python does not enforce this, but I would treat the .bmesh member as private.
As a general rule, you don’t want to expose implementation details.
(One should not run around exposing their private parts to the world!)
Use your MyBMesh() class to create the interface you want to see and hide the details that do not matter.