How to move vertices in UPBGE python?

Like, how would I create a script that manipulates the vertices of a plane or other shape? I get all vertices on the mesh through python, get the XYZ, then set the XYZ to something like 1 on the Z axis, press P, and… nothing??

Could you share your code. There’s numerous ways to move any or all vertices and it’ll reduce wasted time if others can better understand what you’re trying to accomplish.

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
mesh = own.blenderObject.data
verts = mesh.vertices
for vert in verts:
    vert.co += vert.normal *. 01

I don’t have any code at the moment.

Depending on witch version you use for 0.2.5:

def raise_vertex(cont):

    own = cont.owner
         
    mesh = own.meshes[0]
    vertex_count = mesh.getVertexArrayLength(0)

    for index in range(0, vertex_count):

        vert = mesh.getVertex(0,index)
        
        #if index number is an even number
        if index % 2 == 0: 
            
            #height limit
            if vert.z < 1.0: 
                
                #raise the vertex
                vert.z += 0.01 

Always(true pulse) → python(module) → scriptname.raise_vertex

1 Like

I’m using 0.3

ok, won’t be a problem, mine still works in 3.0 only Bpr’s solution would be faster / better due to using bpy.

We don’t have kx_meshProxy anymore.

In 3.0 we have to use bpy *

1 Like

Forgot to reply back to this thread. Here’s a simple script to set a mesh’s Z-axis local to a value of 1.0:

import bge

def main(self):

    for v in self.owner.blenderObject.data.vertices:
        v.co[2] = v.co[2] + 1