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/AtomLyIntegration/CommonFeatures/Code/Source/Thumbnails/Rendering/ThumbnailRendererSteps/FindThumbnailToRenderStep.cpp

84 lines
3.6 KiB
C++

/*
* 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 <Atom/RPI.Reflect/Material/MaterialAsset.h>
#include <Atom/RPI.Reflect/Model/ModelAsset.h>
#include <Thumbnails/ThumbnailUtils.h>
#include <Thumbnails/Rendering/ThumbnailRendererContext.h>
#include <Thumbnails/Rendering/ThumbnailRendererData.h>
#include <Thumbnails/Rendering/ThumbnailRendererSteps/FindThumbnailToRenderStep.h>
namespace AZ
{
namespace LyIntegration
{
namespace Thumbnails
{
FindThumbnailToRenderStep::FindThumbnailToRenderStep(ThumbnailRendererContext* context)
: ThumbnailRendererStep(context)
{
}
void FindThumbnailToRenderStep::Start()
{
TickBus::Handler::BusConnect();
}
void FindThumbnailToRenderStep::Stop()
{
TickBus::Handler::BusDisconnect();
}
void FindThumbnailToRenderStep::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] ScriptTimePoint time)
{
PickNextThumbnail();
}
void FindThumbnailToRenderStep::PickNextThumbnail()
{
if (!m_context->GetData()->m_thumbnailQueue.empty())
{
// pop the next thumbnailkey to be rendered from the queue
m_context->GetData()->m_thumbnailKeyRendered = m_context->GetData()->m_thumbnailQueue.front();
m_context->GetData()->m_thumbnailQueue.pop();
// Find whether thumbnailkey contains a material asset or set a default material
m_context->GetData()->m_materialAsset = m_context->GetData()->m_defaultMaterialAsset;
Data::AssetId materialAssetId = GetAssetId(m_context->GetData()->m_thumbnailKeyRendered, RPI::MaterialAsset::RTTI_Type());
if (materialAssetId.IsValid())
{
if (m_context->GetData()->m_assetsToLoad.emplace(materialAssetId).second)
{
m_context->GetData()->m_materialAsset.Create(materialAssetId);
m_context->GetData()->m_materialAsset.QueueLoad();
}
}
// Find whether thumbnailkey contains a model asset or set a default model
m_context->GetData()->m_modelAsset = m_context->GetData()->m_defaultModelAsset;
Data::AssetId modelAssetId = GetAssetId(m_context->GetData()->m_thumbnailKeyRendered, RPI::ModelAsset::RTTI_Type());
if (modelAssetId.IsValid())
{
if (m_context->GetData()->m_assetsToLoad.emplace(modelAssetId).second)
{
m_context->GetData()->m_modelAsset.Create(modelAssetId);
m_context->GetData()->m_modelAsset.QueueLoad();
}
}
m_context->SetStep(Step::WaitForAssetsToLoad);
}
}
} // namespace Thumbnails
} // namespace LyIntegration
} // namespace AZ