summaryrefslogtreecommitdiff
path: root/src/nw4r/g3d/res/g3d_resanmshp.cpp
blob: 24cdddf0c24aec687a1a77538fb230d3372d4da6 (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
#include "nw4r/g3d.h" // IWYU pragma: export

namespace nw4r {
namespace g3d {

void ResAnmShp::GetAnmResult(ShpAnmResult *pResult, u32 idx, f32 frame, const ShpAnmVtxSet *pShapeArray) const {
    const ResAnmShpAnmData *pAnmData = GetShapeAnm(idx);

    const u16 *pAnmIdxToVtxIdxTable =
        static_cast<const u16 *>(ut::AddOffsetToPtr(pAnmData, pAnmData->toAnmIdxToVtxIdxTable));

    u32 flags = pAnmData->flags;
    u32 constFlags = pAnmData->constFlags;

    pResult->flags = flags;
    pResult->numKeyShape = pAnmData->numKeyShape;
    pResult->baseShapeVtxSet = pShapeArray[pAnmData->baseShapeVtxIdx];
    pResult->baseShapeWeight = 1.0f;

    for (int i = 0; i < pAnmData->numKeyShape; constFlags >>= 1, i++) {
        BlendVtx &rShape = pResult->keyShape[i];

        bool constant = (constFlags & 1) != 0;
        int vtxIdx = pAnmIdxToVtxIdxTable[i];

        f32 weight = detail::GetResAnmResult(&pAnmData->anms[i], frame, constant);

        rShape.vtxSet = pShapeArray[vtxIdx];
        rShape.weight = weight;

        pResult->baseShapeWeight -= weight;
    }
}

} // namespace g3d
} // namespace nw4r