You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Gems/Vegetation/Code/Source/Components/ReferenceShapeComponent.h

104 lines
4.3 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/Component/Component.h>
#include <AzCore/Component/EntityBus.h>
#include <AzCore/Component/TransformBus.h>
#include <LmbrCentral/Shape/ShapeComponentBus.h>
#include <Vegetation/Ebuses/ReferenceShapeRequestBus.h>
namespace LmbrCentral
{
template<typename, typename>
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<typename, typename> 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, float& 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();
};
}