Added particle emitter component

This commit is contained in:
Antoine Pilote
2023-08-02 12:40:12 -04:00
parent ba102e971c
commit 807e9c9a9f
7 changed files with 147 additions and 2 deletions

View File

@@ -0,0 +1,79 @@
#pragma once
#include "ComponentPanel.h"
#include <src/Core/FileSystem.h>
#include <src/Core/Maths.h>
#include <src/Scene/Components/ParticleEmitterComponent.h>
#include <src/Scene/Entities/ImGuiHelper.h>
class ParticleEmitterPanel : ComponentPanel
{
public:
ParticleEmitterPanel() {}
void Draw(Nuake::Entity entity) override
{
if (!entity.HasComponent<Nuake::ParticleEmitterComponent>())
return;
auto& component = entity.GetComponent<Nuake::ParticleEmitterComponent>();
BeginComponentTable(PARTICLE EMITTER, Nuake::ParticleEmitterComponent);
{
{
ImGui::Text("Particle Color");
ImGui::TableNextColumn();
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::ColorEdit3("##lightcolor", &component.ParticleColor.r, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
ImGui::PopItemWidth();
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("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();
}
};

View File

@@ -93,6 +93,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
mTransformPanel.Draw(entity);
mLightPanel.Draw(entity);
mScriptPanel.Draw(entity);
mParticleEmitterPanel.Draw(entity);
mSpritePanel.Draw(entity);
mMeshPanel.Draw(entity);
mQuakeMapPanel.Draw(entity);

View File

@@ -19,9 +19,11 @@
#include "../ComponentsPanel/MeshColliderPanel.h"
#include "../ComponentsPanel/CharacterControllerPanel.h"
#include "../ComponentsPanel/SpritePanel.h"
#include "../ComponentsPanel/ParticleEmitterPanel.h"
class EditorSelectionPanel {
class EditorSelectionPanel
{
private:
TransformPanel mTransformPanel;
LightPanel mLightPanel;
@@ -37,6 +39,7 @@ private:
CylinderColliderPanel mCylinderColliderPanel;
SpritePanel mSpritePanel;
CharacterControllerPanel mCharacterControllerPanel;
ParticleEmitterPanel mParticleEmitterPanel;
Ref<Nuake::File> currentFile;
Ref<Nuake::Resource> selectedResource;

View File

@@ -19,6 +19,9 @@ using json = nlohmann::json;
SERIALIZE_VEC3(v) \
j[#v]["w"] = this->v.w;
#define DESERIALIZE_VEC4(v, p) \
p = Vector4(v["x"], v["y"], v["z"], v["w"]);
#define DESERIALIZE_VEC3(v, p) \
p = Vector3(v["x"], v["y"], v["z"]);

View File

@@ -0,0 +1,28 @@
#include "src/Scene/Components/ParticleEmitterComponent.h"
namespace Nuake
{
json ParticleEmitterComponent::Serialize()
{
BEGIN_SERIALIZE();
SERIALIZE_VEC4(ParticleColor);
SERIALIZE_VAL(Amount);
SERIALIZE_VAL(Life);
SERIALIZE_VEC3(Gravity);
SERIALIZE_VAL(GravityRandom);
SERIALIZE_VAL(Radius);
END_SERIALIZE();
}
bool ParticleEmitterComponent::Deserialize(const std::string& str)
{
BEGIN_DESERIALIZE();
DESERIALIZE_VEC4(j["ParticleColor"], ParticleColor);
Amount = j["Amount"];
Life = j["Life"];
DESERIALIZE_VEC3(j["Gravity"], Gravity);
GravityRandom = j["GravityRandom"];
Radius = j["Radius"];
return true;
}
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include "src/Core/Core.h"
#include "src/Resource/Serializable.h"
#include <src/Core/Maths.h>
namespace Nuake
{
class ParticleEmitterComponent
{
public:
ParticleEmitterComponent() = default;
~ParticleEmitterComponent() = default;
Color ParticleColor;
float Amount;
float Life;
Vector3 Gravity;
float GravityRandom;
// For now use a radius, later should use shape.
float Radius;
public:
json Serialize();
bool Deserialize(const std::string& str);
};
}

View File

@@ -15,7 +15,7 @@
#include "src/Scene/Components/BoxCollider.h"
#include "src/Scene/Components/CapsuleColliderComponent.h"
#include "src/Scene/Components/SpriteComponent.h"
#include "src/Scene/Components/ParticleEmitterComponent.h"
namespace Nuake
{
@@ -39,6 +39,8 @@ namespace Nuake
SERIALIZE_OBJECT_REF_LBL("VisibilityComponent", GetComponent<VisibilityComponent>())
if (HasComponent<CameraComponent>())
SERIALIZE_OBJECT_REF_LBL("CameraComponent", GetComponent<CameraComponent>())
if (HasComponent<ParticleEmitterComponent>())
SERIALIZE_OBJECT_REF_LBL("ParticleEmitterComponent", GetComponent<ParticleEmitterComponent>())
if (HasComponent<SpriteComponent>())
SERIALIZE_OBJECT_REF_LBL("SpriteComponent", GetComponent<SpriteComponent>())
if (HasComponent<QuakeMapComponent>())
@@ -82,6 +84,7 @@ namespace Nuake
}
DESERIALIZE_COMPONENT(NameComponent)
DESERIALIZE_COMPONENT(ParentComponent)
DESERIALIZE_COMPONENT(ParticleEmitterComponent)
DESERIALIZE_COMPONENT(SpriteComponent)
DESERIALIZE_COMPONENT(CameraComponent)
DESERIALIZE_COMPONENT(QuakeMapComponent)