how do you change a single tree's material color? I tried to do this:
TreeIterator3D iter = gTreeLoader->getTrees();
while( iter.hasMoreElements() )
Forests::TreeRef treeRef = iter.getNext();
if( treeRef.getPosition().distance( point ) < 100 )
treeRef.getEntity()->getSubEntity( 1 )->getMaterial()->setDiffuse( 1.f, 0.f, 0.f, 1.f );
treeRef.getEntity()->getSubEntity( 1 )->getMaterial()->setAmbient( 1.f, 0.f, 0.f );
The code does not change the trees color.
Also, how do you get an imposter's texture/entity ? I would also like to set its material color dynamically.
I think what you don't understand is that a TreeRef is nothing more than a position, rotation, and tree type struct. It's a interface for you to access tree positions and rotations (actually it should be returning as const, which I'll probably fix soon). Modifying a TreeRef entity, position, or rotation does nothing because the actual internal method of rendering the tree may vary - it could be an impostor, it could be batched, or anything really. This is up to the PagedGeometry engine to manage, and therefore you can't "hack" into the impostors, etc. and manually change things - not only would it be messy, but it just wouldn't work in many cases.
In this case, you can't modify each tree's material like this because treeRef.getEntity() is returning the same tree object for every tree, which you repeatedly set the color of - the actual duplicated trees you see on the screen are batched (or impostored, based on camera distance) and therefore have no individual entity properties, at least through the standard Ogre::Entity interface.
Currently the only supported way to set a tree's color is through the TreeLoader2D/TreeLoader3D's color map feature, or if you want to create your own PageLoader implementation, through the color parameter of the addEntity() command. Unfortunately, the speed boost PagedGeometry gives for rendering static trees comes at the cost of reduced capability for dynamic updates: updating any aspect of a tree (position, rotation, color) requires the entire page of trees in which it resides to be reloaded completely. Even if you update just the colors of trees, their area needs to be completely reloaded.
Features like dynamic lighting, etc. are planned to be implemented "properly" (efficiently) some time in the future, probably in a "PagedGeometry 2.0".
Thanks for the informative reply. I have a scene where trees and the likes are being bombed. I guess the best way then is to just remove the set of trees, and replace it with the destructed version yes?
Yes, that would be the best way. Basically just keep in mind that modifying a tree in any way (which can only be done by removing and adding in the default TreeLoader implementations) forces it's entire page to be reloaded the next time it's rendered, so it's actually better in many cases to modify a whole bunch of trees at once because whether you modify 1 tree or 10, if they're in the same page, it takes the same time to reload the changes.