Files
o3de/Gems/EMotionFX/Code/Include/Integration/ActorComponentBus.h
T
Adi Bar-Lev 9786d63596 Hair - Hair Gem introduction to O3DE from Atom/barlev/AtomTressFX_DevRebase (#4439)
* Hair
- First introduction of Hair gem to Atom and O3DE
- The hair technology is based off TressFX 4.1
- These are some of the areas we enhanced the original TressFX implementation:
   - Lighting model was replaced and we now use a modified Marschner model
   - Blending is done directly with the back buffer removing the silhouette of the original implementation
   - Hair depth / thickness is now calculated to remove incorrect back lighting (TT lobe in the Marschner model)
   - Thickness corrected to handle hair gaps hence introducing better light passage for the TT
   - The hair is fully integrated into the Atom pipeline and structure design
   - Usage of single shared buffer for the computer buffers reduces barriers sync overhead

Remarks:
- Collisions via SDF compute are to be introduced soon
- Improved shortcut rendering method ala Eidos Montreal to be introduced soon

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - code clean pass

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - EMFX Actor visibility implementation

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - COnnecting hair passes to Atom's MainPipeline.pass

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - adding dedicated thumbnail pipeline that does not include the hair gem

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - changed Atom shader files to allow hooking the hair to the lighting data structures

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - fixed a few headers to have the latest O3DE license + verification fixes

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - enabling editor component only when tool pipline is built + default texture add

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - fixing Linux and Android compilation builds

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - another files change to make Linux compile

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - more Linux and Android build fixes

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair

- Adding usage of fallback white texture
- Removing invalid null assignments into vectors
- Removing redundant mutex preventing deletion on some platforms

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair

- Shame: removed forgoten #pragma optimize
- Adding header complained by Android

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - removing the Hair Gem connection in the active project.

- This submission removes the connection to the active project hence allowing to run without the Gem.  Enable the passes in MainPipeline.pass and declare them again when you want to use the Gem.

Remark: the gem file PassTemplates.azasset was renamed and will be connected via code in the future to avoid the need to declare in the global pass template.
Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - registrating gem pass templates through the gem templates file (#198)

* Hair - registrating gem pass templates through the gem templates file

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - adding handler disconnect for the pass template registration.

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - PPLLIndexCounter buffer going data driven via the pass declarations (#202)

* Hair - PPLLIndexCounter buffer going data driven via the pass declaration
- Moving PPLLIndexCounter from code allocation and attachment to be data driven
- Fixed RPI typo bug that can prevent using buffers like that

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - fixing UI Editor (LYShine) crash (#209)

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* [Hair - resolved the multi pipeline mismatches and crashes + cleaned initialization & leftovers (#222)

* [Hair] - multiple render pipelines handling

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* [Hair] - Shut down order is handle to allow hair feature processor be deregistered only after the bootstrap component has disabled it

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* [Hair] - minor cleanups

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* [Hair] - followups from review nits

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - code fixes based on the CR remarks for the Hair merge to Dev (#248)

* Hair
- First introduction of Hair gem to Atom and O3DE
- The hair technology is based off TressFX 4.1
- These are some of the areas we enhanced the original TressFX implementation:
   - Lighting model was replaced and we now use a modified Marschner model
   - Blending is done directly with the back buffer removing the silhouette of the original implementation
   - Hair depth / thickness is now calculated to remove incorrect back lighting (TT lobe in the Marschner model)
   - Thickness corrected to handle hair gaps hence introducing better light passage for the TT
   - The hair is fully integrated into the Atom pipeline and structure design
   - Usage of single shared buffer for the computer buffers reduces barriers sync overhead

Remarks:
- Collisions via SDF compute are to be introduced soon
- Improved shortcut rendering method ala Eidos Montreal to be introduced soon

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - code clean pass

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - EMFX Actor visibility implementation

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - COnnecting hair passes to Atom's MainPipeline.pass

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - adding dedicated thumbnail pipeline that does not include the hair gem

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - changed Atom shader files to allow hooking the hair to the lighting data structures

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - fixed a few headers to have the latest O3DE license + verification fixes

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - enabling editor component only when tool pipline is built + default texture add

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - fixing Linux and Android compilation builds

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - another files change to make Linux compile

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - more Linux and Android build fixes

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair

- Adding usage of fallback white texture
- Removing invalid null assignments into vectors
- Removing redundant mutex preventing deletion on some platforms

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair

- Shame: removed forgoten #pragma optimize
- Adding header complained by Android

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - removing the Hair Gem connection in the active project.

- This submission removes the connection to the active project hence allowing to run without the Gem.  Enable the passes in MainPipeline.pass and declare them again when you want to use the Gem.

Remark: the gem file PassTemplates.azasset was renamed and will be connected via code in the future to avoid the need to declare in the global pass template.
Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - registrating gem pass templates through the gem templates file (#198)

* Hair - registrating gem pass templates through the gem templates file

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - adding handler disconnect for the pass template registration.

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - PPLLIndexCounter buffer going data driven via the pass declarations (#202)

* Hair - PPLLIndexCounter buffer going data driven via the pass declaration
- Moving PPLLIndexCounter from code allocation and attachment to be data driven
- Fixed RPI typo bug that can prevent using buffers like that

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - fixing UI Editor (LYShine) crash (#209)

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* [Hair - resolved the multi pipeline mismatches and crashes + cleaned initialization & leftovers (#222)

* [Hair] - multiple render pipelines handling

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* [Hair] - Shut down order is handle to allow hair feature processor be deregistered only after the bootstrap component has disabled it

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* [Hair] - minor cleanups

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* [Hair] - followups from review nits

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - last fixes based on CR remarks

Signed-off-by: Adi-Amazon <barlev@amazon.com>

* Hair - fixing AR

Signed-off-by: Adi-Amazon <barlev@amazon.com>
2021-10-04 10:46:31 -04:00

169 lines
7.0 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <AzCore/Component/ComponentBus.h>
#include <AzCore/Component/EntityId.h>
#include <AzCore/Math/Transform.h>
#include <AzCore/Outcome/Outcome.h>
#include <AzCore/RTTI/TypeInfo.h>
#include <AzFramework/Physics/AnimationConfiguration.h>
#include <AzFramework/Physics/Character.h>
namespace EMotionFX
{
class ActorInstance;
namespace Integration
{
/**
* EMotion FX attachment type.
*/
enum class AttachmentType : AZ::u32
{
None = 0, ///< Do not attach to another actor.
ActorAttachment, ///< Attach to another actor as a separately animating attachment.
SkinAttachment, ///< Attach to another actor as a skinned attachment (using the same skeleton as the attachment target).
};
enum class Space : AZ::u32
{
LocalSpace, ///< Relative to the parent.
ModelSpace, ///< Relative to the origin of the character.
WorldSpace ///< Relative to the world origin.
};
enum class SkinningMethod : AZ::u32
{
DualQuat = 0, ///< Dual Quaternions will be used to blend joints during skinning.
Linear ///< Matrices will be used to blend joints during skinning.
};
/**
* EMotion FX Actor Component Request Bus
* Used for making requests to EMotion FX Actor Components.
*/
class ActorComponentRequests
: public AZ::ComponentBus
{
public:
using MutexType = AZStd::mutex;
/// Retrieve component's actor instance.
/// \return pointer to actor instance.
virtual EMotionFX::ActorInstance* GetActorInstance() { return nullptr; }
/// Retrieve the total number of joints.
virtual size_t GetNumJoints() const { return 0; }
/// Find the name index of a given joint by its name.
/// \param name The name of the join to search for, case insensitive.
/// \return The joint index, or s_invalidJointIndex if no found.
virtual size_t GetJointIndexByName(const char* /*name*/) const { return s_invalidJointIndex; }
/// Retrieve the local transform (relative to the parent) of a given joint.
/// \param jointIndex The joint index to get the transform from.
/// \param Space the space to get the transform in.
virtual AZ::Transform GetJointTransform(size_t /*jointIndex*/, Space /*space*/) const { return AZ::Transform::CreateIdentity(); }
virtual void GetJointTransformComponents(size_t /*jointIndex*/, Space /*space*/, AZ::Vector3& outPosition, AZ::Quaternion& outRotation, AZ::Vector3& outScale) const { outPosition = AZ::Vector3::CreateZero(); outRotation = AZ::Quaternion::CreateIdentity(); outScale = AZ::Vector3::CreateOne(); }
virtual Physics::AnimationConfiguration* GetPhysicsConfig() const { return nullptr; }
/// Attach to the specified entity.
/// \param targetEntityId - Id of the entity to attach to.
/// \param attachmentType - Desired type of attachment.
virtual void AttachToEntity(AZ::EntityId /*targetEntityId*/, AttachmentType /*attachmentType*/) {}
/// Detach from parent entity, if attached.
virtual void DetachFromEntity() {}
/// Enables debug-drawing of the actor's root.
virtual void DebugDrawRoot(bool /*enable*/) {}
/// Enables rendering of the actor.
virtual bool GetRenderCharacter() const = 0;
virtual void SetRenderCharacter(bool enable) = 0;
virtual bool GetRenderActorVisible() const = 0;
/// Returns skinning method used by the actor.
virtual SkinningMethod GetSkinningMethod() const = 0;
static const size_t s_invalidJointIndex = std::numeric_limits<size_t>::max();
};
using ActorComponentRequestBus = AZ::EBus<ActorComponentRequests>;
/**
* EMotion FX Actor Component Notification Bus
* Used for monitoring events from actor components.
*/
class ActorComponentNotifications
: public AZ::ComponentBus
{
public:
//////////////////////////////////////////////////////////////////////////
/**
* Custom connection policy notifies connecting listeners immediately if actor instance is already created.
*/
template<class Bus>
struct AssetConnectionPolicy
: public AZ::EBusConnectionPolicy<Bus>
{
static void Connect(typename Bus::BusPtr& busPtr, typename Bus::Context& context, typename Bus::HandlerNode& handler, typename Bus::Context::ConnectLockGuard& connectLock, const typename Bus::BusIdType& id = 0)
{
AZ::EBusConnectionPolicy<Bus>::Connect(busPtr, context, handler, connectLock, id);
EMotionFX::ActorInstance* instance = nullptr;
ActorComponentRequestBus::EventResult(instance, id, &ActorComponentRequestBus::Events::GetActorInstance);
if (instance)
{
handler->OnActorInstanceCreated(instance);
}
}
};
template<typename Bus>
using ConnectionPolicy = AssetConnectionPolicy<Bus>;
//////////////////////////////////////////////////////////////////////////
/// Notifies listeners when the component has created an actor instance.
/// \param actorInstance - pointer to actor instance
virtual void OnActorInstanceCreated(EMotionFX::ActorInstance* /*actorInstance*/) {};
/// Notifies listeners when the component is destroying an actor instance.
/// \param actorInstance - pointer to actor instance
virtual void OnActorInstanceDestroyed(EMotionFX::ActorInstance* /*actorInstance*/) {};
};
using ActorComponentNotificationBus = AZ::EBus<ActorComponentNotifications>;
/**
* EMotion FX Editor Actor Component Request Bus
* Used for making requests to EMotion FX Actor Components.
*/
class EditorActorComponentRequests
: public AZ::ComponentBus
{
public:
virtual const AZ::Data::AssetId& GetActorAssetId() = 0;
virtual AZ::EntityId GetAttachedToEntityId() const = 0;
};
using EditorActorComponentRequestBus = AZ::EBus<EditorActorComponentRequests>;
} //namespace Integration
} // namespace EMotionFX
namespace AZ
{
AZ_TYPE_INFO_SPECIALIZE(EMotionFX::Integration::Space, "{7606E4DD-B7CB-408B-BD0D-3A95636BB017}");
}