Klamp't  0.8.1
ManagedGeometry.h
1 #ifndef MODELING_MANAGED_GEOMETRY_H
2 #define MODELING_MANAGED_GEOMETRY_H
3 
4 #include <KrisLibrary/geometry/AnyGeometry.h>
5 #include <KrisLibrary/GLdraw/GeometryAppearance.h>
6 #include <memory>
7 #include <map>
8 #include <string>
9 
10 class GeometryManager;
11 
38 {
39  public:
40  typedef std::shared_ptr<Geometry::AnyCollisionGeometry3D> GeometryPtr;
41  typedef std::shared_ptr<GLDraw::GeometryAppearance> AppearancePtr;
42 
45  ManagedGeometry(const ManagedGeometry& rhs);
46  ~ManagedGeometry();
48  void Clear();
50  bool Empty() const;
52  GeometryPtr CreateEmpty();
54  bool Load(const std::string& filename);
56  bool LoadNoCache(const std::string& filename);
59  static ManagedGeometry* IsCached(const std::string& filename);
61  bool IsCached() const;
63  void AddToCache(const std::string& filename);
65  const std::string& CachedFilename() const;
67  void RemoveFromCache();
70  void TransformGeometry(const Math3D::Matrix4& xform);
72  AppearancePtr Appearance() const;
75  bool IsAppearanceShared() const;
78  void SetUnique();
81  void SetUniqueAppearance();
83  void OnGeometryChange();
85  void DrawGL();
87  bool IsDynamicGeometry() const;
90  bool DynamicGeometryUpdate();
91 
93  const ManagedGeometry& operator = (const ManagedGeometry& rhs);
94  operator bool() const { return geometry != NULL; }
95  bool operator !() const { return geometry == NULL; }
97  operator GeometryPtr() { return geometry; }
98  operator GeometryPtr() const { return geometry; }
99  GeometryPtr operator ->() { return geometry; }
100  const GeometryPtr operator ->() const { return geometry; }
101  inline Geometry::AnyCollisionGeometry3D& operator *() { return *geometry; }
102  inline const Geometry::AnyCollisionGeometry3D& operator *() const { return *geometry; }
103 
104  friend class GeometryManager;
105  static GeometryManager manager;
106 
107  private:
108  std::string cacheKey,dynamicGeometrySource;
109  GeometryPtr geometry;
110  AppearancePtr appearance;
111 };
112 
114 {
115 public:
116  GeometryManager();
117  ~GeometryManager();
118  void Clear();
119 
120  friend class ManagedGeometry;
122  {
123  std::vector<ManagedGeometry*> geoms;
124  };
125  std::map<std::string,GeometryList> cache;
126 };
127 
128 #endif
const ManagedGeometry & operator=(const ManagedGeometry &rhs)
assignment is a shallow copy
void TransformGeometry(const Math3D::Matrix4 &xform)
const std::string & CachedFilename() const
Returns the filename to which this object is cached.
bool LoadNoCache(const std::string &filename)
Loads a geometry, without caching.
bool Empty() const
Returns true if the pointer is NULL or the geometry itself is empty.
void DrawGL()
Renders the object using OpenGL.
bool DynamicGeometryUpdate()
void AddToCache(const std::string &filename)
Adds to cache, if not already in it.
void OnGeometryChange()
If the geometry is changed, call this to update the appearance.
void Clear()
Erases the items in this geometry.
bool Load(const std::string &filename)
Loads a geometry, with caching.
void SetUniqueAppearance()
bool IsCached() const
Returns true if this instance is cached.
Definition: ManagedGeometry.h:113
GeometryPtr CreateEmpty()
Creates an empty geometry.
void RemoveFromCache()
Remove self from cache, if in it.
A "smart" geometry loading class that caches previous geometries, and does not re-load or re-initiali...
Definition: ManagedGeometry.h:37
bool IsAppearanceShared() const
AppearancePtr Appearance() const
Returns the shared appearance data.
Definition: ManagedGeometry.h:121
bool IsDynamicGeometry() const
Returns true if this geometry is connected to a dynamic source.