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 #388

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
13 changes: 13 additions & 0 deletions Engine/BuiltInShaders/shaders/fs_particle.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$input v_color0, v_texcoord0
#include "../common/common.sh"

SAMPLER2D(s_texColor, 0);

void main()
{
vec4 rgba = texture2D(s_texColor, v_texcoord0.xy);

rgba.xyz = rgba.xyz * v_color0.xyz;
rgba.w = v_color0.w;
gl_FragColor = rgba;
}
8 changes: 7 additions & 1 deletion Engine/BuiltInShaders/shaders/varying.def.sc
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ vec2 a_texcoord0 : TEXCOORD0;
vec4 a_color0 : COLOR0;
vec4 a_color1 : COLOR1;
ivec4 a_indices : BLENDINDICES;
vec4 a_weight : BLENDWEIGHT;
vec4 a_weight : BLENDWEIGHT;

vec4 i_data0 : TEXCOORD7;
vec4 i_data1 : TEXCOORD6;
vec4 i_data2 : TEXCOORD5;
vec4 i_data3 : TEXCOORD4;
vec4 i_data4 : TEXCOORD3;
14 changes: 14 additions & 0 deletions Engine/BuiltInShaders/shaders/vs_particle.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$input a_position, a_color0, a_texcoord0, i_data0, i_data1 ,i_data2 ,i_data3 ,i_data4
$output v_color0, v_texcoord0

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

void main()
{
mat4 model = mtxFromCols(i_data0, i_data1, i_data2, i_data3);

vec4 worldPos = mul(model,vec4(a_position,1.0));
gl_Position = mul(u_viewProj, worldPos);
v_color0 = a_color0*i_data4;
v_texcoord0 = a_texcoord0;
}
Binary file modified Engine/EditorTools/Win64/texturec.exe
Binary file not shown.
32 changes: 31 additions & 1 deletion Engine/Source/Editor/ECWorld/ECWorldConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ void ECWorldConsumer::Execute(const cd::SceneDatabase* pSceneDatabase)
CD_WARN("[ECWorldConsumer] No valid meshes in the consumed SceneDatabase.");
}

if (0U != pSceneDatabase->GetParticleEmitterCount())
{
CD_INFO("[ECWorldConsumer] Have ParticleEmitter");
}

auto ParseMesh = [&](cd::MeshID meshID, const cd::Transform& tranform)
{
engine::Entity meshEntity = m_pSceneWorld->GetWorld()->CreateEntity();
Expand Down Expand Up @@ -139,7 +144,7 @@ void ECWorldConsumer::Execute(const cd::SceneDatabase* pSceneDatabase)
}

for (const auto& node : pSceneDatabase->GetNodes())
{
{
if (m_nodeMinID > node.GetID().Data())
{
continue;
Expand Down Expand Up @@ -167,6 +172,12 @@ void ECWorldConsumer::Execute(const cd::SceneDatabase* pSceneDatabase)
engine::Entity lightEntity = m_pSceneWorld->GetWorld()->CreateEntity();
AddLight(lightEntity, light);
}

for (const auto& particle : pSceneDatabase->GetParticleEmitters())
{
engine::Entity particleEntity = m_pSceneWorld->GetWorld()->CreateEntity();
AddParticleEmitter(particleEntity, particle);
}
}

void ECWorldConsumer::AddCamera(engine::Entity entity, const cd::Camera& camera)
Expand Down Expand Up @@ -371,4 +382,23 @@ void ECWorldConsumer::AddMorphs(engine::Entity entity, const std::vector<cd::Mor
blendShapeComponent.Build();
}

void ECWorldConsumer::AddParticleEmitter(engine::Entity entity, const cd::ParticleEmitter& particle)
{
engine::World* pWorld = m_pSceneWorld->GetWorld();
engine::NameComponent& nameComponent = pWorld->CreateComponent<engine::NameComponent>(entity);
nameComponent.SetName(particle.GetName());
auto& particleEmitterComponent = pWorld->CreateComponent<engine::ParticleEmitterComponent>(entity);
// TODO : Some initialization here.
auto& transformComponent = pWorld->CreateComponent<engine::TransformComponent>(entity);
cd::Vec3f pos = particle.GetPosition();
transformComponent.SetTransform(cd::Transform::Identity());
transformComponent.GetTransform().SetTranslation(pos);
transformComponent.Build();

particleEmitterComponent.GetParticleSystem().Init();
particleEmitterComponent.SetFVelocity(particle.GetVelocity());
particleEmitterComponent.SetFColor(particle.GetColor()/255.0f);
particleEmitterComponent.Build();
}

}
2 changes: 2 additions & 0 deletions Engine/Source/Editor/ECWorld/ECWorldConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Node;
class SceneDatabase;
class Texture;
class VertexFormat;
class ParticleEmitter;

}

