From 33720fdd76f8cb3b06fd01b339f1c5155be64508 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 11 Aug 2023 14:32:46 -0500 Subject: [PATCH] Add 'texture.cpp' --- texture.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 texture.cpp diff --git a/texture.cpp b/texture.cpp new file mode 100644 index 0000000..66fa34c --- /dev/null +++ b/texture.cpp @@ -0,0 +1,44 @@ +```cpp +void getTexturePath(std::string material, std::string libPath, subMesh &currMesh) { + std::ifstream file(libPath); + std::string line; + std::string texturePath; + bool foundMat = false; + while(std::getline(file, line)) { + std::stringstream ss(line); + std::string keyword; + ss.unsetf(std::ios_base::skipws); + + ss >> std::ws; + + ss >> std::ws >> keyword; + std::string currMat; + if (foundMat) { + std::string matName; + ss >> std::ws >> matName; + if (keyword.length() >= 3) { + if (keyword.substr(0, 3) == "map") { + texturePath = line.substr(6 + (keyword.length() - 5)); + + currMesh.subTex = new olc::Sprite(texturePath); + currMesh.hasTexture = true; + currMesh.texPath = texturePath; + return; + } + } + else if (matName == "") { + currMesh.hasTexture = false; + return; + } + } + + if (keyword == "newmtl") { + currMat = line.substr(7); + if (currMat == material) { + foundMat = true; + } + } + } + currMesh.hasTexture = false; + } +``` \ No newline at end of file