NIF reader compiles without Ogre

c++11
scrawl 10 years ago
parent d4dff6ed55
commit 8c10d4badb

@ -221,6 +221,9 @@ if (${OGRE_VERSION} VERSION_LESS "1.9")
message(FATAL_ERROR "OpenMW requires Ogre 1.9 or later, please install the latest stable version from http://ogre3d.org") message(FATAL_ERROR "OpenMW requires Ogre 1.9 or later, please install the latest stable version from http://ogre3d.org")
endif() endif()
find_package(OpenSceneGraph 3.2.0 REQUIRED osgDB)
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})
find_package(MyGUI REQUIRED) find_package(MyGUI REQUIRED)
if (${MYGUI_VERSION} VERSION_LESS "3.2.1") if (${MYGUI_VERSION} VERSION_LESS "3.2.1")
message(FATAL_ERROR "OpenMW requires MyGUI 3.2.1 or later, please install the latest version from http://mygui.info") message(FATAL_ERROR "OpenMW requires MyGUI 3.2.1 or later, please install the latest version from http://mygui.info")

@ -31,24 +31,24 @@ add_component_dir (nifoverrides
) )
add_component_dir (bsa add_component_dir (bsa
bsa_archive bsa_file resources bsa_file
) )
add_component_dir (nif add_component_dir (nif
controlled effect niftypes record controller extra node record_ptr data niffile property nifkey data node base nifstream controlled effect niftypes record controller extra node record_ptr data niffile property nifkey data node base nifstream
) )
add_component_dir (nifcache #add_component_dir (nifcache
nifcache # nifcache
) # )
add_component_dir (nifogre #add_component_dir (nifogre
ogrenifloader skeleton material mesh particles controller # ogrenifloader skeleton material mesh particles controller
) # )
add_component_dir (nifbullet #add_component_dir (nifbullet
bulletnifloader # bulletnifloader
) # )
add_component_dir (to_utf8 add_component_dir (to_utf8
to_utf8 to_utf8
@ -160,7 +160,7 @@ include_directories(${BULLET_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR}) add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR})
target_link_libraries(components ${Boost_LIBRARIES} ${OGRE_LIBRARIES}) target_link_libraries(components ${Boost_LIBRARIES} ${OGRE_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES})
if (GIT_CHECKOUT) if (GIT_CHECKOUT)
add_dependencies (components git-version) add_dependencies (components git-version)

