Remove NIFFile::getType

actorid
Chris Robinson 13 years ago
parent 98ae7168b1
commit 10072f74b4

@ -105,16 +105,16 @@ public:
int verts = nif->getShort();
if(nif->getInt())
vertices = nif->getFloatLen(verts*3);
vertices = nif->getArrayLen<float>(verts*3);
if(nif->getInt())
normals = nif->getFloatLen(verts*3);
normals = nif->getArrayLen<float>(verts*3);
center = nif->getVector();
radius = nif->getFloat();
if(nif->getInt())
colors = nif->getFloatLen(verts*4);
colors = nif->getArrayLen<float>(verts*4);
int uvs = nif->getShort();
@ -123,7 +123,7 @@ public:
uvs &= 0x3f;
if(nif->getInt())
uvlist = nif->getFloatLen(uvs*verts*2);
uvlist = nif->getArrayLen<float>(uvs*verts*2);
}
};
@ -181,7 +181,7 @@ public:
if(nif->getInt())
{
// Particle sizes
nif->getFloatLen(activeCount);
nif->getArrayLen<float>(activeCount);
}
}
};
@ -414,7 +414,9 @@ public:
assert(sizeof(BoneTrafo) == 4*(9+3+1));
assert(sizeof(VertWeight) == 6);
trafo = nif->getType<BoneTrafo>();
trafo.rotation = nif->getMatrix();
trafo.trans = nif->getVector();
trafo.scale = nif->getFloat();
int boneNum = nif->getInt();
nif->getInt(); // -1
@ -424,7 +426,9 @@ public:
{
BoneInfo &bi = bones[i];
bi.trafo = nif->getType<BoneTrafo>();
bi.trafo.rotation = nif->getMatrix();
bi.trafo.trans = nif->getVector();
bi.trafo.scale = nif->getFloat();
bi.unknown = nif->getVector4();
// Number of vertex weights

@ -41,6 +41,14 @@ struct NiLight : Effect
Vector ambient;
Vector diffuse;
Vector specular;
void read(NIFFile *nif)
{
nif->load(dimmer);
ambient = nif->getVector();
diffuse = nif->getVector();
specular = nif->getVector();
}
};
SLight light;
@ -50,7 +58,7 @@ struct NiLight : Effect
nif->getInt(); // 1
nif->getInt(); // 1?
light = nif->getType<SLight>();
light.read(nif);
}
};

@ -56,7 +56,7 @@ public:
/*int i =*/ nif->getInt();
int s = nif->getShort(); // number of vertices
nif->getFloatLen(s); // vertex weights I guess
nif->getArrayLen<float>(s); // vertex weights I guess
}
};

