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, SGReaderWriterBTG::readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options* options) const const osgDB::ReaderWriter::Options* options) const
{ {
SGMaterialLib* matlib = 0;
bool useRandomObjects = false;
bool useRandomVegetation = false;
float vegetation_density = 1.0f;
const SGReaderWriterOptions* sgOptions; const SGReaderWriterOptions* sgOptions;
sgOptions = dynamic_cast<const SGReaderWriterOptions*>(options); sgOptions = dynamic_cast<const SGReaderWriterOptions*>(options);
if (sgOptions) { osg::Node* result = SGLoadBTG(fileName, sgOptions);
matlib = sgOptions->getMaterialLib(); if (!result)
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
return ReadResult::FILE_NOT_HANDLED; 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 // forest into the local Z-up coordinate system we can reuse the
// primitive tree geometry for all the forests of the same type. // 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); Matrix transInv = Matrix::inverse(transform);
static Matrix ident; static Matrix ident;
@ -307,7 +308,7 @@ osg::Group* createForest(SGTreeBinList& forestList, const osg::Matrix& transform
// emphasize n = 0 // emphasize n = 0
params->getChild("texture", 0, true)->getChild("image", 0, true) params->getChild("texture", 0, true)->getChild("image", 0, true)
->setStringValue(forest->texture); ->setStringValue(forest->texture);
effect = makeEffect(effectProp, true); effect = makeEffect(effectProp, true, options);
treeEffectMap.insert(EffectMap::value_type(forest->texture, effect)); treeEffectMap.insert(EffectMap::value_type(forest->texture, effect));
} else { } else {
effect = iter->second.get(); effect = iter->second.get();

View File

@ -65,6 +65,7 @@ public:
typedef std::list<TreeBin*> SGTreeBinList; 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 #endif

View File

@ -600,12 +600,32 @@ typedef QuadTreeBuilder<osg::LOD*, ModelLOD, MakeQuadLeaf, AddModelLOD,
GetModelLODCoord> RandomObjectsQuadtree; GetModelLODCoord> RandomObjectsQuadtree;
osg::Node* 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; SGBinObject tile;
if (!tile.read_bin(path)) if (!tile.read_bin(path))
return NULL; 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(); SGVec3d center = tile.get_gbs_center();
SGGeod geodPos = SGGeod::fromCart(center); SGGeod geodPos = SGGeod::fromCart(center);
SGQuatd hlOr = SGQuatd::fromLonLat(geodPos)*SGQuatd::fromEulerDeg(0, 0, 180); SGQuatd hlOr = SGQuatd::fromLonLat(geodPos)*SGQuatd::fromEulerDeg(0, 0, 180);
@ -655,7 +675,8 @@ SGLoadBTG(const std::string& path, SGMaterialLib *matlib, bool use_random_object
SGMatModelBin::MatModel obj SGMatModelBin::MatModel obj
= tileGeometryBin.randomModels.getMatModel(i); = 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 // Create a matrix to place the object in the correct
// location, and then apply the rotation matrix created // 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); tileGeometryBin.computeRandomForest(matlib, vegetation_density);
if (tileGeometryBin.randomForest.size() > 0) { if (tileGeometryBin.randomForest.size() > 0) {
forestNode = createForest(tileGeometryBin.randomForest, osg::Matrix::identity()); forestNode = createForest(tileGeometryBin.randomForest, osg::Matrix::identity(),
options);
forestNode->setName("Random trees"); forestNode->setName("Random trees");
} }
} }

View File

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

View File

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

View File

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