Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,70 @@
/*
* 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 "StartingPointCamera_precompiled.h"
#include "AcquireByEntityId.h"
#include <AzCore/EBus/EBus.h>
#include <AzCore/Component/TransformBus.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Math/Transform.h>
#include <StartingPointCamera/StartingPointCameraConstants.h>
namespace Camera
{
void AcquireByEntityId::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
// Deprecating the CameraTargetComponent. This acquire behavior makes it obsolete
serializeContext->ClassDeprecate("CameraTargetComponent", "{0D6A6574-4B79-4907-8529-EB61F343D957}");
serializeContext->Class<AcquireByEntityId>()
->Version(1)
->Field("Entity Target", &AcquireByEntityId::m_target)
->Field("Use Target Rotation", &AcquireByEntityId::m_shouldUseTargetRotation)
->Field("Use Target Position", &AcquireByEntityId::m_shouldUseTargetPosition);
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<AcquireByEntityId>("AcquireByEntityId", "Acquires a target by entity ref")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByEntityId::m_target, "Entity target", "Specify an entity to target")
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByEntityId::m_shouldUseTargetRotation, "Use target rotation", "Set to false to not have the camera orient itself with the target")
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByEntityId::m_shouldUseTargetPosition, "Use target position", "Set to false to not have the camera position itself with the target");
}
}
}
bool AcquireByEntityId::AcquireTarget(AZ::Transform& outTransformInformation)
{
if (m_target.IsValid())
{
AZ::Transform targetsTransform = AZ::Transform::Identity();
AZ::TransformBus::EventResult(targetsTransform, m_target, &AZ::TransformInterface::GetWorldTM);
if (m_shouldUseTargetPosition)
{
outTransformInformation.SetTranslation(targetsTransform.GetTranslation());
}
if (m_shouldUseTargetRotation)
{
const AZ::Vector3 translation = outTransformInformation.GetTranslation();
outTransformInformation = targetsTransform;
outTransformInformation.SetTranslation(translation);
}
return true;
}
return false;
}
} // namespace Camera
@@ -0,0 +1,52 @@
/*
* 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.
*
*/
#pragma once
#include <AzCore/std/string/string.h>
#include <AzCore/RTTI/RTTI.h>
#include <CameraFramework/ICameraTargetAcquirer.h>
#include <AzCore/Component/Component.h>
#include <AzCore/Memory/SystemAllocator.h>
namespace AZ
{
class ReflectContext;
}
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// This will request Camera targets from the CameraTarget buses. It will
/// then return that target's transform when requested by the Camera Rig
//////////////////////////////////////////////////////////////////////////
class AcquireByEntityId
: public ICameraTargetAcquirer
{
public:
~AcquireByEntityId() override = default;
AZ_RTTI(AcquireByEntityId, "{14D0D355-1F83-4F46-9DE1-D41D23BDFC3C}", ICameraTargetAcquirer)
AZ_CLASS_ALLOCATOR(AcquireByEntityId, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraTargetAcquirer
bool AcquireTarget(AZ::Transform& outTransformInformation) override;
void Activate(AZ::EntityId) override {}
void Deactivate() override {}
private:
//////////////////////////////////////////////////////////////////////////
// Reflected Data
AZ::EntityId m_target = AZ::EntityId();
bool m_shouldUseTargetRotation = true;
bool m_shouldUseTargetPosition = true;
};
} //namespace Camera
@@ -0,0 +1,120 @@
/*
* 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 "StartingPointCamera_precompiled.h"
#include "AcquireByTag.h"
#include <AzCore/EBus/EBus.h>
#include <AzCore/Component/TransformBus.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Math/Transform.h>
#include <StartingPointCamera/StartingPointCameraConstants.h>
namespace Camera
{
namespace ClassConverters
{
static bool DeprecateCameraTargetComponentAcquirer(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement);
} // namespace ClassConverters
void AcquireByTag::Reflect(AZ::ReflectContext* reflection)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
if (serializeContext)
{
// Deprecating the CameraTargetComponent. This acquire behavior makes it obsolete
serializeContext->ClassDeprecate("CameraTargetComponentAcquirer", "{CF1C04E4-1195-42DD-AF0B-C9F94E80B35D}", &ClassConverters::DeprecateCameraTargetComponentAcquirer);
serializeContext->Class<AcquireByTag>()
->Version(1)
->Field("Target Tag", &AcquireByTag::m_targetTag)
->Field("Use Target Rotation", &AcquireByTag::m_shouldUseTargetRotation)
->Field("Use Target Position", &AcquireByTag::m_shouldUseTargetPosition);
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<AcquireByTag>("AcquireByTag", "Acquires a target by tag")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByTag::m_targetTag, "Target tag", "The tag on an entity you want to target")
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByTag::m_shouldUseTargetRotation, "Use target rotation", "Set to false to not have the camera orient itself with the target")
->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByTag::m_shouldUseTargetPosition, "Use target position", "Set to false to not have the camera position itself with the target");
}
}
}
bool AcquireByTag::AcquireTarget(AZ::Transform& outTransformInformation)
{
if (m_targets.size())
{
AZ::Transform targetsTransform = AZ::Transform::Identity();
AZ::TransformBus::EventResult(targetsTransform, m_targets[0], &AZ::TransformInterface::GetWorldTM);
if (m_shouldUseTargetPosition)
{
outTransformInformation.SetTranslation(targetsTransform.GetTranslation());
}
if (m_shouldUseTargetRotation)
{
const AZ::Vector3 translation = outTransformInformation.GetTranslation();
outTransformInformation = targetsTransform;
outTransformInformation.SetTranslation(translation);
}
return true;
}
return false;
}
void AcquireByTag::Activate(AZ::EntityId)
{
LmbrCentral::TagGlobalNotificationBus::Handler::BusConnect(LmbrCentral::Tag(m_targetTag.c_str()));
}
void AcquireByTag::Deactivate()
{
LmbrCentral::TagGlobalNotificationBus::Handler::BusDisconnect();
}
void AcquireByTag::OnEntityTagAdded(const AZ::EntityId& entityId)
{
AZ_Error("AcquireByTag", entityId.IsValid(), "A tag was added to an invalid entity, this should never happen");
m_targets.push_back(entityId);
}
void AcquireByTag::OnEntityTagRemoved(const AZ::EntityId& entityId)
{
auto&& iterator = AZStd::find(m_targets.begin(), m_targets.end(), entityId);
AZ_Error("AcquireByTag", iterator != m_targets.end(), "A tag was removed without being added, this should never happen");
m_targets.erase(iterator);
}
namespace ClassConverters
{
static bool DeprecateCameraTargetComponentAcquirer(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
{
AZStd::string tag;
classElement.GetChildData(AZ::Crc32("Tag of Specific Target"), tag);
bool useTargetRotation = true;
classElement.GetChildData(AZ::Crc32("Use Target Rotation"), useTargetRotation);
bool useTargetPosition = true;
classElement.GetChildData(AZ::Crc32("Use Target Position"), useTargetPosition);
classElement.Convert(context, AZ::AzTypeInfo<AcquireByTag>::Uuid());
classElement.AddElementWithData(context, "Target Tag", tag);
classElement.AddElementWithData(context, "Use Target Rotation", useTargetRotation);
classElement.AddElementWithData(context, "Use Target Position", useTargetPosition);
return true;
}
} // namespace ClassConverters
} // namespace Camera
@@ -0,0 +1,62 @@
/*
* 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.
*
*/
#pragma once
#include <AzCore/RTTI/RTTI.h>
#include <CameraFramework/ICameraTargetAcquirer.h>
#include <AzCore/Component/Component.h>
#include <LmbrCentral/Scripting/TagComponentBus.h>
#include <AzCore/Memory/SystemAllocator.h>
namespace AZ
{
class ReflectContext;
}
namespace Camera
{
//////////////////////////////////////////////////////////////////////////
/// This will request Camera targets from the CameraTarget buses. It will
/// then return that target's transform when requested by the Camera Rig
//////////////////////////////////////////////////////////////////////////
class AcquireByTag
: public ICameraTargetAcquirer
, private LmbrCentral::TagGlobalNotificationBus::Handler
{
public:
~AcquireByTag() override = default;
AZ_RTTI(AcquireByTag, "{E76621A5-E5A8-41B0-AC1D-EC87553181F5}", ICameraTargetAcquirer)
AZ_CLASS_ALLOCATOR(AcquireByTag, AZ::SystemAllocator, 0); ///< Use AZ::SystemAllocator, otherwise a CryEngine allocator will be used. This will cause the Asset Processor to crash when this object is deleted, because of the wrong uninitialisation order
static void Reflect(AZ::ReflectContext* reflection);
//////////////////////////////////////////////////////////////////////////
// ICameraTargetAcquirer
bool AcquireTarget(AZ::Transform& outTransformInformation) override;
void Activate(AZ::EntityId) override;
void Deactivate() override;
//////////////////////////////////////////////////////////////////////////
// LmbrCentral::TagGlobalNotificationBus
void OnEntityTagAdded(const AZ::EntityId&) override;
void OnEntityTagRemoved(const AZ::EntityId&) override;
private:
//////////////////////////////////////////////////////////////////////////
// Reflected Data
AZStd::string m_targetTag;
bool m_shouldUseTargetRotation = true;
bool m_shouldUseTargetPosition = true;
//////////////////////////////////////////////////////////////////////////
// Private Data
AZStd::vector<AZ::EntityId> m_targets;
};
} //namespace Camera