Gazebo Rendering

API Reference

8.2.1
Ogre2Scene.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef GZ_RENDERING_OGRE2_OGRE2SCENE_HH_
18 #define GZ_RENDERING_OGRE2_OGRE2SCENE_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "gz/rendering/Storage.hh"
27 
28 #include "gz/rendering/ogre2/Export.hh"
29 
30 // This disables warning messages for OGRE
31 #ifndef _MSC_VER
32  #pragma GCC system_header
33 #else
34  #pragma warning(push, 0)
35 #endif
36 #include <Compositor/OgreCompositorShadowNode.h>
37 #ifdef _MSC_VER
38  #pragma warning(pop)
39 #endif
40 
41 namespace Ogre
42 {
43  class Root;
44  class SceneManager;
45 }
46 
47 namespace gz
48 {
49  namespace rendering
50  {
51  inline namespace GZ_RENDERING_VERSION_NAMESPACE {
52  //
53  // forward declaration
54  class Ogre2ScenePrivate;
55  //
57  class GZ_RENDERING_OGRE2_VISIBLE Ogre2Scene :
58  public BaseScene
59  {
63  protected: Ogre2Scene(unsigned int _id, const std::string &_name);
64 
66  public: virtual ~Ogre2Scene();
67 
68  // Documentation inherited.
69  public: virtual void Fini() override;
70 
71  // Documentation inherited.
72  public: virtual RenderEngine *Engine() const override;
73 
74  // Documentation inherited.
75  public: virtual VisualPtr RootVisual() const override;
76 
77  // Documentation inherited.
78  public: virtual void SetTime(
79  const std::chrono::steady_clock::duration &_time) override;
80 
81  // Documentation inherited.
82  public: virtual math::Color AmbientLight() const override;
83 
84  // Documentation inherited.
85  public: virtual void SetAmbientLight(const math::Color &_color) override;
86 
87  // Documentation inherited.
88  public: void SetBackgroundColor(const math::Color &_color) override;
89 
90  // Documentation inherited
91  public: virtual void PreRender() override;
92 
93  // Documentation inherited
94  public: virtual void Clear() override;
95 
96  // Documentation inherited
97  public: virtual void Destroy() override;
98 
99  // Documentation inherited
100  public: virtual void SetSkyEnabled(bool _enabled) override;
101 
102  // Documentation inherited
103  public: virtual bool SkyEnabled() const override;
104 
105  // Documentation inherited
106  public: virtual void SetActiveGlobalIllumination(
107  GlobalIlluminationBasePtr _gi) override;
108 
112  public: void SetLightsGiDirty();
113 
114  // Documentation inherited.
115  public: virtual void SetCameraPassCountPerGpuFlush(
116  uint8_t _numPass) override;
117 
118  // Documentation inherited.
119  public: virtual uint8_t CameraPassCountPerGpuFlush() const override;
120 
121  // Documentation inherited.
122  public: virtual bool LegacyAutoGpuFlush() const override;
123 
126  public: virtual Ogre::SceneManager *OgreSceneManager() const;
127 
128  // Documentation inherited
129  public: virtual void PostRender() override;
130 
143  public: void StartForcedRender();
144 
149  public: void EndForcedRender();
150 
160  public: void StartRendering(Ogre::Camera *_camera);
161 
173  public: void FlushGpuCommandsAndStartNewFrame(uint8_t _numPasses,
174  bool _startNewFrame);
175 
178  protected: void FlushGpuCommandsOnly();
179 
192  protected: void EndFrame();
193 
199  public: void SetShadowsDirty(bool _dirty);
200 
205  public: bool ShadowsDirty() const;
207 
208  // Documentation inherited
209  protected: virtual bool LoadImpl() override;
210 
211  // Documentation inherited
212  protected: virtual bool InitImpl() override;
213 
214  // Documentation inherited
215  protected: virtual COMVisualPtr CreateCOMVisualImpl(unsigned int _id,
216  const std::string &_name) override;
217 
218  // Documentation inherited
220  unsigned int _id, const std::string &_name) override;
221 
222  // Documentation inherited
223  protected: virtual JointVisualPtr CreateJointVisualImpl(unsigned int _id,
224  const std::string &_name) override;
225 
226  // Documentation inherited
227  protected: virtual LightVisualPtr CreateLightVisualImpl(unsigned int _id,
228  const std::string &_name) override;
229 
230  // Documentation inherited
232  unsigned int _id, const std::string &_name) override;
233 
234  // Documentation inherited
235  protected: virtual PointLightPtr CreatePointLightImpl(unsigned int _id,
236  const std::string &_name) override;
237 
238  // Documentation inherited
239  protected: virtual SpotLightPtr CreateSpotLightImpl(unsigned int _id,
240  const std::string &_name) override;
241 
242  // Documentation inherited
243  protected: virtual CameraPtr CreateCameraImpl(unsigned int _id,
244  const std::string &_name) override;
245 
246  // Documentation inherited
247  protected: virtual DepthCameraPtr CreateDepthCameraImpl(unsigned int _id,
248  const std::string &_name) override;
249 
250  // Documentation inherited
252  unsigned int _id, const std::string &_name) override;
253 
254  // Documentation inherited
256  unsigned int _id, const std::string &_name) override;
257 
258  // Documentation inherited
260  unsigned int _id, const std::string &_name) override;
261 
262  // Documentation inherited
264  unsigned int _id, const std::string &_name) override;
265 
266  // Documentation inherited
267  protected: virtual GpuRaysPtr CreateGpuRaysImpl(unsigned int _id,
268  const std::string &_name) override;
269 
270  // Documentation inherited
271  protected: virtual VisualPtr CreateVisualImpl(unsigned int _id,
272  const std::string &_name) override;
273 
274  // Documentation inherited
275  protected: virtual ArrowVisualPtr CreateArrowVisualImpl(unsigned int _id,
276  const std::string &_name) override;
277 
278  // Documentation inherited
279  protected: virtual AxisVisualPtr CreateAxisVisualImpl(unsigned int _id,
280  const std::string &_name) override;
281 
282  // Documentation inherited
283  protected: virtual GizmoVisualPtr CreateGizmoVisualImpl(unsigned int _id,
284  const std::string &_name) override;
285 
286  // Documentation inherited
287  protected: virtual GeometryPtr CreateBoxImpl(unsigned int _id,
288  const std::string &_name) override;
289 
290  // Documentation inherited
291  protected: virtual GeometryPtr CreateConeImpl(unsigned int _id,
292  const std::string &_name) override;
293 
294  // Documentation inherited
295  protected: virtual GeometryPtr CreateCylinderImpl(unsigned int _id,
296  const std::string &_name) override;
297 
298  // Documentation inherited
299  protected: virtual GeometryPtr CreatePlaneImpl(unsigned int _id,
300  const std::string &_name) override;
301 
302  // Documentation inherited
303  protected: virtual GeometryPtr CreateSphereImpl(unsigned int _id,
304  const std::string &_name) override;
305 
310  protected: virtual MeshPtr CreateMeshImpl(unsigned int _id,
311  const std::string &_name, const std::string &_meshName);
312 
313  // Documentation inherited
314  protected: virtual MeshPtr CreateMeshImpl(unsigned int _id,
315  const std::string &_name, const MeshDescriptor &_desc)
316  override;
317 
318  // Documentation inherited
319  protected: virtual CapsulePtr CreateCapsuleImpl(unsigned int _id,
320  const std::string &_name) override;
321 
322  protected: virtual HeightmapPtr CreateHeightmapImpl(unsigned int _id,
323  const std::string &_name, const HeightmapDescriptor &_desc)
324  override;
325 
326  // Documentation inherited
327  protected: virtual GridPtr CreateGridImpl(unsigned int _id,
328  const std::string &_name) override;
329 
330  // Documentation inherited
331  protected: virtual MarkerPtr CreateMarkerImpl(unsigned int _id,
332  const std::string &_name) override;
333 
334  // Documentation inherited
335  protected: virtual LidarVisualPtr CreateLidarVisualImpl(unsigned int _id,
336  const std::string &_name) override;
337 
338  // Documentation inherited
339  protected: virtual WireBoxPtr CreateWireBoxImpl(unsigned int _id,
340  const std::string &_name) override;
341 
342  // Documentation inherited
343  protected: virtual TextPtr CreateTextImpl(unsigned int _id,
344  const std::string &_name) override;
345 
346  protected: virtual MaterialPtr CreateMaterialImpl(unsigned int _id,
347  const std::string &_name) override;
348 
350  unsigned int _id, const std::string &_name) override;
351 
352  // Documentation inherited.
354  unsigned int _id, const std::string &_name) override;
355 
356  // Documentation inherited
357  protected: virtual RayQueryPtr CreateRayQueryImpl(
358  unsigned int _id, const std::string &_name) override;
359 
360  // Documentation inherited
362  unsigned int _id, const std::string &_name) override;
363 
364  // Documentation inherited
365  protected: virtual ProjectorPtr CreateProjectorImpl(
366  unsigned int _id, const std::string &_name) override;
367 
368  // Documentation inherited
369  protected: virtual GlobalIlluminationVctPtr
371  unsigned int _id, const std::string &_name) override;
372 
373  // Documentation inherited
374  protected: virtual GlobalIlluminationCiVctPtr
376  unsigned int _id, const std::string &_name) override;
377 
382  protected: virtual bool InitObject(Ogre2ObjectPtr _object,
383  unsigned int _id, const std::string &_name);
384 
389  public: void UpdateAllHeightmaps(Ogre::Camera *_camera);
390 
394  const;
395 
398  protected: void UpdateShadowNode();
399 
413  private: void CreateShadowNodeWithSettings(
414  Ogre::CompositorManager2 *_compositorManager,
415  const std::string &_shadowNodeName,
416  const Ogre::ShadowNodeHelper::ShadowParamVec &_shadowParams);
417 
418  // Documentation inherited
419  protected: virtual LightStorePtr Lights() const override;
420 
421  // Documentation inherited
422  protected: virtual SensorStorePtr Sensors() const override;
423 
424  // Documentation inherited
425  protected: virtual VisualStorePtr Visuals() const override;
426 
427  // Documentation inherited
428  protected: virtual MaterialMapPtr Materials() const override;
429 
430  // Documentation inherited
431  protected: unsigned int CreateObjectId() override;
432 
434  private: void CreateContext();
435 
437  private: void CreateRootVisual();
438 
440  private: void CreateMeshFactory();
441 
443  private: void CreateStores();
444 
447  public: void ClearMaterialsCache(const std::string &_name);
448 
450  private: Ogre2ScenePtr SharedThis();
451 
454 
457 
460 
463 
466 
469 
472 
474  protected: Ogre::SceneManager *ogreSceneManager = nullptr;
475 
477  private: std::unique_ptr<Ogre2ScenePrivate> dataPtr;
478 
480  private: friend class Ogre2RenderEngine;
481 
482  private: friend class Ogre2SceneExt;
483  };
484 
486  class Ogre2SceneExt : public SceneExt
487  {
490  public: Ogre2SceneExt(Scene *_scene);
491 
492  // Documentation inherited
493  public: virtual ObjectPtr CreateExt(const std::string &_type,
494  const std::string &_name = "") override;
495  };
496  }
497  }
498 }
499 #endif