feat(model): add CM2Model::GetAttachmentWorldTransform

This commit is contained in:
fallenoak 2025-10-12 12:02:18 -05:00
parent 9e4cdf4204
commit f276902621
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 41 additions and 0 deletions

View File

@ -731,6 +731,46 @@ LABEL_36:
} }
} }
C44Matrix CM2Model::GetAttachmentWorldTransform(uint32_t id) {
if (!this->m_loaded) {
this->WaitForLoad("GetAttachmentWorldTransform");
}
auto& attachmentIndicesById = this->m_shared->m_data->attachmentIndicesById;
auto& attachments = this->m_shared->m_data->attachments;
// Look up attachment index
uint16_t attachIndex = 0xFFFF;
if (id < attachmentIndicesById.count) {
attachIndex = attachmentIndicesById[id];
}
// Look up bone index
uint16_t boneIndex = 0xFFFF;
if (attachIndex < this->m_shared->m_data->attachments.count) {
boneIndex = attachments[attachIndex].boneIndex;
}
// Animate
this->Animate();
// Calculate attachment world transform
C44Matrix transform;
if (attachIndex == 0xFFFF) {
transform = this->m_boneMatrices[0];
} else {
transform = this->m_boneMatrices[boneIndex];
transform.Translate(attachments[attachIndex].position);
}
return transform * this->m_scene->m_viewInv;
}
CAaBox& CM2Model::GetBoundingBox(CAaBox& bounds) { CAaBox& CM2Model::GetBoundingBox(CAaBox& bounds) {
// TODO // TODO
// WaitForLoad // WaitForLoad

View File

@ -147,6 +147,7 @@ class CM2Model {
void DetachFromParent(); void DetachFromParent();
void DetachFromScene(); void DetachFromScene();
void FindKey(M2ModelBoneSeq* sequence, const M2TrackBase& track, uint32_t& currentKey, uint32_t& nextKey, float& ratio); void FindKey(M2ModelBoneSeq* sequence, const M2TrackBase& track, uint32_t& currentKey, uint32_t& nextKey, float& ratio);
C44Matrix GetAttachmentWorldTransform(uint32_t id);
CAaBox& GetBoundingBox(CAaBox& bounds); CAaBox& GetBoundingBox(CAaBox& bounds);
HCAMERA GetCameraByIndex(uint32_t index); HCAMERA GetCameraByIndex(uint32_t index);
C3Vector GetPosition(); C3Vector GetPosition();