| 889 | } |
| 890 | |
| 891 | Ref<SceneGraph::MaterialNode> XMLLoader::loadMaterial(const Ref<XML>& xml) |
| 892 | { |
| 893 | const std::string id = xml->parm("id"); |
| 894 | if (id != "" && state.materialMap.find(id) != state.materialMap.end()) |
| 895 | return state.materialMap[id]; |
| 896 | |
| 897 | if (!xml->hasChild("parameters")) { |
| 898 | std::cout << "Warning: material " << id << " is not defined" << std::endl; |
| 899 | return new MatteMaterial(Vec3fa(0.5f,0.0f,0.0f)); |
| 900 | } |
| 901 | Ref<XML> parameters = xml->child("parameters"); |
| 902 | if (state.materialCache.find(parameters) != state.materialCache.end()) { |
| 903 | return state.materialMap[id] = state.materialCache[parameters]; |
| 904 | } |
| 905 | |
| 906 | std::string type = load<std::string>(xml->child("code")).c_str(); |
| 907 | Parms parms = loadMaterialParms(parameters); |
| 908 | Ref<SceneGraph::MaterialNode> material = addMaterial(type,parms); |
| 909 | state.materialCache[parameters] = material; |
| 910 | return state.materialMap[id] = material; |
| 911 | } |
| 912 | |
| 913 | Ref<SceneGraph::MaterialNode> XMLLoader::addMaterial(const std::string& type, const Parms& parms) |
| 914 | { |