Skip to content

Commit

Permalink
init EffekseerProducer about parsing sprite effect node (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
OVOAOVO authored Dec 12, 2023
1 parent e7f2343 commit 4a251fe
Show file tree
Hide file tree
Showing 13 changed files with 660 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/Prototype/Effekseer/EffekseerToCD/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main(int argc, char** argv)
PerformanceProfiler profiler("AssetPipeline");

// TODO : how to input char16_t string from argv?
const char16_t* pInputFilePath = u"S:/Effekseer/Examples/Resources/Laser01.efkefc";
const char16_t* pInputFilePath = u"D:/Effekseer/sample/03_01_Sample/03_01_Sample/effect.efkefc";
const char* pOutputFilePath = argv[2];
EffekseerProducer producer(pInputFilePath);
CDConsumer consumer(pOutputFilePath);
Expand Down
175 changes: 160 additions & 15 deletions private/Producers/EffekseerProducer/EffekseerProducerImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,182 @@
#include "EffekseerProducerImpl.h"

#include "Producers/EffekseerProducer/EffekseerProducer.h"

#include <Effekseer.h>
#include <Effekseer.Modules.h>

#include <codecvt>

namespace cdtools
{

static std::map<Effekseer::EffectNodeType, cd::ParticleEmitterType> EffectNodeTypeMapping = {
{ Effekseer::EffectNodeType::Root, cd::ParticleEmitterType::Root },
{ Effekseer::EffectNodeType::NoneType, cd::ParticleEmitterType::None },
{ Effekseer::EffectNodeType::Sprite, cd::ParticleEmitterType::Sprite },
{ Effekseer::EffectNodeType::Ribbon, cd::ParticleEmitterType::Ribbon },
{ Effekseer::EffectNodeType::Ring, cd::ParticleEmitterType::Ring },
{ Effekseer::EffectNodeType::Model, cd::ParticleEmitterType::Model },
{ Effekseer::EffectNodeType::Track, cd::ParticleEmitterType::Track },
};

EffekseerProducerImpl::EffekseerProducerImpl(const char16_t* pFilePath) :
m_pFilePath(pFilePath)
{
}

void EffekseerProducerImpl::PushAllColor(Effekseer::AllTypeColorParameter* pAllColor)
{
if (pAllColor->type == pAllColor->Fixed)
{
m_fixedColor.push_back(pAllColor->fixed.all);
}
else if (pAllColor->type == pAllColor->Random)
{

}
else if (pAllColor->type == pAllColor->Easing)
{

}
//TODO : there still have some num to analysis
}

void EffekseerProducerImpl::JudgeRotationType(Effekseer::RotationParameter* pParameter)
{
if (pParameter->RotationType == Effekseer::ParameterRotationType::ParameterRotationType_Fixed)
{
m_fixedRotation.push_back(pParameter->RotationFixed.Position);
}
else if (pParameter->RotationType == Effekseer::ParameterRotationType::ParameterRotationType_PVA)
{

}
else if (pParameter->RotationType == Effekseer::ParameterRotationType::ParameterRotationType_Easing)
{

}
///TODO: there still some num to analysis
}

void EffekseerProducerImpl::PushRotate(Effekseer::EffectNodeSprite* pNode)
{

if (pNode->Billboard == Effekseer::BillboardType::Billboard)
{
//NO Rotation
JudgeRotationType(&pNode->RotationParam);
}
else if (pNode->Billboard == Effekseer::BillboardType::RotatedBillboard)
{
//Z Rotation
JudgeRotationType(&pNode->RotationParam);
}
else if (pNode->Billboard == Effekseer::BillboardType::YAxisFixed)
{
//Y Rotation
JudgeRotationType(&pNode->RotationParam);
}
else if (pNode->Billboard == Effekseer::BillboardType::Fixed)
{
// XYZ Rotation
JudgeRotationType(&pNode->RotationParam);
}
}

void EffekseerProducerImpl::PushScale(Effekseer::EffectNodeSprite* pNode)
{
if (pNode->ScalingParam.ScalingType == Effekseer::ParameterScalingType::ParameterScalingType_Fixed)
{
m_fixedScale.push_back(pNode->ScalingParam.ScalingFixed.Position);
}
else if (pNode->ScalingParam.ScalingType == Effekseer::ParameterScalingType::ParameterScalingType_PVA)
{

}
///TODO: there still some num to analysis
}

void EffekseerProducerImpl::TraverseNodeRecursively(Effekseer::EffectNode* pNode)
{
Effekseer::EffectNodeType nodeType = pNode->GetType();
if (Effekseer::EffectNodeType::Sprite == nodeType)
{
//PVA
m_particleType.push_back(nodeType);
auto* pSpriteNode = static_cast<Effekseer::EffectNodeSprite*>(pNode);
m_particlePos.push_back(pSpriteNode->TranslationParam.TranslationPVA.location);
m_particleVelocity.push_back(pSpriteNode->TranslationParam.TranslationPVA.velocity);
m_particleAccelerate.push_back(pSpriteNode->TranslationParam.TranslationPVA.acceleration);
PushAllColor(&pSpriteNode->SpriteAllColor);
PushRotate(pSpriteNode);
PushScale(pSpriteNode);
return;
}
else if (Effekseer::EffectNodeType::Ribbon == nodeType)
{

}
else if (Effekseer::EffectNodeType::Track == nodeType)
{

}
else if (Effekseer::EffectNodeType::Ring == nodeType)
{

}
else if (Effekseer::EffectNodeType::Model == nodeType)
{

}


int childNodeCount = pNode->GetChildrenCount();
for (int childIndex = 0; childIndex < childNodeCount; ++childIndex)
{
TraverseNodeRecursively(pNode->GetChild(childIndex));
}
}


void EffekseerProducerImpl::Execute(cd::SceneDatabase* pSceneDatabase)
{
auto efkManager = ::Effekseer::Manager::Create(8000);
auto effect = Effekseer::Effect::Create(efkManager, m_pFilePath);
auto* pEffectData = effect.Get();

// Mesh
pEffectData->GetProceduralModelCount();
pEffectData->GetWaveCount();

// Materials and ParticleEmitter
pEffectData->GetMaterialCount();
pEffectData->GetLoadingParameter();
pEffectData->GetDefaultDynamicInputs();

// Texture
pEffectData->GetColorImageCount();
pEffectData->GetDistortionImageCount();

// Track
pEffectData->GetCurveCount();
//ID name
const char16_t* pEffectName = pEffectData->GetName();
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
std::u16string u16str = pEffectName;
std::string str = converter.to_bytes(u16str);
const char* pAllParticleEmitterName = str.c_str();

// pos velocity scale
// TODO : check other properties.
TraverseNodeRecursively(pEffectData->GetRoot());
for (int i = 0; i < pEffectData->GetRoot()->GetChildrenCount(); i++)
{
cd::ParticleEmitterID::ValueType particleEmitterHash = cd::StringHash<cd::ParticleEmitterID::ValueType>(pAllParticleEmitterName + i);
cd::ParticleEmitterID particleEmitterID = m_particleEmitterIDGenerator.AllocateID(particleEmitterHash);

cd::ParticleEmitter particleEmitter(particleEmitterID, std::format("{}{}", pAllParticleEmitterName, i).c_str());
particleEmitter.SetType(EffectNodeTypeMapping[static_cast<Effekseer::EffectNodeType>(m_particleType[i])]);
particleEmitter.SetPosition(MeanXYZ(m_particlePos[i].max, m_particlePos[i].min));
particleEmitter.SetVelocity(MeanXYZ(m_particleVelocity[i].max, m_particleVelocity[i].min));
particleEmitter.SetAccelerate(MeanXYZ(m_particleAccelerate[i].max, m_particleAccelerate[i].min));
particleEmitter.SetColor(cd::Vec4f(m_fixedColor[i].R, m_fixedColor[i].G, m_fixedColor[i].B, m_fixedColor[i].A));
particleEmitter.SetFixedRotation(cd::Vec3f(m_fixedRotation[i].X, m_fixedRotation[i].Y, m_fixedRotation[i].Z));
particleEmitter.SetFixedScale(cd::Vec3f(m_fixedScale[i].X, m_fixedScale[i].Y, m_fixedScale[i].Z));

pSceneDatabase->AddParticleEmitter(cd::MoveTemp(particleEmitter));
}
//// Mesh
//auto a = pEffectData->GetName();

//auto b = pEffectData->GetColorImageCount();
//
//auto c = pEffectData->GetColorImagePath(0);
}

}
28 changes: 28 additions & 0 deletions private/Producers/EffekseerProducer/EffekseerProducerImpl.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#pragma once

#include "Base/Template.h"
#include "Hashers/StringHash.hpp"
#include "Scene/ObjectIDGenerator.h"
#include "Scene/SceneDatabase.h"

#include "Effekseer/Effekseer.EffectImplemented.h"
#include "Effekseer/Effekseer.EffectNode.h"
#include "Effekseer/Effekseer.EffectNodeSprite.h"

namespace cdtools
{

Expand All @@ -17,10 +23,32 @@ class EffekseerProducerImpl final
EffekseerProducerImpl& operator=(EffekseerProducerImpl&&) = delete;
~EffekseerProducerImpl() = default;

void TraverseNodeRecursively(Effekseer::EffectNode* pNode);

void PushAllColor(Effekseer::AllTypeColorParameter* AllColor);

void PushRotate(Effekseer::EffectNodeSprite* pNode);

void PushScale(Effekseer::EffectNodeSprite* pNode);

void JudgeRotationType(Effekseer::RotationParameter* Type);

void Execute(cd::SceneDatabase* pSceneDatabase);

cd::Vec3f MeanXYZ(Effekseer::vector3d max, Effekseer::vector3d min) { return cd::Vec3f(((max.x + min.x) / 2), ((max.y + min.y) / 2), ((max.z + min.z) / 2)); }
cd::Vec3f DevXYZ(Effekseer::vector3d max, Effekseer::vector3d min) { return cd::Vec3f(((max.x - min.x) / 2), ((max.y - min.y) / 2), ((max.z - min.z) / 2)); }

private:
const char16_t* m_pFilePath;
std::vector<Effekseer::EffectNodeType> m_particleType;
std::vector<Effekseer::random_vector3d> m_particlePos;
std::vector<Effekseer::random_vector3d> m_particleVelocity;
std::vector<Effekseer::random_vector3d> m_particleAccelerate;
std::vector<Effekseer::Color> m_fixedColor;
std::vector<Effekseer::Vector3D> m_fixedRotation;
std::vector<Effekseer::Vector3D> m_fixedScale;

cd::ObjectIDGenerator<cd::ParticleEmitterID> m_particleEmitterIDGenerator;
};

}
Loading

0 comments on commit 4a251fe

Please sign in to comment.