I want to set up a script that randomly changes the shape of an object. What I have so far is:
from bge import logic
import random
cont = logic.getCurrentController()
object = cont.owner
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)
vertex.setXYZ([ random.random(), random.random(), random.random()])
This works pretty well. However, since every single vertex gets its own random location, the cube turns out something like this:
what I want is something like this:
My question is: how can I achieve something like that?
I think the "broken" shapes happen because 3 vertices are connected to each other and if they all get a different random position, the shape "breaks"?
I assume, that I have to give the vertices 1-3 the same random position, then the vertices 4-6 the same random position and so on?
If that is true, how could I write that down in python?