Esempio n. 1
0
void GeomLoader::loadMaterial(const std::string& filename, DataWriter& dataWriter)
{
	std::ifstream matFile(filename);
	if (!matFile.is_open()) return;

	Json::Value root;
	Json::Reader reader;
	bool parsingSuccessful = reader.parse(matFile, root);
	matFile.close();
	if (!parsingSuccessful) return;

	for (size_t i = 0; i < root.size(); i++)
	{
		Data::Material mat;
		mat.diffuseMapFilename = root[i]["diffuseMap"].asString();
		mat.normalMapFilename = root[i]["normalMap"].asString();
		mat.specularMapFilename = root[i]["specularMap"].asString();

		if (i < dataWriter.getMeshesRef().size())
		{
			dataWriter.getMeshesRef()[i].material = mat;
		}
	}
}