Grouping pieces of a mesh for accessing within the BGE

I want to make a large forrest of trees. Join them all into one mesh, thus freeing up memory.

This is pretty common in games, though usually trees don’t have much interaction in a game.

In my game I want to be able to chop down trees.

The process would go like this:

remove the polygons where the player is chopping(already know how to do this)
Once an adequate amount of wood is removed from the tree, all of the vertices
above the chopped section need to be removed(scale the polygons to 0)
removal of the tree above the stump would allow me to then spawn a falling tree trunk.

the only thing holding me back is how to access very specific pieces of a mesh in the BGE.
I need to be able to access individual trees and then access portions of the trees
A tree would consist of three sections, (stump, choppable section, trunk)

your thoughts?

Joining them all to one mesh will not free up memory at all (it will actually make things much worse) as you will be preventing the use of any of the BGE’s culling mechanics (Frustum culling and occlusion culling).
Also, you make it sound like each tree is its very own object. This takes up an unecessarily large amount of resources on its own. You should only have a few different trees and make linked duplicates (ALT D) of them so that you arent having to store new mesh data for each object. Next you should create 3-5 cut versions of the tree your tree variations that you want to be cut down. The first one being the standing tree; the second one being when it falls; the third one being half of the cut tree; the fourth one being the upper portion of the tree; and the fifth one being the left over kindling (sticks and leaves).
Using the BGE’s LOD (level of detail) system is also a must in this case. LOD lowers the quality of an object based on how far away you are from the object to lower the load on your renderer.

Each point you made is good advice and advice that I’m already aware of, but blender has a budget of how many game objects it can handle, you have to take into account that players will be building shelters with the cut down trees and each log they place is an object, that’s starts adding up and before you know it blender’s performance is bogged down completely.

LOD would still be possible, as I could create groups of trees, each group of trees would be a separate object.
for example, instead of having 5000 tree objects, I would have 500 objects which would be groups of 10 trees or some ratio like that.

another optimization I’ll be using is a texture atlas for trees, this way all of the trees would be batched into one draw call, reducing the rasterizer’s workload

I already know how to fell a tree in the game engine, just looking to optimize and scale.

First think how you are making those trees?
In game or manually before?
This is the key aspect here.

Either way,
you save each trees vertices(index) in a dictionary when you create them, with the key being the location of the tree.
{loc:[vertIndexes]}

Removing would be getting the location of the fake tree you are in front of,
looping over the list of vertex indexes and changing the verts z locoation -10000 or something.

The setup what you ask for would be more like loc:[[choppableIndexes],[allvertsIndexes]], but you should by now get the idea.

yes! I had that idea a while back and I guess it slipped my mind, I had this discussion on the forums before. Thank you for reminding me

can you direct message me your skype name? I can copy/paste our conversation here afterwards for the benefit of others, It’s just really slow using the forum at least for me

or your email/facebook anything like that works for me

Kinda don’t have time to be available, forum kind suits me more.

What you can do is to create the tree then post it here.

Or do this:

You either paint all the chop-able parts with a vertex color or have them as separate objects for now.
They must share the same material/texture…
Make them all quads.

Then create a duplicate of the object ( or of the joined full tree of the parts).
This will have exactly the right amount of vertices as it is a duplicate.
Now we will IN EDIT mode duplicate the vertices X times, so we would have enough vertices for X amount of trees.

Now we have a example object and a donor mesh with enough vertices to fake X amount of trees.

In game, get the tree object as a reference and for loop over its vertices: save them in a dictionary.
You have to save the [uv,normal,position] vectors.
You save the the chop-able vertices under “chop” and all other under “whatever”.

Spawn now the donor mesh in the world.
Move its vertices where they need to be and change the uv and normal.