Skip to content

Commit 76b4b63

Browse files
author
Dominik Ospelt
committed
SceneLoader: working on creating entire scenes
1 parent 74089f7 commit 76b4b63

8 files changed

+101
-271
lines changed

doc/Assumptions.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Meshes in loaded files have unique names
2+
- Eeach component is bound max once per scene node
3+
- Components can be attached to multiple nodes

src/KoRE/MeshLoader.h

+36-37
Original file line numberDiff line numberDiff line change
@@ -32,52 +32,51 @@
3232

3333

3434
namespace kore {
35-
class MeshLoader {
36-
public:
37-
static MeshLoader* getInstance();
38-
~MeshLoader();
35+
class MeshLoader {
36+
public:
37+
static MeshLoader* getInstance();
38+
virtual ~MeshLoader();
3939

40-
SceneNodePtr loadScene(const std::string& szScenePath,
41-
const bool bUseBuffers);
42-
MeshPtr loadSingleMesh(const std::string& szMeshPath,
43-
const bool bUseBuffers);
40+
SceneNodePtr loadScene(const std::string& szScenePath,
41+
const bool bUseBuffers);
42+
MeshPtr loadSingleMesh(const std::string& szMeshPath,
43+
const bool bUseBuffers);
4444

45-
private:
46-
MeshLoader();
47-
const aiScene* readScene(const std::string& szScenePath);
45+
kore::MeshPtr loadMesh(const aiScene* paiScene,
46+
const uint uMeshIdx,
47+
const bool bUseBuffers = true);
4848

49-
void loadChildNode(const aiScene* paiScene,
50-
const aiNode* paiNode,
51-
SceneNodePtr& parentNode,
52-
const bool bUseBuffers);
49+
private:
50+
MeshLoader();
51+
const aiScene* readScene(const std::string& szScenePath);
5352

54-
kore::MeshPtr loadMesh(const aiScene* paiScene,
55-
const uint uMeshIdx,
56-
const bool bUseBuffers);
53+
void loadChildNode(const aiScene* paiScene,
54+
const aiNode* paiNode,
55+
SceneNodePtr& parentNode,
56+
const bool bUseBuffers);
57+
void loadVertexPositions(const aiMesh* pAiMesh,
58+
kore::MeshPtr& pMesh);
5759

58-
void loadVertexPositions(const aiMesh* pAiMesh,
59-
kore::MeshPtr& pMesh);
60+
void loadVertexNormals(const aiMesh* pAiMesh,
61+
kore::MeshPtr& pMesh);
6062

61-
void loadVertexNormals(const aiMesh* pAiMesh,
62-
kore::MeshPtr& pMesh);
63+
void loadVertexTangents(const aiMesh* pAiMesh,
64+
kore::MeshPtr& pMesh);
6365

64-
void loadVertexTangents(const aiMesh* pAiMesh,
65-
kore::MeshPtr& pMesh);
66+
void loadFaceIndices(const aiMesh* pAiMesh,
67+
kore::MeshPtr& pMesh);
6668

67-
void loadFaceIndices(const aiMesh* pAiMesh,
68-
kore::MeshPtr& pMesh);
69+
void loadVertexTextureCoords(const aiMesh* pAiMesh,
70+
kore::MeshPtr& pMesh,
71+
const unsigned int iUVset);
6972

70-
void loadVertexTextureCoords(const aiMesh* pAiMesh,
71-
kore::MeshPtr& pMesh,
72-
const unsigned int iUVset);
73+
void loadVertexColors(const aiMesh* pAiMesh,
74+
kore::MeshPtr& pMesh,
75+
const unsigned int iColorSet);
7376

74-
void loadVertexColors(const aiMesh* pAiMesh,
75-
kore::MeshPtr& pMesh,
76-
const unsigned int iColorSet);
77+
glm::mat4 glmMatFromAiMat(const aiMatrix4x4& aiMat);
7778

78-
glm::mat4 glmMatFromAiMat(const aiMatrix4x4& aiMat);
79-
80-
Assimp::Importer _aiImporter;
81-
};
82-
}
79+
Assimp::Importer _aiImporter;
80+
};
81+
};
8382
#endif // CORE_INCLUDE_CORE_MESHLOADER_H_

src/KoRE/ResourceManager.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ void kore::ResourceManager::loadScene(const std::string& filename, SceneNodePtr
4242
kore::SceneLoader::getInstance()->loadScene(filename, parent);
4343
}
4444

45+
void kore::ResourceManager::loadResources(const std::string& filename) {
46+
kore::SceneLoader::getInstance()->loadRessources(filename);
47+
}
48+
49+
// deprecated
4550
kore::MeshPtr
4651
kore::ResourceManager::loadSingleMesh(const std::string& filename,
4752
uint importFlags) {
@@ -51,3 +56,11 @@ kore::ResourceManager::loadSingleMesh(const std::string& filename,
5156
MeshLoader::getInstance()->loadSingleMesh(filename, bUseBuffers);
5257
return pNewScene;
5358
}
59+
60+
void kore::ResourceManager::addMesh(const std::string& path, MeshPtr mesh) {
61+
_meshes[path][mesh->getName()] = mesh;
62+
}
63+
64+
kore::MeshPtr kore::ResourceManager::getMesh(const std::string& path, const std::string& id) {
65+
return _meshes[path][id];
66+
}

src/KoRE/ResourceManager.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,26 @@ namespace kore {
3838
class ResourceManager {
3939
public:
4040
static ResourceManager *getInstance(void);
41-
// reads a scene file and creates all nodes and components within a scenegraph
41+
// reads a scene file and creates all nodes and components within a scene graph
4242
void loadScene(const std::string& filename,
4343
SceneNodePtr parent =
4444
kore::SceneManager::getInstance()
4545
->getRootNode());
46+
// adds all resources from a specific file
47+
void loadResources(const std::string& filename);
48+
49+
// deprecated
4650
kore::MeshPtr loadSingleMesh(const std::string& filename, uint importFlags);
51+
52+
void addMesh(const std::string& path, MeshPtr mesh);
53+
kore::MeshPtr getMesh(const std::string& path, const std::string& id);
54+
4755
private:
4856
ResourceManager(void);
4957
virtual ~ResourceManager(void);
5058

51-
std::map<std::string, kore::MeshPtr> _meshes;
59+
std::map<std::string, std::map<std::string, kore::MeshPtr>> _meshes; // filepath, id, mesh
60+
std::map<std::string, std::map<std::string, kore::MeshPtr>> _cameras; // filepath, id, camera
5261
std::vector<kore::ShaderPtr> _shader;
5362
};
5463
};

0 commit comments

Comments
 (0)