summaryrefslogtreecommitdiff
path: root/include/JSystem/J3DGraphLoader/J3DModelLoader.h
blob: f120f69f71b74d545f710017d973754117f4ccb7 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#ifndef J3DMODELLOADER_H
#define J3DMODELLOADER_H

#include "JSystem/J3DGraphAnimator/J3DModelData.h"
#include "JSystem/JUtility/JUTDataHeader.h"

inline u32 getBdlFlag_MaterialType(u32 i_flags) {
    return i_flags & 0x3000;
}

struct J3DModelInfoBlock : public JUTDataBlockHeader {
    /* 0x08 */ u16 mFlags;
    /* 0x0C */ u32 mPacketNum;
    /* 0x10 */ u32 mVtxNum;
    /* 0x14 */ void* mpHierarchy;
};  // Size: 0x18

struct J3DVertexBlock : public JUTDataBlockHeader {
    /* 0x08 */ void* mpVtxAttrFmtList;
    /* 0x0C */ void* mpVtxPosArray;
    /* 0x10 */ void* mpVtxNrmArray;
    /* 0x14 */ void* mpVtxNBTArray;
    /* 0x18 */ void* mpVtxColorArray[2];
    /* 0x20 */ void* mpVtxTexCoordArray[8];
};  // Size: 0x40

struct J3DEnvelopBlock : public JUTDataBlockHeader {
    /* 0x08 */ u16 mWEvlpMtxNum;
    /* 0x0C */ void* mpWEvlpMixMtxNum;
    /* 0x10 */ void* mpWEvlpMixMtxIndex;
    /* 0x14 */ void* mpWEvlpMixWeight;
    /* 0x18 */ void* mpInvJointMtx;
};  // Size: 0x1C

struct J3DDrawBlock : public JUTDataBlockHeader {
    /* 0x08 */ u16 mMtxNum;
    /* 0x0C */ void* mpDrawMtxFlag;
    /* 0x10 */ void* mpDrawMtxIndex;
};  // Size: 0x14

struct J3DJointBlock;

struct J3DMaterialBlock : public JUTDataBlockHeader {
    /* 0x08 */ u16 mMaterialNum;
    /* 0x0C */ void* mpMaterialInitData;
    /* 0x10 */ void* mpMaterialID;
    /* 0x14 */ void* mpNameTable;
    /* 0x18 */ void* mpIndInitData;
    /* 0x1C */ void* mpCullMode;
    /* 0x20 */ void* mpMatColor;
    /* 0x24 */ void* mpColorChanNum;
    /* 0x28 */ void* mpColorChanInfo;
    /* 0x2C */ void* mpAmbColor;
    /* 0x30 */ void* mpLightInfo;
    /* 0x34 */ void* mpTexGenNum;
    /* 0x38 */ void* mpTexCoordInfo;
    /* 0x3C */ void* mpTexCoord2Info;
    /* 0x40 */ void* mpTexMtxInfo;
    /* 0x44 */ void* field_0x44;
    /* 0x48 */ void* mpTexNo;
    /* 0x4C */ void* mpTevOrderInfo;
    /* 0x50 */ void* mpTevColor;
    /* 0x54 */ void* mpTevKColor;
    /* 0x58 */ void* mpTevStageNum;
    /* 0x5C */ void* mpTevStageInfo;
    /* 0x60 */ void* mpTevSwapModeInfo;
    /* 0x64 */ void* mpTevSwapModeTableInfo;
    /* 0x68 */ void* mpFogInfo;
    /* 0x6C */ void* mpAlphaCompInfo;
    /* 0x70 */ void* mpBlendInfo;
    /* 0x74 */ void* mpZModeInfo;
    /* 0x78 */ void* mpZCompLoc;
    /* 0x7C */ void* mpDither;
    /* 0x80 */ void* mpNBTScaleInfo;
};

struct J3DMaterialBlock_v21 : public JUTDataBlockHeader {
    /* 0x08 */ u16 mMaterialNum;
    /* 0x0C */ void* mpMaterialInitData;
    /* 0x10 */ void* mpMaterialID;
    /* 0x14 */ void* mpNameTable;
    /* 0x18 */ void* mpCullMode;
    /* 0x1C */ void* mpMatColor;
    /* 0x20 */ void* mpColorChanNum;
    /* 0x24 */ void* mpColorChanInfo;
    /* 0x28 */ void* mpTexGenNum;
    /* 0x2C */ void* mpTexCoordInfo;
    /* 0x30 */ void* mpTexCoord2Info;
    /* 0x34 */ void* mpTexMtxInfo;
    /* 0x38 */ void* field_0x44;
    /* 0x3C */ void* mpTexNo;
    /* 0x40 */ void* mpTevOrderInfo;
    /* 0x44 */ void* mpTevColor;
    /* 0x48 */ void* mpTevKColor;
    /* 0x4C */ void* mpTevStageNum;
    /* 0x50 */ void* mpTevStageInfo;
    /* 0x54 */ void* mpTevSwapModeInfo;
    /* 0x58 */ void* mpTevSwapModeTableInfo;
    /* 0x68 */ void* mpFogInfo;
    /* 0x6C */ void* mpAlphaCompInfo;
    /* 0x70 */ void* mpBlendInfo;
    /* 0x74 */ void* mpZModeInfo;
    /* 0x78 */ void* mpZCompLoc;
    /* 0x7C */ void* mpDither;
    /* 0x80 */ void* mpNBTScaleInfo;
};

