@ -34,7 +34,6 @@ namespace Nif
class NiSourceTexture : public Named
{
public :
// Is this an external (references a separate texture file) or
// internal (data is inside the nif itself) texture?
bool external ;
@ -70,8 +69,8 @@ public:
Named : : read ( nif ) ;
external = ! ! nif - > getByte ( ) ;
if ( external ) filename = nif - > getString ( ) ;
if ( external )
filename = nif - > getString ( ) ;
else
{
nif - > getByte ( ) ; // always 1
@ -84,6 +83,12 @@ public:
nif - > getByte ( ) ; // always 1
}
void post ( NIFFile * nif )
{
Named : : post ( nif ) ;
data . post ( nif ) ;
}
} ;
// Common ancestor for several data classes
@ -173,9 +178,11 @@ public:
nif - > getShort ( ) ; // Number of valid entries in the following arrays ?
if ( nif - > getInt ( ) )
{
// Particle sizes
nif - > getFloatLen ( activeCount ) ;
}
}
} ;
class NiRotatingParticlesData : public NiAutoNormalParticlesData
@ -186,11 +193,13 @@ public:
NiAutoNormalParticlesData : : read ( nif ) ;
if ( nif - > getInt ( ) )
{
// Rotation quaternions. I THINK activeCount is correct here,
// but verts (vertex number) might also be correct, if there is
// any case where the two don't match.
nif - > getArrayLen < Vector4 > ( activeCount ) ;
}
}
} ;
class NiPosData : public Record
@ -228,11 +237,9 @@ public:
// also used in FloatData and KeyframeData. We could probably
// reuse and refactor a lot of this if we actually use it at some
// point.
for ( int i = 0 ; i < 2 ; i + + )
{
int count = nif - > getInt ( ) ;
if ( count )
{
nif - > getInt ( ) ; // always 2
@ -345,9 +352,6 @@ public:
data . read ( nif ) ;
root . read ( nif ) ;
bones . read ( nif ) ;
if ( data . empty ( ) | | root . empty ( ) )
nif - > fail ( " NiSkinInstance missing root or data " ) ;
}
void post ( NIFFile * nif ) ;
@ -415,7 +419,6 @@ public:
nif - > getInt ( ) ; // -1
bones . resize ( boneNum ) ;
for ( int i = 0 ; i < boneNum ; i + + )
{
BoneInfo & bi = bones [ i ] ;
@ -439,33 +442,25 @@ class NiMorphData : public Record
std : : vector < std : : vector < Ogre : : Vector3 > > relevantData ;
std : : vector < std : : vector < Ogre : : Vector3 > > additionalVertices ;
public :
float getStartTime ( ) {
return startTime ;
}
float getStopTime ( ) {
return stopTime ;
}
void setStartTime ( float time ) {
startTime = time ;
}
void setStopTime ( float time ) {
stopTime = time ;
}
std : : vector < Ogre : : Vector3 > getInitialVertices ( ) {
return initialVertices ;
}
std : : vector < std : : vector < Ogre : : Vector3 > > getRelevantData ( ) {
return relevantData ;
}
std : : vector < std : : vector < float > > getRelevantTimes ( ) {
return relevantTimes ;
}
std : : vector < std : : vector < Ogre : : Vector3 > > getAdditionalVertices ( ) {
return additionalVertices ;
}
float getStartTime ( ) const
{ return startTime ; }
float getStopTime ( ) const
{ return stopTime ; }
void setStartTime ( float time )
{ startTime = time ; }
void setStopTime ( float time )
{ stopTime = time ; }
const std : : vector < Ogre : : Vector3 > & getInitialVertices ( ) const
{ return initialVertices ; }
const std : : vector < std : : vector < Ogre : : Vector3 > > & getRelevantData ( ) const
{ return relevantData ; }
const std : : vector < std : : vector < float > > & getRelevantTimes ( ) const
{ return relevantTimes ; }
const std : : vector < std : : vector < Ogre : : Vector3 > > & getAdditionalVertices ( ) const
{ return additionalVertices ; }
void read ( NIFFile * nif )
{
@ -474,8 +469,9 @@ void read(NIFFile *nif)
nif - > getByte ( ) ;
int magic = nif - > getInt ( ) ;
/*int type =*/ nif - > getInt ( ) ;
for ( int i = 0 ; i < vertCount ; i + + ) {
for ( int i = 0 ; i < vertCount ; i + + )
{
float x = nif - > getFloat ( ) ;
float y = nif - > getFloat ( ) ;
float z = nif - > getFloat ( ) ;
@ -488,7 +484,8 @@ void read(NIFFile *nif)
/*type =*/ nif - > getInt ( ) ;
std : : vector < Ogre : : Vector3 > current ;
std : : vector < float > currentTime ;
for ( int i = 0 ; i < magic ; i + + ) {
for ( int i = 0 ; i < magic ; i + + )
{
// Time, data, forward, backward tangents
float time = nif - > getFloat ( ) ;
float x = nif - > getFloat ( ) ;
@ -498,12 +495,16 @@ void read(NIFFile *nif)
currentTime . push_back ( time ) ;
//nif->getFloatLen(4*magic);
}
if ( magic ) {
if ( magic )
{
relevantData . push_back ( current ) ;
relevantTimes . push_back ( currentTime ) ;
}
std : : vector < Ogre : : Vector3 > verts ;
for ( int i = 0 ; i < vertCount ; i + + ) {
for ( int i = 0 ; i < vertCount ; i + + )
{
float x = nif - > getFloat ( ) ;
float y = nif - > getFloat ( ) ;
float z = nif - > getFloat ( ) ;
@ -535,7 +536,6 @@ class NiKeyframeData : public Record
int ttype ;
//Scalings
std : : vector < float > scalefactor ;
std : : vector < float > scaletime ;
std : : vector < float > forwards ;
@ -543,10 +543,8 @@ class NiKeyframeData : public Record
std : : vector < Ogre : : Vector3 > tbcscale ;
int stype ;
public :
void clone ( NiKeyframeData c )
void clone ( const NiKeyframeData & c )
{
quats = c . getQuat ( ) ;
tbc = c . getrTbc ( ) ;
@ -565,22 +563,15 @@ public:
transtime = c . gettTime ( ) ;
bonename = c . getBonename ( ) ;
}
void setBonename ( std : : string bone )
{
bonename = bone ;
}
{ bonename = bone ; }
void setStartTime ( float start )
{
startTime = start ;
}
{ startTime = start ; }
void setStopTime ( float end )
{
stopTime = end ;
}
{ stopTime = end ; }
void read ( NIFFile * nif )
{
// Rotations first
@ -589,7 +580,6 @@ public:
//std::vector<float> rottime(count);
if ( count )
{
//TYPE1 LINEAR_KEY
//TYPE2 QUADRATIC_KEY
//TYPE3 TBC_KEY
@ -602,7 +592,8 @@ public:
{
//We need to actually read in these values instead of skipping them
//nif->skip(count*4*5); // time + quaternion
for ( int i = 0 ; i < count ; i + + ) {
for ( int i = 0 ; i < count ; i + + )
{
float time = nif - > getFloat ( ) ;
float w = nif - > getFloat ( ) ;
float x = nif - > getFloat ( ) ;
@ -616,8 +607,10 @@ public:
}
}
else if ( rtype = = 3 )
{ //Example - node 116 in base_anim.nif
for ( int i = 0 ; i < count ; i + + ) {
{
//Example - node 116 in base_anim.nif
for ( int i = 0 ; i < count ; i + + )
{
float time = nif - > getFloat ( ) ;
float w = nif - > getFloat ( ) ;
float x = nif - > getFloat ( ) ;
@ -627,6 +620,7 @@ public:
float tbcx = nif - > getFloat ( ) ;
float tbcy = nif - > getFloat ( ) ;
float tbcz = nif - > getFloat ( ) ;
Ogre : : Quaternion quat = Ogre : : Quaternion ( Ogre : : Real ( w ) , Ogre : : Real ( x ) , Ogre : : Real ( y ) , Ogre : : Real ( z ) ) ;
Ogre : : Vector3 vec = Ogre : : Vector3 ( tbcx , tbcy , tbcz ) ;
quats . push_back ( quat ) ;
@ -635,8 +629,6 @@ public:
//if(time == 0.0 || time > 355.5)
// std::cout <<"Time:" << time << "W:" << w <<"X:" << x << "Y:" << y << "Z:" << z << "\n";
}
//nif->skip(count*4*8); // rot1 + tension+bias+continuity
}
else if ( rtype = = 4 )
{
@ -651,28 +643,32 @@ public:
nif - > skip ( cnt * 4 * 2 ) ; // time + unknown
else if ( type = = 2 )
nif - > skip ( cnt * 4 * 4 ) ; // time + unknown vector
else nif - > fail ( " Unknown sub-rotation type " ) ;
else
nif - > fail ( " Unknown sub-rotation type " ) ;
}
}
}
else nif - > fail ( " Unknown rotation type in NiKeyframeData " ) ;
else
nif - > fail ( " Unknown rotation type in NiKeyframeData " ) ;
}
//first = false;
// Then translation
count = nif - > getInt ( ) ;
if ( count )
{
ttype = nif - > getInt ( ) ;
//std::cout << "TransCount:" << count << " Type: " << type << "\n";
if ( ttype = = 1 ) {
for ( int i = 0 ; i < count ; i + + ) {
if ( ttype = = 1 )
{
for ( int i = 0 ; i < count ; i + + )
{
float time = nif - > getFloat ( ) ;
float x = nif - > getFloat ( ) ;
float y = nif - > getFloat ( ) ;
float z = nif - > getFloat ( ) ;
Ogre : : Vector3 trans = Ogre : : Vector3 ( x , y , z ) ;
translist1 . push_back ( trans ) ;
transtime . push_back ( time ) ;
@ -680,8 +676,10 @@ public:
//nif->getFloatLen(count*4); // time + translation
}
else if ( ttype = = 2 )
{ //Example - node 116 in base_anim.nif
for ( int i = 0 ; i < count ; i + + ) {
{
//Example - node 116 in base_anim.nif
for ( int i = 0 ; i < count ; i + + )
{
float time = nif - > getFloat ( ) ;
float x = nif - > getFloat ( ) ;
float y = nif - > getFloat ( ) ;
@ -692,6 +690,7 @@ public:
float x3 = nif - > getFloat ( ) ;
float y3 = nif - > getFloat ( ) ;
float z3 = nif - > getFloat ( ) ;
Ogre : : Vector3 trans = Ogre : : Vector3 ( x , y , z ) ;
Ogre : : Vector3 trans2 = Ogre : : Vector3 ( x2 , y2 , z2 ) ;
Ogre : : Vector3 trans3 = Ogre : : Vector3 ( x3 , y3 , z3 ) ;
@ -703,8 +702,10 @@ public:
//nif->getFloatLen(count*10); // trans1 + forward + backward
}
else if ( ttype = = 3 ) {
for ( int i = 0 ; i < count ; i + + ) {
else if ( ttype = = 3 )
{
for ( int i = 0 ; i < count ; i + + )
{
float time = nif - > getFloat ( ) ;
float x = nif - > getFloat ( ) ;
float y = nif - > getFloat ( ) ;
@ -729,10 +730,8 @@ public:
{
stype = nif - > getInt ( ) ;
for ( int i = 0 ; i < count ; i + + ) {
for ( int i = 0 ; i < count ; i + + )
{
//int size = 0;
if ( stype > = 1 & & stype < 4 )
{
@ -742,86 +741,70 @@ public:
scalefactor . push_back ( scale ) ;
//size = 2; // time+scale
}
else nif - > fail ( " Unknown scaling type " ) ;
if ( stype = = 2 ) {
else
nif - > fail ( " Unknown scaling type " ) ;
if ( stype = = 2 )
{
//size = 4; // 1 + forward + backward (floats)
float forward = nif - > getFloat ( ) ;
float backward = nif - > getFloat ( ) ;
forwards . push_back ( forward ) ;
backwards . push_back ( backward ) ;
}
else if ( stype = = 3 ) {
else if ( stype = = 3 )
{
//size = 5; // 1 + tbc
float tbcx = nif - > getFloat ( ) ;
float tbcy = nif - > getFloat ( ) ;
float tbcz = nif - > getFloat ( ) ;
Ogre : : Vector3 vec = Ogre : : Vector3 ( tbcx , tbcy , tbcz ) ;
tbcscale . push_back ( vec ) ;
//size = 5; // 1 + tbc
}
}
}
else
stype = 0 ;
}
int getRtype ( ) {
return rtype ;
}
int getStype ( ) {
return stype ;
}
int getTtype ( ) {
return ttype ;
}
float getStartTime ( ) {
return startTime ;
}
float getStopTime ( ) {
return stopTime ;
}
std : : vector < Ogre : : Quaternion > getQuat ( ) {
return quats ;
}
std : : vector < Ogre : : Vector3 > getrTbc ( ) {
return tbc ;
}
std : : vector < float > getrTime ( ) {
return rottime ;
}
std : : vector < Ogre : : Vector3 > getTranslist1 ( ) {
return translist1 ;
}
std : : vector < Ogre : : Vector3 > getTranslist2 ( ) {
return translist2 ;
}
std : : vector < Ogre : : Vector3 > getTranslist3 ( ) {
return translist3 ;
}
std : : vector < float > gettTime ( ) {
return transtime ;
}
std : : vector < float > getScalefactor ( ) {
return scalefactor ;
}
std : : vector < float > getForwards ( ) {
return forwards ;
}
std : : vector < float > getBackwards ( ) {
return backwards ;
}
std : : vector < Ogre : : Vector3 > getScaleTbc ( ) {
return tbcscale ;
}
std : : vector < float > getsTime ( ) {
return scaletime ;
}
std : : string getBonename ( ) { return bonename ;
}
int getRtype ( ) const
{ return rtype ; }
int getStype ( ) const
{ return stype ; }
int getTtype ( ) const
{ return ttype ; }
float getStartTime ( ) const
{ return startTime ; }
float getStopTime ( ) const
{ return stopTime ; }
const std : : vector < Ogre : : Quaternion > & getQuat ( ) const
{ return quats ; }
const std : : vector < Ogre : : Vector3 > & getrTbc ( ) const
{ return tbc ; }
const std : : vector < float > & getrTime ( ) const
{ return rottime ; }
const std : : vector < Ogre : : Vector3 > & getTranslist1 ( ) const
{ return translist1 ; }
const std : : vector < Ogre : : Vector3 > & getTranslist2 ( ) const
{ return translist2 ; }
const std : : vector < Ogre : : Vector3 > & getTranslist3 ( ) const
{ return translist3 ; }
const std : : vector < float > & gettTime ( ) const
{ return transtime ; }
const std : : vector < float > & getScalefactor ( ) const
{ return scalefactor ; }
const std : : vector < float > & getForwards ( ) const
{ return forwards ; }
const std : : vector < float > & getBackwards ( ) const
{ return backwards ; }
const std : : vector < Ogre : : Vector3 > & getScaleTbc ( ) const
{ return tbcscale ; }
const std : : vector < float > & getsTime ( ) const
{ return scaletime ; }
const std : : string & getBonename ( ) const
{ return bonename ; }
} ;
} // Namespace