]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/mat.hxx
Fix removal of directories.
[simgear.git] / simgear / scene / material / mat.hxx
index ae246ad57e943ed0ca7b5e41890d22c3a93ab448..ee094fa61d2c85d2748e1e99916b259cf8ed08b1 100644 (file)
 #ifndef _SG_MAT_HXX
 #define _SG_MAT_HXX
 
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
 #include <simgear/compiler.h>
 
 #include <string>      // Standard C++ string library
 #include <vector>
 #include <map>
 
-#include <simgear/math/SGMath.hxx>
+#include "Effect.hxx"
 
 #include <osg/ref_ptr>
+#include <osg/Texture2D>
 
 namespace osg
 {
 class StateSet;
 }
 
-namespace osgDB
-{
-class Options;
-}
-
-#include <simgear/props/props.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
-#include <simgear/scene/util/SGSceneFeatures.hxx>
+#include <simgear/threads/SGThread.hxx> // for SGMutex
+#include <simgear/math/SGLimits.hxx>
+#include <simgear/math/SGMisc.hxx>
+#include <simgear/math/SGMath.hxx>
+#include <simgear/math/SGVec2.hxx>
+#include <simgear/math/SGRect.hxx>
+#include <simgear/bvh/BVHMaterial.hxx>
 
-#include "matmodel.hxx"
+typedef osg::ref_ptr<osg::Texture2D> Texture2DRef;
+typedef std::vector<SGRect <float> > AreaList;
 
 namespace simgear
 {
 class Effect;
+void reload_shaders();
+class SGReaderWriterOptions;
 }
 
+class SGMatModelGroup;
+class SGCondition;
+class SGPropertyNode;
 class SGMaterialGlyph;
+class SGTexturedTriangleBin;
 
 /**
  * A material in the scene graph.
@@ -72,7 +76,7 @@ class SGMaterialGlyph;
  * defined in the $FG_ROOT/materials.xml file, and can be changed
  * at runtime.
  */
