It worked fine for me too...
Maybe it's the way that i'm making the vertices?
Take a look:
I allocate the buffers;
Code: Select all
S3DVertex* vertices = new S3DVertex[65536+1];
u16* indexList = new u16[65536*2+1];
Then i read my file;
make 2 counters;
and start to add the vertices. When the vertices of the current meshbuffer exceeds 65536(maxvertex), it add that buffer to the main mesh and make another meshbuffer and start it over again...
Code: Select all
for(f32 x = 0; x < width; x++)
{
for(f32 y = 0; y < height; y++)
{
u32 act = (u32)y * width + (u32)x;
Block* current = &blocks[act];
if(act1 + 3 >= 65536)
{
currentBuffer->append(vertices,act1-1,indexList,act2);
mapMesh->addMeshBuffer(currentBuffer);
currentBuffer->drop();
currentBuffer = new scene::SMeshBuffer();
act1 = act2 = 0;
delete[] vertices;
delete[] indexList;
vertices = new S3DVertex[65536+1];
indexList = new u16[65536*2+1];
}
SColor color = SColor(255,
(current->type == 0 || current->type == 3 ? 0 : 255),
(current->type == 0 || current->type == 3 ? 255 : 0),
0);
vector3df buffer = vector3df(x-1,y-1,current->uppleft);
buffer *= multiplier; // Just to scale the vertice
vertices[act1].Pos = buffer;
vertices[act1].Normal = buffer.normalize();
vertices[act1].Color = color;
buffer = vector3df(x-1,y+1,current->uppright);
buffer *= multiplier;
vertices[act1+1].Pos = buffer;
vertices[act1+1].Normal = buffer.normalize();
vertices[act1+1].Color = color;
buffer = vector3df(x+1,y+1,current->lowright);
buffer *= multiplier;
vertices[act1+2].Pos = buffer;
vertices[act1+2].Normal = buffer.normalize();
vertices[act1+2].Color = color;
buffer = vector3df(x-1,y+1,current->lowleft);
buffer *= multiplier;
vertices[act1+3].Pos = buffer;
vertices[act1+3].Normal = buffer.normalize();
vertices[act1+3].Color = color;
indexList[++act2] = act1;
indexList[++act2] = act1+1;
indexList[++act2] = act1+2;
indexList[++act2] = act1+3;
indexList[++act2] = act1+1;
indexList[++act2] = act1+2;
act1 += 4;
}
}
currentBuffer->append(vertices,act1-1,indexList,act2);
mapMesh->addMeshBuffer(currentBuffer);
Can you understand it?
To help, there's the Block class:
Code: Select all
class Block {
public:
f32 uppleft,
uppright,
lowleft,
lowright;
u8 type;
};
It just holds the height of the block. The position I have to figure it out. But it works with normal mesh nodes!
(If you're thinking I'm crazy to do a poorly file struct like that which just holds the height of the map, those map files aren't mine. They're from Gravity's ragnarok. The .gat files.)