BGE python: get list of vertices

i want to iterate through every single vertex of an object and then store them in a list.

what I have so far is:

for mesh in object.meshes:
for m_index in range(len(mesh.materials)):
for v_index in range(mesh.getVertexArrayLength(m_index)):

vertex = mesh.getVertex(m_index, v_index)


now i understand that "v_index" gets me "vertex 0 through 23" of the object (its a cube), but how can i store the result in a list?

vertex_list(0,1,2,3,4...23)


thanks for any hint,

sputi

• what i want to do ist to simultaneously shift vertices 0-3 and 4-7 by an X value so that the shape don't breaks. – Sputi Sep 17 '15 at 12:28

While not blender specific, it is a basic python list operation. Start by creating an empty list, then append each item.

verts = []
for mesh in object.meshes:
for m_index in range(len(mesh.materials)):
for v_index in range(mesh.getVertexArrayLength(m_index)):
verts.append(mesh.getVertex(m_index, v_index))


You may also want to adjust them as you go instead of making a list.

posadjust = [0,1,2,3]
for mesh in object.meshes:
for m_index in range(len(mesh.materials)):
for v_index in range(mesh.getVertexArrayLength(m_index)):
if v_index in posadjust:
vertex = mesh.getVertex(m_index, v_index)
vertex.x += 0.2
elif v_index in negadjust:
vertex = mesh.getVertex(m_index, v_index)
vertex.x -= 0.2

• thank you, very helpful! However they are in a strange order... how do I know which vertex is where on my cube?? – Sputi Sep 23 '15 at 20:20
• By looking at them in edit mode. How to view and sort them is explained here. – sambler Sep 24 '15 at 5:12
• I've already read that to completion, however it only explains how to see the order of the INDEX (one number per corner) and not of the VERTEX (3 numbers per corner, 3 vertices from 3 faces... ). I always seem to get the same answer that doesn't really help me - Or do I get something completely wrong here?? – Sputi Sep 24 '15 at 7:41
• kind of a solution: blenderartists.org/forum/… – Sputi Sep 24 '15 at 17:44
• @Sputi a vertex has one index which is it's position in the list of vertices. One vertex can have many edges connected to it, that is edge 1,3,6 and 7 can all connect to vertex 4. A face is then surrounded by a list of edges with vertices at each corner. When displaying the indices in the 3dview only the selected items will be shown, which is based on the selection type/s chosen. – sambler Sep 28 '15 at 13:31