/* * 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 #include namespace LmbrCentral { template class EditorWrappedComponentBase; } namespace Vegetation { class ReferenceShapeConfig : public AZ::ComponentConfig { public: AZ_CLASS_ALLOCATOR(ReferenceShapeConfig, AZ::SystemAllocator, 0); AZ_RTTI(ReferenceShapeConfig, "{3E49974D-2EE0-4AF9-92B9-229A22B515C3}", AZ::ComponentConfig); static void Reflect(AZ::ReflectContext* context); AZ::EntityId m_shapeEntityId; }; static const AZ::Uuid ReferenceShapeComponentTypeId = "{EB9C6DC1-900F-4CE8-AA00-81361127063A}"; /** * allows reference and reuse of shape entities */ class ReferenceShapeComponent : public AZ::Component , private AZ::EntityBus::Handler , private AZ::TransformNotificationBus::Handler , private LmbrCentral::ShapeComponentNotificationsBus::Handler , private LmbrCentral::ShapeComponentRequestsBus::Handler , private ReferenceShapeRequestBus::Handler { public: template friend class LmbrCentral::EditorWrappedComponentBase; AZ_COMPONENT(ReferenceShapeComponent, ReferenceShapeComponentTypeId); static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services); static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services); static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services); static void Reflect(AZ::ReflectContext* context); ReferenceShapeComponent(const ReferenceShapeConfig& configuration); ReferenceShapeComponent() = default; ~ReferenceShapeComponent() = default; ////////////////////////////////////////////////////////////////////////// // AZ::Component interface implementation void Activate() override; void Deactivate() override; bool ReadInConfig(const AZ::ComponentConfig* baseConfig) override; bool WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const override; //////////////////////////////////////////////////////////////////////// // EntityEvents void OnEntityActivated(const AZ::EntityId& entityId) override; void OnEntityDeactivated(const AZ::EntityId& entityId) override; ////////////////////////////////////////////////////////////////////////// // TransformNotificationBus void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override; //////////////////////////////////////////////////////////////////////// // LmbrCentral::ShapeComponentNotificationsBus void OnShapeChanged(LmbrCentral::ShapeComponentNotifications::ShapeChangeReasons reasons) override; ////////////////////////////////////////////////////////////////////////// // ShapeComponentRequestsBus AZ::Crc32 GetShapeType() override; AZ::Aabb GetEncompassingAabb() override; void GetTransformAndLocalBounds(AZ::Transform& transform, AZ::Aabb& bounds) override; bool IsPointInside(const AZ::Vector3& point) override; float DistanceFromPoint(const AZ::Vector3& point) override; float DistanceSquaredFromPoint(const AZ::Vector3& point) override; AZ::Vector3 GenerateRandomPointInside(AZ::RandomDistributionType randomDistribution) override; bool IntersectRay(const AZ::Vector3& src, const AZ::Vector3& dir, AZ::VectorFloat& distance) override; protected: ////////////////////////////////////////////////////////////////////////// // ReferenceShapeRequestsBus AZ::EntityId GetShapeEntityId() const override; void SetShapeEntityId(AZ::EntityId entityId) override; private: ReferenceShapeConfig m_configuration; bool m_isRequestInProgress = false; //prevent recursion in case user attaches cyclic dependences bool AllowRequest() const; void SetupDependencies(); }; }