mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
refactor: remove duplicate weapon key-bone fallback in attachWeapon()
Consolidated identical key-bone lookup logic that appeared at lines 3076 and 3099. Both performed the same search for weapon attachment points (ID 1/2 for right/left hand). Removed duplication while preserving behavior and improving code clarity with better comments.
This commit is contained in:
parent
9578e123cc
commit
bc6cd6e5f2
1 changed files with 13 additions and 24 deletions
|
|
@ -3072,30 +3072,7 @@ bool CharacterRenderer::attachWeapon(uint32_t charInstanceId, uint32_t attachmen
|
|||
}
|
||||
}
|
||||
}
|
||||
// Fallback to key-bone lookup for weapon hand attachment IDs.
|
||||
if (!found && (attachmentId == 1 || attachmentId == 2)) {
|
||||
int32_t targetKeyBone = (attachmentId == 1) ? 26 : 27;
|
||||
for (size_t i = 0; i < charModel.bones.size(); i++) {
|
||||
if (charModel.bones[i].keyBoneId == targetKeyBone) {
|
||||
boneIndex = static_cast<uint16_t>(i);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback for head attachment (ID 11): try common head bone indices
|
||||
// Some models may not have attachment 11 defined, but have bone 0 or 1 as head
|
||||
if (!found && attachmentId == 11 && charModel.bones.size() > 0) {
|
||||
// Try bone 0 first (common for head in many humanoid models)
|
||||
boneIndex = 0;
|
||||
found = true;
|
||||
}
|
||||
|
||||
// Validate bone index (bad attachment tables should not silently bind to origin)
|
||||
if (found && boneIndex >= charModel.bones.size()) {
|
||||
found = false;
|
||||
}
|
||||
// Fallback: key-bone lookup for weapon hand attachment IDs (ID 1 = right hand, ID 2 = left hand)
|
||||
if (!found && (attachmentId == 1 || attachmentId == 2)) {
|
||||
int32_t targetKeyBone = (attachmentId == 1) ? 26 : 27;
|
||||
for (size_t i = 0; i < charModel.bones.size(); i++) {
|
||||
|
|
@ -3108,6 +3085,18 @@ bool CharacterRenderer::attachWeapon(uint32_t charInstanceId, uint32_t attachmen
|
|||
}
|
||||
}
|
||||
|
||||
// Fallback for head attachment (ID 11): use bone 0 if attachment not defined
|
||||
// Some models may not have explicit attachment 11 but use bone 0 as head
|
||||
if (!found && attachmentId == 11 && charModel.bones.size() > 0) {
|
||||
boneIndex = 0;
|
||||
found = true;
|
||||
}
|
||||
|
||||
// Validate bone index (bad attachment tables should not silently bind to origin)
|
||||
if (found && boneIndex >= charModel.bones.size()) {
|
||||
found = false;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
core::Logger::getInstance().warning("attachWeapon: no bone found for attachment ", attachmentId);
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue