/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ // Original file Copyright Crytek GMBH or its affiliates, used under license. #include "CryLegacy_precompiled.h" #include "CharacterBoneAttachmentManager.h" #include "Entity.h" #include void CCharacterBoneAttachmentManager::Update() { for (VectorMap::iterator iter = m_attachments.begin(); iter != m_attachments.end(); ++iter) { iter->first.pChild->InvalidateTM(ENTITY_XFORM_FROM_PARENT); } } void CCharacterBoneAttachmentManager::RegisterAttachment(IEntity* pChild, IEntity* pParent, const uint32 targetCRC) { const ICharacterInstance* pCharacterInstance = pParent->GetCharacter(0); if (pCharacterInstance) { const IDefaultSkeleton& defaultSkeleton = pCharacterInstance->GetIDefaultSkeleton(); const uint32 numJoints = defaultSkeleton.GetJointCount(); for (uint i = 0; i < numJoints; ++i) { const uint32 jointCRC = defaultSkeleton.GetJointCRC32ByID(i); if (jointCRC == targetCRC) { SBinding binding; binding.pChild = pChild; binding.pParent = pParent; SAttachmentData attachment; attachment.m_boneIndex = i; m_attachments[binding] = attachment; break; } } } } void CCharacterBoneAttachmentManager::UnregisterAttachment(const IEntity* pChild, const IEntity* pParent) { SBinding binding; binding.pChild = const_cast(pChild); binding.pParent = const_cast(pParent); m_attachments.erase(binding); } Matrix34 CCharacterBoneAttachmentManager::GetNodeWorldTM(const IEntity* pChild, const IEntity* pParent) const { SBinding binding; binding.pChild = const_cast(pChild); binding.pParent = const_cast(pParent); VectorMap::const_iterator findIter = m_attachments.find(binding); if (findIter != m_attachments.end()) { const SAttachmentData data = findIter->second; const ICharacterInstance* pCharacterInstance = binding.pParent->GetCharacter(0); if (pCharacterInstance) { const ISkeletonPose* pSkeletonPose = pCharacterInstance->GetISkeletonPose(); const QuatT jointTransform = pSkeletonPose->GetAbsJointByID(data.m_boneIndex); return pParent->GetWorldTM() * Matrix34(jointTransform); } } return pParent->GetWorldTM(); } bool CCharacterBoneAttachmentManager::IsAttachmentValid(const IEntity* pChild, const IEntity* pParent) const { SBinding binding; binding.pChild = const_cast(pChild); binding.pParent = const_cast(pParent); VectorMap::const_iterator findIter = m_attachments.find(binding); return findIter != m_attachments.end(); }