How to create a mesh in bge at real-time?

Recently I started working on a LOD manager for use in my game projects and found that I couldn’t batch meshes together.

So how can I create a new mesh at real-time?

I attempted to add new vertices and removing some, yet this doesn’t work.
If I create a a New sub class of kx_meshproxy it crashes the game.

I know it should be possible because blender converts it’s meshes to bge meshes when you press “P” to start the game engine.

The only way I can batch at the moment, is if I have a mesh Chunk of say 2048 faces and move the vertices around.
Batching this way means that I always have faces that remain unused.

I don’t think you can create new meshes at runtime. However, you can crate multiple versions of the same mesh in blender, and then, in the BGE, simply switch between existing versions based on distance.

Goran is correct! You cannot instantiate new data within a mesh, nor remove it. You can create a duplicate, individual mesh though, using LibNew. This demonstrates that there is functionality in place, there’s just no strong API to handle it.

Personally, the whole LibNew thing could use some reworking (as could most of the mesh API). It’s on my informal todo list once I’ve gotten some headway with the gameloop modifications.

Cool beans,

Can a seperate copy of blender cominucate with a BGE python module?
if it saved a new model, could libload load the new file?

2 copies of blender

1 copy “primary” = game

2nd copy - “Slave” - just blender running python no game -

Primary sends commands to slave

“make me a pie”

Slave makes a pie,
saves as //Directory/pie.blend

Primary LibLoads pie.blend

I tried this a while ago. It’s fine in concept, but Blender doesn’t like executing operators unless they come from the UI, so it’s a bit tricky to do.
I’d do this for slicing (semi-realtime destruction)

I am already swapping meshes based on detail, batching would have been the fourth step.

Thanks for confirming what I already suspected.

Now this I am looking forward to!

Edit:
For any one who cares, I found a way to batch the mesh.

I create a new mesh using openGL, for now it looks strange because it is not responding to the lights in blender yet.
With a proper shader this will work because of the distance the mesh is from the player.

@ScoutingNinjia: I care! It would be great if you could post an example or something when it’s finished. I’ve been interested in this type of thing for a while. ? (:

When the Lod manager is done I will share it here at Game Engine Resources forum.

That’s exactly what I’ve been working on, although the 2nd copy is simply a python file the BGE loads in realtime (modules can be reloaded during runtime). I can actually transfer objects from one BGE to another BGE in realtime also.

Can you share a blend?
I would like to see how it works.

Could you post a video or something of it working?