Go to the documentation of this file.
18 #ifndef GAZEBO_RENDERING_SCENE_HH_
19 #define GAZEBO_RENDERING_SCENE_HH_
25 #include <boost/enable_shared_from_this.hpp>
26 #include <boost/shared_ptr.hpp>
30 #include <ignition/math/Color.hh>
31 #include <ignition/math/Vector2.hh>
32 #include <ignition/math/Vector3.hh>
36 #include "gazebo/gazebo_config.h"
102 public boost::enable_shared_from_this<Scene>
105 GZ_SKYX_ALL = 0x0FFFFFFF,
106 GZ_SKYX_CLOUDS = 0x0000001,
107 GZ_SKYX_MOON = 0x0000002,
119 public:
Scene(
const std::string &_name,
120 const bool _enableVisualizations =
false,
121 const bool _isServer =
false);
124 public:
virtual ~
Scene();
128 public:
void Load(sdf::ElementPtr _scene);
137 public:
void PreRender();
141 public: Ogre::SceneManager *OgreSceneManager()
const;
145 public: std::string Name()
const;
155 public:
void SetAmbientColor(
const ignition::math::Color &_color);
159 public: ignition::math::Color AmbientColor()
const;
169 public:
void SetBackgroundColor(
const ignition::math::Color &_color);
173 public: ignition::math::Color BackgroundColor()
const;
181 public:
void CreateGrid(
const uint32_t _cellCount,
182 const float _cellLength,
const float _lineWidth,
189 public:
void CreateGrid(
const uint32_t _cellCount,
190 const float _cellLength,
const ignition::math::Color &_color);
195 public:
Grid *GetGrid(uint32_t _index)
const;
199 public: uint32_t GridCount()
const;
206 public:
CameraPtr CreateCamera(
const std::string &_name,
207 const bool _autoRender =
true);
215 const bool _autoRender =
true);
218 public: OculusCameraPtr CreateOculusCamera(
const std::string &_name);
225 public: uint32_t OculusCameraCount()
const;
233 public:
DepthCameraPtr CreateDepthCamera(
const std::string &_name,
234 const bool _autoRender =
true);
241 public:
GpuLaserPtr CreateGpuLaser(
const std::string &_name,
242 const bool _autoRender =
true);
246 public: uint32_t CameraCount()
const;
252 public:
CameraPtr GetCamera(
const uint32_t _index)
const;
257 public:
CameraPtr GetCamera(
const std::string &_name)
const;
266 public:
UserCameraPtr CreateUserCamera(
const std::string &_name,
267 const bool _stereoEnabled =
false);
271 public: uint32_t UserCameraCount()
const;
278 public:
UserCameraPtr GetUserCamera(
const uint32_t _index)
const;
282 public:
void RemoveCamera(
const std::string &_name);
286 public: uint32_t LightCount()
const;
292 public:
LightPtr GetLight(
const std::string &_name)
const
300 public:
LightPtr GetLight(
const uint32_t _index)
const
306 public:
LightPtr LightByName(
const std::string &_name)
const;
312 public:
LightPtr LightByIndex(
const uint32_t _index)
const;
317 public:
LightPtr LightById(
const uint32_t _id)
const;
322 public:
VisualPtr GetVisual(
const std::string &_name)
const;
327 public:
VisualPtr GetVisual(
const uint32_t _id)
const;
332 public:
void SelectVisual(
const std::string &_name,
333 const std::string &_mode);
342 const ignition::math::Vector2i &_mousePos,
347 public:
void SnapVisualToNearestBelow(
const std::string &_visualName);
355 const ignition::math::Vector2i &_mousePos);
363 const ignition::math::Vector2i &_mousePos);
368 public:
VisualPtr VisualBelow(
const std::string &_visualName);
374 public:
void VisualsBelowPoint(
const ignition::math::Vector3d &_pt,
375 std::vector<VisualPtr> &_visuals);
381 public:
double HeightBelowPoint(
const ignition::math::Vector3d &_pt);
388 public:
bool FirstContact(
CameraPtr _camera,
389 const ignition::math::Vector2i &_mousePos,
390 ignition::math::Vector3d &_position);
393 public:
void PrintSceneGraph();
399 public:
void SetVisible(
const std::string &_name,
const bool _visible);
405 public:
void DrawLine(
const ignition::math::Vector3d &_start,
406 const ignition::math::Vector3d &_end,
407 const std::string &_name);
417 public:
void SetFog(
const std::string &_type,
419 const double _density,
const double _start,
429 public:
void SetFog(
const std::string &_type,
430 const ignition::math::Color &_color,
431 const double _density,
const double _start,
436 public: uint32_t Id()
const;
440 public: std::string IdString()
const;
444 public:
void SetShadowsEnabled(
const bool _value);
448 public:
bool ShadowsEnabled()
const;
454 public:
bool SetShadowTextureSize(
const unsigned int _size);
458 public:
unsigned int ShadowTextureSize()
const;
466 public:
void RemoveVisual(
VisualPtr _vis);
470 public:
void RemoveVisual(
const uint32_t _id);
477 public:
void SetVisualId(
VisualPtr _vis,
const uint32_t _id);
481 public:
void AddLight(
LightPtr _light);
485 public:
void RemoveLight(
LightPtr _light);
489 public:
void SetGrid(
const bool _enabled);
493 public:
void ShowOrigin(
const bool _show);
502 public: std::string StripSceneName(
const std::string &_name)
const;
511 public:
void SetHeightmapLOD(
const unsigned int _value);
516 public:
unsigned int HeightmapLOD()
const;
521 public:
void SetHeightmapSkirtLength(
const double _value);
526 public:
double HeightmapSkirtLength()
const;
529 public:
void Clear();
534 public:
VisualPtr SelectedVisual()
const;
538 public:
void SetWireframe(
const bool _show);
542 public:
bool Wireframe()
const;
546 public:
void SetTransparent(
const bool _show);
550 public:
void ShowCOMs(
const bool _show);
554 public:
void ShowInertias(
const bool _show);
558 public:
void ShowLinkFrames(
const bool _show);
562 public:
void ShowSkeleton(
const bool _show);
566 public:
void ShowJoints(
const bool _show);
570 public:
void ShowCollisions(
const bool _show);
574 public:
void ShowContacts(
const bool _show);
578 public:
void ShowClouds(
const bool _show);
582 public:
bool ShowClouds()
const;
588 public:
void SetSkyXMode(
const unsigned int _mode);
592 public: SkyX::SkyX *GetSkyX()
const;
596 public:
bool Initialized()
const;
607 public: uint32_t VisualCount()
const;
610 public:
void RemoveProjectors();
616 public:
void ToggleLayer(
const int32_t _layer);
623 public:
bool LayerState(
const int32_t _layer)
const;
629 public:
bool HasLayer(
const int32_t _layer)
const;
635 public:
void EnableVisualizations(
const bool _enable);
640 public:
bool EnableVisualizations()
const;
643 private:
void SetSky();
646 private:
void InitDeferredShading();
654 private: Ogre::Entity *OgreEntityAt(
CameraPtr _camera,
655 const ignition::math::Vector2i &_mousePos,
656 const bool _ignoreSelectionObj);
668 private:
void MeshInformation(
const Ogre::Mesh *_mesh,
669 size_t &_vertexCount,
670 Ogre::Vector3* &_vertices,
673 const ignition::math::Vector3d &_position,
674 const ignition::math::Quaterniond &_orient,
675 const ignition::math::Vector3d &_scale);
680 private:
void PrintSceneGraphHelper(
const std::string &_prefix,
686 private:
void OnScene(ConstScenePtr &_msg);
690 private:
void OnResponse(ConstResponsePtr &_msg);
694 private:
void OnRequest(ConstRequestPtr &_msg);
698 private:
void OnJointMsg(ConstJointPtr &_msg);
702 private:
bool ProcessSensorMsg(ConstSensorPtr &_msg);
706 private:
bool ProcessJointMsg(ConstJointPtr &_msg);
710 private:
bool ProcessLinkMsg(ConstLinkPtr &_msg);
714 private:
bool ProcessSceneMsg(ConstScenePtr &_msg);
718 private:
bool ProcessModelMsg(
const msgs::Model &_msg);
722 private:
void OnSensorMsg(ConstSensorPtr &_msg);
726 private:
void OnVisualMsg(ConstVisualPtr &_msg);
732 private:
bool ProcessVisualMsg(ConstVisualPtr &_msg,
737 private:
void OnLightFactoryMsg(ConstLightPtr &_msg);
741 private:
void OnLightModifyMsg(ConstLightPtr &_msg);
745 private:
bool ProcessLightFactoryMsg(ConstLightPtr &_msg);
749 private:
bool ProcessLightModifyMsg(ConstLightPtr &_msg);
753 private:
void ProcessRequestMsg(ConstRequestPtr &_msg);
757 private:
void OnSkyMsg(ConstSkyPtr &_msg);
761 private:
void OnModelMsg(ConstModelPtr &_msg);
765 private:
void OnPoseMsg(ConstPosesStampedPtr &_msg);
769 private:
void OnSkeletonPoseMsg(ConstPoseAnimationPtr &_msg);
773 private:
void OnRoadMsg(ConstRoadPtr &_msg);
778 private:
void CreateCOMVisual(ConstLinkPtr &_msg,
VisualPtr _linkVisual);
783 private:
void CreateCOMVisual(sdf::ElementPtr _elem,
789 private:
void CreateInertiaVisual(ConstLinkPtr &_msg,
795 private:
void CreateInertiaVisual(sdf::ElementPtr _elem,
801 private:
void CreateLinkFrameVisual(ConstLinkPtr &_msg,
807 private:
void RemoveVisualizations(
VisualPtr _vis);
811 private: std::unique_ptr<ScenePrivate> dataPtr;
bool FirstContact(CameraPtr _camera, const ignition::math::Vector2i &_mousePos, ignition::math::Vector3d &_position)
Get the world pos of a the first contact at a pixel location.
void ShowOrigin(const bool _show)
Show/hide the world origin indicator.
void SetAmbientColor(const common::Color &_color) GAZEBO_DEPRECATED(9.0)
Set the ambient color.
void SetTransparent(const bool _show)
Enable or disable transparency for all visuals.
void SetHeightmapLOD(const unsigned int _value)
Set the Level Of Detail (LOD) value for the heightmap.
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:94
bool ShowClouds() const
Get whether or not clouds are displayed.
ignition::math::Color BackgroundColor() const
Get the background color.
std::string IdString() const
Get the scene Id as a string.
Definition: JointMaker.hh:39
void Load()
Load the scene with default parameters.
LightPtr LightById(const uint32_t _id) const
Get a light by id.
double HeightBelowPoint(const ignition::math::Vector3d &_pt)
Get the Z-value of the first object below the given point.
Representation of an entire scene graph.
Definition: Scene.hh:101
Forward declarations for the common classes.
Definition: Animation.hh:26
Heightmap * GetHeightmap() const
Get a pointer to the heightmap.
Rendering a terrain using heightmap information.
Definition: Heightmap.hh:62
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:44
bool Wireframe() const
Get whether wireframe is enabled for all visuals.
boost::shared_ptr< GpuLaser > GpuLaserPtr
Definition: RenderTypes.hh:106
Entity visual.
Definition: Visual.hh:68
UserCameraPtr CreateUserCamera(const std::string &_name, const bool _stereoEnabled=false)
Create a user camera.
bool EnableVisualizations() const
Check whether visualizations are enabled or not.
common::Time SimTime() const
Get the scene simulation time.
VisualPtr VisualAt(CameraPtr _camera, const ignition::math::Vector2i &_mousePos, std::string &_mod)
Get an entity at a pixel location using a camera.
Forward declarations for transport.
void VisualsBelowPoint(const ignition::math::Vector3d &_pt, std::vector< VisualPtr > &_visuals)
Get a visual directly below a point.
void SetVisible(const std::string &_name, const bool _visible)
Hide or show a visual.
Grid * GetGrid(uint32_t _index) const
Get a grid based on an index.
uint32_t Id() const
Get the scene ID.
void CreateGrid(const uint32_t _cellCount, const float _cellLength, const float _lineWidth, const common::Color &_color) GAZEBO_DEPRECATED(9.0)
Create a square grid of cells.
uint32_t VisualCount() const
Get the number of visuals.
void ShowJoints(const bool _show)
Enable or disable joint visualization.
void SetSkyXMode(const unsigned int _mode)
Set SkyX mode to enable/disable skyx components such as clouds and moon.
unsigned int HeightmapLOD() const
Get the Level Of Detail (LOD) value for the heightmap.
DepthCameraPtr CreateDepthCamera(const std::string &_name, const bool _autoRender=true)
Create depth camera.
void PrintSceneGraph()
Print the scene graph to std_out.
void Clear()
Clear rendering::Scene.
void SetBackgroundColor(const common::Color &_color) GAZEBO_DEPRECATED(9.0)
Set the background color.
virtual ~Scene()
Destructor.
void ShowSkeleton(const bool _show)
Enable or disable skeleton visualization.
void ShowInertias(const bool _show)
Enable or disable inertia visualization.
void SetHeightmapSkirtLength(const double _value)
Set the skirt length value for the heightmap LOD tiles.
void SetGrid(const bool _enabled)
Set the grid on or off.
double HeightmapSkirtLength() const
Get the skirt length value for the heightmap LOD tiles.
uint32_t CameraCount() const
Get the number of cameras in this scene.
void RemoveProjectors()
Remove all projectors.
Displays a grid of cells, drawn with lines.
Definition: Grid.hh:58
void RemoveCamera(const std::string &_name)
Remove a camera from the scene.
VisualType
Type of visual.
Definition: Visual.hh:65
uint32_t LightCount() const
Get the count of the lights.
LightPtr LightByName(const std::string &_name) const
Get a light by name.
void ShowContacts(const bool _show)
Enable or disable contact visualization.
void SetVisualId(VisualPtr _vis, const uint32_t _id)
boost::shared_ptr< DepthCamera > DepthCameraPtr
Definition: RenderTypes.hh:98
CameraPtr GetCamera(const uint32_t _index) const
Get a camera based on an index.
void ShowCollisions(const bool _show)
Enable or disable collision visualization.
SkyX::SkyX * GetSkyX() const
Get the sky in the scene.
VisualPtr WorldVisual() const
Get the top level world visual.
void SetShadowsEnabled(const bool _value)
Set whether shadows are on or off.
bool Initialized() const
Return true if the Scene has been initialized.
GpuLaserPtr CreateGpuLaser(const std::string &_name, const bool _autoRender=true)
Create laser that generates data from rendering.
void SetFog(const std::string &_type, const common::Color &_color, const double _density, const double _start, const double _end) GAZEBO_DEPRECATED(9.0)
Set the fog parameters.
void RemoveVisual(VisualPtr _vis)
Remove a visual from the scene.
void SetWireframe(const bool _show)
Enable or disable wireframe for all visuals.
LightPtr GetLight(const std::string &_name) const GAZEBO_DEPRECATED(9.1)
Get a light by name.
UserCameraPtr GetUserCamera(const uint32_t _index) const
Get a user camera by index.
VisualPtr SelectedVisual() const
Get the currently selected visual.
bool ShadowsEnabled() const
Get whether shadows are on or off.
uint32_t UserCameraCount() const
Get the number of user cameras in this scene.
void AddLight(LightPtr _light)
Add a light to the scene.
SkyXMode
Definition: Scene.hh:104
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
bool SetShadowTextureSize(const unsigned int _size)
Set the shadow texture size.
void ToggleLayer(const int32_t _layer)
Toggle layer visilibility.
uint32_t GridCount() const
Get the number of grids.
VisualPtr ModelVisualAt(CameraPtr _camera, const ignition::math::Vector2i &_mousePos)
Get a model's visual at a mouse position.
Defines a color.
Definition: Color.hh:36
void Init()
Init rendering::Scene.
LightPtr LightByIndex(const uint32_t _index) const
Get a light based on an index.
void AddVisual(VisualPtr _vis)
Add a visual to the scene.
void RemoveLight(LightPtr _light)
Remove a light to the scene.
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
bool HasLayer(const int32_t _layer) const
Return true if the layer exits.
void ShowLinkFrames(const bool _show)
Enable or disable link frame visualization.
void SelectVisual(const std::string &_name, const std::string &_mode)
Select a visual by name.
VisualPtr GetVisual(const std::string &_name) const
Get a visual by name.
boost::shared_ptr< Light > LightPtr
Definition: RenderTypes.hh:86
Ogre::SceneManager * OgreSceneManager() const
Get the OGRE scene manager.
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
std::string Name() const
Get the name of the scene.
unsigned int ShadowTextureSize() const
Get the shadow texture size.
bool LayerState(const int32_t _layer) const
Return whether a layer is on or off.
VisualPtr VisualBelow(const std::string &_visualName)
Get the closest visual below a given visual.
boost::shared_ptr< Camera > CameraPtr
Definition: RenderTypes.hh:90
boost::shared_ptr< WideAngleCamera > WideAngleCameraPtr
Definition: RenderTypes.hh:102
void PreRender()
Process all received messages.
void DrawLine(const ignition::math::Vector3d &_start, const ignition::math::Vector3d &_end, const std::string &_name)
Draw a named line.
WideAngleCameraPtr CreateWideAngleCamera(const std::string &_name, const bool _autoRender=true)
Create a wide-angle camera.
void SnapVisualToNearestBelow(const std::string &_visualName)
Move the visual to be ontop of the nearest visual below it.
ignition::math::Color AmbientColor() const
Get the ambient color.
std::string StripSceneName(const std::string &_name) const
Remove the name of scene from a string.
void ShowCOMs(const bool _show)
Enable or disable center of mass visualization.
CameraPtr CreateCamera(const std::string &_name, const bool _autoRender=true)
Create a camera.