CSEngine
Loading...
Searching...
No Matches
CSE::DAELoader Class Reference

Public Types

enum  LOAD_TYPE {
  ALL , MESH , ANIMATION , AUTO ,
  NOTHING
}
 

Public Member Functions

 DAELoader (const char *path, LOAD_TYPE type, bool isLoad)
 
void Load (const char *path, LOAD_TYPE type)
 
void LoadTexture (const AssetMgr::AssetReference *asset)
 
SkeletongetSkeleton () const
 
SPrefabGeneratePrefab (Animation *animation, SPrefab *prefab=nullptr)
 

Static Public Member Functions

static SPrefabGeneratePrefab (const char *path, Skeleton *skeleton, MeshSurface *mesh, Animation *animation, SPrefab *prefab=nullptr)
 

Detailed Description

Definition at line 18 of file DAELoader.h.

Member Enumeration Documentation

◆ LOAD_TYPE

enum CSE::DAELoader::LOAD_TYPE

Definition at line 20 of file DAELoader.h.

20 {
21 ALL, MESH, ANIMATION, AUTO, NOTHING
22 };

Constructor & Destructor Documentation

◆ DAELoader()

DAELoader::DAELoader ( const char *  path,
LOAD_TYPE  type,
bool  isLoad 
)

Definition at line 16 of file DAELoader.cpp.

16 {
17 if (type == NOTHING) return;
18
19 if (isLoad) Load(path, type);
20}

◆ ~DAELoader()

DAELoader::~DAELoader ( )

Definition at line 22 of file DAELoader.cpp.

22 {
23 Exterminate();
24}

Member Function Documentation

◆ GeneratePrefab() [1/2]

SPrefab * DAELoader::GeneratePrefab ( Animation animation,
SPrefab prefab = nullptr 
)

Definition at line 519 of file DAELoader.cpp.

519 {
520 if (prefab == nullptr)
521 prefab = new SPrefab();
522 auto* root = new SGameObjectFromSPrefab(m_name);
523 prefab->SetGameObject(root);
524
525 SGameObject* joint_root = nullptr;
526
527 if (m_isSkinning) {
528 joint_root = new SGameObjectFromSPrefab("Armature");
529 root->AddChild(joint_root);
530 DAEConvertSGameObject::CreateJoints(joint_root, m_skeletonData->getHeadJoint());
531 }
532
533 JointComponent* joint_root_component = m_isSkinning ? joint_root->GetChildren().front()->GetComponent<JointComponent>() : nullptr;
534 for (const auto& mesh : m_meshList) {
535 auto* mesh_root = new SGameObjectFromSPrefab(mesh->meshName);
536 root->AddChild(mesh_root);
537 DrawableStaticMeshComponent* mesh_component = nullptr;
538
539 if (m_isSkinning) {
540 mesh_component = mesh_root->CreateComponent<DrawableSkinnedMeshComponent>();
541 } else {
542 mesh_component = mesh_root->CreateComponent<DrawableStaticMeshComponent>();
543 }
544
545 mesh_component->SetMesh(*mesh->meshSurface);
546
547 if (m_isSkinning)
548 dynamic_cast<DrawableSkinnedMeshComponent*>(mesh_component)->SetRootJoint(
549 joint_root_component->GetGameObject(),
550 m_skeletonData->getJointCount());
551
552 auto renderComponent = mesh_root->CreateComponent<RenderComponent>();
553// mesh_root->GetComponent<RenderComponent>()->SetShaderHandle("PBR.shader");
554 }
555
556 if (m_isSkinning) {
557 SGameObject* animationObj = DAEConvertSGameObject::CreateAnimation(root, joint_root_component,
558 m_animationLoader->GetAnimation(),
559 m_name, animation);
560 }
561
562 return prefab;
563}

◆ GeneratePrefab() [2/2]

SPrefab * DAELoader::GeneratePrefab ( const char *  path,
Skeleton skeleton,
MeshSurface mesh,
Animation animation,
SPrefab prefab = nullptr 
)
static

Definition at line 565 of file DAELoader.cpp.

