For my simulator project, I currently have code in place that changes textures of objects on a per-polygon basis, which works great (it's using setMaterialName() on Ogre::SubMesh). I wrote a custom animation controller that is similar to Ogre's texture animation system, but that it defines a duration for each image instead of having a single duration for the whole animation like Ogre has, and then switches between the images, using simulator timers. Currently I don't seem to be able to get Ogre to change the texture on the related material, I've tried a number of different things, including setting the dirty state on the material. I was going through a lot of the Ogre code to find out how the animation system sets the textures, but haven't found anything yet.
I'm using Ogre 14.3.4.
One of the things I tried was to remove the texture unit state and recreate it, this is probably doing it wrong though:
Code: Select all
bool TextureManager::SetTexture(const std::string &name, const std::string &texture)
{
//get texture unit state
Ogre::MaterialPtr mMat = GetMaterialByName(name);
mMat->getTechnique(0)->getPass(0)->removeTextureUnitState(0);
try
{
//set texture unit's texture image
Ogre::TextureUnitState *state = mMat->getTechnique(0)->getPass(0)->createTextureUnitState(texture);
mMat->_dirtyState();
}
catch (Ogre::Exception &e)
{
return ReportError("Error setting texture " + name + " to filename " + texture + "\n" + e.getDescription());
}
return true;
}
I've also tried the SetTexture() and SetTextureName() functions on the unit state. The problem might be something simple that I'm missing.
