summaryrefslogtreecommitdiff
path: root/src/m/m3d/m_bmdl.cpp
blob: 32fa0fc99eb8bdc3ea44ff3e4f26af7ed8dc36df (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include "m/m3d/m_bmdl.h"

#include "m/m3d/m3d.h"
#include "nw4r/g3d/g3d_scnmdl.h"

namespace m3d {

bmdl_c::~bmdl_c() {
    remove();
}

int bmdl_c::getType() const {
    return SCN_LEAF_MODEL;
}

int bmdl_c::getMatID(const char *name) const {
    return m3d::getMatID(getResMdl(), name);
}

int bmdl_c::getNodeID(const char *name) const {
    return m3d::getNodeID(getResMdl(), name);
}

bool bmdl_c::getNodeWorldMtx(u32 p1, nw4r::math::MTX34 *out) const {
    return nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdlSimple>(mpScnLeaf)->GetScnMtxPos(
        out, nw4r::g3d::ScnObj::MTX_WORLD, p1
    );
}

bool bmdl_c::getNodeWorldMtxMultVecZero(u32 p1, nw4r::math::VEC3 &out) const {
    nw4r::math::MTX34 mtx;
    if (!getNodeWorldMtx(p1, &mtx)) {
        return false;
    } else {
        out.x = mtx[0][3];
        out.y = mtx[1][3];
        out.z = mtx[2][3];
        return true;
    }
}

bool bmdl_c::getNodeWorldMtxMultVec(u32 p1, const nw4r::math::VEC3 &in, nw4r::math::VEC3 &out) const {
    nw4r::math::MTX34 mtx;
    if (!getNodeWorldMtx(p1, &mtx)) {
        return false;
    } else {
        MTXMultVec(mtx, in, out);
        return true;
    }
}

bool bmdl_c::setAnm(banm_c &anm) {
    nw4r::g3d::ScnMdlSimple *mdl;
    if (anm.getType() == nw4r::g3d::ScnMdlSimple::ANMOBJTYPE_SHP) {
        mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdl>(mpScnLeaf);
        return mdl->SetAnmObj(anm.getAnimObj(), nw4r::g3d::ScnMdlSimple::ANMOBJTYPE_NOT_SPECIFIED);
    } else {
        mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdlSimple>(mpScnLeaf);
        if (anm.getType() == nw4r::g3d::ScnMdlSimple::ANMOBJTYPE_CHR) {
            mpCurrentAnm = &anm;
        }
        return mdl->SetAnmObj(anm.getAnimObj(), nw4r::g3d::ScnMdlSimple::ANMOBJTYPE_NOT_SPECIFIED);
    }
}

void bmdl_c::play() {
    if (mpCurrentAnm != nullptr) {
        mpCurrentAnm->play();
    }
}

nw4r::g3d::ResMdl bmdl_c::getResMdl() const {
    return nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdlSimple>(mpScnLeaf)->GetResMdl();
}

nw4r::g3d::ResMat bmdl_c::getResMat(u32 index) const {
    nw4r::g3d::ResMdl mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdlSimple>(mpScnLeaf)->GetResMdl();
    return mdl.GetResMat(index);
}

void bmdl_c::removeAnm(nw4r::g3d::ScnMdlSimple::AnmObjType type) {
    nw4r::g3d::ScnMdlSimple *mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdlSimple>(mpScnLeaf);
    if (type == nw4r::g3d::ScnMdlSimple::ANMOBJTYPE_CHR) {
        mpCurrentAnm = nullptr;
    }
    mdl->RemoveAnmObj(type);
}

nw4r::g3d::AnmObj *bmdl_c::getAnmObj(nw4r::g3d::ScnMdlSimple::AnmObjType type) const {
    nw4r::g3d::ScnMdlSimple *mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdlSimple>(mpScnLeaf);
    return mdl->GetAnmObj(type);
}

void bmdl_c::setTevColor(u32 idx, GXTevRegID tevId, GXColor color, bool bMarkDirty) {
    nw4r::g3d::ScnMdl *mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdl>(mpScnLeaf);

    if (mdl) {
        nw4r::g3d::ScnMdl::CopiedMatAccess matAccess(mdl, idx);
        nw4r::g3d::ResMatTevColor resMatTevClr = matAccess.GetResMatTevColor(bMarkDirty);
        resMatTevClr.GXSetTevColor(tevId, color);
        resMatTevClr.DCStore(false);
    } else {
        nw4r::g3d::ResMatTevColor resMatTevClr = getResMat(idx).GetResMatTevColor();
        resMatTevClr.GXSetTevColor(tevId, color);
        resMatTevClr.DCStore(false);
    }
}

void bmdl_c::setTevColorAll(GXTevRegID tevId, GXColor color, bool bMarkDirty) {
    nw4r::g3d::ResMdl resMdl = getResMdl();
    nw4r::g3d::ScnMdl *mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdl>(mpScnLeaf);
    if (mdl) {
        for (u32 i = 0; i < resMdl.GetResMatNumEntries(); i++) {
            nw4r::g3d::ScnMdl::CopiedMatAccess matAccess(mdl, i);
            nw4r::g3d::ResMatTevColor resMatTevClr = matAccess.GetResMatTevColor(bMarkDirty);
            resMatTevClr.GXSetTevColor(tevId, color);
            resMatTevClr.DCStore(false);
        }
    } else {
        for (u32 i = 0; i < resMdl.GetResMatNumEntries(); i++) {
            nw4r::g3d::ResMatTevColor resMatTevClr = resMdl.GetResMat(i).GetResMatTevColor();
            resMatTevClr.GXSetTevColor(tevId, color);
            resMatTevClr.DCStore(false);
        }
    }
}

void bmdl_c::setTevKColor(u32 idx, GXTevKColorID tevKId, GXColor color, bool bMarkDirty) {
    nw4r::g3d::ScnMdl *mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdl>(mpScnLeaf);

    if (mdl) {
        nw4r::g3d::ScnMdl::CopiedMatAccess matAccess(mdl, idx);
        nw4r::g3d::ResMatTevColor resMatTevClr = matAccess.GetResMatTevColor(bMarkDirty);
        resMatTevClr.GXSetTevKColor(tevKId, color);
        resMatTevClr.DCStore(false);
    } else {
        nw4r::g3d::ResMatTevColor resMatTevClr = getResMat(idx).GetResMatTevColor();
        resMatTevClr.GXSetTevKColor(tevKId, color);
        resMatTevClr.DCStore(false);
    }
}

void bmdl_c::setTevKColorAll(GXTevKColorID tevKId, GXColor color, bool bMarkDirty) {
    nw4r::g3d::ResMdl resMdl = getResMdl();
    nw4r::g3d::ScnMdl *mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdl>(mpScnLeaf);
    if (mdl) {
        for (u32 i = 0; i < resMdl.GetResMatNumEntries(); i++) {
            nw4r::g3d::ScnMdl::CopiedMatAccess matAccess(mdl, i);
            nw4r::g3d::ResMatTevColor resMatTevClr = matAccess.GetResMatTevColor(bMarkDirty);
            resMatTevClr.GXSetTevKColor(tevKId, color);
            resMatTevClr.DCStore(false);
        }
    } else {
        for (u32 i = 0; i < resMdl.GetResMatNumEntries(); i++) {
            nw4r::g3d::ResMatTevColor resMatTevClr = resMdl.GetResMat(i).GetResMatTevColor();
            resMatTevClr.GXSetTevKColor(tevKId, color);
            resMatTevClr.DCStore(false);
        }
    }
}

void bmdl_c::setBlendModeAll(
    GXBlendMode blendMode, GXBlendFactor srcFactor, GXBlendFactor dstFactor, GXLogicOp op, bool bMarkDirty
) {
    nw4r::g3d::ResMdl resMdl = getResMdl();
    nw4r::g3d::ScnMdl *mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdl>(mpScnLeaf);
    if (mdl) {
        for (u32 i = 0; i < resMdl.GetResMatNumEntries(); i++) {
            nw4r::g3d::ScnMdl::CopiedMatAccess matAccess(mdl, i);
            nw4r::g3d::ResMatPix resMatPix = matAccess.GetResMatPix(bMarkDirty);
            resMatPix.GXSetBlendMode(blendMode, srcFactor, dstFactor, op);
            resMatPix.DCStore(false);
        }
    } else {
        for (u32 i = 0; i < resMdl.GetResMatNumEntries(); i++) {
            nw4r::g3d::ResMatPix resMatPix = resMdl.GetResMat(i).GetResMatPix();
            resMatPix.GXSetBlendMode(blendMode, srcFactor, dstFactor, op);
            resMatPix.DCStore(false);
        }
    }
}

void bmdl_c::setCullMode(u32 matId, GXCullMode cullMode, bool bMarkDirty) {
    nw4r::g3d::ScnMdl *mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdl>(mpScnLeaf);
    if (mdl) {
        nw4r::g3d::ScnMdl::CopiedMatAccess matAccess(mdl, matId);
        nw4r::g3d::ResGenMode resGenMode = matAccess.GetResGenMode(bMarkDirty);
        resGenMode.GXSetCullMode(cullMode);
    } else {
        nw4r::g3d::ResGenMode resGenMode = getResMat(matId).GetResGenMode();
        resGenMode.GXSetCullMode(cullMode);
    }
}

void bmdl_c::setCullModeAll(GXCullMode cullMode, bool bMarkDirty) {
    // TODO Extra stack allocation?
    nw4r::g3d::ResMdl resMdl = getResMdl();
    nw4r::g3d::ScnMdl *mdl = nw4r::g3d::G3dObj::DynamicCast<nw4r::g3d::ScnMdl>(mpScnLeaf);
    if (mdl) {
        for (u32 i = 0; i < resMdl.GetResMatNumEntries(); i++) {
            nw4r::g3d::ScnMdl::CopiedMatAccess matAccess(mdl, i);
            nw4r::g3d::ResGenMode resGenMode = matAccess.GetResGenMode(bMarkDirty);
            resGenMode.GXSetCullMode(cullMode);
        }
    } else {
        for (u32 i = 0; i < resMdl.GetResMatNumEntries(); i++) {
            nw4r::g3d::ResMat resMat = getResMat(i);
            nw4r::g3d::ResGenMode resGenMode = resMat.GetResGenMode();
            resGenMode.GXSetCullMode(cullMode);
        }
    }
}

void bmdl_c::setMatVisible(u32 matId, bool bVisble) {
    // TODO
}

int bmdl_c::setMatTexture(char *name, GXTexObj *texObj, bool copy, void *unk, int, int) {
    // TODO
}

bool bmdl_c::getBounds(mVec3_c *min, mVec3_c *max) const {
    // TODO
}

void bmdl_c::remove() {
    mpCurrentAnm = nullptr;
    scnLeaf_c::remove();
}

} // namespace m3d