Use Effects system for random buildings.
This commit is contained in:
@@ -517,6 +517,10 @@ void addBuildingToLeafGeode(Geode* geode, const SGBuildingBin::Building& buildin
|
|||||||
geode->setDrawable(0, geom);
|
geode->setDrawable(0, geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef std::map<std::string, osg::observer_ptr<Effect> > EffectMap;
|
||||||
|
|
||||||
|
static EffectMap buildingEffectMap;
|
||||||
|
|
||||||
// Helper classes for creating the quad tree
|
// Helper classes for creating the quad tree
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -537,16 +541,15 @@ struct MakeBuildingLeaf
|
|||||||
// gradually with distance from _range to 2*_range
|
// gradually with distance from _range to 2*_range
|
||||||
for (float i = 0.0; i < SG_BUILDING_FADE_OUT_LEVELS; i++)
|
for (float i = 0.0; i < SG_BUILDING_FADE_OUT_LEVELS; i++)
|
||||||
{
|
{
|
||||||
//osg::ref_ptr<EffectGeode> geode = new EffectGeode();
|
EffectGeode* geode = new EffectGeode;
|
||||||
//geode->setEffect(_effect);
|
geode->setEffect(_effect.get());
|
||||||
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
|
|
||||||
result->addChild(geode, 0, _range * (1.0 + i / (SG_BUILDING_FADE_OUT_LEVELS - 1.0)));
|
result->addChild(geode, 0, _range * (1.0 + i / (SG_BUILDING_FADE_OUT_LEVELS - 1.0)));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float _range;
|
float _range;
|
||||||
Effect* _effect;
|
ref_ptr<Effect> _effect;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AddBuildingLeafObject
|
struct AddBuildingLeafObject
|
||||||
@@ -593,12 +596,31 @@ osg::Group* createRandomBuildings(SGBuildingBinList buildings, const osg::Matrix
|
|||||||
static Matrix ident;
|
static Matrix ident;
|
||||||
// Set up some shared structures.
|
// Set up some shared structures.
|
||||||
MatrixTransform* mt = new MatrixTransform(transform);
|
MatrixTransform* mt = new MatrixTransform(transform);
|
||||||
Effect* effect = makeEffect("Effects/model-default", true);
|
|
||||||
|
|
||||||
SGBuildingBin* bin = NULL;
|
SGBuildingBin* bin = NULL;
|
||||||
|
|
||||||
BOOST_FOREACH(bin, buildings)
|
BOOST_FOREACH(bin, buildings)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ref_ptr<Effect> 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.
|
// Now, create a quadbuilding for the buildings.
|
||||||
BuildingGeometryQuadtree
|
BuildingGeometryQuadtree
|
||||||
quadbuilding(GetBuildingCoord(), AddBuildingLeafObject(),
|
quadbuilding(GetBuildingCoord(), AddBuildingLeafObject(),
|
||||||
@@ -617,6 +639,7 @@ osg::Group* createRandomBuildings(SGBuildingBinList buildings, const osg::Matrix
|
|||||||
|
|
||||||
ref_ptr<Group> group = quadbuilding.getRoot();
|
ref_ptr<Group> group = quadbuilding.getRoot();
|
||||||
|
|
||||||
|
/*
|
||||||
// Set up the stateset for this building bin and the texture to use.
|
// Set up the stateset for this building bin and the texture to use.
|
||||||
osg::StateSet* stateSet = group->getOrCreateStateSet();
|
osg::StateSet* stateSet = group->getOrCreateStateSet();
|
||||||
const std::string texturename = bin->texture;
|
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->setShininess(osg::Material::FRONT, 0.0);
|
||||||
material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
|
material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
|
||||||
stateSet->setAttribute(material);
|
stateSet->setAttribute(material);
|
||||||
|
*/
|
||||||
mt->addChild(group);
|
mt->addChild(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user