ボクセル ベースのゲームの作成を実験しており、何百万ものキューブをレンダリングしています。
レンダリングを高速化するために、32x32x32 のキューブを 1 つのメッシュにグループ化するチャンクにキューブをグループ化しています。これは、GPU へのレンダリング呼び出しの数を減らし、フレームレートを上げるためです。
ブロックを構築するために ManualObject を使用していますが、完全に機能します。ただし、問題は、個々のブロックが個々のシーン ノードに結び付けられたエンティティではないため、衝突検出を行う方法が見つからないことです。
ogre には、ManualObject のサブメッシュを個別に操作する方法がありますか?
// Build a face with triangles if the face is visible. Don't bother building faces for hidden faces.
void Chunk::createMesh()
{
begin("BoxColor");
int iVertex = 0;
Block *block;
Block *testingBlock;
for (int x = 0; x < CHUNK_SIZE.x; ++x)
{
for (int y = 0; y < CHUNK_SIZE.y; ++y)
{
for (int z = 0; z < CHUNK_SIZE.z; ++z)
{
block = m_pBlocks[x][y][z];
if (block == NULL)
{
continue;
}
//x-1
testingBlock = 0;
if (x > 0) testingBlock = m_pBlocks[x-1][y][z];
if (testingBlock == 0)
{
position(x, y, z+1); normal(-1,0,0); textureCoord(0, 1);
position(x, y+1, z+1); normal(-1,0,0); textureCoord(1, 1);
position(x, y+1, z); normal(-1,0,0); textureCoord(1, 0);
position(x, y, z); normal(-1,0,0); textureCoord(0, 0);
triangle(iVertex, iVertex+1, iVertex+2);
triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//x+1
testingBlock = 0;
if (x < 0 + CHUNK_SIZE.x - 1) testingBlock = m_pBlocks[x+1][y][z];
if (testingBlock == 0)
{
position(x+1, y, z); normal(1,0,0); textureCoord(0, 1);
position(x+1, y+1, z); normal(1,0,0); textureCoord(1, 1);
position(x+1, y+1, z+1); normal(1,0,0); textureCoord(1, 0);
position(x+1, y, z+1); normal(1,0,0); textureCoord(0, 0);
triangle(iVertex, iVertex+1, iVertex+2);
triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//y-1
testingBlock = 0;
if (y > 0) testingBlock = m_pBlocks[x][y-1][z];
if (testingBlock == 0)
{
position(x, y, z); normal(0,-1,0); textureCoord(0, 1);
position(x+1, y, z); normal(0,-1,0); textureCoord(1, 1);
position(x+1, y, z+1); normal(0,-1,0); textureCoord(1, 0);
position(x, y, z+1); normal(0,-1,0); textureCoord(0, 0);
triangle(iVertex, iVertex+1, iVertex+2);
triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//y+1
testingBlock = 0;
if (y < 0 + CHUNK_SIZE.y - 1) testingBlock = m_pBlocks[x][y+1][z];
if (testingBlock == 0)
{
position(x, y+1, z+1); normal(0,1,0); textureCoord(0, 1);
position(x+1, y+1, z+1); normal(0,1,0); textureCoord(1, 1);
position(x+1, y+1, z); normal(0,1,0); textureCoord(1, 0);
position(x, y+1, z); normal(0,1,0); textureCoord(0, 0);
triangle(iVertex, iVertex+1, iVertex+2);
triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//z-1
testingBlock = 0;
if (z > 0) testingBlock = m_pBlocks[x][y][z-1];
if (testingBlock == 0)
{
position(x, y+1, z); normal(0,0,-1); textureCoord(0, 1);
position(x+1, y+1, z); normal(0,0,-1); textureCoord(1, 1);
position(x+1, y, z); normal(0,0,-1); textureCoord(1, 0);
position(x, y, z); normal(0,0,-1); textureCoord(0, 0);
triangle(iVertex, iVertex+1, iVertex+2);
triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//z+1
testingBlock = 0;
if (z < 0 + CHUNK_SIZE.z - 1) testingBlock = m_pBlocks[x][y][z+1];
if (testingBlock == 0)
{
position(x, y, z+1); normal(0,0,1); textureCoord(0, 1);
position(x+1, y, z+1); normal(0,0,1); textureCoord(1, 1);
position(x+1, y+1, z+1); normal(0,0,1); textureCoord(1, 0);
position(x, y+1, z+1); normal(0,0,1); textureCoord(0, 0);
triangle(iVertex, iVertex+1, iVertex+2);
triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
}
}
}
end();
}