Go to the documentation of this file.
17 #ifndef GAZEBO_RENDERING_VISUAL_HH_
18 #define GAZEBO_RENDERING_VISUAL_HH_
20 #include <boost/enable_shared_from_this.hpp>
21 #include <boost/function.hpp>
27 #include <ignition/math/AxisAlignedBox.hh>
28 #include <ignition/math/Color.hh>
29 #include <ignition/math/Pose3.hh>
30 #include <ignition/math/Quaternion.hh>
31 #include <ignition/math/Vector3.hh>
32 #include <ignition/msgs/MessageTypes.hh>
37 #include "gazebo/msgs/MessageTypes.hh"
60 public std::enable_shared_from_this<Visual>
90 bool _useRTShader =
true);
98 bool _useRTShader =
true);
101 public:
virtual ~
Visual();
107 public:
virtual void Fini();
117 public:
void LoadFromMsg(ConstVisualPtr &_msg);
121 public:
void Load(sdf::ElementPtr _sdf);
124 public:
virtual void Load();
127 public:
void Update();
135 public: sdf::ElementPtr GetSDF()
const;
139 public:
void SetName(
const std::string &_name);
143 public: std::string Name()
const;
147 public:
void AttachVisual(
VisualPtr _vis);
151 public:
void DetachVisual(
VisualPtr _vis);
155 public:
void DetachVisual(
const std::string &_name);
159 public:
void AttachObject(Ogre::MovableObject *_obj);
163 public:
bool HasAttachedObject(
const std::string &_name);
167 public:
unsigned int GetAttachedObjectCount()
const;
170 public:
void DetachObjects();
174 public:
unsigned int GetChildCount();
180 public:
VisualPtr GetChild(
unsigned int _index);
189 public: Ogre::MovableObject *AttachMesh(
const std::string &_meshName,
190 const std::string &_subMesh=
"",
191 bool _centerSubmesh =
false,
192 const std::string &_objName=
"");
196 public:
void SetScale(
const ignition::math::Vector3d &_scale);
200 public: ignition::math::Vector3d Scale()
const;
204 public: ignition::math::Vector3d DerivedScale()
const;
208 public:
bool GetLighting()
const;
212 public:
void SetLighting(
bool _lighting);
220 public:
void SetMaterial(
const std::string &_materialName,
221 bool _unique =
true,
const bool _cascade =
true);
232 public:
void SetMaterialShaderParam(
const std::string &_paramName,
233 const std::string &_shaderType,
const std::string &_value);
238 public:
void SetAmbient(
const ignition::math::Color &_color,
239 const bool _cascade =
true);
244 public:
void SetDiffuse(
const ignition::math::Color &_color,
245 const bool _cascade =
true);
250 public:
void SetSpecular(
const ignition::math::Color &_color,
251 const bool _cascade =
true);
256 public:
virtual void SetEmissive(
const ignition::math::Color &_color,
257 const bool _cascade =
true);
261 public: ignition::math::Color Ambient()
const;
265 public: ignition::math::Color Diffuse()
const;
269 public: ignition::math::Color Specular()
const;
273 public: ignition::math::Color Emissive()
const;
277 public:
void SetWireframe(
bool _show);
281 public:
bool Wireframe()
const;
286 private:
void SetTransparencyInnerLoop(Ogre::SceneNode *_sceneNode);
291 public:
void SetTransparency(
float _trans);
295 public:
float GetTransparency();
300 public:
float DerivedTransparency()
const;
304 public:
void SetInheritTransparency(
const bool _inherit);
308 public:
bool InheritTransparency()
const;
313 public:
virtual void SetHighlighted(
bool _highlighted);
318 public:
bool GetHighlighted()
const;
322 public:
bool GetCastShadows()
const;
326 public:
void SetCastShadows(
bool _shadows);
331 public:
virtual void SetVisible(
bool _visible,
bool _cascade =
true);
334 public:
void ToggleVisible();
338 public:
bool GetVisible()
const;
342 public:
void SetPosition(
const ignition::math::Vector3d &_pos);
346 public:
void SetRotation(
const ignition::math::Quaterniond &_rot);
350 public:
void SetPose(
const ignition::math::Pose3d &_pose);
354 public: ignition::math::Vector3d Position()
const;
358 public: ignition::math::Quaterniond Rotation()
const;
362 public: ignition::math::Pose3d Pose()
const;
366 public: ignition::math::Pose3d InitialRelativePose()
const;
370 public: ignition::math::Pose3d WorldPose()
const;
374 public:
void SetWorldPose(
const ignition::math::Pose3d &_pose);
378 public:
void SetWorldPosition(
const ignition::math::Vector3d &_pos);
382 public:
void SetWorldRotation(
const ignition::math::Quaterniond &_rot);
386 public: Ogre::SceneNode *GetSceneNode()
const;
389 public:
void MakeStatic();
393 public:
bool IsStatic()
const;
397 public:
void EnableTrackVisual(
VisualPtr _vis);
400 public:
void DisableTrackVisual();
404 public: std::string GetNormalMap()
const;
408 public:
void SetNormalMap(
const std::string &_nmap);
414 public:
void SetRibbonTrail(
bool _value,
415 const ignition::math::Color &_initialColor,
416 const ignition::math::Color &_changeColor);
420 public: ignition::math::AxisAlignedBox BoundingBox()
const;
436 unsigned int _index);
440 public: std::string GetMaterialName()
const;
446 public:
void InsertMesh(
const std::string &_meshName,
447 const std::string &_subMesh =
"",
448 bool _centerSubmesh =
false);
454 public:
static void InsertMesh(
const common::Mesh *_mesh,
455 const std::string &_subMesh =
"",
456 bool _centerSubmesh =
false);
460 public:
void UpdateFromMsg(ConstVisualPtr &_msg);
464 public:
bool IsPlane()
const;
481 public:
VisualPtr GetNthAncestor(
unsigned int _n);
496 public:
unsigned int GetDepth()
const;
501 public: std::string GetShaderType()
const;
506 public:
void SetShaderType(
const std::string &_type);
511 public:
void MoveToPosition(
const ignition::math::Pose3d &_pose,
518 public:
void MoveToPositions(
519 const std::vector<ignition::math::Pose3d> &_pts,
const double _time,
520 std::function<
void()> _onComplete =
nullptr);
527 public:
void SetVisibilityFlags(uint32_t _flags);
534 public: uint32_t GetVisibilityFlags();
537 public:
void ShowBoundingBox();
542 public:
void ShowCollision(
bool _show);
546 public:
void ShowSkeleton(
bool _show);
550 public:
void SetScene(
ScenePtr _scene);
558 public:
void ShowJoints(
bool _show);
562 public:
void ShowCOM(
bool _show);
566 public:
void ShowInertia(
bool _show);
570 public:
void ShowLinkFrame(
bool _show);
574 public:
void SetSkeletonPose(
const msgs::PoseAnimation &_pose);
580 public:
void LoadPlugin(
const std::string &_filename,
581 const std::string &_name,
582 sdf::ElementPtr _sdf);
586 public:
void RemovePlugin(
const std::string &_name);
589 public: uint32_t GetId()
const;
592 public:
void SetId(uint32_t _id);
596 public: std::string GetGeometryType()
const;
600 public: ignition::math::Vector3d GetGeometrySize()
const;
604 public: std::string GetMeshName()
const;
609 public: std::string GetSubMeshName()
const;
612 public:
void ClearParent();
617 public:
void ToggleLayer(
const int32_t _layer);
621 public:
void SetLayer(
const int32_t _layer);
633 public:
bool UseRTShader()
const;
638 public:
void SetTypeMsg(
const google::protobuf::Message *_msg);
644 public:
void AddPendingChild(std::pair<VisualType,
645 const google::protobuf::Message *> _pair);
651 const msgs::Visual::Type &_type);
656 public:
static msgs::Visual::Type ConvertVisualType(
662 public:
void FillMaterialMsg(ignition::msgs::Material &_msg)
const;
671 protected:
Visual(VisualPrivate &_dataPtr,
672 const std::string &_name,
VisualPtr _parent,
673 bool _useRTShader =
true);
682 protected:
Visual(VisualPrivate &_dataPtr,
683 const std::string &_name,
ScenePtr _scene,
684 bool _useRTShader =
true);
690 protected:
void ProcessMaterialMsg(
const msgs::Material &_msg);
698 protected:
void ProcessMaterialMsg(
const ignition::msgs::Material &_msg);
706 private:
void Init(
const std::string &_name,
ScenePtr _scene,
715 private:
void Init(
const std::string &_name,
VisualPtr _parent,
720 private:
void LoadPlugins();
722 private:
void LoadPlugin(sdf::ElementPtr _sdf);
727 private:
void BoundsHelper(Ogre::SceneNode *_node,
728 ignition::math::AxisAlignedBox &_box)
const;
733 private:
bool GetCenterSubMesh()
const;
737 private:
void DestroyAllAttachedMovableObjects(
738 Ogre::SceneNode *_sceneNode);
743 private:
void UpdateGeomSize(
const ignition::math::Vector3d &_scale);
747 private:
void UpdateTransparency(
const bool _cascade =
true);
void SetWorldRotation(const ignition::math::Quaterniond &_rot)
Set the world orientation of the visual.
static Visual::VisualType ConvertVisualType(const msgs::Visual::Type &_type)
Convert from msgs::Visual::Type to VisualType.
ScenePtr GetScene() const
Get current.
void RemovePlugin(const std::string &_name)
Remove a running plugin.
@ VT_MODEL
Model visual.
Definition: Visual.hh:69
@ VT_SENSOR
Sensor visual.
Definition: Visual.hh:77
ignition::math::Vector3d GetGeometrySize() const
Get the geometry size.
Definition: JointMaker.hh:39
unsigned int GetAttachedObjectCount() const
Return the number of attached movable objects.
virtual void Load()
Load the visual with default parameters.
Visual(const std::string &_name, VisualPtr _parent, bool _useRTShader=true)
Constructor.
virtual void SetVisible(bool _visible, bool _cascade=true)
Set whether the visual is visible.
Ogre::SceneNode * GetSceneNode() const
Return the scene Node of this visual entity.
void SetType(const Visual::VisualType _type)
Set type of visual.
void SetAmbient(const ignition::math::Color &_color, const bool _cascade=true)
Set the ambient color of the visual.
virtual ~Visual()
Destructor.
void SetRotation(const ignition::math::Quaterniond &_rot)
Set the rotation of the visual.
Forward declarations for the common classes.
Definition: Animation.hh:26
void ShowBoundingBox()
Display the bounding box visual.
void SetScene(ScenePtr _scene)
Set current scene.
void SetMaterialShaderParam(const std::string &_paramName, const std::string &_shaderType, const std::string &_value)
Set a shader program parameter associated to this visual's material.
void SetNormalMap(const std::string &_nmap)
Set the normal map.
void DetachObjects()
Detach all objects.
@ VT_COLLISION
Collision visual.
Definition: Visual.hh:75
void FillMaterialMsg(ignition::msgs::Material &_msg) const
Fill an ignition::msgs::Material message based on this visual's material properties.
ignition::math::Pose3d WorldPose() const
Get the global pose of the visual.
void SetPosition(const ignition::math::Vector3d &_pos)
Set the position of the visual.
@ VT_ENTITY
Entity visual.
Definition: Visual.hh:67
VisualPrivate * dataPtr
Definition: Visual.hh:751
void SetTypeMsg(const google::protobuf::Message *_msg)
Set a message specific for this visual type.
void SetMaterial(const std::string &_materialName, bool _unique=true, const bool _cascade=true)
Set the material.
@ VT_VISUAL
Visual visual.
Definition: Visual.hh:73
void SetSpecular(const ignition::math::Color &_color, const bool _cascade=true)
Set the specular color of the visual.
void DeleteDynamicLine(DynamicLines *_line)
Delete a dynamic line.
std::string GetMaterialName() const
Get the name of the material.
VisualPtr Clone(const std::string &_name, VisualPtr _newParent)
Clone the visual with a new name.
void SetId(uint32_t _id)
Set the id associated with this visual.
void Init()
Helper for the contructor.
ignition::math::Color Diffuse() const
Get the diffuse color of the visual.
ignition::math::Vector3d Scale() const
Get the scale.
void SetPose(const ignition::math::Pose3d &_pose)
Set the pose of the visual.
unsigned int GetDepth() const
Get the depth of this visual, where 0 is the depth of the world visual.
bool GetLighting() const
Get whether or not lighting is enabled.
void SetLighting(bool _lighting)
Set whether or not to enable or disable lighting.
void EnableTrackVisual(VisualPtr _vis)
Set one visual to track/follow another.
uint32_t GetVisibilityFlags()
Get visibility flags for this visual and all children.
bool UseRTShader() const
Get whether this visual uses RT shader system.
VisualPtr GetChild(unsigned int _index)
Get an attached visual based on an index.
void SetShaderType(const std::string &_type)
Set the shader type for the visual's material.
void AddPendingChild(std::pair< VisualType, const google::protobuf::Message * > _pair)
Push a message for a child of this visual which hasn't been loaded yet.
Class for drawing lines that can change.
Definition: DynamicLines.hh:42
@ VT_GUI
GUI visual.
Definition: Visual.hh:79
VisualPtr GetParent() const
Get the parent visual, if one exists.
ignition::math::Color Emissive() const
Get the emissive color of the visual.
void SetWorldPose(const ignition::math::Pose3d &_pose)
Set the world pose of the visual.
sdf::ElementPtr GetSDF() const
Get the visual SDF.
bool IsAncestorOf(const rendering::VisualPtr _visual) const
Check if this visual is an ancestor of another visual.
void Update()
Update the visual.
@ RENDERING_LINE_STRIP
A strip of connected lines, 1 vertex per line plus 1 start vertex.
Definition: RenderTypes.hh:226
void SetWorldPosition(const ignition::math::Vector3d &_pos)
Set the world linear position of the visual.
void ShowCOM(bool _show)
Display Center of Mass visuals.
VisualPtr GetNthAncestor(unsigned int _n)
Get the nth ancestor counting from the world visual.
void ProcessMaterialMsg(const msgs::Material &_msg)
Process a gazebo material message, which uses proto2 syntax that allows unset fields to be ignored,...
void ShowCollision(bool _show)
Display the collision visuals.
bool GetVisible() const
Get whether the visual is visible.
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:82
std::string GetGeometryType() const
Get the geometry type.
RenderOpType
Type of render operation for a drawable.
Definition: RenderTypes.hh:216
std::string GetMeshName() const
The name of the mesh set in the visual's SDF.
void MoveToPosition(const ignition::math::Pose3d &_pose, const double _time)
Move to a pose and over a given time.
bool Wireframe() const
Get whether wireframe is enabled for this visual.
void MoveToPositions(const std::vector< ignition::math::Pose3d > &_pts, const double _time, std::function< void()> _onComplete=nullptr)
Move to a series of pose and over a given time.
void ShowLinkFrame(bool _show)
Display link frame visuals.
ignition::math::Pose3d InitialRelativePose() const
Get the initial relative pose of the visual.
rendering
Definition: RenderEngine.hh:31
void SetScale(const ignition::math::Vector3d &_scale)
Set the scale.
A renderable object.
Definition: Visual.hh:59
VisualType
Type of visual.
Definition: Visual.hh:64
Ogre::MovableObject * AttachMesh(const std::string &_meshName, const std::string &_subMesh="", bool _centerSubmesh=false, const std::string &_objName="")
Attach a mesh to this visual by name.
std::string GetShaderType() const
Get the shader type.
void ToggleLayer(const int32_t _layer)
Toggle layer visibility.
void LoadPlugin(const std::string &_filename, const std::string &_name, sdf::ElementPtr _sdf)
Load a plugin.
bool IsPlane() const
Return true if the visual is a plane.
void SetWireframe(bool _show)
Enable or disable wireframe for this visual.
void SetName(const std::string &_name)
Set the name of the visual.
void SetDiffuse(const ignition::math::Color &_color, const bool _cascade=true)
Set the diffuse color of the visual.
void AttachVisual(VisualPtr _vis)
Attach a visual to this visual.
void ClearParent()
Clear parents.
@ VT_LINK
Link visual.
Definition: Visual.hh:71
void UpdateFromMsg(ConstVisualPtr &_msg)
Update a visual based on a message.
DynamicLines * CreateDynamicLine(RenderOpType _type=RENDERING_LINE_STRIP)
Add a line to the visual.
std::string GetNormalMap() const
Get the normal map.
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
void SetInheritTransparency(const bool _inherit)
Set whether to inherit transparency from parent.
uint32_t GetId() const
Get the id associated with this visual.
void SetSkeletonPose(const msgs::PoseAnimation &_pose)
Set animation skeleton pose.
void SetVisibilityFlags(uint32_t _flags)
Set visibility flags for this visual and all children.
A 3D mesh.
Definition: Mesh.hh:42
float DerivedTransparency() const
Get the transparency of the visual as inherited from all parents.
void SetLayer(const int32_t _layer)
Set the layer this visual belongs to.
bool IsStatic() const
Return true if the visual is a static geometry.
std::string GetSubMeshName() const
Get the name of the sub mesh set in the visual's SDF.
unsigned int GetChildCount()
Get the number of attached visuals.
void ShowSkeleton(bool _show)
Display the skeleton visuals.
virtual void SetEmissive(const ignition::math::Color &_color, const bool _cascade=true)
Set the emissive value.
void SetTransparency(float _trans)
Set the transparency.
bool GetHighlighted() const
Get whether or not the visual is visually highlighted.
void AttachObject(Ogre::MovableObject *_obj)
Attach a renerable object to the visual.
ignition::math::Color Ambient() const
Get the ambient color of the visual.
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
void AttachLineVertex(DynamicLines *_line, unsigned int _index)
Attach a vertex of a line to the position of the visual.
Visual::VisualType GetType() const
Get type of visual.
ignition::math::Vector3d Position() const
Get the position of the visual.
void InsertMesh(const std::string &_meshName, const std::string &_subMesh="", bool _centerSubmesh=false)
Insert a mesh into Ogre.
void ToggleVisible()
Toggle whether this visual is visible.
bool GetCastShadows() const
Get whether the visual casts shadows.
void SetCastShadows(bool _shadows)
Set whether the visual should cast shadows.
std::string Name() const
Get the name of the visual.
void ShowJoints(bool _show)
Display joint visuals.
bool HasAttachedObject(const std::string &_name)
Returns true if an object with _name is attached.
void DisableTrackVisual()
Disable tracking of a visual.
virtual void Fini()
Helper for the destructor.
ignition::math::AxisAlignedBox BoundingBox() const
Get the bounding box for the visual.
ignition::math::Vector3d DerivedScale() const
Get the scale of the visual as inherited from all parents.
void SetRibbonTrail(bool _value, const ignition::math::Color &_initialColor, const ignition::math::Color &_changeColor)
True on or off a ribbon trail.
ignition::math::Quaterniond Rotation() const
Get the rotation of the visual.
ignition::math::Color Specular() const
Get the specular color of the visual.
bool IsDescendantOf(const rendering::VisualPtr _visual) const
Check if this visual is a descendant of another visual.
VisualPtr GetRootVisual()
Get the root visual.
void LoadFromMsg(ConstVisualPtr &_msg)
Load from a message.
void DetachVisual(VisualPtr _vis)
Detach a visual.
bool InheritTransparency() const
Get whether this visual inherits transparency from parent.
virtual void SetHighlighted(bool _highlighted)
Set the visual to be visually highlighted.
void ShowInertia(bool _show)
Display inertia visuals.
ignition::math::Pose3d Pose() const
Get the pose of the visual.
float GetTransparency()
Get the transparency.
void MakeStatic()
Make the visual objects static renderables.
@ VT_PHYSICS
Physics data visual.
Definition: Visual.hh:81