summaryrefslogtreecommitdiff
path: root/src/JSystem/J3DGraphAnimator/J3DModelData.cpp
blob: 606882eb0accf4865b421afc24e256b1e807b1e4 (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
//
// J3DModelData
//

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

#include "JSystem/J3DGraphAnimator/J3DModelData.h"
#include "JSystem/J3DGraphAnimator/J3DJoint.h"
#include "JSystem/J3DGraphAnimator/J3DMaterialAnm.h"
#include "JSystem/J3DGraphAnimator/J3DModel.h"
#include "JSystem/J3DGraphBase/J3DMaterial.h"

void J3DModelData::clear() {
    mpRawData = 0;
    mFlags = 0;
    mbHasBumpArray = 0;
    mbHasBillboard = 0;
}

J3DModelData::J3DModelData() {
    clear();
}

s32 J3DModelData::newSharedDisplayList(u32 mdlFlags) {
    u16 matNum = getMaterialNum();

    for (u16 i = 0; i < matNum; i++) {
        s32 ret;
        if (mdlFlags & J3DMdlFlag_UseSingleDL) {
            ret = getMaterialNodePointer(i)->newSingleSharedDisplayList(getMaterialNodePointer(i)->countDLSize());
            if (ret != kJ3DError_Success)
                return ret;
        } else {
            ret = getMaterialNodePointer(i)->newSharedDisplayList(getMaterialNodePointer(i)->countDLSize());
            if (ret != kJ3DError_Success)
                return ret;
        }
    }

    return kJ3DError_Success;
}

void J3DModelData::indexToPtr() {
    j3dSys.setTexture(getTexture());

    static BOOL sInterruptFlag = OSDisableInterrupts();
    OSDisableScheduler();

    GDLObj gdl_obj;
    u16 matNum = getMaterialNum();
    for (u16 i = 0; i < matNum; i++) {
        J3DMaterial* matNode = getMaterialNodePointer(i);
        J3DDisplayListObj* dl_obj = matNode->getSharedDisplayListObj();

        GDInitGDLObj(&gdl_obj, dl_obj->getDisplayList(0), dl_obj->getDisplayListSize());
        GDSetCurrent(&gdl_obj);
        matNode->getTevBlock()->indexToPtr();
    }

    GDSetCurrent(NULL);
    OSEnableScheduler();
    OSRestoreInterrupts(sInterruptFlag);
}

void J3DModelData::makeSharedDL() {
    j3dSys.setTexture(getTexture());

    u16 matNum = getMaterialNum();
    for (u16 i = 0; i < matNum; i++) {
        getMaterialNodePointer(i)->makeSharedDisplayList();
    }
}

void J3DModelData::simpleCalcMaterial(u16 idx, Mtx param_1) {
    syncJ3DSysFlags();

    J3DMaterial* mat;
    J3DJoint* jointNode = getJointNodePointer(idx);
    for (mat = jointNode->getMesh(); mat != NULL; mat = mat->getNext()) {
        if (mat->getMaterialAnm() != NULL) {
            mat->getMaterialAnm()->calc(mat);
        }
        mat->calc(param_1);
    }
}

void J3DModelData::syncJ3DSysPointers() const {
    j3dSys.setTexture(getTexture());
    j3dSys.setVtxPos(getVtxPosArray());
    j3dSys.setVtxNrm(getVtxNrmArray());
    j3dSys.setVtxCol(getVtxColorArray(0));
}

void J3DModelData::syncJ3DSysFlags() const {
    if (checkFlag(0x20)) {
        j3dSys.onFlag(J3DSysFlag_PostTexMtx);
    } else {
        j3dSys.offFlag(J3DSysFlag_PostTexMtx);
    }
}