@ -99,20 +99,70 @@ public:
void skip(size_t size) { inp->skip(size); }
template<class X> X getType()
uint32_t read_le32()
{
X obj;
if(inp->read(&obj, sizeof(X)) != sizeof(X))
fail("Failed to read from NIF");
return obj;
uint8_t buffer[4];
if(inp->read(buffer, 4) != 4) return 0;
return buffer[0] | (buffer[1]<<8) | (buffer[2]<<16) | (buffer[3]<<24);
}
uint16_t read_le16()
{
uint8_t buffer[2];
if(inp->read(buffer, 2) != 2) return 0;
return buffer[0] | (buffer[1]<<8);
}
uint8_t read_byte()
{
uint8_t byte;
if(inp->read(&byte, 1) != 1) return 0;
return byte;
}
std::string read_string(size_t length)
{
std::string str;
str.resize(length);
if(inp->read(&str[0], length) != length)
return std::string();
return str.substr(0, str.find('\0'));
}
unsigned short getShort() { return getType<unsigned short>(); }
int getInt() { return getType<int>(); }
float getFloat() { return getType<float>(); }
char getByte() { return getType<char>(); }
template<class X>
std::vector<X> getArrayLen(int num)
char& load(char &c) { c = read_byte(); return c; }
unsigned char& load(unsigned char &c) { c = read_byte(); return c; }
short& load(short &s) { s = read_le16(); return s; }
unsigned short& load(unsigned short &s) { s = read_le16(); return s; }
int& load(int &i) { i = read_le32(); return i; }
unsigned int& load(unsigned int &i) { i = read_le32(); return i; }
float& load(float &f)
{
union {
int i;
float f;
} u = { read_le32() };
f = u.f;
return f;
}
template<typename T, size_t N>
T* load(T (&a)[N])
{
for(size_t i = 0;i < N;i++)
load(a[i]);
return a;
}
template<typename T>
std::vector<T>& load(std::vector<T> &v, size_t size)
{
v.resize(size);
for(size_t i = 0;i < size;i++)
load(v[i]);
return v;
}
template<typename X>
std::vector<X> getArrayLen(size_t num)
{
std::vector<X> v(num);
if(inp->read(&v[0], num*sizeof(X)) != num*sizeof(X))
@ -120,20 +170,47 @@ public:
return v;
}
template<class X>
template<typename X>
std::vector<X> getArray()
{
int len = getInt();
size_t len = read_le32();
return getArrayLen<X>(len);
}
Vector getVector() { return getType<Vector>(); }
Matrix getMatrix() { return getType<Matrix>(); }
Transformation getTrafo() { return getType<Transformation>(); }
Vector4 getVector4() { return getType<Vector4>(); }
char getByte() { char c; return load(c); }
unsigned short getShort() { unsigned short s; return load(s); }
int getInt() { int i; return load(i); }
float getFloat() { float f; return load(f); }
Vector getVector()
{
Vector v;
load(v.array);
return v;
}
Vector4 getVector4()
{
Vector4 v;
load(v.array);
return v;
}
Matrix getMatrix()
{
Matrix m;
m.v[0] = getVector();
m.v[1] = getVector();
m.v[2] = getVector();
return m;
}
Transformation getTrafo()
{
Transformation t;
t.pos = getVector();
t.rotation = getMatrix();
load(t.scale);
t.velocity = getVector();
return t;
}
std::vector<float> getFloatLen(int num)
{ return getArrayLen<float>(num); }
// For fixed-size strings where you already know the size
std::string getString(size_t size)
@ -151,5 +228,14 @@ public:
}
};
template<>
inline std::vector<float> NIFFile::getArrayLen<float>(size_t num)
{
std::vector<float> v(num);
for(size_t i = 0;i < num;i++)
load(v[i]);
return v;
}
} // Namespace
#endif

@ -218,6 +218,23 @@ struct NiCamera : Node
// Level of detail modifier
float LOD;
void read(NIFFile *nif)
{
nif->load(left);
nif->load(right);
nif->load(top);
nif->load(bottom);
nif->load(nearDist);
nif->load(farDist);
nif->load(vleft);
nif->load(vright);
nif->load(vtop);
nif->load(vbottom);
nif->load(LOD);
}
};
Camera cam;
@ -225,7 +242,7 @@ struct NiCamera : Node
{
Node::read(nif);
cam = nif->getType<Camera>();
cam.read(nif);
nif->getInt(); // -1
nif->getInt(); // 0

@ -160,7 +160,7 @@ struct StructPropT : Property
void read(NIFFile *nif)
{
Property::read(nif);
data = nif->getType<T>();
data.read(nif);
}
};
@ -169,6 +169,16 @@ struct S_MaterialProperty
// The vector components are R,G,B
Vector ambient, diffuse, specular, emissive;
float glossiness, alpha;
void read(NIFFile *nif)
{
ambient = nif->getVector();
diffuse = nif->getVector();
specular = nif->getVector();
emissive = nif->getVector();
nif->load(glossiness);
nif->load(alpha);
}
};
struct S_VertexColorProperty
@ -183,6 +193,12 @@ struct S_VertexColorProperty
1 - lighting emmisive ambient/diffuse
*/
int vertmode, lightmode;
void read(NIFFile *nif)
{
nif->load(vertmode);
nif->load(lightmode);
}
};
struct S_AlphaProperty
@ -234,6 +250,11 @@ struct S_AlphaProperty
// Tested against when certain flags are set (see above.)
unsigned char threshold;
void read(NIFFile *nif)
{
nif->load(threshold);
}
};
typedef StructPropT<S_AlphaProperty> NiAlphaProperty;

Loading…
Cancel
Save