scenery: Route loader options through the btg loader.

This commit is contained in:
Mathias Froehlich 2012-03-03 10:37:54 +01:00
parent 3020990121
commit 9e46820c57
7 changed files with 39 additions and 48 deletions

View File

@ -59,36 +59,13 @@ osgDB::ReaderWriter::ReadResult
SGReaderWriterBTG::readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options* options) const
{
SGMaterialLib* matlib = 0;
bool useRandomObjects = false;
bool useRandomVegetation = false;
float vegetation_density = 1.0f;
const SGReaderWriterOptions* sgOptions;
sgOptions = dynamic_cast<const SGReaderWriterOptions*>(options);
if (sgOptions) {
matlib = sgOptions->getMaterialLib();
SGPropertyNode* propertyNode = sgOptions->getPropertyNode().get();
if (propertyNode) {
useRandomObjects
= propertyNode->getBoolValue("/sim/rendering/random-objects",
useRandomObjects);
useRandomVegetation
= propertyNode->getBoolValue("/sim/rendering/random-vegetation",
useRandomVegetation);
vegetation_density
= propertyNode->getFloatValue("/sim/rendering/vegetation-density",
vegetation_density);
}
}
osg::Node* result = SGLoadBTG(fileName, matlib,
useRandomObjects,
useRandomVegetation,
vegetation_density);
if (result)
return result;
else
osg::Node* result = SGLoadBTG(fileName, sgOptions);
if (!result)
return ReadResult::FILE_NOT_HANDLED;
return result;
}

View File

@ -285,7 +285,8 @@ struct TreeTransformer
// forest into the local Z-up coordinate system we can reuse the
// primitive tree geometry for all the forests of the same type.
osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform)
osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform,
const SGReaderWriterOptions* options)
{
Matrix transInv = Matrix::inverse(transform);
static Matrix ident;
@ -307,7 +308,7 @@ osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform
// emphasize n = 0
params->getChild("texture", 0, true)->getChild("image", 0, true)
->setStringValue(forest->texture);
effect = makeEffect(effectProp, true);
effect = makeEffect(effectProp, true, options);
treeEffectMap.insert(EffectMap::value_type(forest->texture, effect));
} else {
effect = iter->second.get();

View File

@ -65,6 +65,7 @@ public:
typedef std::list<TreeBin*> SGTreeBinList;
osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform);
osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform,
const SGReaderWriterOptions* options);
}
#endif

View File

@ -600,12 +600,32 @@ typedef QuadTreeBuilder<osg::LOD*, ModelLOD, MakeQuadLeaf, AddModelLOD,
GetModelLODCoord> RandomObjectsQuadtree;
osg::Node*
SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool use_random_objects, bool use_random_vegetation, float vegetation_density)
SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options)
{
SGBinObject tile;
if (!tile.read_bin(path))
return NULL;
SGMaterialLib* matlib = 0;
bool use_random_objects = false;
bool use_random_vegetation = false;
float vegetation_density = 1.0f;
if (options) {
matlib = options->getMaterialLib();
SGPropertyNode* propertyNode = options->getPropertyNode().get();
if (propertyNode) {
use_random_objects
= propertyNode->getBoolValue("/sim/rendering/random-objects",
use_random_objects);
use_random_vegetation
= propertyNode->getBoolValue("/sim/rendering/random-vegetation",
use_random_vegetation);
vegetation_density
= propertyNode->getFloatValue("/sim/rendering/vegetation-density",
vegetation_density);
}
}
SGVec3d center = tile.get_gbs_center();
SGGeod geodPos = SGGeod::fromCart(center);
SGQuatd hlOr = SGQuatd::fromLonLat(geodPos)*SGQuatd::fromEulerDeg(0, 0, 180);
@ -654,8 +674,9 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool use_random_object
i < tileGeometryBin.randomModels.getNumModels(); i++) {
SGMatModelBin::MatModel obj
= tileGeometryBin.randomModels.getMatModel(i);
osg::Node* node = sgGetRandomModel(obj.model, &seed);
SGPropertyNode* root = options->getPropertyNode()->getRootNode();
osg::Node* node = obj.model->get_random_model(root, &seed);
// Create a matrix to place the object in the correct
// location, and then apply the rotation matrix created
@ -694,7 +715,8 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool use_random_object
tileGeometryBin.computeRandomForest(matlib, vegetation_density);
if (tileGeometryBin.randomForest.size() > 0) {
forestNode = createForest(tileGeometryBin.randomForest, osg::Matrix::identity());
forestNode = createForest(tileGeometryBin.randomForest, osg::Matrix::identity(),
options);
forestNode->setName("Random trees");
}
}

View File

@ -42,6 +42,9 @@ using std::string;
class SGBucket;
class SGMaterialLib;
namespace simgear {
class SGReaderWriterOptions;
}
// Generate an ocean tile
inline bool SGGenTile( const std::string&, const SGBucket& b,
@ -57,9 +60,6 @@ inline bool SGGenTile( const std::string&, const SGBucket& b,
osg::Node*
SGLoadBTG(const std::string& path,
SGMaterialLib *matlib,
bool use_random_objects,
bool use_random_vegetation,
float vegetation_density);
const simgear::SGReaderWriterOptions* options);
#endif // _SG_OBJ_HXX

View File

@ -59,10 +59,6 @@ void sgUserDataInit( SGPropertyNode *p ) {
root_props = p;
}
osg::Node* sgGetRandomModel(SGMatModel *obj, mt *seed) {
return obj->get_random_model( root_props, seed );
}
namespace simgear
{
SGPropertyNode* getPropertyRoot()

View File

@ -26,7 +26,6 @@
#define _SG_USERDATA_HXX
#include <simgear/compiler.h>
#include <simgear/math/sg_random.h>
#include <osg/Node>
@ -40,11 +39,6 @@ class SGPropertyNode;
*/
void sgUserDataInit(SGPropertyNode *p);
/**
* Get a random model.
*/
osg::Node* sgGetRandomModel(SGMatModel *obj, mt *seed);
namespace simgear
{
/**