Gazebo Rendering

API Reference

7.4.2
gz/rendering/ogre2/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: virtual void PreRender() override;
89 
90  // Documentation inherited
91  public: virtual void Clear() override;
92 
93  // Documentation inherited
94  public: virtual void Destroy() override;
95 
96  // Documentation inherited
97  public: virtual void SetSkyEnabled(bool _enabled) override;
98 
99  // Documentation inherited
100  public: virtual bool SkyEnabled() const override;
101 
102  // Documentation inherited.
103  public: virtual void SetCameraPassCountPerGpuFlush(
104  uint8_t _numPass) override;
105 
106  // Documentation inherited.
107  public: virtual uint8_t CameraPassCountPerGpuFlush() const override;
108 
109  // Documentation inherited.
110  public: virtual bool LegacyAutoGpuFlush() const override;
111 
114  public: virtual Ogre::SceneManager *OgreSceneManager() const;
115 
116  // Documentation inherited
117  public: virtual void PostRender() override;
118 
131  public: void StartForcedRender();
132 
137  public: void EndForcedRender();
138 
148  public: void StartRendering(Ogre::Camera *_camera);
149 
161  public: void FlushGpuCommandsAndStartNewFrame(uint8_t _numPasses,
162  bool _startNewFrame);
163 
166  protected: void FlushGpuCommandsOnly();
167 
180  protected: void EndFrame();
181 
187  public: void SetShadowsDirty(bool _dirty);
188 
193  public: bool ShadowsDirty() const;
195 
196  // Documentation inherited
197  protected: virtual bool LoadImpl() override;
198 
199  // Documentation inherited
200  protected: virtual bool InitImpl() override;
201 
202  // Documentation inherited
203  protected: virtual COMVisualPtr CreateCOMVisualImpl(unsigned int _id,
204  const std::string &_name) override;
205 
206  // Documentation inherited
207  protected: virtual InertiaVisualPtr CreateInertiaVisualImpl(
208  unsigned int _id, const std::string &_name) override;
209 
210  // Documentation inherited
211  protected: virtual JointVisualPtr CreateJointVisualImpl(unsigned int _id,
212  const std::string &_name) override;
213 
214  // Documentation inherited
215  protected: virtual LightVisualPtr CreateLightVisualImpl(unsigned int _id,
216  const std::string &_name) override;
217 
218  // Documentation inherited
219  protected: virtual DirectionalLightPtr CreateDirectionalLightImpl(
220  unsigned int _id, const std::string &_name) override;
221 
222  // Documentation inherited
223  protected: virtual PointLightPtr CreatePointLightImpl(unsigned int _id,
224  const std::string &_name) override;
225 
226  // Documentation inherited
227  protected: virtual SpotLightPtr CreateSpotLightImpl(unsigned int _id,
228  const std::string &_name) override;
229 
230  // Documentation inherited
231  protected: virtual CameraPtr CreateCameraImpl(unsigned int _id,
232  const std::string &_name) override;
233 
234  // Documentation inherited
235  protected: virtual DepthCameraPtr CreateDepthCameraImpl(unsigned int _id,
236  const std::string &_name) override;
237 
238  // Documentation inherited
239  protected: virtual ThermalCameraPtr CreateThermalCameraImpl(
240  unsigned int _id, const std::string &_name) override;
241 
242  // Documentation inherited
243  protected: virtual BoundingBoxCameraPtr CreateBoundingBoxCameraImpl(
244  unsigned int _id, const std::string &_name) override;
245 
246  // Documentation inherited
247  protected: virtual SegmentationCameraPtr CreateSegmentationCameraImpl(
248  unsigned int _id, const std::string &_name) override;
249 
250  // Documentation inherited
251  protected: virtual GpuRaysPtr CreateGpuRaysImpl(unsigned int _id,
252  const std::string &_name) override;
253 
254  // Documentation inherited
255  protected: virtual VisualPtr CreateVisualImpl(unsigned int _id,
256  const std::string &_name) override;
257 
258  // Documentation inherited
259  protected: virtual ArrowVisualPtr CreateArrowVisualImpl(unsigned int _id,
260  const std::string &_name) override;
261 
262  // Documentation inherited
263  protected: virtual AxisVisualPtr CreateAxisVisualImpl(unsigned int _id,
264  const std::string &_name) override;
265 
266  // Documentation inherited
267  protected: virtual GizmoVisualPtr CreateGizmoVisualImpl(unsigned int _id,
268  const std::string &_name) override;
269 
270  // Documentation inherited
271  protected: virtual GeometryPtr CreateBoxImpl(unsigned int _id,
272  const std::string &_name) override;
273 
274  // Documentation inherited
275  protected: virtual GeometryPtr CreateConeImpl(unsigned int _id,
276  const std::string &_name) override;
277 
278  // Documentation inherited
279  protected: virtual GeometryPtr CreateCylinderImpl(unsigned int _id,
280  const std::string &_name) override;
281 
282  // Documentation inherited
283  protected: virtual GeometryPtr CreatePlaneImpl(unsigned int _id,
284  const std::string &_name) override;
285 
286  // Documentation inherited
287  protected: virtual GeometryPtr CreateSphereImpl(unsigned int _id,
288  const std::string &_name) override;
289 
294  protected: virtual MeshPtr CreateMeshImpl(unsigned int _id,
295  const std::string &_name, const std::string &_meshName);
296 
297  // Documentation inherited
298  protected: virtual MeshPtr CreateMeshImpl(unsigned int _id,
299  const std::string &_name, const MeshDescriptor &_desc)
300  override;
301 
302  // Documentation inherited
303  protected: virtual CapsulePtr CreateCapsuleImpl(unsigned int _id,
304  const std::string &_name) override;
305 
306  protected: virtual HeightmapPtr CreateHeightmapImpl(unsigned int _id,
307  const std::string &_name, const HeightmapDescriptor &_desc)
308  override;
309 
310  // Documentation inherited
311  protected: virtual GridPtr CreateGridImpl(unsigned int _id,
312  const std::string &_name) override;
313 
314  // Documentation inherited
315  protected: virtual MarkerPtr CreateMarkerImpl(unsigned int _id,
316  const std::string &_name) override;
317 
318  // Documentation inherited
319  protected: virtual LidarVisualPtr CreateLidarVisualImpl(unsigned int _id,
320  const std::string &_name) override;
321 
322  // Documentation inherited
323  protected: virtual WireBoxPtr CreateWireBoxImpl(unsigned int _id,
324  const std::string &_name) override;
325 
326  // Documentation inherited
327  protected: virtual TextPtr CreateTextImpl(unsigned int _id,
328  const std::string &_name) override;
329 
330  protected: virtual MaterialPtr CreateMaterialImpl(unsigned int _id,
331  const std::string &_name) override;
332 
333  protected: virtual RenderTexturePtr CreateRenderTextureImpl(
334  unsigned int _id, const std::string &_name) override;
335 
336  // Documentation inherited.
337  protected: virtual RenderWindowPtr CreateRenderWindowImpl(
338  unsigned int _id, const std::string &_name) override;
339 
340  // Documentation inherited
341  protected: virtual RayQueryPtr CreateRayQueryImpl(
342  unsigned int _id, const std::string &_name) override;
343 
344  // Documentation inherited
345  protected: virtual ParticleEmitterPtr CreateParticleEmitterImpl(
346  unsigned int _id, const std::string &_name) override;
347 
348  // Documentation inherited
349  // \todo(iche033) make this virtual in gz-rendering8
350  protected: ProjectorPtr CreateProjectorImpl(
351  unsigned int _id, const std::string &_name);
352 
357  protected: virtual bool InitObject(Ogre2ObjectPtr _object,
358  unsigned int _id, const std::string &_name);
359 
364  public: void UpdateAllHeightmaps(Ogre::Camera *_camera);
365 
368  public: const std::vector<std::weak_ptr<Ogre2Heightmap>> &Heightmaps()
369  const;
370 
373  protected: void UpdateShadowNode();
374 
388  private: void CreateShadowNodeWithSettings(
389  Ogre::CompositorManager2 *_compositorManager,
390  const std::string &_shadowNodeName,
391  const Ogre::ShadowNodeHelper::ShadowParamVec &_shadowParams);
392 
393  // Documentation inherited
394  protected: virtual LightStorePtr Lights() const override;
395 
396  // Documentation inherited
397  protected: virtual SensorStorePtr Sensors() const override;
398 
399  // Documentation inherited
400  protected: virtual VisualStorePtr Visuals() const override;
401 
402  // Documentation inherited
403  protected: virtual MaterialMapPtr Materials() const override;
404 
405  // Documentation inherited
406  protected: unsigned int CreateObjectId() override;
407 
409  private: void CreateContext();
410 
412  private: void CreateRootVisual();
413 
415  private: void CreateMeshFactory();
416 
418  private: void CreateStores();
419 
422  public: void ClearMaterialsCache(const std::string &_name);
423 
425  private: Ogre2ScenePtr SharedThis();
426 
429 
432 
435 
438 
441 
444 
447 
449  protected: Ogre::SceneManager *ogreSceneManager = nullptr;
450 
452  private: std::unique_ptr<Ogre2ScenePrivate> dataPtr;
453 
455  private: friend class Ogre2RenderEngine;
456 
457  private: friend class Ogre2SceneExt;
458  };
459 
461  class Ogre2SceneExt : public SceneExt
462  {
465  public: Ogre2SceneExt(Scene *_scene);
466 
467  // Documentation inherited
468  public: virtual ObjectPtr CreateExt(const std::string &_type,
469  const std::string &_name = "") override;
470  };
471 
472  }
473  }
474 }
475 #endif