Best way to add scene nodes when using geometry primitives?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
itzjac
Posts: 57
Joined: Fri Nov 17, 2006 7:41 pm
Location: Mexico City

Best way to add scene nodes when using geometry primitives?

Post by itzjac »

I created a new geometry primitive CConeSceneNode, based on the CCubeSceneNode.

I used the code from CGeometryCreator::createCubeMesh(...) to generate the mesh buffer, vertices and indices, basically it uses:

Code: Select all

 
 
SMeshBuffer* buffer = new SMeshBuffer();
Vertices = new video::S3DVertex[TotalVertices];
indices = new u16[TotalIndices];
...
buffer->Indices.set_used(TotalIndices);
buffer->Vertices.reallocate(TotalVertices);
buffer->BoundingBox.reset(0,0,0);
 
SMesh* Mesh = new SMesh;
Mesh->addMeshBuffer(buffer);
buffer->drop();
 
Mesh->recalculateBoundingBox();
...
 
Didn't change anything from the render method copied from the cube:

Code: Select all

 
video::IVideoDriver* driver = SceneManager->getVideoDriver();
    driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
 
    // for debug purposes only:
    video::SMaterial mat = Mesh->getMeshBuffer(0)->getMaterial();
 
    // overwrite half transparency
    if (DebugDataVisible & scene::EDS_HALF_TRANSPARENCY)
        mat.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
    else
        driver->setMaterial(Mesh->getMeshBuffer(0)->getMaterial());
    driver->setMaterial(mat);
    driver->drawMeshBuffer(Mesh->getMeshBuffer(0));
 
...
// rest of the debugging code
 

The way this is added to the scene is:

Code: Select all

 
scene::IMeshSceneNode *mesh = smgr->addConeSceneNode(0, -1, 
                36, 0, 5, 5, video::SColor(0,255,0,255));
 
Those parameters are using o create a more or less tessellated version of a cone, height, etc.

Am planing to add thousands of this nodes to a scene, create a random movement for each. I wonder what will be the best way for this to work, maybe changing the calls for the render method or giving a hint to use a vertex buffer or whatever serves performance wise. What would you recommend?

I added this line

Code: Select all

 
mesh->getMesh()->getMeshBuffer(0)->setHardwareMappingHint(scene::EHM_STATIC);
 
But 10,000 of this entities are slowing the application.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Best way to add scene nodes when using geometry primitiv

Post by hybrid »

Yes, cones are just like cubes, only worse. So make yourself a favor and search for minecraft clones in the forum and check what is suggested there to handle thius amount of scene nodes (well, there is none actually, so better how to handle this amount of objects). Since you want arbitrary movement for each cone, your job might be a little trickier than for simple block worlds. Not even sure how, e.g., instancing would behave in these cases. But for a first test, batching is the way to go.
EHM_STATIC is not helping much here, because it's merely the scene node handling and not the geometry that is using up performance.
Post Reply