]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/mat.cxx
A patch from Frederic Bouvier to correct a naming problem caused bu Curts work. This...
[simgear.git] / simgear / scene / material / mat.cxx
index 77f74969e26dc0fdf096658e51897e97e3f8eeb3..2c45c322b26fbccf13321a93a6511d4edaa5e74a 100644 (file)
@@ -40,7 +40,7 @@ SG_USING_STD(map);
 #include <simgear/math/sg_random.h>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/misc/sgstream.hxx>
-#include <simgear/scene/model/loader.hxx>
+#include <simgear/scene/model/modellib.hxx>
 
 #include "mat.hxx"
 
@@ -66,187 +66,6 @@ local_file_exists( const string& path ) {
 }
 
 
-\f
-////////////////////////////////////////////////////////////////////////
-// Implementation of SGMaterial::Object.
-////////////////////////////////////////////////////////////////////////
-
-SGMaterial::Object::Object (const SGPropertyNode * node, double range_m)
-  : _models_loaded(false),
-    _coverage_m2(node->getDoubleValue("coverage-m2", 1000000)),
-    _range_m(range_m)
-{
-                               // Sanity check
-  if (_coverage_m2 < 1000) {
-    SG_LOG(SG_INPUT, SG_ALERT, "Random object coverage " << _coverage_m2
-          << " is too small, forcing, to 1000");
-    _coverage_m2 = 1000;
-  }
-
-                               // Note all the model paths
-  vector <SGPropertyNode_ptr> path_nodes = node->getChildren("path");
-  for (unsigned int i = 0; i < path_nodes.size(); i++)
-    _paths.push_back(path_nodes[i]->getStringValue());
-
-                               // Note the heading type
-  string hdg = node->getStringValue("heading-type", "fixed");
-  if (hdg == "fixed") {
-    _heading_type = HEADING_FIXED;
-  } else if (hdg == "billboard") {
-    _heading_type = HEADING_BILLBOARD;
-  } else if (hdg == "random") {
-    _heading_type = HEADING_RANDOM;
-  } else {
-    _heading_type = HEADING_FIXED;
-    SG_LOG(SG_INPUT, SG_ALERT, "Unknown heading type: " << hdg
-          << "; using 'fixed' instead.");
-  }
-
-  // uncomment to preload models
-  // load_models();
-}
-
-SGMaterial::Object::~Object ()
-{
-  for (unsigned int i = 0; i < _models.size(); i++) {
-    if (_models[i] != 0) {
-      _models[i]->deRef();
-      _models[i] = 0;
-    }
-  }
-}
-
-int
-SGMaterial::Object::get_model_count( SGModelLoader *loader,
-                                   const string &fg_root,
-                                   SGPropertyNode *prop_root,
-                                   double sim_time_sec )
-{
-  load_models( loader, fg_root, prop_root, sim_time_sec );
-  return _models.size();
-}
-
-inline void
-SGMaterial::Object::load_models ( SGModelLoader *loader,
-                                const string &fg_root,
-                                SGPropertyNode *prop_root,
-                                double sim_time_sec )
-{
-                               // Load model only on demand
-  if (!_models_loaded) {
-    for (unsigned int i = 0; i < _paths.size(); i++) {
-      ssgEntity *entity = loader->load_model( fg_root, _paths[i],
-                                              prop_root, sim_time_sec );
-      if (entity != 0) {
-                                // FIXME: this stuff can be handled
-                                // in the XML wrapper as well (at least,
-                                // the billboarding should be handled
-                                // there).
-       float ranges[] = {0, _range_m};
-       ssgRangeSelector * lod = new ssgRangeSelector;
-        lod->ref();
-        lod->setRanges(ranges, 2);
-       if (_heading_type == HEADING_BILLBOARD) {
-         ssgCutout * cutout = new ssgCutout(false);
-         cutout->addKid(entity);
-         lod->addKid(cutout);
-       } else {
-         lod->addKid(entity);
-       }
-       _models.push_back(lod);
-      } else {
-       SG_LOG(SG_INPUT, SG_ALERT, "Failed to load object " << _paths[i]);
-      }
-    }
-  }
-  _models_loaded = true;
-}
-
-ssgEntity *
-SGMaterial::Object::get_model( int index,
-                             SGModelLoader *loader,
-                             const string &fg_root,
-                             SGPropertyNode *prop_root,
-                             double sim_time_sec )
-{
-  load_models( loader, fg_root, prop_root, sim_time_sec ); // comment this out if preloading models
-  return _models[index];
-}
-
-ssgEntity *
-SGMaterial::Object::get_random_model( SGModelLoader *loader,
-                                    const string &fg_root,
-                                    SGPropertyNode *prop_root,
-                                    double sim_time_sec )
-{
-  load_models( loader, fg_root, prop_root, sim_time_sec ); // comment this out if preloading models
-  int nModels = _models.size();
-  int index = int(sg_random() * nModels);
-  if (index >= nModels)
-    index = 0;
-  return _models[index];
-}
-
-double
-SGMaterial::Object::get_coverage_m2 () const
-{
-  return _coverage_m2;
-}
-
-SGMaterial::Object::HeadingType
-SGMaterial::Object::get_heading_type () const
-{
-  return _heading_type;
-}
-
-
-\f
-////////////////////////////////////////////////////////////////////////
-// Implementation of SGMaterial::ObjectGroup.
-////////////////////////////////////////////////////////////////////////
-
-SGMaterial::ObjectGroup::ObjectGroup (SGPropertyNode * node)
-  : _range_m(node->getDoubleValue("range-m", 2000))
-{
-                               // Load the object subnodes
-  vector<SGPropertyNode_ptr> object_nodes =
-    ((SGPropertyNode *)node)->getChildren("object");
-  for (unsigned int i = 0; i < object_nodes.size(); i++) {
-    const SGPropertyNode * object_node = object_nodes[i];
-    if (object_node->hasChild("path"))
-      _objects.push_back(new Object(object_node, _range_m));
-    else
-      SG_LOG(SG_INPUT, SG_ALERT, "No path supplied for object");
-  }
-}
-
-SGMaterial::ObjectGroup::~ObjectGroup ()
-{
-  for (unsigned int i = 0; i < _objects.size(); i++) {
-    delete _objects[i];
-    _objects[i] = 0;
-  }
-}
-
-double
-SGMaterial::ObjectGroup::get_range_m () const
-{
-  return _range_m;
-}
-
-int
-SGMaterial::ObjectGroup::get_object_count () const
-{
-  return _objects.size();
-}
-
-SGMaterial::Object *
-SGMaterial::ObjectGroup::get_object (int index) const
-{
-  return _objects[index];
-}
-
-
 \f
 ////////////////////////////////////////////////////////////////////////
 // Constructors and destructor.
@@ -334,7 +153,7 @@ SGMaterial::read_properties( const string &fg_root, const SGPropertyNode * props
   vector<SGPropertyNode_ptr> object_group_nodes =
     ((SGPropertyNode *)props)->getChildren("object-group");
   for (unsigned int i = 0; i < object_group_nodes.size(); i++)
-    object_groups.push_back(new ObjectGroup(object_group_nodes[i]));
+    object_groups.push_back(new SGMatModelGroup(object_group_nodes[i]));
 }
 
 
@@ -429,4 +248,4 @@ void SGMaterial::set_ssg_state( ssgSimpleState *s )
     texture_loaded = true;
 }
 
-// end of newmat.cxx
+// end of mat.cxx