-class SGMaterial : public SGReferenced {
+class SGMaterial : public simgear::BVHMaterial {
 
 public:
 
@@ -88,7 +92,18 @@ public:
    * state information for the material.  This node is usually
    * loaded from the $FG_ROOT/materials.xml file.
    */
-  SGMaterial( const osgDB::Options*, const SGPropertyNode *props);
+  SGMaterial(const osgDB::Options*,
+             const SGPropertyNode *props,
+             SGPropertyNode *prop_root,
+             AreaList *a,
+                        SGSharedPtr<const SGCondition> c);
+
+
+  SGMaterial(const simgear::SGReaderWriterOptions*,
+             const SGPropertyNode *props,
+             SGPropertyNode *prop_root,
+             AreaList *a,
+                        SGSharedPtr<const SGCondition> c);
 
   /**
    * Destructor.
@@ -104,7 +119,14 @@ public:
   /**
    * Get the textured state.
    */
-  simgear::Effect *get_effect(int n = -1);
+  simgear::Effect* get_one_effect(int texIndex);
+  simgear::Effect* get_effect();
+
+  /**
+   * Get the textured state.
+   */
+  osg::Texture2D* get_one_object_mask(int texIndex);
+
 
   /**
    * Get the number of textures assigned to this material.
@@ -132,25 +154,100 @@ public:
    * @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; }
+
+  /**
+   * Get the building lightmap.
+   *
+   * This is the lightmap used for auto-generated buildings.
+   *
+   * @return The lightmap for auto-generated buildings.
+   */
+  inline std::string get_building_lightmap () const { return building_lightmap; }
+  
+  // 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; }
+  
+  inline double get_building_range () const { return building_range; }
+  
+  inline double get_cos_object_max_density_slope_angle () const { return cos_object_max_density_slope_angle; }
+  inline double get_cos_object_zero_density_slope_angle () const { return cos_object_zero_density_slope_angle; }
+
+  /**
+   * 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.
    */
@@ -177,32 +274,32 @@ public:
    */
   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.
-   */
-  bool get_solid () const { return solid; }
-
-  /**
-   * Get the friction factor for that material
-   */
-  double get_friction_factor () const { return friction_factor; }
 
   /**
-   * Get the rolling friction for that material
+   * Get the effect file name to use for trees
+   *
+   * @return the effect to use for this set of trees.
    */
-  double get_rolling_friction () const { return rolling_friction; }
-
+  inline std::string get_tree_effect () const { return  tree_effect; }
+  
   /**
-   * Get the bumpines for that material
+   * Get the cosine of the maximum tree density slope angle. We
+   * use the cosine as it can be compared directly to the z component
+   * of a triangle normal.
+   * 
+   * @return the cosine of the maximum tree density slope angle.
    */
-  double get_bumpiness () const { return bumpiness; }
-
+  inline double get_cos_tree_max_density_slope_angle () const { return cos_tree_max_density_slope_angle; }
+  
   /**
-   * Get the load resistance
+   * Get the cosine of the maximum tree density slope angle. We
+   * use the cosine as it can be compared directly to the z component
+   * of a triangle normal.
+   * 
+   * @return the cosine of the maximum tree density slope angle.
    */
-  double get_load_resistance () const { return load_resistance; }
-
+  inline double get_cos_tree_zero_density_slope_angle () const { return cos_tree_zero_density_slope_angle; }
+  
   /**
    * Get the list of names for this material
    */
@@ -224,6 +321,12 @@ public:
   SGMatModelGroup * get_object_group (int index) const {
     return object_groups[index];
   }
+  
+  /**
+   * Evaluate whether this material is valid given the current global
+   * property state and the tile location.
+   */
+     bool valid(SGVec2f loc) const;
 
   /**
    * Return pointer to glyph class, or 0 if it doesn't exist.
@@ -243,7 +346,7 @@ public:
     return SGVec2f((0 < tex_width) ? 1000.0f/tex_width : 1.0f,
                    (0 < tex_height) ? 1000.0f/tex_height : 1.0f);
   }
-
+  
 protected:
 
 \f
@@ -259,12 +362,15 @@ protected:
 protected:
 
   struct _internal_state {
+      _internal_state(simgear::Effect *e, bool l,
+                      const simgear::SGReaderWriterOptions *o);
       _internal_state(simgear::Effect *e, const std::string &t, bool l,
-                      const osgDB::Options *o);
+                      const simgear::SGReaderWriterOptions *o);
+      void add_texture(const std::string &t, int i);
       osg::ref_ptr<simgear::Effect> effect;
-      std::string texture_path;
+      std::vector<std::pair<std::string,int> > texture_paths;
       bool effect_realized;
-      osg::ref_ptr<const osgDB::Options> options;
+      osg::ref_ptr<const simgear::SGReaderWriterOptions> options;
   };
 
 private:
@@ -277,9 +383,6 @@ private:
   // texture status
   std::vector<_internal_state> _status;
 
-  // Round-robin counter
-  mutable unsigned int _current_ptr;
-
   // texture size
   double xsize, ysize;
 
@@ -292,9 +395,61 @@ private:
   // 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 & lightmap
+  std::string building_texture;
+  std::string building_lightmap;
+
+  // 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;
+  
+  double building_range;
+  
+  // Cosine of the angle of maximum and zero density, 
+  // used to stop buildings and random objects from being 
+  // created on too steep a slope.
+  double cos_object_max_density_slope_angle;
+  double cos_object_zero_density_slope_angle;
+  
+  // coverage of woods
+  double wood_coverage;
+
   // Range at which trees become visible
   double tree_range;
 
@@ -306,21 +461,11 @@ private:
 
   // Number of varieties of tree texture
   int tree_varieties;
-
-  // 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 resistance of that surface material
-  double load_resistance;
+  
+  // cosine of the tile angle of maximum and zero density,
+  // used to stop trees from being created on too steep a slope.
+  double cos_tree_max_density_slope_angle;
+  double cos_tree_zero_density_slope_angle;
 
   // material properties
   SGVec4f ambient, diffuse, specular, emission;
@@ -339,14 +484,35 @@ private:
   
   // Tree texture, typically a strip of applicable tree textures
   std::string tree_texture;
-\f
+
+  // Tree effect to be used for a particular material
+  std::string tree_effect;
+  
+  // Object mask, a simple RGB texture used as a mask when placing
+  // random vegetation, objects and buildings
+  std::vector<Texture2DRef> _masks;
+  
+  // Condition, indicating when this material is active
+  SGSharedPtr<const SGCondition> condition;
+  
+  // List of geographical rectangles for this material
+  AreaList* areas;
+
+  // Parameters from the materials file
+  const SGPropertyNode* parameters;
+
+  // per-material lock for entrypoints called from multiple threads
+  SGMutex _lock;
+
   ////////////////////////////////////////////////////////////////////
   // Internal constructors and methods.
   ////////////////////////////////////////////////////////////////////
 
-  void read_properties(const osgDB::Options* options,
-                        const SGPropertyNode *props);
-  void buildEffectProperties(const osgDB::Options* options);
+  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);
 };