- if (! omname.empty()) {
- SGPath ompath("Textures.high");
- ompath.append(omname);
- string fullMaskPath = SGModelLib::findDataFile(ompath.str(), options);
-
- if (fullMaskPath.empty()) {
- ompath = SGPath("Textures");
- ompath.append(omname);
- fullMaskPath = SGModelLib::findDataFile(ompath.str(), options);
- }
-
- osg::Image* image = osgDB::readImageFile(fullMaskPath, options);
- if (image->valid())
- {
- osg::Texture2D* object_mask = new osg::Texture2D;
+ std::vector<SGPropertyNode_ptr> masks = props->getChildren("object-mask");
+ for (unsigned int i = 0; i < masks.size(); i++)
+ {
+ string omname = masks[i]->getStringValue();
+
+ if (! omname.empty()) {
+ SGPath ompath("Textures.high");
+ ompath.append(omname);
+ string fullMaskPath = SGModelLib::findDataFile(ompath.str(), options);
+
+ if (fullMaskPath.empty()) {
+ ompath = SGPath("Textures");
+ ompath.append(omname);
+ fullMaskPath = SGModelLib::findDataFile(ompath.str(), options);
+ }
+
+ if (fullMaskPath.empty()) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find texture \""
+ << omname << "\" in Textures or Textures.high folders.");
+ }
+ else
+ {
+ osg::Image* image = osgDB::readImageFile(fullMaskPath, options);
+ if (image && image->valid())
+ {
+ osg::Texture2D* object_mask = new osg::Texture2D;
+
+ bool dds_mask = (ompath.lower_extension() == "dds");
+
+ if (dds[i] != dds_mask) {
+ // Texture format does not match mask format. This is relevant for
+ // the object mask, as DDS textures have an origin at the bottom
+ // left rather than top left, therefore we flip the object mask
+ // vertically.
+ image->flipVertical();
+ }
+
+ object_mask->setImage(image);
+
+ // We force the filtering to be nearest, as the red channel (rotation)
+ // in particular, doesn't make sense to be interpolated between pixels.
+ object_mask->setFilter(osg::Texture::MIN_FILTER, osg::Texture::NEAREST);
+ object_mask->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST);
+
+ object_mask->setDataVariance(osg::Object::STATIC);
+ object_mask->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
+ object_mask->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
+ _masks.push_back(object_mask);
+ }
+ }
+ }
+ }
+
+ xsize = props->getDoubleValue("xsize", 0.0);
+ ysize = props->getDoubleValue("ysize", 0.0);
+ wrapu = props->getBoolValue("wrapu", true);
+ wrapv = props->getBoolValue("wrapv", true);
+ mipmap = props->getBoolValue("mipmap", true);
+ light_coverage = props->getDoubleValue("light-coverage", 0.0);
+
+ // Building properties
+ building_coverage = props->getDoubleValue("building-coverage", 0.0);
+ building_spacing = props->getDoubleValue("building-spacing-m", 5.0);
+
+ string bt = props->getStringValue("building-texture", "Textures/buildings.png");
+ building_texture = SGModelLib::findDataFile(bt, options);
+
+ if (building_texture.empty()) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find texture \"" << bt);
+ }