mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-04 15:04:31 +00:00
Small Skin system documentation pass (#1017)
* some docs * rename a bunch of callbacks * more cleanup * format * last cleanup * some updates * more docs * done i think * name flag and format * name unused variable * comments * revert unwanted change * z64skin.h * format * Address review * Rename PostLimbDraw callbacks to PostDraw and some PR addressing * add true/false for setTranslation * ahhhh * remove "you" Co-authored-by: fig02 <fig02srl@gmail.com>
This commit is contained in:
parent
e5ecdfd559
commit
9fec455805
21 changed files with 442 additions and 345 deletions
|
@ -1,131 +1,155 @@
|
|||
#include "global.h"
|
||||
#include "overlays/actors/ovl_En_fHG/z_en_fhg.h"
|
||||
|
||||
void func_800A6460(GlobalContext* globalCtx, PSkinAwb* skin, s32 limbIndex) {
|
||||
/**
|
||||
* Initialises the Vtx buffers used for limb at index `limbIndex`
|
||||
*/
|
||||
void Skin_InitAnimatedLimb(GlobalContext* globalCtx, Skin* skin, s32 limbIndex) {
|
||||
s32 i;
|
||||
SkinLimb** skeleton = SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment);
|
||||
Struct_800A5E28* temp_v1 = SEGMENTED_TO_VIRTUAL(((SkinLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]))->segment);
|
||||
Struct_800A598C* temp_v0 = SEGMENTED_TO_VIRTUAL(temp_v1->unk_4);
|
||||
Struct_800A598C* phi_s0;
|
||||
Struct_800A57C0* temp_s1;
|
||||
SkinAnimatedLimbData* animatedLimbData =
|
||||
SEGMENTED_TO_VIRTUAL(((SkinLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]))->segment);
|
||||
SkinLimbModif* limbModifications = SEGMENTED_TO_VIRTUAL(animatedLimbData->limbModifications);
|
||||
SkinLimbModif* modifEntry;
|
||||
SkinVertex* skinVtxEntry;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
Vtx* temp2 = skin->avbTbl[limbIndex].buf[i];
|
||||
for (i = 0; i < ARRAY_COUNT(skin->vtxTable->buf); i++) {
|
||||
Vtx* vtxBuf = skin->vtxTable[limbIndex].buf[i];
|
||||
|
||||
for (phi_s0 = temp_v0; phi_s0 < temp_v0 + temp_v1->unk_2; phi_s0++) {
|
||||
Struct_800A57C0* phi_s1 = SEGMENTED_TO_VIRTUAL(phi_s0->unk_8);
|
||||
for (modifEntry = limbModifications; modifEntry < limbModifications + animatedLimbData->limbModifCount;
|
||||
modifEntry++) {
|
||||
SkinVertex* skinVertices = SEGMENTED_TO_VIRTUAL(modifEntry->skinVertices);
|
||||
|
||||
for (temp_s1 = phi_s1; temp_s1 < phi_s1 + phi_s0->unk_0; temp_s1++) {
|
||||
Vtx* temp_t5_3 = &temp2[temp_s1->unk_0];
|
||||
for (skinVtxEntry = skinVertices; skinVtxEntry < &skinVertices[modifEntry->vtxCount]; skinVtxEntry++) {
|
||||
Vtx* vtx = &vtxBuf[skinVtxEntry->index];
|
||||
|
||||
temp_t5_3->v.flag = 0;
|
||||
temp_t5_3->v.tc[0] = temp_s1->unk_2;
|
||||
temp_t5_3->v.tc[1] = temp_s1->unk_4;
|
||||
temp_t5_3->v.cn[3] = temp_s1->unk_9;
|
||||
vtx->n.flag = 0;
|
||||
vtx->n.tc[0] = skinVtxEntry->s;
|
||||
vtx->n.tc[1] = skinVtxEntry->t;
|
||||
vtx->n.a = skinVtxEntry->alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void func_800A663C(GlobalContext* globalCtx, PSkinAwb* skin, SkeletonHeader* skeletonHeader,
|
||||
AnimationHeader* animationHeader) {
|
||||
/**
|
||||
* Initializes a skin skeleton to looping animation, dynamically allocating the frame tables,
|
||||
* and dynamically allocating and initializing the Vtx and SkinLimbVtx buffers for its animated limbs
|
||||
*/
|
||||
void Skin_Init(GlobalContext* globalCtx, Skin* skin, SkeletonHeader* skeletonHeader, AnimationHeader* animationHeader) {
|
||||
s32 limbCount;
|
||||
s32 i;
|
||||
SkinLimb** skeleton;
|
||||
SkeletonHeader* virtSkelHeader = SEGMENTED_TO_VIRTUAL(skeletonHeader);
|
||||
|
||||
skin->avbCount = virtSkelHeader->limbCount;
|
||||
skin->limbCount = virtSkelHeader->limbCount;
|
||||
skin->skeletonHeader = virtSkelHeader;
|
||||
|
||||
skeleton = SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment);
|
||||
limbCount = skin->skeletonHeader->limbCount;
|
||||
skin->avbTbl = ZeldaArena_MallocDebug(limbCount * sizeof(SkinAvb), "../z_skin_awb.c", 212);
|
||||
|
||||
ASSERT(skin->avbTbl != NULL, "pskin_awb->avb_tbl != NULL", "../z_skin_awb.c", 214);
|
||||
skin->vtxTable = ZeldaArena_MallocDebug(limbCount * sizeof(SkinLimbVtx), "../z_skin_awb.c", 212);
|
||||
|
||||
ASSERT(skin->vtxTable != NULL, "pskin_awb->avb_tbl != NULL", "../z_skin_awb.c", 214);
|
||||
|
||||
for (i = 0; i < limbCount; i++) {
|
||||
SkinAvb* avbEntry = &skin->avbTbl[i];
|
||||
SkinLimbVtx* vtxEntry = &skin->vtxTable[i];
|
||||
SkinLimb* limb = SEGMENTED_TO_VIRTUAL(skeleton[i]);
|
||||
|
||||
if ((limb->unk_8 != 4) || (limb->segment == NULL)) {
|
||||
avbEntry->unk_0 = 0;
|
||||
if ((limb->segmentType != SKIN_LIMB_TYPE_ANIMATED) || (limb->segment == NULL)) {
|
||||
vtxEntry->index = 0;
|
||||
|
||||
avbEntry->buf[0] = NULL;
|
||||
avbEntry->buf[1] = NULL;
|
||||
vtxEntry->buf[0] = NULL;
|
||||
vtxEntry->buf[1] = NULL;
|
||||
} else {
|
||||
Struct_800A5E28* temp_s1 = SEGMENTED_TO_VIRTUAL(((void)0, limb->segment));
|
||||
SkinAnimatedLimbData* animatedLimbData = SEGMENTED_TO_VIRTUAL(((void)0, limb->segment));
|
||||
|
||||
avbEntry->unk_0 = 0;
|
||||
avbEntry->buf[0] = ZeldaArena_MallocDebug(temp_s1->unk_0 * sizeof(Vtx), "../z_skin_awb.c", 235);
|
||||
ASSERT(avbEntry->buf[0] != NULL, "psavb->buf[0] != NULL", "../z_skin_awb.c", 237);
|
||||
avbEntry->buf[1] = ZeldaArena_MallocDebug(temp_s1->unk_0 * sizeof(Vtx), "../z_skin_awb.c", 240);
|
||||
ASSERT(avbEntry->buf[1] != NULL, "psavb->buf[1] != NULL", "../z_skin_awb.c", 242);
|
||||
func_800A6460(globalCtx, skin, i);
|
||||
vtxEntry->index = 0;
|
||||
|
||||
vtxEntry->buf[0] =
|
||||
ZeldaArena_MallocDebug(animatedLimbData->totalVtxCount * sizeof(Vtx), "../z_skin_awb.c", 235);
|
||||
ASSERT(vtxEntry->buf[0] != NULL, "psavb->buf[0] != NULL", "../z_skin_awb.c", 237);
|
||||
|
||||
vtxEntry->buf[1] =
|
||||
ZeldaArena_MallocDebug(animatedLimbData->totalVtxCount * sizeof(Vtx), "../z_skin_awb.c", 240);
|
||||
ASSERT(vtxEntry->buf[1] != NULL, "psavb->buf[1] != NULL", "../z_skin_awb.c", 242);
|
||||
|
||||
Skin_InitAnimatedLimb(globalCtx, skin, i);
|
||||
}
|
||||
if (1) {}
|
||||
}
|
||||
|
||||
SkelAnime_InitSkin(globalCtx, &skin->skelAnime, skeletonHeader, animationHeader);
|
||||
}
|
||||
|
||||
void func_800A6888(GlobalContext* globalCtx, PSkinAwb* arg1) {
|
||||
if (arg1->avbTbl != NULL) {
|
||||
/**
|
||||
* Frees the dynamically allocated Vtx and SkinLimbVtx buffers and tables
|
||||
*/
|
||||
void Skin_Free(GlobalContext* globalCtx, Skin* skin) {
|
||||
if (skin->vtxTable != NULL) {
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < arg1->avbCount; i++) {
|
||||
if (arg1->avbTbl[i].buf[0] != 0) {
|
||||
ZeldaArena_FreeDebug(arg1->avbTbl[i].buf[0], "../z_skin_awb.c", 276);
|
||||
arg1->avbTbl[i].buf[0] = 0;
|
||||
for (i = 0; i < skin->limbCount; i++) {
|
||||
if (skin->vtxTable[i].buf[0] != NULL) {
|
||||
ZeldaArena_FreeDebug(skin->vtxTable[i].buf[0], "../z_skin_awb.c", 276);
|
||||
skin->vtxTable[i].buf[0] = NULL;
|
||||
}
|
||||
if (arg1->avbTbl[i].buf[1] != 0) {
|
||||
ZeldaArena_FreeDebug(arg1->avbTbl[i].buf[1], "../z_skin_awb.c", 280);
|
||||
arg1->avbTbl[i].buf[1] = 0;
|
||||
if (skin->vtxTable[i].buf[1] != NULL) {
|
||||
ZeldaArena_FreeDebug(skin->vtxTable[i].buf[1], "../z_skin_awb.c", 280);
|
||||
skin->vtxTable[i].buf[1] = NULL;
|
||||
}
|
||||
}
|
||||
if (arg1->avbTbl != NULL) {
|
||||
ZeldaArena_FreeDebug(arg1->avbTbl, "../z_skin_awb.c", 286);
|
||||
|
||||
if (skin->vtxTable != NULL) {
|
||||
ZeldaArena_FreeDebug(skin->vtxTable, "../z_skin_awb.c", 286);
|
||||
}
|
||||
SkelAnime_Free(&arg1->skelAnime, globalCtx);
|
||||
|
||||
SkelAnime_Free(&skin->skelAnime, globalCtx);
|
||||
}
|
||||
}
|
||||
|
||||
s32 func_800A698C(PSkinAwb* skin, SkinLimb** skeleton, MtxF* mf, u8 parentIndex, u8 limbIndex) {
|
||||
s32 func_800A698C(Skin* skin, SkinLimb** skeleton, MtxF* limbMatrices, u8 parentIndex, u8 limbIndex) {
|
||||
s32 pad;
|
||||
SkinLimb* limb = SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]);
|
||||
MtxF* mtx;
|
||||
s32 temp_ret;
|
||||
s32 ret;
|
||||
MtxF sp28;
|
||||
|
||||
if (parentIndex == 0xFF) {
|
||||
if (parentIndex == LIMB_DONE) {
|
||||
SkinMatrix_GetClear(&mtx);
|
||||
} else {
|
||||
mtx = &mf[(s32)parentIndex];
|
||||
mtx = &limbMatrices[(s32)parentIndex];
|
||||
}
|
||||
|
||||
SkinMatrix_MtxFMtxFMult(mtx, &mf[limbIndex], &sp28);
|
||||
SkinMatrix_MtxFCopy(&sp28, &mf[limbIndex]);
|
||||
SkinMatrix_MtxFMtxFMult(mtx, &limbMatrices[limbIndex], &sp28);
|
||||
SkinMatrix_MtxFCopy(&sp28, &limbMatrices[limbIndex]);
|
||||
|
||||
if (limb->child != 0xFF) {
|
||||
temp_ret = func_800A698C(skin, skeleton, mf, limbIndex, limb->child);
|
||||
if (temp_ret) { // func_800A698C only returns false
|
||||
return temp_ret;
|
||||
if (limb->child != LIMB_DONE) {
|
||||
ret = func_800A698C(skin, skeleton, limbMatrices, limbIndex, limb->child);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (limb->sibling != 0xFF) {
|
||||
temp_ret = func_800A698C(skin, skeleton, mf, parentIndex, limb->sibling);
|
||||
if (temp_ret) { // func_800A698C only returns false
|
||||
return temp_ret;
|
||||
if (limb->sibling != LIMB_DONE) {
|
||||
ret = func_800A698C(skin, skeleton, limbMatrices, parentIndex, limb->sibling);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
s32 func_800A6AC4(PSkinAwb* skin, MtxF* arg1, Actor* actor, s32 arg3) {
|
||||
/**
|
||||
* Recursively applies matrix tranformations to each limb
|
||||
*/
|
||||
s32 Skin_ApplyAnimTransformations(Skin* skin, MtxF* limbMatrices, Actor* actor, s32 setTranslation) {
|
||||
s32 i;
|
||||
s32 pad;
|
||||
f32 yRot;
|
||||
f32 xRot;
|
||||
f32 zRot;
|
||||
s32 temp_ret;
|
||||
s32 ret;
|
||||
f32 yTransl;
|
||||
f32 xTransl;
|
||||
f32 zTransl;
|
||||
|
@ -133,28 +157,33 @@ s32 func_800A6AC4(PSkinAwb* skin, MtxF* arg1, Actor* actor, s32 arg3) {
|
|||
Vec3s* jointRot = &skin->skelAnime.jointTable[0];
|
||||
|
||||
jointRot++;
|
||||
xRot = jointRot[0].x;
|
||||
yRot = jointRot[0].y;
|
||||
zRot = jointRot[0].z;
|
||||
|
||||
if (arg3 != 0) {
|
||||
xRot = jointRot->x;
|
||||
yRot = jointRot->y;
|
||||
zRot = jointRot->z;
|
||||
|
||||
if (setTranslation) {
|
||||
jointRot--; // access joint table entry 0 for translation data
|
||||
|
||||
xTransl = jointRot->x;
|
||||
yTransl = jointRot->y;
|
||||
zTransl = jointRot->z;
|
||||
|
||||
jointRot--;
|
||||
xTransl = jointRot[0].x;
|
||||
yTransl = jointRot[0].y;
|
||||
zTransl = jointRot[0].z;
|
||||
jointRot++;
|
||||
|
||||
if (arg3 == 0x23) {
|
||||
if (setTranslation == SKIN_TRANSFORM_IS_FHG) {
|
||||
EnfHG* horse = (EnfHG*)actor;
|
||||
|
||||
yRot += horse->turnRot;
|
||||
}
|
||||
SkinMatrix_SetTranslateRotateZYX(arg1, xRot, yRot, zRot, xTransl, yTransl, zTransl);
|
||||
|
||||
SkinMatrix_SetTranslateRotateZYX(&limbMatrices[0], xRot, yRot, zRot, xTransl, yTransl, zTransl);
|
||||
} else {
|
||||
SkinMatrix_SetTranslateRotateZYX(arg1, xRot, yRot, zRot, 0.0f, 0.0f, 0.0f);
|
||||
SkinMatrix_SetTranslateRotateZYX(&limbMatrices[0], xRot, yRot, zRot, 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
jointRot++;
|
||||
|
||||
for (i = 1; i < skin->skeletonHeader->limbCount; i++) {
|
||||
SkinLimb* limb = SEGMENTED_TO_VIRTUAL(skeleton[i]);
|
||||
|
||||
|
@ -165,7 +194,7 @@ s32 func_800A6AC4(PSkinAwb* skin, MtxF* arg1, Actor* actor, s32 arg3) {
|
|||
yRot = jointRot->y;
|
||||
zRot = jointRot->z;
|
||||
jointRot++;
|
||||
SkinMatrix_SetTranslateRotateZYX(&arg1[i], xRot, yRot, zRot, xTransl, yTransl, zTransl);
|
||||
SkinMatrix_SetTranslateRotateZYX(&limbMatrices[i], xRot, yRot, zRot, xTransl, yTransl, zTransl);
|
||||
}
|
||||
|
||||
SkinMatrix_SetTranslateRotateYXZScale(
|
||||
|
@ -173,9 +202,10 @@ s32 func_800A6AC4(PSkinAwb* skin, MtxF* arg1, Actor* actor, s32 arg3) {
|
|||
actor->shape.rot.z, actor->world.pos.x, actor->world.pos.y + (actor->shape.yOffset * actor->scale.y),
|
||||
actor->world.pos.z);
|
||||
|
||||
temp_ret = func_800A698C(skin, SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment), arg1, 0xFF, 0);
|
||||
if (!temp_ret) { // func_800A698C only returns false
|
||||
return temp_ret;
|
||||
ret = func_800A698C(skin, SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment), limbMatrices, LIMB_DONE, 0);
|
||||
if (!ret) {
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue