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;
}
// 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;
// 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();
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
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);
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
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");
}
}
class SGBucket;
class SGMaterialLib;
+namespace simgear {
+class SGReaderWriterOptions;
+}
// Generate an ocean tile
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
root_props = p;
}
-osg::Node* sgGetRandomModel(SGMatModel *obj, mt *seed) {
- return obj->get_random_model( root_props, seed );
- }
-
namespace simgear
{
SGPropertyNode* getPropertyRoot()
#define _SG_USERDATA_HXX
#include <simgear/compiler.h>
-#include <simgear/math/sg_random.h>
#include <osg/Node>
*/
void sgUserDataInit(SGPropertyNode *p);
-/**
- * Get a random model.
- */
-osg::Node* sgGetRandomModel(SGMatModel *obj, mt *seed);
-
namespace simgear
{
/**