566 {
567 auto* loader = new DAELoader(path, AUTO, false);
568 auto asset = CORE->GetCore(ResMgr)->GetAssetReference(path);
569 if (asset == nullptr) {
570 SAFE_DELETE(loader);
571 return nullptr;
572 }
573 std::string prefab_id = asset->id;
574
575 loader->m_resource_id = asset->id;
576 loader->m_skeletonData = skeleton;
577
578 if (loader->m_skeletonData == nullptr) {
579 loader->m_skeletonData = new Skeleton();
580 }
581
582 const auto& meshData = loader->m_meshList;
583 for (const auto& mesh : meshData) {
584 mesh->meshSurface->LinkResource(prefab_id + "." + mesh->meshName +"?mesh");
585 }
586 loader->m_skeletonData->LinkResource(prefab_id + "?skeleton");
587
588 loader->Load(path, AUTO);
589 prefab = loader->GeneratePrefab(animation, prefab);
590
591 SAFE_DELETE(loader);
592 return prefab;
593}

◆ getSkeleton()

Skeleton * CSE::DAELoader::getSkeleton ( ) const
inline

Definition at line 56 of file DAELoader.h.

56 {
57 return m_skeletonData;
58 }

◆ Load()

void DAELoader::Load ( const char *  path,
LOAD_TYPE  type 
)

Definition at line 26 of file DAELoader.cpp.

26 {
27 {
28 std::string path_str = path;
29 std::size_t index = path_str.rfind('/');
30 if (index == std::string::npos) {
31 index = path_str.rfind('\\');
32 }
33 std::size_t name_index = path_str.rfind('.');
34
35 m_name = path_str.substr(index + 1, name_index - index - 1);
36 }
37
38 m_root = XFILE(path).getRoot();
39 XNode collada = m_root->getChild("COLLADA");
40
41 if (type == LOAD_TYPE::MESH || type == LOAD_TYPE::ALL || type == LOAD_TYPE::AUTO) {
42 try {
43 bool safe_result;
44 if(collada.hasChild("library_controllers") && collada.hasChild("library_visual_scenes")) {
45 safe_result = LoadSkin(collada.getChild("library_controllers"));
46 safe_result &= LoadSkeleton(collada.getChild("library_visual_scenes"));
47 }
48 else
49 safe_result = false;
50 m_isSkinning = safe_result;
51 } catch (int error) {
52 std::cout << "passing skinning...\n";
53 m_isSkinning = false;
54 }
55
56 try {
57 if(collada.hasChild("library_images"))
58 LoadTexturePath(collada.getChild("library_images"));
59 else
60 std::cout << "passing texture...\n";
61 } catch (int error) {
62 std::cout << "passing texture...\n";
63 }
64
65 try {
66 const auto& geometryData = collada.getChild("library_geometries").children;
67 m_meshList.reserve(geometryData.size());
68
69 for (const auto& geometry : geometryData) {
70 auto meshData = new DAEMeshData();
71 meshData->meshName = geometry.getAttribute("id").value;
72 LoadGeometry(geometry, meshData);
73 m_meshList.push_back(meshData);
74 }
75 } catch (int error) {
76 std::cout << "passing geometry...\n";
77 }
78 }
79 if (type == ANIMATION || type == ALL || type == AUTO) {
80 try {
81 bool safe_exception;
82 m_animationLoader = new DAEAnimationLoader();
83 safe_exception = m_animationLoader->Load(path, m_name);
84#ifdef __EMSCRIPTEN__
85 if(!safe_exception) {
86 SAFE_DELETE(m_animationLoader);
87 }
88#endif
89 } catch (int error) {
90 SAFE_DELETE(m_animationLoader);
91 std::cout << "passing Animation...\n";
92 }
93 }
94// LoadTexture(texture_path);
95}
Definition XML.h:77
Definition XML.h:43

◆ LoadTexture()

void DAELoader::LoadTexture ( const AssetMgr::AssetReference asset)

Definition at line 98 of file DAELoader.cpp.

98 {
99 if (asset == nullptr) return;
100
101 auto* texture = SResource::Create<STexture>(asset);
102 m_texture_name = texture->GetName();
103}

The documentation for this class was generated from the following files: