From b5e932c493742411fdcef695be5879b729d115c8 Mon Sep 17 00:00:00 2001 From: hatal175 Date: Wed, 16 Apr 2025 00:09:31 +0300 Subject: [PATCH] A Little j3d work (#2396) --- configure.py | 2 +- .../JSystem/J3DGraphAnimator/J3DAnimation.h | 2 +- include/JSystem/J3DGraphAnimator/J3DCluster.h | 6 +- .../JSystem/J3DGraphAnimator/J3DJointTree.h | 2 +- include/JSystem/J3DGraphAnimator/J3DModel.h | 2 +- .../JSystem/J3DGraphAnimator/J3DModelData.h | 2 +- .../JSystem/J3DGraphAnimator/J3DMtxBuffer.h | 2 +- include/JSystem/J3DGraphBase/J3DVertex.h | 2 +- include/JSystem/JUtility/JUTAssert.h | 3 + src/JSystem/J3DGraphAnimator/J3DCluster.cpp | 94 +++++++------- src/JSystem/J3DGraphAnimator/J3DMtxBuffer.cpp | 121 +++++++++++------- .../J3DGraphAnimator/J3DSkinDeform.cpp | 115 +++++++++-------- 12 files changed, 204 insertions(+), 149 deletions(-) diff --git a/configure.py b/configure.py index 41bef79e06e..261a48720ba 100755 --- a/configure.py +++ b/configure.py @@ -1061,7 +1061,7 @@ config.libs = [ Object(MatchingFor("GZ2E01"), "JSystem/J3DGraphAnimator/J3DAnimation.cpp", extra_cflags=['-pragma "nosyminline off"']), Object(MatchingFor("GZ2E01"), "JSystem/J3DGraphAnimator/J3DMaterialAnm.cpp"), Object(NonMatching, "JSystem/J3DGraphAnimator/J3DSkinDeform.cpp"), - Object(NonMatching, "JSystem/J3DGraphAnimator/J3DCluster.cpp"), + Object(MatchingFor("GZ2E01"), "JSystem/J3DGraphAnimator/J3DCluster.cpp"), Object(MatchingFor("GZ2E01"), "JSystem/J3DGraphAnimator/J3DJoint.cpp"), Object(NonMatching, "JSystem/J3DGraphAnimator/J3DMaterialAttach.cpp"), ], diff --git a/include/JSystem/J3DGraphAnimator/J3DAnimation.h b/include/JSystem/J3DGraphAnimator/J3DAnimation.h index 88e0480badd..ca556f15460 100644 --- a/include/JSystem/J3DGraphAnimator/J3DAnimation.h +++ b/include/JSystem/J3DGraphAnimator/J3DAnimation.h @@ -722,7 +722,7 @@ public: u16 getUpdateMaterialNum() const { return mUpdateMaterialNum; } bool isValidUpdateMaterialID(u16 id) const { return mUpdateMaterialID[id] != 0xFFFF; } u16 getUpdateMaterialID(u16 idx) const { - JUT_ASSERT_MSG(1578, 0 <= mUpdateMaterialNum - idx, "Error : range over.") + J3D_ASSERT(1578, idx < mUpdateMaterialNum, "Error : range over.") return mUpdateMaterialID[idx]; } diff --git a/include/JSystem/J3DGraphAnimator/J3DCluster.h b/include/JSystem/J3DGraphAnimator/J3DCluster.h index ea9fbe2b7b3..c575e890f9e 100644 --- a/include/JSystem/J3DGraphAnimator/J3DCluster.h +++ b/include/JSystem/J3DGraphAnimator/J3DCluster.h @@ -1,6 +1,7 @@ #ifndef J3DCLUSTER_H #define J3DCLUSTER_H +#include "JSystem/JUtility/JUTAssert.h" #include "dolphin/types.h" class J3DDeformer; @@ -79,7 +80,10 @@ public: /* 8032E274 */ void deform(J3DModel*); /* 8032E364 */ void setAnm(J3DAnmCluster*); - J3DCluster* getClusterPointer(u16 index) { return &mClusterPointer[index]; } + J3DCluster* getClusterPointer(u16 index) { + J3D_ASSERT(186, (index < mClusterNum),"Error : range over."); + return &mClusterPointer[index]; + } u16 getClusterNum() const { return mClusterNum; } u16 getClusterKeyNum() const { return mClusterKeyNum; } J3DClusterKey* getClusterKeyPointer(u16 i) { return &mClusterKeyPointer[i]; } diff --git a/include/JSystem/J3DGraphAnimator/J3DJointTree.h b/include/JSystem/J3DGraphAnimator/J3DJointTree.h index c1558e5a91c..3b9bb855391 100644 --- a/include/JSystem/J3DGraphAnimator/J3DJointTree.h +++ b/include/JSystem/J3DGraphAnimator/J3DJointTree.h @@ -65,7 +65,7 @@ public: J3DJoint* getRootNode() { return mRootNode; } J3DJoint* getJointNodePointer(u16 idx) const { return mJointNodePointer[idx]; } J3DMtxCalc* getBasicMtxCalc() const { return mBasicMtxCalc; } - Mtx& getInvJointMtx(s32 idx) const { return mInvJointMtx[idx]; } + Mtx& getInvJointMtx(int idx) { return mInvJointMtx[idx]; } u32 getModelDataType() const { return mModelDataType; } void setModelDataType(u32 type) { mModelDataType = type; } bool checkFlag(u32 flag) { return mFlags & flag; } diff --git a/include/JSystem/J3DGraphAnimator/J3DModel.h b/include/JSystem/J3DGraphAnimator/J3DModel.h index 5bbd7dc352f..eca87c81277 100644 --- a/include/JSystem/J3DGraphAnimator/J3DModel.h +++ b/include/JSystem/J3DGraphAnimator/J3DModel.h @@ -86,7 +86,7 @@ public: Mtx& getBaseTRMtx() { return mBaseTransformMtx; } void setBaseTRMtx(Mtx m) { MTXCopy(m, mBaseTransformMtx); } u32 getMtxCalcMode() const { return mFlags & 0x03; } - J3DVertexBuffer* getVertexBuffer() const { return (J3DVertexBuffer*)&mVertexBuffer; } + J3DVertexBuffer* getVertexBuffer() { return (J3DVertexBuffer*)&mVertexBuffer; } J3DMatPacket* getMatPacket(u16 idx) const { return &mMatPacket[idx]; } J3DShapePacket* getShapePacket(u16 idx) const { return &mShapePacket[idx]; } J3DMtxBuffer* getMtxBuffer() const { return mMtxBuffer; } diff --git a/include/JSystem/J3DGraphAnimator/J3DModelData.h b/include/JSystem/J3DGraphAnimator/J3DModelData.h index 629a82e12dd..fd613ce6163 100644 --- a/include/JSystem/J3DGraphAnimator/J3DModelData.h +++ b/include/JSystem/J3DGraphAnimator/J3DModelData.h @@ -52,7 +52,7 @@ public: void setHierarchy(J3DModelHierarchy* hierarchy) { mJointTree.setHierarchy(hierarchy); } void setBasicMtxCalc(J3DMtxCalc* calc) { mJointTree.setBasicMtxCalc(calc); } JUTNameTab* getJointName() const { return mJointTree.getJointName(); } - Mtx& getInvJointMtx(s32 idx) const { return mJointTree.getInvJointMtx(idx); } + Mtx& getInvJointMtx(int idx) { return mJointTree.getInvJointMtx(idx); } J3DTexture* getTexture() const { return mMaterialTable.getTexture(); } JUTNameTab* getTextureName() const { return mMaterialTable.getTextureName(); } u16 getWEvlpMtxNum() const { return mJointTree.getWEvlpMtxNum(); } diff --git a/include/JSystem/J3DGraphAnimator/J3DMtxBuffer.h b/include/JSystem/J3DGraphAnimator/J3DMtxBuffer.h index abf85d35c8d..5f9d4da0471 100644 --- a/include/JSystem/J3DGraphAnimator/J3DMtxBuffer.h +++ b/include/JSystem/J3DGraphAnimator/J3DMtxBuffer.h @@ -15,7 +15,7 @@ public: /* 80326214 */ void initialize(); /* 80326258 */ s32 create(J3DModelData*, u32); - /* 80326364 */ s32 createAnmMtx(J3DModelData*); + /* 80326364 */ J3DError createAnmMtx(J3DModelData*); /* 803263F0 */ s32 createWeightEnvelopeMtx(J3DModelData*); /* 8032648C */ s32 setNoUseDrawMtx(); /* 803264B8 */ s32 createDoubleDrawMtx(J3DModelData*, u32); diff --git a/include/JSystem/J3DGraphBase/J3DVertex.h b/include/JSystem/J3DGraphBase/J3DVertex.h index ccc247c0dda..c6def61e961 100644 --- a/include/JSystem/J3DGraphBase/J3DVertex.h +++ b/include/JSystem/J3DGraphBase/J3DVertex.h @@ -102,7 +102,7 @@ public: void* getTransformedVtxPos(int idx) { return mTransformedVtxPosArray[idx]; } void* getTransformedVtxNrm(int idx) { return mTransformedVtxNrmArray[idx]; } - J3DVertexData* getVertexData() { return mVtxData; } + J3DVertexData* getVertexData() const { return mVtxData; } void swapTransformedVtxPos() { void* tmp = mTransformedVtxPosArray[0]; diff --git a/include/JSystem/JUtility/JUTAssert.h b/include/JSystem/JUtility/JUTAssert.h index 71a764b3c86..5d469fb3a09 100644 --- a/include/JSystem/JUtility/JUTAssert.h +++ b/include/JSystem/JUtility/JUTAssert.h @@ -13,6 +13,8 @@ #define JUT_ASSERT_MSG_F(LINE, COND, MSG, ...) \ (COND) ? (void)0 : (JUTAssertion::showAssert_f(JUTAssertion::getSDevice(), __FILE__, LINE, MSG, __VA_ARGS__), OSPanic(__FILE__, LINE, "Halt")); +#define J3D_ASSERT(LINE, COND, MSG) JUT_ASSERT_MSG(LINE, (COND) != 0, MSG) + #define JUT_PANIC(LINE, TEXT) \ JUTAssertion::showAssert(JUTAssertion::getSDevice(), __FILE__, LINE, TEXT); \ OSPanic(__FILE__, LINE, "Halt"); @@ -33,6 +35,7 @@ #define JUT_ASSERT(...) (void)0; #define JUT_ASSERT_MSG(...) (void)0; #define JUT_ASSERT_MSG_F(...) (void)0; +#define J3D_ASSERT(...) (void)0; #define JUT_PANIC(...) #define JUT_WARN(...) #define JUT_WARN_DEVICE(...) diff --git a/src/JSystem/J3DGraphAnimator/J3DCluster.cpp b/src/JSystem/J3DGraphAnimator/J3DCluster.cpp index 32d5ac3118c..411457599c6 100644 --- a/src/JSystem/J3DGraphAnimator/J3DCluster.cpp +++ b/src/JSystem/J3DGraphAnimator/J3DCluster.cpp @@ -11,17 +11,6 @@ #include "dolphin/base/PPCArch.h" #include "dolphin/os.h" -#ifdef DEBUG -#define J3D_ASSERT(COND) \ - if ((COND) == 0) { \ - JUTAssertion::showAssert(JUTAssertion::getSDevice(), __FILE__, __LINE__, \ - "Error : null pointer"); \ - OSPanic(__FILE__, __LINE__, "Halt"); \ - } -#else -#define J3D_ASSERT(COND) -#endif - /* 8032E1F8-8032E230 328B38 0038+00 0/0 1/1 0/0 .text __ct__13J3DDeformDataFv */ J3DDeformData::J3DDeformData() { mClusterNum = 0; @@ -48,7 +37,7 @@ void J3DDeformData::offAllFlag(u32 i_flag) { /* 8032E274-8032E298 328BB4 0024+00 0/0 1/1 0/0 .text deform__13J3DDeformDataFP8J3DModel */ void J3DDeformData::deform(J3DModel* model) { - J3D_ASSERT(model != NULL); + J3D_ASSERT(110, model,"Error : null pointer"); deform(model->getVertexBuffer()); } @@ -56,7 +45,7 @@ void J3DDeformData::deform(J3DModel* model) { /* 8032E298-8032E364 328BD8 00CC+00 1/1 0/0 0/0 .text deform__13J3DDeformDataFP15J3DVertexBuffer */ void J3DDeformData::deform(J3DVertexBuffer* buffer) { - J3D_ASSERT(buffer != NULL); + J3D_ASSERT(141, buffer,"Error : null pointer"); buffer->swapVtxPosArrayPointer(); buffer->swapVtxNrmArrayPointer(); @@ -94,7 +83,7 @@ J3DDeformer::J3DDeformer(J3DDeformData* data) { /* 8032E3BC-8032E4A4 328CFC 00E8+00 1/1 0/0 0/0 .text deform__11J3DDeformerFP15J3DVertexBufferUs */ void J3DDeformer::deform(J3DVertexBuffer* buffer, u16 param_1) { - J3D_ASSERT(buffer != 0); + J3D_ASSERT(222, buffer,"Error : null pointer"); u16 var_r31 = 0; if (mAnmCluster != NULL) { @@ -115,6 +104,7 @@ void J3DDeformer::deform(J3DVertexBuffer* buffer, u16 param_1) { * deform_VtxPosF32__11J3DDeformerFP15J3DVertexBufferP10J3DClusterP13J3DClusterKeyPf */ void J3DDeformer::deform_VtxPosF32(J3DVertexBuffer* i_buffer, J3DCluster* i_cluster, J3DClusterKey* i_key, f32* i_weights) { + J3DClusterKey* key; int posNum = i_cluster->mPosNum; int keyNum = i_cluster->mKeyNum; f32* vtxPosArray = (f32*)i_buffer->getVtxPosArrayPointer(0); @@ -129,18 +119,22 @@ void J3DDeformer::deform_VtxPosF32(J3DVertexBuffer* i_buffer, J3DCluster* i_clus } f32 local_58[2] = {1.0f, -1.0f}; - + for (u16 i = 0; i < posNum; i++) { int index = i_cluster->field_0x18[i] * 3; for (u16 j = 0; j < keyNum; j++) { - int uVar7 = ((u16*)i_key[j].field_0x4)[i]; - f32* deform = &deformVtxPos[(uVar7 & ~0xE000) * 3]; - f32 deform0 = deform[0]; - f32 deform1 = deform[1]; - f32 deform2 = deform[2]; - deform0 *= local_58[((uVar7 & 0x8000) >> 0xF)]; - deform1 *= local_58[((uVar7 & 0x4000) >> 0xE)]; - deform2 *= local_58[((uVar7 & 0x2000) >> 0xD)]; + int uVar8; + int uVar7; + key = &i_key[j]; + uVar8 = uVar7 = ((u16*)key->field_0x4)[i]; + uVar7 &= ~0xE000; + uVar7 *= 3; + f32 deform0 = deformVtxPos[uVar7]; + f32 deform1 = deformVtxPos[uVar7 + 1]; + f32 deform2 = deformVtxPos[uVar7 + 2]; + deform0 *= local_58[((uVar8 & 0x8000) >> 0xF)]; + deform1 *= local_58[((uVar8 & 0x4000) >> 0xE)]; + deform2 *= local_58[((uVar8 & 0x2000) >> 0xD)]; vtxPosArray[index] += deform0 * i_weights[j]; vtxPosArray[index + 1] += deform1 * i_weights[j]; vtxPosArray[index + 2] += deform2 * i_weights[j]; @@ -165,26 +159,30 @@ void J3DDeformer::deform_VtxNrmF32(J3DVertexBuffer* i_buffer, J3DCluster* i_clus iVar13[index + 1] = 0.0f; iVar13[index + 2] = 0.0f; for (u16 j = 0; j < keyNum; j++) { - int uVar3 = ((u16*)i_key[j].field_0x8)[i]; - f32 deform0, deform1, deform2; - if (uVar3 & 0x8000) { - deform0 = -deformVtxNrm[(uVar3 & ~0xE000) * 3]; + J3DClusterKey* key = &i_key[j]; + int uVar3 = ((u16*)key->field_0x8)[i]; + int uVar4 = uVar3; + uVar3 &= ~0xE000; + uVar3 *= 3; + Vec deform0; + if (uVar4 & 0x8000) { + deform0.x = -deformVtxNrm[uVar3]; } else { - deform0 = deformVtxNrm[(uVar3 & ~0xE000) * 3]; + deform0.x = deformVtxNrm[uVar3]; } - if (uVar3 & 0x4000) { - deform1 = -deformVtxNrm[(uVar3 & ~0xE000) * 3 + 1]; + if (uVar4 & 0x4000) { + deform0.y = -deformVtxNrm[uVar3 + 1]; } else { - deform1 = deformVtxNrm[(uVar3 & ~0xE000) * 3 + 1]; + deform0.y = deformVtxNrm[uVar3 + 1]; } - if (uVar3 & 0x2000) { - deform2 = -deformVtxNrm[(uVar3 & ~0xE000) * 3 + 2]; + if (uVar4 & 0x2000) { + deform0.z = -deformVtxNrm[uVar3 + 2]; } else { - deform2 = deformVtxNrm[(uVar3 & ~0xE000) * 3 + 2]; + deform0.z = deformVtxNrm[uVar3 + 2]; } - iVar13[index] += deform0 * i_weights[j]; - iVar13[index + 1] += deform1 * i_weights[j]; - iVar13[index + 2] += deform2 * i_weights[j]; + iVar13[index] += deform0.x * i_weights[j]; + iVar13[index + 1] += deform0.y * i_weights[j]; + iVar13[index + 2] += deform0.z * i_weights[j]; } normalize(&iVar13[index]); } @@ -210,7 +208,8 @@ void J3DDeformer::deform_VtxNrmF32(J3DVertexBuffer* i_buffer, J3DCluster* i_clus continue; } int index = tmp * 3; - int index2 = clusterVtx->field_0x4[j] * 3; + u16 iVar4 = clusterVtx->field_0x4[j]; + int index2 = iVar4 * 3; f32 dot = vec.x * iVar13[index2] + vec.y * iVar13[index2 + 1] + vec.z * iVar13[index2 + 2]; @@ -228,18 +227,17 @@ void J3DDeformer::deform_VtxNrmF32(J3DVertexBuffer* i_buffer, J3DCluster* i_clus vtxNrmArray[index + 1] = vec.y; vtxNrmArray[index + 2] = vec.z; } else if (angle > i_cluster->mMaxAngle) { - int index3 = clusterVtx->field_0x4[j]; - Vec* iVar13a = (Vec*)iVar13; - vtxNrmArray[index] = iVar13a[index3].x; - vtxNrmArray[index + 1] = iVar13a[index3].y; - vtxNrmArray[index + 2] = iVar13a[index3].z; + vtxNrmArray[index] = iVar13[iVar4 * 3]; + vtxNrmArray[index + 1] = iVar13[iVar4 * 3 + 1]; + vtxNrmArray[index + 2] = iVar13[iVar4 * 3 + 2]; } else { - f32 weight1 = (angle - i_cluster->mMinAngle) + f32 weights[2]; + weights[0] = (angle - i_cluster->mMinAngle) / (i_cluster->mMaxAngle - i_cluster->mMinAngle); - f32 weight2 = 1.0f - weight1; - vtxNrmArray[index] = weight1 * iVar13[index2] + weight2 * vec.x; - vtxNrmArray[index + 1] = weight1 * iVar13[index2 + 1] + weight2 * vec.y; - vtxNrmArray[index + 2] = weight1 * iVar13[index2 + 2] + weight2 * vec.z; + weights[1] = 1.0f - weights[0]; + vtxNrmArray[index] = weights[0] * iVar13[index2] + weights[1] * vec.x; + vtxNrmArray[index + 1] = weights[0] * iVar13[index2 + 1] + weights[1] * vec.y; + vtxNrmArray[index + 2] = weights[0] * iVar13[index2 + 2] + weights[1] * vec.z; } } } diff --git a/src/JSystem/J3DGraphAnimator/J3DMtxBuffer.cpp b/src/JSystem/J3DGraphAnimator/J3DMtxBuffer.cpp index 0e462edb587..3d7888edb83 100644 --- a/src/JSystem/J3DGraphAnimator/J3DMtxBuffer.cpp +++ b/src/JSystem/J3DGraphAnimator/J3DMtxBuffer.cpp @@ -7,6 +7,19 @@ #include "JSystem/J3DGraphBase/J3DMaterial.h" #include "JSystem/J3DGraphLoader/J3DModelLoader.h" #include "JSystem/JKernel/JKRHeap.h" +#include "JSystem/JUtility/JUTAssert.h" + +/* 804371C0-804371F0 063EE0 0030+00 1/0 0/0 0/0 .bss sNoUseDrawMtx__12J3DMtxBuffer */ +Mtx J3DMtxBuffer::sNoUseDrawMtx; + +/* 804371F0-80437218 063F10 0024+04 1/0 0/0 0/0 .bss sNoUseNrmMtx__12J3DMtxBuffer */ +Mtx33 J3DMtxBuffer::sNoUseNrmMtx; + +/* 80450970-80450974 -00001 0004+00 1/1 0/0 0/0 .sdata sNoUseDrawMtxPtr__12J3DMtxBuffer */ +Mtx* J3DMtxBuffer::sNoUseDrawMtxPtr = &J3DMtxBuffer::sNoUseDrawMtx; + +/* 80450974-80450978 -00001 0004+00 1/1 0/0 0/0 .sdata sNoUseNrmMtxPtr__12J3DMtxBuffer */ +Mtx33* J3DMtxBuffer::sNoUseNrmMtxPtr = &J3DMtxBuffer::sNoUseNrmMtx; /* 80326214-80326258 320B54 0044+00 0/0 1/1 0/0 .text initialize__12J3DMtxBufferFv */ void J3DMtxBuffer::initialize() { @@ -33,8 +46,10 @@ enum { }; s32 J3DMtxBuffer::create(J3DModelData* p_modelData, u32 flag) { - s32 ret; + J3D_ASSERT(76, p_modelData, "Error : null pointer."); + J3D_ASSERT(77, flag, "Error : non-zero argument is specified 0."); + s32 ret = 0; mFlags = flag; mJointTree = &p_modelData->getJointTree(); @@ -49,7 +64,8 @@ s32 J3DMtxBuffer::create(J3DModelData* p_modelData, u32 flag) { if (p_modelData->checkFlag(J3DMdlDataFlag_NoAnimation)) { setNoUseDrawMtx(); } else { - switch (getMdlDataFlag_MtxLoadType(p_modelData->getFlag())) { + u32 loadType = getMdlDataFlag_MtxLoadType(p_modelData->getFlag()); + switch (loadType) { case J3DMdlDataFlag_ConcatView: ret = setNoUseDrawMtx(); break; @@ -77,7 +93,7 @@ s32 J3DMtxBuffer::create(J3DModelData* p_modelData, u32 flag) { /* 80326364-803263F0 320CA4 008C+00 1/1 0/0 0/0 .text createAnmMtx__12J3DMtxBufferFP12J3DModelData */ -s32 J3DMtxBuffer::createAnmMtx(J3DModelData* p_modelData) { + J3DError J3DMtxBuffer::createAnmMtx(J3DModelData* p_modelData) { if (p_modelData->getJointNum() != 0) { mpScaleFlagArr = new u8[p_modelData->getJointNum()]; mpAnmMtx = new Mtx[p_modelData->getJointNum()]; @@ -87,7 +103,10 @@ s32 J3DMtxBuffer::createAnmMtx(J3DModelData* p_modelData) { if (mpScaleFlagArr == NULL) return kJ3DError_Alloc; - return mpAnmMtx == NULL ? kJ3DError_Alloc : kJ3DError_Success; + if (mpAnmMtx == NULL) { + return kJ3DError_Alloc; + } + return kJ3DError_Success; } /* 803263F0-8032648C 320D30 009C+00 1/1 0/0 0/0 .text @@ -106,27 +125,12 @@ s32 J3DMtxBuffer::createWeightEnvelopeMtx(J3DModelData* p_modelData) { return kJ3DError_Success; } -/* 804371C0-804371F0 063EE0 0030+00 1/0 0/0 0/0 .bss sNoUseDrawMtx__12J3DMtxBuffer */ -Mtx J3DMtxBuffer::sNoUseDrawMtx; - -/* 804371F0-80437218 063F10 0024+04 1/0 0/0 0/0 .bss sNoUseNrmMtx__12J3DMtxBuffer */ -Mtx33 J3DMtxBuffer::sNoUseNrmMtx; - -/* 80450970-80450974 -00001 0004+00 1/1 0/0 0/0 .sdata sNoUseDrawMtxPtr__12J3DMtxBuffer */ -Mtx* J3DMtxBuffer::sNoUseDrawMtxPtr = &J3DMtxBuffer::sNoUseDrawMtx; - -/* 80450974-80450978 -00001 0004+00 1/1 0/0 0/0 .sdata sNoUseNrmMtxPtr__12J3DMtxBuffer */ -Mtx33* J3DMtxBuffer::sNoUseNrmMtxPtr = &J3DMtxBuffer::sNoUseNrmMtx; - /* 8032648C-803264B8 320DCC 002C+00 1/1 0/0 0/0 .text setNoUseDrawMtx__12J3DMtxBufferFv */ s32 J3DMtxBuffer::setNoUseDrawMtx() { - mpDrawMtxArr[1] = &sNoUseDrawMtxPtr; - mpDrawMtxArr[0] = &sNoUseDrawMtxPtr; - mpNrmMtxArr[1] = &sNoUseNrmMtxPtr; - mpNrmMtxArr[0] = &sNoUseNrmMtxPtr; - mpBumpMtxArr[1] = NULL; - mpBumpMtxArr[0] = NULL; + mpDrawMtxArr[0] = mpDrawMtxArr[1] = &sNoUseDrawMtxPtr; + mpNrmMtxArr[0] = mpNrmMtxArr[1] = &sNoUseNrmMtxPtr; + mpBumpMtxArr[0] = mpBumpMtxArr[1] = NULL; return kJ3DError_Success; } @@ -142,7 +146,7 @@ s32 J3DMtxBuffer::createDoubleDrawMtx(J3DModelData* p_modelData, u32 num) { } if (num != 0) { - for (u32 i = 0; i < 2; i++) { + for (s32 i = 0; i < 2; i++) { if (mpDrawMtxArr[i] == NULL) return kJ3DError_Alloc; if (mpNrmMtxArr[i] == NULL) @@ -176,8 +180,9 @@ s32 J3DMtxBuffer::createDoubleDrawMtx(J3DModelData* p_modelData, u32 num) { /* 80326664-803268D4 320FA4 0270+00 1/1 0/0 0/0 .text * createBumpMtxArray__12J3DMtxBufferFP12J3DModelDataUl */ s32 J3DMtxBuffer::createBumpMtxArray(J3DModelData* i_modelData, u32 param_1) { + J3D_ASSERT(295, i_modelData, "Error : null pointer."); if (i_modelData->getModelDataType() == 0) { - u32 bumpMtxNum = 0; + u16 bumpMtxNum = 0; u16 materialCount = 0; u16 materialNum = i_modelData->getMaterialNum(); for (u16 j = 0; j < materialNum; j++) { @@ -188,7 +193,7 @@ s32 J3DMtxBuffer::createBumpMtxArray(J3DModelData* i_modelData, u32 param_1) { } } - if ((u16)bumpMtxNum != 0 && param_1 != 0) { + if (bumpMtxNum != 0 && param_1 != 0) { for (int i = 0; i < 2; i++) { mpBumpMtxArr[i] = new Mtx33**[(u16)materialCount]; if (mpBumpMtxArr[i] == NULL) { @@ -217,7 +222,7 @@ s32 J3DMtxBuffer::createBumpMtxArray(J3DModelData* i_modelData, u32 param_1) { u32 offset = 0; u16 materialNum = i_modelData->getMaterialNum(); for (u16 j = 0; j < materialNum; j++) { - J3DMaterial* material = i_modelData->getMaterialNodePointer(j); + J3DMaterial* material = i_modelData->getMaterialNodePointer((u16)j); if (material->getNBTScale()->mbHasScale == true) { for (int k = 0; k < param_1; k++) { mpBumpMtxArr[i][offset][k] = new (0x20) Mtx33[i_modelData->getDrawMtxNum()]; @@ -245,23 +250,53 @@ static u8 J3DUnit01[8] = { /* 803268D4-80326ACC 321214 01F8+00 0/0 1/1 0/0 .text calcWeightEnvelopeMtx__12J3DMtxBufferFv */ void J3DMtxBuffer::calcWeightEnvelopeMtx() { - int max = mJointTree->getWEvlpMtxNum(); - u16* indices = mJointTree->getWEvlpMixIndex(); - f32* weights = mJointTree->getWEvlpMixWeight(); - for (int i = -1; i < max; i++) { - u8* scaleFlags = mpEvlpScaleFlagArr; - scaleFlags[i] = 1; - Mtx* weightAnmMtx = &mpWeightEvlpMtx[i]; - int mixNum = mJointTree->getWEvlpMixMtxNum(i); - for (int j = 0; j < mixNum; j++) { - u16 idx = indices[j]; - f32 weight = weights[j]; - Mtx& invMtx = mJointTree->getInvJointMtx(idx); - Mtx& worldMtx = mpUserAnmMtx[idx]; - // I think it's this but as ASM? maybe? - MTXConcat(invMtx, worldMtx, *weightAnmMtx); - scaleFlags[i] &= mpScaleFlagArr[j]; - } + MtxP weightAnmMtx; + Mtx* worldMtx; + Mtx* invMtx; + f32 weight; + int idx; + int j; + int mixNum; + int i; + u8 stack_8; + int max; + u16* indices; + f32* weights; + u8* pScale; + Mtx mtx; + i = -1; + max = mJointTree->getWEvlpMtxNum(); + indices = mJointTree->getWEvlpMixMtxIndex() - 1; + weights = mJointTree->getWEvlpMixWeight() - 1; + while (++i < max) { + pScale = &mpEvlpScaleFlagArr[i]; + *pScale = 1; + weightAnmMtx = mpWeightEvlpMtx[i]; + weightAnmMtx[0][0] = weightAnmMtx[0][1] = weightAnmMtx[0][2] = weightAnmMtx[0][3] = + weightAnmMtx[1][0] = weightAnmMtx[1][1] = weightAnmMtx[1][2] = weightAnmMtx[1][3] = + weightAnmMtx[2][0] = weightAnmMtx[2][1] = weightAnmMtx[2][2] = weightAnmMtx[2][3] = 0.0f; + j = 0; + mixNum = mJointTree->getWEvlpMixMtxNum(i); + do { + idx = *++indices; + worldMtx = &mpAnmMtx[idx]; + invMtx = &mJointTree->getInvJointMtx((u16)idx); + MTXConcat(*worldMtx, *invMtx, mtx); + weight = *++weights; + weightAnmMtx[0][0] += mtx[0][0] * weight; + weightAnmMtx[0][1] += mtx[0][1] * weight; + weightAnmMtx[0][2] += mtx[0][2] * weight; + weightAnmMtx[0][3] += mtx[0][3] * weight; + weightAnmMtx[1][0] += mtx[1][0] * weight; + weightAnmMtx[1][1] += mtx[1][1] * weight; + weightAnmMtx[1][2] += mtx[1][2] * weight; + weightAnmMtx[1][3] += mtx[1][3] * weight; + weightAnmMtx[2][0] += mtx[2][0] * weight; + weightAnmMtx[2][1] += mtx[2][1] * weight; + weightAnmMtx[2][2] += mtx[2][2] * weight; + weightAnmMtx[2][3] += mtx[2][3] * weight; + *pScale &= mpScaleFlagArr[idx]; + } while (++j < mixNum); } } diff --git a/src/JSystem/J3DGraphAnimator/J3DSkinDeform.cpp b/src/JSystem/J3DGraphAnimator/J3DSkinDeform.cpp index 9dd2cd165a4..fe9a21ebb3a 100644 --- a/src/JSystem/J3DGraphAnimator/J3DSkinDeform.cpp +++ b/src/JSystem/J3DGraphAnimator/J3DSkinDeform.cpp @@ -57,20 +57,24 @@ static void J3DPSWeightMTXMultVecSR(f32 (*param_0)[4], f32 param_1, Vec* param_2 /* 8032C85C-8032C8E4 32719C 0088+00 1/1 0/0 0/0 .text calcSkin_VtxPosF32__12J3DSkinNListFPA4_fPvPv */ void J3DSkinNList::calcSkin_VtxPosF32(f32 (*param_0)[4], void* param_1, void* param_2) { - u16 r29 = field_0x10; + int r29 = field_0x10; for (int i = 0; i < r29; i++) { - u16 ind = field_0x0[i]; - J3DPSWeightMTXMultVec(param_0, field_0x8[i], ((Vec*)param_1 + ind), ((Vec*)param_2 + ind)); + Vec* pVec1 = (Vec*)param_1 + field_0x0[i]; + Vec* pVec2 = (Vec*)param_2 + field_0x0[i]; + f32 weight = field_0x8[i]; + J3DPSWeightMTXMultVec(param_0, weight, pVec1, pVec2); } } /* 8032C8E4-8032C96C 327224 0088+00 1/1 0/0 0/0 .text calcSkin_VtxNrmF32__12J3DSkinNListFPA4_fPvPv */ void J3DSkinNList::calcSkin_VtxNrmF32(f32 (*param_0)[4], void* param_1, void* param_2) { - u16 r29 = field_0x12; + int r29 = field_0x12; for (int i = 0; i < r29; i++) { - u16 ind = field_0x4[i]; - J3DPSWeightMTXMultVecSR(param_0, field_0xc[i], ((Vec*)param_1 + ind), ((Vec*)param_2 + ind)); + Vec* pVec1 = (Vec*)param_1 + field_0x4[i]; + Vec* pVec2 = (Vec*)param_2 + field_0x4[i]; + f32 weight = field_0xc[i]; + J3DPSWeightMTXMultVecSR(param_0, weight, pVec1, pVec2); } } @@ -100,7 +104,9 @@ f32* J3DSkinDeform::sWorkArea_WEvlpMixWeight[1024]; /* 8032C9B0-8032CF44 3272F0 0594+00 0/0 1/1 0/0 .text * initSkinInfo__13J3DSkinDeformFP12J3DModelData */ void J3DSkinDeform::initSkinInfo(J3DModelData* param_0) { - u16 wevlpMtxNum = param_0->getWEvlpMtxNum(); + J3D_ASSERT(322, param_0, "Error : null pointer."); + int vtxNum = param_0->getVtxNum(); + int wevlpMtxNum = param_0->getWEvlpMtxNum(); u16* wevlpMtxIndex = param_0->getWEvlpMixMtxIndex(); f32* wevlpMixWeights = param_0->getWEvlpMixWeight(); int currentOffset = 0; @@ -122,7 +128,7 @@ void J3DSkinDeform::initSkinInfo(J3DModelData* param_0) { mSkinNList[drawMtxIndex].field_0x10++; } else { u16 drawMtxIndex = param_0->getDrawMtxIndex(uVar8); - wevlpMtxNum = param_0->getWEvlpMixMtxNum(drawMtxIndex); + int wevlpMtxNum = param_0->getWEvlpMixMtxNum(drawMtxIndex); u16* indices = sWorkArea_WEvlpMixMtx[drawMtxIndex]; for (int j = 0; j < wevlpMtxNum; j++) { mSkinNList[indices[j]].field_0x10++; @@ -138,7 +144,7 @@ void J3DSkinDeform::initSkinInfo(J3DModelData* param_0) { mSkinNList[drawMtxIndex].field_0x12++; } else { u16 drawMtxIndex = param_0->getDrawMtxIndex(uVar8); - wevlpMtxNum = param_0->getWEvlpMixMtxNum(drawMtxIndex); + int wevlpMtxNum = param_0->getWEvlpMixMtxNum(drawMtxIndex); u16* indices = sWorkArea_WEvlpMixMtx[drawMtxIndex]; for (int j = 0; j < wevlpMtxNum; j++) { mSkinNList[indices[j]].field_0x12++; @@ -163,16 +169,16 @@ void J3DSkinDeform::initSkinInfo(J3DModelData* param_0) { if (uVar8 != 0xffff) { if (param_0->getDrawMtxFlag(uVar8) == 0) { u16 drawMtxIndex = param_0->getDrawMtxIndex(uVar8); - u16 uVar9 = mSkinNList[drawMtxIndex].field_0x10++; + int uVar9 = mSkinNList[drawMtxIndex].field_0x10++; mSkinNList[drawMtxIndex].field_0x0[uVar9] = i; mSkinNList[drawMtxIndex].field_0x8[uVar9] = 1.0f; } else { u16 drawMtxIndex = param_0->getDrawMtxIndex(uVar8); - wevlpMtxNum = param_0->getWEvlpMixMtxNum(drawMtxIndex); + int wevlpMtxNum = param_0->getWEvlpMixMtxNum(drawMtxIndex); u16* indices = sWorkArea_WEvlpMixMtx[drawMtxIndex]; f32* weights = sWorkArea_WEvlpMixWeight[drawMtxIndex]; for (int j = 0; j < wevlpMtxNum; j++) { - u16 uVar9 = mSkinNList[indices[j]].field_0x10++; + int uVar9 = mSkinNList[indices[j]].field_0x10++; mSkinNList[indices[j]].field_0x0[uVar9] = i; mSkinNList[indices[j]].field_0x8[uVar9] = weights[j]; } @@ -184,16 +190,16 @@ void J3DSkinDeform::initSkinInfo(J3DModelData* param_0) { if (uVar8 != 0xffff) { if (param_0->getDrawMtxFlag(uVar8) == 0) { u16 drawMtxIndex = param_0->getDrawMtxIndex(uVar8); - u16 uVar9 = mSkinNList[drawMtxIndex].field_0x12++; + int uVar9 = mSkinNList[drawMtxIndex].field_0x12++; mSkinNList[drawMtxIndex].field_0x4[uVar9] = i; mSkinNList[drawMtxIndex].field_0xc[uVar9] = 1.0f; } else { u16 drawMtxIndex = param_0->getDrawMtxIndex(uVar8); - wevlpMtxNum = param_0->getWEvlpMixMtxNum(drawMtxIndex); + int wevlpMtxNum = param_0->getWEvlpMixMtxNum(drawMtxIndex); u16* indices = sWorkArea_WEvlpMixMtx[drawMtxIndex]; f32* weights = sWorkArea_WEvlpMixWeight[drawMtxIndex]; for (int j = 0; j < wevlpMtxNum; j++) { - u16 uVar9 = mSkinNList[indices[j]].field_0x12++; + int uVar9 = mSkinNList[indices[j]].field_0x12++; mSkinNList[indices[j]].field_0x4[uVar9] = i; mSkinNList[indices[j]].field_0xc[uVar9] = weights[j]; } @@ -208,8 +214,9 @@ u16 J3DSkinDeform::sWorkArea_MtxReg[1024 + 4 /* padding */]; /* 8032CF44-8032D378 327884 0434+00 0/0 1/1 0/0 .text * initMtxIndexArray__13J3DSkinDeformFP12J3DModelData */ -// NONMATCHING - Several register order and regalloc issues +// NONMATCHING - local_58 issue int J3DSkinDeform::initMtxIndexArray(J3DModelData* param_0) { + J3D_ASSERT(507, param_0, "Error : null pointer."); if (mPosData != NULL && mNrmData != NULL) { return 0; } @@ -249,6 +256,7 @@ int J3DSkinDeform::initMtxIndexArray(J3DModelData* param_0) { int r26 = -1; int r25 = -1; int r24 = -1; + int stack_3c = -1; int r23 = 0; for (GXVtxDescList* local_4c = param_0->getShapeNodePointer(local_6c)->getVtxDesc(); local_4c->attr != 0xff; local_4c++) { switch (local_4c->attr) { @@ -270,6 +278,7 @@ int J3DSkinDeform::initMtxIndexArray(J3DModelData* param_0) { } break; case GX_VA_TEX0: + stack_3c = r23; if (local_4c->type != GX_INDEX16) { OSReport(" Invlid Data : CPU Pipeline process GX_INDEX16 Data Only\n"); return 6; @@ -281,29 +290,36 @@ int J3DSkinDeform::initMtxIndexArray(J3DModelData* param_0) { for (u16 local_6e = 0; local_6e < param_0->getShapeNodePointer(local_6c)->getMtxGroupNum(); local_6e++) { J3DShapeMtx* piVar8 = param_0->getShapeNodePointer(local_6c)->getShapeMtx(local_6e); u8* pcVar10 = param_0->getShapeNodePointer(local_6c)->getShapeDraw(local_6e)->getDisplayList(); - u16 uVar13; - for (u8* local_58 = pcVar10; + u8* local_58 = pcVar10; + int uVar13; + for (; (int)local_58 - (int)pcVar10 < param_0->getShapeNodePointer(local_6c)->getShapeDraw(local_6e)->getDisplayListSize(); - local_58 += r23 * uVar13, local_58 += 3) { - if (*local_58 != 0xA0 && *local_58 != 0x98) { + local_58 += r23 * uVar13) { + u8 uVar1 = *local_58; + local_58++; + if (uVar1 != 0xA0 && uVar1 != 0x98) { break; } - uVar13 = *(u16*)(local_58 + 1); + uVar13 = *(u16*)local_58; + local_58 += 2; for (int local_60 = 0; local_60 < uVar13; local_60++) { - u8* iVar5 = local_58; - iVar5 += r23 * local_60 + 3; + u8* iVar5 = local_58 + r23 * local_60; u8 bVar3 = *(iVar5 + r26) / 3U; u16 uVar1 = *(u16*)(iVar5 + r25); u16 uVar2 = *(u16*)(iVar5 + r24); - u32 local_76 = piVar8->getUseMtxIndex(bVar3); - if ((u16)local_76 == 0xffff) { + u16 uVar3 = *(u16*)(iVar5 + stack_3c); + u16 local_76 = piVar8->getUseMtxIndex(bVar3); + if (local_76 == 0xffff) { local_76 = sWorkArea_MtxReg[bVar3]; } else if (r26 != -1) { sWorkArea_MtxReg[bVar3] = local_76; } + J3D_ASSERT(673, local_76 < param_0->getDrawMtxNum(), "Error : range over."); + J3D_ASSERT(674, uVar1 < param_0->getVtxNum(), "Error : range over."); mPosData[uVar1] = local_76; if (r24 != -1) { + J3D_ASSERT(680, uVar2 < param_0->getNrmNum(), "Error : range over."); mNrmData[uVar2] = local_76; } } @@ -315,58 +331,55 @@ int J3DSkinDeform::initMtxIndexArray(J3DModelData* param_0) { } } - for (int local_68 = 0; local_68 < param_0->getVtxNum(); local_68++) { - if (mPosData[local_68] == 0xffff) { + for (int i = 0; i < param_0->getVtxNum(); i++) { + if (mPosData[i] == 0xffff) { field_0x18 = 0x0; - mPosData[local_68] = 0; + mPosData[i] = 0; + OS_REPORT("Error : Invalid Positon Data Exists!."); + OS_REPORT("Error : Invalid Positon Index = %d\n", i); } } return 0; } -/* ############################################################################################## */ -/* 803A2018-803A2028 02E678 0010+00 1/1 0/0 0/0 .rodata @1270 */ -SECTION_RODATA static u8 const lit_1270[16] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, -}; -COMPILER_STRIP_GATE(0x803A2018, &lit_1270); - /* 8032D378-8032D5C4 327CB8 024C+00 0/0 1/1 0/0 .text * changeFastSkinDL__13J3DSkinDeformFP12J3DModelData */ // NONMATCHING - regalloc, display list access issues void J3DSkinDeform::changeFastSkinDL(J3DModelData* param_0) { + J3D_ASSERT(740, param_0, "Error : null pointer."); for (u16 i = 0; i < param_0->getShapeNum(); i++) { u32 local_28[4] = {0,1,1,2}; - s32 local_30 = -1; - s32 local_34 = 0; + int local_30 = -1; + int local_34 = 0; J3DShape* pShapeNode = param_0->getShapeNodePointer(i); for (GXVtxDescList* local_3c = pShapeNode->getVtxDesc(); local_3c->attr != GX_VA_NULL; local_3c++) { if (local_3c->attr == GX_VA_PNMTXIDX) { local_30 = local_34; } - local_34 += local_28[(int)local_3c->type]; + local_34 += local_28[local_3c->type]; } if (local_30 != -1) { for (u16 j = 0; j < pShapeNode->getMtxGroupNum(); j++) { u8* puVar5 = pShapeNode->getShapeDraw(j)->getDisplayList(); - u8* puVar10 = puVar5; u8* local_44 = puVar5; - while ((int)local_44 - (int)puVar5 < pShapeNode->getShapeDraw(j)->getDisplayListSize()) { - u8 cVar1 = *(u8*)local_44; + u8* puVar10 = puVar5; + while (local_44 - puVar5 < pShapeNode->getShapeDraw(j)->getDisplayListSize()) { + u8 cVar1 = *local_44; + local_44++; *puVar10++ = cVar1; if ((cVar1 != 0xA0) && (cVar1 != 0x98)) break; - u16 uVar9 = *(u16*)((int)local_44 + 1); + int uVar9 = *(u16*)local_44; + local_44 += 2; *(u16*)puVar10 = uVar9; puVar10 += 2; for (int local_4c = 0; local_4c < uVar9; local_4c++) { - u8* dst; - memcpy(puVar10, &local_44[(local_34 * local_4c) + 4], local_34 - 1); - puVar10 = (u8*)((int)puVar10 + local_34 - 1); + u8* dst = &local_44[local_34 * local_4c]; + memcpy(puVar10, dst + 1, local_34 - 1); + puVar10 = ((local_34 + puVar10) - 1); } local_44 += local_34 * uVar9; - local_44 += 3; } int pcVar2 = ((int)puVar10 - (int)puVar5 + 0x1f) & ~0x1f; while ((int)puVar10 - (int)puVar5 < pShapeNode->getShapeDraw(j)->getDisplayListSize()) { @@ -377,11 +390,13 @@ void J3DSkinDeform::changeFastSkinDL(J3DModelData* param_0) { } } } - + ; + ; for (u16 i = 0; i < param_0->getShapeNum(); i++) { J3DShape* pShape = param_0->getShapeNodePointer(i); - GXVtxDescList* local_60 = pShape->getVtxDesc(); - for (GXVtxDescList*local_5c = local_60; local_5c->attr != GX_VA_NULL; local_5c++) { + GXVtxDescList* local_5c = pShape->getVtxDesc(); + GXVtxDescList* local_60 = local_5c; + for (; local_5c->attr != GX_VA_NULL; local_5c++) { if (local_5c->attr != GX_VA_PNMTXIDX) { local_60->attr = local_5c->attr; local_60->type = local_5c->type; @@ -567,7 +582,7 @@ void J3DSkinDeform::deformVtxNrm_F32(J3DVertexBuffer* param_0) const { void* currentVtxNrm = param_0->getCurrentVtxNrm(); void* transformedVtxNrm = param_0->getTransformedVtxNrm(0); for (int i = 0; i < nrmNum; i++) { - J3DPSMulMtxVec(mNrmMtx[mNrmData[i]], ((Vec*)currentVtxNrm) + i, ((Vec*)transformedVtxNrm) + i); + J3DPSMulMtxVec(mNrmMtx[mNrmData[i]], (Vec*)((u8*)currentVtxNrm + i * 3 * 4), (Vec*)((u8*)transformedVtxNrm + i * 3 * 4)); } DCStoreRange(param_0->getTransformedVtxNrm(0), param_0->getVertexData()->getNrmNum() * sizeof(Vec)); param_0->setCurrentVtxNrm(transformedVtxNrm);