Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Lidar intensity data #33

Merged
merged 11 commits into from
Aug 7, 2024
18 changes: 17 additions & 1 deletion Code/Include/RGL/RGLBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <AzCore/Component/EntityId.h>
#include <AzCore/EBus/EBus.h>
#include <AzCore/Interface/Interface.h>
#include <SceneConfigurationComponent.h>
#include <RGL/SceneConfiguration.h>

namespace RGL
{
Expand Down Expand Up @@ -52,4 +52,20 @@ namespace RGL

using RGLRequestBus = AZ::EBus<RGLRequests, RGLBusTraits>;
using RGLInterface = AZ::Interface<RGLRequests>;

class RGLNotifications : public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////

virtual void OnSceneConfigurationSet(const SceneConfiguration& config)
{
}
//////////////////////////////////////////////////////////////////////////
};
using RGLNotificationBus = AZ::EBus<RGLNotifications>;
} // namespace RGL
44 changes: 44 additions & 0 deletions Code/Include/RGL/SceneConfiguration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright 2024, Robotec.ai sp. z o.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <Atom/RPI.Reflect/Image/StreamingImageAsset.h>
#include <AzCore/Asset/AssetCommon.h>

namespace RGL
{
//! Structure used to describe global terrain intensity configuration.
struct TerrainIntensityConfiguration
{
AZ_TYPE_INFO(TerrainIntensityConfiguration, "{6cf06491-3d18-4aad-88f6-d1990d6f791f}");
static void Reflect(AZ::ReflectContext* context);

AZ::Data::Asset<AZ::RPI::StreamingImageAsset> m_colorImageAsset{ AZ::Data::AssetLoadBehavior::QueueLoad };
AZ::u8 m_defaultValue{ 0U };
bool m_isTiled{ true };
};

//! Structure used to describe all global scene parameters.
struct SceneConfiguration
{
AZ_TYPE_INFO(SceneConfiguration, "{7e55de90-e26c-4567-9e06-822c6ce62b9c}");
static void Reflect(AZ::ReflectContext* context);

TerrainIntensityConfiguration m_terrainIntensityConfig;
// clang-format off
bool m_isSkinnedMeshUpdateEnabled{ true }; //!< If set to true, all skinned meshes will be updated. Otherwise they will remain unchanged.
// clang-format on
};
} // namespace RGL
49 changes: 20 additions & 29 deletions Code/Source/Entity/ActorEntityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
* limitations under the License.
*/

#include <Entity/ActorEntityManager.h>

#include <AzCore/std/string/string.h>
#include <EMotionFX/Source/ActorInstance.h>
#include <EMotionFX/Source/Mesh.h>
#include <EMotionFX/Source/Node.h>
#include <EMotionFX/Source/SubMesh.h>
#include <EMotionFX/Source/TransformData.h>
#include <Entity/ActorEntityManager.h>
#include <RGL/RGLBus.h>
#include <Utilities/RGLUtils.h>
#include <Wrappers/RglEntity.h>
#include <Wrappers/RglMesh.h>
#include <rgl/api/core.h>
#include <RGL/RGLBus.h>

namespace RGL
{
Expand All @@ -32,14 +35,6 @@ namespace RGL
EMotionFX::Integration::ActorComponentNotificationBus::Handler::BusConnect(entityId);
}

ActorEntityManager::~ActorEntityManager()
{
for (MeshPair mesh : m_meshes)
{
RGL_CHECK(rgl_mesh_destroy(mesh.m_rglMesh));
}
}

void ActorEntityManager::Update()
{
if (RGLInterface::Get()->GetSceneConfiguration().m_isSkinnedMeshUpdateEnabled)
Expand All @@ -65,10 +60,11 @@ namespace RGL
continue;
}

