CSEngine
Loading...
Searching...
No Matches
DAELoader.h
1#pragma once
2
3#include <iostream>
4#include "../../../Object/SPrefab.h"
5#include "DAEUtil/VertexSkinData.h"
6#include "DAEUtil/SkinningData.h"
7#include "../../Animation/Skeleton.h"
8#include "../XML/XML.h"
9#include "DAEUtil/Vertex.h"
10#include "../../Render/MeshSurface.h"
11#include "DAEAnimationLoader.h"
12#include "../../Animation/Animation.h"
13
14namespace CSE {
15
16 class Animation;
17
18 class DAELoader {
19 public:
20 enum LOAD_TYPE {
21 ALL, MESH, ANIMATION, AUTO, NOTHING
22 };
23 private:
24 class DAEMeshData {
25 public:
26 DAEMeshData() {
27 meshSurface = new MeshSurface();
28 };
29 ~DAEMeshData() {
30 std::cout << "\ndeleting " << vertices.size() << " DAE Vertexes...\n";
31 for (auto vertex : vertices) {
32 SAFE_DELETE(vertex);
33 }
34 vertices.clear();
35 }
36
37 MeshSurface* meshSurface;
38 std::vector<Vertex*> vertices;
39 std::vector<vec3> normals;
40 std::vector<vec2> texUVs;
41 std::vector<int> indices;
42 std::string meshName;
43 };
44 enum POLYGON_TYPE {
45 POLYLIST = -1, TRIANGLES = 3,
46 };
47 public:
48 DAELoader(const char* path, LOAD_TYPE type, bool isLoad);
49
50 ~DAELoader();
51
52 void Load(const char* path, LOAD_TYPE type);
53
54 void LoadTexture(const AssetMgr::AssetReference* asset);
55
56 Skeleton* getSkeleton() const {
57 return m_skeletonData;
58 }
59
60 SPrefab* GeneratePrefab(Animation* animation, SPrefab* prefab = nullptr);
61
62 static SPrefab* GeneratePrefab(const char* path, Skeleton* skeleton, MeshSurface* mesh, Animation* animation,
63 SPrefab* prefab = nullptr);
64
65 private:
66 bool LoadSkin(const XNode& root_s);
67
68 bool LoadSkeleton(const XNode& root_s);
69
70 bool LoadGeometry(const XNode& root_g, DAEMeshData* meshData);
71
72//===================================================================
73// GeometryLoader Functions
74//===================================================================
75 void ReadPositions(const XNode& data, std::vector<VertexSkinData*> vertexWeight, DAEMeshData* meshData) const;
76
77 static void ReadNormals(const XNode& data, const std::string& normalsId, DAEMeshData* meshData);
78
79 static void ReadUVs(const XNode& data, const std::string& texCoordsId, DAEMeshData* meshData);
80
81 void AssembleVertices(const XNode& data, DAEMeshData* meshData);
82
83 Vertex* processVertex(int posIndex, int normIndex, int texIndex, DAEMeshData* meshData);
84
85 Vertex* dealWithAlreadyProcessedVertex(Vertex* previousVertex, int newTextureIndex, int newNormalIndex,
86 DAEMeshData* meshData);
87
88 static void removeUnusedVertices(DAEMeshData* meshData);
89
90 void ConvertDataToVectors(DAEMeshData* meshData) const;
91
92//===================================================================
93// SkinLoader Functions
94//===================================================================
95 static std::vector<std::string> loadJointsList(const XNode& skinningData);
96
97 static std::vector<float> loadWeights(const XNode& skinningData);
98
99 std::vector<int> getEffectiveJointsCounts(const XNode& node);
100
101 std::vector<VertexSkinData*>
102 getSkinData(const XNode& weightsDataNode, const std::vector<int>& counts, std::vector<float> weights) const;
103
104//===================================================================
105// SkeletonLoader Functions
106//===================================================================
107
108 Joint* loadJointData(const XNode& jointNode, bool isRoot);
109
110 Joint* extractMainJointData(const XNode& jointNode, bool isRoot);
111
112 void LoadTexturePath(const XNode& imageNode);
113
114
115 static void AttachDataToObjSurface(int vertices_size, std::vector<float> vertices, std::vector<float> normals,
116 std::vector<float> texUVs, std::vector<int> indices, std::vector<short> jointIDs,
117 std::vector<float> weights, DAEMeshData* meshData);
118
119 void Exterminate();
120
121 private:
122 const XNode* m_root{};
123
124 std::vector<DAEMeshData*> m_meshList;
125
126
127 SkinningData* m_skinningData = nullptr;
128 Skeleton* m_skeletonData = nullptr;
129 DAEAnimationLoader* m_animationLoader = nullptr;
130
131
132 int m_maxWeight = 3;
133 int m_jointSize = 0;
134
135 bool m_isSkinning = false;
136 POLYGON_TYPE m_polygonType = POLYGON_TYPE::POLYLIST;
137
138 std::string m_name;
139 std::string m_texture_name;
140
141 std::string m_resource_id;
142
143 };
144}
Definition XML.h:43