TDME2  1.9.200
Scene.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <memory>
5 #include <set>
6 #include <string>
7 #include <unordered_map>
8 #include <unordered_set>
9 #include <vector>
10 
11 #include <tdme/tdme.h>
20 #include <tdme/math/fwd-tdme.h>
21 #include <tdme/math/Vector3.h>
23 
24 using std::make_unique;
25 using std::map;
26 using std::set;
27 using std::string;
28 using std::unique_ptr;
29 using std::unordered_map;
30 using std::unordered_set;
31 using std::vector;
32 
43 
44 /**
45  * Scene definition
46  * @author Andreas Drewke
47  */
49  : public BaseProperties
50 {
51 private:
53  string fileName;
55  vector<unique_ptr<SceneLight>> lights;
56  unique_ptr<SceneLibrary> library;
57  map<string, SceneEntity*> entitiesById;
58  vector<unique_ptr<SceneEntity>> entities;
59  set<string> environmentMappingIds;
60  int entityIdx;
65  unordered_set<string> enabledPostProcessingShaders;
66  unordered_map<string, EntityShaderParameters> postProcessingShaderParameters;
67  string guiFileName;
68 
69  /**
70  * Computes scene bounding box
71  * @return dimension
72  */
73  void computeBoundingBox();
74 
75  /**
76  * @return scene center
77  */
78  void computeCenter();
79 
80 public:
81  /**
82  * Public constructor
83  * @param name name
84  * @param description description
85  */
86  Scene(const string& name, const string& description);
87 
88  /**
89  * Destructor
90  */
91  virtual ~Scene();
92 
93  /**
94  * @return application root path name
95  */
96  inline const string& getApplicationRootPathName() {
98  }
99 
100  /**
101  * Set application root path name
102  * @param applicationRootPathName application root path name
103  */
105  this->applicationRootPathName = applicationRootPathName;
106  }
107 
108  /**
109  * @return scene file name including relative path
110  */
111  inline const string& getFileName() {
112  return fileName;
113  }
114 
115  /**
116  * Set up scene file name including relative path
117  * @param fileName scene file name including relative path
118  */
119  inline void setFileName(const string& fileName) {
120  this->fileName = fileName;
121  }
122 
123  /**
124  * @return rotation order
125  */
127  return rotationOrder;
128  }
129 
130  /**
131  * Set rotation order
132  * @param rotationOrder rotation order
133  */
135  this->rotationOrder = rotationOrder;
136  }
137 
138  /**
139  * @return Lights iterator
140  */
142  return UniquePtrSequenceIterator<SceneLight>(&(*lights.begin()), &(*lights.end()));
143  }
144 
145  /**
146  * @return number of lights
147  */
148  inline int getLightCount() {
149  return lights.size();
150  }
151 
152  /**
153  * Get light at given index
154  * @param i index
155  * @return light
156  */
157  inline SceneLight* getLightAt(int i) {
158  if (i < 0 || i >= lights.size()) return nullptr;
159  return lights[i].get();
160  }
161 
162  /**
163  * Add light
164  * @return light
165  */
166  inline SceneLight* addLight() {
167  lights.push_back(make_unique<SceneLight>(static_cast<int>(lights.size())));
168  return lights[lights.size() - 1].get();
169  }
170 
171  /**
172  * Remove light at given index i
173  * @param i index
174  * @return success
175  */
176  bool removeLightAt(int i) {
177  if (i < 0 || i >= lights.size()) return false;
178  lights.erase(lights.begin() + i);
179  return true;
180  }
181 
182  /**
183  * @return scene prototype library
184  */
186  return library.get();
187  }
188 
189  /**
190  * @return dimension
191  */
192  inline const Vector3& getDimension() {
193  return dimension;
194  }
195 
196  /**
197  * @return scene bounding box
198  */
200  return &boundingBox;
201  }
202 
203  /**
204  * @return scene center
205  */
206  inline const Vector3& getCenter() {
207  return center;
208  }
209 
210  /**
211  * @return new entity id
212  */
213  inline int allocateEntityId() {
214  return entityIdx++;
215  }
216 
217  /**
218  * @return entity idx
219  */
220  inline int getEntityIdx() {
221  return entityIdx;
222  }
223 
224  /**
225  * Set entity idx
226  * @param entityIdx objectIdx
227  */
228  inline void setEntityIdx(int entityIdx) {
229  this->entityIdx = entityIdx;
230  }
231 
232  /**
233  * Clears all scene entities
234  */
235  void clearEntities();
236 
237  /**
238  * Get entities with given prototype id
239  * @param prototypeId prototype id
240  * @param entitiesByPrototypeId entities by prototype id
241  */
242  void getEntitiesByPrototypeId(int prototypeId, vector<string>& entitiesByPrototypeId);
243 
244  /**
245  * Remove entities with given prototype id
246  * @param prototypeId prototype id
247  */
248  void removeEntitiesByPrototypeId(int prototypeId);
249 
250  /**
251  * Replace prototype of given search prototype with new prototype
252  * @param searchPrototypeId search prototype id
253  * @param newPrototypeId new prototype id
254  */
255  void replacePrototypeByIds(int searchPrototypeId, int newPrototypeId);
256 
257  /**
258  * @return environment mapping object ids
259  */
260  inline set<string> getEnvironmentMappingIds() {
261  return environmentMappingIds;
262  }
263 
264  /**
265  * @return Entities iterator
266  */
268  return UniquePtrSequenceIterator<SceneEntity>(&(*entities.begin()), &(*entities.end()));
269  }
270 
271  /**
272  * @return number of entities
273  */
274  inline int getEntityCount() {
275  return entities.size();
276  }
277 
278  /**
279  * Returns entity at given index
280  * @param idx index
281  * @return scene entity
282  */
283  inline SceneEntity* getEntityAt(int idx) {
284  if (idx < 0 || idx >= entities.size()) return nullptr;
285  return entities[idx].get();
286  }
287 
288  /**
289  * Returns scene entity by id
290  * @param id id
291  * @return scene entity
292  */
293  SceneEntity* getEntity(const string& id);
294 
295  /**
296  * Adds an entity to scene
297  * @param object object
298  */
299  void addEntity(SceneEntity* entity);
300 
301  /**
302  * Removes an entity from scene
303  * @param id id
304  * @return success
305  */
306  bool removeEntity(const string& id);
307 
308  /**
309  * Rename an entity from scene
310  * @param id id
311  * @param newId new id
312  * @return success
313  */
314  bool renameEntity(const string& id, const string& newId);
315 
316  /**
317  * Get sky shader parameters
318  * @return shader parameters
319  */
321  return skyShaderParameters;
322  }
323 
324  /**
325  * Set sky shader parameters
326  * @param parameters shader parameters
327  */
329  skyShaderParameters = parameters;
330  }
331 
332  /**
333  * Return enabled processing shader
334  * @return enabled post processing shader
335  */
336  inline unordered_set<string> getEnabledPostProcessingShader() {
338  }
339 
340  /**
341  * Is post processing shader enabled
342  * @param shaderId shader id
343  * @return processing shader enabled
344  */
345  inline bool isPostProcessingShaderEnabled(const string& shaderId) {
346  return enabledPostProcessingShaders.contains(shaderId);
347  }
348 
349  /**
350  * Enable post processing shader
351  * @param shaderId shader id
352  */
353  inline void enablePostProcessingShader(const string& shaderId) {
354  enabledPostProcessingShaders.insert(shaderId);
355  }
356 
357  /**
358  * Disable post processing shader
359  * @param shaderId shader id
360  */
361  inline void disablePostProcessingShader(const string& shaderId) {
362  enabledPostProcessingShaders.erase(shaderId);
363  }
364 
365  /**
366  * Get post processing shader parameters
367  * @param shaderId shader id
368  * @return shader parameters
369  */
370  inline const EntityShaderParameters* getPostProcessingShaderParameters(const string& shaderId) {
371  auto postProcessingShaderParametersIt = postProcessingShaderParameters.find(shaderId);
372  if (postProcessingShaderParametersIt == postProcessingShaderParameters.end()) return nullptr;
373  return &postProcessingShaderParametersIt->second;
374  }
375 
376  /**
377  * Set post processing shader parameters
378  * @param parameters shader parameters
379  */
380  inline void setPostProcessingShaderParameters(const string& shaderId, const EntityShaderParameters& parameters) {
381  postProcessingShaderParameters[shaderId] = parameters;
382  }
383 
384  /**
385  * @return Scene GUI file name including relative path
386  */
387  inline const string& getGUIFileName() {
388  return guiFileName;
389  }
390 
391  /**
392  * Set up scene GUI file name including relative path
393  * @param fileName scene GUI file name including relative path
394  */
395  inline void setGUIFileName(const string& fileName) {
396  this->guiFileName = fileName;
397  }
398 
399  /**
400  * Update scene dimension, bounding box, center
401  */
402  void update();
403 
404 };
TDME2 engine entity shader parameters.
Representation of a 3D model.
Definition: Model.h:35
Represents rotation orders of a model.
Definition: RotationOrder.h:23
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
Scene entity definition.
Definition: SceneEntity.h:23
Scene prototype library definition.
Definition: SceneLibrary.h:32
Scene light definition.
Definition: SceneLight.h:20
Scene definition.
Definition: Scene.h:50
map< string, SceneEntity * > entitiesById
Definition: Scene.h:57
bool removeEntity(const string &id)
Removes an entity from scene.
Definition: Scene.cpp:218
const Vector3 & getDimension()
Definition: Scene.h:192
void setFileName(const string &fileName)
Set up scene file name including relative path.
Definition: Scene.h:119
void replacePrototypeByIds(int searchPrototypeId, int newPrototypeId)
Replace prototype of given search prototype with new prototype.
Definition: Scene.cpp:189
virtual ~Scene()
Destructor.
Definition: Scene.cpp:69
RotationOrder * getRotationOrder()
Definition: Scene.h:126
const string & getFileName()
Definition: Scene.h:111
void removeEntitiesByPrototypeId(int prototypeId)
Remove entities with given prototype id.
Definition: Scene.cpp:180
EntityShaderParameters skyShaderParameters
Definition: Scene.h:64
bool isPostProcessingShaderEnabled(const string &shaderId)
Is post processing shader enabled.
Definition: Scene.h:345
vector< unique_ptr< SceneLight > > lights
Definition: Scene.h:55
UniquePtrSequenceIterator< SceneLight > getLights()
Definition: Scene.h:141
const EntityShaderParameters & getSkyShaderParameters()
Get sky shader parameters.
Definition: Scene.h:320
BoundingBox * getBoundingBox()
Definition: Scene.h:199
void setRotationOrder(RotationOrder *rotationOrder)
Set rotation order.
Definition: Scene.h:134
void setGUIFileName(const string &fileName)
Set up scene GUI file name including relative path.
Definition: Scene.h:395
void getEntitiesByPrototypeId(int prototypeId, vector< string > &entitiesByPrototypeId)
Get entities with given prototype id.
Definition: Scene.cpp:172
UniquePtrSequenceIterator< SceneEntity > getEntities()
Definition: Scene.h:267
RotationOrder * rotationOrder
Definition: Scene.h:54
set< string > getEnvironmentMappingIds()
Definition: Scene.h:260
SceneLight * addLight()
Add light.
Definition: Scene.h:166
const string & getApplicationRootPathName()
Definition: Scene.h:96
unique_ptr< SceneLibrary > library
Definition: Scene.h:56
void setEntityIdx(int entityIdx)
Set entity idx.
Definition: Scene.h:228
unordered_map< string, EntityShaderParameters > postProcessingShaderParameters
Definition: Scene.h:66
void setApplicationRootPathName(const string &applicationRootPathName)
Set application root path name.
Definition: Scene.h:104
bool renameEntity(const string &id, const string &newId)
Rename an entity from scene.
Definition: Scene.cpp:237
unordered_set< string > enabledPostProcessingShaders
Definition: Scene.h:65
SceneLight * getLightAt(int i)
Get light at given index.
Definition: Scene.h:157
bool removeLightAt(int i)
Remove light at given index i.
Definition: Scene.h:176
const string & getGUIFileName()
Definition: Scene.h:387
Scene(const string &name, const string &description)
Public constructor.
Definition: Scene.cpp:54
SceneEntity * getEntity(const string &id)
Returns scene entity by id.
Definition: Scene.cpp:254
void setPostProcessingShaderParameters(const string &shaderId, const EntityShaderParameters &parameters)
Set post processing shader parameters.
Definition: Scene.h:380
void enablePostProcessingShader(const string &shaderId)
Enable post processing shader.
Definition: Scene.h:353
void addEntity(SceneEntity *entity)
Adds an entity to scene.
Definition: Scene.cpp:202
set< string > environmentMappingIds
Definition: Scene.h:59
string applicationRootPathName
Definition: Scene.h:52
SceneLibrary * getLibrary()
Definition: Scene.h:185
void update()
Update scene dimension, bounding box, center.
Definition: Scene.cpp:263
void setSkyShaderParameters(EntityShaderParameters &parameters)
Set sky shader parameters.
Definition: Scene.h:328
vector< unique_ptr< SceneEntity > > entities
Definition: Scene.h:58
void clearEntities()
Clears all scene entities.
Definition: Scene.cpp:164
BoundingBox boundingBox
Definition: Scene.h:61
SceneEntity * getEntityAt(int idx)
Returns entity at given index.
Definition: Scene.h:283
void disablePostProcessingShader(const string &shaderId)
Disable post processing shader.
Definition: Scene.h:361
const Vector3 & getCenter()
Definition: Scene.h:206
unordered_set< string > getEnabledPostProcessingShader()
Return enabled processing shader.
Definition: Scene.h:336
const EntityShaderParameters * getPostProcessingShaderParameters(const string &shaderId)
Get post processing shader parameters.
Definition: Scene.h:370
void computeBoundingBox()
Computes scene bounding box.
Definition: Scene.cpp:72
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20