diff --git a/src/Objects/matlib.cxx b/src/Objects/matlib.cxx index 82f496eef..e80bd1492 100644 --- a/src/Objects/matlib.cxx +++ b/src/Objects/matlib.cxx @@ -51,6 +51,7 @@ #include
#include +#include "newmat.hxx" #include "matlib.hxx" SG_USING_NAMESPACE(std); diff --git a/src/Objects/matlib.hxx b/src/Objects/matlib.hxx index ee1f65017..539074f8a 100644 --- a/src/Objects/matlib.hxx +++ b/src/Objects/matlib.hxx @@ -48,8 +48,8 @@ #include // plib include -#include "newmat.hxx" +class FGNewMat; SG_USING_STD(string); SG_USING_STD(map); diff --git a/src/Objects/newmat.cxx b/src/Objects/newmat.cxx index 9d11efa97..c2f32754f 100644 --- a/src/Objects/newmat.cxx +++ b/src/Objects/newmat.cxx @@ -91,6 +91,8 @@ FGNewMat::FGNewMat (ssgSimpleState * s) FGNewMat::~FGNewMat (void) { + for (int i = 0; i < objects.size(); i++) + objects[i].model->deRef(); } @@ -140,6 +142,39 @@ FGNewMat::read_properties (const SGPropertyNode * props) emission[1] = props->getDoubleValue("emissive/g", 0.0); emission[2] = props->getDoubleValue("emissive/b", 0.0); emission[3] = props->getDoubleValue("emissive/a", 0.0); + + vector object_nodes = + ((SGPropertyNode *)props)->getChildren("object"); + for (int i = 0; i < object_nodes.size(); i++) { + const SGPropertyNode * object_node = object_nodes[i]; + if (object_node->hasChild("path")) { + Object object; + SGPath path = globals->get_fg_root(); + path.append(object_node->getStringValue("path")); + ssgTexturePath((char *)path.dir().c_str()); + ssgEntity * model = ssgLoad((char *)path.c_str()); + if (model != 0) { + float ranges[] = {0, object_node->getDoubleValue("range-m", 2000)}; + object.model = new ssgRangeSelector; + ((ssgRangeSelector *)object.model)->setRanges(ranges, 2); + if (object_node->getBoolValue("billboard", false)) { + ssgCutout * cutout = new ssgCutout(false); + cutout->addKid(model); + ((ssgBranch *)object.model)->addKid(cutout); + } else { + ((ssgBranch *)object.model)->addKid(model); + } + object.model->ref(); + object.coverage = object_node->getDoubleValue("coverage", 100000); + object.group_lod = object_node->getDoubleValue("group-range-m", 5000); + objects.push_back(object); + } else { + SG_LOG(SG_INPUT, SG_ALERT, "Failed to load object " << path.str()); + } + } else { + SG_LOG(SG_INPUT, SG_ALERT, "No path supplied for object"); + } + } } diff --git a/src/Objects/newmat.hxx b/src/Objects/newmat.hxx index 687b40d9e..57a9e9df9 100644 --- a/src/Objects/newmat.hxx +++ b/src/Objects/newmat.hxx @@ -147,6 +147,34 @@ public: virtual inline double get_light_coverage () const { return light_coverage; } + /** + * Get the number of dynamic objects defined for this material. + */ + virtual int get_object_count () const { return objects.size(); } + + + /** + * Get a dynamic object for this material. + */ + virtual ssgEntity * get_object (int i) const { return objects[i].model; } + + + /** + * Get the average space for a dynamic object for this material. + */ + virtual double get_object_coverage (int i) const { + return objects[i].coverage; + } + + + /** + * Get the group LOD range for a dynamic object for this material. + */ + virtual double get_object_group_lod (int i) const { + return objects[i].group_lod; + } + + /** * Get the current state. */ @@ -221,6 +249,15 @@ private: // true if texture loading deferred, and not yet loaded bool texture_loaded; + struct Object + { + ssgEntity * model; + double coverage; + double group_lod; + }; + + vector objects; + // ref count so we can properly delete if we have multiple // pointers to this record int refcount; diff --git a/src/Objects/obj.cxx b/src/Objects/obj.cxx index dba84040c..479e5a56a 100644 --- a/src/Objects/obj.cxx +++ b/src/Objects/obj.cxx @@ -52,8 +52,10 @@ #include
#include
+#include