Expand Down Expand Up @@ -67,6 +68,7 @@ class ECWorldConsumer final : public cdtools::IConsumer
void AddAnimation(engine::Entity entity, const cd::Animation& animation, const cd::SceneDatabase* pSceneDatabase);
void AddMaterial(engine::Entity entity, const cd::Material* pMaterial, engine::MaterialType* pMaterialType, const cd::SceneDatabase* pSceneDatabase);
void AddMorphs(engine::Entity entity, const std::vector<cd::Morph>& morphs, const cd::Mesh* pMesh);
void AddParticleEmitter(engine::Entity entity, const cd::ParticleEmitter& particle);

private:
engine::MaterialType* m_pDefaultMaterialType = nullptr;
Expand Down
55 changes: 55 additions & 0 deletions Engine/Source/Editor/UILayers/AssetBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Log/Log.h"
#include "Material/MaterialType.h"
#include "Producers/CDProducer/CDProducer.h"
#include "Producers/EffekseerProducer/EffekseerProducer.h"
#include "Rendering/WorldRenderer.h"
#include "Rendering/RenderContext.h"
#include "Resources/ResourceBuilder.h"
Expand All @@ -22,6 +23,7 @@
#include "Producers/GenericProducer/GenericProducer.h"
#endif

#include <Windows.h>
#include <json/json.hpp>

#include <imgui/imgui.h>
Expand Down Expand Up @@ -98,6 +100,21 @@ bool IsLightInputFile(const char* pFileExtension)
return false;
}

bool IsParticleInputFile(const char* pFileExtension)
{
constexpr const char* pFileExtensions[] = { ".efkefc"};
constexpr const int fileExtensionsSize = sizeof(pFileExtensions) / sizeof(pFileExtensions[0]);
for (int extensionIndex = 0; extensionIndex < fileExtensionsSize; ++extensionIndex)
{
if (0 == strcmp(pFileExtensions[extensionIndex], pFileExtension))
{
return true;
}
}

return false;
}

std::string GetFilePathExtension(const std::string& FileName)
{
auto pos = FileName.find_last_of('.');
Expand Down Expand Up @@ -780,6 +797,10 @@ void AssetBrowser::ImportAssetFile(const char* pFilePath)
{
m_importOptions.AssetType = IOAssetType::Light;
}
else if (IsParticleInputFile(pFileExtension.c_str()))
{
m_importOptions.AssetType = IOAssetType::Particle;
}
else
{
// Still unknown, exit.
Expand Down Expand Up @@ -852,6 +873,10 @@ void AssetBrowser::ImportAssetFile(const char* pFilePath)
{
ImportJson(pFilePath);
}
else if (IOAssetType::Particle == m_importOptions.AssetType)
{
ImportParticleEffect(pFilePath);
}
}

void AssetBrowser::ProcessSceneDatabase(cd::SceneDatabase* pSceneDatabase, bool keepMesh, bool keepMaterial, bool keepTexture, bool keepCamera, bool keepLight)
Expand Down Expand Up @@ -1084,6 +1109,36 @@ void AssetBrowser::ImportJson(const char* pFilePath)
}
}

void AssetBrowser::ImportParticleEffect(const char* pFilePath)
{
////engine::RenderContext* pCurrentRenderContext = GetRenderContext();
//engine::SceneWorld* pSceneWorld = GetImGuiContextInstance()->GetSceneWorld();

//cd::SceneDatabase* pSceneDatabase = pSceneWorld->GetSceneDatabase();
////uint32_t oldNodeCount = pSceneDatabase->GetNodeCount();
////uint32_t oldMeshCount = pSceneDatabase->GetMeshCount();
//uint32_t oldParticleEmitterCount = pSceneDatabase->GetParticleEmitterCount();

//// Step 1 : Convert model file to cd::SceneDatabase
//std::filesystem::path inputFilePath(pFilePath);
//std::filesystem::path inputFileExtension = inputFilePath.extension();
//if (0 == inputFileExtension.compare(".efkefc"))
//{
///* cdtools::CDProducer cdProducer(pFilePath);
// cd::SceneDatabase newSceneDatabase;
// cdtools::Processor processor(&cdProducer, nullptr, &newSceneDatabase);
// proce qssor.Run();
// pSceneDatabase->Merge(cd::MoveTemp(newSceneDatabase));*/
// std::string filePath = pFilePath;
// int size = MultiByteToWideChar(CP_UTF8, 0, filePath.c_str(), -1, nullptr, 0);
// std::wstring wstr(size, 0);
// MultiByteToWideChar(CP_UTF8, 0, filePath.c_str(), -1, &wstr[0], size);
// std::wstring wFilePath = wstr;
// const char16_t* u16_cstr = reinterpret_cast<const char16_t*>(wFilePath.c_str());
// cdtools::EffekseerProducer efkProducer(u16_cstr);
//}
}

