#include <vector>
#include <map>
+#include <simgear/math/SGMath.hxx>
+
#include <plib/sg.h>
#include <plib/ssg.h>
/**
* Destructor.
*/
- virtual ~SGMaterial( void );
+ ~SGMaterial( void );
\f
* @return true if the texture loaded, false if it was loaded
* already.
*/
- virtual bool load_texture (int n = -1);
+ bool load_texture (int n = -1);
/**
* Get the textured state.
*/
- virtual ssgSimpleState *get_state (int n = -1) const;
+ ssgSimpleState *get_state (int n = -1) const;
/**
* Get the number of textures assigned to this material.
*/
- virtual inline int get_num() const { return _status.size(); }
+ inline int get_num() const { return _status.size(); }
/**
* Get the xsize of the texture, in meters.
*/
- virtual inline double get_xsize() const { return xsize; }
+ inline double get_xsize() const { return xsize; }
/**
* Get the ysize of the texture, in meters.
*/
- virtual inline double get_ysize() const { return ysize; }
+ inline double get_ysize() const { return ysize; }
/**
*
* @return The area (m^2?) covered by each light.
*/
- virtual inline double get_light_coverage () const { return light_coverage; }
+ inline double get_light_coverage () const { return light_coverage; }
+ /**
+ * Return if the surface material is solid, if it is not solid, a fluid
+ * can be assumed, that is usually water.
+ */
+ bool get_solid () const { return solid; }
/**
- * Get the number of randomly-placed objects defined for this material.
+ * Get the friction factor for that material
+ */
+ double get_friction_factor () const { return friction_factor; }
+
+ /**
+ * Get the rolling friction for that material
+ */
+ double get_rolling_friction () const { return rolling_friction; }
+
+ /**
+ * Get the bumpines for that material
+ */
+ double get_bumpiness () const { return bumpiness; }
+
+ /**
+ * Get the load resistence
+ */
+ double get_load_resistence () const { return load_resistence; }
+
+ /**
+ * Get the list of names for this material
*/
- virtual int get_object_group_count () const { return object_groups.size(); }
+ const vector<string>& get_names() const { return _names; }
+ /**
+ * add the given name to the list of names this material is known
+ */
+ void add_name(const string& name) { _names.push_back(name); }
+
+ /**
+ * Get the number of randomly-placed objects defined for this material.
+ */
+ int get_object_group_count () const { return object_groups.size(); }
/**
* Get a randomly-placed object for this material.
*/
- virtual SGMatModelGroup * get_object_group (int index) const {
+ SGMatModelGroup * get_object_group (int index) const {
return object_groups[index];
}
/**
* Return pointer to glyph class, or 0 if it doesn't exist.
*/
- virtual SGMaterialGlyph * get_glyph (const string& name) const {
- map<string, SGMaterialGlyph *>::const_iterator it = glyphs.find(name);
+ SGMaterialGlyph * get_glyph (const string& name) const {
+ map<string, SGSharedPtr<SGMaterialGlyph> >::const_iterator it = glyphs.find(name);
return it != glyphs.end() ? it->second : 0;
}
/**
* Initialization method, invoked by all public constructors.
*/
- virtual void init();
+ void init();
protected:
// coverage of night lighting.
double light_coverage;
+ // True if the material is solid, false if it is a fluid
+ bool solid;
+
+ // the friction factor of that surface material
+ double friction_factor;
+
+ // the rolling friction of that surface material
+ double rolling_friction;
+
+ // the bumpiness of that surface material
+ double bumpiness;
+
+ // the load resistence of that surface material
+ double load_resistence;
+
// material properties
- sgVec4 ambient, diffuse, specular, emission;
+ SGVec4f ambient, diffuse, specular, emission;
double shininess;
+ // the list of names for this material. May be empty.
+ vector<string> _names;
+
vector<SGSharedPtr<SGMatModelGroup> > object_groups;
// taxiway-/runway-sign texture elements
- map<string, SGMaterialGlyph *> glyphs;
+ map<string, SGSharedPtr<SGMaterialGlyph> > glyphs;
\f
////////////////////////////////////////////////////////////////////
};
-class SGMaterialGlyph {
+class SGMaterialGlyph : public SGReferenced {
public:
SGMaterialGlyph(SGPropertyNode *);
inline double get_left() const { return _left; }
double _right;
};
+class SGMaterialUserData : public ssgBase {
+public:
+ SGMaterialUserData(const SGMaterial* material) :
+ mMaterial(material)
+ {}
+ const SGMaterial* getMaterial() const
+ { return mMaterial; }
+private:
+ SGSharedPtr<const SGMaterial> mMaterial;
+};
+
#endif // _SG_MAT_HXX
# include <windows.h>
#endif
+#include <plib/ssg.h>
+
#include <simgear/compiler.h>
#include <simgear/constants.h>
#include <simgear/structure/exception.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/sgstream.hxx>
#include <simgear/props/props_io.hxx>
+#include <simgear/scene/tgdb/userdata.hxx>
#include "mat.hxx"
throw;
}
+ SGSharedPtr<SGMaterial> m;
+
int nMaterials = materials.nChildren();
for (int i = 0; i < nMaterials; i++) {
const SGPropertyNode * node = materials.getChild(i);
if (!strcmp(node->getName(), "material")) {
- SGSharedPtr<SGMaterial> m = new SGMaterial( fg_root, node, season );
+ m = new SGMaterial( fg_root, node, season );
vector<SGPropertyNode_ptr>names = node->getChildren("name");
for ( unsigned int j = 0; j < names.size(); j++ ) {
string name = names[j]->getStringValue();
// cerr << "Material " << name << endl;
matlib[name] = m;
+ m->add_name(name);
SG_LOG( SG_TERRAIN, SG_INFO, " Loading material "
<< names[j]->getStringValue() );
}
gnd_lights->enable( GL_BLEND );
gnd_lights->disable( GL_ALPHA_TEST );
gnd_lights->disable( GL_LIGHTING );
- matlib["GROUND_LIGHTS"] = new SGMaterial( gnd_lights );
+ m = new SGMaterial( gnd_lights );
+ m->add_name("GROUND_LIGHTS");
+ matlib["GROUND_LIGHTS"] = m;
GLuint tex_name;
rwy_white_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_white_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_white_lights->setTexture( tex_name );
- matlib["RWY_WHITE_LIGHTS"] = new SGMaterial( rwy_white_lights );
+ m = new SGMaterial( rwy_white_lights );
+ m->add_name("RWY_WHITE_LIGHTS");
+ matlib["RWY_WHITE_LIGHTS"] = m;
// For backwards compatibility ... remove someday
- matlib["RUNWAY_LIGHTS"] = new SGMaterial( rwy_white_lights );
- matlib["RWY_LIGHTS"] = new SGMaterial( rwy_white_lights );
+ m->add_name("RUNWAY_LIGHTS");
+ matlib["RUNWAY_LIGHTS"] = m;
+ m->add_name("RWY_LIGHTS");
+ matlib["RWY_LIGHTS"] = m;
// end of backwards compatitibilty
// hard coded runway medium intensity white light state
rwy_white_medium_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_white_medium_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_white_medium_lights->setTexture( tex_name );
- matlib["RWY_WHITE_MEDIUM_LIGHTS"]
- = new SGMaterial( rwy_white_medium_lights );
+ m = new SGMaterial( rwy_white_medium_lights );
+ m->add_name("RWY_WHITE_MEDIUM_LIGHTS");
+ matlib["RWY_WHITE_MEDIUM_LIGHTS"] = m;
// hard coded runway low intensity white light state
tex_name = gen_standard_dir_light_map( 235, 235, 195, 155 );
rwy_white_low_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_white_low_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_white_low_lights->setTexture( tex_name );
- matlib["RWY_WHITE_LOW_LIGHTS"]
- = new SGMaterial( rwy_white_low_lights );
+ m = new SGMaterial( rwy_white_low_lights );
+ m->add_name("RWY_WHITE_LOW_LIGHTS");
+ matlib["RWY_WHITE_LOW_LIGHTS"] = m;
// hard coded runway yellow light state
tex_name = gen_standard_dir_light_map( 235, 215, 20, 255 );
rwy_yellow_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_yellow_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_yellow_lights->setTexture( tex_name );
- matlib["RWY_YELLOW_LIGHTS"] = new SGMaterial( rwy_yellow_lights );
+ m = new SGMaterial( rwy_yellow_lights );
+ m->add_name("RWY_YELLOW_LIGHTS");
+ matlib["RWY_YELLOW_LIGHTS"] = m;
// hard coded runway medium intensity yellow light state
tex_name = gen_standard_dir_light_map( 235, 215, 20, 205 );
rwy_yellow_medium_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_yellow_medium_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_yellow_medium_lights->setTexture( tex_name );
- matlib["RWY_YELLOW_MEDIUM_LIGHTS"]
- = new SGMaterial( rwy_yellow_medium_lights );
+ m = new SGMaterial( rwy_yellow_medium_lights );
+ m->add_name("RWY_YELLOW_MEDIUM_LIGHTS");
+ matlib["RWY_YELLOW_MEDIUM_LIGHTS"] = m;
// hard coded runway low intensity yellow light state
tex_name = gen_standard_dir_light_map( 235, 215, 20, 155 );
rwy_yellow_low_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_yellow_low_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_yellow_low_lights->setTexture( tex_name );
- matlib["RWY_YELLOW_LOW_LIGHTS"]
- = new SGMaterial( rwy_yellow_low_lights );
+ m = new SGMaterial( rwy_yellow_low_lights );
+ m->add_name("RWY_YELLOW_LOW_LIGHTS");
+ matlib["RWY_YELLOW_LOW_LIGHTS"] = m;
// hard coded runway red light state
tex_name = gen_standard_dir_light_map( 235, 90, 90, 255 );
rwy_red_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_red_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_red_lights->setTexture( tex_name );
- matlib["RWY_RED_LIGHTS"]
- = new SGMaterial( rwy_red_lights );
+ m = new SGMaterial( rwy_red_lights );
+ m->add_name("RWY_RED_LIGHTS");
+ matlib["RWY_RED_LIGHTS"] = m;
// hard coded medium intensity runway red light state
tex_name = gen_standard_dir_light_map( 235, 90, 90, 205 );
rwy_red_medium_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_red_medium_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_red_medium_lights->setTexture( tex_name );
- matlib["RWY_RED_MEDIUM_LIGHTS"]
- = new SGMaterial( rwy_red_medium_lights );
+ m = new SGMaterial( rwy_red_medium_lights );
+ m->add_name("RWY_RED_MEDIUM_LIGHTS");
+ matlib["RWY_RED_MEDIUM_LIGHTS"] = m;
// hard coded low intensity runway red light state
tex_name = gen_standard_dir_light_map( 235, 90, 90, 155 );
rwy_red_low_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_red_low_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_red_low_lights->setTexture( tex_name );
- matlib["RWY_RED_LOW_LIGHTS"]
- = new SGMaterial( rwy_red_low_lights );
+ m = new SGMaterial( rwy_red_low_lights );
+ m->add_name("RWY_RED_LOW_LIGHTS");
+ matlib["RWY_RED_LOW_LIGHTS"] = m;
// hard coded runway green light state
tex_name = gen_standard_dir_light_map( 20, 235, 20, 255 );
rwy_green_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_green_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_green_lights->setTexture( tex_name );
- matlib["RWY_GREEN_LIGHTS"]
- = new SGMaterial( rwy_green_lights );
+ m = new SGMaterial( rwy_green_lights );
+ m->add_name("RWY_GREEN_LIGHTS");
+ matlib["RWY_GREEN_LIGHTS"] = m;
// hard coded medium intensity runway green light state
tex_name = gen_standard_dir_light_map( 20, 235, 20, 205 );
rwy_green_medium_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_green_medium_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_green_medium_lights->setTexture( tex_name );
- matlib["RWY_GREEN_MEDIUM_LIGHTS"]
- = new SGMaterial( rwy_green_medium_lights );
+ m = new SGMaterial( rwy_green_medium_lights );
+ m->add_name("RWY_GREEN_MEDIUM_LIGHTS");
+ matlib["RWY_GREEN_MEDIUM_LIGHTS"] = m;
// hard coded low intensity runway green light state
tex_name = gen_standard_dir_light_map( 20, 235, 20, 155 );
rwy_green_low_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
rwy_green_low_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
rwy_green_low_lights->setTexture( tex_name );
- matlib["RWY_GREEN_LOW_LIGHTS"]
- = new SGMaterial( rwy_green_low_lights );
- matlib["RWY_GREEN_TAXIWAY_LIGHTS"]
- = new SGMaterial( rwy_green_low_lights );
+ m = new SGMaterial( rwy_green_low_lights );
+ m->add_name("RWY_GREEN_LOW_LIGHTS");
+ matlib["RWY_GREEN_LOW_LIGHTS"] = m;
+ m->add_name("RWY_GREEN_TAXIWAY_LIGHTS");
+ matlib["RWY_GREEN_TAXIWAY_LIGHTS"] = m;
// hard coded low intensity taxiway blue light state
tex_name = gen_taxiway_dir_light_map( 90, 90, 235, 205 );
taxiway_blue_low_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
taxiway_blue_low_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
taxiway_blue_low_lights->setTexture( tex_name );
- matlib["RWY_BLUE_TAXIWAY_LIGHTS"]
- = new SGMaterial( taxiway_blue_low_lights );
+ m = new SGMaterial( taxiway_blue_low_lights );
+ m->add_name("RWY_BLUE_TAXIWAY_LIGHTS");
+ matlib["RWY_BLUE_TAXIWAY_LIGHTS"] = m;
// hard coded runway vasi light state
tex_name = gen_standard_dir_light_map( 235, 235, 195, 255 );
rwy_vasi_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
// rwy_vasi_lights->setTexture( gen_vasi_light_map_old() );
rwy_vasi_lights->setTexture( tex_name );
- matlib["RWY_VASI_LIGHTS"] = new SGMaterial( rwy_vasi_lights );
+ m = new SGMaterial( rwy_vasi_lights );
+ m->add_name("RWY_VASI_LIGHTS");
+ matlib["RWY_VASI_LIGHTS"] = m;
return true;
}
<< mat_name << " (" << full_path << ")");
matlib[mat_name] = new SGMaterial( full_path );
+ matlib[mat_name]->add_name(mat_name);
return true;
}
bool SGMaterialLib::add_item ( const string &mat_name, ssgSimpleState *state )
{
matlib[mat_name] = new SGMaterial( state );
+ matlib[mat_name]->add_name(mat_name);
SG_LOG( SG_TERRAIN, SG_INFO, " Loading material given a premade "
<< "ssgSimpleState = " << mat_name );
}
}
-bool SGMaterialLib::find( ssgSimpleState *state, string & material ) const
+// Return the material from that given leaf
+const SGMaterial* SGMaterialLib::findMaterial(/*const*/ssgLeaf* leaf) const
{
+ if (!leaf)
+ return 0;
+
+ ssgBase* base = leaf->getUserData();
+ if (!base)
+ return 0;
+
+ SGMaterialUserData* matUserData = dynamic_cast<SGMaterialUserData*>(base);
+ if (!matUserData)
+ return 0;
+
+ return matUserData->getMaterial();
+}
+
+bool SGMaterialLib::find( ssgSimpleState* state, string & material ) const
+{
+ // is obsolete, just kept here to avoid a race condition with
+ // SimGear/flightgear cvs checkouts ...
bool found = false;
ssgSimpleState *state_mat;
for( const_material_map_iterator iter = begin(); iter != end(); iter++ )
{
- int nb_tex = (*iter).second->get_num();
+ int nb_tex = (*iter).second->get_num();
- // many textures per material
- for( int i = 0; i < nb_tex; i++ )
- {
- // material state
- state_mat = (*iter).second->get_state( i );
+ // many textures per material
+ for( int i = 0; i < nb_tex; i++ )
+ {
+ // material state
+ state_mat = (*iter).second->get_state( i );
- if( state_mat == state )
- {
+ if( state_mat == state )
+ {
material = (*iter).first.c_str();
- found = true;
- break;
- }
- }
+ found = true;
+ break;
+ }
+ }
- if( found )
- break;
+ if( found )
+ break;
}
return found;
}
-