So, short of modifying the engine (to make CCubeSceneNode an IMeshSceneNode and return an IMeshSceneNode from addCubeSceneNode()), I'd do it with something like this:
Code: Select all
f32 cubeSize = 5.f;
video::SColor cubeColour(255,255,255,255);
SMeshBuffer * buffer = new SMeshBuffer();
u16 u[36] = { 0,2,1, 0,3,2, 1,5,4, 1,2,5, 4,6,7, 4,5,6,
7,3,0, 7,6,3, 9,5,2, 9,8,5, 0,11,10, 0,10,7};
buffer->Indices.set_used(36);
for (s32 i=0; i<36; ++i)
buffer->Indices[i] = u[i];
buffer->Vertices.set_used(12);
buffer->Vertices[0] = video::S3DVertex(0,0,0, -1,-1,-1, cubeColour, 0, 1);
buffer->Vertices[1] = video::S3DVertex(1,0,0, 1,-1,-1, cubeColour, 1, 1);
buffer->Vertices[2] = video::S3DVertex(1,1,0, 1, 1,-1, cubeColour, 1, 0);
buffer->Vertices[3] = video::S3DVertex(0,1,0, -1, 1,-1, cubeColour, 0, 0);
buffer->Vertices[4] = video::S3DVertex(1,0,1, 1,-1, 1, cubeColour, 0, 1);
buffer->Vertices[5] = video::S3DVertex(1,1,1, 1, 1, 1, cubeColour, 0, 0);
buffer->Vertices[6] = video::S3DVertex(0,1,1, -1, 1, 1, cubeColour, 1, 0);
buffer->Vertices[7] = video::S3DVertex(0,0,1, -1,-1, 1, cubeColour, 1, 1);
buffer->Vertices[8] = video::S3DVertex(0,1,1, -1, 1, 1, cubeColour, 0, 1);
buffer->Vertices[9] = video::S3DVertex(0,1,0, -1, 1,-1, cubeColour, 1, 1);
buffer->Vertices[10] = video::S3DVertex(1,0,1, 1,-1, 1, cubeColour, 1, 0);
buffer->Vertices[11] = video::S3DVertex(1,0,0, 1,-1,-1, cubeColour, 0, 0);
buffer->BoundingBox.reset(0,0,0);
for (int i=0; i<12; ++i)
{
buffer->Vertices[i].Pos -= core::vector3df(0.5f, 0.5f, 0.5f);
buffer->Vertices[i].Pos *= cubeSize;
buffer->BoundingBox.addInternalPoint(buffer->Vertices[i].Pos);
}
SMesh * cubeMesh = new SMesh();
cubeMesh->addMeshBuffer(buffer);
ISceneNode * cubeSceneNode = smgr->addMeshSceneNode(cubeMesh);