add icon to EditorNameComponent
This commit is contained in:
parent
fa4cc84a31
commit
bc18b5ef5d
|
|
@ -2,10 +2,19 @@
|
||||||
|
|
||||||
#include <NazaraEditor/Core/Config.hpp>
|
#include <NazaraEditor/Core/Config.hpp>
|
||||||
|
|
||||||
|
#include <Nazara/Core/Clock.hpp>
|
||||||
|
#include <NazaraUtils/Signal.hpp>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
class Billboard;
|
||||||
|
class NodeComponent;
|
||||||
|
class WorldInstance;
|
||||||
|
|
||||||
enum EditorEntityFlags : uint64_t
|
enum EditorEntityFlags : uint64_t
|
||||||
{
|
{
|
||||||
EditorEntityFlags_None = 0,
|
EditorEntityFlags_None = 0,
|
||||||
|
|
@ -24,15 +33,32 @@ namespace Nz
|
||||||
EditorNameComponent& operator=(const EditorNameComponent&) = delete;
|
EditorNameComponent& operator=(const EditorNameComponent&) = delete;
|
||||||
EditorNameComponent& operator=(EditorNameComponent&&) = default;
|
EditorNameComponent& operator=(EditorNameComponent&&) = default;
|
||||||
|
|
||||||
|
void Update(Time elapsedTime, NodeComponent& node);
|
||||||
|
|
||||||
void SetName(const std::string& name) { m_name = name; }
|
void SetName(const std::string& name) { m_name = name; }
|
||||||
const std::string& GetName() const { return m_name; }
|
const std::string& GetName() const { return m_name; }
|
||||||
|
|
||||||
|
void SetIcon(const std::filesystem::path& path);
|
||||||
|
|
||||||
void SetFlags(const uint64_t flags) { m_flags = flags; }
|
void SetFlags(const uint64_t flags) { m_flags = flags; }
|
||||||
uint64_t GetFlags() const { return m_flags; }
|
uint64_t GetFlags() const { return m_flags; }
|
||||||
|
|
||||||
|
NazaraSignal(OnIconChanged, EditorNameComponent*, const std::filesystem::path& );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
uint64_t m_flags;
|
uint64_t m_flags;
|
||||||
|
|
||||||
|
std::filesystem::path m_iconPath; // @TODO replace with asset
|
||||||
|
|
||||||
|
struct BillboardData
|
||||||
|
{
|
||||||
|
size_t index;
|
||||||
|
std::shared_ptr<Nz::WorldInstance> instance;
|
||||||
|
std::shared_ptr<Nz::Billboard> billboard;
|
||||||
|
};
|
||||||
|
std::optional<BillboardData> m_icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
#include <NazaraEditor/Core/Components/NameComponent.hpp>
|
||||||
|
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||||
|
|
||||||
|
#include <Nazara/Core/AppFilesystemComponent.hpp>
|
||||||
|
#include <Nazara/Graphics/Billboard.hpp>
|
||||||
|
#include <Nazara/Graphics/FramePipeline.hpp>
|
||||||
|
#include <Nazara/Graphics/MaterialInstance.hpp>
|
||||||
|
#include <Nazara/Graphics/Systems/RenderSystem.hpp>
|
||||||
|
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
void EditorNameComponent::Update(Time, NodeComponent& node)
|
||||||
|
{
|
||||||
|
if (!m_icon.has_value())
|
||||||
|
return;
|
||||||
|
m_icon.value().instance->UpdateWorldMatrix(node.GetTransformMatrix());
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorNameComponent::SetIcon(const std::filesystem::path& path)
|
||||||
|
{
|
||||||
|
auto& level = EditorBaseApplication::Instance()->GetLevel();
|
||||||
|
auto& renderer = level.GetEnttWorld()->GetSystem<RenderSystem>();
|
||||||
|
|
||||||
|
if (m_icon.has_value())
|
||||||
|
{
|
||||||
|
renderer.GetFramePipeline().UnregisterRenderable(m_icon.value().index);
|
||||||
|
m_icon = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& fs = EditorBaseApplication::Instance()->GetComponent<Nz::AppFilesystemComponent>();
|
||||||
|
|
||||||
|
Nz::TextureParams params;
|
||||||
|
params.loadFormat = Nz::PixelFormat::RGBA8_SRGB;
|
||||||
|
std::shared_ptr<Nz::Texture> tex = fs.Load<Nz::Texture>(path.string(), params);
|
||||||
|
std::shared_ptr<Nz::MaterialInstance> mat = Nz::MaterialInstance::GetDefault(Nz::MaterialType::Basic, Nz::MaterialInstancePreset::Transparent)->Clone();
|
||||||
|
|
||||||
|
mat->SetTextureProperty("BaseColorMap", tex);
|
||||||
|
mat->SetValueProperty("Billboard", true);
|
||||||
|
|
||||||
|
m_icon = BillboardData{
|
||||||
|
.index = 0,
|
||||||
|
.instance = std::make_shared<Nz::WorldInstance>(),
|
||||||
|
.billboard = std::make_shared<Nz::Billboard>(mat, Nz::Vector2f(1.f, 1.f))
|
||||||
|
};
|
||||||
|
|
||||||
|
auto& icon = m_icon.value();
|
||||||
|
|
||||||
|
Nz::Recti scissorBox(-1, -1, -1, -1);
|
||||||
|
|
||||||
|
Nz::ElementRendererRegistry elementRegistry;
|
||||||
|
icon.index = renderer.GetFramePipeline().RegisterWorldInstance(icon.instance);
|
||||||
|
renderer.GetFramePipeline().RegisterRenderable(icon.index, Nz::FramePipeline::NoSkeletonInstance, icon.billboard.get(), 0xFFFFFFFF, scissorBox);
|
||||||
|
|
||||||
|
OnIconChanged(this, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue