Edit mesh vertex, edges or faces at run-time in Blender 2.68 and Python 3.3

This question might have been posted before but a long time ago so I don’t know if at this moment there’s some progress in regards to this feature.
I want to dynamically edit an object (a plane that is supposed to become a terrain). I must subdivide it and change its vertex positions then, when the game is closed leave everything as it was at the beginning.
So, I have a simple plane (called Terrain) already created and what I am trying is this:


terrain_object = bpy.data.objects['Terrain']
terrain_object.dimensions = (10, 10, 0.0) # !!!

# add some vertices
terrain_object.data.vertices.add(4)  
terrain_object.data.vertices[-4].co = (1, -1, 1)  
terrain_object.data.vertices[-3].co = (-1, -1, 1)  
terrain_object.data.vertices[-2].co = (-1, 1, 1)  
terrain_object.data.vertices[-1].co = (1, 1, 1)

# add one face
terrain_object.data.tessfaces.add(1)
terrain_object.data.faces[-1].vertices_raw = [7,4,5,6]  
terrain_object.data.update(calc_edges=True)  

In first place, when I run the game I get this error:

Error: cannot add tessfaces to a mesh that already has polygons

Secondly, I see that when I change the dimensions of the plane (at # !!!) it is changed into the 3D view and remains changed after the game stops. Looks like working with bpy.data.objects is only for plugins, not for games, so I don’t know what will happen in the run-time executable when doing this.

Is there anything else I could take use of in order to make this work. To be able to do this would really push Blender game engine to the top and open limitless possibilities for editing objects in the game.

long time not seen … it is time for:
/uploads/default/original/4X/7/a/6/7a6be7869646a2cdd84599e7f3f3096d0c9bbdee.pngd=1326444037

Yes, I know, I know. I just tried to show what I want. What does BGE offer for this, then?

You can change the UV and the XYZ of vertices. You can’t add or delete faces/vertices/materials.

Look at the BGE API search for KX_MeshProxy

If you really wan’t to edit a object at real time, use OpenGL shaders.

You can use the OpenGL wrapper(bgl) to add a new mesh to a scene, but it seems there is no way to turn it into a KX_MeshProxy.

I have recently started learning OpenGL shaders and found that I could move,add and remove polygons from a mesh and by updating the physics objects could interact with it.

What about changing a grid’s subdivisions? Could I change that in the game? I will have a look at the bgl, maybe it is the only solution until they implement this features (or maybe I will stick to OpenGL/C++ and use Blender just for modeling and animations)

Blender acts as a go-between OpenGL and the physics engine.

If you use OpenGl and C++ you will still need a physics engine, build your own level editor, game engine animation system, particle emiters, terrains tools and sound engine.
With a bit of OpenGL knowledge there really isn’t any thing you can’t make with Blender.

I will probably be flamed for this… I would advise to switch to Panda3D (your choice of Python and/or C++) , and come back to Blender in a year or two, when there will be tighter integration between the BGE and Blender, so that these things will be possible.

Good advice Sjoerd.
Using other game engines is a good way to gain understanding about game engines in general, it will also help in finding the right game engine for the game you are making.

Well, then. I see Blender becoming anything you need in order to create any graphic/multimedia content (images, videos, games and even other kind of 3d apps), so, why re-inventing the wheel and trying to create a new engine when I could try to learn how Blender is coded and cooperate. I will get a slice of that source code and have a look, see what skills I need (I know lots of assembly, C, C++, not so much of Python, OpenGL and DirectX) and where to start from. BGE must become a tough opponent in the list of game engines. Thanks and make room, I’m in a mission. :smiley:

A volunteer to improve the BGE code, excellent! There are build instructions on the Blender web site, and I highly recommend to drop by at #blendercoders.

I would also recommend going to #bgecoders on Freenode (same server as #blendercoders as Sjoerd mentioned above). Some of the other BGE-specific devs hang out there. I’ve been known to idle there sometimes as well when I’m investigating a bug or adding some little feature nobody will use, haha. :stuck_out_tongue: