vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ModelManager.h
Go to the documentation of this file.
1 #ifndef _MODELMANAGER
2 #define _MODELMANAGER 1
3 
4 #include <vector>
5 #include <map>
6 
7 #include <osg/Notify>
8 #include <osg/Node>
9 #include <osg/Geode>
10 #include <osg/Group>
11 #include <osg/ShadeModel>
12 #include <osg/CullFace>
13 #include <osg/StateSet>
14 
15 #include <osgDB/Registry>
16 #include <osgDB/ReadFile>
17 #include <osgUtil/Optimizer>
18 
19 #include <osgCal/CoreModel>
20 #include <osgCal/Model>
21 
22 
23 using namespace vrecko;
24 using namespace ArtificialWorld;
25 
28 public:
29  GeometryState(){geometry = NULL; count = 0;};
32  osg::ref_ptr<EnvironmentObject> GetGeometry(){return geometry.get();};
34  void RemoveGeometry(){geometry = NULL;};
36  int Count(){return count;};
38  void AddReference(){count++;};
40  void RemoveReference()
41  {
42  count--;
43  if(count < 0)
44  count = 0;
45  };
46 private:
48  osg::ref_ptr<EnvironmentObject> geometry;
50  int count;
51 };
52 
55 public:
56  AnimatedGeometryState(){ coreModel = NULL; count = 0;};
57  AnimatedGeometryState(osgCal::CoreModel *cm){ coreModel = cm; count = 1;};
59  osg::ref_ptr<osgCal::CoreModel> GetAnimatedGeometry(){ return coreModel.get();};
61  void RemoveGeometry(){ coreModel = NULL;};
63  int Count(){ return count;};
65  void AddReference(){ count++;};
67  void RemoveReference()
68  {
69  count--;
70  if(count < 0)
71  count = 0;
72  };
73 private:
75  osg::ref_ptr<osgCal::CoreModel> coreModel;
77  int count;
78 };
79 
82 public:
86  virtual void DeleteUpdate(osg::ref_ptr<EnvironmentObject> deletingObject, int num, ModelType modelType) = 0;
87 };
88 
91 public:
95  virtual void GetUpdate(string modelFilename, int num, ModelType modelType) = 0;
96 };
97 
100 public:
104  virtual void AddUpdate(string modelFilename, ModelType modelType) = 0;
105 };
106 
111 private:
112  //zajemci o udalosti mazani, ziskani a pridani
113  static vector<DeleteObserver*> delObservers;
114  static vector<GetObserver*> getObservers;
115  static vector<AddObserver*> addObservers;
116 
117 public:
119  static osg::ref_ptr<EnvironmentObject> GetModelGeometry(string modelFilename);
121  static void DeleteModelGeometry(osg::ref_ptr<EnvironmentObject> *ptr);
122 
124  static bool ContainsModelGeometry(string modelFilename);
126  static bool ContainsAnimatedModelGeometry(string modelFilename);
128  static bool ContainsModelGeometry(string modelFilename, ModelType modelType);
129 
131  static osg::ref_ptr<EnvironmentObject> GetAnimatedModelGeometry(string modelFilename, int animationIndex, bool startAnimation);
133  static void DeleteAnimatedModelGeometry(osg::ref_ptr<EnvironmentObject> *ptr);
135  static void DeleteModelGeometry(osg::ref_ptr<EnvironmentObject> *ptr, ModelType modelType);
136 
138  static void AddModelGeometry(string modelFilename, osg::ref_ptr<EnvironmentObject> newGeometry);
139 
141  static void AddDeleteObserver(DeleteObserver* newObserver);
143  static void AddGetObserver(GetObserver* newObserver);
145  static void AddAddObserver(AddObserver *newObserver);
147  static void RemoveDeleteObserver(DeleteObserver* observer);
149  static void RemoveGetObserver(GetObserver* observer);
151  static void RemoveAddObserver(AddObserver *observer);
152 
153 private:
154 
156  static map<string, GeometryState> geoms;
158  static map<string, AnimatedGeometryState> animGeoms;
159 
161  static void DeleteNotify(osg::ref_ptr<EnvironmentObject> deletingObject, int remaining_count, ModelType modelType);
162  static void GetNotify(string modelFilename, int existing_count, ModelType modelType);
163  static void AddNotify(string modelFilename, ModelType modelType);
164 
165  // Pomocna funkce pro nacitani animovane geometrie. Je tu jen pro to, aby sla zachytavat vyjimka.
166  // V GetAnimatedModelGeometry() to neslo kvuli chybe C2712
167  // (Cannot use __try in functions that require object unwinding)
168  static bool SubLoadAnimatedGeometry(osgCal::CoreModel &coreModel, std::string &modelFilename, osgCal::MeshParameters &meshParameters);
169 };
170 
171 #endif
172