00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _SG_MAT_HXX
00027 #define _SG_MAT_HXX
00028
00029 #ifndef __cplusplus
00030 # error This library requires C++
00031 #endif
00032
00033 #include <simgear/compiler.h>
00034
00035 #include <string>
00036 #include <vector>
00037 #include <map>
00038
00039 #include <simgear/math/SGMath.hxx>
00040
00041 #include <osg/ref_ptr>
00042 #include <osgDB/ReaderWriter>
00043
00044 namespace osg
00045 {
00046 class StateSet;
00047 }
00048
00049 #include <simgear/props/props.hxx>
00050 #include <simgear/structure/SGSharedPtr.hxx>
00051 #include <simgear/scene/util/SGSceneFeatures.hxx>
00052
00053 #include "matmodel.hxx"
00054
00055 namespace simgear
00056 {
00057 class Effect;
00058 void reload_shaders();
00059 }
00060
00061 class SGMaterialGlyph;
00062
00072 class SGMaterial : public SGReferenced {
00073
00074 public:
00075
00076
00078
00080
00088 SGMaterial( const osgDB::ReaderWriter::Options*, const SGPropertyNode *props);
00089
00093 ~SGMaterial( void );
00094
00095
00096
00098
00100
00104 simgear::Effect *get_effect(int n = -1);
00105
00109 inline int get_num() const { return _status.size(); }
00110
00111
00115 inline double get_xsize() const { return xsize; }
00116
00117
00121 inline double get_ysize() const { return ysize; }
00122
00123
00131 inline double get_light_coverage () const { return light_coverage; }
00132
00140 inline double get_wood_coverage () const { return wood_coverage; }
00141
00147 inline double get_tree_density () const { return tree_density; }
00148
00154 inline double get_wood_size () const { return wood_size; }
00155
00161 inline double get_tree_height () const { return tree_height; }
00162
00168 inline double get_tree_width () const { return tree_width; }
00169
00175 inline double get_tree_range () const { return tree_range; }
00176
00182 inline int get_tree_varieties () const { return tree_varieties; }
00183
00189 inline std::string get_tree_texture () const { return tree_texture; }
00190
00195 bool get_solid () const { return solid; }
00196
00200 double get_friction_factor () const { return friction_factor; }
00201
00205 double get_rolling_friction () const { return rolling_friction; }
00206
00210 double get_bumpiness () const { return bumpiness; }
00211
00215 double get_load_resistance () const { return load_resistance; }
00216
00220 const std::vector<std::string>& get_names() const { return _names; }
00221
00225 void add_name(const std::string& name) { _names.push_back(name); }
00226
00230 int get_object_group_count () const { return object_groups.size(); }
00231
00235 SGMatModelGroup * get_object_group (int index) const {
00236 return object_groups[index];
00237 }
00238
00242 SGMaterialGlyph * get_glyph (const std::string& name) const;
00243
00244 void set_light_color(const SGVec4f& color)
00245 { emission = color; }
00246 const SGVec4f& get_light_color() const
00247 { return emission; }
00248
00249 SGVec2f get_tex_coord_scale() const
00250 {
00251 float tex_width = get_xsize();
00252 float tex_height = get_ysize();
00253
00254 return SGVec2f((0 < tex_width) ? 1000.0f/tex_width : 1.0f,
00255 (0 < tex_height) ? 1000.0f/tex_height : 1.0f);
00256 }
00257
00258 protected:
00259
00260
00262
00264
00268 void init();
00269
00270 protected:
00271
00272 struct _internal_state {
00273 _internal_state(simgear::Effect *e, const std::string &t, bool l,
00274 const osgDB::ReaderWriter::Options *o);
00275 osg::ref_ptr<simgear::Effect> effect;
00276 std::string texture_path;
00277 bool effect_realized;
00278 osg::ref_ptr<const osgDB::ReaderWriter::Options> options;
00279 };
00280
00281 private:
00282
00283
00285
00287
00288
00289 std::vector<_internal_state> _status;
00290
00291
00292 mutable unsigned int _current_ptr;
00293
00294
00295 double xsize, ysize;
00296
00297
00298 bool wrapu, wrapv;
00299
00300
00301 bool mipmap;
00302
00303
00304 double light_coverage;
00305
00306
00307 double wood_coverage;
00308
00309
00310 double wood_size;
00311
00312
00313 double tree_density;
00314
00315
00316 double tree_range;
00317
00318
00319 double tree_height;
00320
00321
00322 double tree_width;
00323
00324
00325 int tree_varieties;
00326
00327
00328 bool solid;
00329
00330
00331 double friction_factor;
00332
00333
00334 double rolling_friction;
00335
00336
00337 double bumpiness;
00338
00339
00340 double load_resistance;
00341
00342
00343 SGVec4f ambient, diffuse, specular, emission;
00344 double shininess;
00345
00346
00347 std::string effect;
00348
00349
00350 std::vector<std::string> _names;
00351
00352 std::vector<SGSharedPtr<SGMatModelGroup> > object_groups;
00353
00354
00355 std::map<std::string, SGSharedPtr<SGMaterialGlyph> > glyphs;
00356
00357
00358 std::string tree_texture;
00359
00361
00363
00364 void read_properties(const osgDB::ReaderWriter::Options* options,
00365 const SGPropertyNode *props);
00366 void buildEffectProperties(const osgDB::ReaderWriter::Options* options);
00367 };
00368
00369
00370 class SGMaterialGlyph : public SGReferenced {
00371 public:
00372 SGMaterialGlyph(SGPropertyNode *);
00373 inline double get_left() const { return _left; }
00374 inline double get_right() const { return _right; }
00375 inline double get_width() const { return _right - _left; }
00376
00377 protected:
00378 double _left;
00379 double _right;
00380 };
00381
00382 class SGMaterialUserData : public osg::Referenced {
00383 public:
00384 SGMaterialUserData(const SGMaterial* material) :
00385 mMaterial(material)
00386 {}
00387 const SGMaterial* getMaterial() const
00388 { return mMaterial; }
00389 private:
00390
00391
00392 const SGMaterial* mMaterial;
00393 };
00394
00395 void
00396 SGSetTextureFilter( int max);
00397
00398 int
00399 SGGetTextureFilter();
00400
00401 #endif // _SG_MAT_HXX