2
3
4
5
9#include "Resources/Loader/GltfLoader.h"
10#include "World/Entity.h"
11#include "World/World/World.h"
12#include "World/Components/MeshComponent.h"
13#include "World/Components/EntityComponent.h"
14#include "Resources/Mesh/GltfPack.h"
15#include "Core/Math/Math.h"
16#include "Slate/SlateInfoBar.h"
31 const std::shared_ptr<
LoadingState> loadingState = std::make_shared<LoadingState>();
34
35
36 for (
auto& item : m_Scenes->m_ScenesData)
38 for (
const auto& node : item.nodes)
40 CreateEntityRecursive(world, tag, node, transform.ToMatrix(), loadingState);
45
46
48 ss <<
"GLTF: " << tag <<
" is on Loading...";
50 auto self = shared_from_this();
51 SlateInfoBar::Create<
float>(ss.str(), [=]() ->
float {
52 return static_cast<
float>(loadingState->loadedMeshes.load()) /
static_cast<
float>(self->m_Meshes->GetNMeshes());
53 }, [=](SlateInfoBar* that) {
54 return std::any_cast<
float>(that->GetRate()) >= 1.0f;
62 const std::string& tag ,
64 const glm::mat4& model ,
71
72
73 auto self = shared_from_this();
84 DecomposeTransform(model * item.matrix, position, rotation, scale);
85 rotation = glm::vec3(glm::degrees(rotation.x), glm::degrees(rotation.y), glm::degrees(rotation.z));
87 transformComp.SetPosition(position);
88 transformComp.SetRotation(rotation);
89 transformComp.SetScale(scale);
92 std::vector<Entity> childrens;
94 for (
auto& n : item.children)
96 childrens.push_back(CreateEntityRecursive(world, tag, n, item.matrix, loadingState));
99 if (!childrens.empty())
103 for (
auto& e : childrens)
105 entityComp.AddEntity(e);
109 if (item
.mesh < -0.5f)
116 for (
int i = 0; i < self->m_Meshes->m_MeshesData[item.mesh].primitives.size(); i++)
118 std::stringstream ss;
119 ss << self->m_Meshes->m_MeshesData[item.mesh].name <<
'_' << node;
121 std::shared_ptr<GltfPack> pack = std::make_shared<GltfPack>(ss.str(), [&](GltfPack* gltfPack) {
122 GltfLoader::LoadPack(gltfPack, self->m_Meshes->m_MeshesData[item.mesh].primitives[i], self->m_Accessors.get(), self->m_Buffers.get(), self->m_BufferViews.get());
125 std::shared_ptr<Material> material = GltfLoader::LoadMaterial(self->m_Materials->m_MaterialsData[self->m_Meshes->m_MeshesData[item.mesh].primitives[i].material], self->m_Images.get());
127 pack->SetMaterial(material);
129 builder.AddPack(pack);
132 std::shared_ptr<
Mesh> mesh = builder.Build();
136 meshComp.SetMesh(mesh);
#define SPICES_PROFILE_ZONE
EntityComponent Class. This class defines the specific behaves of EntityComponent.
Entity Class. This class defines the specific behaves of Entity.
Entity CreateEntityRecursive(World *world, const std::string &tag, uint32_t node, const glm::mat4 &model, std::shared_ptr< LoadingState > loadingState)
Create Entity recursive from gltf file nodes.
GltfCollection(const std::string &path)
Constructor Function.
void CreateEntity(World *world, const std::string &tag, Transform transform={})
Create Entity instance from gltf file.
Wrapper of Gltf file data.
static bool Load(const std::string &fileName, GltfCollection *collection)
Load a gltf file to GltfCollection.
Loader of load gltf file or items.
Wrapper of Gltf Json Nodes.
MeshComponent Class. This class defines the specific behaves of MeshComponent.
Builder Class. This class helps to create a mesh.
MeshRenderer Class. This class is a wrapper of mashpack.
void Mark(WorldMarkFlags flags)
Mark WorldMarkFlags with flags.
Entity CreateEntity(const std::string &name="None")
Create a new empty entity in this world.
World Class. This class defines the basic behaves of World. When we create an new world,...