COGS
Computer Graphics Structures library
cogs::Skeleton Class Reference

3D Graph structure, usually representing topology of a 3D model. More...

Inherited by cogs::Armature.

Data Structures

struct  BaseProperty
 Abstract helper class used for storage of skeleton properties. More...
 
struct  Property
 Template class used for storage of skeleton properties. More...
 

Public Member Functions

 Skeleton ()
 Creates an empty skeleton.
 
 Skeleton (const Skeleton &skeleton)
 Creates a copy of specified skeleton.
 
Skeleton & operator= (const Skeleton &skeleton)
 Creates a copy of specified skeleton.
 
 ~Skeleton ()
 Destroys instance and free all its data.
 
std::string GetName () const
 Changes the name of this skeleton object.
 
void SetName (const std::string &new_name)
 Returns the name of this skeleton object.
 
std::vector< Bone * > GetAllBones () const
 Returns all bones.
 
std::vector< std::string > GetAllBoneCaptions () const
 Returns captions of all bones.
 
std::vector< Bone * > GetBones (const std::vector< std::string > &bone_captions) const
 Returns all bones that have specified captions.
 
Bone * GetBone (const uint32_t id) const
 Returns bone with specified id.
 
Bone * GetBone (const std::string &bone_caption) const
 Returns bone with specified caption.
 
std::vector< Bone * > GetRootBones () const
 Returns all bones which are starting the sub hierarchies.
 
void Clear ()
 Removes all bones from skeleton and clears hierarchy data.
 
unsigned GetBoneCount () const
 Number of bones in skeleton hierarchy.
 
Bone * AddBone (const std::string &name, const std::string &parent_name, const glm::vec3 &tail_position)
 Will add bone to skeleton, which starts at the fathers tail position and ends in specified tail_position.
 
Bone * AddBone (const std::string &name, const std::string &parent_name, const BoneTransform &transform)
 Will add bone to skeleton, which has a defined bone transform.
 
Bone * AddBoneToRoot (const std::string &name, const glm::vec3 &tail_position)
 Adds bone to skeleton, which starts at skeleton root position and ends in defined tail_position.
 
Bone * AddBoneToRoot (const std::string &name, const BoneTransform &transform)
 Adds bone to skeleton, which has a defined bone transform.
 
void RollBasis (const std::string &bone_name, const float roll_angle)
 Rolls basis of a single bone, without manipulating whole child hierarchy.
 
void ApplyBoneLengths (const std::vector< float > &bone_lengths)
 Resizes individual bones their orientation will not change.
 
void SortBySkeleton (const cogs::Skeleton &ref_skeleton)
 
void InterpolateTo (const cogs::Skeleton &target_skel, float target_weight, cogs::Skeleton *out_skeleton) const
 
SkeletonPose GetCurrentPose () const
 Returns current skeleton pose.
 
SkeletonPose GetCurrentPose (const std::vector< std::string > &bone_order) const
 Returns current skeleton pose, with reordered bones.
 
void ApplyPose (const SkeletonPose &pose, bool ignore_root_transform=false)
 Applies pose to the skeleton bones.
 
void ApplyBindpose ()
 Sets default pose (pose with only identity matrices).
 
void ApplyCurrentPoseAsBindpose ()
 Overwrites bind pose by current pose transformations. Current pose transformations will be identities.
 
BaseProperty * GetProperty (const std::string &prop) const
 Returns specific skeleton property.
 
template<class T >
T GetProperty (const std::string &prop) const
 Returns specific skeleton property.
 
template<class T >
void SetProperty (const std::string &prop, const T &value)
 Sets specific skeleton property. If property do not exist yet, creates new property record.
 
bool HasProperty (const std::string &prop) const
 Checks if the property exist.
 

Data Fields

cogs::Transform transform
 Transformation of the entire skeleton.
 

Protected Member Functions

Bone * CreateNewBone (const std::string &caption)
 
Bone * CreateBoneClone (const cogs::Bone *bone)
 
void MakeCloneOf (const Skeleton &skeleton)
 
void OnTransformChange ()
 

Protected Attributes

std::string name_
 
cogs::Transform bind_transform
 
std::unordered_map< std::string, BaseProperty * > properties_
 
std::map< std::string, Bone * > bone_for_name_
 
std::vector< Bone * > bones_
 
std::vector< Bone * > root_bones_
 
unsigned bone_count_ = 0
 

Detailed Description

3D Graph structure, usually representing topology of a 3D model.

Member Function Documentation

◆ InterpolateTo()

void cogs::Skeleton::InterpolateTo ( const cogs::Skeleton &  target_skel,
float  target_weight,
cogs::Skeleton *  out_skeleton 
) const

/brief Interpolates skeleton into target skeleton (same principle as SkeletonPose::InterpolateWith).

/param target_skel Target skeleton. Must have same number of bones and same bone names as this skeleton.

/param target_weight Number in interval <0, 1>, if equals 0 then output will be copy of this skeleton. If equals 1, output will be copy of target skeleton.

/param out_skeleton Result of the interpolation.

◆ SortBySkeleton()

void cogs::Skeleton::SortBySkeleton ( const cogs::Skeleton &  ref_skeleton)

/brief Sorts the vector of bones (returned by GetBones) so it corresponds with input skeleton.

/param ref_skeleton Reference skeleton, must have same number of bones with same names as this skeleton.