diff --git a/Chapter08/02_SceneGraph/src/main.cpp b/Chapter08/02_SceneGraph/src/main.cpp index 00d2d39..6df6739 100644 --- a/Chapter08/02_SceneGraph/src/main.cpp +++ b/Chapter08/02_SceneGraph/src/main.cpp @@ -78,7 +78,7 @@ bool editTransformUI(const mat4& view, const mat4& projection, mat4& matrix) int* textureToEdit = nullptr; -bool editMaterialUI(Scene& scene, MeshData& meshData, int node, int& outUpdateMaterialIndex, TextureCache& textureCache) +bool editMaterialUI(Scene& scene, MeshData& meshData, int node, int& outUpdateMaterialIndex, const TextureCache& textureCache) { if (!scene.materialForNode.contains(node)) return false; @@ -141,7 +141,7 @@ bool editMaterialUI(Scene& scene, MeshData& meshData, int node, int& outUpdateMa } void editNodeUI( - Scene& scene, MeshData& meshData, const mat4& view, const mat4 proj, int node, int& outUpdateMaterialIndex, TextureCache& textureCache) + Scene& scene, MeshData& meshData, const mat4& view, const mat4 proj, int node, int& outUpdateMaterialIndex, const TextureCache& textureCache) { ImGuizmo::SetOrthographic(false); ImGuizmo::BeginFrame(); diff --git a/Chapter08/SceneUtils.h b/Chapter08/SceneUtils.h index c55959c..118ccf0 100644 --- a/Chapter08/SceneUtils.h +++ b/Chapter08/SceneUtils.h @@ -55,8 +55,10 @@ std::string convertTexture( const int maxNewWidth = DEMO_TEXTURE_MAX_SIZE; const int maxNewHeight = DEMO_TEXTURE_MAX_SIZE; - if (!std::filesystem::exists(DEMO_TEXTURE_CACHE_FOLDER)) { - std::filesystem::create_directories(DEMO_TEXTURE_CACHE_FOLDER); + namespace fs = std::filesystem; + + if (!fs::exists(DEMO_TEXTURE_CACHE_FOLDER)) { + fs::create_directories(DEMO_TEXTURE_CACHE_FOLDER); } const std::string srcFile = replaceAll(basePath + file, "\\", "/"); @@ -210,16 +212,16 @@ void traverse(const aiScene* sourceScene, Scene& scene, aiNode* N, int parent, i printPrefix(depth); printf("Node[%d].name = %s\n", newNode, N->mName.C_Str()); - const uint32_t stringID = (uint32_t)scene.names.size(); - scene.names.push_back(std::string(N->mName.C_Str())); + const uint32_t stringID = (uint32_t)scene.nodeNames.size(); + scene.nodeNames.push_back(std::string(N->mName.C_Str())); scene.nameForNode[newNode] = stringID; } for (size_t i = 0; i < N->mNumMeshes; i++) { const int newSubNode = addNode(scene, newNode, depth + 1); - const uint32_t stringID = (uint32_t)scene.names.size(); - scene.names.push_back(std::string(N->mName.C_Str()) + "_Mesh_" + std::to_string(i)); + const uint32_t stringID = (uint32_t)scene.nodeNames.size(); + scene.nodeNames.push_back(std::string(N->mName.C_Str()) + "_Mesh_" + std::to_string(i)); scene.nameForNode[newSubNode] = stringID; const int mesh = (int)N->mMeshes[i]; diff --git a/deps/bootstrap.json b/deps/bootstrap.json index 0b1efdd..63f58f7 100644 --- a/deps/bootstrap.json +++ b/deps/bootstrap.json @@ -4,7 +4,7 @@ "source": { "type": "git", "url": "https://github.com/corporateshark/lightweightvk.git", - "revision": "12bbe18d68ac288c02cb871dfae92facb3dc711f" + "revision": "c297911d8daefb26d4e0a9826a667c6ea9807a46" } }, { diff --git a/shared/Scene/Scene.cpp b/shared/Scene/Scene.cpp index c2e7c0c..24e03da 100644 --- a/shared/Scene/Scene.cpp +++ b/shared/Scene/Scene.cpp @@ -56,7 +56,7 @@ int findNodeByName(const Scene& scene, const std::string& name) if (scene.nameForNode.contains(i)) { int strID = scene.nameForNode.at(i); if (strID > -1) - if (scene.names[strID] == name) + if (scene.nodeNames[strID] == name) return (int)i; } @@ -131,7 +131,7 @@ void loadScene(const char* fileName, Scene& scene) if (!feof(f)) { loadMap(f, scene.nameForNode); - loadStringList(f, scene.names); + loadStringList(f, scene.nodeNames); loadStringList(f, scene.materialNames); } @@ -169,9 +169,9 @@ void saveScene(const char* fileName, const Scene& scene) saveMap(f, scene.materialForNode); saveMap(f, scene.meshForNode); - if (!scene.names.empty() && !scene.nameForNode.empty()) { + if (!scene.nodeNames.empty() && !scene.nameForNode.empty()) { saveMap(f, scene.nameForNode); - saveStringList(f, scene.names); + saveStringList(f, scene.nodeNames); saveStringList(f, scene.materialNames); } fclose(f); @@ -289,7 +289,7 @@ void mergeScenes( }; scene.nameForNode[0] = 0; - scene.names = { "NewRoot" }; + scene.nodeNames = { "NewRoot" }; scene.localTransform.push_back(glm::mat4(1.f)); scene.globalTransform.push_back(glm::mat4(1.f)); @@ -299,7 +299,7 @@ void mergeScenes( int offs = 1; int meshOffs = 0; - int nameOffs = (int)scene.names.size(); + int nameOffs = (int)scene.nodeNames.size(); int materialOfs = 0; auto meshCount = meshCounts.begin(); @@ -313,7 +313,7 @@ void mergeScenes( mergeVectors(scene.hierarchy, s->hierarchy); - mergeVectors(scene.names, s->names); + mergeVectors(scene.nodeNames, s->nodeNames); if (mergeMaterials) mergeVectors(scene.materialNames, s->materialNames); @@ -328,7 +328,7 @@ void mergeScenes( offs += nodeCount; materialOfs += (int)s->materialNames.size(); - nameOffs += (int)s->names.size(); + nameOffs += (int)s->nodeNames.size(); if (mergeMeshes) { meshOffs += *meshCount; @@ -371,7 +371,7 @@ void dumpSceneToDot(const char* fileName, const Scene& scene, int* visited) std::string extra = ""; if (scene.nameForNode.contains(i)) { int strID = scene.nameForNode.at(i); - name = scene.names[strID]; + name = scene.nodeNames[strID]; } if (visited) { if (visited[i]) diff --git a/shared/Scene/Scene.h b/shared/Scene/Scene.h index 9c7ba18..f5cac86 100644 --- a/shared/Scene/Scene.h +++ b/shared/Scene/Scene.h @@ -51,7 +51,7 @@ struct Scene { std::unordered_map nameForNode; // List of scene node names - std::vector names; + std::vector nodeNames; // Debug list of material names std::vector materialNames; @@ -66,13 +66,13 @@ int findNodeByName(const Scene& scene, const std::string& name); inline std::string getNodeName(const Scene& scene, int node) { int strID = scene.nameForNode.contains(node) ? scene.nameForNode.at(node) : -1; - return (strID > -1) ? scene.names[strID] : std::string(); + return (strID > -1) ? scene.nodeNames[strID] : std::string(); } inline void setNodeName(Scene& scene, int node, const std::string& name) { - uint32_t stringID = (uint32_t)scene.names.size(); - scene.names.push_back(name); + uint32_t stringID = (uint32_t)scene.nodeNames.size(); + scene.nodeNames.push_back(name); scene.nameForNode[node] = stringID; } diff --git a/shared/Utils.h b/shared/Utils.h index 508bd77..0e40c03 100644 --- a/shared/Utils.h +++ b/shared/Utils.h @@ -33,7 +33,7 @@ template inline void mergeVectors(std::vector& v1, const std::ve // Delete a list of items from std::vector with indices in 'selection' // e.g., eraseSelected({1, 2, 3, 4, 5}, {1, 3}) -> {1, 3, 5} // ^ ^ 2 and 4 get deleted -template inline void eraseSelected(std::vector& v, const std::vector& selection) +template inline void eraseSelected(std::vector& v, const std::vector& selection) { // cut off the elements moved to the end of the vector by std::stable_partition v.resize(std::distance(