forked from mirror/openmw-tes3mp
Moved functions from niffile.cpp to where they belong.
Also cleaned up some #includes Removed a few asserts. Vector already throws an out_of_range error.deque
parent
45c0be8f62
commit
8be6aefd95
@ -0,0 +1,29 @@
|
||||
#include "data.hpp"
|
||||
#include "node.hpp"
|
||||
|
||||
namespace Nif
|
||||
{
|
||||
void NiSkinInstance::post(NIFFile *nif)
|
||||
{
|
||||
data.post(nif);
|
||||
root.post(nif);
|
||||
bones.post(nif);
|
||||
|
||||
if(data.empty() || root.empty())
|
||||
nif->fail("NiSkinInstance missing root or data");
|
||||
|
||||
size_t bnum = bones.length();
|
||||
if(bnum != data->bones.size())
|
||||
nif->fail("Mismatch in NiSkinData bone count");
|
||||
|
||||
root->makeRootBone(&data->trafo);
|
||||
|
||||
for(size_t i=0; i<bnum; i++)
|
||||
{
|
||||
if(bones[i].empty())
|
||||
nif->fail("Oops: Missing bone! Don't know how to handle this.");
|
||||
bones[i]->makeBone(i, data->bones[i]);
|
||||
}
|
||||
}
|
||||
|
||||
} // Namespace
|
@ -0,0 +1,140 @@
|
||||
///File to handle keys used by nif file records
|
||||
|
||||
#ifndef OPENMW_COMPONENTS_NIF_NIFKEY_HPP
|
||||
#define OPENMW_COMPONENTS_NIF_NIFKEY_HPP
|
||||
|
||||
#include <OgreStringConverter.h>
|
||||
|
||||
#include "nifstream.hpp"
|
||||
|
||||
namespace Nif
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct KeyT {
|
||||
float mTime;
|
||||
T mValue;
|
||||
T mForwardValue; // Only for Quadratic interpolation, and never for QuaternionKeyList
|
||||
T mBackwardValue; // Only for Quadratic interpolation, and never for QuaternionKeyList
|
||||
float mTension; // Only for TBC interpolation
|
||||
float mBias; // Only for TBC interpolation
|
||||
float mContinuity; // Only for TBC interpolation
|
||||
};
|
||||
typedef KeyT<float> FloatKey;
|
||||
typedef KeyT<Ogre::Vector3> Vector3Key;
|
||||
typedef KeyT<Ogre::Vector4> Vector4Key;
|
||||
typedef KeyT<Ogre::Quaternion> QuaternionKey;
|
||||
|
||||
template<typename T, T (NIFStream::*getValue)()>
|
||||
struct KeyListT {
|
||||
typedef std::vector< KeyT<T> > VecType;
|
||||
|
||||
static const unsigned int sLinearInterpolation = 1;
|
||||
static const unsigned int sQuadraticInterpolation = 2;
|
||||
static const unsigned int sTBCInterpolation = 3;
|
||||
static const unsigned int sXYZInterpolation = 4;
|
||||
|
||||
unsigned int mInterpolationType;
|
||||
VecType mKeys;
|
||||
|
||||
KeyListT() : mInterpolationType(sLinearInterpolation) {}
|
||||
|
||||
//Read in a KeyGroup (see http://niftools.sourceforge.net/doc/nif/NiKeyframeData.html)
|
||||
void read(NIFStream *nif, bool force=false)
|
||||
{
|
||||
assert(nif);
|
||||
|
||||
mInterpolationType = 0;
|
||||
|
||||
size_t count = nif->getUInt();
|
||||
if(count == 0 && !force)
|
||||
return;
|
||||
|
||||
//If we aren't forcing things, make sure that read clears any previous keys
|
||||
if(!force)
|
||||
mKeys.clear();
|
||||
|
||||
mInterpolationType = nif->getUInt();
|
||||
|
||||
KeyT<T> key;
|
||||
NIFStream &nifReference = *nif;
|
||||
|
||||
if(mInterpolationType == sLinearInterpolation)
|
||||
{
|
||||
for(size_t i = 0;i < count;i++)
|
||||
{
|
||||
readTimeAndValue(nifReference, key);
|
||||
mKeys.push_back(key);
|
||||
}
|
||||
}
|
||||
else if(mInterpolationType == sQuadraticInterpolation)
|
||||
{
|
||||
for(size_t i = 0;i < count;i++)
|
||||
{
|
||||
readQuadratic(nifReference, key);
|
||||
mKeys.push_back(key);
|
||||
}
|
||||
}
|
||||
else if(mInterpolationType == sTBCInterpolation)
|
||||
{
|
||||
for(size_t i = 0;i < count;i++)
|
||||
{
|
||||
readTBC(nifReference, key);
|
||||
mKeys.push_back(key);
|
||||
}
|
||||
}
|
||||
//XYZ keys aren't actually read here.
|
||||
//data.hpp sees that the last type read was sXYZInterpolation and:
|
||||
// Eats a floating point number, then
|
||||
// Re-runs the read function 3 more times, with force enabled so that the previous values aren't cleared.
|
||||
// When it does that it's reading in a bunch of sLinearInterpolation keys, not sXYZInterpolation.
|
||||
else if(mInterpolationType == sXYZInterpolation)
|
||||
{
|
||||
//Don't try to read XYZ keys into the wrong part
|
||||
if ( count != 1 )
|
||||
nif->file->fail("XYZ_ROTATION_KEY count should always be '1' . Retrieved Value: "+Ogre::StringConverter::toString(count));
|
||||
}
|
||||
else if (0 == mInterpolationType)
|
||||
{
|
||||
if (count != 0)
|
||||
nif->file->fail("Interpolation type 0 doesn't work with keys");
|
||||
}
|
||||
else
|
||||
nif->file->fail("Unhandled interpolation type: "+Ogre::StringConverter::toString(mInterpolationType));
|
||||
}
|
||||
|
||||
private:
|
||||
static void readTimeAndValue(NIFStream &nif, KeyT<T> &key)
|
||||
{
|
||||
key.mTime = nif.getFloat();
|
||||
key.mValue = (nif.*getValue)();
|
||||
}
|
||||
|
||||
static void readQuadratic(NIFStream &nif, KeyT<Ogre::Quaternion> &key)
|
||||
{
|
||||
readTimeAndValue(nif, key);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
static void readQuadratic(NIFStream &nif, KeyT<U> &key)
|
||||
{
|
||||
readTimeAndValue(nif, key);
|
||||
key.mForwardValue = (nif.*getValue)();
|
||||
key.mBackwardValue = (nif.*getValue)();
|
||||
}
|
||||
|
||||
static void readTBC(NIFStream &nif, KeyT<T> &key)
|
||||
{
|
||||
readTimeAndValue(nif, key);
|
||||
key.mTension = nif.getFloat();
|
||||
key.mBias = nif.getFloat();
|
||||
key.mContinuity = nif.getFloat();
|
||||
}
|
||||
};
|
||||
typedef KeyListT<float,&NIFStream::getFloat> FloatKeyList;
|
||||
typedef KeyListT<Ogre::Vector3,&NIFStream::getVector3> Vector3KeyList;
|
||||
typedef KeyListT<Ogre::Vector4,&NIFStream::getVector4> Vector4KeyList;
|
||||
typedef KeyListT<Ogre::Quaternion,&NIFStream::getQuaternion> QuaternionKeyList;
|
||||
|
||||
} // Namespace
|
||||
#endif //#ifndef OPENMW_COMPONENTS_NIF_NIFKEY_HPP
|
@ -0,0 +1,57 @@
|
||||
#include "node.hpp"
|
||||
|
||||
namespace Nif
|
||||
{
|
||||
|
||||
void Node::getProperties(const Nif::NiTexturingProperty *&texprop,
|
||||
const Nif::NiMaterialProperty *&matprop,
|
||||
const Nif::NiAlphaProperty *&alphaprop,
|
||||
const Nif::NiVertexColorProperty *&vertprop,
|
||||
const Nif::NiZBufferProperty *&zprop,
|
||||
const Nif::NiSpecularProperty *&specprop,
|
||||
const Nif::NiWireframeProperty *&wireprop) const
|
||||
{
|
||||
if(parent)
|
||||
parent->getProperties(texprop, matprop, alphaprop, vertprop, zprop, specprop, wireprop);
|
||||
|
||||
for(size_t i = 0;i < props.length();i++)
|
||||
{
|
||||
// Entries may be empty
|
||||
if(props[i].empty())
|
||||
continue;
|
||||
|
||||
const Nif::Property *pr = props[i].getPtr();
|
||||
if(pr->recType == Nif::RC_NiTexturingProperty)
|
||||
texprop = static_cast<const Nif::NiTexturingProperty*>(pr);
|
||||
else if(pr->recType == Nif::RC_NiMaterialProperty)
|
||||
matprop = static_cast<const Nif::NiMaterialProperty*>(pr);
|
||||
else if(pr->recType == Nif::RC_NiAlphaProperty)
|
||||
alphaprop = static_cast<const Nif::NiAlphaProperty*>(pr);
|
||||
else if(pr->recType == Nif::RC_NiVertexColorProperty)
|
||||
vertprop = static_cast<const Nif::NiVertexColorProperty*>(pr);
|
||||
else if(pr->recType == Nif::RC_NiZBufferProperty)
|
||||
zprop = static_cast<const Nif::NiZBufferProperty*>(pr);
|
||||
else if(pr->recType == Nif::RC_NiSpecularProperty)
|
||||
specprop = static_cast<const Nif::NiSpecularProperty*>(pr);
|
||||
else if(pr->recType == Nif::RC_NiWireframeProperty)
|
||||
wireprop = static_cast<const Nif::NiWireframeProperty*>(pr);
|
||||
else
|
||||
std::cerr<< "Unhandled property type: "<<pr->recName <<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Ogre::Matrix4 Node::getLocalTransform() const
|
||||
{
|
||||
Ogre::Matrix4 mat4 = Ogre::Matrix4(Ogre::Matrix4::IDENTITY);
|
||||
mat4.makeTransform(trafo.pos, Ogre::Vector3(trafo.scale), Ogre::Quaternion(trafo.rotation));
|
||||
return mat4;
|
||||
}
|
||||
|
||||
Ogre::Matrix4 Node::getWorldTransform() const
|
||||
{
|
||||
if(parent != NULL)
|
||||
return parent->getWorldTransform() * getLocalTransform();
|
||||
return getLocalTransform();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue