|
|
|
@ -534,18 +534,18 @@ public:
|
|
|
|
|
class Value : public Ogre::ControllerValue<Ogre::Real>, public ValueInterpolator
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
Ogre::SubEntity *mSubEntity;
|
|
|
|
|
Ogre::Entity *mEntity;
|
|
|
|
|
std::vector<Nif::NiMorphData::MorphData> mMorphs;
|
|
|
|
|
std::vector<float> mValues;
|
|
|
|
|
size_t mControllerIndex;
|
|
|
|
|
|
|
|
|
|
std::vector<Ogre::Vector3> mVertices;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Value(Ogre::SubEntity *subent, const Nif::NiMorphData *data)
|
|
|
|
|
: mSubEntity(subent)
|
|
|
|
|
Value(Ogre::Entity *ent, const Nif::NiMorphData *data, size_t controllerIndex)
|
|
|
|
|
: mEntity(ent)
|
|
|
|
|
, mMorphs(data->mMorphs)
|
|
|
|
|
, mControllerIndex(controllerIndex)
|
|
|
|
|
{
|
|
|
|
|
mValues.resize(mMorphs.size()-1, 0.f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual Ogre::Real getValue() const
|
|
|
|
@ -558,21 +558,7 @@ public:
|
|
|
|
|
{
|
|
|
|
|
if (mMorphs.size() <= 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
#if OGRE_DOUBLE_PRECISION
|
|
|
|
|
#error "This code needs to be rewritten for double precision mode"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
Ogre::VertexData* data = mSubEntity->_getSoftwareVertexAnimVertexData();
|
|
|
|
|
|
|
|
|
|
const Ogre::VertexElement* posElem =
|
|
|
|
|
data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
|
|
|
|
|
|
|
|
|
|
Ogre::HardwareVertexBufferSharedPtr vbuf =
|
|
|
|
|
data->vertexBufferBinding->getBuffer(posElem->getSource());
|
|
|
|
|
|
|
|
|
|
bool needToUpdate = false;
|
|
|
|
|
int i=0;
|
|
|
|
|
int i = 1;
|
|
|
|
|
for (std::vector<Nif::NiMorphData::MorphData>::iterator it = mMorphs.begin()+1; it != mMorphs.end(); ++it,++i)
|
|
|
|
|
{
|
|
|
|
|
float val = 0;
|
|
|
|
@ -580,37 +566,13 @@ public:
|
|
|
|
|
val = interpKey(it->mData.mKeys, time);
|
|
|
|
|
val = std::max(0.f, std::min(1.f, val));
|
|
|
|
|
|
|
|
|
|
if (val != mValues[i])
|
|
|
|
|
needToUpdate = true;
|
|
|
|
|
mValues[i] = val;
|
|
|
|
|
}
|
|
|
|
|
if (!needToUpdate)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// The first morph key always contains the original positions
|
|
|
|
|
mVertices = mMorphs[0].mVertices;
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
for (std::vector<Nif::NiMorphData::MorphData>::iterator it = mMorphs.begin()+1; it != mMorphs.end(); ++it,++i)
|
|
|
|
|
{
|
|
|
|
|
float val = mValues[i];
|
|
|
|
|
Ogre::String animationID = Ogre::StringConverter::toString(mControllerIndex)
|
|
|
|
|
+ "_" + Ogre::StringConverter::toString(i);
|
|
|
|
|
|
|
|
|
|
if (it->mVertices.size() != mMorphs[0].mVertices.size())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (val != 0)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned int v=0; v<mVertices.size(); ++v)
|
|
|
|
|
mVertices[v] += it->mVertices[v] * val;
|
|
|
|
|
}
|
|
|
|
|
Ogre::AnimationState* state = mEntity->getAnimationState(animationID);
|
|
|
|
|
state->setEnabled(val > 0);
|
|
|
|
|
state->setWeight(val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mVertices.size() * sizeof(float)*3 != vbuf->getSizeInBytes())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
vbuf->writeData(0, vbuf->getSizeInBytes(), &mVertices[0]);
|
|
|
|
|
|
|
|
|
|
mSubEntity->_markBuffersUsedForAnimation();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -629,13 +591,6 @@ class NIFObjectLoader
|
|
|
|
|
std::cerr << "NIFObjectLoader: Warn: " << msg << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fail(const std::string &msg)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "NIFObjectLoader: Fail: "<< msg << std::endl;
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void createEntity(const std::string &name, const std::string &group,
|
|
|
|
|
Ogre::SceneManager *sceneMgr, ObjectScenePtr scene,
|
|
|
|
|
const Nif::Node *node, int flags, int animflags)
|
|
|
|
@ -693,7 +648,8 @@ class NIFObjectLoader
|
|
|
|
|
Ogre::ControllerValueRealPtr srcval((animflags&Nif::NiNode::AnimFlag_AutoPlay) ?
|
|
|
|
|
Ogre::ControllerManager::getSingleton().getFrameTimeSource() :
|
|
|
|
|
Ogre::ControllerValueRealPtr());
|
|
|
|
|
Ogre::ControllerValueRealPtr dstval(OGRE_NEW GeomMorpherController::Value(entity->getSubEntity(0), geom->data.getPtr()));
|
|
|
|
|
Ogre::ControllerValueRealPtr dstval(OGRE_NEW GeomMorpherController::Value(
|
|
|
|
|
entity, geom->data.getPtr(), geom->recIndex));
|
|
|
|
|
|
|
|
|
|
GeomMorpherController::Function* function = OGRE_NEW GeomMorpherController::Function(geom, (animflags&Nif::NiNode::AnimFlag_AutoPlay));
|
|
|
|
|
scene->mMaxControllerLength = std::max(function->mStopTime, scene->mMaxControllerLength);
|
|
|
|
|