rgl_mesh_t rglMesh;
if (rglMesh = EMotionFXMeshToRglMesh(*mesh))
Wrappers::RglMesh rglMesh = AZStd::move(EMotionFXMeshToRglMesh(*mesh));
if (rglMesh.IsValid())
{
m_meshes.push_back({ mesh, rglMesh });
m_emotionFxMeshes.emplace_back(mesh);
m_rglMeshes.emplace_back(AZStd::move(rglMesh));
}
else
{
Expand All @@ -81,14 +77,13 @@ namespace RGL
}
}

m_entities.reserve(m_meshes.size());
for (MeshPair& mesh : m_meshes)
m_entities.reserve(m_emotionFxMeshes.size());
for (const Wrappers::RglMesh& rglMesh : m_rglMeshes)
{
rgl_entity_t entity = nullptr;
Utils::SafeRglEntityCreate(entity, mesh.m_rglMesh);
if (entity)
Wrappers::RglEntity entity(rglMesh);
if (entity.IsValid())
{
m_entities.emplace_back(entity);
m_entities.emplace_back(AZStd::move(entity));
}
else
{
Expand All @@ -108,10 +103,10 @@ namespace RGL
{
m_actorInstance->UpdateMeshDeformers(0.0f);

for (MeshPair& mesh : m_meshes)
for (size_t i = 0; i < m_emotionFxMeshes.size(); ++i)
{
UpdateVertexPositions(*mesh.m_eMotionMesh);
RGL_CHECK(rgl_mesh_update_vertices(mesh.m_rglMesh, m_positions.data(), m_positions.size()));
UpdateVertexPositions(*m_emotionFxMeshes[i]);
m_rglMeshes[i].UpdateVertices(m_positions.data(), m_positions.size());
}
}

Expand Down Expand Up @@ -162,14 +157,10 @@ namespace RGL
return rglIndices;
}

rgl_mesh_t ActorEntityManager::EMotionFXMeshToRglMesh(const EMotionFX::Mesh& mesh)
Wrappers::RglMesh ActorEntityManager::EMotionFXMeshToRglMesh(const EMotionFX::Mesh& mesh)
{
UpdateVertexPositions(mesh);
const AZStd::vector<rgl_vec3i> RglIndices = CollectIndexData(mesh);

rgl_mesh_t rglMesh = nullptr;
Utils::SafeRglMeshCreate(rglMesh, m_positions.data(), m_positions.size(), RglIndices.data(), RglIndices.size());

return rglMesh;
return { m_positions.data(), m_positions.size(), RglIndices.data(), RglIndices.size() };
}
} // namespace RGL
} // namespace RGL
17 changes: 7 additions & 10 deletions Code/Source/Entity/ActorEntityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <Entity/EntityManager.h>
#include <Integration/ActorComponentBus.h>
#include <rgl/api/core.h>
#include <AzCore/std/containers/vector.h>
#include <Wrappers/RglMesh.h>

namespace EMotionFX
{
Expand All @@ -36,7 +38,7 @@ namespace RGL
ActorEntityManager(ActorEntityManager&& other) = delete;
ActorEntityManager& operator=(ActorEntityManager&& rhs) = delete;
ActorEntityManager& operator=(const ActorEntityManager&) = delete;
~ActorEntityManager();
~ActorEntityManager() = default;

void Update() override;

Expand All @@ -45,21 +47,16 @@ namespace RGL
void OnActorInstanceCreated(EMotionFX::ActorInstance* actorInstance) override;

private:
struct MeshPair
{
EMotionFX::Mesh* m_eMotionMesh; // might need to change (depends on its lifetime)
rgl_mesh_t m_rglMesh;
};

EMotionFX::ActorInstance* m_actorInstance = nullptr;
// We do not use the MeshLibrary since the actor mesh is
// We do not use the ModelLibrary since the actor mesh is
// skinned and the mesh sharing would not be useful.
AZStd::vector<MeshPair> m_meshes;
AZStd::vector<EMotionFX::Mesh*> m_emotionFxMeshes;
AZStd::vector<Wrappers::RglMesh> m_rglMeshes;
AZStd::vector<rgl_vec3f> m_positions;

void UpdateMeshVertices();
void UpdateVertexPositions(const EMotionFX::Mesh& mesh);
AZStd::vector<rgl_vec3i> CollectIndexData(const EMotionFX::Mesh& mesh);
Mesh* EMotionFXMeshToRglMesh(const EMotionFX::Mesh& mesh);
Wrappers::RglMesh EMotionFXMeshToRglMesh(const EMotionFX::Mesh& mesh);
};
} // namespace RGL
15 changes: 7 additions & 8 deletions Code/Source/Entity/EntityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include <Entity/EntityManager.h>
#include <LmbrCentral/Scripting/TagComponentBus.h>
#include <Utilities/RGLUtils.h>

