#include "MeshMaterial.h" #include #include #include "common.h" using std::ifstream; MeshMaterial::MeshMaterial(const std::string& filename) { ifstream file(MESHDIR+filename); string dataType; file >> dataType; if (dataType != "MeshMat") { std::cout << "File " << filename << " is not a MeshMaterial!\n"; return; } int version; file >> version; if (version != 1) { std::cout << "File " << filename << " has incompatible version " << version << "!\n"; return; } int matCount; int meshCount; file >> matCount; file >> meshCount; materialLayers.resize(matCount); for (int i = 0; i < matCount; ++i) { string name; int count; file >> name; file >> count; for (int j = 0; j < count; ++j) { string entryData; file >> entryData; string channel; string file; size_t split = entryData.find_first_of(':'); channel = entryData.substr(0, split); file = entryData.substr(split + 1); materialLayers[i].entries.insert(std::make_pair(channel, file)); } } for (int i = 0; i < meshCount; ++i) { int entry; file >> entry; meshLayers.emplace_back(&materialLayers[entry]); } } const MeshMaterialEntry* MeshMaterial::GetMaterialForLayer(int i) const { if (i < 0 || i >= (int)meshLayers.size()) { return nullptr; } return meshLayers[i]; }