I'm writing a python script that is about to reduce the vertex count of some meshes in accordance with some custom rules (for technical uses, for example, parallel edges must remain parallel and so on).
For this, I need to store data considering Meshes, Vertices and Edges (for example, connecting edges' length for a vertex). It's important that I need to access the containing Mesh from a Vertex or Edge.
My first approach was to inherit a VertexData object from the Vertex where I can add all data needed, like this:
class CustomVertex(bpy.types.MeshVertex): def __init__(self, inMesh, inVertex): self.data = blabla
But later I realized that this doesn't work too well, for example, I couldn't give more than one parameter to
__init__() . (When inherited from a Mesh,
__init__() could absorb more parameters).
When discussed here, I was advised to use Properties:
class CustomVertex(bpy.types.PropertyGroup): pass bpy.utils.register_class(CustomVertex) bpy.types.Mesh.my_vertdata = bpy.props.CollectionProperty(type=CustomVertex) objdata = bpy.context.object.data new_item = objdata.my_vertdata.add()
But when using this, I realized that
- I cannot add data to Vertices and Edges this way (only to Meshes, but Meshes allowed inheriting from them, so the first approach was better for this).
- I have much more constraints (for example, I cannot sort CollectionProperty like I can sort a list).
- My code became much more complicated, I myself cannot read it easily.
- I suspect that *Property stuff is useful only when it must be set via UI (most of my internal data doesn't have to be like this).
So, finally my question is: are these my only options for storing/manipulatin geometry/object-related data in Blender? Which is the best approach for this?