real time vertex manipulation

Hi! I’m trying to make waves on an ocean by manipulating the vertices of a plane from frame to frame. I’ve taken some code from the manual and it seems to be working, because the plane is distorted to a wavy pattern when the game is startet. However nothing more happens and the waves are frozen instead of moving. The code for the vertice is in the main game loop, and i know the code is run each frame, but it doesn’t seem to do anythin. The code is:

    #change z component of vertices in water plane
    geomNodeCollection = self.waves.findAllMatches('**/+GeomNode')
    for nodePath in geomNodeCollection.asList():
        geomNode = nodePath.node()

        
        for i in range(geomNode.getNumGeoms()):
            geom = geomNode.getGeom(i)
            vdata = geom.getVertexData()

            vertex = GeomVertexRewriter(vdata, 'vertex')
            while not vertex.isAtEnd():
                v = vertex.getData3f()
                #print v[2], self.waveFunction(v[0],v[1],task.time)
                vertex.setData3f(v[0], v[1],self.waveFunction(v[0],v[1],task.time))

And the wave function is:

#waveFunction
def waveFunction(self,x,y,time):
    z=(math.sin(time+x/WAVE_LENGTH)+math.sin(y+x)/WAVE_LENGTH)*WAVE_HEIGHT/2

    return z

The wave is time dependent, so there should be differences from frame to frame. But there’s not! Help me!!

In order to get a modifiable pointer, you should call:

geom = geomNode.modifyGeom(i)
vdata = geom.modifyVertexData()

Instead of:

geom = geomNode.getGeom(i)
vdata = geom.getVertexData()

It is technically an error to modify an object returned by getGeom() or getVertexData(), but the Python wrappers don’t detect this error.

David

It works!! Thank you so much. Now I have cool moving water!