diff --git a/include/JSystem/J3DGraphBase/J3DShape.h b/include/JSystem/J3DGraphBase/J3DShape.h index 944fe20ce..21ce6841f 100644 --- a/include/JSystem/J3DGraphBase/J3DShape.h +++ b/include/JSystem/J3DGraphBase/J3DShape.h @@ -105,6 +105,7 @@ public: void setTexMtxLoadType(u32 type) { mFlags = (mFlags & 0xFFFF0FFF) | type; } bool getNBTFlag() const { return mHasNBT; } u32 getBumpMtxOffset() const { return mBumpMtxOffset; } + void setBumpMtxOffset(u32 offs) { mBumpMtxOffset = offs; } GXVtxDescList* getVtxDesc() const { return mVtxDesc; } J3DMaterial* getMaterial() const { return mMaterial; } diff --git a/src/JSystem/J3DGraphAnimator/J3DModel.cpp b/src/JSystem/J3DGraphAnimator/J3DModel.cpp index 2efb3af1f..81b410393 100644 --- a/src/JSystem/J3DGraphAnimator/J3DModel.cpp +++ b/src/JSystem/J3DGraphAnimator/J3DModel.cpp @@ -319,8 +319,57 @@ s32 J3DModel::createMatPacket(J3DModelData* pModelData, u32 flag) { } /* 802EDF60-802EE1D4 .text createBumpMtxArray__8J3DModelFP12J3DModelDataUl */ -s32 J3DModel::createBumpMtxArray(J3DModelData*, unsigned long) { +s32 J3DModel::createBumpMtxArray(J3DModelData* modelData, u32 flag) { /* Nonmatching */ + if (modelData->getModelDataType() == 0) { + u16 num = 0; + for (s32 matIdx = 0; matIdx < modelData->getMaterialNum(); matIdx++) { + J3DMaterial * pMaterial = getModelData()->getMaterialNodePointer(matIdx); + if (pMaterial->getNBTScale()->mbHasScale == 1) + num += pMaterial->getShape()->countBumpMtxNum(); + } + + if (num != 0 && flag != 0) { + for (s32 i = 0; i < 2; i++) { + mpBumpMtxArr[i] = new Mtx33**[num]; + if (mpBumpMtxArr[i] == NULL) + return kJ3DError_Alloc; + } + } + + for (s32 i = 0; i < 2; i++) { + u32 bumpMtxOffset = 0; + for (s32 matIdx = 0; matIdx < modelData->getMaterialNum(); matIdx++) { + J3DMaterial * pMaterial = getModelData()->getMaterialNodePointer(matIdx); + if (pMaterial->getNBTScale()->mbHasScale == 1) { + mpBumpMtxArr[i][matIdx] = new Mtx33*[num]; + if (mpBumpMtxArr[i][matIdx] == NULL) + return kJ3DError_Alloc; + pMaterial->getShape()->setBumpMtxOffset(bumpMtxOffset); + bumpMtxOffset++; + } + } + } + + for (s32 i = 0; i < 2; i++) { + u32 bumpMtxOffset = 0; + for (s32 matIdx = 0; matIdx < modelData->getMaterialNum(); matIdx++) { + J3DMaterial * pMaterial = getModelData()->getMaterialNodePointer(matIdx); + if (pMaterial->getNBTScale()->mbHasScale == 1) { + for (u32 j = 0; j < flag; j++) { + mpBumpMtxArr[i][matIdx][j] = new(0x20) Mtx33[modelData->getDrawMtxNum()]; + if (mpBumpMtxArr[i][matIdx][j] == NULL) + return kJ3DError_Alloc; + } + } + } + } + + if (num != 0) + getModelData()->setBumpFlag(1); + } + + return kJ3DError_Success; } /* 802EE1D4-802EE254 .text newDifferedDisplayList__8J3DModelFUl */ @@ -372,7 +421,7 @@ void J3DModel::calcMaterial() { for (u16 i = 0; i < mModelData->getMaterialNum(); i++) { j3dSys.setMatPacket(&mpMatPacket[i]); - + J3DMaterial* pMaterial = mModelData->getMaterialNodePointer(i); if (pMaterial->getMaterialAnm() != NULL) pMaterial->getMaterialAnm()->calc(pMaterial);