/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #include "Scene/Drawable.hpp" #include "Scene/UniformBuffer.hpp" #include "Scene/BillboardControlBlock.hpp" #include "Math/AABB.hpp" #include "Scene/TextDrawable.hpp" #include namespace OpenVulkano::Scene { class Shader; struct LabelDrawableSettings { Math::Vector4f backgroundColor = { 1, 0, 0, 1 }; Math::Vector2f padding = { 0.2f, 0.2f }; float cornerRadius = 0.05f; float arrowLength = 0.5f; float arrowWidth = 0.2f; int32_t hasRoundedCorners = false; int32_t hasArrow = false; }; struct LabelUniformData { Math::Vector4f color = { 0, 0, 0, 0 }; Math::Vector2f textSize = {}; Math::Vector2f bboxCenter = {}; float cornerRadius = 0.f; float arrowLength = 0.f; float arrowWidth = 0.f; int32_t hasRoundedCorners = false; int32_t hasArrow = false; }; class LabelDrawable final : public Drawable { public: LabelDrawable(const std::shared_ptr& atlasData, const LabelDrawableSettings& settings = LabelDrawableSettings(), bool isBillboard = false); void AddText(const std::string& text, const TextConfig& config = TextConfig()); void SetLabelSettings(const LabelDrawableSettings& settings); void SetBillboardSettings(const BillboardControlBlock& settings); void SetPosition(const Math::Vector3f& pos) { m_position = pos; } [[nodiscard]] std::list& GetTexts() { return m_texts; } [[nodiscard]] LabelDrawableSettings& GetSettings() { return m_settings; } [[nodiscard]] UniformBuffer* GetBillboardBuffer() { return &m_billboardBuffer; } [[nodiscard]] UniformBuffer* GetLabelBuffer() { return &m_labelBuffer; } [[nodiscard]] BillboardControlBlock& GetBillboardSettings() { return m_billboardSettings; } [[nodiscard]] Math::Vector3f& GetPosition() { return m_position; } [[nodiscard]] bool IsBillboard() const { return m_isBillboard; } [[nodiscard]] const Math::AABB& GetBoundingBox() const { return m_bbox; } std::optional Intersect(const Ray& ray) const override; private: void SetupBuffers(); UniformBuffer m_billboardBuffer; UniformBuffer m_labelBuffer; std::list m_texts; // Using list instead of vector for stable iterators LabelDrawableSettings m_settings; LabelUniformData m_labelData; std::shared_ptr m_atlasData; BillboardControlBlock m_billboardSettings; Math::Vector3f m_position = { 0, 0, 0 }; Math::AABB m_bbox; bool m_isBillboard; }; }