/* * 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 #include #include namespace NvCloth { extern const int InvalidIndex; //! Base collider class with transform and joint information. struct Collider { //! Offset transform relative to the joint attached. AZ::Transform m_offsetTransform = AZ::Transform::CreateIdentity(); //! Current transform in model space after animation applied. AZ::Transform m_currentModelSpaceTransform = AZ::Transform::CreateIdentity(); //! Joint this collider is attached to. int m_jointIndex = InvalidIndex; }; //! Describes the shape on an sphere collider. struct SphereCollider : public Collider { //! Radius of the sphere. float m_radius = 0.0f; int m_nvSphereIndex = InvalidIndex; //!< Identifies the sphere within m_spheres in ActorClothColliders. }; //! Describes the shape on an sphere collider. struct CapsuleCollider : public Collider { //! Height of the capsule. float m_height = 0.0f; //! Radius of the capsule. float m_radius = 0.0f; int m_capsuleIndex = InvalidIndex; //!< Identifies first index of the capsule within m_capsuleIndices in ActorClothColliders. int m_sphereAIndex = InvalidIndex; //!< Identifies the first sphere within m_spheres in ActorClothColliders. int m_sphereBIndex = InvalidIndex; //!< Identifies the second sphere within m_spheres in ActorClothColliders. }; //! Class to retrieve cloth colliders information from an actor on the same entity //! and updates their transform from skinning animation. //! //! @note There is a limit of 32 sphere colliders and 32 capsule colliders. //! In the case that all capsules use unique spheres then the maximum //! number of capsule would go down to 16, limited by the maximum number of spheres (32). class ActorClothColliders { public: AZ_TYPE_INFO(ActorClothColliders, "{EA2D9B6A-2493-4B6A-972E-BB639E16798E}"); static AZStd::unique_ptr Create(AZ::EntityId entityId); explicit ActorClothColliders(AZ::EntityId entityId); //! Updates the colliders' transforms with the current pose of the actor. void Update(); const AZStd::vector& GetSphereColliders() const; const AZStd::vector& GetCapsuleColliders() const; const AZStd::vector& GetSpheres() const; const AZStd::vector& GetCapsuleIndices() const; private: void UpdateSphere(const SphereCollider& sphere); void UpdateCapsule(const CapsuleCollider& capsule); AZ::EntityId m_entityId; // Configuration data of spheres and capsules, describing their shape and transforms relative to joints. AZStd::vector m_sphereColliders; AZStd::vector m_capsuleColliders; // The current positions and radius of sphere colliders. // Every update, these positions are computed with the current pose of the actor. // Note: The spheres used to formed capsules are also part of this list. AZStd::vector m_spheres; // The sphere collider indices associated with capsules. // Each capsule is 2 indices within the list. AZStd::vector m_capsuleIndices; }; } // namespace NvCloth