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