Add 'texture.cpp'
This commit is contained in:
parent
a3a3142bdd
commit
33720fdd76
44
texture.cpp
Normal file
44
texture.cpp
Normal file
@ -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;
|
||||
}
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user