(C++) CBatchingMesh for tile-based worlds

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

(C++) CBatchingMesh for tile-based worlds

Post by bitplane »

Here's a little thing I've been playing with in case anyone wants it.

Lot of people are working on tile-based games and using one node per tile, which isn't such a good idea as it causes lots and lots of separate draw calls. Most exporters will group materials into surfaces, but you have to do it yourself if you're making a game from some kind of tile-set.

So, this is an IMesh that lets you drop other meshes or mesh buffers into it using addMesh or addMeshBuffer, then you can create your OctTreeNode or MeshNode and triangle selectors from it in the usual way.
One way to do it would be to split your world up into octtree chunks made from CBatchingMesh, which contains tiles for an area, then cull them using ProSoft's QuadTree node. (that's how i'm planning to use it)

You can get the code here, and a demo here

If you're not using SVN, you'll have to add the following lines to the top of CBatchingMesh.cpp

Code: Select all

#include "SMeshBufferLightmap.h"
#include "SMeshBufferTangents.h"
ps) if anyone wants to donate their code snippets into the irrlicht-plugins svn, or make changes to this and the other stuff up there.. just let me know your google account name by pm or email and I'll add you :)
Last edited by bitplane on Thu Jun 28, 2007 1:38 am, edited 2 times in total.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

Post by Halan »

so can i still attach a texture to each mesh?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

you can change textures between adding the same mesh multiple times yes, and every time you use a new texture/material combo it will add a new internal buffer.
you can't change the texture of a mesh after it has been added, you can change it's transformation though.

edit: demo added
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

And 3 years later, a question arises. How difficult would it be to allow adding of animated meshes?
Post Reply