Kale
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Kale::SkeletalAnimatable Class Reference

#include <SkeletalAnimatable.hpp>

+ Inheritance diagram for Kale::SkeletalAnimatable:

Public Member Functions

 SkeletalAnimatable ()
 
 SkeletalAnimatable (const Skeleton &base)
 
void setBase (const Skeleton &skeleton)
 
const std::vector< Transform > & getSkeleton (float deltaTime)
 
const std::vector< Transform > & getSkeletonNoRecalc () const
 
Vector2f transform (Vector2f vert, const std::array< std::pair< int, float >, 4 > &weights, float deltaTime)
 
Vector2f transformNoRecalc (Vector2f vert, const std::array< std::pair< int, float >, 4 > &weights) const
 
- Public Member Functions inherited from Kale::StateAnimatable< Skeleton >
 StateAnimatable ()
 
 StateAnimatable (JSON json)
 
void updateState (float deltaTime)
 
void addStructure (T state, const Skeleton &structure)
 
void removeStructure (T state)
 
Skeleton getStructure (T state) const
 
void animateTo (T state, float duration)
 
void animateOnce (std::vector< std::pair< T, float > > stages)
 
void animateLoop (std::vector< std::pair< T, float > > stages)
 
void setState (T state)
 
getCurrentState () const
 
std::vector< std::pair< T, float > > getStateComposition () const
 
bool isTransitioning () const
 

Protected Member Functions

void update (size_t threadNum, const Scene &scene, float deltaTime) override
 
void preUpdate (size_t threadNum, const Scene &scene, float deltaTime) override
 
- Protected Member Functions inherited from Kale::Node
virtual void begin (const Scene &scene)
 
virtual void render (const Camera &camera, float deltaTime) const
 
virtual void end (const Scene &scene)
 
 Node ()
 
 Node (float preUpdateTime, float updateTime)
 

Private Member Functions

void recalculateSkeleton (float deltaTime)
 

Private Attributes

std::vector< Transformskeleton
 
Skeleton base
 
bool skeletonRecalculated
 
std::mutex mutex
 

Additional Inherited Members

- Public Attributes inherited from Kale::Node
std::string name
 
const float updateTime = 100.0f
 
const float preUpdateTime = 100.0f
 
- Protected Attributes inherited from Kale::Node
std::optional< std::mutex > mutex
 
- Protected Attributes inherited from Kale::StateAnimatable< Skeleton >
int state
 
int transitionState
 
bool transitioning
 
float transitionTime
 
float transitionDuration
 
std::unordered_map< int, Skeletonstructures
 
std::vector< std::pair< int, float > > animationInfo
 
size_t animationIndex
 
bool animationLoop
 

Detailed Description

A system for skeletal animations. Unlike the state animatable system, skeletal animatables are a node and can be directly added to the scene. Nodes which support skeleton animatables can link to the node via a shared ptr.

Definition at line 142 of file SkeletalAnimatable.hpp.

Constructor & Destructor Documentation

◆ SkeletalAnimatable() [1/2]

SkeletalAnimatable::SkeletalAnimatable ( )

Creates an empty skeletal animatable

Definition at line 50 of file SkeletalAnimatable.cpp.

◆ SkeletalAnimatable() [2/2]

SkeletalAnimatable::SkeletalAnimatable ( const Skeleton & base)

Creates a skeletal animatable with a base skeleton which all given vertices are weighted by

Parameters
baseThe base skeleton all transformed vertices are rigged by

Definition at line 58 of file SkeletalAnimatable.cpp.

Member Function Documentation

◆ getSkeleton()

const std::vector< Transform > & SkeletalAnimatable::getSkeleton ( float deltaTime)

Thread-Safe method to get the current skeleton, must be called during a pre-update and cannot be called during the update. If you need access to the skeleton for transformation/skinning during an update, use getSkeletonNoRecalc().

Parameters
deltaTimeThe duration of the last frame in microseconds
Returns
The skeleton for this frame

Definition at line 134 of file SkeletalAnimatable.cpp.

◆ getSkeletonNoRecalc()

const std::vector< Transform > & SkeletalAnimatable::getSkeletonNoRecalc ( ) const

Thread-Safe method to get the current skeleton, the skeleton will not be recalculated even if it is flagged as out of date. This method should only be called after pre-updates, otherwise it may not be updated, or worse may update on another thread while given.