struct J3DMaterialDLBlock : public JUTDataBlockHeader {
    /* 0x08 */ u16 mMaterialNum;
    /* 0x0C */ void* mpDisplayListInit;
    /* 0x10 */ void* mpPatchingInfo;
    /* 0x14 */ void* mpCurrentMtxInfo;
    /* 0x18 */ void* field_0x18;
    /* 0x1C */ void* field_0x1c;
    /* 0x20 */ void* mpNameTable;
    /* more */
};

struct J3DShapeBlock;

struct J3DTextureBlock : public JUTDataBlockHeader {
    /* 0x08 */ u16 mTextureNum;
    /* 0x0C */ void* mpTextureRes;
    /* 0x10 */ void* mpNameTable;
};

static inline u32 getMdlDataFlag_TevStageNum(u32 flags) { return (flags >> 0x10) & 0x1f; }
static inline u32 getMdlDataFlag_TexGenFlag(u32 flags) { return flags & 0x0c000000; }
static inline u32 getMdlDataFlag_ColorFlag(u32 flags) { return flags & 0xc0000000; }
static inline u32 getMdlDataFlag_PEFlag(u32 flags) { return flags & 0x30000000; }
static inline u32 getMdlDataFlag_MtxLoadType(u32 flags) { return flags & 0x10; }

class J3DModelLoaderDataBase {
public:
    static J3DModelData* load(void const*, u32);
    static J3DModelData* loadBinaryDisplayList(void const*, u32);
    static J3DMaterialTable* loadMaterialTable(void const*);
};

class J3DModelLoader {
public:
    J3DModelLoader() :
        mpModelData(NULL),
        mpMaterialTable(NULL),
        mpShapeBlock(NULL),
        mpMaterialBlock(NULL),
        mpModelHierarchy(NULL),
        field_0x18(0) {}

    virtual J3DModelData* load(const void*, u32);
    virtual J3DMaterialTable* loadMaterialTable(const void*);
    virtual J3DModelData* loadBinaryDisplayList(const void*, u32);
    virtual u32 calcLoadSize(const void*, u32);
    virtual u32 calcLoadMaterialTableSize(const void*);
    virtual u32 calcLoadBinaryDisplayListSize(const void*, u32);
    virtual u16 countMaterialNum(const void*);
    virtual void setupBBoardInfo();
    virtual ~J3DModelLoader() {}
    virtual void readMaterial(const J3DMaterialBlock*, u32) {}
    virtual void readMaterial_v21(const J3DMaterialBlock_v21*, u32) {}
    virtual void readMaterialTable(const J3DMaterialBlock*, u32) {}
    virtual void readMaterialTable_v21(const J3DMaterialBlock_v21*, u32) {}
    virtual u32 calcSizeMaterial(const J3DMaterialBlock*, u32) { return 0; }
    virtual u32 calcSizeMaterialTable(const J3DMaterialBlock*, u32) { return 0; }
    
    void readInformation(const J3DModelInfoBlock*, u32);
    void readVertex(const J3DVertexBlock*);
    void readEnvelop(const J3DEnvelopBlock*);
    void readDraw(const J3DDrawBlock*);
    void readJoint(const J3DJointBlock*);
    void readShape(const J3DShapeBlock*, u32);
    void readTexture(const J3DTextureBlock*);
    void readTextureTable(const J3DTextureBlock*);
    void readPatchedMaterial(const J3DMaterialBlock*, u32);
    void readMaterialDL(const J3DMaterialDLBlock*, u32);
    void modifyMaterial(u32);
    u32 calcSizeInformation(const J3DModelInfoBlock*, u32);
    u32 calcSizeJoint(const J3DJointBlock*);
    u32 calcSizeShape(const J3DShapeBlock*, u32);
    u32 calcSizeTexture(const J3DTextureBlock*);
    u32 calcSizeTextureTable(const J3DTextureBlock*);
    u32 calcSizePatchedMaterial(const J3DMaterialBlock*, u32);
    u32 calcSizeMaterialDL(const J3DMaterialDLBlock*, u32);

protected:
    /* 0x04 */ J3DModelData* mpModelData;
    /* 0x08 */ J3DMaterialTable* mpMaterialTable;
    /* 0x0C */ const J3DShapeBlock* mpShapeBlock;
    /* 0x10 */ const J3DMaterialBlock* mpMaterialBlock;
    /* 0x14 */ J3DModelHierarchy* mpModelHierarchy;
    /* 0x18 */ u8 field_0x18;
    /* 0x19 */ u8 field_0x19;
};

class J3DModelLoader_v21 : public J3DModelLoader {
public:
    ~J3DModelLoader_v21() {}
    void readMaterial_v21(const J3DMaterialBlock_v21*, u32);
    void readMaterialTable_v21(const J3DMaterialBlock_v21*, u32);
};

class J3DModelLoader_v26 : public J3DModelLoader {
public:
    ~J3DModelLoader_v26() {}
    void readMaterial(const J3DMaterialBlock*, u32);
    void readMaterialTable(const J3DMaterialBlock*, u32);
    u32 calcSizeMaterial(const J3DMaterialBlock*, u32);
    u32 calcSizeMaterialTable(const J3DMaterialBlock*, u32);
};

#endif /* J3DMODELLOADER_H */