Allow manually setting vertex animation type

Minor issues with the Ogre API that can be trivial to fix
Post Reply
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 216

Allow manually setting vertex animation type

Post by scrawl »

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:

Code: Select all

    if (srcVerts.size() && geomMorpherController)
        mesh->createAnimation("dummy", 0)->createVertexTrack(1, subMesh->vertexData, Ogre::VAT_MORPH);
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.

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