]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/mat.hxx
My old email address is no longer valid ... point to my web page.
[simgear.git] / simgear / scene / material / mat.hxx
index 82772890c8e2cb7d2006c5cfc193bf10b6364011..a32bde3220cd450a9b1bbe22b9d2d31fcad3d1d3 100644 (file)
@@ -1,10 +1,10 @@
-// newmat.hxx -- a material in the scene graph.
+// mat.hxx -- a material in the scene graph.
 // TODO: this class needs to be renamed.
 //
 // Written by Curtis Olson, started May 1998.
 // Overhauled by David Megginson, December 2001
 //
-// Copyright (C) 1998 - 2000  Curtis L. Olson  - curt@flightgear.org
+// Copyright (C) 1998 - 2000  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
@@ -23,8 +23,8 @@
 // $Id$
 
 
-#ifndef _NEWMAT_HXX
-#define _NEWMAT_HXX
+#ifndef _SG_MAT_HXX
+#define _SG_MAT_HXX
 
 #ifndef __cplusplus                                                          
 # error This library requires C++
 #include <simgear/compiler.h>
 
 #include STL_STRING      // Standard C++ string library
+#include <vector>
 
 #include <plib/sg.h>
 #include <plib/ssg.h>
 
 #include <simgear/props/props.hxx>
-#include <simgear/scene/model/loader.hxx>
+
+#include "matmodel.hxx"
 
 SG_USING_STD(string);
+SG_USING_STD(vector);
 
 
 /**
@@ -52,173 +55,10 @@ SG_USING_STD(string);
  * defined in the $FG_ROOT/materials.xml file, and can be changed
  * at runtime.
  */
