/* * 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 #include namespace Physics { class Material; } namespace PhysX { class Material; class Shape : public Physics::Shape , public AZStd::enable_shared_from_this { public: AZ_CLASS_ALLOCATOR(Shape, AZ::SystemAllocator, 0); AZ_RTTI(Shape, "{A84BCCA2-7F29-4E17-830F-911E7BB3E80C}", Physics::Shape); Shape(const Physics::ColliderConfiguration& colliderConfiguration, const Physics::ShapeConfiguration& configuration); Shape(physx::PxShape* nativeShape); virtual ~Shape(); Shape(Shape&& shape); Shape& operator=(Shape&& shape); Shape(const Shape& shape) = delete; Shape& operator=(const Shape& shape) = delete; physx::PxShape* GetPxShape(); void SetMaterial(const AZStd::shared_ptr& material) override; AZStd::shared_ptr GetMaterial() const override; void SetMaterials(const AZStd::vector>& materials); const AZStd::vector>& GetMaterials(); void SetCollisionLayer(const Physics::CollisionLayer& layer) override; Physics::CollisionLayer GetCollisionLayer() const override; void SetCollisionGroup(const Physics::CollisionGroup& group) override; Physics::CollisionGroup GetCollisionGroup() const override; void SetName(const char* name) override; void SetLocalPose(const AZ::Vector3& offset, const AZ::Quaternion& rotation) override; AZStd::pair GetLocalPose() const override; float GetRestOffset() const override; float GetContactOffset() const override; void SetRestOffset(float restOffset) override; void SetContactOffset(float contactOffset) override; void* GetNativePointer() override; AZ::Crc32 GetTag() const override; bool IsTrigger() const; void AttachedToActor(void* actor) override; void DetachedFromActor() override; //! Raycast against this shape. //! @param request Ray parameters in world space. //! @param worldTransform World transform of this shape. Physics::RayCastHit RayCast(const Physics::RayCastRequest& worldSpaceRequest, const AZ::Transform& worldTransform) override; //! Raycast against this shape using local coordinates. //! @param request Ray parameters in local space. Physics::RayCastHit RayCastLocal(const Physics::RayCastRequest& localSpaceRequest) override; //! Retrieve this shape AABB. //! @param worldTransform World transform of this shape. AZ::Aabb GetAabb(const AZ::Transform& worldTransform) const override; //! Retrieve this shape AABB using local coordinates AZ::Aabb GetAabbLocal() const override; void GetGeometry(AZStd::vector& vertices, AZStd::vector& indices, AZ::Aabb* optionalBounds = nullptr) override; private: void BindMaterialsWithPxShape(); void ExtractMaterialsFromPxShape(); physx::PxScene* GetScene() const; void ReleasePxShape(physx::PxShape* shape); Physics::RayCastHit RayCastInternal(const Physics::RayCastRequest& worldSpaceRequest, const physx::PxTransform& pose); using PxShapeUniquePtr = AZStd::unique_ptr>; Shape() = default; PxShapeUniquePtr m_pxShape; AZStd::vector> m_materials; Physics::CollisionLayer m_collisionLayer; Physics::CollisionGroup m_collisionGroup; AZ::Crc32 m_tag; physx::PxActor* m_attachedActor = nullptr; }; }