summaryrefslogtreecommitdiff
path: root/src/JSystem/J3DGraphAnimator/J3DModelData.cpp
blob: e838f5697e782226598b6527cace34cd2552ff9e (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
//
// Generated by dtk
// Translation Unit: J3DModelData.cpp
//

#include "JSystem/JSystem.h" // IWYU pragma: keep

#include "JSystem/J3DGraphAnimator/J3DModelData.h"
#include "JSystem/J3DGraphAnimator/J3DShapeTable.h"
#include "JSystem/JUtility/JUTNameTab.h"
#include "dolphin/types.h"

/* 802ECF30-802ECF70       .text clear__12J3DJointTreeFv */
void J3DJointTree::clear() {
    mHierarchy = NULL;
    mFlags = 0;
    mModelDataType = 0;
    mRootNode = NULL;
    mBasicMtxCalc = NULL;
    mJointNum = NULL;
    mJointNodePointer = NULL;
    field_0x40 = NULL;
    mWEvlpMtxNum = 0;
    mWEvlpMixMtxNum = NULL;
    mWEvlpMixMtxIndex = NULL;
    mWEvlpMixWeight = NULL;
    mInvJointMtx = NULL;
    mJointName = NULL;
}

/* 802ECF70-802ED108       .text makeHierarchy__12J3DJointTreeFP7J3DNodePPC17J3DModelHierarchyP16J3DMaterialTablePP8J3DShape */
void J3DJointTree::makeHierarchy(J3DNode* pRootNode, const J3DModelHierarchy** pHierarchy, J3DMaterialTable* pMaterialTable, J3DShape** pShapeTable) {
    enum {
        kTypeEnd        = 0x00,
        kTypeBeginChild = 0x01,
        kTypeEndChild   = 0x02,
        kTypeJoint      = 0x10,
        kTypeMaterial   = 0x11,
        kTypeShape      = 0x12,
    };

    J3DNode * pCurNode = pRootNode;

    while (true) {
        J3DNode * pNewNode = NULL;
        J3DMaterial * pNewMaterial = NULL;
        J3DShape * pNewShape = NULL;
        const J3DModelHierarchy * inf = *pHierarchy;

        switch (inf->mType) {
        case kTypeBeginChild:
            *pHierarchy = inf + 1;
            makeHierarchy(pCurNode, pHierarchy, pMaterialTable, pShapeTable);
            break;
        case kTypeEndChild:
            *pHierarchy = inf + 1; 
            return;
        case kTypeEnd:
            return;
        case kTypeJoint:
            {
                J3DJoint ** pJoints = mJointNodePointer;
                *pHierarchy = inf + 1;
                pNewNode = pJoints[inf->mValue];
            }
            break;
        case kTypeMaterial:
            {
                *pHierarchy = inf + 1;
                pNewMaterial = pMaterialTable->getMaterialNodePointer(inf->getValue());
            }
            break;
        case kTypeShape:
            *pHierarchy = inf + 1;
            pNewShape = pShapeTable[inf->mValue];
            break;
        }

        if (pNewNode != NULL) {
            pCurNode = pNewNode;
            if (pRootNode == NULL)
                mRootNode = (J3DJoint*)pNewNode;
            else
                pRootNode->appendChild(pNewNode);
        } else if (pNewMaterial != NULL && pRootNode->getType() == 'NJNT') {
            ((J3DJoint*)pRootNode)->addMesh(pNewMaterial);
            pNewMaterial->mJoint = ((J3DJoint*)pRootNode);
        } else if (pNewShape != NULL && pRootNode->getType() == 'NJNT') {
            pNewMaterial = ((J3DJoint*)pRootNode)->getMesh();
            pNewMaterial->mShape = pNewShape;
            pNewShape->mMaterial = pNewMaterial;
        }
    }
}

/* 802ED108-802ED130       .text clear__12J3DModelDataFv */
void J3DModelData::clear() {
    mBinary = NULL;
    mFlags = 0;
    mbHasBumpArray = 0;
    mbHasBillboard = 0;
    mShapeTable.clear();
    mName = NULL;
    mVertexData.clear();
}

/* 802ED130-802ED1A8       .text __ct__12J3DModelDataFv */
J3DModelData::J3DModelData() {
    clear();
}

/* 802ED1A8-802ED238       .text __dt__12J3DModelDataFv */
J3DModelData::~J3DModelData() {
}

/* 802ED238-802ED2A4       .text initShapeNodes__12J3DModelDataFv */
void J3DModelData::initShapeNodes() {
    for (u16 i = 0; i < getShapeNum(); i++) {
        J3DShape *pShape = getShapeNodePointer(i);
        pShape->setDrawMtxDataPointer(getDrawMtxData());
        pShape->setVertexDataPointer(&getVertexData());
        pShape->makeVcdVatCmd();
    }
}

/* 802ED2A4-802ED340       .text sortVcdVatCmd__12J3DModelDataFv */
void J3DModelData::sortVcdVatCmd() {
    for (u16 i = 0; i < getShapeNum(); i++)
        for (u16 j = 0; j < i; j++)
            if (getShapeNodePointer(i)->isSameVcdVatCmd(getShapeNodePointer(j)))
                getShapeNodePointer(i)->setVcdVatCmd(getShapeNodePointer(j)->getVcdVatCmd());
}

/* 802ED340-802ED3E8       .text indexToPtr__12J3DModelDataFv */
void J3DModelData::indexToPtr() {
    j3dSys.setTexture(getTexture());

    GDLObj dlObj;
    for (u16 i = 0; i < getMaterialNum(); i++) {
        J3DDisplayListObj *pDLObj = getMaterialNodePointer(i)->getSharedDisplayListObj();
        GDInitGDLObj(&dlObj, pDLObj->getDisplayList(0), pDLObj->getDisplayListSize());
        GDSetCurrent(&dlObj);
        getMaterialNodePointer(i)->getTevBlock()->indexToPtr();
    }

    GDSetCurrent(NULL);
}

/* 802ED3E8-802ED434       .text isDeformablePositionFormat__12J3DModelDataCFv */
bool J3DModelData::isDeformablePositionFormat() const {
    GXVtxAttrFmtList *vtxAttr = getVtxAttrFmtList();

    for (; vtxAttr->attr != GX_VA_NULL; vtxAttr++) {
        switch (vtxAttr->attr) {
        case GX_VA_POS:
            if (vtxAttr->type == GX_F32 && vtxAttr->cnt == GX_POS_XYZ)
                return true;
            break;
        default:
            break;
        }
    }

    return false;
}

/* 802ED434-802ED4F4       .text setMaterialTable__12J3DModelDataFP16J3DMaterialTable19J3DMaterialCopyFlag */
void J3DModelData::setMaterialTable(J3DMaterialTable* pMaterialTable, J3DMaterialCopyFlag flag) {
    if (flag & J3DMatCopyFlag_Material) {
        for (u16 i = 0; i < pMaterialTable->getMaterialNum(); i++) {
            JUTNameTab *pMaterialName = getMaterialName();
            const char *pName = pMaterialTable->getMaterialName()->getName(i);
            s32 nameIndex = pMaterialName->getIndex(pName);
            if (nameIndex != -1)
                getMaterialNodePointer(nameIndex)->copy(pMaterialTable->getMaterialNodePointer(i));
        }
    }

    if ((flag & J3DMatCopyFlag_Texture) && pMaterialTable->getTexture()->getNum() != 0) {
        setTexture(pMaterialTable->getTexture());
        setTextureName(pMaterialTable->getTextureName());
    }
}