From c19d9b02be5d894f91cd45884eed67152dffffa4 Mon Sep 17 00:00:00 2001 From: hatal175 Date: Tue, 6 Feb 2024 07:04:35 +0200 Subject: J3D work (#2064) --- include/JSystem/J3DGraphAnimator/J3DAnimation.h | 15 ++- include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h | 33 ++++++- .../JSystem/J3DGraphAnimator/J3DMaterialAttach.h | 10 +- include/JSystem/J3DGraphBase/J3DMatBlock.h | 10 +- include/JSystem/J3DGraphBase/J3DMaterial.h | 2 + include/JSystem/J3DGraphBase/J3DStruct.h | 2 + include/JSystem/J3DGraphBase/J3DTevs.h | 109 +++++++++++++++++---- include/JSystem/J3DGraphBase/J3DTexture.h | 6 ++ 8 files changed, 151 insertions(+), 36 deletions(-) (limited to 'include/JSystem') diff --git a/include/JSystem/J3DGraphAnimator/J3DAnimation.h b/include/JSystem/J3DGraphAnimator/J3DAnimation.h index be944dd686..565eb289dd 100644 --- a/include/JSystem/J3DGraphAnimator/J3DAnimation.h +++ b/include/JSystem/J3DGraphAnimator/J3DAnimation.h @@ -89,7 +89,7 @@ struct J3DAnmCRegKeyTable { /* 0x06 */ J3DAnmKeyTableBase mGTable; /* 0x0C */ J3DAnmKeyTableBase mBTable; /* 0x12 */ J3DAnmKeyTableBase mATable; - /* 0x18 */ u8 _18; + /* 0x18 */ u8 mColorId; u8 padding[3]; }; // Size = 0x1C @@ -98,7 +98,7 @@ struct J3DAnmKRegKeyTable { /* 0x06 */ J3DAnmKeyTableBase mGTable; /* 0x0C */ J3DAnmKeyTableBase mBTable; /* 0x12 */ J3DAnmKeyTableBase mATable; - /* 0x18 */ u8 _18; + /* 0x18 */ u8 mColorId; u8 padding[3]; }; // Size = 0x1C @@ -444,6 +444,11 @@ public: u16 getUpdateMaterialID(u16 idx) const { return mUpdateMaterialID[idx]; } u16 getUpdateMaterialNum() const { return mTrackNum / 3; } + int getUpdateTexMtxID(u16 idx) { return mUpdateTexMtxID[idx]; } + bool isValidUpdateMaterialID(u16 idx) const { return mUpdateMaterialID[idx] != 0xffff; } + u32 getTexMtxCalcType() const { return mTexMtxCalcType; } + Vec* getSRTCenter(u16 idx) { return &mSRTCenter[idx]; } + /* 0x0C */ int mDecShift; /* 0x10 */ J3DAnmTransformKeyTable* mAnmTable; /* 0x14 */ u16 mTrackNum; @@ -512,6 +517,12 @@ public: u16 getCRegUpdateMaterialID(u16 idx) const { return mCRegUpdateMaterialID[idx]; } u16 getKRegUpdateMaterialID(u16 idx) const { return mKRegUpdateMaterialID[idx]; } + const J3DAnmCRegKeyTable* getAnmCRegKeyTable() const { return mAnmCRegKeyTable; } + const J3DAnmKRegKeyTable* getAnmKRegKeyTable() const { return mAnmKRegKeyTable; } + + bool isValidCRegUpdateMaterialID(u16 idx) { return mCRegUpdateMaterialID[idx] != 0xffff; } + bool isValidKRegUpdateMaterialID(u16 idx) { return mKRegUpdateMaterialID[idx] != 0xffff; } + /* 0x0C */ u16 mCRegUpdateMaterialNum; /* 0x0E */ u16 mKRegUpdateMaterialNum; /* 0x10 */ u16 mCRegDataCountR; diff --git a/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h b/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h index b2d5316afb..91ecb818a5 100644 --- a/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h +++ b/include/JSystem/J3DGraphAnimator/J3DMaterialAnm.h @@ -10,6 +10,11 @@ class J3DMatColorAnm { public: /* 8003B2B8 */ ~J3DMatColorAnm() {}; /* 8003B2F4 */ J3DMatColorAnm() {}; + J3DMatColorAnm(u16 param_1, J3DAnmColor* param_2) { + field_0x0 = param_1; + mAnmFlag = 1; + mAnmColor = param_2; + } void operator=(J3DMatColorAnm const& other) { mAnmColor = other.mAnmColor; @@ -31,6 +36,11 @@ class J3DTexNoAnm { public: /* 8003B1F8 */ ~J3DTexNoAnm() {}; /* 8003B240 */ J3DTexNoAnm() {}; + J3DTexNoAnm(u16 param_1, J3DAnmTexPattern* param_2) { + field_0x4 = param_1; + mAnmFlag = 1; + mAnmTexPattern = param_2; + } /* 8003C82C */ virtual void calc(u16* param_0) const { mAnmTexPattern->getTexNo(field_0x4, param_0); } void operator=(J3DTexNoAnm const& other) { @@ -53,6 +63,11 @@ class J3DTexMtxAnm { public: /* 8003B264 */ ~J3DTexMtxAnm() {}; /* 8003B2A0 */ J3DTexMtxAnm() {}; + J3DTexMtxAnm(u16 param_1, J3DAnmTextureSRTKey* param_2) { + field_0x0 = param_1; + mAnmFlag = 1; + mAnmTransform = param_2; + } void operator=(J3DTexMtxAnm const& other) { mAnmTransform = other.mAnmTransform; @@ -74,8 +89,13 @@ private: class J3DTevKColorAnm { public: - /* 8003B150 */ ~J3DTevKColorAnm() {}; - /* 8003B18C */ J3DTevKColorAnm() {}; + /* 8003B150 */ ~J3DTevKColorAnm() {} + /* 8003B18C */ J3DTevKColorAnm() {} + J3DTevKColorAnm(u16 param_1, J3DAnmTevRegKey* param_2) { + field_0x0 = param_1; + mAnmFlag = 1; + mAnmTevReg = param_2; + } void operator=(J3DTevKColorAnm const& other) { mAnmTevReg = other.mAnmTevReg; @@ -95,8 +115,13 @@ private: class J3DTevColorAnm { public: - /* 8003B1A4 */ ~J3DTevColorAnm() {}; - /* 8003B1E0 */ J3DTevColorAnm() {}; + /* 8003B1A4 */ ~J3DTevColorAnm() {} + /* 8003B1E0 */ J3DTevColorAnm() {} + J3DTevColorAnm(u16 param_1, J3DAnmTevRegKey* param_2) { + field_0x0 = param_1; + mAnmFlag = 1; + mAnmTevReg = param_2; + } void operator=(J3DTevColorAnm const& other) { mAnmTevReg = other.mAnmTevReg; diff --git a/include/JSystem/J3DGraphAnimator/J3DMaterialAttach.h b/include/JSystem/J3DGraphAnimator/J3DMaterialAttach.h index d770e32846..4086f29ce5 100644 --- a/include/JSystem/J3DGraphAnimator/J3DMaterialAttach.h +++ b/include/JSystem/J3DGraphAnimator/J3DMaterialAttach.h @@ -19,11 +19,11 @@ public: /* 8032F6F8 */ int removeTexNoAnimator(J3DAnmTexPattern*); /* 8032F7B4 */ int removeTexMtxAnimator(J3DAnmTextureSRTKey*); /* 8032F880 */ int removeTevRegAnimator(J3DAnmTevRegKey*); - /* 8032F9C0 */ void createTexMtxForAnimator(J3DAnmTextureSRTKey*); - /* 8032FAF4 */ void entryMatColorAnimator(J3DAnmColor*); - /* 8032FBC8 */ void entryTexNoAnimator(J3DAnmTexPattern*); - /* 8032FCC4 */ void entryTexMtxAnimator(J3DAnmTextureSRTKey*); - /* 8032FE70 */ void entryTevRegAnimator(J3DAnmTevRegKey*); + /* 8032F9C0 */ int createTexMtxForAnimator(J3DAnmTextureSRTKey*); + /* 8032FAF4 */ int entryMatColorAnimator(J3DAnmColor*); + /* 8032FBC8 */ int entryTexNoAnimator(J3DAnmTexPattern*); + /* 8032FCC4 */ int entryTexMtxAnimator(J3DAnmTextureSRTKey*); + /* 8032FE70 */ int entryTevRegAnimator(J3DAnmTevRegKey*); /* 8032F604 */ virtual ~J3DMaterialTable(); diff --git a/include/JSystem/J3DGraphBase/J3DMatBlock.h b/include/JSystem/J3DGraphBase/J3DMatBlock.h index 4f8e8bf0aa..d488d0b703 100644 --- a/include/JSystem/J3DGraphBase/J3DMatBlock.h +++ b/include/JSystem/J3DGraphBase/J3DMatBlock.h @@ -48,7 +48,7 @@ public: /* 8000DFE8 */ virtual u32 getTexGenNum() const; /* 8000E0CC */ virtual void setTexCoord(u32, J3DTexCoord const*); /* 8000DFE0 */ virtual J3DTexCoord* getTexCoord(u32); - /* 8003AB2C */ virtual void setTexMtx(u32, J3DTexMtx*); + /* 8003AB2C */ virtual void setTexMtx(u32, J3DTexMtx*) {} /* 8000DFD8 */ virtual J3DTexMtx* getTexMtx(u32); /* 80317424 */ virtual void setNBTScale(J3DNBTScale const*); /* 80317420 */ virtual void setNBTScale(J3DNBTScale); @@ -611,7 +611,7 @@ inline u32 calcAlphaCmpID(u32 param_1, u32 param_2, u32 param_3) { return ((param_1 & 0xff) << 5) + ((param_2 & 0xff) << 3) + (param_3 & 0xff); } -// matches for `J3DMaterialFactory::newAlphaComp` but fails for `d_resorce::addWarpMaterial` +// matches for `J3DMaterialFactory::newAlphaComp,J3DMaterialFactory_v21::newAlphaComp` but fails for `d_resorce::addWarpMaterial` // inline u32 calcAlphaCmpID(u8 param_1, u8 param_2, u8 param_3) { // return param_1 * 0x20 + param_2 * 8 + param_3; // } @@ -794,7 +794,7 @@ struct J3DIndTexCoordScaleInfo { /* 0x3 */ u8 field_0x3; }; // Size: 0x4 -extern J3DIndTexCoordScaleInfo j3dDefaultIndTexCoordScaleInfo; +extern const J3DIndTexCoordScaleInfo j3dDefaultIndTexCoordScaleInfo; struct J3DIndTexCoordScale : public J3DIndTexCoordScaleInfo { /* 8000E0E4 */ J3DIndTexCoordScale() : J3DIndTexCoordScaleInfo(j3dDefaultIndTexCoordScaleInfo) {} @@ -817,7 +817,7 @@ struct J3DIndTexOrderInfo { /* 0x3 */ u8 field_0x3; }; // Size: 0x04 -extern J3DIndTexOrderInfo j3dDefaultIndTexOrderNull; +extern const J3DIndTexOrderInfo j3dDefaultIndTexOrderNull; struct J3DIndTexOrder : public J3DIndTexOrderInfo { /* 8000E128 */ J3DIndTexOrder() : J3DIndTexOrderInfo(j3dDefaultIndTexOrderNull) {} @@ -895,7 +895,7 @@ struct J3DColorChanInfo { /* 0x6 */ u8 pad[2]; }; -extern J3DColorChanInfo j3dDefaultColorChanInfo; +extern const J3DColorChanInfo j3dDefaultColorChanInfo; /* static inline u32 setChanCtrlMacro(u8 param_0, GXColorSrc param_1, GXColorSrc param_2, u32 param_3, GXDiffuseFn param_4, GXAttnFn param_5) { diff --git a/include/JSystem/J3DGraphBase/J3DMaterial.h b/include/JSystem/J3DGraphBase/J3DMaterial.h index c7838fb96e..fd9fce606a 100644 --- a/include/JSystem/J3DGraphBase/J3DMaterial.h +++ b/include/JSystem/J3DGraphBase/J3DMaterial.h @@ -72,11 +72,13 @@ public: void onInvalid() { mInvalid = 1; } u32 getTexGenNum() const { return mTexGenBlock->getTexGenNum(); } u8 getTevStageNum() const { return mTevBlock->getTevStageNum(); } + J3DTexCoord* getTexCoord(u32 idx) { return mTexGenBlock->getTexCoord(idx); } void setTevColor(u32 i, const J3DGXColorS10* i_color) { mTevBlock->setTevColor(i, i_color); } void setTevKColor(u32 i, const J3DGXColor* i_color) { mTevBlock->setTevKColor(i, i_color); } void setMaterialAnm(J3DMaterialAnm* i_anm) { mMaterialAnm = i_anm; } void setCullMode(u8 i_mode) { mColorBlock->setCullMode(i_mode); } + void setTexMtx(u32 idx, J3DTexMtx* mtx) { mTexGenBlock->setTexMtx(idx, mtx); } public: /* 0x04 */ J3DMaterial* mNext; diff --git a/include/JSystem/J3DGraphBase/J3DStruct.h b/include/JSystem/J3DGraphBase/J3DStruct.h index e0e23f6379..13e097cf3e 100644 --- a/include/JSystem/J3DGraphBase/J3DStruct.h +++ b/include/JSystem/J3DGraphBase/J3DStruct.h @@ -66,6 +66,8 @@ struct J3DTexMtxInfo { /* 0x00 */ u8 mProjection; /* 0x01 */ u8 mInfo; + /* 0x02 */ u8 field_0x2; + /* 0x03 */ u8 field_0x3; /* 0x04 */ Vec mCenter; /* 0x10 */ J3DTextureSRTInfo mSRT; /* 0x24 */ Mtx44 mEffectMtx; diff --git a/include/JSystem/J3DGraphBase/J3DTevs.h b/include/JSystem/J3DGraphBase/J3DTevs.h index 35bfd28691..6453019814 100644 --- a/include/JSystem/J3DGraphBase/J3DTevs.h +++ b/include/JSystem/J3DGraphBase/J3DTevs.h @@ -12,16 +12,101 @@ struct J3DTevStageInfo { /* 0x5 */ u8 mTevAlphaOp; /* 0x6 */ u8 mTevAlphaAB; /* 0x7 */ u8 mTevSwapModeInfo; - /* 0x8 */ u8 field_0x8[0xc]; + /* 0x8 */ u8 field_0x8; + /* 0x8 */ u8 field_0x9; + /* 0x8 */ u8 field_0xa; + /* 0x8 */ u8 field_0xb; + /* 0x8 */ u8 field_0xc; + /* 0x8 */ u8 field_0xd; + /* 0x8 */ u8 field_0xe; + /* 0x8 */ u8 field_0xf; + /* 0x8 */ u8 field_0x10; + /* 0x8 */ u8 field_0x11; + /* 0x8 */ u8 field_0x12; + /* 0x8 */ u8 field_0x13; }; extern J3DTevStageInfo const j3dDefaultTevStageInfo; +struct J3DTevSwapModeTableInfo { + /* 0x0 */ u8 field_0x0; + /* 0x1 */ u8 field_0x1; + /* 0x2 */ u8 field_0x2; + /* 0x3 */ u8 field_0x3; +}; // Size: 0x4 + +extern const J3DTevSwapModeTableInfo j3dDefaultTevSwapModeTable; + +struct J3DTevSwapModeInfo { + /* 0x0 */ u8 mRasSel; + /* 0x1 */ u8 mTexSel; + /* 0x2 */ u8 field_0x2; + /* 0x3 */ u8 field_0x3; +}; // Size: 0x4 + +extern J3DTevSwapModeInfo const j3dDefaultTevSwapMode; + struct J3DTevStage { /* 8000E230 */ J3DTevStage(); - /* 8000E298 */ void setTevStageInfo(J3DTevStageInfo const&); - /* 8003AACC */ J3DTevStage(J3DTevStageInfo const&); + void setTevColorOp(u8 param_1, u8 param_2, u8 param_3, u8 param_4, u8 param_5) { + mTevColorOp = mTevColorOp & ~(0x01 << 2) | param_1 << 2; + if (param_1 <= 1) { + mTevColorOp = mTevColorOp & ~(0x03 << 4) | param_3 << 4; + mTevColorOp = mTevColorOp & ~0x03 | param_2; + } else { + mTevColorOp = mTevColorOp & ~(0x03 << 4) | (param_1 >> 1 & 3) << 4; + mTevColorOp = mTevColorOp & ~0x03 | 3; + } + mTevColorOp = mTevColorOp & ~(0x01 << 3) | param_4 << 3; + mTevColorOp = mTevColorOp & ~(0x03 << 6) | param_5 << 6; + } + + void setTevColorAB(u8 a, u8 b) { mTevColorAB = a << 4 | b; } + void setTevColorCD(u8 c, u8 d) { mTevColorCD = c << 4 | d; } + void setAlphaA(u8 a) { mTevAlphaAB = mTevAlphaAB & ~(0x07 << 5) | a << 5; } + void setAlphaB(u8 b) { mTevAlphaAB = mTevAlphaAB & ~(0x07 << 2) | b << 2; } + void setAlphaC(u8 c) { + mTevAlphaAB = mTevAlphaAB & ~0x03 | c >> 1; + mTevSwapModeInfo = mTevSwapModeInfo & ~(0x01 << 7) | c << 7; + } + void setAlphaD(u8 d) { mTevSwapModeInfo = mTevSwapModeInfo & ~(0x07 << 4) | d << 4; } + void setAlphaABCD(u8 a, u8 b, u8 c, u8 d) { + setAlphaA(a); + setAlphaB(b); + setAlphaC(c); + setAlphaD(d); + } + + void setTevAlphaOp(u8 param_1, u8 param_2, u8 param_3, u8 param_4, u8 param_5) { + mTevAlphaOp = mTevAlphaOp & ~(0x01 << 2) | param_1 << 2; + if (param_1 <= 1) { + mTevAlphaOp = mTevAlphaOp & ~0x03 | param_2; + mTevAlphaOp = mTevAlphaOp & ~(0x03 << 4) | param_3 << 4; + } else { + mTevAlphaOp = mTevAlphaOp & ~(0x03 << 4) | (param_1 >> 1 & 3) << 4; + mTevAlphaOp = mTevAlphaOp & ~0x03 | 3; + } + mTevAlphaOp = mTevAlphaOp & ~(0x01 << 3) | param_4 << 3; + mTevAlphaOp = mTevAlphaOp & ~(0x03 << 6) | param_5 << 6; + } + + void setTevStageInfo(const J3DTevStageInfo& info) { + setTevColorOp(info.mTevAlphaOp, info.mTevAlphaAB, info.mTevSwapModeInfo, info.field_0x8, info.field_0x9); + setTevColorAB(info.mTevColorOp, info.mTevColorAB); + setTevColorCD(info.mTevColorCD, info.field_0x4); + setAlphaABCD(info.field_0xa, info.field_0xb, info.field_0xc, info.field_0xd); + setTevAlphaOp(info.field_0xe, info.field_0xf, info.field_0x10, info.field_0x11, info.field_0x12); + } + /* 8003AACC */ J3DTevStage(J3DTevStageInfo const& param_0) { + setTevStageInfo(param_0); + setTevSwapModeInfo(j3dDefaultTevSwapMode); + } + + void setTevSwapModeInfo(J3DTevSwapModeInfo const& param_0) { + setTexSel(param_0.mTexSel); + setRasSel(param_0.mRasSel); + } void setRasSel(u8 ras_sel) { mTevSwapModeInfo = (mTevSwapModeInfo & ~3) | ras_sel; } void setTexSel(u8 tex_sel) { mTevSwapModeInfo = (mTevSwapModeInfo & ~0xc) | (tex_sel << 2); } @@ -88,7 +173,7 @@ struct J3DTevOrderInfo { /* 0x3 */ u8 field_0x3; // Maybe padding }; -extern J3DTevOrderInfo j3dDefaultTevOrderInfoNull; +extern const J3DTevOrderInfo j3dDefaultTevOrderInfoNull; struct J3DTevOrder : public J3DTevOrderInfo { /* 8000E140 */ J3DTevOrder() : J3DTevOrderInfo(j3dDefaultTevOrderInfoNull) {} @@ -97,15 +182,6 @@ struct J3DTevOrder : public J3DTevOrderInfo { u8 getTexMap() { return mTexMap; } }; -struct J3DTevSwapModeTableInfo { - /* 0x0 */ u8 field_0x0; - /* 0x1 */ u8 field_0x1; - /* 0x2 */ u8 field_0x2; - /* 0x3 */ u8 field_0x3; -}; // Size: 0x4 - -extern J3DTevSwapModeTableInfo j3dDefaultTevSwapModeTable; - struct J3DTevSwapModeTable { /* 8000E134 */ J3DTevSwapModeTable(); J3DTevSwapModeTable(J3DTevSwapModeTableInfo const& info) { @@ -118,13 +194,6 @@ struct J3DTevSwapModeTable { /* 0x0 */ u8 field_0x0; }; // Size: 0x1 -struct J3DTevSwapModeInfo { - /* 0x0 */ u8 mRasSel; - /* 0x1 */ u8 mTexSel; - /* 0x2 */ u8 field_0x2; - /* 0x3 */ u8 field_0x3; -}; // Size: 0x4 - struct J3DNBTScale; struct J3DTexCoord; void loadNBTScale(J3DNBTScale& param_0); diff --git a/include/JSystem/J3DGraphBase/J3DTexture.h b/include/JSystem/J3DGraphBase/J3DTexture.h index c0741a4d0a..6deb7e563f 100644 --- a/include/JSystem/J3DGraphBase/J3DTexture.h +++ b/include/JSystem/J3DGraphBase/J3DTexture.h @@ -28,8 +28,13 @@ public: } }; +extern J3DTexMtxInfo const j3dDefaultTexMtxInfo; + class J3DTexMtx { public: + J3DTexMtx() { + mTexMtxInfo = j3dDefaultTexMtxInfo; + } J3DTexMtx(const J3DTexMtxInfo& info) { mTexMtxInfo = info; } @@ -75,6 +80,7 @@ struct J3DTexCoord : public J3DTexCoordInfo { u8 getTexGenSrc() { return mTexGenSrc; } u8 getTexGenMtx() { return mTexGenMtx & 0xff; } u16 getTexMtxReg() { return mTexMtxReg & 0xff; } + void setTexGenMtx(u8 param_1) { mTexGenMtx = param_1; } void resetTexMtxReg() { mTexMtxReg = mTexGenMtx; -- cgit v1.2.3