Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<vector>
- #include<string>
- using namespace std;
- struct Header {
- //Structure for header on skl files
- char fileType[8];
- int numObjects;
- int skeletonHash;
- int numElements;
- };
- struct Bone {
- //Structure for a bone in skl files
- char name[32];
- int parent;
- float scale;
- float matrix[3][4];
- };
- struct SkinModelHeader {
- //Structure for the Header in skn files
- int magic;
- short numMaterials;
- short numObjects;
- };
- struct SkinModelMaterial {
- //Structure for a material block in skn files
- int matIndex;
- char name[64];
- int startVertex;
- int numVertices;
- int startIndex;
- int numIndices;
- };
- struct SkinModelVertex {
- //Vertex block in skn files
- float position[3];
- char boneIndex[4];
- float weights[4];
- float normal[3];
- float texcoords[2];
- };
- struct SkinModelData {
- //data block in skn files
- int numIndices;
- int numVertices;
- vector<short> indices;
- vector<SkinModelVertex> verteces;
- };
- struct SkinModel {
- //Skin model data structure
- SkinModelHeader header;
- vector<SkinModelMaterial> materials;
- SkinModelData modelData;
- void importSkn(string infile) {
- //import from .skn file
- ifstream fin;
- fin.open(infile.c_str(), ios::binary);
- if (fin.fail()) {
- cout << "ERROR: could not open " << infile << endl;
- exit(1);
- }
- fin.read((char*)(void*)&header,sizeof(SkinModelHeader));
- if (header.magic != 1122867) {
- cout << "ERROR: " << infile << " is not a valid skn file" << endl;
- exit(1);
- }
- //for (int i = 0; i < header.numMaterials; i++) {
- if (header.numMaterials) {
- SkinModelMaterial mat;
- fin.read((char*)(void*)&mat, sizeof(SkinModelMaterial));
- materials.push_back(mat);
- }
- fin.read((char*)(void*)&modelData.numIndices,4);
- fin.read((char*)(void*)&modelData.numVertices,4);
- for (int i = 0; i < modelData.numIndices; i++) {
- short idx;
- fin.read((char*)(void*)&idx, 2);
- modelData.indices.push_back(idx);
- }
- for (int i = 0; i < modelData.numVertices; i++) {
- SkinModelVertex vtx;
- fin.read((char*)(void*)&vtx,sizeof(SkinModelVertex));
- modelData.verteces.push_back(vtx);
- }
- }
- };
- struct AnimationHeader {
- char filetype[8];
- int three;
- int magic;
- int numBones;
- int numFrames;
- int fps;
- };
- struct AnimationFrame {
- float quat[4];
- float position[3];
- };
- struct AnimationBone {
- char boneName[32];
- int boneID;
- };
- void quat2mat(const float* quat, float mat[3][4]) {
- float X = quat[0];
- float Y = quat[1];
- float Z = quat[2];
- float W = quat[3];
- float xx = X * X;
- float xy = X * Y;
- float xz = X * Z;
- float xw = X * W;
- float yy = Y * Y;
- float yz = Y * Z;
- float yw = Y * W;
- float zz = Z * Z;
- float zw = Z * W;
- mat[0][0] = 1 - 2 * ( yy + zz );
- mat[0][1] = 2 * ( xy - zw );
- mat[0][2] = 2 * ( xz + yw );
- mat[1][0] = 2 * ( xy + zw );
- mat[1][1] = 1 - 2 * ( xx + zz );
- mat[1][2] = 2 * ( yz - xw );
- mat[2][0] = 2 * ( xz - yw );
- mat[2][1] = 2 * ( yz + xw );
- mat[2][2] = 1 - 2 * ( xx + yy );
- mat[0][3] = mat[1][3] = mat[2][3] = 0;
- }
- struct IniBinHeader {
- int one;
- int numEntries;
- int stringsSize;
- };
- struct IniBinEntry {
- unsigned int varID;
- int offset;
- };
- int main(int argc, char *argv[])
- {
- if(argc<5) exit(5);
- string cmd = string(argv[1]);
- string type = string(argv[2]);
- string inputFile = string(argv[3]);
- string outputFile = string(argv[4]);
- if (cmd == "decompile" || cmd == "d") {
- if (type == "skn" || type == "skin") {
- cout << "Decompiling binary .skn file: " << inputFile << " to .obj file: " << outputFile << endl;
- SkinModel model;
- model.importSkn(inputFile);
- model.exportObj(outputFile);
- cout << "Done!" << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment