LightSourcePointer SceneLoader::readLightSource(const QDomElement &element) const { QString lightSourceType; if (!readAttributeAsString(element, "type", lightSourceType)) { return LightSourcePointer(NULL); } Color ambientIntensity; Color diffuseIntensity; Color specularIntensity; if (!readChildElementAsVector(element, "ambient_emission", ambientIntensity) || !readChildElementAsVector(element, "diffuse_emission", diffuseIntensity) || !readChildElementAsVector(element, "specular_emission", specularIntensity)) { return LightSourcePointer(NULL); } if (lightSourceType == "directional") { return readDirectedLight(element, ambientIntensity, diffuseIntensity, specularIntensity); } if (lightSourceType == "point") { return readPointLight(element, ambientIntensity, diffuseIntensity, specularIntensity); } if (lightSourceType == "spotlight") { return readSpotLight(element, ambientIntensity, diffuseIntensity, specularIntensity); } std::cerr << "Scene parsing error: unknown light source type '" << lightSourceType.toUtf8().constData() << "'" << std::endl; return LightSourcePointer(NULL); }
// Read in all the dynamic lights for the scene void readDynamicLights(scene_data* scene, const boost::property_tree::ptree& pt) { boost::property_tree::ptree::const_iterator iter = pt.front().second.begin(); for (; iter != pt.front().second.end(); ++iter) { if (iter->first == "point") readPointLight(scene, iter->second); else if (iter->first == "spot") readSpotLight(scene, iter->second); else { std::cerr << "Error - unknown dynamic light encountered: " << iter->second.front().first << std::endl; exit(EXIT_FAILURE); } } scene->dynamic.create(); }