#4250 Crash uploading a dae model

master
Andrey Kleshchev 2025-06-18 21:55:57 +03:00 committed by Andrey Kleshchev
parent 5099401a53
commit 5bc92322e9
2 changed files with 28 additions and 23 deletions

View File

@ -1804,21 +1804,23 @@ LLSD LLMeshSkinInfo::asLLSD(bool include_joints, bool lock_scale_if_joint_positi
{
ret["joint_names"][i] = mJointNames[i];
if (i < mInvBindMatrix.size())
{
for (U32 j = 0; j < 4; j++)
{
for (U32 k = 0; k < 4; k++)
{
ret["inverse_bind_matrix"][i][j*4+k] = mInvBindMatrix[i].mMatrix[j][k];
}
}
}
else
// For model to work at all there must be a matching bind matrix,
// so supply an indentity one if it isn't true
// Note: can build an actual bind matrix from joints
const LLMatrix4a& inv_bind = mInvBindMatrix.size() > i ? mInvBindMatrix[i] : LLMatrix4a::identity();
if (i >= mInvBindMatrix.size())
{
LL_WARNS("MESHSKININFO") << "Joint index " << i << " (" << mJointNames[i] << ") exceeds inverse bind matrix size "
<< mInvBindMatrix.size() << LL_ENDL;
}
for (U32 j = 0; j < 4; j++)
{
for (U32 k = 0; k < 4; k++)
{
ret["inverse_bind_matrix"][i][j * 4 + k] = inv_bind.mMatrix[j][k];
}
}
}
for (U32 i = 0; i < 4; i++)
@ -1829,25 +1831,27 @@ LLSD LLMeshSkinInfo::asLLSD(bool include_joints, bool lock_scale_if_joint_positi
}
}
// optional 'joint overrides'
if (include_joints && mAlternateBindMatrix.size() > 0)
{
for (U32 i = 0; i < mJointNames.size(); ++i)
{
if (i < mAlternateBindMatrix.size())
{
for (U32 j = 0; j < 4; j++)
{
for (U32 k = 0; k < 4; k++)
{
ret["alt_inverse_bind_matrix"][i][j*4+k] = mAlternateBindMatrix[i].mMatrix[j][k];
}
}
}
else
// If there is not enough to match mJointNames,
// either supply no alternate matrixes at all or supply
// replacements
const LLMatrix4a& alt_bind = mAlternateBindMatrix.size() > i ? mAlternateBindMatrix[i] : LLMatrix4a::identity();
if (i >= mAlternateBindMatrix.size())
{
LL_WARNS("MESHSKININFO") << "Joint index " << i << " (" << mJointNames[i] << ") exceeds alternate bind matrix size "
<< mAlternateBindMatrix.size() << LL_ENDL;
}
for (U32 j = 0; j < 4; j++)
{
for (U32 k = 0; k < 4; k++)
{
ret["alt_inverse_bind_matrix"][i][j * 4 + k] = alt_bind.mMatrix[j][k];
}
}
}
if (lock_scale_if_joint_position)

View File

@ -360,7 +360,8 @@ void LLSkinningUtil::updateRiggingInfo(const LLMeshSkinInfo* skin, LLVOAvatar *a
{
rig_info_tab[joint_num].setIsRiggedTo(true);
const LLMatrix4a& mat = skin->mBindPoseMatrix[joint_index];
size_t bind_poses_size = skin->mBindPoseMatrix.size();
const LLMatrix4a& mat = bind_poses_size > joint_index ? skin->mBindPoseMatrix[joint_index] : LLMatrix4a::identity();
LLVector4a pos_joint_space;
mat.affineTransform(pos, pos_joint_space);