If I base a script on vertex indices -- how much risk that the index will change with time? Is it possible to assign some identifier of my own to a vertex? For example, add a uuid for every vertex I am interested in.
Asked
Active
Viewed 840 times
1 Answers
7
In general vertex indices are not a reliable way to keep track of vertices.
However in some cases you can't avoid using them (MDD/PC2 animations and texmesh feature for example), basically - as long as you only deform the geometry and don't add/remove/subdivide... etc. They can be used - but users of your tools need to be aware of this limitation. If you can avoid relying on vertex indices, its normally best to do so.
This example shows why vertex indices aren't safe as reference:
import bpy
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
ob = bpy.context.object
verts = ob.data.vertices
print("Before", verts[0].co)
# could also be edge-split, subdivide, knife-project, delete ... etc
bpy.ops.mesh.sort_elements(type='RANDOMIZE', elements={'VERT',})
ob.update_from_editmode()
print("After", verts[0].co)
# Before <Vector (1.0000, 1.0000, -1.0000)>
# After <Vector (1.0000, 1.0000, 1.0000)>
You should look into custom data layers:
http://www.blender.org/documentation/blender_python_api_2_69_release/bmesh.html#customdata-access
ideasman42
- 47,387
- 10
- 141
- 223
CodeManX
- 29,298
- 3
- 89
- 128
-
1Is there a safer identifier for a vertex? Can I make an identifier of my own? – dimus Dec 15 '13 at 17:14
-
@dimus This should probably be a separate question – gandalf3 Dec 15 '13 at 17:25
-
1do you need an identifier, or do you actually need to store data per vertex? Basically, it's the same. Unfortunately, there's no way to run code on geometry add / remove, so it's hard to assign identifiers to a custom data layer as you edit the mesh. Note that custom data will be copied on mesh extrude etc., which would also copy a possible identifier, which is probably not what you want. – CodeManX Dec 15 '13 at 22:41