AddMesh - remove mesh

Blitz3D Forums/Blitz3D Programming/AddMesh - remove mesh

groovylime(Posted 2010) [#1]
I'm hoping you guys can help me out...
Imagine a wall built with cubes. I want to be able to remove cubes from the wall during game play. This is simple if I have each cube as an entity... just use FreeEntity on the cube.
Of course the problem with this approach is that if the wall is large, ie. many entities, this will be too slow during game play.

I'm thinking that the wall should be a single mesh, made up of the cubes each added using AddMesh. This has much lower overhead, so is more efficient, but I need to have a way of removing a cube from the mesh wall. Each cube mesh on its own is a single surface, and when it's added to the wall mesh, its surface is melded with the wall surface without an increase to the wall's surface count.
If it was added as a new surface then I could use the GetSurface function to target the Cube, then use the ClearSurface function to remove it.
I don't want to have to regenerate the entire wall just to be able to remove a cube.

Any ideas?
It seems like such a basic problem.


Ross C(Posted 2010) [#2]
You'll have to rebuild the entire mesh if your removing triangles. The only other way is to make sure the walls vertices are not shared and then use vertexcolor to apply alpha to all those wall vertices


PowerPC603(Posted 2010) [#3]
You can also move the vertices way out of the playfield to remove a cube.

I tried a similar approach for my Arkanoid3D game.
All the blocks were added into one big mesh.
When the ball has hit one block, the block needs to be destroyed.
I simply used types to hold the indexes of the vertices that represented the block and moved them all way out of the playfield (to coords -5000, 0, 0) using VertexCoords.

I moved all the vertices of that block to the same coordinates (-5000, 0, 0).

Then you don't have to rebuild your entire mesh without the vertices and triangles for removing just one block.
Simply reposition the vertices and the triangles move with them automatically.

NOTE: I had to drop this idea as I was checking for collisions on this big mesh and collision-processing was too slow (the big mesh had over 10.000 triangles on some levels with lots of blocks).
For every collision (ball to big mesh), I needed to figure out which triangle was hit to identify which block was actually hit, before I could move the vertices.



Or, like Ross said, if all your cubes have their own vertices, make those vertices invisible (alpha'd).


groovylime(Posted 2010) [#4]
Thanks for the feedback guys!
I think this solves my problem.... instead of trying to target the surface of the cube to remove, I go down to the verticies level and target them.. moving them out of the wall moves the cube out.
I just need to keep track of the index of each vertex when I add the cube mesh.
Thanks for your help!

If anyone has a better idea, this thread is still open.