Integrating github/staging through commit ab87ed9
This commit is contained in:
+1
-5
@@ -98,10 +98,7 @@ namespace AZ
|
||||
->Attribute(AZ::Edit::Attributes::DefaultAsset, &EditorMaterialComponentSlot::GetDefaultAssetId)
|
||||
->Attribute(AZ::Edit::Attributes::NameLabelOverride, &EditorMaterialComponentSlot::GetLabel)
|
||||
->Attribute(AZ::Edit::Attributes::ShowProductAssetFileName, true)
|
||||
->Attribute("ShowThumbnail", true)
|
||||
->Attribute("EditButton", ":/Cards/img/UI20/Cards/menu_ico.svg")
|
||||
->Attribute("EditDescription", "")
|
||||
->Attribute("EditCallback", &EditorMaterialComponentSlot::OpenPopupMenu)
|
||||
->Attribute("ThumbnailWithDropDown", &EditorMaterialComponentSlot::OpenPopupMenu)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -109,7 +106,6 @@ namespace AZ
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<EditorMaterialComponentSlot>("EditorMaterialComponentSlot")
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::Preview)
|
||||
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
|
||||
->Attribute(AZ::Script::Attributes::Category, "Editor")
|
||||
->Attribute(AZ::Script::Attributes::Module, "editor")
|
||||
|
||||
@@ -75,7 +75,6 @@ namespace AZ
|
||||
if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->Class<MaterialComponentConfig>("MaterialComponentConfig")
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::Preview)
|
||||
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
|
||||
->Attribute(AZ::Script::Attributes::Category, "render")
|
||||
->Attribute(AZ::Script::Attributes::Module, "render")
|
||||
|
||||
-1
@@ -33,7 +33,6 @@ namespace AZ
|
||||
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
|
||||
{
|
||||
behaviorContext->EBus<MaterialComponentRequestBus>("MaterialComponentRequestBus")
|
||||
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::Preview)
|
||||
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
|
||||
->Attribute(AZ::Script::Attributes::Category, "render")
|
||||
->Attribute(AZ::Script::Attributes::Module, "render")
|
||||
|
||||
@@ -137,7 +137,9 @@ namespace AZ
|
||||
AZ::Transform transform = AZ::Transform::CreateIdentity();
|
||||
AZ::TransformBus::EventResult(transform, GetEntityId(), &AZ::TransformBus::Events::GetWorldTM);
|
||||
|
||||
return m_controller.GetModel()->RayIntersection(transform, src, dir, distance);
|
||||
AZ::Vector3 ignoreNormal;
|
||||
|
||||
return m_controller.GetModel()->RayIntersection(transform, src, dir, distance, ignoreNormal);
|
||||
}
|
||||
|
||||
bool EditorMeshComponent::SupportsEditorRayIntersect()
|
||||
@@ -197,7 +199,6 @@ namespace AZ
|
||||
&AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay,
|
||||
AzToolsFramework::Refresh_EntireTree);
|
||||
}
|
||||
|
||||
AZ::u32 EditorMeshComponent::OnConfigurationChanged()
|
||||
{
|
||||
// temp variable is needed to hold reference to m_modelAsset while it's being loaded.
|
||||
|
||||
@@ -87,6 +87,12 @@ namespace AZ
|
||||
return values;
|
||||
}
|
||||
|
||||
MeshComponentController::~MeshComponentController()
|
||||
{
|
||||
// Release memory, disconnect from buses in the right order and broadcast events so that other components are aware.
|
||||
Deactivate();
|
||||
}
|
||||
|
||||
void MeshComponentController::Reflect(ReflectContext* context)
|
||||
{
|
||||
MeshComponentConfig::Reflect(context);
|
||||
@@ -130,11 +136,13 @@ namespace AZ
|
||||
void MeshComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
|
||||
{
|
||||
provided.push_back(AZ_CRC("MaterialReceiverService", 0x0d1a6a74));
|
||||
provided.push_back(AZ_CRC("MeshService", 0x71d8a455));
|
||||
}
|
||||
|
||||
void MeshComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
incompatible.push_back(AZ_CRC("MaterialReceiverService", 0x0d1a6a74));
|
||||
incompatible.push_back(AZ_CRC("MeshService", 0x71d8a455));
|
||||
}
|
||||
|
||||
// [GFX TODO] [ATOM-13339] Remove the ModelAsset id fix up function in MeshComponentController
|
||||
@@ -157,7 +165,7 @@ namespace AZ
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Assert(false, "Failed to find asset id for [%s] ", modelAsset.GetHint().c_str());
|
||||
AZ_Error("MeshComponentController", false, "Failed to find asset id for [%s] ", modelAsset.GetHint().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,14 +200,15 @@ namespace AZ
|
||||
|
||||
void MeshComponentController::Deactivate()
|
||||
{
|
||||
// Buses must be disconnected after unregistering the model, otherwise they can't deliver the events during the process.
|
||||
UnregisterModel();
|
||||
|
||||
AzFramework::BoundsRequestBus::Handler::BusDisconnect();
|
||||
MeshComponentRequestBus::Handler::BusDisconnect();
|
||||
TransformNotificationBus::Handler::BusDisconnect();
|
||||
MaterialReceiverRequestBus::Handler::BusDisconnect();
|
||||
MaterialComponentNotificationBus::Handler::BusDisconnect();
|
||||
|
||||
UnregisterModel();
|
||||
|
||||
m_meshFeatureProcessor = nullptr;
|
||||
m_transformInterface = nullptr;
|
||||
m_entityId = AZ::EntityId(AZ::EntityId::InvalidEntityId);
|
||||
@@ -283,6 +292,7 @@ namespace AZ
|
||||
{
|
||||
if (m_meshFeatureProcessor)
|
||||
{
|
||||
MeshComponentNotificationBus::Event(m_entityId, &MeshComponentNotificationBus::Events::OnModelPreDestroy);
|
||||
m_meshFeatureProcessor->ReleaseMesh(m_meshHandle);
|
||||
}
|
||||
}
|
||||
@@ -320,7 +330,7 @@ namespace AZ
|
||||
|
||||
const Data::Asset<RPI::ModelAsset>& MeshComponentController::GetModelAsset() const
|
||||
{
|
||||
return m_configuration.m_modelAsset;
|
||||
return GetModel() ? GetModel()->GetModelAsset() : m_configuration.m_modelAsset;
|
||||
}
|
||||
|
||||
Data::AssetId MeshComponentController::GetModelAssetId() const
|
||||
|
||||
@@ -66,6 +66,8 @@ namespace AZ
|
||||
AZ_CLASS_ALLOCATOR(MeshComponentController, AZ::SystemAllocator, 0);
|
||||
AZ_RTTI(AZ::Render::MeshComponentController, "{D0F35FAC-4194-4C89-9487-D000DDB8B272}");
|
||||
|
||||
~MeshComponentController();
|
||||
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
|
||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <SkyBox/HDRiSkyboxComponent.h>
|
||||
#include <SkyBox/PhysicalSkyComponent.h>
|
||||
#include <Scripting/EntityReferenceComponent.h>
|
||||
#include <SurfaceData/SurfaceDataMeshComponent.h>
|
||||
|
||||
#ifdef ATOMLYINTEGRATION_FEATURE_COMMON_EDITOR
|
||||
#include <EditorCommonFeaturesSystemComponent.h>
|
||||
@@ -71,6 +72,7 @@
|
||||
#include <SkyBox/EditorHDRiSkyboxComponent.h>
|
||||
#include <SkyBox/EditorPhysicalSkyComponent.h>
|
||||
#include <Scripting/EditorEntityReferenceComponent.h>
|
||||
#include <SurfaceData/EditorSurfaceDataMeshComponent.h>
|
||||
#endif
|
||||
|
||||
namespace AZ
|
||||
@@ -114,6 +116,7 @@ namespace AZ
|
||||
GradientWeightModifierComponent::CreateDescriptor(),
|
||||
DiffuseProbeGridComponent::CreateDescriptor(),
|
||||
DeferredFogComponent::CreateDescriptor(),
|
||||
SurfaceData::SurfaceDataMeshComponent::CreateDescriptor(),
|
||||
|
||||
#ifdef ATOMLYINTEGRATION_FEATURE_COMMON_EDITOR
|
||||
EditorAreaLightComponent::CreateDescriptor(),
|
||||
@@ -145,6 +148,7 @@ namespace AZ
|
||||
EditorGradientWeightModifierComponent::CreateDescriptor(),
|
||||
EditorDiffuseProbeGridComponent::CreateDescriptor(),
|
||||
EditorDeferredFogComponent::CreateDescriptor(),
|
||||
SurfaceData::EditorSurfaceDataMeshComponent::CreateDescriptor(),
|
||||
#endif
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
#include <AzFramework/Components/ComponentAdapter.h>
|
||||
#include <AtomLyIntegration/CommonFeatures/PostProcess/GradientWeightModifier/GradientWeightModifierComponentConstants.h>
|
||||
#include <AtomLyIntegration/CommonFeatures/PostProcess/GradientWeightModifier/GradientWeightModifierComponentConfig.h>
|
||||
#include <PostProcess/GradientWeightModifier/GradientWeightModifierComponentController.h>
|
||||
#include <PostProcess/GradientWeightModifier/GradientWeightModifierController.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <PostProcess/GradientWeightModifier/GradientWeightModifierComponentController.h>
|
||||
#include <PostProcess/GradientWeightModifier/GradientWeightModifierController.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "EditorSurfaceDataMeshComponent.h"
|
||||
#include <AzCore/Serialization/Utils.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
|
||||
#include <LmbrCentral/Dependency/DependencyNotificationBus.h>
|
||||
|
||||
namespace SurfaceData
|
||||
{
|
||||
void EditorSurfaceDataMeshComponent::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
BaseClassType::ReflectSubClass<EditorSurfaceDataMeshComponent, BaseClassType>(context, 2, &LmbrCentral::EditorWrappedComponentBaseVersionConverter<typename BaseClassType::WrappedComponentType, typename BaseClassType::WrappedConfigType,2>);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 <AzCore/Module/Module.h>
|
||||
#include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
|
||||
#include <AzToolsFramework/ToolsComponents/EditorVisibilityBus.h>
|
||||
#include <SurfaceData/SurfaceDataMeshComponent.h>
|
||||
#include <LmbrCentral/Component/EditorWrappedComponentBase.h>
|
||||
|
||||
namespace SurfaceData
|
||||
{
|
||||
class EditorSurfaceDataMeshComponent
|
||||
: public LmbrCentral::EditorWrappedComponentBase<SurfaceDataMeshComponent, SurfaceDataMeshConfig>
|
||||
{
|
||||
public:
|
||||
using BaseClassType = LmbrCentral::EditorWrappedComponentBase<SurfaceDataMeshComponent, SurfaceDataMeshConfig>;
|
||||
AZ_EDITOR_COMPONENT(EditorSurfaceDataMeshComponent, "{4D73E979-5463-4B75-AE46-70B1E52CBF43}", BaseClassType);
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
|
||||
static constexpr const char* const s_categoryName = "Surface Data";
|
||||
static constexpr const char* const s_componentName = "Mesh Surface Tag Emitter";
|
||||
static constexpr const char* const s_componentDescription = "Enables a static mesh to emit surface tags";
|
||||
static constexpr const char* const s_icon = "Editor/Icons/Components/SurfaceData.svg";
|
||||
static constexpr const char* const s_viewportIcon = "Editor/Icons/Components/Viewport/SurfaceData.png";
|
||||
static constexpr const char* const s_helpUrl = "https://docs.aws.amazon.com/console/lumberyard/surfacedata/mesh-surface-tag-emitter";
|
||||
};
|
||||
}
|
||||
+288
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||
* its licensor's.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "SurfaceDataMeshComponent.h"
|
||||
|
||||
#include <AzCore/Debug/Profiler.h>
|
||||
#include <AzCore/Serialization/EditContext.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <LmbrCentral/Rendering/MeshAsset.h>
|
||||
#include <Atom/RPI.Reflect/Model/ModelAssetCreator.h>
|
||||
|
||||
#include <SurfaceData/SurfaceDataSystemRequestBus.h>
|
||||
#include <SurfaceData/Utility/SurfaceDataUtility.h>
|
||||
|
||||
#include <MathConversion.h>
|
||||
|
||||
namespace SurfaceData
|
||||
{
|
||||
void SurfaceDataMeshConfig::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
if (serialize)
|
||||
{
|
||||
serialize->Class<SurfaceDataMeshConfig, AZ::ComponentConfig>()
|
||||
->Version(0)
|
||||
->Field("SurfaceTags", &SurfaceDataMeshConfig::m_tags)
|
||||
;
|
||||
|
||||
AZ::EditContext* edit = serialize->GetEditContext();
|
||||
if (edit)
|
||||
{
|
||||
edit->Class<SurfaceDataMeshConfig>(
|
||||
"Mesh Surface Tag Emitter", "")
|
||||
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
||||
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
|
||||
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
||||
->DataElement(0, &SurfaceDataMeshConfig::m_tags, "Generated Tags", "")
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services)
|
||||
{
|
||||
services.push_back(AZ_CRC("SurfaceDataProviderService", 0xfe9fb95e));
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services)
|
||||
{
|
||||
services.push_back(AZ_CRC("SurfaceDataProviderService", 0xfe9fb95e));
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services)
|
||||
{
|
||||
services.push_back(AZ_CRC("MeshService", 0x71d8a455));
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
SurfaceDataMeshConfig::Reflect(context);
|
||||
|
||||
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
if (serialize)
|
||||
{
|
||||
serialize->Class<SurfaceDataMeshComponent, AZ::Component>()
|
||||
->Version(0)
|
||||
->Field("Configuration", &SurfaceDataMeshComponent::m_configuration)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
SurfaceDataMeshComponent::SurfaceDataMeshComponent(const SurfaceDataMeshConfig& configuration)
|
||||
: m_configuration(configuration)
|
||||
{
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::Activate()
|
||||
{
|
||||
AZ::TransformNotificationBus::Handler::BusConnect(GetEntityId());
|
||||
AZ::Render::MeshComponentNotificationBus::Handler::BusConnect(GetEntityId());
|
||||
|
||||
m_providerHandle = InvalidSurfaceDataRegistryHandle;
|
||||
m_refresh = false;
|
||||
|
||||
// Update the cached mesh data and bounds, then register the surface data provider
|
||||
UpdateMeshData();
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::Deactivate()
|
||||
{
|
||||
if (m_providerHandle != InvalidSurfaceDataRegistryHandle)
|
||||
{
|
||||
SurfaceDataSystemRequestBus::Broadcast(&SurfaceDataSystemRequestBus::Events::UnregisterSurfaceDataProvider, m_providerHandle);
|
||||
m_providerHandle = InvalidSurfaceDataRegistryHandle;
|
||||
}
|
||||
|
||||
SurfaceDataProviderRequestBus::Handler::BusDisconnect();
|
||||
AZ::TickBus::Handler::BusDisconnect();
|
||||
AZ::TransformNotificationBus::Handler::BusDisconnect();
|
||||
AZ::Render::MeshComponentNotificationBus::Handler::BusDisconnect();
|
||||
m_refresh = false;
|
||||
|
||||
// Clear the cached mesh data
|
||||
{
|
||||
AZStd::lock_guard<decltype(m_cacheMutex)> lock(m_cacheMutex);
|
||||
m_meshAssetData = {};
|
||||
m_meshBounds = AZ::Aabb::CreateNull();
|
||||
m_meshWorldTM = AZ::Transform::CreateIdentity();
|
||||
m_meshWorldTMInverse = AZ::Transform::CreateIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
bool SurfaceDataMeshComponent::ReadInConfig(const AZ::ComponentConfig* baseConfig)
|
||||
{
|
||||
if (auto config = azrtti_cast<const SurfaceDataMeshConfig*>(baseConfig))
|
||||
{
|
||||
m_configuration = *config;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SurfaceDataMeshComponent::WriteOutConfig(AZ::ComponentConfig* outBaseConfig) const
|
||||
{
|
||||
if (auto config = azrtti_cast<SurfaceDataMeshConfig*>(outBaseConfig))
|
||||
{
|
||||
*config = m_configuration;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SurfaceDataMeshComponent::DoRayTrace(const AZ::Vector3& inPosition, AZ::Vector3& outPosition, AZ::Vector3& outNormal) const
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Entity);
|
||||
|
||||
AZStd::lock_guard<decltype(m_cacheMutex)> lock(m_cacheMutex);
|
||||
|
||||
// test AABB as first pass to claim the point
|
||||
const AZ::Vector3 testPosition = AZ::Vector3(
|
||||
inPosition.GetX(),
|
||||
inPosition.GetY(),
|
||||
(m_meshBounds.GetMax().GetZ() + m_meshBounds.GetMin().GetZ()) * 0.5f);
|
||||
|
||||
if (!m_meshBounds.Contains(testPosition))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::RPI::ModelAsset* mesh = m_meshAssetData.GetAs<AZ::RPI::ModelAsset>();
|
||||
if (!mesh)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const AZ::Vector3 rayOrigin = AZ::Vector3(inPosition.GetX(), inPosition.GetY(), m_meshBounds.GetMax().GetZ() + s_rayAABBHeightPadding);
|
||||
const AZ::Vector3 rayDirection = -AZ::Vector3::CreateAxisZ();
|
||||
return GetMeshRayIntersection(*mesh, m_meshWorldTM, m_meshWorldTMInverse, rayOrigin, rayDirection, outPosition, outNormal);
|
||||
}
|
||||
|
||||
|
||||
void SurfaceDataMeshComponent::GetSurfacePoints(const AZ::Vector3& inPosition, SurfacePointList& surfacePointList) const
|
||||
{
|
||||
AZ::Vector3 hitPosition;
|
||||
AZ::Vector3 hitNormal;
|
||||
if (DoRayTrace(inPosition, hitPosition, hitNormal))
|
||||
{
|
||||
SurfacePoint point;
|
||||
point.m_entityId = GetEntityId();
|
||||
point.m_position = hitPosition;
|
||||
point.m_normal = hitNormal;
|
||||
AddMaxValueForMasks(point.m_masks, m_configuration.m_tags, 1.0f);
|
||||
surfacePointList.push_back(point);
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Aabb SurfaceDataMeshComponent::GetSurfaceAabb() const
|
||||
{
|
||||
return m_meshBounds;
|
||||
}
|
||||
|
||||
SurfaceTagVector SurfaceDataMeshComponent::GetSurfaceTags() const
|
||||
{
|
||||
return m_configuration.m_tags;
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::OnCompositionChanged()
|
||||
{
|
||||
if (!m_refresh)
|
||||
{
|
||||
m_refresh = true;
|
||||
AZ::TickBus::Handler::BusConnect();
|
||||
}
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::OnModelReady([[maybe_unused]] const AZ::Data::Asset<AZ::RPI::ModelAsset>& modelAsset, [[maybe_unused]] const AZ::Data::Instance<AZ::RPI::Model>& model)
|
||||
{
|
||||
OnCompositionChanged();
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::OnTransformChanged(const AZ::Transform & local, const AZ::Transform & world)
|
||||
{
|
||||
(void)local;
|
||||
(void)world;
|
||||
OnCompositionChanged();
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::OnTick(float /*deltaTime*/, AZ::ScriptTimePoint /*time*/)
|
||||
{
|
||||
if (m_refresh)
|
||||
{
|
||||
UpdateMeshData();
|
||||
m_refresh = false;
|
||||
}
|
||||
AZ::TickBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
void SurfaceDataMeshComponent::UpdateMeshData()
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Entity);
|
||||
|
||||
bool meshValidBeforeUpdate = false;
|
||||
bool meshValidAfterUpdate = false;
|
||||
|
||||
{
|
||||
AZStd::lock_guard<decltype(m_cacheMutex)> lock(m_cacheMutex);
|
||||
|
||||
meshValidBeforeUpdate = (m_meshAssetData.GetAs<AZ::RPI::ModelAsset>() != nullptr) && (m_meshBounds.IsValid());
|
||||
|
||||
m_meshAssetData = {};
|
||||
AZ::Render::MeshComponentRequestBus::EventResult(m_meshAssetData, GetEntityId(), &AZ::Render::MeshComponentRequestBus::Events::GetModelAsset);
|
||||
|
||||
m_meshBounds = AZ::Aabb::CreateNull();
|
||||
AZ::Render::MeshComponentRequestBus::EventResult(m_meshBounds, GetEntityId(), &AZ::Render::MeshComponentRequestBus::Events::GetWorldBounds);
|
||||
|
||||
m_meshWorldTM = AZ::Transform::CreateIdentity();
|
||||
AZ::TransformBus::EventResult(m_meshWorldTM, GetEntityId(), &AZ::TransformBus::Events::GetWorldTM);
|
||||
m_meshWorldTMInverse = m_meshWorldTM.GetInverse();
|
||||
|
||||
meshValidAfterUpdate = (m_meshAssetData.GetAs<AZ::RPI::ModelAsset>() != nullptr) && (m_meshBounds.IsValid());
|
||||
}
|
||||
|
||||
SurfaceDataRegistryEntry registryEntry;
|
||||
registryEntry.m_entityId = GetEntityId();
|
||||
registryEntry.m_bounds = GetSurfaceAabb();
|
||||
registryEntry.m_tags = GetSurfaceTags();
|
||||
|
||||
if (!meshValidBeforeUpdate && !meshValidAfterUpdate)
|
||||
{
|
||||
// We didn't have a valid mesh asset before or after running this, so do nothing.
|
||||
}
|
||||
else if (!meshValidBeforeUpdate && meshValidAfterUpdate)
|
||||
{
|
||||
// Our mesh has become valid, so register as a provider and save off the provider handle
|
||||
AZ_Assert((m_providerHandle == InvalidSurfaceDataRegistryHandle), "Surface data handle is initialized before our mesh became active");
|
||||
AZ_Assert(m_meshBounds.IsValid(), "Mesh Geometry isn't correctly initialized.");
|
||||
SurfaceDataSystemRequestBus::BroadcastResult(m_providerHandle, &SurfaceDataSystemRequestBus::Events::RegisterSurfaceDataProvider, registryEntry);
|
||||
|
||||
// Start listening for surface data events
|
||||
AZ_Assert((m_providerHandle != InvalidSurfaceDataRegistryHandle), "Invalid surface data handle");
|
||||
SurfaceDataProviderRequestBus::Handler::BusConnect(m_providerHandle);
|
||||
}
|
||||
else if (meshValidBeforeUpdate && !meshValidAfterUpdate)
|
||||
{
|
||||
// Our mesh has stopped being valid, so unregister and stop listening for surface data events
|
||||
AZ_Assert((m_providerHandle != InvalidSurfaceDataRegistryHandle), "Invalid surface data handle");
|
||||
SurfaceDataSystemRequestBus::Broadcast(&SurfaceDataSystemRequestBus::Events::UnregisterSurfaceDataProvider, m_providerHandle);
|
||||
m_providerHandle = InvalidSurfaceDataRegistryHandle;
|
||||
|
||||
SurfaceDataProviderRequestBus::Handler::BusDisconnect();
|
||||
}
|
||||
else if (meshValidBeforeUpdate && meshValidAfterUpdate)
|
||||
{
|
||||
// Our mesh was valid before and after, it just changed in some way, so update our registry entry.
|
||||
AZ_Assert((m_providerHandle != InvalidSurfaceDataRegistryHandle), "Invalid surface data handle");
|
||||
SurfaceDataSystemRequestBus::Broadcast(&SurfaceDataSystemRequestBus::Events::UpdateSurfaceDataProvider, m_providerHandle, registryEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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 <AzCore/Asset/AssetCommon.h>
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzCore/Component/TickBus.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/std/containers/unordered_map.h>
|
||||
#include <AtomLyIntegration/CommonFeatures/Mesh/MeshComponentBus.h>
|
||||
#include <SurfaceData/SurfaceDataProviderRequestBus.h>
|
||||
#include <SurfaceData/SurfaceDataTypes.h>
|
||||
|
||||
namespace LmbrCentral
|
||||
{
|
||||
template<typename, typename>
|
||||
class EditorWrappedComponentBase;
|
||||
}
|
||||
|
||||
namespace SurfaceData
|
||||
{
|
||||
constexpr float s_rayAABBHeightPadding = 0.1f;
|
||||
|
||||
class SurfaceDataMeshConfig
|
||||
: public AZ::ComponentConfig
|
||||
{
|
||||
public:
|
||||
AZ_CLASS_ALLOCATOR(SurfaceDataMeshConfig, AZ::SystemAllocator, 0);
|
||||
AZ_RTTI(SurfaceDataMeshConfig, "{764C602E-7CA8-4BCC-AB2D-3E46623B3A20}", AZ::ComponentConfig);
|
||||
static void Reflect(AZ::ReflectContext* context);
|
||||
SurfaceTagVector m_tags;
|
||||
};
|
||||
|
||||
class SurfaceDataMeshComponent
|
||||
: public AZ::Component
|
||||
, public AZ::TickBus::Handler
|
||||
, public AZ::TransformNotificationBus::Handler
|
||||
, public AZ::Render::MeshComponentNotificationBus::Handler
|
||||
, public SurfaceDataProviderRequestBus::Handler
|
||||
{
|
||||
public:
|
||||
template<typename, typename> friend class LmbrCentral::EditorWrappedComponentBase;
|
||||
AZ_COMPONENT(SurfaceDataMeshComponent, "{F8915F34-BE8B-40B4-B7E8-01EBF3DA1C95}");
|
||||
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);
|
||||
|
||||
SurfaceDataMeshComponent(const SurfaceDataMeshConfig& configuration);
|
||||
SurfaceDataMeshComponent() = default;
|
||||
~SurfaceDataMeshComponent() = 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;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// MeshComponentNotificationBus
|
||||
void OnModelReady(const AZ::Data::Asset<AZ::RPI::ModelAsset>& modelAsset, const AZ::Data::Instance<AZ::RPI::Model>& model) override;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// TransformNotificationBus
|
||||
void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// AZ::TickBus
|
||||
void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// SurfaceDataProviderRequestBus
|
||||
void GetSurfacePoints(const AZ::Vector3& inPosition, SurfacePointList& surfacePointList) const override;
|
||||
|
||||
private:
|
||||
bool DoRayTrace(const AZ::Vector3& inPosition, AZ::Vector3& outPosition, AZ::Vector3& outNormal) const;
|
||||
void UpdateMeshData();
|
||||
void OnCompositionChanged();
|
||||
|
||||
AZ::Aabb GetSurfaceAabb() const;
|
||||
SurfaceTagVector GetSurfaceTags() const;
|
||||
|
||||
SurfaceDataMeshConfig m_configuration;
|
||||
|
||||
SurfaceDataRegistryHandle m_providerHandle = InvalidSurfaceDataRegistryHandle;
|
||||
|
||||
// cached data
|
||||
AZStd::atomic_bool m_refresh{ false };
|
||||
mutable AZStd::recursive_mutex m_cacheMutex;
|
||||
AZ::Data::Asset<AZ::Data::AssetData> m_meshAssetData;
|
||||
AZ::Transform m_meshWorldTM = AZ::Transform::CreateIdentity();
|
||||
AZ::Transform m_meshWorldTMInverse = AZ::Transform::CreateIdentity();
|
||||
AZ::Aabb m_meshBounds = AZ::Aabb::CreateNull();
|
||||
};
|
||||
}
|
||||
+1
-1
@@ -35,7 +35,7 @@ namespace AZ
|
||||
//! ThumbnailRendererData encapsulates all data used by thumbnail renderer and caches assets
|
||||
struct ThumbnailRendererData final
|
||||
{
|
||||
static constexpr const char* LightingPresetPath = "lightingpresets/default.lightingpreset.azasset";
|
||||
static constexpr const char* LightingPresetPath = "lightingpresets/thumbnail.lightingpreset.azasset";
|
||||
static constexpr const char* DefaultModelPath = "materialeditor/viewportmodels/quadsphere.azmodel";
|
||||
static constexpr const char* DefaultMaterialPath = "materials/basic_grey.azmaterial";
|
||||
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ namespace AZ
|
||||
data->m_renderPipeline->SetDefaultView(data->m_view);
|
||||
|
||||
// Create lighting preset
|
||||
data->m_lightingPresetAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath<AZ::RPI::AnyAsset>(LightingPresetPath);
|
||||
data->m_lightingPresetAsset = AZ::RPI::AssetUtils::LoadAssetByProductPath<AZ::RPI::AnyAsset>(ThumbnailRendererData::LightingPresetPath);
|
||||
if (data->m_lightingPresetAsset.IsReady())
|
||||
{
|
||||
auto preset = data->m_lightingPresetAsset->GetDataAs<Render::LightingPreset>();
|
||||
|
||||
-1
@@ -31,7 +31,6 @@ namespace AZ
|
||||
void Start() override;
|
||||
|
||||
private:
|
||||
static constexpr const char* LightingPresetPath = "lightingpresets/default.lightingpreset.azasset";
|
||||
static constexpr float AspectRatio = 1.0f;
|
||||
static constexpr float NearDist = 0.1f;
|
||||
static constexpr float FarDist = 100.0f;
|
||||
|
||||
Reference in New Issue
Block a user