Created
June 22, 2016 09:30
-
-
Save feliwir/a075de5d377ee78cbeaf2f89ba761b76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void JsonLoader::LoadMaterial(const std::string &name, const std::string &path) | |
{ | |
std::shared_ptr<Material> mat; | |
std::ifstream fin(path, std::ios::in); | |
if (fin.fail()) | |
throw AnvilException("Failed to open material file: " + path, __FILE__, __LINE__); | |
IStreamWrapper isw(fin); | |
Document d; | |
ParseResult ok = d.ParseStream(isw); | |
if (!ok) | |
throw AnvilException("Failed to parse file: " + path, __FILE__, __LINE__); | |
if (d.HasMember("material")) | |
{ | |
mat = std::make_shared<Material>(); | |
if (d["material"].HasMember("displacement_factor")) | |
mat->SetDisplacementFactor(d["material"]["displacement_factor"].GetDouble()); | |
if (d["material"].HasMember("uPerSec")) | |
mat->SetUPerSecond(d["material"]["uPerSec"].GetDouble()); | |
if (d["material"].HasMember("vPerSec")) | |
mat->SetVPerSecond(d["material"]["vPerSec"].GetDouble()); | |
if (d["material"].HasMember("displacement_factor")) | |
mat->SetDisplacementFactor(d["material"]["displacement_factor"].GetDouble()); | |
if (d["material"].HasMember("albedo")) | |
mat->SetAlbedoTexture(d["material"]["albedo"].GetString()); | |
else | |
throw AnvilException("Material file has no albedo texture: " + path, __FILE__, __LINE__); | |
if (d["material"].HasMember("normal")) | |
mat->SetNormalTexture(d["material"]["normal"].GetString()); | |
if (d["material"].HasMember("specular")) | |
mat->SetSpecularTexture(d["material"]["specular"].GetString()); | |
if (d["material"].HasMember("displacement")) | |
mat->SetDisplacementTexture(d["material"]["displacement"].GetString()); | |
if (d["material"].HasMember("ambient_occ")) | |
mat->SetAmbientOcclusionTexture(d["material"]["ambient_occ"].GetString()); | |
} | |
else | |
throw AnvilException("Material file has no material object: " + path, __FILE__, __LINE__); | |
fin.close(); | |
Core::GetCore()->GetResources()->AddResource(name, mat); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment