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

ParticleSystem and ImGui node test #386

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Engine/BuiltInShaders/shaders/fs_particle.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$input v_color0
#include "../common/common.sh"


void main()
{
gl_FragColor = float4(v_color0.rgb,1.0f);
}
21 changes: 0 additions & 21 deletions Engine/BuiltInShaders/shaders/varying.def.sc

This file was deleted.

10 changes: 10 additions & 0 deletions Engine/BuiltInShaders/shaders/vs_particle.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$input a_position, a_color0
$output v_color0

#include "../common/common.sh"

void main()
{
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
v_color0 = a_color0;
}
6 changes: 5 additions & 1 deletion Engine/Source/Editor/UILayers/EntityList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ void EntityList::AddEntity(engine::SceneWorld* pSceneWorld)
else if (ImGui::MenuItem("Add Particle Emitter"))
{
engine::Entity entity = AddNamedEntity("ParticleEmitter");
auto& particleEmitterComponent = pWorld->CreateComponent<engine::ParticleEmitterComponent>(entity);
// TODO : Some initialization here.
auto& transformComponent = pWorld->CreateComponent<engine::TransformComponent>(entity);
transformComponent.SetTransform(cd::Transform::Identity());
transformComponent.Build();

auto& particleEmitterComponent = pWorld->CreateComponent<engine::ParticleEmitterComponent>(entity);
}
}

Expand Down
12 changes: 6 additions & 6 deletions Engine/Source/Editor/UILayers/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,16 @@ void UpdateComponentWidget<engine::SkyComponent>(engine::SceneWorld* pSceneWorld
}