-class FGNewMat {
+class SGMaterial {
 
 public:
 
-\f
-  //////////////////////////////////////////////////////////////////////
-  // Inner classes.
-  //////////////////////////////////////////////////////////////////////
-
-  class ObjectGroup;
-
-  /**
-   * A randomly-placeable object.
-   *
-   * FGNewMat uses this class to keep track of the model(s) and
-   * parameters for a single instance of a randomly-placeable object.
-   * The object can have more than one variant model (i.e. slightly
-   * different shapes of trees), but they are considered equivalent
-   * and interchangeable.
-   */
-  class Object
-  {
-  public:
-
-    /**
-     * The heading type for a randomly-placed object.
-     */
-    enum HeadingType {
-      HEADING_FIXED,
-      HEADING_BILLBOARD,
-      HEADING_RANDOM
-    };
-
-
-    /**
-     * Get the number of variant models available for the object.
-     *
-     * @return The number of variant models.
-     */
-    int get_model_count( FGModelLoader *loader,
-                         const string &fg_root,
-                         SGPropertyNode *prop_root,
-                         double sim_time_sec );
-
-
-    /**
-     * Get a specific variant model for the object.
-     *
-     * @param index The index of the model.
-     * @return The model.
-     */
-    ssgEntity *get_model( int index,
-                          FGModelLoader *loader,
-                          const string &fg_root,
-                          SGPropertyNode *prop_root,
-                          double sim_time_sec );
-
-
-    /**
-     * Get a randomly-selected variant model for the object.
-     *
-     * @return A randomly select model from the variants.
-     */
-    ssgEntity *get_random_model( FGModelLoader *loader,
-                                 const string &fg_root,
-                                 SGPropertyNode *prop_root,
-                                 double sim_time_sec );
-
-
-    /**
-     * Get the average number of meters^2 occupied by each instance.
-     *
-     * @return The coverage in meters^2.
-     */
-    double get_coverage_m2 () const;
-
-
-    /**
-     * Get the heading type for the object.
-     *
-     * @return The heading type.
-     */
-    HeadingType get_heading_type () const;
-
-  protected:
-
-    friend class ObjectGroup;
-
-    Object (const SGPropertyNode * node, double range_m);
-
-    virtual ~Object ();
-
-  private:
-
-    /**
-     * Actually load the models.
-     *
-     * This class uses lazy loading so that models won't be held
-     * in memory for materials that are never referenced.
-     */
-    void load_models( FGModelLoader *loader,
-                      const string &fg_root,
-                      SGPropertyNode *prop_root,
-                      double sim_time_sec );
-
-    vector<string> _paths;
-    mutable vector<ssgEntity *> _models;
-    mutable bool _models_loaded;
-    double _coverage_m2;
-    double _range_m;
-    HeadingType _heading_type;
-  };
-
-
-  /**
-   * A collection of related objects with the same visual range.
-   *
-   * Grouping objects with the same range together significantly
-   * reduces the memory requirements of randomly-placed objects.
-   * Each FGNewMat instance keeps a (possibly-empty) list of
-   * object groups for placing randomly on the scenery.
-   */
-  class ObjectGroup
-  {
-  public:
-    virtual ~ObjectGroup ();
-
-
-    /**
-     * Get the visual range of the object in meters.
-     *
-     * @return The visual range.
-     */
-    double get_range_m () const;
-
-
-    /**
-     * Get the number of objects in the group.
-     *
-     * @return The number of objects.
-     */
-    int get_object_count () const;
-
-
-    /**
-     * Get a specific object.
-     *
-     * @param index The object's index, zero-based.
-     * @return The object selected.
-     */
-    Object * get_object (int index) const;
-
-  protected:
-
-    friend class FGNewMat;
-
-    ObjectGroup (SGPropertyNode * node);
-
-  private:
-
-    double _range_m;
-    vector<Object *> _objects;
-
-  };
-
-
-
 \f
   ////////////////////////////////////////////////////////////////////
   // Public Constructors.
@@ -231,8 +71,7 @@ public:
    * state information for the material.  This node is usually
    * loaded from the $FG_ROOT/materials.xml file.
    */
-  FGNewMat( const string &fg_root, const SGPropertyNode *props,
-            bool smooth_shading, bool use_textures );
+  SGMaterial( const string &fg_root, const SGPropertyNode *props );
 
 
   /**
@@ -241,7 +80,7 @@ public:
    * @param texture_path A string containing an absolute path
    * to a texture file (usually RGB).
    */
-  FGNewMat( const string &texpath, bool smooth_shading, bool use_textures );
+  SGMaterial( const string &texpath );
 
 
   /**
@@ -253,12 +92,12 @@ public:
    *
    * @param s The SSG state for this material.
    */
-  FGNewMat( ssgSimpleState *s, bool smooth_shading, bool use_textures );
+  SGMaterial( ssgSimpleState *s );
 
   /**
    * Destructor.
    */
-  virtual ~FGNewMat( void );
+  virtual ~SGMaterial( void );
 
 
 \f
@@ -272,13 +111,19 @@ public:
    * @return true if the texture loaded, false if it was loaded
    * already.
    */
-  virtual bool load_texture ();
+  virtual bool load_texture (int n = -1);
 
 
   /**
    * Get the textured state.
    */
-  virtual inline ssgSimpleState *get_textured () { return textured; }
+  virtual 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(); }
 
 
   /**
@@ -312,17 +157,11 @@ public:
   /**
    * Get a randomly-placed object for this material.
    */
-  virtual ObjectGroup * get_object_group (int index) const {
+  virtual SGMatModelGroup * get_object_group (int index) const {
     return object_groups[index];
   }
 
 
-  /**
-   * Get the current state.
-   */
-  virtual inline ssgStateSelector *get_state () const { return state; }
-
-
   /**
    * Increment the reference count for this material.
    *
@@ -357,6 +196,15 @@ protected:
    */
   virtual void init();
 
+protected:
+
+  struct _internal_state {
+     _internal_state( ssgSimpleState *s, const string &t, bool l )
+                  : state(s), texture_path(t), texture_loaded(l) {}
+      ssgSimpleState *state;
+      string texture_path;
+      bool texture_loaded;
+  };
 
 private:
 
@@ -365,13 +213,11 @@ private:
   // Internal state.
   ////////////////////////////////////////////////////////////////////
 
-  // names
-  string texture_path;
+  // texture status
+  vector<_internal_state> _status;
 
-  // pointers to ssg states
-  ssgStateSelector *state;
-  ssgSimpleState *textured;
-  ssgSimpleState *nontextured;
+  // Round-robin counter
+  unsigned int _current_ptr;
 
   // texture size
   double xsize, ysize;
@@ -389,10 +235,7 @@ private:
   sgVec4 ambient, diffuse, specular, emission;
   double shininess;
 
-  // true if texture loading deferred, and not yet loaded
-  bool texture_loaded;
-
-  vector<ObjectGroup *> object_groups;
+  vector<SGMatModelGroup *> object_groups;
 
   // ref count so we can properly delete if we have multiple
   // pointers to this record
@@ -404,16 +247,13 @@ private:
   // Internal constructors and methods.
   ////////////////////////////////////////////////////////////////////
 
-  FGNewMat( const string &fg_root, const FGNewMat &mat ); // unimplemented
+  SGMaterial( const string &fg_root, const SGMaterial &mat ); // unimplemented
 
   void read_properties( const string &fg_root, const SGPropertyNode *props );
-  void build_ssg_state( bool defer_tex_load,
-                        bool smooth_shading,
-                        bool use_textures );
-  void set_ssg_state( ssgSimpleState *s,
-                      bool smooth_shading, bool use_textures );
+  void build_ssg_state( bool defer_tex_load );
+  void set_ssg_state( ssgSimpleState *s );
 
 
 };
 
-#endif // _NEWMAT_HXX 
+#endif // _SG_MAT_HXX