// Read in material data from the scene file void readMaterials(scene_data* scene, const boost::property_tree::ptree& pt) { boost::property_tree::ptree::const_iterator iter = pt.begin(); // Iterate through all the sub branches, and read in the relevant data for (; iter != pt.end(); ++iter) { material* mat = new material(); std::string name = iter->first; mat->data.emissive = readVec4(iter->second.get_child("emmisive")); mat->data.ambient = readVec4(iter->second.get_child("ambient")); mat->data.diffuse = readVec4(iter->second.get_child("diffuse")); mat->data.specular = readVec4(iter->second.get_child("specular")); mat->data.shininess = iter->second.get_child("shininess").get_value<float>(); std::string texture = iter->second.get_child("texture").get_value<std::string>(); // Try and find texture, and set material accordingly. If the not found, // set to nullptr if (scene->textures.find(texture) != scene->textures.end()) mat->texture = scene->textures[texture]; else mat->texture = nullptr; // Create the material, and add to the table mat->create(); scene->material[name] = mat; } }
// Reads in lighting data for a scene void readLighting(scene_data* scene, const boost::property_tree::ptree& pt) { scene->light.data.ambient = readVec4(pt.get_child("ambient")); scene->light.data.diffuse = readVec4(pt.get_child("diffuse")); scene->light.data.specular = readVec4(pt.get_child("specular")); scene->light.data.lightDir = readVec4(pt.get_child("lightDir")); scene->light.create(); }
// Reads in data for a point light void readPointLight(scene_data* scene, const boost::property_tree::ptree& pt) { point_light_data point; point.ambient = readVec4(pt.get_child("ambient")); point.diffuse = readVec4(pt.get_child("diffuse")); point.specular = readVec4(pt.get_child("specular")); point.lightPos = readVec4(pt.get_child("lightPos")); point.attenuation = readVec4(pt.get_child("attenuation")); point.dist = pt.get_child("dist").get_value<float>(); scene->dynamic.addPoint(point); }
void readMaterials(scene_data* scene, const boost::property_tree::ptree& pt) { boost::property_tree::ptree::const_iterator iter = pt.begin(); for (; iter != pt.end(); ++iter) { material* mat = new material(); std::string name = iter->first; mat->data.emissive = readVec4(iter->second.get_child("emmisive")); mat->data.ambient = readVec4(iter->second.get_child("ambient")); mat->data.diffuse = readVec4(iter->second.get_child("diffuse")); mat->data.specular = readVec4(iter->second.get_child("specular")); mat->data.shininess = iter->second.get_child("shininess").get_value<float>(); std::string texture = iter->second.get_child("texture").get_value<std::string>(); mat->texture = scene->textures[texture]; mat->create(); scene->material[name] = mat; } }
// Reads in data for a spot light void readSpotLight(scene_data* scene, const boost::property_tree::ptree& pt) { spot_light_data spot; spot.ambient = readVec4(pt.get_child("ambient")); spot.diffuse = readVec4(pt.get_child("diffuse")); spot.specular = readVec4(pt.get_child("specular")); spot.lightPos = readVec4(pt.get_child("lightPos")); spot.attenuation = readVec4(pt.get_child("attenuation")); spot.lightDir = readVec4(pt.get_child("lightDir")); spot.power = pt.get_child("power").get_value<float>(); spot.dist = pt.get_child("dist").get_value<float>(); scene->dynamic.addSpot(spot); }