From: Stuart Buchanan Date: Sat, 28 Apr 2012 22:11:52 +0000 (+0100) Subject: Use Effects system for random buildings. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=db6e99f88516b71bb059b36fa49472efce681d52;p=simgear.git Use Effects system for random buildings. --- diff --git a/simgear/scene/tgdb/SGBuildingBin.cxx b/simgear/scene/tgdb/SGBuildingBin.cxx index bcbffcce..72d9ec50 100644 --- a/simgear/scene/tgdb/SGBuildingBin.cxx +++ b/simgear/scene/tgdb/SGBuildingBin.cxx @@ -517,6 +517,10 @@ void addBuildingToLeafGeode(Geode* geode, const SGBuildingBin::Building& buildin geode->setDrawable(0, geom); } +typedef std::map > EffectMap; + +static EffectMap buildingEffectMap; + // Helper classes for creating the quad tree namespace { @@ -536,17 +540,16 @@ struct MakeBuildingLeaf // Create a series of LOD nodes so trees cover decreases slightly // gradually with distance from _range to 2*_range for (float i = 0.0; i < SG_BUILDING_FADE_OUT_LEVELS; i++) - { - //osg::ref_ptr geode = new EffectGeode(); - //geode->setEffect(_effect); - osg::ref_ptr geode = new osg::Geode(); - result->addChild(geode, 0, _range * (1.0 + i / (SG_BUILDING_FADE_OUT_LEVELS - 1.0))); + { + EffectGeode* geode = new EffectGeode; + geode->setEffect(_effect.get()); + result->addChild(geode, 0, _range * (1.0 + i / (SG_BUILDING_FADE_OUT_LEVELS - 1.0))); } return result; } float _range; - Effect* _effect; + ref_ptr _effect; }; struct AddBuildingLeafObject @@ -593,12 +596,31 @@ osg::Group* createRandomBuildings(SGBuildingBinList buildings, const osg::Matrix static Matrix ident; // Set up some shared structures. MatrixTransform* mt = new MatrixTransform(transform); - Effect* effect = makeEffect("Effects/model-default", true); SGBuildingBin* bin = NULL; BOOST_FOREACH(bin, buildings) { + + ref_ptr effect; + EffectMap::iterator iter = buildingEffectMap.find(bin->texture); + + if ((iter == buildingEffectMap.end())|| + (!iter->second.lock(effect))) + { + SGPropertyNode_ptr effectProp = new SGPropertyNode; + makeChild(effectProp, "inherits-from")->setStringValue("Effects/building"); + SGPropertyNode* params = makeChild(effectProp, "parameters"); + // emphasize n = 0 + params->getChild("texture", 0, true)->getChild("image", 0, true) + ->setStringValue(bin->texture); + effect = makeEffect(effectProp, true, options); + if (iter == buildingEffectMap.end()) + buildingEffectMap.insert(EffectMap::value_type(bin->texture, effect)); + else + iter->second = effect; // update existing, but empty observer + } + // Now, create a quadbuilding for the buildings. BuildingGeometryQuadtree quadbuilding(GetBuildingCoord(), AddBuildingLeafObject(), @@ -617,6 +639,7 @@ osg::Group* createRandomBuildings(SGBuildingBinList buildings, const osg::Matrix ref_ptr group = quadbuilding.getRoot(); + /* // Set up the stateset for this building bin and the texture to use. osg::StateSet* stateSet = group->getOrCreateStateSet(); const std::string texturename = bin->texture; @@ -643,6 +666,7 @@ osg::Group* createRandomBuildings(SGBuildingBinList buildings, const osg::Matrix material->setShininess(osg::Material::FRONT, 0.0); material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); stateSet->setAttribute(material); + */ mt->addChild(group); }