More test output: NiSkinInstance and NiSkinData

actorid
Nicolay Korslund 15 years ago
parent b4eefb6ca3
commit ef69584793

@ -321,29 +321,57 @@ struct NiVisData : Record
struct NiSkinData : Record
{
// This is to make sure the structs are packed, ie. that the
// compiler doesn't mess them up with extra alignment bytes.
#pragma pack(push)
#pragma pack(1)
struct BoneTrafo
{
Matrix rotation; // Rotation offset from bone?
Vector trans; // Translation
float scale; // Probably scale (always 1)
};
struct VertWeight
{
short vertex;
float weight;
};
#pragma pack(pop)
struct BoneInfo
{
const BoneTrafo *trafo;
const Vector4 *unknown;
SliceArray<VertWeight> weights;
};
const BoneTrafo *trafo;
std::vector<BoneInfo> bones;
void read(NIFFile *nif)
{
// Not really decoded fully.
nif->getMatrix(); // global skin rotation?
nif->getVector(); // skin translation
nif->getFloat(); // probably scale (always 1)
assert(sizeof(BoneTrafo) == 4*(9+3+1));
assert(sizeof(VertWeight) == 6);
int bones = nif->getInt();
trafo = nif->getPtr<BoneTrafo>();
int boneNum = nif->getInt();
nif->getInt(); // -1
for(int i=0;i<bones;i++)
bones.resize(boneNum);
for(int i=0;i<boneNum;i++)
{
nif->getMatrix(); // skin rotation offset from this bone
nif->getVector(); // translation
nif->getFloat(); // scale
BoneInfo &bi = bones[i];
nif->getVector4();
bi.trafo = nif->getPtr<BoneTrafo>();
bi.unknown = nif->getVector4();
// Number of vertex weights
int count = nif->getShort();
// Each weight is a vertex index (short) and a weight (float)
nif->skip(count*6);
bi.weights = nif->getArrayLen<VertWeight>(count);
}
}
};

@ -135,7 +135,7 @@ void NIFFile::parse()
else if(rec == "NiPixelData") { r = new NiPixelData; r->recType = RC_NiPixelData; }
else if(rec == "NiMorphData") { r = new NiMorphData; r->recType = RC_NiMorphData; }
else if(rec == "NiKeyframeData") { r = new NiKeyframeData; r->recType = RC_NiKeyframeData; }
else if(rec == "NiSkinData") { r = new NiSkinData; r->recType = RC_NiSkindata; }
else if(rec == "NiSkinData") { r = new NiSkinData; r->recType = RC_NiSkinData; }
else if(rec == "NiUVData") { r = new NiUVData; r->recType = RC_NiUVData; }
else if(rec == "NiPosData") { r = new NiPosData; r->recType = RC_NiPosData; }
else if(rec == "NiRotatingParticlesData") { r = new NiRotatingParticlesData; r->recType = RC_NiRotatingParticlesData; }

@ -72,7 +72,7 @@ enum RecordType
RC_NiPixelData,
RC_NiMorphData,
RC_NiKeyframeData,
RC_NiSkindata,
RC_NiSkinData,
RC_NiUVData,
RC_NiPosData,
RC_NiRotatingParticlesData,

@ -2,3 +2,4 @@ niftool
*_test
*.nif
*.kf
output.txt

@ -8,11 +8,15 @@
#include "../../mangle/stream/servers/file_stream.h"
#include "../node.h"
#include "../controller.h"
#include "../data.h"
using namespace Mangle::Stream;
using namespace std;
using namespace Nif;
// Display very verbose information
bool verbose = false;
void doVector(const Vector *vec)
{
cout << "["
@ -21,6 +25,15 @@ void doVector(const Vector *vec)
<< vec->array[2] << "]\n";
}
void doVector4(const Vector4 *vec)
{
cout << "["
<< vec->array[0] << ","
<< vec->array[1] << ","
<< vec->array[2] << ","
<< vec->array[3] << "]\n";
}
void doMatrix(const Matrix *mat)
{
cout << "Matrix:\n";
@ -79,6 +92,54 @@ void doNode(Node *n)
}
}
void doNiTriShape(NiTriShape *n)
{
doNode(n);
cout << "Shape data: " << n->data.getIndex() << endl;
cout << "Skin instance: " << n->skin.getIndex() << endl;
}
void doNiSkinData(NiSkinData *n)
{
int c = n->bones.size();
cout << "Global transformation:\n";
doMatrix(&n->trafo->rotation);
doVector(&n->trafo->trans);
cout << "Scale: " << n->trafo->scale << endl;
cout << "Bone number: " << c << endl;
for(int i=0; i<c; i++)
{
NiSkinData::BoneInfo &bi = n->bones[i];
cout << "-- Bone " << i << ":\n";
doMatrix(&bi.trafo->rotation);
doVector(&bi.trafo->trans);
cout << "Scale: " << bi.trafo->scale << endl;
cout << "Unknown: "; doVector4(bi.unknown);
cout << "Weight number: " << bi.weights.length << endl;
if(verbose)
for(int j=0; j<bi.weights.length; j++)
{
const NiSkinData::VertWeight &w = bi.weights.ptr[j];
cout << " vert:" << w.vertex << " weight:" << w.weight << endl;
}
}
}
void doNiSkinInstance(NiSkinInstance *n)
{
cout << "Data: " << n->data.getIndex() << endl;
cout << "Root: " << n->root.getIndex() << endl;
cout << "Bones:";
for(int i=0; i<n->bones.length(); i++)
cout << " " << n->bones.getIndex(i);
cout << endl;
}
void doNiNode(NiNode *n)
{
doNode(n);
@ -148,6 +209,9 @@ int main(int argc, char **args)
switch(r->recType)
{
case RC_NiNode: doNiNode((NiNode*)r); break;
case RC_NiSkinData: doNiSkinData((NiSkinData*)r); break;
case RC_NiSkinInstance: doNiSkinInstance((NiSkinInstance*)r); break;
case RC_NiTriShape: doNiTriShape((NiTriShape*)r); break;
case RC_NiStringExtraData: doNiStringExtraData((NiStringExtraData*)r); break;
case RC_NiSequenceStreamHelper: doNamed((Named*)r); break;
case RC_NiTextKeyExtraData: doNiTextKeyExtraData((NiTextKeyExtraData*)r); break;

Loading…
Cancel
Save