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();