@ -129,8 +129,8 @@ public:
* 1 - Point (fixed origin) * 1 - Point (fixed origin)
*/ */
int mType; int mType;
Ogre::Vector3 mPosition; osg::Vec3f mPosition;
Ogre::Vector3 mDirection; osg::Vec3f mDirection;
void read(NIFStream *nif) void read(NIFStream *nif)
{ {

@ -33,7 +33,7 @@ class NiParticleSystemController : public Controller
{ {
public: public:
struct Particle { struct Particle {
Ogre::Vector3 velocity; osg::Vec3f velocity;
float lifetime; float lifetime;
float lifespan; float lifespan;
float timestamp; float timestamp;
@ -64,7 +64,7 @@ public:
}; };
int emitFlags; int emitFlags;
Ogre::Vector3 offsetRandom; osg::Vec3f offsetRandom;
NodePtr emitter; NodePtr emitter;

@ -33,10 +33,10 @@ namespace Nif
class ShapeData : public Record class ShapeData : public Record
{ {
public: public:
std::vector<Ogre::Vector3> vertices, normals; std::vector<osg::Vec3f> vertices, normals;
std::vector<Ogre::Vector4> colors; std::vector<osg::Vec4f> colors;
std::vector< std::vector<Ogre::Vector2> > uvlist; std::vector< std::vector<osg::Vec2f> > uvlist;
Ogre::Vector3 center; osg::Vec3f center;
float radius; float radius;
void read(NIFStream *nif) void read(NIFStream *nif)
@ -131,7 +131,7 @@ public:
class NiRotatingParticlesData : public NiAutoNormalParticlesData class NiRotatingParticlesData : public NiAutoNormalParticlesData
{ {
public: public:
std::vector<Ogre::Quaternion> rotations; std::vector<osg::Quat> rotations;
void read(NIFStream *nif) void read(NIFStream *nif)
{ {
@ -272,9 +272,9 @@ class NiSkinData : public Record
public: public:
struct BoneTrafo struct BoneTrafo
{ {
Ogre::Matrix3 rotation; // Rotation offset from bone? Matrix3 rotation; // Rotation offset from bone?
Ogre::Vector3 trans; // Translation osg::Vec3f trans; // Translation
float scale; // Probably scale (always 1) float scale; // Scale
}; };
struct VertWeight struct VertWeight
@ -286,7 +286,7 @@ public:
struct BoneInfo struct BoneInfo
{ {
BoneTrafo trafo; BoneTrafo trafo;
Ogre::Vector4 unknown; osg::Vec4f unknown;
std::vector<VertWeight> weights; std::vector<VertWeight> weights;
}; };
@ -327,7 +327,7 @@ struct NiMorphData : public Record
{ {
struct MorphData { struct MorphData {
FloatKeyMap mData; FloatKeyMap mData;
std::vector<Ogre::Vector3> mVertices; std::vector<osg::Vec3f> mVertices;
}; };
std::vector<MorphData> mMorphs; std::vector<MorphData> mMorphs;

@ -38,9 +38,9 @@ struct NiLight : Effect
struct SLight struct SLight
{ {
float dimmer; float dimmer;
Ogre::Vector3 ambient; osg::Vec3f ambient;
Ogre::Vector3 diffuse; osg::Vec3f diffuse;
Ogre::Vector3 specular; osg::Vec3f specular;
void read(NIFStream *nif) void read(NIFStream *nif)
{ {

@ -2,16 +2,16 @@
#include "effect.hpp" #include "effect.hpp"
#include <map> #include <map>
#include <sstream>
#include <OgreResourceGroupManager.h>
namespace Nif namespace Nif
{ {
/// Open a NIF stream. The name is used for error messages. /// Open a NIF stream. The name is used for error messages.
NIFFile::NIFFile(const std::string &name) NIFFile::NIFFile(Files::IStreamPtr stream, const std::string &name)
: ver(0) : ver(0)
, filename(name) , filename(name)
, mStream(stream)
{ {
parse(); parse();
} }
@ -121,63 +121,68 @@ std::string NIFFile::printVersion(unsigned int version)
version_out.full = version; version_out.full = version;
return Ogre::StringConverter::toString(version_out.quad[3]) std::stringstream stream;
+"." + Ogre::StringConverter::toString(version_out.quad[2]) stream << version_out.quad[3] << "."
+"." + Ogre::StringConverter::toString(version_out.quad[1]) << version_out.quad[2] << "."
+"." + Ogre::StringConverter::toString(version_out.quad[0]); << version_out.quad[1] << "."
<< version_out.quad[0];
return stream.str();
} }
void NIFFile::parse() void NIFFile::parse()
{ {
NIFStream nif (this, Ogre::ResourceGroupManager::getSingleton().openResource(filename)); NIFStream nif (this, mStream);
// Check the header string // Check the header string
std::string head = nif.getVersionString(); std::string head = nif.getVersionString();
if(head.compare(0, 22, "NetImmerse File Format") != 0) if(head.compare(0, 22, "NetImmerse File Format") != 0)
fail("Invalid NIF header: " + head); fail("Invalid NIF header: " + head);
// Get BCD version // Get BCD version
ver = nif.getUInt(); ver = nif.getUInt();
if(ver != VER_MW) if(ver != VER_MW)
fail("Unsupported NIF version: " + printVersion(ver)); fail("Unsupported NIF version: " + printVersion(ver));
// Number of records // Number of records
size_t recNum = nif.getInt(); size_t recNum = nif.getInt();
records.resize(recNum); records.resize(recNum);
/* The format for 10.0.1.0 seems to be a bit different. After the /* The format for 10.0.1.0 seems to be a bit different. After the
header, it contains the number of records, r (int), just like header, it contains the number of records, r (int), just like
4.0.0.2, but following that it contains a short x, followed by x 4.0.0.2, but following that it contains a short x, followed by x
strings. Then again by r shorts, one for each record, giving strings. Then again by r shorts, one for each record, giving
which of the above strings to use to identify the record. After which of the above strings to use to identify the record. After
this follows two ints (zero?) and then the record data. However this follows two ints (zero?) and then the record data. However
we do not support or plan to support other versions yet. we do not support or plan to support other versions yet.
*/ */
for(size_t i = 0;i < recNum;i++) for(size_t i = 0;i < recNum;i++)
{ {
Record *r = NULL; Record *r = NULL;
std::string rec = nif.getString();
if(rec.empty())
fail("Record number " + Ogre::StringConverter::toString(i) + " out of " + Ogre::StringConverter::toString(recNum) + " is blank.");
std::string rec = nif.getString();
if(rec.empty())
{
std::stringstream error;
error << "Record number " << i << " out of " << recNum << " is blank.";
fail(error.str());
}
std::map<std::string,RecordFactoryEntry>::const_iterator entry = factories.find(rec); std::map<std::string,RecordFactoryEntry>::const_iterator entry = factories.find(rec);
if (entry != factories.end())
{
r = entry->second.mCreate ();
r->recType = entry->second.mType;
}
else
fail("Unknown record type " + rec);
assert(r != NULL); if (entry != factories.end())
assert(r->recType != RC_MISSING); {
r->recName = rec; r = entry->second.mCreate ();
r->recIndex = i; r->recType = entry->second.mType;
records[i] = r; }
r->read(&nif); else
fail("Unknown record type " + rec);
assert(r != NULL);
assert(r->recType != RC_MISSING);
r->recName = rec;
r->recIndex = i;
records[i] = r;
r->read(&nif);
} }
size_t rootNum = nif.getUInt(); size_t rootNum = nif.getUInt();

@ -7,6 +7,8 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include <components/files/constrainedfilestream.hpp>
#include "record.hpp" #include "record.hpp"
namespace Nif namespace Nif
@ -42,6 +44,8 @@ class NIFFile
///\overload ///\overload
void operator = (NIFFile const &); void operator = (NIFFile const &);
Files::IStreamPtr mStream;
public: public:
/// Used if file parsing fails /// Used if file parsing fails
void fail(const std::string &msg) void fail(const std::string &msg)
@ -57,8 +61,8 @@ public:
<< "File: " << filename <<std::endl; << "File: " << filename <<std::endl;
} }
/// Open a NIF stream. The name is used for error messages and opening the file. /// Open a NIF stream. The name is used for error messages.
NIFFile(const std::string &name); NIFFile(Files::IStreamPtr stream, const std::string &name);
~NIFFile(); ~NIFFile();
/// Get a given record /// Get a given record

@ -3,26 +3,27 @@
#ifndef OPENMW_COMPONENTS_NIF_NIFKEY_HPP #ifndef OPENMW_COMPONENTS_NIF_NIFKEY_HPP
#define OPENMW_COMPONENTS_NIF_NIFKEY_HPP #define OPENMW_COMPONENTS_NIF_NIFKEY_HPP
#include <OgreStringConverter.h>
#include "nifstream.hpp" #include "nifstream.hpp"
#include <sstream>
#include <map>
namespace Nif namespace Nif
{ {
template<typename T> template<typename T>
struct KeyT { struct KeyT {
T mValue; T mValue;
// FIXME: Implement Quadratic and TBC interpolation
/*
T mForwardValue; // Only for Quadratic interpolation, and never for QuaternionKeyList T mForwardValue; // Only for Quadratic interpolation, and never for QuaternionKeyList
T mBackwardValue; // 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 mTension; // Only for TBC interpolation
float mBias; // Only for TBC interpolation float mBias; // Only for TBC interpolation
float mContinuity; // 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)()> template<typename T, T (NIFStream::*getValue)()>
struct KeyMapT { struct KeyMapT {
@ -92,7 +93,12 @@ struct KeyMapT {
{ {
//Don't try to read XYZ keys into the wrong part //Don't try to read XYZ keys into the wrong part
if ( count != 1 ) if ( count != 1 )
nif->file->fail("XYZ_ROTATION_KEY count should always be '1' . Retrieved Value: "+Ogre::StringConverter::toString(count)); {
std::stringstream error;
error << "XYZ_ROTATION_KEY count should always be '1' . Retrieved Value: "
<< count;
nif->file->fail(error.str());
}
} }
else if (0 == mInterpolationType) else if (0 == mInterpolationType)
{ {
@ -100,7 +106,11 @@ struct KeyMapT {
nif->file->fail("Interpolation type 0 doesn't work with keys"); nif->file->fail("Interpolation type 0 doesn't work with keys");
} }
else else
nif->file->fail("Unhandled interpolation type: "+Ogre::StringConverter::toString(mInterpolationType)); {
std::stringstream error;
error << "Unhandled interpolation type: " << mInterpolationType;
nif->file->fail(error.str());
}
} }
private: private:
@ -109,31 +119,26 @@ private:
key.mValue = (nif.*getValue)(); key.mValue = (nif.*getValue)();
} }
static void readQuadratic(NIFStream &nif, KeyT<Ogre::Quaternion> &key)
{
readValue(nif, key);
}
template <typename U> template <typename U>
static void readQuadratic(NIFStream &nif, KeyT<U> &key) static void readQuadratic(NIFStream &nif, KeyT<U> &key)
{ {
readValue(nif, key); readValue(nif, key);
key.mForwardValue = (nif.*getValue)(); /*key.mForwardValue = */(nif.*getValue)();
key.mBackwardValue = (nif.*getValue)(); /*key.mBackwardValue = */(nif.*getValue)();
} }
static void readTBC(NIFStream &nif, KeyT<T> &key) static void readTBC(NIFStream &nif, KeyT<T> &key)
{ {
readValue(nif, key); readValue(nif, key);
key.mTension = nif.getFloat(); /*key.mTension = */nif.getFloat();
key.mBias = nif.getFloat(); /*key.mBias = */nif.getFloat();
key.mContinuity = nif.getFloat(); /*key.mContinuity = */nif.getFloat();
} }
}; };
typedef KeyMapT<float,&NIFStream::getFloat> FloatKeyMap; typedef KeyMapT<float,&NIFStream::getFloat> FloatKeyMap;
typedef KeyMapT<Ogre::Vector3,&NIFStream::getVector3> Vector3KeyMap; typedef KeyMapT<osg::Vec3f,&NIFStream::getVector3> Vector3KeyMap;
typedef KeyMapT<Ogre::Vector4,&NIFStream::getVector4> Vector4KeyMap; typedef KeyMapT<osg::Vec4f,&NIFStream::getVector4> Vector4KeyMap;
typedef KeyMapT<Ogre::Quaternion,&NIFStream::getQuaternion> QuaternionKeyMap; typedef KeyMapT<osg::Quat,&NIFStream::getQuaternion> QuaternionKeyMap;
} // Namespace } // Namespace
#endif //#ifndef OPENMW_COMPONENTS_NIF_NIFKEY_HPP #endif //#ifndef OPENMW_COMPONENTS_NIF_NIFKEY_HPP

@ -9,19 +9,19 @@ namespace Nif
uint8_t NIFStream::read_byte() uint8_t NIFStream::read_byte()
{ {
uint8_t byte; uint8_t byte;
if(inp->read(&byte, 1) != 1) return 0; inp->read((char*)&byte, 1);
return byte; return byte;
} }
uint16_t NIFStream::read_le16() uint16_t NIFStream::read_le16()
{ {
uint8_t buffer[2]; uint8_t buffer[2];
if(inp->read(buffer, 2) != 2) return 0; inp->read((char*)buffer, 2);
return buffer[0] | (buffer[1]<<8); return buffer[0] | (buffer[1]<<8);
} }
uint32_t NIFStream::read_le32() uint32_t NIFStream::read_le32()
{ {
uint8_t buffer[4]; uint8_t buffer[4];
if(inp->read(buffer, 4) != 4) return 0; inp->read((char*)buffer, 4);
return buffer[0] | (buffer[1]<<8) | (buffer[2]<<16) | (buffer[3]<<24); return buffer[0] | (buffer[1]<<8) | (buffer[2]<<16) | (buffer[3]<<24);
} }
float NIFStream::read_le32f() float NIFStream::read_le32f()
@ -34,43 +34,45 @@ float NIFStream::read_le32f()
} }
//Public functions //Public functions
Ogre::Vector2 NIFStream::getVector2() osg::Vec2f NIFStream::getVector2()
{ {
float a[2]; osg::Vec2f vec;
for(size_t i = 0;i < 2;i++) for(size_t i = 0;i < 2;i++)
a[i] = getFloat(); vec._v[i] = getFloat();
return Ogre::Vector2(a); return vec;
} }
Ogre::Vector3 NIFStream::getVector3() osg::Vec3f NIFStream::getVector3()
{ {
float a[3]; osg::Vec3f vec;
for(size_t i = 0;i < 3;i++) for(size_t i = 0;i < 3;i++)
a[i] = getFloat(); vec._v[i] = getFloat();
return Ogre::Vector3(a); return vec;
} }
Ogre::Vector4 NIFStream::getVector4() osg::Vec4f NIFStream::getVector4()
{ {
float a[4]; osg::Vec4f vec;
for(size_t i = 0;i < 4;i++) for(size_t i = 0;i < 4;i++)
a[i] = getFloat(); vec._v[i] = getFloat();
return Ogre::Vector4(a); return vec;
} }
Ogre::Matrix3 NIFStream::getMatrix3() Matrix3 NIFStream::getMatrix3()
{ {
Ogre::Real a[3][3]; Matrix3 mat;
for(size_t i = 0;i < 3;i++) for(size_t i = 0;i < 3;i++)
{ {
for(size_t j = 0;j < 3;j++) for(size_t j = 0;j < 3;j++)
a[i][j] = Ogre::Real(getFloat()); mat.mValues[i][j] = getFloat();
} }
return Ogre::Matrix3(a); return mat;
} }
Ogre::Quaternion NIFStream::getQuaternion() osg::Quat NIFStream::getQuaternion()
{ {
float a[4]; osg::Quat quat;
for(size_t i = 0;i < 4;i++) quat.w() = getFloat();
a[i] = getFloat(); quat.x() = getFloat();
return Ogre::Quaternion(a); quat.y() = getFloat();
quat.z() = getFloat();
return quat;
} }
Transformation NIFStream::getTrafo() Transformation NIFStream::getTrafo()
{ {
@ -83,16 +85,9 @@ Transformation NIFStream::getTrafo()
std::string NIFStream::getString(size_t length) std::string NIFStream::getString(size_t length)
{ {
//Make sure we're not reading in too large of a string
unsigned int fileSize = inp->size();
if(fileSize != 0 && fileSize < length)
file->fail("Attempted to read a string with " + Ogre::StringConverter::toString(length) + " characters , but file is only "+Ogre::StringConverter::toString(fileSize)+ " bytes!");
std::vector<char> str (length+1, 0); std::vector<char> str (length+1, 0);
if(inp->read(&str[0], length) != length) inp->read(&str[0], length);
throw std::runtime_error (": String length in NIF file "+ file->getFilename() +" does not match! Expected length: "
+ Ogre::StringConverter::toString(length));
return &str[0]; return &str[0];
} }
@ -103,7 +98,9 @@ std::string NIFStream::getString()
} }
std::string NIFStream::getVersionString() std::string NIFStream::getVersionString()
{ {
return inp->getLine(); std::string result;
std::getline(*inp, result);
return result;
} }
void NIFStream::getShorts(std::vector<short> &vec, size_t size) void NIFStream::getShorts(std::vector<short> &vec, size_t size)
@ -118,25 +115,25 @@ void NIFStream::getFloats(std::vector<float> &vec, size_t size)
for(size_t i = 0;i < vec.size();i++) for(size_t i = 0;i < vec.size();i++)
vec[i] = getFloat(); vec[i] = getFloat();
} }
void NIFStream::getVector2s(std::vector<Ogre::Vector2> &vec, size_t size) void NIFStream::getVector2s(std::vector<osg::Vec2f> &vec, size_t size)
{ {
vec.resize(size); vec.resize(size);
for(size_t i = 0;i < vec.size();i++) for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector2(); vec[i] = getVector2();
} }
void NIFStream::getVector3s(std::vector<Ogre::Vector3> &vec, size_t size) void NIFStream::getVector3s(std::vector<osg::Vec3f> &vec, size_t size)
{ {
vec.resize(size); vec.resize(size);
for(size_t i = 0;i < vec.size();i++) for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector3(); vec[i] = getVector3();
} }
void NIFStream::getVector4s(std::vector<Ogre::Vector4> &vec, size_t size) void NIFStream::getVector4s(std::vector<osg::Vec4f> &vec, size_t size)
{ {
vec.resize(size); vec.resize(size);
for(size_t i = 0;i < vec.size();i++) for(size_t i = 0;i < vec.size();i++)
vec[i] = getVector4(); vec[i] = getVector4();
} }
void NIFStream::getQuaternions(std::vector<Ogre::Quaternion> &quat, size_t size) void NIFStream::getQuaternions(std::vector<osg::Quat> &quat, size_t size)
{ {
quat.resize(size); quat.resize(size);
for(size_t i = 0;i < quat.size();i++) for(size_t i = 0;i < quat.size();i++)

@ -5,14 +5,13 @@
#include <stdint.h> #include <stdint.h>
#include <stdexcept> #include <stdexcept>
#include <vector>
#include <OgreDataStream.h> #include <components/files/constrainedfilestream.hpp>
#include <OgreVector2.h>
#include <OgreVector3.h> #include <osg/Vec3f>
#include <OgreVector4.h> #include <osg/Vec4f>
#include <OgreMatrix3.h> #include <osg/Quat>
#include <OgreQuaternion.h>
#include <OgreStringConverter.h>
#include "niftypes.hpp" #include "niftypes.hpp"
@ -24,7 +23,7 @@ class NIFFile;
class NIFStream { class NIFStream {
/// Input stream /// Input stream
Ogre::DataStreamPtr inp; Files::IStreamPtr inp;
uint8_t read_byte(); uint8_t read_byte();
uint16_t read_le16(); uint16_t read_le16();
@ -35,9 +34,9 @@ public:
NIFFile * const file; NIFFile * const file;
NIFStream (NIFFile * file, Ogre::DataStreamPtr inp): file (file), inp (inp) {} NIFStream (NIFFile * file, Files::IStreamPtr inp): file (file), inp (inp) {}
void skip(size_t size) { inp->skip(size); } void skip(size_t size) { inp->ignore(size); }
char getChar() { return read_byte(); } char getChar() { return read_byte(); }
short getShort() { return read_le16(); } short getShort() { return read_le16(); }
@ -46,11 +45,11 @@ public:
unsigned int getUInt() { return read_le32(); } unsigned int getUInt() { return read_le32(); }
float getFloat() { return read_le32f(); } float getFloat() { return read_le32f(); }
Ogre::Vector2 getVector2(); osg::Vec2f getVector2();
Ogre::Vector3 getVector3(); osg::Vec3f getVector3();
Ogre::Vector4 getVector4(); osg::Vec4f getVector4();
Ogre::Matrix3 getMatrix3(); Matrix3 getMatrix3();
Ogre::Quaternion getQuaternion(); osg::Quat getQuaternion();
Transformation getTrafo(); Transformation getTrafo();
///Read in a string of the given length ///Read in a string of the given length
@ -62,10 +61,10 @@ public:
void getShorts(std::vector<short> &vec, size_t size); void getShorts(std::vector<short> &vec, size_t size);
void getFloats(std::vector<float> &vec, size_t size); void getFloats(std::vector<float> &vec, size_t size);
void getVector2s(std::vector<Ogre::Vector2> &vec, size_t size); void getVector2s(std::vector<osg::Vec2f> &vec, size_t size);
void getVector3s(std::vector<Ogre::Vector3> &vec, size_t size); void getVector3s(std::vector<osg::Vec3f> &vec, size_t size);
void getVector4s(std::vector<Ogre::Vector4> &vec, size_t size); void getVector4s(std::vector<osg::Vec4f> &vec, size_t size);
void getQuaternions(std::vector<Ogre::Quaternion> &quat, size_t size); void getQuaternions(std::vector<osg::Quat> &quat, size_t size);
}; };
} }

@ -24,24 +24,35 @@
#ifndef OPENMW_COMPONENTS_NIF_NIFTYPES_HPP #ifndef OPENMW_COMPONENTS_NIF_NIFTYPES_HPP
#define OPENMW_COMPONENTS_NIF_NIFTYPES_HPP #define OPENMW_COMPONENTS_NIF_NIFTYPES_HPP
#include <OgreVector3.h> #include <osg/Vec3f>
#include <OgreMatrix3.h>
// Common types used in NIF files // Common types used in NIF files
namespace Nif namespace Nif
{ {
struct Matrix3
{
float mValues[3][3];
Matrix3()
{
for (int i=0;i<3;++i)
for (int j=0;j<3;++j)
mValues[i][j] = 0;
}
};
struct Transformation struct Transformation
{ {
Ogre::Vector3 pos; osg::Vec3f pos;
Ogre::Matrix3 rotation; Matrix3 rotation;
float scale; float scale;
static const Transformation& getIdentity() static const Transformation& getIdentity()
{ {
static const Transformation identity = { static const Transformation identity = {
Ogre::Vector3::ZERO, Ogre::Matrix3::IDENTITY, 1.0f osg::Vec3f(), Matrix3(), 1.0f
}; };
return identity; return identity;
} }

@ -1,60 +1,2 @@
#include "node.hpp" #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 Nif::NiStencilProperty *&stencilprop) const
{
if(parent)
parent->getProperties(texprop, matprop, alphaprop, vertprop, zprop, specprop, wireprop, stencilprop);
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 if (pr->recType == Nif::RC_NiStencilProperty)
stencilprop = static_cast<const Nif::NiStencilProperty*>(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();
}
}

@ -1,8 +1,6 @@
#ifndef OPENMW_COMPONENTS_NIF_NODE_HPP #ifndef OPENMW_COMPONENTS_NIF_NODE_HPP
#define OPENMW_COMPONENTS_NIF_NODE_HPP #define OPENMW_COMPONENTS_NIF_NODE_HPP
#include <OgreMatrix4.h>
#include "controlled.hpp" #include "controlled.hpp"
#include "extra.hpp" #include "extra.hpp"
#include "data.hpp" #include "data.hpp"
@ -26,14 +24,14 @@ public:
// Node flags. Interpretation depends somewhat on the type of node. // Node flags. Interpretation depends somewhat on the type of node.
int flags; int flags;
Transformation trafo; Transformation trafo;
Ogre::Vector3 velocity; // Unused? Might be a run-time game state osg::Vec3f velocity; // Unused? Might be a run-time game state
PropertyList props; PropertyList props;
// Bounding box info // Bounding box info
bool hasBounds; bool hasBounds;
Ogre::Vector3 boundPos; osg::Vec3f boundPos;
Ogre::Matrix3 boundRot; Matrix3 boundRot;
Ogre::Vector3 boundXYZ; // Box size osg::Vec3f boundXYZ; // Box size
void read(NIFStream *nif) void read(NIFStream *nif)
{ {
@ -91,18 +89,6 @@ public:
boneTrafo = &bi.trafo; boneTrafo = &bi.trafo;
boneIndex = ind; boneIndex = ind;
} }
void 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 Nif::NiStencilProperty *&stencilprop) const;
Ogre::Matrix4 getLocalTransform() const;
Ogre::Matrix4 getWorldTransform() const;
}; };
struct NiNode : Node struct NiNode : Node

@ -159,7 +159,7 @@ class NiFogProperty : public Property
{ {
public: public:
float mFogDepth; float mFogDepth;
Ogre::Vector3 mColour; osg::Vec3f mColour;
void read(NIFStream *nif) void read(NIFStream *nif)
@ -194,7 +194,7 @@ struct StructPropT : Property
struct S_MaterialProperty struct S_MaterialProperty
{ {
// The vector components are R,G,B // The vector components are R,G,B
Ogre::Vector3 ambient, diffuse, specular, emissive; osg::Vec3f ambient, diffuse, specular, emissive;
float glossiness, alpha; float glossiness, alpha;
void read(NIFStream *nif) void read(NIFStream *nif)
@ -265,14 +265,6 @@ struct S_AlphaProperty
Taken from: Taken from:
http://niftools.sourceforge.net/doc/nif/NiAlphaProperty.html http://niftools.sourceforge.net/doc/nif/NiAlphaProperty.html
Right now we only use standard alpha blending (see the Ogre code
that sets it up) and it appears that this is the only blending
used in the original game. Bloodmoon (along with several mods) do
however use other settings, such as discarding pixel values with
alpha < 1.0. This is faster because we don't have to mess with the
depth stuff like we did for blending. And OGRE has settings for
this too.
*/ */
// Tested against when certain flags are set (see above.) // Tested against when certain flags are set (see above.)

Loading…
Cancel
Save