mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Real material shared system + parsing
This commit is contained in:
@ -21,6 +21,27 @@ SceneParser::SceneParser(Scene *scene) : _scene(scene)
|
||||
};
|
||||
}
|
||||
|
||||
void SceneParser::parseMaterial(std::stringstream &line)
|
||||
{
|
||||
float r,g,b;
|
||||
float emission;
|
||||
float roughness;
|
||||
float specular;
|
||||
Material *mat;
|
||||
|
||||
if (!(line >> r >> g >> b >> emission >> roughness >> specular))
|
||||
throw std::runtime_error("Material: Missing material properties");
|
||||
|
||||
mat = new Material;
|
||||
|
||||
mat->color = glm::vec3(r / 255.0f, g / 255.0f, b / 255.0f);
|
||||
mat->emission = emission;
|
||||
mat->roughness = roughness;
|
||||
mat->specular = specular;
|
||||
|
||||
_scene->addMaterial(mat);
|
||||
}
|
||||
|
||||
bool SceneParser::parseLine(const std::string &line)
|
||||
{
|
||||
if (line.empty() || line[0] == '#')
|
||||
@ -31,17 +52,25 @@ bool SceneParser::parseLine(const std::string &line)
|
||||
|
||||
ss >> identifier;
|
||||
|
||||
auto it = object_parsers.find(identifier);
|
||||
if (it != object_parsers.end())
|
||||
try
|
||||
{
|
||||
try {
|
||||
auto it = object_parsers.find(identifier);
|
||||
if (it != object_parsers.end())
|
||||
{
|
||||
Object *obj = it->second(ss);
|
||||
(void) _scene->getMaterial(obj->getMaterialIndex()); //verify material
|
||||
|
||||
_scene->addObject(obj);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error parsing sphere: " << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (identifier == "MAT")
|
||||
this->parseMaterial(ss);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
return (false);
|
||||
}
|
||||
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user