From 269533eb03233115de5f0ff850aadae34949b01b Mon Sep 17 00:00:00 2001 From: WiggleWizard <1405402+WiggleWizard@users.noreply.github.com> Date: Sun, 15 Sep 2024 21:28:22 +0100 Subject: [PATCH] Particle Emitter Component reflected --- .../ComponentsPanel/ParticleEmitterPanel.h | 132 ------------------ Editor/src/Windows/EditorSelectionPanel.cpp | 16 ++- Nuake/src/Rendering/SceneRenderer.cpp | 17 ++- Nuake/src/Scene/Components/Component.h | 1 + Nuake/src/Scene/Components/FieldTypes.h | 1 + .../Components/ParticleEmitterComponent.cpp | 19 +-- .../Components/ParticleEmitterComponent.h | 23 +++ 7 files changed, 59 insertions(+), 150 deletions(-) diff --git a/Editor/src/ComponentsPanel/ParticleEmitterPanel.h b/Editor/src/ComponentsPanel/ParticleEmitterPanel.h index d45495de..02bbfc47 100644 --- a/Editor/src/ComponentsPanel/ParticleEmitterPanel.h +++ b/Editor/src/ComponentsPanel/ParticleEmitterPanel.h @@ -18,138 +18,6 @@ public: void Draw(Nuake::Entity entity) override { - if (!entity.HasComponent()) - return; - - auto& component = entity.GetComponent(); - BeginComponentTable(PARTICLE EMITTER, Nuake::ParticleEmitterComponent); - { - { - ImGui::Text("Particle Material"); - ImGui::TableNextColumn(); - - std::string label = "Empty"; - if (component.ParticleMaterial && !component.ParticleMaterial->Path.empty()) - { - label = component.ParticleMaterial->Path; - } - - if (ImGui::Button(label.c_str(), ImVec2(ImGui::GetContentRegionAvail().x, 0))) - { - - } - - if (ImGui::BeginDragDropTarget()) - { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Material")) - { - char* file = (char*)payload->Data; - std::string fullPath = std::string(file, 256); - - fullPath = Nuake::FileSystem::AbsoluteToRelative(fullPath); - - Ref material = Nuake::ResourceLoader::LoadMaterial(fullPath); - component.ParticleMaterial = material; - } - ImGui::EndDragDropTarget(); - } - - //std::string childId = "materialEditorParticle"; - //ImGui::BeginChild(childId.c_str(), ImVec2(0, 0), false); - //{ - // MaterialEditor editor; - // editor.Draw(component.ParticleMaterial); - //} - //ImGui::EndChild(); - - ImGui::TableNextColumn(); - //ComponentTableReset(component.ParticleColor, Nuake::Vector4(1, 1, 1, 1)); - } - - ImGui::TableNextColumn(); - { - ImGui::Text("Amount"); - ImGui::TableNextColumn(); - - ImGui::DragFloat("##ParticleAmount", &component.Amount, 0.1f, 0.0f, 500.0f); - ImGui::TableNextColumn(); - ComponentTableReset(component.Amount, 10.0f); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Particle Scale"); - ImGui::TableNextColumn(); - - ImGuiHelper::DrawVec3("##particleSize", &component.ParticleScale); - - ImGui::TableNextColumn(); - ComponentTableReset(component.ParticleScale, Nuake::Vector3(0.1, 0.1, 0.1)); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Particle Scale Random"); - ImGui::TableNextColumn(); - - ImGui::DragFloat("##particleSizeRandom", &component.ScaleRandomness, 0.01f, 0.0f); - - ImGui::TableNextColumn(); - ComponentTableReset(component.ScaleRandomness, 0.0f); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Global Space"); - ImGui::TableNextColumn(); - - ImGui::Checkbox("##globalSpace", &component.GlobalSpace); - - ImGui::TableNextColumn(); - ComponentTableReset(component.GlobalSpace, false); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Rate"); - ImGui::TableNextColumn(); - - ImGui::DragFloat("##ParticleRate", &component.Rate, 0.1f, 0.0f, 10.0f); - ImGui::TableNextColumn(); - ComponentTableReset(component.Rate, 0.0f); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Life"); - ImGui::TableNextColumn(); - - ImGui::DragFloat("##ParticleLife", &component.Life, 0.1f, 0.0f, 100.0f); - ImGui::TableNextColumn(); - ComponentTableReset(component.Life, 5.0f); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Gravity"); - ImGui::TableNextColumn(); - - ImGuiHelper::DrawVec3("Gravity", &component.Gravity); - ImGui::TableNextColumn(); - ComponentTableReset(component.Gravity, Nuake::Vector3(0, -1, 0)); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Gravity Random"); - ImGui::TableNextColumn(); - ImGui::DragFloat("##GravityRandom", &component.GravityRandom, 0.01f, 0.0f, 1.0f); - ImGui::TableNextColumn(); - ComponentTableReset(component.GravityRandom, 0.0f); - } - ImGui::TableNextColumn(); - { - ImGui::Text("Radius"); - ImGui::TableNextColumn(); - ImGui::DragFloat("##ParticleRadius", &component.Radius, 0.01f, 0.0f, 10.0f); - ImGui::TableNextColumn(); - ComponentTableReset(component.Radius, 1.0f); - } - } - EndComponentTable(); } }; \ No newline at end of file diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index 17ba5726..2f6a7525 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -16,6 +16,8 @@ #include +#include "Tracy.hpp" + #define REGISTER_TYPE_DRAWER(forType, fn) \ FieldTypeDrawers[entt::type_id().hash()] = std::bind(&fn, this, std::placeholders::_1, std::placeholders::_2); @@ -122,6 +124,8 @@ void EditorSelectionPanel::DrawNone() void EditorSelectionPanel::DrawEntity(Nuake::Entity entity) { + ZoneScoped; + if (!entity.IsValid()) { return; @@ -545,6 +549,8 @@ void EditorSelectionPanel::DrawNetScriptPanel(Ref file) void EditorSelectionPanel::DrawComponent(const Nuake::Entity& entity, entt::meta_any& component) { + ZoneScoped; + const entt::meta_type componentMeta = component.type(); const std::string componentName = Component::GetName(componentMeta); @@ -580,6 +586,8 @@ void EditorSelectionPanel::DrawComponent(const Nuake::Entity& entity, entt::meta ImGui::TableSetupColumn("set", 0, 0.65f); ImGui::TableSetupColumn("reset", 0, 0.1f); + ImGui::TableNextRow(); + DrawComponentContent(component); ImGui::EndTable(); @@ -596,6 +604,8 @@ void EditorSelectionPanel::DrawComponent(const Nuake::Entity& entity, entt::meta void EditorSelectionPanel::DrawComponentContent(entt::meta_any& component) { + ZoneScoped; + entt::meta_type componentMeta = component.type(); // Draw component bound data @@ -608,7 +618,7 @@ void EditorSelectionPanel::DrawComponentContent(entt::meta_any& component) continue; } - ImGui::TableNextColumn(); + ImGui::TableSetColumnIndex(0); // Search for the appropriate drawer for the type entt::id_type dataId = dataType.type().id(); @@ -628,12 +638,10 @@ void EditorSelectionPanel::DrawComponentContent(entt::meta_any& component) // Draw any actions bound to the component for (auto [fst, funcMeta] : componentMeta.func()) { - ImGui::TableSetColumnIndex(0); - const ComponentFuncTrait funcTraits = funcMeta.traits(); if ((funcTraits & ComponentFuncTrait::Action) == ComponentFuncTrait::Action) { - ImGui::TableNextColumn(); + ImGui::TableSetColumnIndex(0); std::string funcDisplayName = ""; auto prop = funcMeta.prop(HashedName::DisplayName).value(); diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index ff7b2162d..773af6cb 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -917,9 +917,24 @@ namespace Nuake { auto [transform, emitterComponent, visibility] = particleEmitterView.get(e); - if (!visibility.Visible || !emitterComponent.ParticleMaterial) + if (!visibility.Visible) continue; + if (emitterComponent.resFile.dirty) + { + emitterComponent.resFile.dirty = false; + if (emitterComponent.resFile.Exist()) + { + Ref material = Nuake::ResourceLoader::LoadMaterial(emitterComponent.resFile.GetRelativePath()); + emitterComponent.ParticleMaterial = material; + } + } + + if (emitterComponent.ParticleMaterial == nullptr) + { + continue; + } + Renderer::QuadMesh->SetMaterial(emitterComponent.ParticleMaterial); Vector3 oldColor = Renderer::QuadMesh->GetMaterial()->data.m_AlbedoColor; diff --git a/Nuake/src/Scene/Components/Component.h b/Nuake/src/Scene/Components/Component.h index 5bfe9f06..1a07dc6d 100644 --- a/Nuake/src/Scene/Components/Component.h +++ b/Nuake/src/Scene/Components/Component.h @@ -1,6 +1,7 @@ #pragma once #include "src/Core/Object/Object.h" +#include "FieldTypes.h" namespace Nuake { diff --git a/Nuake/src/Scene/Components/FieldTypes.h b/Nuake/src/Scene/Components/FieldTypes.h index 5d4174e6..3f321904 100644 --- a/Nuake/src/Scene/Components/FieldTypes.h +++ b/Nuake/src/Scene/Components/FieldTypes.h @@ -18,6 +18,7 @@ namespace Nuake std::string GetAbsolutePath(); Ref file = nullptr; + bool dirty = true; }; struct DynamicItemList diff --git a/Nuake/src/Scene/Components/ParticleEmitterComponent.cpp b/Nuake/src/Scene/Components/ParticleEmitterComponent.cpp index 80297e15..3c74162e 100644 --- a/Nuake/src/Scene/Components/ParticleEmitterComponent.cpp +++ b/Nuake/src/Scene/Components/ParticleEmitterComponent.cpp @@ -1,11 +1,14 @@ #include "src/Scene/Components/ParticleEmitterComponent.h" +#include "src/FileSystem/File.h" #include #include + namespace Nuake { json ParticleEmitterComponent::Serialize() { BEGIN_SERIALIZE(); + SERIALIZE_RES_FILE(resFile); SERIALIZE_VEC3(ParticleScale); SERIALIZE_VAL(Amount); SERIALIZE_VAL(Life); @@ -14,10 +17,6 @@ namespace Nuake SERIALIZE_VAL(GravityRandom); SERIALIZE_VAL(Radius); SERIALIZE_VAL(GlobalSpace); - if (ParticleMaterial) - { - SERIALIZE_OBJECT(ParticleMaterial); - } SERIALIZE_VAL(LifeRandomness); SERIALIZE_VAL(ScaleRandomness); END_SERIALIZE(); @@ -51,16 +50,10 @@ namespace Nuake { DESERIALIZE_VAL(GlobalSpace); } - if (j.contains("ParticleMaterial")) - { - if (j["ParticleMaterial"].contains("Path")) - { - Ref newMaterial = ResourceLoader::LoadMaterial(j["ParticleMaterial"]["Path"]); - ParticleMaterial = newMaterial; - } - } GravityRandom = j["GravityRandom"]; Radius = j["Radius"]; + + DESERIALIZE_RES_FILE(resFile); return true; } -} \ No newline at end of file +} diff --git a/Nuake/src/Scene/Components/ParticleEmitterComponent.h b/Nuake/src/Scene/Components/ParticleEmitterComponent.h index 755294aa..f6dc6846 100644 --- a/Nuake/src/Scene/Components/ParticleEmitterComponent.h +++ b/Nuake/src/Scene/Components/ParticleEmitterComponent.h @@ -15,10 +15,33 @@ namespace Nuake { NUAKECOMPONENT(ParticleEmitterComponent, "Particle Emitter") + static void InitializeComponentClass() + { + BindComponentField<&ParticleEmitterComponent::resFile>("Particle", "Particle"); + BindComponentField<&ParticleEmitterComponent::Amount>("Amount", "Amount"); + FieldFloatLimits(0.1f, 0.0f, 500.0f); + BindComponentField<&ParticleEmitterComponent::LifeRandomness>("LifeRandomness", "Life Randomness"); + FieldFloatLimits(0.1f, 0.f, 9999.f); + BindComponentField<&ParticleEmitterComponent::Life>("Life", "Life"); + FieldFloatLimits(0.1f, 0.0f, 100.0f); + BindComponentField<&ParticleEmitterComponent::Rate>("Rate", "Rate"); + FieldFloatLimits(0.1f, 0.0f, 10.0f); + BindComponentField<&ParticleEmitterComponent::ScaleRandomness>("ScaleRandomness", "Scale Randomness"); + FieldFloatLimits(0.01f, 0.0f, 0.f); + BindComponentField<&ParticleEmitterComponent::ParticleScale>("ParticleScale", "Particle Scale"); + BindComponentField<&ParticleEmitterComponent::GlobalSpace>("GlobalSpace", "Global Space"); + BindComponentField<&ParticleEmitterComponent::Gravity>("Gravity", "Gravity"); + BindComponentField<&ParticleEmitterComponent::GravityRandom>("GravityRandom", "Gravity Random"); + FieldFloatLimits(0.01f, 0.0f, 1.0f); + BindComponentField<&ParticleEmitterComponent::Radius>("Radius", "Radius"); + FieldFloatLimits(0.01f, 0.0f, 10.0f); + } + public: ParticleEmitterComponent() = default; ~ParticleEmitterComponent() = default; + ResourceFile resFile; Ref ParticleMaterial = CreateRef(); float Amount;