Efficiently planting multiple nodes
Posted: Mon Dec 10, 2007 5:10 pm
I'm sure there's a very simple solution {sighs}... although I'm slowly becoming more familiar with Irrlicht through the API, tutorials, and (much) searching through these forums, the little things are killing me, lol! Doesn't help I'm still working on getting C++ down beyond the very basic code (I'm a transplant from VB6).
At this time, I simply want to "plant" a field of randomly-positioned grass across a flat terrain. A small level was created integrating Irrlicht's Tutorial 12 code (Terrain Rendering) with elvman's Realistic Water node. I needed water, lol! Anyway, the fps with that combination averages around 400+ fps.
Thanks to Acki's loop/nodeID code at http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24874, this works to plant 2000 instances of grass (one GrassPlane2.x model is simply made of two intersecting planes [4 triangles total] and currently not animated):
This works fine, but REALLY slows the frame rate down to about 20 fps on an NVIDIA GEForce 8600 card just with this loop. Replacing the random_ variables in setPosition and setRotation (those variables were generated previously) with actual numbers did not appear to change the fps.
Is this loop (and the engine's API behaviour) reloading the model and texture 2000 times, or is the original file being stored in IMeshCache automatically? Is there a better way to tackle this?
Thanks very much for any thoughts!
At this time, I simply want to "plant" a field of randomly-positioned grass across a flat terrain. A small level was created integrating Irrlicht's Tutorial 12 code (Terrain Rendering) with elvman's Realistic Water node. I needed water, lol! Anyway, the fps with that combination averages around 400+ fps.
Thanks to Acki's loop/nodeID code at http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24874, this works to plant 2000 instances of grass (one GrassPlane2.x model is simply made of two intersecting planes [4 triangles total] and currently not animated):
Code: Select all
// create 2000 nodes with IDs from 1 to 2000:
for(int ID = 1; ID <= 2000; ID++)
{
scene::IAnimatedMeshSceneNode* arrGrass = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/GrassPlane2.x"), 0, ID);
arrGrass->setMaterialFlag(video::EMF_LIGHTING, false);
arrGrass->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
arrGrass->getMaterial(0).MaterialTypeParam = 0.01f;
arrGrass->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
arrGrass->setPosition(core::vector3df(random_intX,1800,random_intY));
arrGrass->setRotation(core::vector3df (0,random_rot,0));
}
Is this loop (and the engine's API behaviour) reloading the model and texture 2000 times, or is the original file being stored in IMeshCache automatically? Is there a better way to tackle this?
Thanks very much for any thoughts!