Skip to content

Commit

Permalink
conflict fix
Browse files Browse the repository at this point in the history
  • Loading branch information
OVOAOVO committed Feb 21, 2024
1 parent c953111 commit 6399646
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
62 changes: 59 additions & 3 deletions Engine/Source/Editor/ECWorld/ECWorldConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,41 @@ void ECWorldConsumer::Execute(const cd::SceneDatabase* pSceneDatabase)
}
};

auto ParseMeshWithParticles= [&](cd::MeshID meshID, const cd::ParticleEmitter& emitter)
{
engine::Entity meshEntity = m_pSceneWorld->GetWorld()->CreateEntity();

engine::MaterialType* pMaterialType = m_pSceneWorld->GetParticleMaterialType();

const auto& mesh = pSceneDatabase->GetMesh(meshID.Data());
AddParticleEmitter(meshEntity, mesh, pMaterialType->GetRequiredVertexFormat(),emitter);
};

// There are multiple kinds of cases in the SceneDatabase:
// 1. No nodes but have meshes in the SceneDatabase.
// 2. Only a root node with multiple meshes.
// 3. Node hierarchy.
// Another case is that we want to skip Node/Mesh which alreay parsed previously.
std::set<uint32_t> parsedMeshIDs;
m_particleMinID = 0;
for (const auto& mesh : pSceneDatabase->GetMeshes())
{
if (m_meshMinID > mesh.GetID().Data())
{
continue;
}

ParseMesh(mesh.GetID(), cd::Transform::Identity());
parsedMeshIDs.insert(mesh.GetID().Data());

if (pSceneDatabase->GetParticleEmitterCount())
{
ParseMeshWithParticles(mesh.GetID(), pSceneDatabase->GetParticleEmitter(m_particleMinID));
parsedMeshIDs.insert(mesh.GetID().Data());
++m_particleMinID;
}
else
{
ParseMesh(mesh.GetID(), cd::Transform::Identity());
parsedMeshIDs.insert(mesh.GetID().Data());
}
}

for (const auto& node : pSceneDatabase->GetNodes())
Expand Down Expand Up @@ -384,4 +404,40 @@ void ECWorldConsumer::AddBlendShape(engine::Entity entity, const cd::Mesh* pMesh
blendShapeComponent.Build();
}

void ECWorldConsumer::AddParticleEmitter(engine::Entity entity, const cd::Mesh& mesh, const cd::VertexFormat& vertexFormat, const cd::ParticleEmitter& emitter)
{
engine::World* pWorld = m_pSceneWorld->GetWorld();
engine::NameComponent& nameComponent = pWorld->CreateComponent<engine::NameComponent>(entity);
nameComponent.SetName(emitter.GetName());
auto& particleEmitterComponent = pWorld->CreateComponent<engine::ParticleEmitterComponent>(entity);
// TODO : Some initialization here.
auto& transformComponent = pWorld->CreateComponent<engine::TransformComponent>(entity);
cd::Vec3f pos = emitter.GetPosition();
cd::Vec3f rotation = emitter.GetFixedRotation();
cd::Vec3f scale = emitter.GetFixedScale();
auto fixedrotation = cd::Math::RadianToDegree(rotation);
cd::Quaternion rotationQuat = cd::Quaternion::FromPitchYawRoll(fixedrotation.x(), fixedrotation.y(), fixedrotation.z());
transformComponent.GetTransform().SetTranslation(pos);
transformComponent.GetTransform().SetRotation(rotationQuat);
transformComponent.GetTransform().SetScale(scale);
transformComponent.Build();

particleEmitterComponent.SetRequiredVertexFormat(&vertexFormat);
////const cd::VertexFormat *requriredVertexFormat = emitter.GetVertexFormat();
////particleEmitterComponent.SetRequiredVertexFormat(requriredVertexFormat);
////particleEmitterComponent.GetParticleSystem().Init();
if (nameof::nameof_enum(emitter.GetType()) == "Sprite") { particleEmitterComponent.SetEmitterParticleType(engine::ParticleType::Sprite); }
else if (nameof::nameof_enum(emitter.GetType()) == "Ribbon") { particleEmitterComponent.SetEmitterParticleType(engine::ParticleType::Ribbon); }
else if (nameof::nameof_enum(emitter.GetType()) == "Ring") { particleEmitterComponent.SetEmitterParticleType(engine::ParticleType::Ring); }
else if (nameof::nameof_enum(emitter.GetType()) == "Model") { particleEmitterComponent.SetEmitterParticleType(engine::ParticleType::Model); }
else if (nameof::nameof_enum(emitter.GetType()) == "Track") { particleEmitterComponent.SetEmitterParticleType(engine::ParticleType::Track); }

particleEmitterComponent.SetSpawnCount(emitter.GetMaxCount());
particleEmitterComponent.SetEmitterColor(emitter.GetColor()/255.0f);
particleEmitterComponent.SetEmitterVelocity(emitter.GetVelocity());
particleEmitterComponent.SetEmitterAcceleration(emitter.GetAccelerate());
particleEmitterComponent.SetMeshData(&mesh);
particleEmitterComponent.Build();
}

}
2 changes: 1 addition & 1 deletion Engine/Source/Editor/ECWorld/ECWorldConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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 AddBlendShape(engine::Entity entity, const cd::Mesh* pMesh, const cd::BlendShape& blendShape, const cd::SceneDatabase* pSceneDatabase);

void AddParticleEmitter(engine::Entity entity, const cd::Mesh& mesh, const cd::VertexFormat& vertexFormat, const cd::ParticleEmitter& emitter);
private:
engine::MaterialType* m_pDefaultMaterialType = nullptr;
engine::SceneWorld* m_pSceneWorld = nullptr;
Expand Down

0 comments on commit 6399646

Please sign in to comment.