#include <map>
#include <simgear/math/SGMath.hxx>
+#include "Effect.hxx"
+#include <simgear/scene/tgdb/SGTexturedTriangleBin.hxx>
#include <osg/ref_ptr>
+#include <osg/Texture2D>
namespace osg
{
class StateSet;
}
+#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <simgear/props/props.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/scene/util/SGSceneFeatures.hxx>
+#include <simgear/props/condition.hxx>
#include "matmodel.hxx"
namespace simgear
{
class Effect;
+void reload_shaders();
}
class SGMaterialGlyph;
* state information for the material. This node is usually
* loaded from the $FG_ROOT/materials.xml file.
*/
- SGMaterial( const std::string &fg_root, const SGPropertyNode *props);
-
-
- /**
- * Construct a material from an absolute texture path.
- *
- * @param texture_path A string containing an absolute path
- * to a texture file (usually RGB).
- */
- SGMaterial( const std::string &texpath );
-
-
- /**
- * Construct a material around an existing state.
- *
- * This constructor allows the application to create a custom,
- * low-level state for the scene graph and wrap a material around
- * it. Note: the pointer ownership is transferred to the material.
- *
- * @param s The state for this material.
- */
- SGMaterial( osg::StateSet *s );
+ SGMaterial( const osgDB::Options*,
+ const SGPropertyNode *props,
+ SGPropertyNode *prop_root);
+ SGMaterial(const simgear::SGReaderWriterOptions*,
+ const SGPropertyNode *props,
+ SGPropertyNode *prop_root);
/**
* Destructor.
*/
/**
* Get the textured state.
*/
- osg::StateSet *get_state (int n = -1);
- simgear::Effect *get_effect(int n = -1);
+ simgear::Effect* get_effect(SGTexturedTriangleBin triangleBin);
+ simgear::Effect* get_effect();
+
+ /**
+ * Get the textured state.
+ */
+ osg::Texture2D* get_object_mask(SGTexturedTriangleBin triangleBin);
+
/**
* Get the number of textures assigned to this material.
* @return The area (m^2) covered by each light.
*/
inline double get_light_coverage () const { return light_coverage; }
+
+ /**
+ * Get the building coverage.
+ *
+ * A smaller number means more generated buildings.
+ *
+ * @return The area (m^2) covered by each light.
+ */
+ inline double get_building_coverage () const { return building_coverage; }
/**
- * Get the forest coverage.
+ * Get the building spacing.
*
- * A smaller number means more generated forest canopy.
+ * This is the minimum spacing between buildings
*
- * @return The area (m^2) covered by each canopy.
+ * @return The minimum distance between buildings
*/
- inline double get_tree_coverage () const { return tree_coverage; }
+ inline double get_building_spacing () const { return building_spacing; }
/**
- * Get the forest height.
+ * Get the building texture.
+ *
+ * This is the texture used for auto-generated buildings.
+ *
+ * @return The texture for auto-generated buildings.
+ */
+ inline std::string get_building_texture () const { return building_texture; }
+
+ // Ratio of the 3 random building sizes
+ inline double get_building_small_fraction () const { return building_small_ratio / (building_small_ratio + building_medium_ratio + building_large_ratio); }
+ inline double get_building_medium_fraction () const { return building_medium_ratio / (building_small_ratio + building_medium_ratio + building_large_ratio); }
+ inline double get_building_large_fraction () const { return building_large_ratio / (building_small_ratio + building_medium_ratio + building_large_ratio); }
+
+ // Proportion of buildings with pitched roofs
+ inline double get_building_small_pitch () const { return building_small_pitch; }
+ inline double get_building_medium_pitch () const { return building_medium_pitch; }
+ inline double get_building_large_pitch () const { return building_large_pitch; }
+
+ // Min/Max number of floors for each size
+ inline int get_building_small_min_floors () const { return building_small_min_floors; }
+ inline int get_building_small_max_floors () const { return building_small_max_floors; }
+ inline int get_building_medium_min_floors () const { return building_medium_min_floors; }
+ inline int get_building_medium_max_floors () const { return building_medium_max_floors; }
+ inline int get_building_large_min_floors () const { return building_large_min_floors; }
+ inline int get_building_large_max_floors () const { return building_large_max_floors; }
+
+ // Minimum width and depth for each size
+ inline double get_building_small_min_width () const { return building_small_min_width; }
+ inline double get_building_small_max_width () const { return building_small_max_width; }
+ inline double get_building_small_min_depth () const { return building_small_min_depth; }
+ inline double get_building_small_max_depth () const { return building_small_max_depth; }
+
+ inline double get_building_medium_min_width () const { return building_medium_min_width; }
+ inline double get_building_medium_max_width () const { return building_medium_max_width; }
+ inline double get_building_medium_min_depth () const { return building_medium_min_depth; }
+ inline double get_building_medium_max_depth () const { return building_medium_max_depth; }
+
+ inline double get_building_large_min_width () const { return building_large_min_width; }
+ inline double get_building_large_max_width () const { return building_large_max_width; }
+ inline double get_building_large_min_depth () const { return building_large_min_depth; }
+ inline double get_building_large_max_depth () const { return building_large_max_depth; }
+
+ /**
+ * Get the wood coverage.
+ *
+ * A smaller number means more generated woods within the forest.
+ *
+ * @return The area (m^2) covered by each wood.
+ */
+ inline double get_wood_coverage () const { return wood_coverage; }
+
+ /**
+ * Get the tree height.
*
* @return The average height of the trees.
*/
inline double get_tree_height () const { return tree_height; }
/**
- * Get the forest width.
+ * Get the tree width.
*
* @return The average width of the trees.
*/
* @return the texture to use for trees.
*/
inline std::string get_tree_texture () const { return tree_texture; }
-
+
/**
* Return if the surface material is solid, if it is not solid, a fluid
* can be assumed, that is usually water.
SGMatModelGroup * get_object_group (int index) const {
return object_groups[index];
}
+
+ /**
+ * Evaluate whether this material is valid given the current global
+ * property state.
+ */
+ bool valid() {
+ if (condition) {
+ return condition->test();
+ } else {
+ return true;
+ }
+ }
/**
* Return pointer to glyph class, or 0 if it doesn't exist.
protected:
struct _internal_state {
- _internal_state( osg::StateSet *s, const std::string &t, bool l );
- osg::ref_ptr<osg::StateSet> state;
+ _internal_state(simgear::Effect *e, bool l,
+ const simgear::SGReaderWriterOptions *o);
+ _internal_state(simgear::Effect *e, const std::string &t, bool l,
+ const simgear::SGReaderWriterOptions *o);
+ void add_texture(const std::string &t, int i);
osg::ref_ptr<simgear::Effect> effect;
- std::string texture_path;
- bool texture_loaded;
+ std::vector<std::pair<std::string,int> > texture_paths;
+ bool effect_realized;
+ osg::ref_ptr<const simgear::SGReaderWriterOptions> options;
};
private:
// texture status
std::vector<_internal_state> _status;
- // Round-robin counter
- mutable unsigned int _current_ptr;
-
// texture size
double xsize, ysize;
// coverage of night lighting.
double light_coverage;
- // coverage of trees
- double tree_coverage;
+ // coverage of buildings
+ double building_coverage;
+
+ // building spacing
+ double building_spacing;
+ // building texture
+ std::string building_texture;
+
+ // Ratio of the 3 random building sizes
+ double building_small_ratio;
+ double building_medium_ratio;
+ double building_large_ratio;
+
+ // Proportion of buildings with pitched roofs
+ double building_small_pitch;
+ double building_medium_pitch;
+ double building_large_pitch;
+
+ // Min/Max number of floors for each size
+ int building_small_min_floors;
+ int building_small_max_floors;
+ int building_medium_min_floors;
+ int building_medium_max_floors;
+ int building_large_min_floors;
+ int building_large_max_floors;
+
+ // Minimum width and depth for each size
+ double building_small_min_width;
+ double building_small_max_width;
+ double building_small_min_depth;
+ double building_small_max_depth;
+
+ double building_medium_min_width;
+ double building_medium_max_width;
+ double building_medium_min_depth;
+ double building_medium_max_depth;
+
+ double building_large_min_width;
+ double building_large_max_width;
+ double building_large_min_depth;
+ double building_large_max_depth;
+
+ // coverage of woods
+ double wood_coverage;
+
// Range at which trees become visible
double tree_range;
SGVec4f ambient, diffuse, specular, emission;
double shininess;
+ // effect for this material
+ std::string effect;
+
// the list of names for this material. May be empty.
std::vector<std::string> _names;
// Tree texture, typically a strip of applicable tree textures
std::string tree_texture;
-\f
+
+ // Object mask, a simple RGB texture used as a mask when placing
+ // random vegetation, objects and buildings
+ std::vector<osg::Texture2D*> _masks;
+
+ // Condition, indicating when this material is active
+ SGSharedPtr<const SGCondition> condition;
+
////////////////////////////////////////////////////////////////////
// Internal constructors and methods.
////////////////////////////////////////////////////////////////////
- SGMaterial( const std::string &fg_root, const SGMaterial &mat ); // unimplemented
-
- void read_properties( const std::string &fg_root, const SGPropertyNode *props );
- void build_state( bool defer_tex_load );
- void set_state( osg::StateSet *s );
-
- void assignTexture( osg::StateSet *state, const std::string &fname, bool _wrapu = true, bool _wrapv = true, bool _mipmap = true );
-
+ void read_properties(const simgear::SGReaderWriterOptions* options,
+ const SGPropertyNode *props,
+ SGPropertyNode *prop_root);
+ void buildEffectProperties(const simgear::SGReaderWriterOptions* options);
+ simgear::Effect* get_effect(int i);
};