remove some file which were deleted on main

This commit is contained in:
greerdv
2021-05-25 13:18:13 +01:00
parent e0fc4cd985
commit 9211452d15
2 changed files with 0 additions and 587 deletions
@@ -1,349 +0,0 @@
/*
* 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.
*
*/
#include "LmbrCentral_precompiled.h"
#include "AttachmentComponent.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Component/Entity.h>
#include <MathConversion.h>
#include <LmbrCentral/Rendering/MeshAsset.h>
#include <LmbrCentral/Animation/AttachmentComponentBus.h>
namespace LmbrCentral
{
/// Behavior Context handler for AttachmentComponentNotificationBus
class BehaviorAttachmentComponentNotificationBusHandler : public AttachmentComponentNotificationBus::Handler, public AZ::BehaviorEBusHandler
{
public:
AZ_EBUS_BEHAVIOR_BINDER(BehaviorAttachmentComponentNotificationBusHandler, "{636B95A0-5C7D-4EE7-8645-955665315451}", AZ::SystemAllocator
, OnAttached, OnDetached);
void OnAttached(AZ::EntityId id) override
{
Call(FN_OnAttached, id);
}
void OnDetached(AZ::EntityId id) override
{
Call(FN_OnDetached, id);
}
};
void AttachmentConfiguration::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<AttachmentConfiguration>()
->Version(1)
->Field("Target ID", &AttachmentConfiguration::m_targetId)
->Field("Target Bone Name", &AttachmentConfiguration::m_targetBoneName)
->Field("Target Offset", &AttachmentConfiguration::m_targetOffset)
->Field("Attached Initially", &AttachmentConfiguration::m_attachedInitially)
->Field("Scale Source", &AttachmentConfiguration::m_scaleSource)
;
}
AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
if (behaviorContext)
{
behaviorContext->EBus<AttachmentComponentRequestBus>("AttachmentComponentRequestBus")
->Event("Attach", &AttachmentComponentRequestBus::Events::Attach)
->Event("Detach", &AttachmentComponentRequestBus::Events::Detach)
->Event("SetAttachmentOffset", &AttachmentComponentRequestBus::Events::SetAttachmentOffset);
behaviorContext->EBus<AttachmentComponentNotificationBus>("AttachmentComponentNotificationBus")
->Handler<BehaviorAttachmentComponentNotificationBusHandler>();
}
}
void AttachmentComponent::Reflect(AZ::ReflectContext* context)
{
AttachmentConfiguration::Reflect(context);
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<AttachmentComponent, AZ::Component>()
->Version(1)
->Field("Configuration", &AttachmentComponent::m_initialConfiguration)
;
}
}
//=========================================================================
// BoneFollower
//=========================================================================
void BoneFollower::Activate(AZ::Entity* owner, const AttachmentConfiguration& configuration, bool targetCanAnimate)
{
AZ_Assert(owner, "owner is required");
AZ_Assert(!m_ownerId.IsValid(), "BoneFollower is already Activated");
m_ownerId = owner->GetId();
m_targetCanAnimate = targetCanAnimate;
m_isUpdatingOwnerTransform = false;
m_scaleSource = configuration.m_scaleSource;
m_cachedOwnerTransform = AZ::Transform::CreateIdentity();
EBUS_EVENT_ID_RESULT(m_cachedOwnerTransform, m_ownerId, AZ::TransformBus, GetWorldTM);
if (configuration.m_attachedInitially)
{
Attach(configuration.m_targetId, configuration.m_targetBoneName.c_str(), configuration.m_targetOffset);
}
AttachmentComponentRequestBus::Handler::BusConnect(m_ownerId);
}
void BoneFollower::Deactivate()
{
AZ_Assert(m_ownerId.IsValid(), "BoneFollower was never Activated");
AttachmentComponentRequestBus::Handler::BusDisconnect();
Detach();
m_ownerId.SetInvalid();
}
AZ::EntityId BoneFollower::GetTargetEntityId()
{
return m_targetId;
}
AZ::Transform BoneFollower::GetOffset()
{
return m_targetOffset;
}
void BoneFollower::Attach(AZ::EntityId targetId, const char* targetBoneName, const AZ::Transform& offset)
{
AZ_Assert(m_ownerId.IsValid(), "BoneFollower must be Activated to use.")
// safe to try and detach, even if we weren't attached
Detach();
if (!targetId.IsValid())
{
return;
}
if (targetId == m_ownerId)
{
AZ_Error("Attachment Component", false, "AttachmentComponent cannot target itself");
return;
}
// Note: the target entity may not be activated yet. That's ok.
// When mesh is ready we are notified via MeshComponentEvents::OnMeshCreated
// When transform is ready we are notified via TransformNotificationBus::OnTransformChanged
m_targetId = targetId;
m_targetBoneName = targetBoneName;
m_targetOffset = offset;
BindTargetBone();
m_targetBoneTransform = AZ::Transform::Identity();
m_isTargetEntityTransformKnown = false; // target's transform may not be available yet
AZ::TransformBus::EventResult(m_cachedOwnerTransform, m_ownerId, &AZ::TransformBus::Events::GetWorldTM); // owner query will always succeed
MeshComponentNotificationBus::Handler::BusConnect(m_targetId); // fires OnMeshCreated if asset is already ready
AZ::TransformNotificationBus::Handler::BusConnect(m_targetId);
if (m_targetCanAnimate)
{
// Only register for per-frame updates when target can animate
AZ::TickBus::Handler::BusConnect();
}
// update owner's transform
UpdateOwnerTransformIfNecessary();
// alert others that we've attached
AttachmentComponentNotificationBus::Event(m_targetId, &AttachmentComponentNotificationBus::Events::OnAttached, m_ownerId);
}
void BoneFollower::Detach()
{
AZ_Assert(m_ownerId.IsValid(), "BoneFollower must be Activated to use.");
if (m_targetId.IsValid())
{
// alert others that we're detaching
EBUS_EVENT_ID(m_targetId, AttachmentComponentNotificationBus, OnDetached, m_ownerId);
MeshComponentNotificationBus::Handler::BusDisconnect();
AZ::TransformNotificationBus::Handler::BusDisconnect(m_targetId);
AZ::TickBus::Handler::BusDisconnect();
m_targetId.SetInvalid();
}
}
const char* BoneFollower::GetJointName()
{
return m_targetBoneName.c_str();
}
void BoneFollower::SetAttachmentOffset(const AZ::Transform& offset)
{
AZ_Assert(m_ownerId.IsValid(), "BoneFollower must be Activated to use.");
if (m_targetId.IsValid())
{
m_targetOffset = offset;
UpdateOwnerTransformIfNecessary();
}
}
void BoneFollower::OnMeshCreated(const AZ::Data::Asset<AZ::Data::AssetData>& asset)
{
(void)asset;
// reset character values
BindTargetBone();
m_targetBoneTransform = QueryBoneTransform();
// move owner if necessary
UpdateOwnerTransformIfNecessary();
}
void BoneFollower::BindTargetBone()
{
m_targetBoneId = -1;
SkeletalHierarchyRequestBus::EventResult(m_targetBoneId, m_targetId, &SkeletalHierarchyRequests::GetJointIndexByName, m_targetBoneName.c_str());
}
void BoneFollower::UpdateOwnerTransformIfNecessary()
{
// Can't update until target entity's transform is known
if (!m_isTargetEntityTransformKnown)
{
if (AZ::TransformBus::GetNumOfEventHandlers(m_targetId) == 0)
{
return;
}
AZ::TransformBus::EventResult(m_targetEntityTransform, m_targetId, &AZ::TransformBus::Events::GetWorldTM);
m_isTargetEntityTransformKnown = true;
}
AZ::Transform finalTransform;
if (m_scaleSource == AttachmentConfiguration::ScaleSource::WorldScale)
{
// apply offset in world-space
finalTransform = m_targetEntityTransform * m_targetBoneTransform;
finalTransform.SetUniformScale(1.0f);
finalTransform *= m_targetOffset;
}
else if (m_scaleSource == AttachmentConfiguration::ScaleSource::TargetEntityScale)
{
// apply offset in target-entity-space (ignoring bone scale)
AZ::Transform boneNoScale = m_targetBoneTransform;
boneNoScale.SetUniformScale(1.0f);
finalTransform = m_targetEntityTransform * boneNoScale * m_targetOffset;
}
else // AttachmentConfiguration::ScaleSource::TargetEntityScale
{
// apply offset in target-bone-space
finalTransform = m_targetEntityTransform * m_targetBoneTransform * m_targetOffset;
}
if (m_cachedOwnerTransform != finalTransform)
{
AZ_Warning("Attachment Component", !m_isUpdatingOwnerTransform, "AttachmentComponent detected a cycle when updating transform, do not target child entities.");
if (!m_isUpdatingOwnerTransform)
{
m_cachedOwnerTransform = finalTransform;
m_isUpdatingOwnerTransform = true;
EBUS_EVENT_ID(m_ownerId, AZ::TransformBus, SetWorldTM, finalTransform);
m_isUpdatingOwnerTransform = false;
}
}
}
AZ::Transform BoneFollower::QueryBoneTransform() const
{
AZ::Transform boneTransform = AZ::Transform::CreateIdentity();
if (m_targetBoneId >= 0)
{
SkeletalHierarchyRequestBus::EventResult(boneTransform, m_targetId, &SkeletalHierarchyRequests::GetJointTransformCharacterRelative, m_targetBoneId);
}
return boneTransform;
}
// fires when target's transform changes
void BoneFollower::OnTransformChanged(const AZ::Transform& /*local*/, const AZ::Transform& world)
{
m_targetEntityTransform = world;
m_isTargetEntityTransformKnown = true;
UpdateOwnerTransformIfNecessary();
}
void BoneFollower::OnTick(float /*deltaTime*/, AZ::ScriptTimePoint /*time*/)
{
m_targetBoneTransform = QueryBoneTransform();
UpdateOwnerTransformIfNecessary();
}
int BoneFollower::GetTickOrder()
{
return AZ::TICK_ATTACHMENT;
}
void BoneFollower::Reattach(bool detachFirst)
{
#ifdef AZ_ENABLE_TRACING
AZ::Entity* ownerEntity = nullptr;
AZ::Entity* targetEntity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(ownerEntity, &AZ::ComponentApplicationBus::Events::FindEntity, m_ownerId);
AZ::ComponentApplicationBus::BroadcastResult(targetEntity, &AZ::ComponentApplicationBus::Events::FindEntity, m_targetId);
AZ_TracePrintf("BoneFollower", "Reattaching entity '%s' to entity '%s'", ownerEntity ? ownerEntity->GetName().c_str() : "",
targetEntity ? targetEntity->GetName().c_str() : "");
#endif
if (m_targetId.IsValid() && detachFirst)
{
AttachmentComponentNotificationBus::Event(m_targetId, &AttachmentComponentNotificationBus::Events::OnDetached, m_ownerId);
}
if (m_targetId != m_ownerId)
{
AttachmentComponentNotificationBus::Event(m_targetId, &AttachmentComponentNotificationBus::Events::OnAttached, m_ownerId);
}
}
//=========================================================================
// AttachmentComponent
//=========================================================================
void AttachmentComponent::Activate()
{
#ifdef AZ_ENABLE_TRACING
bool isStaticTransform = false;
AZ::TransformBus::EventResult(isStaticTransform, GetEntityId(), &AZ::TransformBus::Events::IsStaticTransform);
AZ_Warning("Attachment Component", !isStaticTransform,
"Attachment needs to move, but entity '%s' %s has a static transform.", GetEntity()->GetName().c_str(), GetEntityId().ToString().c_str());
#endif
m_boneFollower.Activate(GetEntity(), m_initialConfiguration, true);
}
void AttachmentComponent::Deactivate()
{
m_boneFollower.Deactivate();
}
} // namespace LmbrCentral
@@ -1,238 +0,0 @@
/*
* 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.
*
*/
#include "LmbrCentral_precompiled.h"
#include "EditorAttachmentComponent.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Math/Quaternion.h>
#include <AzCore/Math/Transform.h>
namespace LmbrCentral
{
void EditorAttachmentComponent::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<EditorAttachmentComponent, EditorComponentBase>()
->Version(1)
->Field("Target ID", &EditorAttachmentComponent::m_targetId)
->Field("Target Bone Name", &EditorAttachmentComponent::m_targetBoneName)
->Field("Position Offset", &EditorAttachmentComponent::m_positionOffset)
->Field("Rotation Offset", &EditorAttachmentComponent::m_rotationOffset)
->Field("Scale Offset", &EditorAttachmentComponent::m_scaleOffset)
->Field("Attached Initially", &EditorAttachmentComponent::m_attachedInitially)
->Field("Scale Source", &EditorAttachmentComponent::m_scaleSource)
;
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<EditorAttachmentComponent>(
"Attachment", "The Attachment component lets an entity attach to a bone on the skeleton of another entity")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Category, "Animation")
->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/Attachment.svg")
->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/Viewport/Attachment.png")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->Attribute(AZ::Edit::Attributes::HelpPageURL, "https://docs.aws.amazon.com/lumberyard/latest/userguide/component-attachment.html")
->DataElement(0, &EditorAttachmentComponent::m_targetId,
"Target entity", "Attach to this entity.")
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnTargetIdChanged)
->DataElement(AZ::Edit::UIHandlers::ComboBox, &EditorAttachmentComponent::m_targetBoneName,
"Joint name", "Attach to this joint on target entity.")
->Attribute(AZ::Edit::Attributes::StringList, &EditorAttachmentComponent::GetTargetBoneOptions)
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnTargetBoneChanged)
->DataElement(0, &EditorAttachmentComponent::m_positionOffset,
"Position offset", "Local position offset from target bone")
->Attribute(AZ::Edit::Attributes::Suffix, "m")
->Attribute(AZ::Edit::Attributes::Step, 0.01f)
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnTargetOffsetChanged)
->DataElement(0, &EditorAttachmentComponent::m_rotationOffset,
"Rotation offset", "Local rotation offset from target bone")
->Attribute(AZ::Edit::Attributes::Suffix, "deg")
->Attribute(AZ::Edit::Attributes::Step, 0.01f)
->Attribute(AZ::Edit::Attributes::Min, -AZ::RadToDeg(AZ::Constants::TwoPi))
->Attribute(AZ::Edit::Attributes::Max, AZ::RadToDeg(AZ::Constants::TwoPi))
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnTargetOffsetChanged)
->DataElement(0, &EditorAttachmentComponent::m_scaleOffset,
"Scale offset", "Local scale offset from target entity")
->Attribute(AZ::Edit::Attributes::Step, 0.1f)
->Attribute(AZ::Edit::Attributes::Min, 0.001f)
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnTargetOffsetChanged)
->DataElement(0, &EditorAttachmentComponent::m_attachedInitially,
"Attached initially", "Whether to attach to target upon activation.")
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnAttachedInitiallyChanged)
->DataElement(AZ::Edit::UIHandlers::ComboBox, &EditorAttachmentComponent::m_scaleSource,
"Scaling", "How object scale should be determined. "
"Use world scale = Attached object is scaled in world space, Use target entity scale = Attached object adopts scale of target entity., Use target bone scale = Attached object adopts scale of target entity/joint.")
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorAttachmentComponent::OnScaleSourceChanged)
->EnumAttribute(AttachmentConfiguration::ScaleSource::WorldScale, "Use world scale")
->EnumAttribute(AttachmentConfiguration::ScaleSource::TargetEntityScale, "Use target entity scale")
->EnumAttribute(AttachmentConfiguration::ScaleSource::TargetBoneScale, "Use target bone scale")
;
}
}
}
void EditorAttachmentComponent::Activate()
{
Base::Activate();
m_boneFollower.Activate(GetEntity(),
CreateAttachmentConfiguration(),
false); // Entity's don't animate in Editor
}
void EditorAttachmentComponent::Deactivate()
{
m_boneFollower.Deactivate();
Base::Deactivate();
}
void EditorAttachmentComponent::BuildGameEntity(AZ::Entity* gameEntity)
{
AttachmentComponent* component = gameEntity->CreateComponent<AttachmentComponent>();
if (component)
{
component->m_initialConfiguration = CreateAttachmentConfiguration();
}
}
AttachmentConfiguration EditorAttachmentComponent::CreateAttachmentConfiguration() const
{
AttachmentConfiguration configuration;
configuration.m_targetId = m_targetId;
configuration.m_targetBoneName = m_targetBoneName;
configuration.m_targetOffset = GetTargetOffset();
configuration.m_attachedInitially = m_attachedInitially;
configuration.m_scaleSource = m_scaleSource;
return configuration;
}
AZ::Transform EditorAttachmentComponent::GetTargetOffset() const
{
AZ::Transform offset = AZ::ConvertEulerDegreesToTransform(m_rotationOffset);
offset.SetTranslation(m_positionOffset);
offset.MultiplyByUniformScale(m_scaleOffset.GetMaxElement());
return offset;
}
AZStd::vector<AZStd::string> EditorAttachmentComponent::GetTargetBoneOptions() const
{
AZStd::vector<AZStd::string> names;
// insert blank entry, so user may choose to bind to NO bone.
names.push_back("");
// track whether currently-set bone is found
bool currentTargetBoneFound = false;
// Get character and iterate over bones
AZ::u32 jointCount = 0;
SkeletalHierarchyRequestBus::EventResult(jointCount, m_targetId, &SkeletalHierarchyRequests::GetJointCount);
for (AZ::u32 jointIndex = 0; jointIndex < jointCount; ++jointIndex)
{
const char* name = nullptr;
SkeletalHierarchyRequestBus::EventResult(name, m_targetId, &SkeletalHierarchyRequests::GetJointNameByIndex, jointIndex);
if (name)
{
names.push_back(name);
if (!currentTargetBoneFound)
{
currentTargetBoneFound = (m_targetBoneName == names.back());
}
}
}
// If we never found currently-set bone name,
// stick it at top of list, just in case user wants to keep it anyway
if (!currentTargetBoneFound && !m_targetBoneName.empty())
{
names.insert(names.begin(), m_targetBoneName);
}
return names;
}
AZ::u32 EditorAttachmentComponent::OnTargetIdChanged()
{
// Warn about bad setups (it won't crash, but it's nice to handle this early)
if (m_targetId == GetEntityId())
{
AZ_Warning(GetEntity()->GetName().c_str(), false, "AttachmentComponent cannot target self.")
m_targetId.SetInvalid();
}
// Warn about children attaching to a parent
AZ::EntityId parentOfTarget;
AZ::TransformBus::EventResult(parentOfTarget, m_targetId, &AZ::TransformBus::Events::GetParentId);
while (parentOfTarget.IsValid())
{
if (parentOfTarget == GetEntityId())
{
AZ_Warning(GetEntity()->GetName().c_str(), parentOfTarget != GetEntityId(), "AttachmentComponent cannot target child entity");
m_targetId.SetInvalid();
break;
}
AZ::EntityId currentParentId = parentOfTarget;
parentOfTarget.SetInvalid();
AZ::TransformBus::EventResult(parentOfTarget, currentParentId, &AZ::TransformBus::Events::GetParentId);
}
AttachOrDetachAsNecessary();
return AZ::Edit::PropertyRefreshLevels::AttributesAndValues; // refresh bone options
}
AZ::u32 EditorAttachmentComponent::OnTargetBoneChanged()
{
AttachOrDetachAsNecessary();
return AZ::Edit::PropertyRefreshLevels::None;
}
AZ::u32 EditorAttachmentComponent::OnTargetOffsetChanged()
{
EBUS_EVENT_ID(GetEntityId(), AttachmentComponentRequestBus, SetAttachmentOffset, GetTargetOffset());
return AZ::Edit::PropertyRefreshLevels::None;
}
AZ::u32 EditorAttachmentComponent::OnAttachedInitiallyChanged()
{
AttachOrDetachAsNecessary();
return AZ::Edit::PropertyRefreshLevels::None;
}
AZ::u32 EditorAttachmentComponent::OnScaleSourceChanged()
{
m_boneFollower.Deactivate();
m_boneFollower.Activate(GetEntity(),
CreateAttachmentConfiguration(),
false);
return AZ::Edit::PropertyRefreshLevels::None;
}
void EditorAttachmentComponent::AttachOrDetachAsNecessary()
{
if (m_attachedInitially && m_targetId.IsValid())
{
EBUS_EVENT_ID(GetEntityId(), AttachmentComponentRequestBus, Attach, m_targetId, m_targetBoneName.c_str(), GetTargetOffset());
}
else
{
EBUS_EVENT_ID(GetEntityId(), AttachmentComponentRequestBus, Detach);
}
}
} // namespace LmbrCentral