namespace RGL
Expand All @@ -27,11 +28,6 @@ namespace RGL
EntityManager::~EntityManager()
{
AZ::EntityBus::Handler::BusDisconnect();

for (rgl_entity_t entity : m_entities)
{
RGL_CHECK(rgl_entity_destroy(entity));
}
}

void EntityManager::Update()
Expand All @@ -54,7 +50,8 @@ namespace RGL

//// Non-uniform scale
// Register non-uniform scale changed event handler
AZ::NonUniformScaleRequestBus::Event(entityId, &AZ::NonUniformScaleRequests::RegisterScaleChangedEvent, m_nonUniformScaleChangedHandler);
AZ::NonUniformScaleRequestBus::Event(
entityId, &AZ::NonUniformScaleRequests::RegisterScaleChangedEvent, m_nonUniformScaleChangedHandler);
// Get current non-uniform scale (if there is no non-uniform scale added, the value won't be changed (nullopt))
AZ::NonUniformScaleRequestBus::EventResult(m_nonUniformScale, entityId, &AZ::NonUniformScaleRequests::GetScale);

Expand All @@ -80,11 +77,13 @@ namespace RGL
{
transform3x4f *= AZ::Matrix3x4::CreateScale(m_nonUniformScale.value());
}

const rgl_mat3x4f entityPoseRgl = Utils::RglMat3x4FromAzMatrix3x4(transform3x4f);
for (rgl_entity_t entity : m_entities)
for (Wrappers::RglEntity& entity : m_entities)
{
RGL_CHECK(rgl_entity_set_pose(entity, &entityPoseRgl));
entity.SetPose(entityPoseRgl);
}

m_isPoseUpdateNeeded = false;
}
} // namespace RGL
8 changes: 5 additions & 3 deletions Code/Source/Entity/EntityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <AzCore/Component/TransformBus.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/optional.h>
#include <Wrappers/RglEntity.h>
#include <rgl/api/core.h>

namespace RGL
Expand All @@ -37,7 +38,6 @@ namespace RGL
virtual void Update();

protected:

// AZ::EntityBus::Handler implementation overrides
void OnEntityActivated(const AZ::EntityId& entityId) override;
void OnEntityDeactivated(const AZ::EntityId& entityId) override;
Expand All @@ -46,10 +46,11 @@ namespace RGL
virtual void UpdatePose();

AZ::EntityId m_entityId;
AZStd::vector<rgl_entity_t> m_entities;
AZStd::vector<Wrappers::RglEntity> m_entities;
bool m_isPoseUpdateNeeded{ false };
private:

private:
// clang-format off
AZ::TransformChangedEvent::Handler m_transformChangedHandler{[this](
[[maybe_unused]] const AZ::Transform& local, const AZ::Transform& world)
{
Expand All @@ -63,6 +64,7 @@ namespace RGL
m_nonUniformScale = scale;
m_isPoseUpdateNeeded = true;
}};
// clang-format on

AZ::Transform m_worldTm{ AZ::Transform::CreateIdentity() };
AZStd::optional<AZ::Vector3> m_nonUniformScale{ AZStd::nullopt };
Expand Down
Loading