Actor.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 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 GAZEBO_PHYSICS_ACTOR_HH_
18#define GAZEBO_PHYSICS_ACTOR_HH_
19
20#include <string>
21#include <map>
22#include <memory>
23#include <vector>
24
25#include <ignition/math/Color.hh>
26
28#include "gazebo/common/Time.hh"
30#include "gazebo/util/system.hh"
31
32namespace gazebo
33{
34 namespace common
35 {
36 class Mesh;
37 class Skeleton;
38 }
39
40 namespace physics
41 {
42 class ActorPrivate;
43
47 class GZ_PHYSICS_VISIBLE TrajectoryInfo
48 {
50 public: TrajectoryInfo();
51
53 public: unsigned int id;
54
57 public: std::string type;
58
60 public: double duration;
61
63 public: double startTime;
64
66 public: double endTime;
67
69 public: bool translated;
70 };
71
74
78 class GZ_PHYSICS_VISIBLE Actor : public Model
79 {
81 public: typedef std::map<std::string, common::SkeletonAnimation *>
83
86 public: explicit Actor(BasePtr _parent);
87
89 public: virtual ~Actor();
90
93 public: void Load(sdf::ElementPtr _sdf);
94
98 public: void AlignBvh(common::Skeleton *_skel,
99 const std::map<std::string, std::string> &_skelMap);
100
102 public: virtual void Init();
103
105 public: virtual void Play();
106
108 public: virtual void Stop();
109
112 public: virtual bool IsActive() const;
113
115 public: void Update();
116
118 public: virtual void Fini();
119
122 public: virtual void UpdateParameters(sdf::ElementPtr _sdf);
123
126 public: virtual const sdf::ElementPtr GetSDF();
127
129 public: void Reset();
130 using Model::Reset;
131
136 public: void SetScriptTime(const double _time);
137
142 public: double ScriptTime() const;
143
148
155 public: void SetCustomTrajectory(TrajectoryInfoPtr &_trajInfo);
156
159 public: const common::Mesh *Mesh() const;
160
166
169 public: void ResetCustomTrajectory();
170
175 public: virtual bool GetSelfCollide() const;
176
182 public: virtual void SetSelfCollide(bool _selfCollide);
183
188 public: virtual bool WindMode() const;
189
195 public: virtual void SetWindMode(const bool _enabled);
196
202 private: void AddSphereInertia(const sdf::ElementPtr &_linkSdf,
203 const ignition::math::Pose3d &_pose,
204 const double _mass, const double _radius);
205
212 private: void AddSphereCollision(const sdf::ElementPtr &_linkSdf,
213 const std::string &_name,
214 const ignition::math::Pose3d &_pose,
215 const double _radius);
216
223 private: void AddBoxCollision(const sdf::ElementPtr &_linkSdf,
224 const std::string &_name,
225 const ignition::math::Pose3d &_pose,
226 const ignition::math::Vector3d &_size);
227
235 private: void AddSphereVisual(const sdf::ElementPtr &_linkSdf,
236 const std::string &_name,
237 const ignition::math::Pose3d &_pose, const double _radius,
238 const std::string &_material,
239 const ignition::math::Color &_ambient);
240
248 private: void AddBoxVisual(const sdf::ElementPtr &_linkSdf,
249 const std::string &_name,
250 const ignition::math::Pose3d &_pose,
251 const ignition::math::Vector3d &_size,
252 const std::string &_material,
253 const ignition::math::Color &_ambient);
254
259 private: void AddActorVisual(const sdf::ElementPtr &_linkSdf,
260 const std::string &_name,
261 const ignition::math::Pose3d &_pose);
262
267 private: bool LoadSkin(sdf::ElementPtr _sdf);
268
274 private: void LoadAnimation(sdf::ElementPtr _sdf);
275
278 private: void LoadScript(sdf::ElementPtr _sdf);
279
285 private: void SetPose(
286 std::map<std::string, ignition::math::Matrix4d> _frame,
287 std::map<std::string, std::string> _skelMap,
288 const double _time);
289
291 protected: const common::Mesh *mesh = nullptr;
292
294 protected: common::Skeleton *skeleton = nullptr;
295
297 protected: std::string skinFile;
298
300 protected: double skinScale;
301
304 protected: double startDelay;
305
307 protected: double scriptLength;
308
310 protected: bool loop;
311
313 protected: bool active;
314
317 protected: bool autoStart;
318
320 protected: LinkPtr mainLink;
321
324
327
331 protected: std::map<unsigned int, common::PoseAnimation *> trajectories;
332
337 protected: std::vector<TrajectoryInfo> trajInfo;
338
344
353 protected: std::map<std::string, std::map<std::string, std::string> >
355
358 // direction.
361 protected: std::map<std::string, bool> interpolateX;
362
364 protected: ignition::math::Vector3d lastPos;
365
367 protected: double pathLength;
368
370 protected: unsigned int lastTraj;
371
373 protected: std::string visualName;
374
376 protected: uint32_t visualId;
377
380
383 private: double scriptTime;
384
387 private: TrajectoryInfoPtr customTrajectoryInfo;
388
390 private: std::unique_ptr<ActorPrivate> dataPtr;
391 };
393 }
394}
395#endif
396
common
Definition FuelModelDatabase.hh:42
A 3D mesh.
Definition Mesh.hh:43
A skeleton.
Definition Skeleton.hh:53
A Time class, can be used to hold wall- or sim-time.
Definition Time.hh:48
Actor class enables GPU based mesh model / skeleton scriptable animation.
Definition Actor.hh:79
bool active
True if the actor is being updated.
Definition Actor.hh:313
uint32_t visualId
ID for the visual representing the skin.
Definition Actor.hh:376
double ScriptTime() const
Get the current script time.
void SetCustomTrajectory(TrajectoryInfoPtr &_trajInfo)
Set a custom trajectory for the actor, using one of the existing animations.
const SkeletonAnimation_M & SkeletonAnimations() const
Returns a dictionary of all the skeleton animations associated with the actor.
virtual bool GetSelfCollide() const
Get whether the links in the actor can collide with each other.
const common::Mesh * mesh
Pointer to the actor's mesh.
Definition Actor.hh:291
void AlignBvh(common::Skeleton *_skel, const std::map< std::string, std::string > &_skelMap)
Align BVH to DAE skin.
LinkPtr mainLink
Pointer to the actor's canonical link.
Definition Actor.hh:320
TrajectoryInfoPtr CustomTrajectory() const
Get the custom trajectory.
virtual void Fini()
Finalize the actor.
const common::Mesh * Mesh() const
Returns the actor's mesh.
void Reset()
Reset the actor.
virtual void Init()
Initialize the actor.
bool autoStart
True if the actor should start running automatically, otherwise it will only start once Play is calle...
Definition Actor.hh:317
std::string visualName
Name of the visual representing the skin.
Definition Actor.hh:373
std::map< std::string, std::map< std::string, std::string > > skelNodesMap
Skeleton to node map:
Definition Actor.hh:354
std::map< unsigned int, common::PoseAnimation * > trajectories
Map of all the trajectories (pose animations) and their indices.
Definition Actor.hh:331
common::Time prevFrameTime
Time of the previous frame.
Definition Actor.hh:323
double startDelay
Time to wait before starting the script.
Definition Actor.hh:304
std::string skinFile
Filename for the skin.
Definition Actor.hh:297
void ResetCustomTrajectory()
Reset custom trajectory of the actor.
SkeletonAnimation_M skelAnimation
Map of skeleton animations, indexed by their names.
Definition Actor.hh:343
void SetScriptTime(const double _time)
Set the current script time.
bool loop
True if the animation should loop.
Definition Actor.hh:310
virtual const sdf::ElementPtr GetSDF()
Get the SDF values for the actor.
unsigned int lastTraj
Id of the last trajectory.
Definition Actor.hh:370
ignition::math::Vector3d lastPos
Last position of the actor.
Definition Actor.hh:364
common::Skeleton * skeleton
The actor's skeleton.
Definition Actor.hh:294
transport::PublisherPtr bonePosePub
Publisher to send bone info.
Definition Actor.hh:379
virtual bool IsActive() const
Returns true when actor is playing animation.
std::vector< TrajectoryInfo > trajInfo
A vector of trajectory information, which contains information such as their durations,...
Definition Actor.hh:337
virtual void SetSelfCollide(bool _selfCollide)
Override set self collide method to make it impossible to set it to true for actors.
virtual bool WindMode() const
Get whether the links in the actor are affected by wind.
double pathLength
Length of the actor's path.
Definition Actor.hh:367
std::map< std::string, common::SkeletonAnimation * > SkeletonAnimation_M
Typedef the skeleton animation map, indexed by their names.
Definition Actor.hh:82
common::Time playStartTime
Time when the animation was started.
Definition Actor.hh:326
virtual void SetWindMode(const bool _enabled)
Override set wind mode method to make it impossible to set it to true for actors.
double skinScale
Scaling factor to apply to the skin.
Definition Actor.hh:300
void Load(sdf::ElementPtr _sdf)
Load the actor.
virtual void Play()
Start playing the script.
virtual void UpdateParameters(sdf::ElementPtr _sdf)
Update the parameters using new sdf values.
double scriptLength
Total time length of the script, in seconds.
Definition Actor.hh:307
std::map< std::string, bool > interpolateX
Map of animation types (the same name as in skelAnimation and skelNodesMap) and whether they should b...
Definition Actor.hh:361
void Update()
Update the actor.
Actor(BasePtr _parent)
Constructor.
virtual void Stop()
Stop playing the script.
virtual ~Actor()
Destructor.
A model is a collection of links, joints, and plugins.
Definition Model.hh:60
void Reset() override
Reset the model.
Information about a trajectory for an Actor.
Definition Actor.hh:48
double startTime
Start time of this keyframe within the trajectory, in seconds.
Definition Actor.hh:63
double endTime
End time of this keyframe within the trajectory, in seconds.
Definition Actor.hh:66
std::string type
Type of trajectory.
Definition Actor.hh:57
bool translated
True if the trajectory is translated.
Definition Actor.hh:69
unsigned int id
ID of the trajectory.
Definition Actor.hh:53
double duration
Duration of this keyframe in seconds.
Definition Actor.hh:60
boost::shared_ptr< Link > LinkPtr
Definition PhysicsTypes.hh:110
boost::shared_ptr< Base > BasePtr
Definition PhysicsTypes.hh:78
std::shared_ptr< TrajectoryInfo > TrajectoryInfoPtr
Definition PhysicsTypes.hh:102
boost::shared_ptr< Publisher > PublisherPtr
Definition TransportTypes.hh:49
Forward declarations for the common classes.
Definition Animation.hh:27