-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrw1.cpp
101 lines (81 loc) · 2.12 KB
/
drw1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "drw1.h"
#include <iostream>
using namespace std;
namespace bmd
{
// DRW1 /////////////////////////////////////////////////////////////
struct Drw1Header
{
char tag[4];
u32 sizeOfSection;
u16 count;
u16 pad;
//stores for each matrix if it's weighted (normal (0)/skinned (1) matrix types)
u32 offsetToIsWeighted;
//for normal (0) matrices, this is an index into the global matrix
//table (which stores a matrix for every joint). for skinned
//matrices (1), I'm not yet totally sure how this works (but it's
//probably an offset into the Evp1-array)
u32 offsetToData;
};
};
void readDrw1Header(FILE* f, bmd::Drw1Header& h)
{
fread(h.tag, 1, 4, f);
readDWORD(f, h.sizeOfSection);
readWORD(f, h.count);
readWORD(f, h.pad);
readDWORD(f, h.offsetToIsWeighted);
readDWORD(f, h.offsetToData);
}
void dumpDrw1(FILE* f, Drw1& dst)
{
int drw1Offset = ftell(f), i;
//read header
bmd::Drw1Header h;
readDrw1Header(f, h);
//read bool array
dst.isWeighted.resize(h.count);
fseek(f, drw1Offset + h.offsetToIsWeighted, SEEK_SET);
for(i = 0; i < h.count; ++i)
{
u8 v; fread(&v, 1, 1, f);
if(v == 0)
dst.isWeighted[i] = false;
else if(v == 1)
dst.isWeighted[i] = true;
else
warn("drw1: unexpected value in isWeighted array: %d", v);
}
//read data array
dst.data.resize(h.count);
fseek(f, drw1Offset + h.offsetToData, SEEK_SET);
for(i = 0; i < h.count; ++i)
readWORD(f, dst.data[i]);
}
void writeDrw1Info(FILE* f, ostream& out)
{
out << string(50, '/') << endl
<< "//Drw1 section" << endl
<< string(50, '/') << endl << endl;
int drw1Offset = ftell(f), i;
bmd::Drw1Header h;
readDrw1Header(f, h);
out << h.count << " many" << endl << endl;
out << "isWeighted:" << endl;
fseek(f, drw1Offset + h.offsetToIsWeighted, SEEK_SET);
for(i = 0; i < h.count; ++i)
{
u8 v; fread(&v, 1, 1, f);
out << " " << (int)v;
}
out << endl;
out << "Data:" << endl;
fseek(f, drw1Offset + h.offsetToData, SEEK_SET);
for(i = 0; i < h.count; ++i)
{
u16 v; readWORD(f, v);
out << " " << v;
}
out << endl << endl;
}