Returns
The skeleton as it is

Definition at line 145 of file SkeletalAnimatable.cpp.

◆ preUpdate()

void SkeletalAnimatable::preUpdate ( size_t threadNum,
const Scene & scene,
float deltaTime )
overrideprotectedvirtual

Called prior to update, perfect place to do things such as updating the bounding box, etc

Parameters
threadNumthe index of the thread this update is called on
sceneThe scene being updated to
deltaTimeThe duration of the last frame in microseconds

Reimplemented from Kale::Node.

Definition at line 124 of file SkeletalAnimatable.cpp.

◆ recalculateSkeleton()

void SkeletalAnimatable::recalculateSkeleton ( float deltaTime)
private

Recalculates the skeleton based on the current state composition

Parameters
deltaTimeThe duration of the last frame in microseconds

Definition at line 74 of file SkeletalAnimatable.cpp.

◆ setBase()

void SkeletalAnimatable::setBase ( const Skeleton & skeleton)

Sets the base skeleton transformed vertices are rigged by

Parameters
skeletonThe base skeleton transformed vertices are rigged by

Definition at line 66 of file SkeletalAnimatable.cpp.

◆ transform()

Vector2f SkeletalAnimatable::transform ( Vector2f vert,
const std::array< std::pair< int, float >, 4 > & weights,
float deltaTime )

Transforms a single vertex given its weights, cannot be called during the update.

Parameters
vertThe vertex to transform
weightsThe weights of the vertex, 4 pairs of the index of the bone along with the significance. Must add up to 1, set the index of the bone to -1 if it is unassigned.
deltaTimeThe duration of the last frame in microseconds
Returns
The transformed vertex

Transforms a single vertex given its weights

Parameters
vertThe vertex to transform
weightsThe weights of the vertex, 4 pairs of the index of the bone along with the significance. Must add up to 1, set the index of the bone to -1 if it is unassigned.
Returns
The transformed vertex

Definition at line 156 of file SkeletalAnimatable.cpp.

◆ transformNoRecalc()

Vector2f SkeletalAnimatable::transformNoRecalc ( Vector2f vert,
const std::array< std::pair< int, float >, 4 > & weights ) const

Transforms a single vertex given its weights. This method should only be called after pre-updates, otherwise it may not be updated, or worse may update on another thread while given.

Parameters
vertThe vertex to transform
weightsThe weights of the vertex, 4 pairs of the index of the bone along with the significance. Must add up to 1, set the index of the bone to -1 if it is unassigned.
Returns
The transformed vertex

Transforms a single vertex given its weights

Parameters
vertThe vertex to transform
weightsThe weights of the vertex, 4 pairs of the index of the bone along with the significance. Must add up to 1, set the index of the bone to -1 if it is unassigned.
Returns
The transformed vertex

Definition at line 168 of file SkeletalAnimatable.cpp.

◆ update()

void SkeletalAnimatable::update ( size_t threadNum,
const Scene & scene,
float deltaTime )
overrideprotectedvirtual

Called on update, perfect place to do any physics updating, game logic, etc

Parameters
threadNumthe index of the thread this update is called on
sceneThe scene being updated to
deltaTimeThe duration of the last frame in microseconds

Reimplemented from Kale::Node.

Definition at line 114 of file SkeletalAnimatable.cpp.

Member Data Documentation

◆ base

Skeleton Kale::SkeletalAnimatable::base
private

The base state of the skeleton, vertices are rigged to this skeleton

Definition at line 153 of file SkeletalAnimatable.hpp.

◆ mutex

std::mutex Kale::SkeletalAnimatable::mutex
private

Mutex used for ensuring safe access to skeleton updates

Definition at line 164 of file SkeletalAnimatable.hpp.

◆ skeleton

std::vector<Transform> Kale::SkeletalAnimatable::skeleton
private

The currently held skeleton offsets

Definition at line 148 of file SkeletalAnimatable.hpp.

◆ skeletonRecalculated

bool Kale::SkeletalAnimatable::skeletonRecalculated
private

Whether or not the skeleton has been recalculated for this frame. This is set to true whenever the skeleton is recalculated and set to false again every update.

Definition at line 159 of file SkeletalAnimatable.hpp.


The documentation for this class was generated from the following files: