bool parseMaterial(XMLElement* node, MaterialMap& materials) { const char* attr; attr = node->Attribute("name"); if (!attr || strlen(attr) == 0) { cerr << "WARNING: material tag is missing a name" << endl; return false; } string name(attr); auto material_iter = materials.find(name); bool already_in_map = false; if (material_iter != materials.end()) { already_in_map = true; } Vector4d rgba; XMLElement* color_node = node->FirstChildElement("color"); if (color_node) { if (!parseVectorAttribute(color_node, "rgba", rgba)) { cerr << "WARNING: color tag is missing rgba attribute" << endl; return false; } materials[name] = rgba; } else if (!already_in_map) { cerr << "WARNING: material \"" << name << "\" is not a simple color material (so is currently unsupported)" << endl; return false; } return true; }
void Mesh::render(const MaterialMap &mats) const { // index aktualni skupiny size_t index = 0; // pomocny seznam materialu pro predavani vertexgrupe pri renderu MaterialMap localMats; // iterace nad skupinami a jejich vykresleni for (VGList::const_iterator pos = vg.begin(); pos != vg.end(); pos++, index++) { // vyhodnoceni materialu // pokud index v danem seznamu existuje, zapise se MaterialMap::const_iterator matPos = mats.find(index); if (matPos != mats.end()) { localMats[0] = matPos->second; } else { localMats[0] = 0x0; } pos->render(localMats); } }
//------------------------------------------------------------------------ Mtl::MaterialIterator::MaterialIterator( const MaterialMap& _materialMap ) : IteratorWrapper<MaterialMap, MaterialMap::const_iterator, MaterialPtr> ( _materialMap.begin(), _materialMap.end() ) { }