BGE: alter a "cube"'s shape in real time

Hi there,

how is it possible to get all vertices of an object (say a cube) and then randomly change their location? What I want to do is everytime I hit space, the cube alters and generate random shapes.

What I have figured out myself so far:


    import bge
    import random
    
    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    # get the 1st mesh
    mesh = own.meshes[0]
    
    # get the first vertex of the first mesh
    vert  = mesh.getVertex( 0, 0)
    
    # get the position
    pos = vert.getXYZ()

    # set the position
    vert.setXYZ([ 10, 1.0, 15])

How does

    getVertex(matid, index)

exactely work? It only gets me one vertex, how can I get one after another? And then alter their position?

Thank you for any hint!

Ok i got it almost:


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, 0)
         vertex.setXYZ([ 9, 2, 8])
         vertex = mesh.getVertex(m_index, 1)
         vertex.setXYZ([ 12, 0, 4])
         vertex = mesh.getVertex(m_index, 2)
         vertex.setXYZ([ 4, 9, 2])

etc.
etc.

Is there an easier way though to set the position of every single vertex more conveniently instead of makeing a hughe list and setting every single one of them by hand?