]> git.mxchange.org Git - flightgear.git/commitdiff
A few enhancements to allow object definitions to reference new textures
authorcurt <curt>
Fri, 2 Jun 2000 23:37:40 +0000 (23:37 +0000)
committercurt <curt>
Fri, 2 Jun 2000 23:37:40 +0000 (23:37 +0000)
on the fly.

src/Objects/material.cxx
src/Objects/material.hxx
src/Objects/materialmgr.cxx
src/Objects/materialmgr.hxx
src/Objects/obj.cxx

index 737e8471b9e3f4e361c29260d52bea9a19060b05..2c53dbe4dfc2b1552700603ccce18b4f8d16d5a0 100644 (file)
@@ -64,6 +64,22 @@ FGMaterial::FGMaterial ( void )
 }
 
 
+// Constructor
+FGMaterial::FGMaterial ( const string &name )
+    : loaded(false),
+      alpha(0)
+    // , list_size(0)
+{
+    texture_name = name;
+    xsize = ysize = 0;
+    alpha = 0; 
+    ambient[0]  = ambient[1]  = ambient[2]  = ambient[3]  = 1.0;
+    diffuse[0]  = diffuse[1]  = diffuse[2]  = diffuse[3]  = 1.0;
+    specular[0] = specular[1] = specular[2] = specular[3] = 1.0;
+    emission[0] = emission[1] = emission[2] = emission[3] = 1.0;
+}
+
+
 istream&
 operator >> ( istream& in, FGMaterial& m )
 {
index 464189e45373cd2c950753914cbda0cb2e803bd9..32eb83be2713cc93cbacb082e0b34fe4fac8570d 100644 (file)
@@ -78,6 +78,7 @@ public:
 
     // Constructor
     FGMaterial ( void );
+    FGMaterial ( const string& name );
 
     // Destructor
     ~FGMaterial ( void );
index 44180cfe4998d0bb420fed4a486bb027846d0897..ec27a1b339bd3e7f72efa5030be5812d5f3801d7 100644 (file)
@@ -262,6 +262,103 @@ fgMATERIAL_MGR::load_lib ( void )
 }
 
 
+// Load a library of material properties
+bool
+fgMATERIAL_MGR::add_item ( const string &path )
+{
+    string material_name = path;
+    int pos = path.rfind( "/" );
+    material_name = material_name.substr( pos + 1 );
+
+    FGMaterial m( material_name );
+
+    FGMaterialSlot m_slot;
+    m_slot.set_m( m );
+
+    // build the ssgSimpleState
+    FGPath tex_file( path );
+
+    FG_LOG( FG_TERRAIN, FG_INFO, "  Loading material " 
+           << material_name << " (" << tex_file.c_str() << ")");
+
+#if EXTRA_DEBUG
+    m.dump_info();
+#endif
+           
+    ssgStateSelector *state = new ssgStateSelector(2);
+    ssgSimpleState *textured = new ssgSimpleState();
+    ssgSimpleState *nontextured = new ssgSimpleState();
+
+    // Set up the textured state
+    textured->enable( GL_LIGHTING );
+    if ( current_options.get_shading() == 1 ) {
+       textured->setShadeModel( GL_SMOOTH );
+    } else {
+       textured->setShadeModel( GL_FLAT );
+    }
+
+    textured->enable ( GL_CULL_FACE ) ;
+    textured->enable( GL_TEXTURE_2D );
+    textured->disable( GL_BLEND );
+    textured->disable( GL_ALPHA_TEST );
+    textured->setTexture( (char *)tex_file.c_str() );
+    textured->enable( GL_COLOR_MATERIAL );
+    textured->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
+    textured->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
+    textured->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
+
+    // Set up the coloured state
+    nontextured->enable( GL_LIGHTING );
+    if ( current_options.get_shading() == 1 ) {
+       nontextured->setShadeModel( GL_SMOOTH );
+    } else {
+       nontextured->setShadeModel( GL_FLAT );
+    }
+
+    nontextured->enable ( GL_CULL_FACE      ) ;
+    nontextured->disable( GL_TEXTURE_2D );
+    nontextured->disable( GL_BLEND );
+    nontextured->disable( GL_ALPHA_TEST );
+    nontextured->disable( GL_COLOR_MATERIAL );
+    GLfloat *ambient, *diffuse, *specular, *emission;
+    ambient = m.get_ambient();
+    diffuse = m.get_diffuse();
+    specular = m.get_specular();
+    emission = m.get_emission();
+
+    /* cout << "ambient = " << ambient[0] << "," << ambient[1] 
+       << "," << ambient[2] << endl; */
+    nontextured->setMaterial ( GL_AMBIENT, 
+                              ambient[0], ambient[1], 
+                              ambient[2], ambient[3] ) ;
+    nontextured->setMaterial ( GL_DIFFUSE, 
+                              diffuse[0], diffuse[1], 
+                              diffuse[2], diffuse[3] ) ;
+    nontextured->setMaterial ( GL_SPECULAR, 
+                              specular[0], specular[1], 
+                              specular[2], specular[3] ) ;
+    nontextured->setMaterial ( GL_EMISSION, 
+                              emission[0], emission[1], 
+                              emission[2], emission[3] ) ;
+
+    state->setStep( 0, textured );    // textured
+    state->setStep( 1, nontextured ); // untextured
+
+    // Choose the appropriate starting state.
+    if ( current_options.get_textures() ) {
+       state->selectStep(0);
+    } else {
+       state->selectStep(1);
+    }
+
+    m_slot.set_state( state );
+
+    material_mgr.material_map[material_name] = m_slot;
+
+    return 1;
+}
+
+
 // Initialize the transient list of fragments for each material property
 void
 fgMATERIAL_MGR::init_transient_material_lists( void )
index db57805e0ad90996dba4330d8541fe0c93735a0c..e999e89510ac47f44dc433248b9a9be9ecd37a88 100644 (file)
@@ -145,6 +145,9 @@ public:
     // Load a library of material properties
     int load_lib ( void );
 
+    // Add the named texture with default properties
+    bool add_item( const string &name );
+
     inline bool loaded() const { return materials_loaded; }
 
     // Initialize the transient list of fragments for each material property
index 2eb51231d674a2b5b8b2412002d0b6059450d926..9fbff7d1bba7ffb7f1445aa2b9861b97ab7bb4a4 100644 (file)
@@ -458,9 +458,27 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t, const bool is_base) {
                
                // find this material in the properties list
                if ( ! material_mgr.find( material, fragment.material_ptr )) {
-                   FG_LOG( FG_TERRAIN, FG_ALERT, 
-                           "Ack! unknown usemtl name = " << material 
-                           << " in " << path );
+                   // see if this is an on the fly texture
+                   string file = path;
+                   int pos = file.rfind( "/" );
+                   file = file.substr( 0, pos );
+                   cout << "current file = " << file << endl;
+                   file += "/";
+                   file += material;
+                   cout << "current file = " << file << endl;
+                   if ( ! material_mgr.add_item( file ) ) {
+                       FG_LOG( FG_TERRAIN, FG_ALERT, 
+                               "Ack! unknown usemtl name = " << material 
+                               << " in " << path );
+                   } else {
+                       // locate our newly created material
+                       if ( !material_mgr.find( material, fragment.material_ptr ) ) {
+                           FG_LOG( FG_TERRAIN, FG_ALERT, 
+                                   "Ack! bad on the fly materia create = "
+                                   << material << " in " << path );
+                       }
+                           
+                   }
                }
 
                // set the texture width and height values for this