Allow manually setting vertex animation type
Posted: Fri Dec 06, 2013 8:52 pm
In my project, I have vertex animations that I need to apply manually. I am not using Ogre's morph animation system because it's simply not compatible.
The problem is that Ogre only creates the SubEntity's software vertex animation buffer that I need IF a vertex animation track is used in the mesh.
As a workaround, I had to create a dummy animation track:
This is not very nice; it would be better if there was an API to manually override the vertex animation type.
For reference, here is how I'm applying the animation, which works great.
The problem is that Ogre only creates the SubEntity's software vertex animation buffer that I need IF a vertex animation track is used in the mesh.
As a workaround, I had to create a dummy animation track:
Code: Select all
if (srcVerts.size() && geomMorpherController)
mesh->createAnimation("dummy", 0)->createVertexTrack(1, subMesh->vertexData, Ogre::VAT_MORPH);
For reference, here is how I'm applying the animation, which works great.
Code: Select all
Ogre::VertexData* data = mSubEntity->_getSoftwareVertexAnimVertexData();
const Ogre::VertexElement* posElem =
data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
Ogre::HardwareVertexBufferSharedPtr vbuf =
data->vertexBufferBinding->getBuffer(posElem->getSource());
// The first morph key always contains the original positions
mNewVertices = mMorphs[0].mVertices;
for (std::vector<Nif::NiMorphData::MorphData>::iterator it = mMorphs.begin()+1; it != mMorphs.end(); ++it)
{
float val = 0;
if (!it->mData.mKeys.empty())
val = interpKey(it->mData.mKeys, time);
val = std::max(0.f, std::min(1.f, val));
if (it->mVertices.size() != mMorphs[0].mVertices.size())
continue;
if (val != 0)
{
for (unsigned int v=0; v<mNewVertices.size(); ++v)
mNewVertices[v] += it->mVertices[v] * val;
}
}
vbuf->writeData(0, vbuf->getSizeInBytes(), &mNewVertices[0]);
mSubEntity->_markBuffersUsedForAnimation();