]> git.mxchange.org Git - flightgear.git/commitdiff
Create an instance of SGMaterialLib in the "globals" structure and use
authorcurt <curt>
Wed, 14 May 2003 18:33:56 +0000 (18:33 +0000)
committercurt <curt>
Wed, 14 May 2003 18:33:56 +0000 (18:33 +0000)
that.

src/Main/fg_init.cxx
src/Main/globals.hxx
src/Main/main.cxx
src/Objects/apt_signs.cxx
src/Objects/apt_signs.hxx
src/Objects/obj.cxx
src/Objects/obj.hxx
src/Objects/pt_lights.cxx
src/Objects/pt_lights.hxx
src/Scenery/tileentry.cxx
src/Scenery/tileentry.hxx

index adf2f936ba8f16eacd78856cbf226b3df194d373..9949478d420f7f723d797a650bff8be2cd616cb7 100644 (file)
@@ -1314,7 +1314,7 @@ bool fgInitSubsystems() {
 
     SGPath mpath( globals->get_fg_root() );
     mpath.append( "materials.xml" );
-    if ( ! material_lib.load( globals->get_fg_root(), mpath.str() ) ) {
+    if ( ! globals->get_matlib()->load(globals->get_fg_root(), mpath.str()) ) {
         SG_LOG( SG_GENERAL, SG_ALERT, "Error loading material lib!" );
         exit(-1);
     }
index 4a6dda60049a258744e39d0c113c148ad18dfcc8..905752c6dfe092ab9662e0d70581ddbeb7e031a9 100644 (file)
@@ -52,6 +52,7 @@ class SGEphemeris;
 
 class SGCommandMgr;
 class SGMagVar;
+class SGMaterialLib;
 class SGModelLoader;
 class SGPropertyNode;
 class SGRoute;
@@ -120,6 +121,9 @@ private:
     // Magnetic Variation
     SGMagVar *mag;
 
+    // Material properties library
+    SGMaterialLib *matlib;
+
     // Current autopilot
     FGAutopilot *autopilot;
 
@@ -232,6 +236,9 @@ public:
     inline SGMagVar *get_mag() const { return mag; }
     inline void set_mag( SGMagVar *m ) { mag = m; }
 
+    inline SGMaterialLib *get_matlib() const { return matlib; }
+    inline void set_matlib( SGMaterialLib *m ) { matlib = m; }
+
     inline FGAutopilot *get_autopilot() const { return autopilot; }
     inline void set_autopilot( FGAutopilot *ap) { autopilot = ap; }
 
index d7c3c38d515c0354bfc57077cda21bcc4c225d00..24f294a6e19b7a108b1b6828c08725e46edeafdc 100644 (file)
@@ -1228,7 +1228,7 @@ static void fgMainLoop( void ) {
     globals->get_io()->update( delta_time_sec );
 
     // see if we need to load any deferred-load textures
-    material_lib.load_next_deferred();
+    globals->get_matlib()->load_next_deferred();
 
     // Run audio scheduler
 #ifdef ENABLE_AUDIO_SUPPORT
@@ -1681,6 +1681,7 @@ static bool fgMainInit( int argc, char **argv ) {
     ssgModelPath( (char *)modelpath.c_str() );
 
     // Initialize the global scenery manager
+    globals->set_matlib( new SGMaterialLib );
     globals->set_scenery( new FGScenery );
     globals->get_scenery()->init();
     globals->get_scenery()->bind();
index ee377b64e814a802ca903d6aa5fa045d5c6caa31..cf842a85799016295d0f03262aa7b20476b941c5 100644 (file)
@@ -28,7 +28,9 @@
 #include "obj.hxx"
 
 
-ssgBranch *gen_taxi_sign( const string path, const string content ) {
+ssgBranch *gen_taxi_sign( SGMaterialLib *matlib,
+                          const string path, const string content )
+{
     // for demo purposes we assume each element (letter) is 1x1 meter.
     // Sign is placed 0.25 meters above the ground
 
@@ -95,7 +97,7 @@ ssgBranch *gen_taxi_sign( const string path, const string content ) {
        tex_index.push_back( 2 );
        tex_index.push_back( 3 );
 
-       ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
+       ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, matlib, material,
                                  nodes, normals, texcoords,
                                  vertex_index, normal_index, tex_index,
                                  false, NULL );
@@ -107,7 +109,9 @@ ssgBranch *gen_taxi_sign( const string path, const string content ) {
 }
 
 
-ssgBranch *gen_runway_sign( const string path, const string name ) {
+ssgBranch *gen_runway_sign( SGMaterialLib *matlib,
+                            const string path, const string name )
+{
     // for demo purposes we assume each element (letter) is 1x1 meter.
     // Sign is placed 0.25 meters above the ground
 
@@ -152,7 +156,7 @@ ssgBranch *gen_runway_sign( const string path, const string name ) {
     tex_index.push_back( 2 );
     tex_index.push_back( 3 );
 
-    ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, material,
+    ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, matlib, material,
                              nodes, normals, texcoords,
                              vertex_index, normal_index, tex_index,
                              false, NULL );
index 1c0df1c15164a4ff7fe3c2140bef15430727c07a..edd96dfb13df86ceac3f69a6dc1a8fd2008e131b 100644 (file)
 
 #include <plib/ssg.h>          // plib include
 
+class SGMaterialLib;            // forward declaration
+
 SG_USING_STD(string);
 
 
 // Generate a taxi sign
-ssgBranch *gen_taxi_sign( const string path, const string content );
+ssgBranch *gen_taxi_sign( SGMaterialLib *matlib,
+                          const string path, const string content );
 
 
 // Generate a runway sign
-ssgBranch *gen_runway_sign( const string path, const string name );
+ssgBranch *gen_runway_sign( SGMaterialLib *matlib,
+                            const string path, const string name );
 
 
 #endif // _APT_SIGNS_HXX
index 85395e309406d02aee09db09734f780067b3e48a..0beeb9eb30d0423b9caa7b826abc57ed715e46ad 100644 (file)
@@ -1,4 +1,4 @@
-// obj.hxx -- routines to handle loading scenery and building the plib
+// obj.cxx -- routines to handle loading scenery and building the plib
 //            scene graph.
 //
 // Written by Curtis Olson, started October 1997.
@@ -58,7 +58,6 @@
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Time/light.hxx>
-#include <Scenery/tileentry.hxx>
 
 #include "pt_lights.hxx"
 #include "obj.hxx"
@@ -85,29 +84,26 @@ runway_lights_pretrav (ssgEntity * e, int mask)
 
 // Generate an ocean tile
 bool fgGenTile( const string& path, SGBucket b,
-                      Point3D *center,
-                      double *bounding_radius,
-                      ssgBranch* geometry )
+                Point3D *center, double *bounding_radius,
+                SGMaterialLib *matlib, ssgBranch* geometry )
 {
-    SGMaterial *newmat;
-
     ssgSimpleState *state = NULL;
 
-    geometry -> setName ( (char *)path.c_str() ) ;
+    geometry->setName( (char *)path.c_str() );
 
     double tex_width = 1000.0;
     // double tex_height;
 
     // find Ocean material in the properties list
-    newmat = material_lib.find( "Ocean" );
-    if ( newmat != NULL ) {
+    SGMaterial *mat = matlib->find( "Ocean" );
+    if ( mat != NULL ) {
         // set the texture width and height values for this
         // material
-        tex_width = newmat->get_xsize();
+        tex_width = mat->get_xsize();
         // tex_height = newmat->get_ysize();
         
         // set ssgState
-        state = newmat->get_state();
+        state = mat->get_state();
     } else {
         SG_LOG( SG_TERRAIN, SG_ALERT, 
                 "Ack! unknown usemtl name = " << "Ocean" 
@@ -282,9 +278,9 @@ class LeafUserData : public ssgBase
 {
 public:
     bool is_filled_in;
-    ssgLeaf * leaf;
-    SGMaterial * mat;
-    ssgBranch * branch;
+    ssgLeaf *leaf;
+    SGMaterial *mat;
+    ssgBranch *branch;
     float sin_lat;
     float cos_lat;
     float sin_lon;
@@ -660,26 +656,19 @@ leaf_out_of_range_callback (ssgEntity * entity, int mask)
 static void
 gen_random_surface_objects (ssgLeaf *leaf,
                             ssgBranch *branch,
-                            Point3D * center,
-                            const string &material_name)
+                            Point3D *center,
+                            SGMaterial *mat )
 {
                                 // If the surface has no triangles, return
                                 // now.
     int num_tris = leaf->getNumTriangles();
     if (num_tris < 1)
-      return;
-
-                                // Get the material for this surface.
-    SGMaterial * mat = material_lib.find(material_name);
-    if (mat == 0) {
-      SG_LOG(SG_INPUT, SG_ALERT, "Unknown material " << material_name);
-      return;
-    }
+        return;
 
                                 // If the material has no randomly-placed
                                 // objects, return now.
     if (mat->get_object_group_count() < 1)
-      return;
+        return;
 
                                 // Calculate the geodetic centre of
                                 // the tile, for aligning automatic
@@ -731,7 +720,8 @@ gen_random_surface_objects (ssgLeaf *leaf,
 ////////////////////////////////////////////////////////////////////////
 
 ssgLeaf *gen_leaf( const string& path,
-                   const GLenum ty, const string& material,
+                   const GLenum ty, 
+                   SGMaterialLib *matlib, const string& material,
                    const point_list& nodes, const point_list& normals,
                    const point_list& texcoords,
                    const int_list& node_index,
@@ -743,8 +733,8 @@ ssgLeaf *gen_leaf( const string& path,
     ssgSimpleState *state = NULL;
     float coverage = -1;
 
-    SGMaterial *newmat = material_lib.find( material );
-    if ( newmat == NULL ) {
+    SGMaterial *mat = matlib->find( material );
+    if ( mat == NULL ) {
         // see if this is an on the fly texture
         string file = path;
         string::size_type pos = file.rfind( "/" );
@@ -753,14 +743,14 @@ ssgLeaf *gen_leaf( const string& path,
         file += "/";
         file += material;
         // cout << "current file = " << file << endl;
-        if ( ! material_lib.add_item( file ) ) {
+        if ( ! matlib->add_item( file ) ) {
             SG_LOG( SG_TERRAIN, SG_ALERT, 
                     "Ack! unknown usemtl name = " << material 
                     << " in " << path );
         } else {
             // locate our newly created material
-            newmat = material_lib.find( material );
-            if ( newmat == NULL ) {
+            mat = matlib->find( material );
+            if ( mat == NULL ) {
                 SG_LOG( SG_TERRAIN, SG_ALERT, 
                         "Ack! bad on the fly material create = "
                         << material << " in " << path );
@@ -768,13 +758,13 @@ ssgLeaf *gen_leaf( const string& path,
         }
     }
 
-    if ( newmat != NULL ) {
+    if ( mat != NULL ) {
         // set the texture width and height values for this
         // material
-        tex_width = newmat->get_xsize();
-        tex_height = newmat->get_ysize();
-        state = newmat->get_state();
-        coverage = newmat->get_light_coverage();
+        tex_width = mat->get_xsize();
+        tex_height = mat->get_ysize();
+        state = mat->get_state();
+        coverage = mat->get_light_coverage();
         // cout << "(w) = " << tex_width << " (h) = "
         //      << tex_width << endl;
     } else {
@@ -879,6 +869,7 @@ ssgLeaf *gen_leaf( const string& path,
 bool fgBinObjLoad( const string& path, const bool is_base,
                    Point3D *center,
                    double *bounding_radius,
+                   SGMaterialLib *matlib,
                    ssgBranch* geometry,
                    ssgBranch* rwy_lights,
                    ssgBranch* taxi_lights,
@@ -920,7 +911,7 @@ bool fgBinObjLoad( const string& path, const bool is_base,
             // returns a transform -> lod -> leaf structure
             ssgBranch *branch = gen_directional_lights( nodes, normals,
                                                         pts_v[i], pts_n[i],
-                                                        pt_materials[i],
+                                                        matlib, pt_materials[i],
                                                         up );
             // branches don't honor callbacks as far as I know so I'm
             // commenting this out to avoid a plib runtime warning.
@@ -934,7 +925,7 @@ bool fgBinObjLoad( const string& path, const bool is_base,
         } else {
             material = pt_materials[i];
             tex_index.clear();
-            ssgLeaf *leaf = gen_leaf( path, GL_POINTS, material,
+            ssgLeaf *leaf = gen_leaf( path, GL_POINTS, matlib, material,
                                       nodes, normals, texcoords,
                                       pts_v[i], pts_n[i], tex_index,
                                       false, ground_lights );
@@ -961,14 +952,21 @@ bool fgBinObjLoad( const string& path, const bool is_base,
     group_list const& tris_n = obj.get_tris_n();
     group_list const& tris_tc = obj.get_tris_tc();
     for ( i = 0; i < tris_v.size(); ++i ) {
-        ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, tri_materials[i],
+        ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLES, matlib, tri_materials[i],
                                   nodes, normals, texcoords,
                                   tris_v[i], tris_n[i], tris_tc[i],
                                   is_base, ground_lights );
 
-        if (use_random_objects)
-          gen_random_surface_objects(leaf, random_object_branch,
-                                     center, tri_materials[i]);
+        if ( use_random_objects ) {
+            SGMaterial *mat = matlib->find( tri_materials[i] );
+            if ( mat == NULL ) {
+                SG_LOG( SG_INPUT, SG_ALERT,
+                        "Unknown material for random surface objects = "
+                        << tri_materials[i] );
+            }
+            gen_random_surface_objects( leaf, random_object_branch,
+                                        center, mat );
+        }
         geometry->addKid( leaf );
     }
 
@@ -978,14 +976,22 @@ bool fgBinObjLoad( const string& path, const bool is_base,
     group_list const& strips_n = obj.get_strips_n();
     group_list const& strips_tc = obj.get_strips_tc();
     for ( i = 0; i < strips_v.size(); ++i ) {
-        ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP, strip_materials[i],
+        ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_STRIP,
+                                  matlib, strip_materials[i],
                                   nodes, normals, texcoords,
                                   strips_v[i], strips_n[i], strips_tc[i],
                                   is_base, ground_lights );
 
-        if (use_random_objects)
-          gen_random_surface_objects(leaf, random_object_branch,
-                                     center,strip_materials[i]);
+        if ( use_random_objects ) {
+            SGMaterial *mat = matlib->find( strip_materials[i] );
+            if ( mat == NULL ) {
+                SG_LOG( SG_INPUT, SG_ALERT,
+                        "Unknown material for random surface objects = "
+                        << strip_materials[i] );
+            }
+            gen_random_surface_objects( leaf, random_object_branch,
+                                        center, mat );
+        }
         geometry->addKid( leaf );
     }
 
@@ -995,13 +1001,21 @@ bool fgBinObjLoad( const string& path, const bool is_base,
     group_list const& fans_n = obj.get_fans_n();
     group_list const& fans_tc = obj.get_fans_tc();
     for ( i = 0; i < fans_v.size(); ++i ) {
-        ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN, fan_materials[i],
+        ssgLeaf *leaf = gen_leaf( path, GL_TRIANGLE_FAN,
+                                  matlib, fan_materials[i],
                                   nodes, normals, texcoords,
                                   fans_v[i], fans_n[i], fans_tc[i],
                                   is_base, ground_lights );
-        if (use_random_objects)
-          gen_random_surface_objects(leaf, random_object_branch,
-                                     center, fan_materials[i]);
+        if ( use_random_objects ) {
+            SGMaterial *mat = matlib->find( fan_materials[i] );
+            if ( mat == NULL ) {
+                SG_LOG( SG_INPUT, SG_ALERT,
+                        "Unknown material for random surface objects = "
+                        << fan_materials[i] );
+            }
+            gen_random_surface_objects( leaf, random_object_branch,
+                                        center, mat );
+        }
         geometry->addKid( leaf );
     }
 
index c4842e82083d632d00e5620a6eee72a23e4fc202..4197fdcf97aac68aafa48fd02f820dca7b0f9487 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <simgear/bucket/newbucket.hxx>
 #include <simgear/math/sg_types.hxx>
+#include <simgear/scene/material/matlib.hxx>
 
 SG_USING_STD(string);
 
@@ -51,6 +52,7 @@ SG_USING_STD(string);
 bool fgBinObjLoad( const string& path, const bool is_base,
                    Point3D *center,
                    double *bounding_radius,
+                   SGMaterialLib *matlib,
                    ssgBranch* geometry,
                    ssgBranch* rwy_lights,
                    ssgBranch* taxi_lights,
@@ -58,14 +60,14 @@ bool fgBinObjLoad( const string& path, const bool is_base,
 
 // Generate an ocean tile
 bool fgGenTile( const string& path, SGBucket b,
-                Point3D *center,
-                double *bounding_radius,
-                ssgBranch* geometry );
+                Point3D *center, double *bounding_radius,
+                SGMaterialLib *matlib, ssgBranch* geometry );
 
 
 // Create a ssg leaf
 ssgLeaf *gen_leaf( const string& path,
-                   const GLenum ty, const string& material,
+                   const GLenum ty,
+                   SGMaterialLib *matlib, const string& material,
                    const point_list& nodes, const point_list& normals,
                    const point_list& texcoords,
                    const int_list& node_index,
index 96f05e83dd09c2861e4e0950123278ecdab65eec..393606a7173d6c8d7962213e727138744bdc638e 100644 (file)
@@ -48,7 +48,7 @@ static int StrobePostDraw( ssgEntity *e ) {
 
 // Generate a directional light
 ssgLeaf *gen_directional_light( sgVec3 pt, sgVec3 dir, sgVec3 up, 
-                                const string &material ) {
+                                const SGMaterial *mat ) {
 
     // calculate a vector perpendicular to dir and up
     sgVec3 perp;
@@ -117,13 +117,10 @@ ssgLeaf *gen_directional_light( sgVec3 pt, sgVec3 dir, sgVec3 up,
     ssgLeaf *leaf = 
         new ssgVtxTable ( GL_TRIANGLES, vl, nl, NULL, cl );
 
-    SGMaterial *newmat = material_lib.find( material );
-
-    if ( newmat != NULL ) {
-        leaf->setState( newmat->get_state() );
+    if ( mat != NULL ) {
+        leaf->setState( mat->get_state() );
     } else {
-        SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: can't material = "
-                << material );
+        SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: mat = NULL" );
     }
 
     return leaf;
@@ -159,12 +156,12 @@ static void calc_center_point( const point_list &nodes,
 }
 
 
-ssgTransform *gen_dir_light_group( const point_list &nodes,
-                                   const point_list &normals,
-                                   const int_list &pnt_i,
-                                   const int_list &nml_i,
-                                   const string &material,
-                                   sgVec3 up, bool vertical = false )
+static ssgTransform *gen_dir_light_group( const point_list &nodes,
+                                          const point_list &normals,
+                                          const int_list &pnt_i,
+                                          const int_list &nml_i,
+                                          const SGMaterial *mat,
+                                          sgVec3 up, bool vertical = false )
 {
     sgVec3 center;
     calc_center_point( nodes, pnt_i, center );
@@ -234,13 +231,10 @@ ssgTransform *gen_dir_light_group( const point_list &nodes,
     ssgLeaf *leaf = 
         new ssgVtxTable ( GL_TRIANGLES, vl, nl, NULL, cl );
 
-    SGMaterial *newmat = material_lib.find( material );
-
-    if ( newmat != NULL ) {
-        leaf->setState( newmat->get_state() );
+    if ( mat != NULL ) {
+        leaf->setState( mat->get_state() );
     } else {
-        SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: can't material = "
-                << material );
+        SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: material = NULL" );
     }
 
     // put an LOD on each lighting component
@@ -260,12 +254,12 @@ ssgTransform *gen_dir_light_group( const point_list &nodes,
 }
 
 
-ssgTransform *gen_reil_lights( const point_list &nodes,
-                               const point_list &normals,
-                               const int_list &pnt_i,
-                               const int_list &nml_i,
-                               const string &material,
-                               sgVec3 up )
+static ssgTransform *gen_reil_lights( const point_list &nodes,
+                                      const point_list &normals,
+                                      const int_list &pnt_i,
+                                      const int_list &nml_i,
+                                      SGMaterialLib *matlib,
+                                      sgVec3 up )
 {
     sgVec3 center;
     calc_center_point( nodes, pnt_i, center );
@@ -319,13 +313,13 @@ ssgTransform *gen_reil_lights( const point_list &nodes,
     ssgLeaf *leaf = 
         new ssgVtxTable ( GL_TRIANGLES, vl, nl, NULL, cl );
 
-    SGMaterial *newmat = material_lib.find( "RWY_WHITE_LIGHTS" );
+    SGMaterial *mat = matlib->find( "RWY_WHITE_LIGHTS" );
 
-    if ( newmat != NULL ) {
-        leaf->setState( newmat->get_state() );
+    if ( mat != NULL ) {
+        leaf->setState( mat->get_state() );
     } else {
-        SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: can't material = "
-                << material );
+        SG_LOG( SG_TERRAIN, SG_ALERT,
+                "Warning: can't find material = RWY_WHITE_LIGHTS" );
     }
 
     leaf->setCallback( SSG_CALLBACK_PREDRAW, StrobePreDraw );
@@ -359,12 +353,12 @@ ssgTransform *gen_reil_lights( const point_list &nodes,
 }
 
 
-ssgTransform *gen_odals_lights( const point_list &nodes,
-                                const point_list &normals,
-                                const int_list &pnt_i,
-                                const int_list &nml_i,
-                                const string &material,
-                                sgVec3 up )
+static ssgTransform *gen_odals_lights( const point_list &nodes,
+                                       const point_list &normals,
+                                       const int_list &pnt_i,
+                                       const int_list &nml_i,
+                                       SGMaterialLib *matlib,
+                                       sgVec3 up )
 {
     sgVec3 center;
     calc_center_point( nodes, pnt_i, center );
@@ -375,6 +369,13 @@ ssgTransform *gen_odals_lights( const point_list &nodes,
     sgVec4 color;
     sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
 
+    // we don't want directional lights here
+    SGMaterial *mat = matlib->find( "GROUND_LIGHTS" );
+    if ( mat == NULL ) {
+        SG_LOG( SG_TERRAIN, SG_ALERT,
+                "Warning: can't material = GROUND_LIGHTS" );
+    }
+
     // center line strobes
     int i;
     sgVec3 pt;
@@ -392,16 +393,7 @@ ssgTransform *gen_odals_lights( const point_list &nodes,
         ssgLeaf *leaf = 
             new ssgVtxTable ( GL_POINTS, vl, NULL, NULL, cl );
 
-        // we don't want directional lights here
-        SGMaterial *newmat = material_lib.find( "GROUND_LIGHTS" );
-
-        if ( newmat != NULL ) {
-            leaf->setState( newmat->get_state() );
-        } else {
-            SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: can't material = "
-                    << material );
-        }
-
+        leaf->setState( mat->get_state() );
         leaf->setCallback( SSG_CALLBACK_PREDRAW, StrobePreDraw );
         leaf->setCallback( SSG_CALLBACK_POSTDRAW, StrobePostDraw );
 
@@ -427,16 +419,7 @@ ssgTransform *gen_odals_lights( const point_list &nodes,
     ssgLeaf *leaf = 
         new ssgVtxTable ( GL_POINTS, vl, NULL, NULL, cl );
 
-    // we don't want directional lights here
-    SGMaterial *newmat = material_lib.find( "GROUND_LIGHTS" );
-
-    if ( newmat != NULL ) {
-        leaf->setState( newmat->get_state() );
-    } else {
-        SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: can't material = "
-                << material );
-    }
-
+    leaf->setState( mat->get_state() );
     leaf->setCallback( SSG_CALLBACK_PREDRAW, StrobePreDraw );
     leaf->setCallback( SSG_CALLBACK_POSTDRAW, StrobePostDraw );
 
@@ -466,12 +449,12 @@ ssgTransform *gen_odals_lights( const point_list &nodes,
 }
 
 
-ssgTransform *gen_rabbit_lights( const point_list &nodes,
-                                 const point_list &normals,
-                                 const int_list &pnt_i,
-                                 const int_list &nml_i,
-                                 const string &material,
-                                 sgVec3 up )
+static ssgTransform *gen_rabbit_lights( const point_list &nodes,
+                                        const point_list &normals,
+                                        const int_list &pnt_i,
+                                        const int_list &nml_i,
+                                        SGMaterialLib *matlib,
+                                        sgVec3 up )
 {
     sgVec3 center;
     calc_center_point( nodes, pnt_i, center );
@@ -482,6 +465,12 @@ ssgTransform *gen_rabbit_lights( const point_list &nodes,
 
     ssgTimedSelector *rabbit = new ssgTimedSelector;
 
+    SGMaterial *mat = matlib->find( "RWY_WHITE_LIGHTS" );
+    if ( mat == NULL ) {
+        SG_LOG( SG_TERRAIN, SG_ALERT,
+                "Warning: can't material = RWY_WHITE_LIGHTS" );
+    }
+
     int i;
     sgVec3 pt, normal;
     for ( i = (int)pnt_i.size() - 1; i >= 0; --i ) {
@@ -527,15 +516,7 @@ ssgTransform *gen_rabbit_lights( const point_list &nodes,
         ssgLeaf *leaf = 
             new ssgVtxTable ( GL_TRIANGLES, vl, nl, NULL, cl );
 
-        SGMaterial *newmat = material_lib.find( "RWY_WHITE_LIGHTS" );
-
-        if ( newmat != NULL ) {
-            leaf->setState( newmat->get_state() );
-        } else {
-            SG_LOG( SG_TERRAIN, SG_ALERT, "Warning: can't material = "
-                    << material );
-        }
-
+        leaf->setState( mat->get_state() );
         leaf->setCallback( SSG_CALLBACK_PREDRAW, StrobePreDraw );
         leaf->setCallback( SSG_CALLBACK_POSTDRAW, StrobePostDraw );
 
@@ -564,8 +545,10 @@ ssgTransform *gen_rabbit_lights( const point_list &nodes,
 }
 
 
-// Generate a directional light
-ssgLeaf *gen_normal_line( sgVec3 pt, sgVec3 dir, sgVec3 up ) {
+#if 0 // debugging infrastructure
+// Generate a normal line 
+static ssgLeaf *gen_normal_line( SGMaterialLib *matlib,
+                                 sgVec3 pt, sgVec3 dir, sgVec3 up ) {
 
     ssgVertexArray *vl = new ssgVertexArray( 3 );
     ssgColourArray *cl = new ssgColourArray( 3 );
@@ -584,47 +567,51 @@ ssgLeaf *gen_normal_line( sgVec3 pt, sgVec3 dir, sgVec3 up ) {
     ssgLeaf *leaf = 
         new ssgVtxTable ( GL_LINES, vl, NULL, NULL, cl );
 
-    SGMaterial *newmat = material_lib.find( "GROUND_LIGHTS" );
-    leaf->setState( newmat->get_state() );
+    SGMaterial *mat = matlib->find( "GROUND_LIGHTS" );
+    leaf->setState( mat->get_state() );
 
     return leaf;
 }
+#endif
 
 
 ssgBranch *gen_directional_lights( const point_list &nodes,
                                    const point_list &normals,
                                    const int_list &pnt_i,
                                    const int_list &nml_i,
+                                   SGMaterialLib *matlib,
                                    const string &material,
                                    sgVec3 up )
 {
     sgVec3 nup;
     sgNormalizeVec3( nup, up );
 
+    SGMaterial *mat = matlib->find( material );
+
     if ( material == "RWY_REIL_LIGHTS" ) {
         // cout << "found a reil" << endl;
         ssgTransform *reil = gen_reil_lights( nodes, normals, pnt_i, nml_i,
-                                              material, up );
+                                              matlib, up );
         return reil;
     } else if ( material == "RWY_ODALS_LIGHTS" ) {
         // cout << "found a odals" << endl;
         ssgTransform *odals = gen_odals_lights( nodes, normals, pnt_i, nml_i,
-                                                material, up );
+                                                matlib, up );
         return odals;
     } else if ( material == "RWY_SEQUENCED_LIGHTS" ) {
         // cout << "found a rabbit" << endl;
         ssgTransform *rabbit = gen_rabbit_lights( nodes, normals,
                                                   pnt_i, nml_i,
-                                                  material, up );
+                                                  matlib, up );
         return rabbit;
     } else if ( material == "RWY_BLUE_TAXIWAY_LIGHTS" ) {
         ssgTransform *light_group = gen_dir_light_group( nodes, normals, pnt_i,
-                                                         nml_i, material, up,
+                                                         nml_i, mat, up,
                                                          true );
         return light_group;
     } else {
         ssgTransform *light_group = gen_dir_light_group( nodes, normals, pnt_i,
-                                                         nml_i, material, up );
+                                                         nml_i, mat, up );
         return light_group;
     }
 
index b78117ea307a60095e9e6a98742765d6df691851..2a2e4c01ce58f81c2fd8e24c37a8d4aa78668d5d 100644 (file)
@@ -99,6 +99,7 @@ ssgBranch *gen_directional_lights( const point_list &nodes,
                                    const point_list &normals,
                                    const int_list &pnt_i,
                                    const int_list &nml_i,
+                                   SGMaterialLib *matlib,
                                    const string &material,
                                    sgVec3 up );
 
index a307620bcf005e97f4468cae92a2a580d139021d..0e28acc0456974769f12bd12628b52d68ecef3fd 100644 (file)
@@ -27,6 +27,8 @@
 
 #include <simgear/compiler.h>
 
+#include STL_STRING
+
 #include <simgear/bucket/newbucket.hxx>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
@@ -47,6 +49,8 @@
 #include "tileentry.hxx"
 #include "tilemgr.hxx"
 
+SG_USING_STD(string);
+
 
 // Constructor
 FGTileEntry::FGTileEntry ( const SGBucket& b )
@@ -475,7 +479,9 @@ static int fgLightsPostdraw( ssgEntity *e ) {
 }
 
 
-ssgLeaf* FGTileEntry::gen_lights( ssgVertexArray *lights, int inc, float bright ) {
+ssgLeaf* FGTileEntry::gen_lights( SGMaterialLib *matlib, ssgVertexArray *lights,
+                                  int inc, float bright )
+{
     // generate a repeatable random seed
     float *p1 = lights->get( 0 );
     unsigned int *seed = (unsigned int *)p1;
@@ -525,8 +531,8 @@ ssgLeaf* FGTileEntry::gen_lights( ssgVertexArray *lights, int inc, float bright
         new ssgVtxTable ( GL_POINTS, vl, nl, tl, cl );
 
     // assign state
-    SGMaterial *newmat = material_lib.find( "GROUND_LIGHTS" );
-    leaf->setState( newmat->get_state() );
+    SGMaterial *mat = matlib->find( "GROUND_LIGHTS" );
+    leaf->setState( mat->get_state() );
     leaf->setCallback( SSG_CALLBACK_PREDRAW, fgLightsPredraw );
     leaf->setCallback( SSG_CALLBACK_POSTDRAW, fgLightsPostdraw );
 
@@ -534,7 +540,7 @@ ssgLeaf* FGTileEntry::gen_lights( ssgVertexArray *lights, int inc, float bright
 }
 
 
-bool FGTileEntry::obj_load( const std::string& path,
+bool FGTileEntry::obj_load( const string& path,
                             ssgBranch* geometry,
                             ssgBranch* rwy_lights,
                             ssgBranch* taxi_lights,
@@ -545,7 +551,7 @@ bool FGTileEntry::obj_load( const std::string& path,
 
     // try loading binary format
     if ( fgBinObjLoad( path, is_base,
-                       &c, &br, geometry,
+                       &c, &br, globals->get_matlib(), geometry,
                        rwy_lights, taxi_lights, ground_lights ) )
     {
         if ( is_base ) {
@@ -554,7 +560,9 @@ bool FGTileEntry::obj_load( const std::string& path,
         }
     } else {
         // default to an ocean tile
-        if ( fgGenTile( path, tile_bucket, &c, &br, geometry ) ) {
+        if ( fgGenTile( path, tile_bucket, &c, &br,
+                        globals->get_matlib(), geometry ) )
+        {
             center = c;
             bounding_radius = br;
         } else {
@@ -711,7 +719,8 @@ FGTileEntry::load( const SGPath& base, bool is_base )
                 obj_trans->setTransform( &obj_pos );
 
                 ssgBranch *custom_obj
-                    = gen_taxi_sign( custom_path.str(), name );
+                    = gen_taxi_sign( globals->get_matlib(),
+                                     custom_path.str(), name );
 
                 // wire the pieces together
                 if ( custom_obj != NULL ) {
@@ -739,7 +748,8 @@ FGTileEntry::load( const SGPath& base, bool is_base )
                 obj_trans->setTransform( &obj_pos );
 
                 ssgBranch *custom_obj
-                    = gen_runway_sign( custom_path.str(), name );
+                    = gen_runway_sign( globals->get_matlib(),
+                                       custom_path.str(), name );
 
                 // wire the pieces together
                 if ( custom_obj != NULL ) {
@@ -770,7 +780,8 @@ FGTileEntry::load( const SGPath& base, bool is_base )
         ssgBranch *geometry = new ssgBranch;
         Point3D c;
         double br;
-        if ( fgGenTile( basename.str(), tile_bucket, &c, &br, geometry ) ) {
+        if ( fgGenTile( basename.str(), tile_bucket, &c, &br,
+                        globals->get_matlib(), geometry ) ) {
             center = c;
             bounding_radius = br;
             new_tile -> addKid( geometry );
@@ -806,13 +817,13 @@ FGTileEntry::load( const SGPath& base, bool is_base )
         gnd_lights_brightness = new ssgSelector;
         ssgLeaf *lights;
 
-        lights = gen_lights( light_pts, 4, 0.7 );
+        lights = gen_lights( globals->get_matlib(), light_pts, 4, 0.7 );
         gnd_lights_brightness->addKid( lights );
 
-        lights = gen_lights( light_pts, 2, 0.85 );
+        lights = gen_lights( globals->get_matlib(), light_pts, 2, 0.85 );
         gnd_lights_brightness->addKid( lights );
 
-        lights = gen_lights( light_pts, 1, 1.0 );
+        lights = gen_lights( globals->get_matlib(), light_pts, 1, 1.0 );
         gnd_lights_brightness->addKid( lights );
 
         gnd_lights_range->addKid( gnd_lights_brightness );
index 18e3b429e30e2a6a0b59f03a81719c4a405dd4b6..d323aaaf8cf489c1aec6698b0d61304a4b6b5d8e 100644 (file)
@@ -146,14 +146,15 @@ private:
      */
     volatile int pending_models;
 
-    bool obj_load( const std::string& path,
-                        ssgBranch* geometry,
-                        ssgBranch* rwy_lights,
-                        ssgBranch* taxi_lights,
-                        ssgVertexArray* gound_lights,
-                        bool is_base );
-
-    ssgLeaf* gen_lights( ssgVertexArray *lights, int inc, float bright );
+    bool obj_load( const string& path,
+                   ssgBranch* geometry,
+                   ssgBranch* rwy_lights,
+                   ssgBranch* taxi_lights,
+                   ssgVertexArray* gound_lights,
+                   bool is_base );
+
+    ssgLeaf* gen_lights( SGMaterialLib *matlib, ssgVertexArray *lights,
+                         int inc, float bright );
 
     double timestamp;