diff --git a/Engine/Core/inc/Core/GUI/ComponentDrawer.h b/Engine/Core/inc/Core/GUI/ComponentDrawer.h index 390721c77..76b1500df 100644 --- a/Engine/Core/inc/Core/GUI/ComponentDrawer.h +++ b/Engine/Core/inc/Core/GUI/ComponentDrawer.h @@ -13,6 +13,7 @@ namespace SR_SCRIPTING_NS { namespace SR_ANIMATIONS_NS { class Animator; + class BoneComponent; class Skeleton; } @@ -62,6 +63,7 @@ namespace SR_CORE_NS::GUI::ComponentDrawer { void DrawComponent(SR_PTYPES_NS::Rigidbody3D*& pComponent, EditorGUI* context, int32_t index); void DrawComponent(SR_ANIMATIONS_NS::Animator*& pComponent, EditorGUI* context, int32_t index); void DrawComponent(SR_ANIMATIONS_NS::Skeleton*& pComponent, EditorGUI* context, int32_t index); + void DrawComponent(SR_ANIMATIONS_NS::BoneComponent*& pComponent, EditorGUI* context, int32_t index) { } void DrawComponent(SR_UTILS_NS::LookAtComponent*& pComponent, EditorGUI* context, int32_t index); void DrawComponent(SR_PTYPES_NS::Rigidbody*& pComponent, EditorGUI* context, int32_t index); diff --git a/Engine/Core/libs/Graphics/Graphics.cxx b/Engine/Core/libs/Graphics/Graphics.cxx index fd4083ac2..0633fdd02 100644 --- a/Engine/Core/libs/Graphics/Graphics.cxx +++ b/Engine/Core/libs/Graphics/Graphics.cxx @@ -13,6 +13,7 @@ #include "../Graphics/src/Graphics/Animations/AnimationStateTransition.cpp" #include "../Graphics/src/Graphics/Animations/AnimationStateMachine.cpp" #include "../Graphics/src/Graphics/Animations/AnimationState.cpp" +#include "../Graphics/src/Graphics/Animations/BoneComponent.cpp" #include "../Graphics/src/Graphics/Pipeline/Vulkan/VulkanImGUI.cpp" #include "../Graphics/src/Graphics/Pipeline/Vulkan/VulkanMemory.cpp" diff --git a/Engine/Core/libs/Graphics/inc/Graphics/Animations/AnimationChannel.h b/Engine/Core/libs/Graphics/inc/Graphics/Animations/AnimationChannel.h index 8912dbb8c..34fa7c686 100644 --- a/Engine/Core/libs/Graphics/inc/Graphics/Animations/AnimationChannel.h +++ b/Engine/Core/libs/Graphics/inc/Graphics/Animations/AnimationChannel.h @@ -16,12 +16,12 @@ namespace SR_ANIMATIONS_NS { class AnimationPose; class AnimationChannel final : public SR_UTILS_NS::NonCopyable { - using Keys = std::vector>; + using Keys = std::vector>; public: ~AnimationChannel() override; public: - static void Load(aiNodeAnim* pChannel, double_t ticksPerSecond, std::vector& channels); + static void Load(aiNodeAnim* pChannel, float_t ticksPerSecond, std::vector& channels); SR_NODISCARD AnimationChannel* Copy() const noexcept { auto&& pChannel = new AnimationChannel(); @@ -36,7 +36,7 @@ namespace SR_ANIMATIONS_NS { } void SetName(const std::string_view& name); - void AddKey(double_t timePoint, AnimationKey* pKey); + void AddKey(float_t timePoint, AnimationKey* pKey); uint32_t UpdateChannel(uint32_t keyIndex, float_t time, diff --git a/Engine/Core/libs/Graphics/inc/Graphics/Animations/AnimationKey.h b/Engine/Core/libs/Graphics/inc/Graphics/Animations/AnimationKey.h index b413fccbe..580fe87d5 100644 --- a/Engine/Core/libs/Graphics/inc/Graphics/Animations/AnimationKey.h +++ b/Engine/Core/libs/Graphics/inc/Graphics/Animations/AnimationKey.h @@ -15,23 +15,33 @@ namespace SR_UTILS_NS { namespace SR_ANIMATIONS_NS { class AnimationChannel; + class TranslationKey; + class RotationKey; + class ScalingKey; + /// Задача ключа обеспечить необходимый переход из предыдущего ключа в этот в зависимости от интервала времени. /// Интервал времени задается от 0.f до 1.f в зависимости от положения перехода в момент времени. /// Переход должен работать и в обратную сторону (от 1.f до 0.f) class AnimationKey : public SR_UTILS_NS::NonCopyable { public: - explicit AnimationKey(AnimationChannel* pChannel) - : m_channel(pChannel) - { } + explicit AnimationKey(AnimationChannel* pChannel); public: - virtual void Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) = 0; - virtual void Set(float_t weight, AnimationData* pData) = 0; + virtual void SR_FASTCALL Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) noexcept = 0; + virtual void SR_FASTCALL Set(float_t weight, AnimationData* pData) noexcept = 0; virtual AnimationKey* Copy(AnimationChannel* pChannel) const noexcept = 0; + SR_NODISCARD SR_FORCE_INLINE TranslationKey* SR_FASTCALL GetTranslation() const noexcept { return m_translation; } + SR_NODISCARD SR_FORCE_INLINE RotationKey* SR_FASTCALL GetRotation() const noexcept { return m_rotation; } + SR_NODISCARD SR_FORCE_INLINE ScalingKey* SR_FASTCALL GetScaling() const noexcept { return m_scaling; } + protected: AnimationChannel* m_channel = nullptr; + TranslationKey* m_translation = nullptr; + RotationKey* m_rotation = nullptr; + ScalingKey* m_scaling = nullptr; + }; /// ---------------------------------------------------------------------------------------------------------------- @@ -46,8 +56,8 @@ namespace SR_ANIMATIONS_NS { { } public: - void Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) override; - void Set(float_t weight, AnimationData* pData) override; + void SR_FASTCALL Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) noexcept override; + void SR_FASTCALL Set(float_t weight, AnimationData* pData) noexcept override; SR_NODISCARD AnimationKey* Copy(AnimationChannel* pChannel) const noexcept override { return new TranslationKey(pChannel, m_translation, m_delta); @@ -71,8 +81,8 @@ namespace SR_ANIMATIONS_NS { { } public: - void Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) override; - void Set(float_t weight, AnimationData* pData) override; + void SR_FASTCALL Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) noexcept override; + void SR_FASTCALL Set(float_t weight, AnimationData* pData) noexcept override; SR_NODISCARD AnimationKey* Copy(AnimationChannel* pChannel) const noexcept override { return new RotationKey(pChannel, m_rotation, m_delta); @@ -96,8 +106,8 @@ namespace SR_ANIMATIONS_NS { { } public: - void Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) override; - void Set(float_t weight, AnimationData* pData) override; + void SR_FASTCALL Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) noexcept override; + void SR_FASTCALL Set(float_t weight, AnimationData* pData) noexcept override; SR_NODISCARD AnimationKey* Copy(AnimationChannel* pChannel) const noexcept override { return new ScalingKey(pChannel, m_scaling, m_delta); diff --git a/Engine/Core/libs/Graphics/inc/Graphics/Animations/Bone.h b/Engine/Core/libs/Graphics/inc/Graphics/Animations/Bone.h index 18174f91d..0e62751c3 100644 --- a/Engine/Core/libs/Graphics/inc/Graphics/Animations/Bone.h +++ b/Engine/Core/libs/Graphics/inc/Graphics/Animations/Bone.h @@ -11,6 +11,8 @@ #include namespace SR_ANIMATIONS_NS { + class BoneComponent; + struct Bone : public SR_UTILS_NS::NonCopyable { public: ~Bone() override { @@ -38,43 +40,7 @@ namespace SR_ANIMATIONS_NS { return pRootBone; } - bool Initialize() { - if (!pRoot->gameObject && !pRoot->pScene) { - SRHalt0(); - hasError = true; - return false; - } - - std::vector names = { hashName }; - - Bone* pParentBone = pParent; - /// рутовую ноду в расчет не берем - while (pParentBone && pParentBone->pParent) { - names.emplace_back(pParentBone->hashName); - pParentBone = pParentBone->pParent; - } - - if (pRoot->gameObject) { - gameObject = pRoot->gameObject; - } - - for (int32_t i = names.size() - 1; i >= 0; i--) { - if (gameObject) { - if (!(gameObject = gameObject->Find(names[i]))) { - break; - } - } - else { - if (!(gameObject = pRoot->pScene->Find(names[i]))) { - break; - } - } - } - - hasError = !gameObject.Valid(); - - return !hasError; - } + bool Initialize(); private: SR_NODISCARD Bone* Clone(Bone* pParentBone) const noexcept { diff --git a/Engine/Core/libs/Graphics/inc/Graphics/Animations/BoneComponent.h b/Engine/Core/libs/Graphics/inc/Graphics/Animations/BoneComponent.h new file mode 100644 index 000000000..471f11b49 --- /dev/null +++ b/Engine/Core/libs/Graphics/inc/Graphics/Animations/BoneComponent.h @@ -0,0 +1,42 @@ +// +// Created by Monika on 28.07.2023. +// + +#ifndef SRENGINE_BONECOMPONENT_H +#define SRENGINE_BONECOMPONENT_H + +#include +#include + +namespace SR_ANIMATIONS_NS { + class Skeleton; + + class BoneComponent : public SR_UTILS_NS::Component { + SR_ENTITY_SET_VERSION(1000); + SR_INITIALIZE_COMPONENT(BoneComponent); + using Super = SR_UTILS_NS::Component; + public: + using RenderScenePtr = SR_HTYPES_NS::SafePtr; + public: + BoneComponent(); + + static Component* LoadComponent(SR_HTYPES_NS::Marshal& marshal, const SR_HTYPES_NS::DataStorage* pDataStorage); + + public: + SR_NODISCARD Component* CopyComponent() const override; + SR_NODISCARD SR_HTYPES_NS::Marshal::Ptr Save(SR_HTYPES_NS::Marshal::Ptr pMarshal, SR_UTILS_NS::SavableFlags flags) const override; + + void OnMatrixDirty() override; + + void Initialize(Skeleton* pSkeleton, uint16_t boneIndex); + + SR_NODISCARD bool ExecuteInEditMode() const override { return true; } + + private: + uint16_t m_boneIndex = 0; + SR_UTILS_NS::EntityRef m_skeleton; + + }; +} + +#endif //SRENGINE_BONECOMPONENT_H diff --git a/Engine/Core/libs/Graphics/inc/Graphics/Animations/Skeleton.h b/Engine/Core/libs/Graphics/inc/Graphics/Animations/Skeleton.h index 9065aa5d4..6c164c18c 100644 --- a/Engine/Core/libs/Graphics/inc/Graphics/Animations/Skeleton.h +++ b/Engine/Core/libs/Graphics/inc/Graphics/Animations/Skeleton.h @@ -30,14 +30,16 @@ namespace SR_ANIMATIONS_NS { void OnDestroy() override; bool ReCalculateSkeleton(); + void CalculateMatrices(); Bone* AddBone(Bone* pParent, const std::string& name, bool recalculate); SR_NODISCARD Bone* GetRootBone() const noexcept { return m_rootBone; } + const SR_MATH_NS::Matrix4x4& GetMatrixByIndex(uint16_t index) noexcept; + SR_UTILS_NS::Transform* GetTransformByIndex(uint16_t index) noexcept; SR_NODISCARD const std::vector& GetBones() const noexcept { return m_bonesByIndex; }; SR_NODISCARD Bone* TryGetBone(uint64_t hashName); SR_NODISCARD Bone* GetBone(uint64_t hashName); - SR_NODISCARD Bone* GetBoneByIndex(uint64_t index); SR_NODISCARD uint64_t GetBoneIndex(uint64_t hashName); SR_NODISCARD bool IsDebugEnabled() const noexcept { return m_debugEnabled; } void SetDebugEnabled(bool enabled) { m_debugEnabled = enabled; } @@ -53,11 +55,15 @@ namespace SR_ANIMATIONS_NS { ska::flat_hash_map m_debugLines; ska::flat_hash_map m_bonesByName; + std::vector m_bonesByIndex; + std::vector m_matrices; + bool m_dirtyMatrices = false; + Bone* m_rootBone = nullptr; - }; + }; } #endif //SRENGINE_SKELETON_H diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationChannel.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationChannel.cpp index 7b00e201a..fb00540c1 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationChannel.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationChannel.cpp @@ -12,11 +12,13 @@ namespace SR_ANIMATIONS_NS { } uint32_t AnimationChannel::UpdateChannel(uint32_t keyIndex, - float_t time, - float_t weight, - const AnimationPose* pStaticPose, - AnimationPose* pWorkingPose + float_t time, + float_t weight, + const AnimationPose* pStaticPose, + AnimationPose* pWorkingPose ) const { + SR_TRACY_ZONE; + auto&& pWorkingData = pWorkingPose->GetData(GetGameObjectHashName()); auto&& pStaticData = pStaticPose->GetData(GetGameObjectHashName()); @@ -50,9 +52,9 @@ namespace SR_ANIMATIONS_NS { else { auto&& [prevTime, prevKey] = m_keys.at(keyIndex - 1); - const double_t currentTime = time - prevTime; - const double_t keyCurrTime = keyTime - prevTime; - const double_t progress = currentTime / keyCurrTime; + const float_t currentTime = time - prevTime; + const float_t keyCurrTime = keyTime - prevTime; + const float_t progress = currentTime / keyCurrTime; pKey->Update(progress, weight, prevKey, pWorkingData, pStaticData); } @@ -60,7 +62,9 @@ namespace SR_ANIMATIONS_NS { return keyIndex; } - void AnimationChannel::Load(aiNodeAnim *pChannel, double_t ticksPerSecond, std::vector& channels) { + void AnimationChannel::Load(aiNodeAnim* pChannel, float_t ticksPerSecond, std::vector& channels) { + SR_TRACY_ZONE; + if (pChannel->mNumPositionKeys > 0) { static constexpr float_t mul = 0.01; @@ -122,7 +126,7 @@ namespace SR_ANIMATIONS_NS { auto&& scale = AiV3ToFV3(pScalingKey.mValue, 1.f); - pScalingChannel->AddKey(pScalingKey.mTime /ticksPerSecond, + pScalingChannel->AddKey(pScalingKey.mTime / ticksPerSecond, new ScalingKey( pScalingChannel, scale, @@ -142,7 +146,7 @@ namespace SR_ANIMATIONS_NS { } } - void AnimationChannel::AddKey(double_t timePoint, AnimationKey* pKey) { + void AnimationChannel::AddKey(float_t timePoint, AnimationKey* pKey) { m_keys.emplace_back(std::make_pair(timePoint, pKey)); } } \ No newline at end of file diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationGraph.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationGraph.cpp index 946e7ce55..1d1656ac6 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationGraph.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationGraph.cpp @@ -32,6 +32,7 @@ namespace SR_ANIMATIONS_NS { } void AnimationGraph::Update(const UpdateContext& context) { + SR_TRACY_ZONE; GetFinal()->Update(context, AnimationLink(SR_ID_INVALID, SR_ID_INVALID)); } diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationGraphNode.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationGraphNode.cpp index 62149df17..8a22e71b1 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationGraphNode.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationGraphNode.cpp @@ -37,6 +37,8 @@ namespace SR_ANIMATIONS_NS { } void AnimationGraphNodeFinal::Update(const UpdateContext& context, const AnimationLink& from) { + SR_TRACY_ZONE; + if (m_inputPins.front().has_value()) { auto&& pNode = m_graph->GetNode(m_inputPins.front().value().m_targetNodeIndex); if (pNode) { @@ -46,6 +48,8 @@ namespace SR_ANIMATIONS_NS { } void AnimationGraphNodeStateMachine::Update(const UpdateContext& context, const AnimationLink& from) { + SR_TRACY_ZONE; + if (m_stateMachine) { m_stateMachine->Update(context); } diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationKey.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationKey.cpp index 97b20f74b..aee38ffa9 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationKey.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationKey.cpp @@ -9,7 +9,16 @@ #include namespace SR_ANIMATIONS_NS { - void TranslationKey::Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) { + AnimationKey::AnimationKey(AnimationChannel* pChannel) + : m_channel(pChannel) + , m_translation(dynamic_cast(this)) + , m_rotation(dynamic_cast(this)) + , m_scaling(dynamic_cast(this)) + { } + + /// ---------------------------------------------------------------------------------------------------------------- + + void TranslationKey::Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) noexcept { if (!pStaticData->translation.has_value()) { return; } @@ -18,7 +27,7 @@ namespace SR_ANIMATIONS_NS { pData->translation = SR_MATH_NS::FVector3::Zero(); } - if (auto&& pKey = dynamic_cast(pPreviousKey)) { + if (auto&& pKey = pPreviousKey ? pPreviousKey->GetTranslation() : nullptr) { auto&& newValue = (pKey->m_delta + pStaticData->translation.value()).Lerp(pStaticData->translation.value() + m_delta, progress); pData->translation = pData->translation->Lerp(newValue, weight); } @@ -27,7 +36,7 @@ namespace SR_ANIMATIONS_NS { } } - void TranslationKey::Set(float_t weight, AnimationData *pData) { + void TranslationKey::Set(float_t weight, AnimationData *pData) noexcept { if (!pData->translation.has_value()) { pData->translation = SR_MATH_NS::FVector3::Zero(); } @@ -37,7 +46,7 @@ namespace SR_ANIMATIONS_NS { /// ---------------------------------------------------------------------------------------------------------------- - void RotationKey::Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) { + void RotationKey::Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) noexcept { if (!pStaticData->rotation.has_value()) { return; } @@ -46,7 +55,7 @@ namespace SR_ANIMATIONS_NS { pData->rotation = SR_MATH_NS::Quaternion::Identity(); } - if (auto&& pKey = dynamic_cast(pPreviousKey)) { + if (auto&& pKey = pPreviousKey ? pPreviousKey->GetRotation() : nullptr) { auto&& newValue = (pKey->m_delta * pStaticData->rotation.value()).Slerp(m_delta * pStaticData->rotation.value(), progress); pData->rotation = pData->rotation->Slerp(newValue, weight); } @@ -55,7 +64,7 @@ namespace SR_ANIMATIONS_NS { } } - void RotationKey::Set(float_t weight, AnimationData *pData) { + void RotationKey::Set(float_t weight, AnimationData *pData) noexcept { if (!pData->rotation.has_value()) { pData->rotation = SR_MATH_NS::Quaternion::Identity(); } @@ -65,7 +74,7 @@ namespace SR_ANIMATIONS_NS { /// ---------------------------------------------------------------------------------------------------------------- - void ScalingKey::Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) { + void ScalingKey::Update(double_t progress, float_t weight, AnimationKey* pPreviousKey, AnimationData* pData, AnimationData* pStaticData) noexcept { if (!pStaticData->scale.has_value()) { return; } @@ -74,7 +83,7 @@ namespace SR_ANIMATIONS_NS { pData->scale = SR_MATH_NS::FVector3::One(); } - if (auto&& pKey = dynamic_cast(pPreviousKey)) { + if (auto&& pKey = pPreviousKey ? pPreviousKey->GetScaling() : nullptr) { auto&& newValue = (pKey->m_delta * pStaticData->scale.value()).Lerp(pStaticData->scale.value() * m_delta, progress); pData->scale = pData->scale->Lerp(newValue, weight); } @@ -83,7 +92,7 @@ namespace SR_ANIMATIONS_NS { } } - void ScalingKey::Set(float_t weight, AnimationData* pData) { + void ScalingKey::Set(float_t weight, AnimationData* pData) noexcept { if (!pData->scale.has_value()) { pData->scale = SR_MATH_NS::FVector3::One(); } diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationPose.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationPose.cpp index 7ad27737f..558029ea0 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationPose.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationPose.cpp @@ -22,6 +22,8 @@ namespace SR_ANIMATIONS_NS { } AnimationData* AnimationPose::GetData(AnimationPose::BoneHashName boneHashName) const noexcept { + SR_TRACY_ZONE; + if (auto&& pIt = m_indices.find(boneHashName); pIt != m_indices.end()) { return pIt->second; } diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationState.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationState.cpp index 613a4e7b9..eda467e07 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationState.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationState.cpp @@ -12,6 +12,8 @@ namespace SR_ANIMATIONS_NS { } void AnimationClipState::Update(const UpdateContext& context) { + SR_TRACY_ZONE; + if (!m_clip) { Super::Update(context); return; @@ -51,6 +53,8 @@ namespace SR_ANIMATIONS_NS { } void IAnimationClipState::SetClip(AnimationClip* pClip) { + SR_TRACY_ZONE; + if (m_clip == pClip) { return; } diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationStateMachine.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationStateMachine.cpp index fb779922c..a7a05119a 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationStateMachine.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/AnimationStateMachine.cpp @@ -19,6 +19,8 @@ namespace SR_ANIMATIONS_NS { } void AnimationStateMachine::Update(const UpdateContext& context) { + SR_TRACY_ZONE; + for (auto pIt = m_activeStates.begin(); pIt != m_activeStates.end(); ) { AnimationState* pState = *pIt; diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/Animator.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/Animator.cpp index 2608f8ce8..1e352ddaf 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Animations/Animator.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/Animator.cpp @@ -45,16 +45,20 @@ namespace SR_ANIMATIONS_NS { } void Animator::Update(float_t dt) { + SR_TRACY_ZONE; + m_skeleton = GetParent()->GetComponent(); if (!m_sync) { - UpdateInternal(dt / 1000.f); + UpdateInternal(dt); } Super::Update(dt); } void Animator::UpdateInternal(float_t dt) { + SR_TRACY_ZONE; + if (!GetGameObject() || !m_skeleton) { return; } @@ -96,15 +100,15 @@ namespace SR_ANIMATIONS_NS { auto&& pStateMachine = pStateMachineNode->GetMachine(); auto&& pSetPoseState = pStateMachine->AddState(pAnimationClip); - pSetPoseState->SetClip(pAnimationClip); + //pSetPoseState->SetClip(pAnimationClip); auto&& pClipState = pStateMachine->AddState(pAnimationClip); - pClipState->SetClip(pAnimationClip); + //pClipState->SetClip(pAnimationClip); pStateMachine->GetEntryPoint()->AddTransition(pSetPoseState); pSetPoseState->AddTransition(pClipState); - //pStateMachine->GetEntryPoint()->AddTransition(pClipState); + pStateMachine->GetEntryPoint()->AddTransition(pClipState); m_graph->GetFinal()->AddInput(pStateMachineNode, 0, 0); diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/Bone.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/Bone.cpp index afe52ad98..88a1a0c77 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Animations/Bone.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/Bone.cpp @@ -3,4 +3,50 @@ // #include +#include +namespace SR_ANIMATIONS_NS { + bool Bone::Initialize() { + SR_TRACY_ZONE; + + if (!pRoot->gameObject && !pRoot->pScene) { + SRHalt0(); + hasError = true; + return false; + } + + std::vector names = { hashName }; + + Bone* pParentBone = pParent; + /// рутовую ноду в расчет не берем + while (pParentBone && pParentBone->pParent) { + names.emplace_back(pParentBone->hashName); + pParentBone = pParentBone->pParent; + } + + if (pRoot->gameObject) { + gameObject = pRoot->gameObject; + } + + for (int32_t i = names.size() - 1; i >= 0; i--) { + if (gameObject) { + if (!(gameObject = gameObject->Find(names[i]))) { + break; + } + } + else { + if (!(gameObject = pRoot->pScene->Find(names[i]))) { + break; + } + } + } + + if ((hasError = !gameObject.Valid())) { + return false; + } + + SR_NOOP; + + return true; + } +} diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/BoneComponent.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/BoneComponent.cpp new file mode 100644 index 000000000..0cfabf10f --- /dev/null +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/BoneComponent.cpp @@ -0,0 +1,38 @@ +// +// Created by Monika on 28.07.2023. +// + +#include +#include +#include + +namespace SR_ANIMATIONS_NS { + SR_REGISTER_COMPONENT(BoneComponent); + + BoneComponent::BoneComponent() + : Super() + , m_skeleton(GetThis()) + { } + + SR_UTILS_NS::Component* BoneComponent::LoadComponent(SR_HTYPES_NS::Marshal& marshal, const SR_HTYPES_NS::DataStorage* pDataStorage) { + return new BoneComponent(); + } + + SR_UTILS_NS::Component* BoneComponent::CopyComponent() const { + return new BoneComponent(); + } + + SR_HTYPES_NS::Marshal::Ptr BoneComponent::Save(SR_HTYPES_NS::Marshal::Ptr pMarshal, SR_UTILS_NS::SavableFlags flags) const { + return Super::Save(pMarshal, flags); + } + + void BoneComponent::OnMatrixDirty() { + Super::OnMatrixDirty(); + } + + void BoneComponent::Initialize(Skeleton* pSkeleton, uint16_t boneIndex) { + m_skeleton.SetPathTo(pSkeleton->GetEntity()); + SRAssert(m_skeleton.GetComponent()); + m_boneIndex = boneIndex; + } +} diff --git a/Engine/Core/libs/Graphics/src/Graphics/Animations/Skeleton.cpp b/Engine/Core/libs/Graphics/src/Graphics/Animations/Skeleton.cpp index 80a93ea30..0e10ebc2c 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Animations/Skeleton.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Animations/Skeleton.cpp @@ -127,13 +127,13 @@ namespace SR_ANIMATIONS_NS { bool hasErrors = false; const SR_HTYPES_NS::Function processBone = [&](SR_ANIMATIONS_NS::Bone* pBone) { -#ifdef SR_DEBUG + #ifdef SR_DEBUG if (m_bonesByName.count(pBone->hashName) == 1) { SR_ERROR("Skeleton::ReCalculateSkeleton() : bone with name \"" + pBone->name + "\" already exists in hash table!"); hasErrors = true; return; } -#endif + #endif m_bonesByIndex.emplace_back(pBone); m_bonesByName.insert(std::make_pair(pBone->hashName, pBone)); @@ -159,10 +159,6 @@ namespace SR_ANIMATIONS_NS { return nullptr; } - //if (pBoneIt->second->name != "Armature") { - // return nullptr; - //} - if (!pBoneIt->second->gameObject && !pBoneIt->second->hasError && !pBoneIt->second->Initialize()) { SR_WARN("Skeleton::GetBone() : failed to find bone game object!\n\tName: " + pBoneIt->second->name); } @@ -176,10 +172,6 @@ namespace SR_ANIMATIONS_NS { return nullptr; } - //if (pBoneIt->second->name != "Armature") { - // return nullptr; - //} - if (!pBoneIt->second->gameObject && !pBoneIt->second->hasError) { pBoneIt->second->Initialize(); } @@ -207,6 +199,8 @@ namespace SR_ANIMATIONS_NS { return; } + m_dirtyMatrices = true; + if (m_debugEnabled) { UpdateDebug(); } @@ -265,16 +259,24 @@ namespace SR_ANIMATIONS_NS { } } - Bone *Skeleton::GetBoneByIndex(uint64_t index) { + SR_UTILS_NS::Transform* Skeleton::GetTransformByIndex(uint16_t index) noexcept { if (index >= m_bonesByIndex.size()) { return nullptr; } - if (!m_bonesByIndex[index]->gameObject && !m_bonesByIndex[index]->hasError && !m_bonesByIndex[index]->Initialize()) { - SR_WARN("Skeleton::GetBoneByIndex() : failed to find bone game object!\n\tName: " + m_bonesByIndex[index]->name); + auto&& pBone = m_bonesByIndex[index]; + auto&& pGameObject = pBone->gameObject; + + if (!pGameObject && !pBone->hasError && !pBone->Initialize()) { + return nullptr; } - return m_bonesByIndex.at(index); + if (pGameObject) { + return pGameObject->GetTransform(); + } + else { + return nullptr; + } } uint64_t Skeleton::GetBoneIndex(uint64_t hashName) { @@ -286,4 +288,39 @@ namespace SR_ANIMATIONS_NS { return SR_ID_INVALID; } + + void Skeleton::CalculateMatrices() { + if (!m_dirtyMatrices) { + return; + } + + SR_TRACY_ZONE; + + m_matrices.resize(m_bonesByIndex.size()); + + for (uint16_t i = 0; i < m_bonesByIndex.size(); ++i) { + auto&& pBone = m_bonesByIndex[i]; + auto&& pGameObject = pBone->gameObject; + + if (!pGameObject && !pBone->hasError && !pBone->Initialize()) { + continue; + } + + if (pGameObject) { + m_matrices[i] = pGameObject->GetTransform()->GetMatrix(); + } + } + + m_dirtyMatrices = false; + } + + const SR_MATH_NS::Matrix4x4& Skeleton::GetMatrixByIndex(uint16_t index) noexcept { + static SR_MATH_NS::Matrix4x4 identityMatrix = SR_MATH_NS::Matrix4x4().Identity(); + + if (index >= m_bonesByIndex.size()) { + return identityMatrix; + } + + return m_matrices[index]; + } } diff --git a/Engine/Core/libs/Graphics/src/Graphics/Types/Geometry/SkinnedMesh.cpp b/Engine/Core/libs/Graphics/src/Graphics/Types/Geometry/SkinnedMesh.cpp index 8b3f72482..b5d487bd4 100644 --- a/Engine/Core/libs/Graphics/src/Graphics/Types/Geometry/SkinnedMesh.cpp +++ b/Engine/Core/libs/Graphics/src/Graphics/Types/Geometry/SkinnedMesh.cpp @@ -220,8 +220,6 @@ namespace SR_GTYPES_NS { bool SkinnedMesh::PopulateSkeletonMatrices() { SR_TRACY_ZONE; - static SR_MATH_NS::Matrix4x4 identityMatrix = SR_MATH_NS::Matrix4x4().Identity(); - auto&& bones = GetRawMesh()->GetBones(GetMeshId()); if (bones.empty()) { @@ -234,11 +232,6 @@ namespace SR_GTYPES_NS { m_bonesIds.resize(bonesCount); m_skeletonOffsets.resize(bonesCount); m_skeletonMatrices.resize(bonesCount); - - /// for (uint64_t i = 0; i < bonesCount; ++i) { - /// m_skeletonMatrices[i] = identityMatrix; - /// m_skeletonOffsets[i] = identityMatrix; - /// } } auto&& pSkeleton = m_skeletonRef.GetComponent(); @@ -255,13 +248,12 @@ namespace SR_GTYPES_NS { m_isOffsetsInitialized = true; } + auto&& pSkeletonRaw = pSkeleton.Get(); + + pSkeletonRaw->CalculateMatrices(); + for (uint64_t boneId = 0; boneId < m_bonesIds.size(); ++boneId) { - if (auto&& bone = pSkeleton->GetBoneByIndex(m_bonesIds[boneId]); bone && bone->gameObject) { - m_skeletonMatrices[boneId] = bone->gameObject->GetTransform()->GetMatrix(); - } - else { - m_skeletonMatrices[boneId] = identityMatrix; - } + memcpy(&m_skeletonMatrices[boneId], &pSkeletonRaw->GetMatrixByIndex(m_bonesIds[boneId]), sizeof(SR_MATH_NS::Matrix4x4)); } return true; diff --git a/Engine/Core/libs/Utils/inc/Utils/ECS/ComponentManager.h b/Engine/Core/libs/Utils/inc/Utils/ECS/ComponentManager.h index e52a38879..507c97449 100644 --- a/Engine/Core/libs/Utils/inc/Utils/ECS/ComponentManager.h +++ b/Engine/Core/libs/Utils/inc/Utils/ECS/ComponentManager.h @@ -32,6 +32,7 @@ namespace SR_UTILS_NS { typedef SR_HTYPES_NS::Function Construction; typedef SR_HTYPES_NS::Function Loader; using ContextInitializerFn = SR_HTYPES_NS::Function; + using Hash = uint64_t; struct MetaComponent { Construction constructor; @@ -41,6 +42,7 @@ namespace SR_UTILS_NS { }; public: Component* CreateComponentOfName(const std::string& name); + Component* CreateComponentOfName(Hash hashName); template T* CreateComponent() { SR_SCOPED_LOCK @@ -106,7 +108,7 @@ namespace SR_UTILS_NS { ContextInitializerFn m_contextInitializer; std::unordered_map m_meta; - std::unordered_map m_ids; + std::unordered_map m_ids; SR_HTYPES_NS::DataStorage m_context; uint64_t m_lastComponent = 0; diff --git a/Engine/Core/libs/Utils/inc/Utils/ECS/Entity.h b/Engine/Core/libs/Utils/inc/Utils/ECS/Entity.h index 2687cbb03..f4332c374 100644 --- a/Engine/Core/libs/Utils/inc/Utils/ECS/Entity.h +++ b/Engine/Core/libs/Utils/inc/Utils/ECS/Entity.h @@ -6,6 +6,7 @@ #define SRENGINE_ENTITY_H #include +#include #include #include @@ -96,6 +97,8 @@ namespace SR_UTILS_NS { SR_NODISCARD EntityPath GetEntityPath() const { return m_entityPath; } SR_NODISCARD EntityBranch GetEntityTree() const { return EntityBranch(m_entityId, GetEntityBranches()); } + SR_NODISCARD EntityRef GetRef() const noexcept { return EntityRef(GetThis()); } + SR_NODISCARD Ptr GetEntity() const noexcept { return GetThis(); } SR_NODISCARD virtual std::string GetEntityInfo() const { return "None"; } SR_NODISCARD virtual uint16_t GetEntityVersion() const noexcept = 0; diff --git a/Engine/Core/libs/Utils/inc/Utils/ECS/EntityRef.h b/Engine/Core/libs/Utils/inc/Utils/ECS/EntityRef.h index e67055c10..588fe8beb 100644 --- a/Engine/Core/libs/Utils/inc/Utils/ECS/EntityRef.h +++ b/Engine/Core/libs/Utils/inc/Utils/ECS/EntityRef.h @@ -25,6 +25,7 @@ namespace SR_UTILS_NS { public: SR_NODISCARD SR_HTYPES_NS::Marshal::Ptr Save(SR_HTYPES_NS::Marshal::Ptr pMarshal) const; SR_NODISCARD EntityRef Copy(const EntityRefUtils::OwnerRef& owner) const; + SR_NODISCARD const SR_HTYPES_NS::SharedPtr& GetTarget() const { return m_target; } void Save(SR_HTYPES_NS::Marshal& marshal) const; void Load(SR_HTYPES_NS::Marshal& marshal); @@ -36,13 +37,13 @@ namespace SR_UTILS_NS { return nullptr; } - SR_NODISCARD GameObject::Ptr GetGameObject() const; - SR_NODISCARD Component::Ptr GetComponent() const; + SR_NODISCARD SR_HTYPES_NS::SharedPtr GetGameObject() const; + SR_NODISCARD SR_HTYPES_NS::SharedPtr GetComponent() const; SR_NODISCARD bool IsValid() const; SR_NODISCARD bool IsRelative() const { return m_relative; } void SetRelative(bool relative); - void SetPathTo(Entity::Ptr pEntity); + EntityRef& SetPathTo(SR_HTYPES_NS::SharedPtr pEntity); void SetOwner(const EntityRefUtils::OwnerRef& owner); private: @@ -55,7 +56,7 @@ namespace SR_UTILS_NS { bool m_relative = true; EntityRefUtils::OwnerRef m_owner; - mutable Entity::Ptr m_target; + mutable SR_HTYPES_NS::SharedPtr m_target; }; } diff --git a/Engine/Core/libs/Utils/inc/Utils/ECS/EntityRefUtils.h b/Engine/Core/libs/Utils/inc/Utils/ECS/EntityRefUtils.h index aab4aa5d4..b8211c452 100644 --- a/Engine/Core/libs/Utils/inc/Utils/ECS/EntityRefUtils.h +++ b/Engine/Core/libs/Utils/inc/Utils/ECS/EntityRefUtils.h @@ -6,20 +6,26 @@ #define SRENGINE_ENTITYREFUTILS_H #include -#include -#include -#include -#include +#include +#include + +namespace SR_WORLD_NS { + class Scene; +} + +namespace SR_UTILS_NS { + class Entity; +} namespace SR_UTILS_NS::EntityRefUtils { struct OwnerRef { OwnerRef() = default; - OwnerRef(const Entity::Ptr& ptr) /** NOLINT */ + OwnerRef(const SR_HTYPES_NS::SharedPtr& ptr) /** NOLINT */ : pEntity(ptr) { } - OwnerRef(const SR_WORLD_NS::Scene::Ptr& ptr) /** NOLINT */ + OwnerRef(const SR_HTYPES_NS::SafePtr& ptr) /** NOLINT */ : pScene(ptr) { } @@ -45,8 +51,9 @@ namespace SR_UTILS_NS::EntityRefUtils { return *this; } - Entity::Ptr pEntity; - SR_WORLD_NS::Scene::Ptr pScene; + SR_HTYPES_NS::SharedPtr pEntity; + SR_HTYPES_NS::SafePtr pScene; + }; SR_ENUM_NS_CLASS_T(Action, uint8_t, @@ -68,9 +75,9 @@ namespace SR_UTILS_NS::EntityRefUtils { typedef std::vector RefPath; - SR_MAYBE_UNUSED SR_WORLD_NS::Scene::Ptr GetSceneFromOwner(const OwnerRef& owner); + SR_MAYBE_UNUSED SR_HTYPES_NS::SafePtr GetSceneFromOwner(const OwnerRef& owner); - SR_MAYBE_UNUSED Entity::Ptr GetEntity(const OwnerRef& owner, const RefPath& path); + SR_MAYBE_UNUSED SR_HTYPES_NS::SharedPtr GetEntity(const OwnerRef& owner, const RefPath& path); SR_MAYBE_UNUSED RefPath CalculatePath(const OwnerRef& from); SR_MAYBE_UNUSED RefPath CalculateRelativePath(const OwnerRef& from, const OwnerRef& target); diff --git a/Engine/Core/libs/Utils/inc/Utils/ECS/IComponentable.h b/Engine/Core/libs/Utils/inc/Utils/ECS/IComponentable.h index 85ee4163e..afbe1e4ab 100644 --- a/Engine/Core/libs/Utils/inc/Utils/ECS/IComponentable.h +++ b/Engine/Core/libs/Utils/inc/Utils/ECS/IComponentable.h @@ -47,6 +47,7 @@ namespace SR_UTILS_NS { }; virtual Component* GetOrCreateComponent(const std::string& name); + virtual Component* GetOrCreateComponent(size_t hashName); virtual Component* GetComponent(const std::string& name); virtual Component* GetComponent(size_t hashName); diff --git a/Engine/Core/libs/Utils/inc/Utils/Math/Vector3.h b/Engine/Core/libs/Utils/inc/Utils/Math/Vector3.h index fe45d2346..d00af14f2 100644 --- a/Engine/Core/libs/Utils/inc/Utils/Math/Vector3.h +++ b/Engine/Core/libs/Utils/inc/Utils/Math/Vector3.h @@ -261,7 +261,7 @@ namespace SR_MATH_NS { return v; } - SR_NODISCARD Vector3 Lerp(const Vector3& vector3, Unit t) const noexcept { + SR_NODISCARD SR_FORCE_INLINE Vector3 SR_FASTCALL Lerp(const Vector3& vector3, Unit t) const noexcept { return (Vector3)(*this + (vector3 - *this) * t); } @@ -357,9 +357,11 @@ namespace SR_MATH_NS { z += p_v.z; return *this; } - template SR_FORCE_INLINE Vector3 operator+(const Vector3 &p_v) const { + + template SR_FORCE_INLINE Vector3 SR_FASTCALL operator+(const Vector3 &p_v) const noexcept { return Vector3(x + p_v.x, y + p_v.y, z + p_v.z); } + template SR_FORCE_INLINE Vector3 operator%(const Vector3 &p_v) const { return Vector3( static_cast(x) % static_cast(p_v.x), diff --git a/Engine/Core/libs/Utils/src/Utils/ECS/ComponentManager.cpp b/Engine/Core/libs/Utils/src/Utils/ECS/ComponentManager.cpp index da6264d82..7ab773e87 100644 --- a/Engine/Core/libs/Utils/src/Utils/ECS/ComponentManager.cpp +++ b/Engine/Core/libs/Utils/src/Utils/ECS/ComponentManager.cpp @@ -14,7 +14,12 @@ namespace SR_UTILS_NS { return nullptr; } - return CreateComponentImpl(m_ids.at(name)); + return CreateComponentOfName(m_ids.at(name)); + } + + Component *ComponentManager::CreateComponentOfName(ComponentManager::Hash hashName) { + SR_SCOPED_LOCK + return CreateComponentImpl(hashName); } Component* ComponentManager::CreateComponentImpl(size_t id) { diff --git a/Engine/Core/libs/Utils/src/Utils/ECS/EntityRef.cpp b/Engine/Core/libs/Utils/src/Utils/ECS/EntityRef.cpp index e15250f38..7af388e3d 100644 --- a/Engine/Core/libs/Utils/src/Utils/ECS/EntityRef.cpp +++ b/Engine/Core/libs/Utils/src/Utils/ECS/EntityRef.cpp @@ -25,6 +25,8 @@ namespace SR_UTILS_NS { } GameObject::Ptr EntityRef::GetGameObject() const { + SR_TRACY_ZONE; + if (m_path.empty() && m_target) { UpdatePath(); } @@ -37,6 +39,8 @@ namespace SR_UTILS_NS { } Component::Ptr EntityRef::GetComponent() const { + SR_TRACY_ZONE; + if (m_path.empty() && m_target) { UpdatePath(); } @@ -87,16 +91,16 @@ namespace SR_UTILS_NS { UpdatePath(); } - void EntityRef::SetPathTo(Entity::Ptr pEntity) { + EntityRef& EntityRef::SetPathTo(Entity::Ptr pEntity) { if (!EntityRefUtils::IsOwnerValid(m_owner)) { SRHalt("Invalid owner!"); - return; + return *this; } if (!pEntity) { m_target = pEntity; m_path.clear(); - return; + return *this; } if (IsRelative()) { @@ -107,6 +111,8 @@ namespace SR_UTILS_NS { } UpdateTarget(); + + return *this; } bool EntityRef::IsValid() const { diff --git a/Engine/Core/libs/Utils/src/Utils/ECS/EntityRefUtils.cpp b/Engine/Core/libs/Utils/src/Utils/ECS/EntityRefUtils.cpp index cae5e0b12..2a545fd5d 100644 --- a/Engine/Core/libs/Utils/src/Utils/ECS/EntityRefUtils.cpp +++ b/Engine/Core/libs/Utils/src/Utils/ECS/EntityRefUtils.cpp @@ -3,6 +3,10 @@ // #include +#include +#include +#include +#include namespace SR_UTILS_NS::EntityRefUtils { Entity::Ptr GetEntity(const OwnerRef& owner, const RefPath& path) { diff --git a/Engine/Core/libs/Utils/src/Utils/ECS/IComponentable.cpp b/Engine/Core/libs/Utils/src/Utils/ECS/IComponentable.cpp index 278e67541..064fe6093 100644 --- a/Engine/Core/libs/Utils/src/Utils/ECS/IComponentable.cpp +++ b/Engine/Core/libs/Utils/src/Utils/ECS/IComponentable.cpp @@ -48,20 +48,12 @@ namespace SR_UTILS_NS { return pMarshal; } - Component* IComponentable::GetComponent(const std::string& name) { - return GetComponent(SR_HASH_STR(name)); - } - - bool IComponentable::ContainsComponent(const std::string& name) { - return GetComponent(name); - } - - Component* IComponentable::GetOrCreateComponent(const std::string& name) { - if (auto&& pComponent = GetComponent(name)) { + Component* IComponentable::GetOrCreateComponent(size_t hashName) { + if (auto&& pComponent = GetComponent(hashName)) { return pComponent; } - if (auto&& pComponent = ComponentManager::Instance().CreateComponentOfName(name)) { + if (auto&& pComponent = ComponentManager::Instance().CreateComponentOfName(hashName)) { if (AddComponent(pComponent)) { return pComponent; } @@ -73,6 +65,18 @@ namespace SR_UTILS_NS { return nullptr; } + Component* IComponentable::GetComponent(const std::string& name) { + return GetComponent(SR_HASH_STR(name)); + } + + bool IComponentable::ContainsComponent(const std::string& name) { + return GetComponent(name); + } + + Component* IComponentable::GetOrCreateComponent(const std::string& name) { + return GetOrCreateComponent(SR_HASH_STR(name)); + } + Component* IComponentable::GetComponent(size_t hashName) { for (auto&& pComponent : m_components) { if (pComponent->GetComponentHashName() != hashName) { @@ -101,6 +105,7 @@ namespace SR_UTILS_NS { m_loadedComponents.emplace_back(pComponent); + pComponent->SetParent(this); pComponent->OnLoaded(); /// pComponent->OnAttached(); diff --git a/Engine/Core/libs/Utils/src/Utils/World/Scene.cpp b/Engine/Core/libs/Utils/src/Utils/World/Scene.cpp index 612f5ad00..a605bc8a9 100644 --- a/Engine/Core/libs/Utils/src/Utils/World/Scene.cpp +++ b/Engine/Core/libs/Utils/src/Utils/World/Scene.cpp @@ -331,6 +331,8 @@ namespace SR_WORLD_NS { m_newQueue.emplace_back(ptr); + ptr->SetScene(this); + for (auto&& child : ptr->GetChildrenRef()) { RegisterGameObject(child); } @@ -358,7 +360,6 @@ namespace SR_WORLD_NS { const uint64_t id = m_freeObjIndices.empty() ? m_gameObjects.size() : m_freeObjIndices.front(); gameObject->SetIdInScene(id); - gameObject->SetScene(this); if (m_freeObjIndices.empty()) { m_gameObjects.emplace_back(gameObject); diff --git a/Engine/Core/src/Core/GUI/Inspector.cpp b/Engine/Core/src/Core/GUI/Inspector.cpp index d0a32b3da..ee4cd6dc1 100644 --- a/Engine/Core/src/Core/GUI/Inspector.cpp +++ b/Engine/Core/src/Core/GUI/Inspector.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace Framework::Core::GUI { Inspector::Inspector(Hierarchy* hierarchy) @@ -191,6 +192,7 @@ namespace Framework::Core::GUI { copyPtrComponent = DrawComponent(copyPtrComponent, "Text", index); copyPtrComponent = DrawComponent(copyPtrComponent, "Animator", index); copyPtrComponent = DrawComponent(copyPtrComponent, "Skeleton", index); + copyPtrComponent = DrawComponent(copyPtrComponent, "Bone", index); copyPtrComponent = DrawComponent(copyPtrComponent, "LookAtComponent", index); if (copyPtrComponent != component && copyPtrComponent) {