template<>
void UpdateComponentWidget<engine::ParticleComponent>(engine::SceneWorld* pSceneWorld, engine::Entity entity)
void UpdateComponentWidget<engine::ParticleEmitterComponent>(engine::SceneWorld* pSceneWorld, engine::Entity entity)
{
auto* pParticleComponent = pSceneWorld->GetParticleComponent(entity);
if (!pParticleComponent)
auto* pParticleEmitterComponent = pSceneWorld->GetParticleEmitterComponent(entity);
if (!pParticleEmitterComponent)
{

return;
}

bool isOpen = ImGui::CollapsingHeader("Particle Component", ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_DefaultOpen);
bool isOpen = ImGui::CollapsingHeader("ParticleEmitter Component", ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_DefaultOpen);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
ImGui::Separator();

Expand Down Expand Up @@ -570,8 +571,7 @@ void Inspector::Update()
details::UpdateComponentWidget<engine::LightComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::SkyComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::TerrainComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::ParticleComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::ShaderVariantCollectionsComponent>(pSceneWorld, selectedEntity);
details::UpdateComponentWidget<engine::ParticleEmitterComponent>(pSceneWorld, selectedEntity);

#ifdef ENABLE_DDGI
details::UpdateComponentWidget<engine::DDGIComponent>(pSceneWorld, selectedEntity);
Expand Down
255 changes: 218 additions & 37 deletions Engine/Source/Editor/UILayers/TestNodeEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#include "TestNodeEditor.h"

#include "ECWorld/CameraComponent.h"
#include "ECWorld/SceneWorld.h"
#include "ECWorld/StaticMeshComponent.h"
#include "ECWorld/TransformComponent.h"
#include "ImGui/ImGuiContextInstance.h"

// TODO : can use StringCrc to access other UILayers from ImGuiContextInstance.
#include "UILayers/SceneView.h"

#include <imgui/imgui.h>
#include <ImGuizmo/ImGuizmo.h>
#include <imgui_node_editor.h>

namespace ed = ax::NodeEditor;

Expand All @@ -24,39 +15,229 @@ TestNodeEditor::~TestNodeEditor()

void TestNodeEditor::Init()
{
ImGuizmo::SetGizmoSizeClipSpace(0.25f);
ImGuizmo::SetGizmoSizeClipSpace(0.25f);

ed::Config config;
config.SettingsFile = "Simple.json";
m_pNodeEditorContext = ed::CreateEditor(&config);
ed::Config config;
config.SettingsFile = "BasicInteraction.json";
m_Context = ed::CreateEditor(&config);
}

void TestNodeEditor::Update()
{
{
auto& io = ImGui::GetIO();

ImGui::Text("FPS: %.2f (%.2gms)", io.Framerate, io.Framerate ? 1000.0f / io.Framerate : 0.0f);

ImGui::Separator();

ed::SetCurrentEditor(m_pNodeEditorContext);
ed::Begin("My Editor", ImVec2(0.0, 0.0f));
int uniqueId = 1;
// Start drawing nodes.
ed::BeginNode(uniqueId++);
ImGui::Text("Node A");
ed::BeginPin(uniqueId++, ed::PinKind::Input);
ImGui::Text("-> In");
ed::EndPin();
ImGui::SameLine();
ed::BeginPin(uniqueId++, ed::PinKind::Output);
ImGui::Text("Out ->");
ed::EndPin();
ed::EndNode();
ed::End();
ed::SetCurrentEditor(nullptr);
}
{
auto& io = ImGui::GetIO();

ImGui::Text("FPS: %.2f (%.2gms)", io.Framerate, io.Framerate ? 1000.0f / io.Framerate : 0.0f);

ImGui::Separator();

ed::SetCurrentEditor(m_Context);

// Start interaction with editor.
ed::Begin("My Editor", ImVec2(0.0, 0.0f));

int uniqueId = 1;

//
// 1) Commit known data to editor
//

engine::SceneWorld* pSceneWorld = GetSceneWorld();
ed::NodeId MaterialNode = uniqueId++;
materialNodePinIds.clear();
textureMap.clear();
textureNodeId.clear();
textureNodePinId.clear();

for (int i = 0; i < 9; i++)
{
materialNodePinIds.push_back(uniqueId++);
}

for (auto& texture : pSceneWorld->GetSceneDatabase()->GetTextures())
{
textureNodeId.push_back(uniqueId++);
textureNodePinId.push_back(uniqueId++);
switch (texture.GetType())
{
case cd::MaterialTextureType::BaseColor:
textureTypeList.push_back(0);
break;
case cd::MaterialTextureType::Occlusion:
textureTypeList.push_back(1);
break;
case cd::MaterialTextureType::Roughness:
textureTypeList.push_back(2);
break;
case cd::MaterialTextureType::Metallic:
textureTypeList.push_back(3);
break;
case cd::MaterialTextureType::Normal:
textureTypeList.push_back(4);
break;
case cd::MaterialTextureType::Emissive:
textureTypeList.push_back(5);
break;
case cd::MaterialTextureType::Elevation:
textureTypeList.push_back(6);
break;
case cd::MaterialTextureType::AlphaMap:
textureTypeList.push_back(7);
break;
case cd::MaterialTextureType::General:
textureTypeList.push_back(8);
break;
}
}

int numNodes = sizeof(textureNodeId) / sizeof(textureNodeId[0]);
if (pSceneWorld->GetSceneDatabase()->GetTextureCount())
{
for (int i = 0; i < numNodes; i++)
{
if (m_FirstFrame)
ed::SetNodePosition(textureNodeId[i], ImVec2(1, i * 90.0f));
ed::BeginNode(textureNodeId[i]);
ImGui::Text("texture %d", i);
ed::BeginPin(textureNodePinId[i], ed::PinKind::Output);
ImGui::Text("Out ->");
ed::EndPin();
ed::EndNode();
}
}

if (pSceneWorld->GetSceneDatabase()->GetMaterialCount())
{
if (m_FirstFrame)
ed::SetNodePosition(MaterialNode, ImVec2(0, 90));
ed::BeginNode(MaterialNode);
ImGui::Text("Material ");
ed::BeginPin(materialNodePinIds[0], ed::PinKind::Input);
ImGui::Text(" BaseColor");
ed::EndPin();
ed::BeginPin(materialNodePinIds[1], ed::PinKind::Input);
ImGui::Text(" Occlusion");
ed::EndPin();
ed::BeginPin(materialNodePinIds[2], ed::PinKind::Input);
ImGui::Text(" Roughness");
ed::EndPin();
ed::BeginPin(materialNodePinIds[3], ed::PinKind::Input);
ImGui::Text(" Metallic");
ed::EndPin();
ed::BeginPin(materialNodePinIds[4], ed::PinKind::Input);
ImGui::Text(" Normal");
ed::EndPin();
ed::BeginPin(materialNodePinIds[5], ed::PinKind::Input);
ImGui::Text(" Emissive");
ed::EndPin();
ed::BeginPin(materialNodePinIds[6], ed::PinKind::Input);
ImGui::Text(" Elevation");
ed::EndPin();
ed::BeginPin(materialNodePinIds[7], ed::PinKind::Input);
ImGui::Text(" AlphaMap");
ed::EndPin();
ed::BeginPin(materialNodePinIds[8], ed::PinKind::Input);
ImGui::Text(" General");
ed::EndPin();
ed::EndNode();
}

if ((pSceneWorld->GetSceneDatabase()->GetMaterialCount() || pSceneWorld->GetSceneDatabase()->GetTextureCount() )&& linkSwitch)
{
for (int i = 0; i < numNodes; i++)
{
m_Links.push_back({ ed::LinkId(m_NextLinkId++), textureNodePinId[i], materialNodePinIds[textureTypeList[i]] });
ed::Link(m_Links.back().Id, m_Links.back().InputId, m_Links.back().OutputId);
}
linkSwitch = false;
}

// Submit Links
for (auto& linkInfo : m_Links)
ed::Link(linkInfo.Id, linkInfo.InputId, linkInfo.OutputId);

//
// 2) Handle interactions
//

// Handle creation action, returns true if editor want to create new object (node or link)
if (ed::BeginCreate())
{
ed::PinId inputPinId, outputPinId;
if (ed::QueryNewLink(&inputPinId, &outputPinId))
{
// QueryNewLink returns true if editor want to create new link between pins.
//
// Link can be created only for two valid pins, it is up to you to
// validate if connection make sense. Editor is happy to make any.
//
// Link always goes from input to output. User may choose to drag
// link from output pin or input pin. This determine which pin ids
// are valid and which are not:
// * input valid, output invalid - user started to drag new ling from input pin
// * input invalid, output valid - user started to drag new ling from output pin
// * input valid, output valid - user dragged link over other pin, can be validated

if (inputPinId && outputPinId) // both are valid, let's accept link
{
// ed::AcceptNewItem() return true when user release mouse button.
if (ed::AcceptNewItem())
{
// Since we accepted new link, lets add one to our list of links.
m_Links.push_back({ ed::LinkId(m_NextLinkId++), inputPinId, outputPinId });

// Draw new link.
ed::Link(m_Links.back().Id, m_Links.back().InputId, m_Links.back().OutputId);
}

// You may choose to reject connection between these nodes
// by calling ed::RejectNewItem(). This will allow editor to give
// visual feedback by changing link thickness and color.
}
}
}
ed::EndCreate(); // Wraps up object creation action handling.


// Handle deletion action
if (ed::BeginDelete())
{
// There may be many links marked for deletion, let's loop over them.
ed::LinkId deletedLinkId;
while (ed::QueryDeletedLink(&deletedLinkId))
{
// If you agree that link can be deleted, accept deletion.
if (ed::AcceptDeletedItem())
{
// Then remove link from your data.
for (auto& link : m_Links)
{
if (link.Id == deletedLinkId)
{
m_Links.erase(&link);
break;
}
}
}

// You may reject link deletion by calling:
// ed::RejectDeletedItem();
}
}
ed::EndDelete(); // Wrap up deletion action

// End of interaction with editor.
ed::End();

if (m_FirstFrame)
ed::NavigateToContent(0.0f);

ed::SetCurrentEditor(nullptr);

m_FirstFrame = false;

// ImGui::ShowMetricsWindow();
}
}

}
Loading
Loading