void AssetBrowser::ExportAssetFile(const char* pFilePath)
{
engine::SceneWorld* pSceneWorld = GetImGuiContextInstance()->GetSceneWorld();
Expand Down
2 changes: 2 additions & 0 deletions Engine/Source/Editor/UILayers/AssetBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum class IOAssetType
SceneDatabase,
Terrain,
Light,
Particle,
Unknown,
};

Expand Down Expand Up @@ -95,6 +96,7 @@ class AssetBrowser : public engine::ImGuiBaseLayer
private:
void ProcessSceneDatabase(cd::SceneDatabase* pSceneDatabase, bool keepMesh, bool keepMaterial, bool keepTexture, bool keepCamera, bool keepLight);
void ImportModelFile(const char* pFilePath);
void ImportParticleEffect(const char* pFilePath);
void ImportJson(const char* pFilePath);
void DrawFolder(const std::shared_ptr<DirectoryInformation>& dirInfo, bool defaultOpen = false);
void ChangeDirectory(std::shared_ptr<DirectoryInformation>& directory);
Expand Down
6 changes: 6 additions & 0 deletions Engine/Source/Editor/UILayers/EntityList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ void EntityList::AddEntity(engine::SceneWorld* pSceneWorld)
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();

particleEmitterComponent.GetParticleSystem().Init();
particleEmitterComponent.Build();
}
}

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 @@ -616,10 +616,10 @@ 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;
}
Expand All @@ -630,7 +630,8 @@ void UpdateComponentWidget<engine::ParticleComponent>(engine::SceneWorld* pScene

if (isOpen)
{

ImGuiUtils::ImGuiVectorProperty("Velocity",pParticleEmitterComponent->GetFVelocity());
ImGuiUtils::ColorPickerProperty(" Color", pParticleEmitterComponent->GetFColor());
}

ImGui::Separator();
Expand Down Expand Up @@ -674,7 +675,6 @@ void Inspector::Update()
}

ImGui::BeginChild("Inspector");

details::UpdateComponentWidget<engine::NameComponent>(pSceneWorld, m_lastSelectedEntity);
details::UpdateComponentWidget<engine::TransformComponent>(pSceneWorld, m_lastSelectedEntity);
details::UpdateComponentWidget<engine::CameraComponent>(pSceneWorld, m_lastSelectedEntity);
Expand All @@ -683,7 +683,7 @@ void Inspector::Update()
details::UpdateComponentWidget<engine::TerrainComponent>(pSceneWorld, m_lastSelectedEntity);
details::UpdateComponentWidget<engine::StaticMeshComponent>(pSceneWorld, m_lastSelectedEntity);
details::UpdateComponentWidget<engine::MaterialComponent>(pSceneWorld, m_lastSelectedEntity);
details::UpdateComponentWidget<engine::ParticleComponent>(pSceneWorld, m_lastSelectedEntity);
details::UpdateComponentWidget<engine::ParticleEmitterComponent>(pSceneWorld, m_lastSelectedEntity);
details::UpdateComponentWidget<engine::CollisionMeshComponent>(pSceneWorld, m_lastSelectedEntity);
details::UpdateComponentWidget<engine::BlendShapeComponent>(pSceneWorld, m_lastSelectedEntity);

Expand Down
1 change: 0 additions & 1 deletion Engine/Source/Runtime/ECWorld/AllComponentsHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
#include "ECWorld/StaticMeshComponent.h"
#include "ECWorld/TerrainComponent.h"
#include "ECWorld/TransformComponent.h"
#include "ECWorld/ParticleComponent.h"
#include "ECWorld/ParticleEmitterComponent.h"
1 change: 0 additions & 1 deletion Engine/Source/Runtime/ECWorld/ParticleComponent.cpp

This file was deleted.

30 changes: 0 additions & 30 deletions Engine/Source/Runtime/ECWorld/ParticleComponent.h

This file was deleted.

Loading
Loading