|
Nebula
|
#include <charactercontext.h>
Assumes control over the character animation functionalities of a model if it contains a character definition and an animation set.
Internally, the character context is responsible for dispatching animation jobs, blending animation, and keeping track of the current time playing for each registered entity.
The character context also handles animation events, which are triggers to play when animation hits a certain time stamp.
How the context works is like this: Every character has a buffer of samples which is updated every frame. Every character has a set of tracks to play animations on, which can be blended between if requested. Tracks are blended in sequential order. Every character has a list per track of pending animations, which are ticked off whenever the current animation has finished. Animations can be played without enqueueing, which replaces the currently playing animation on that track.
Inherits Graphics::GraphicsContext.
Classes | |
| struct | FiredEvent |
| an event a clip played on a track passed More... | |
| struct | AnimationRuntime |
| struct | AnimationTracks |
Public Types | |
| enum | LoadState { NoneLoaded = 0 , SkeletonLoaded = N_BIT(1) , AnimationLoaded = N_BIT(2) } |
Public Member Functions | |
| CharacterContext () | |
| constructor | |
| virtual | ~CharacterContext () |
| destructor | |
| Public Member Functions inherited from Graphics::GraphicsContext | |
| GraphicsContext () | |
| constructor | |
| virtual | ~GraphicsContext () |
| destructor | |
Static Public Member Functions | |
| static void | Create () |
| setup character context | |
| static void | Setup (const Graphics::GraphicsEntityId id, const Resources::ResourceName &skeletonResource, const IndexT skeletonIndex, const Resources::ResourceName &animationResource, const IndexT animationIndex, const Util::StringAtom &tag, bool supportBlending=true) |
| setup character context, assumes there is already a model attached, by loading a skeleton and animation resource | |
| static bool | SetupFromModel (const Graphics::GraphicsEntityId id, const IO::Path &model, const Util::StringAtom &tag) |
| if the entity's model is skinned, register and setup the entity as a character using the skeleton and animation packaged with the model (folder:file:ske and folder:file:ani), and play its first clip. | |
| static IndexT | GetClipIndex (const Graphics::GraphicsEntityId id, const Util::StringAtom &name) |
| perform a clip name lookup | |
| static bool | PlayClip (const Graphics::GraphicsEntityId id, const CoreAnimation::AnimSampleMask *mask, const IndexT clipIndex, const IndexT track, const EnqueueMode mode, const float weight=1.0f, const SizeT loopCount=1, const float startTime=0.0f, const float fadeIn=0.0f, const float fadeOut=0.0f, const float timeOffset=0.0f, const float timeFactor=1.0f) |
| play animation on a specific track | |
| static void | StopTrack (const Graphics::GraphicsEntityId id, const IndexT track) |
| stops all animations queued on track (and resets their time) | |
| static void | StopAllTracks (const Graphics::GraphicsEntityId id) |
| stops all animations on all tracks | |
| static void | PauseTrack (const Graphics::GraphicsEntityId id, const IndexT track) |
| pause animation on track, which doesn't reset time | |
| static void | Seek (const Graphics::GraphicsEntityId id, const float time) |
| seek animation to a certain time, clamps to length | |
| static const float | GetTime (const Graphics::GraphicsEntityId id) |
| get current time of animation | |
| static bool | IsPlaying (const Graphics::GraphicsEntityId id) |
| check if any animation is playing | |
| static void | SetTrackWeight (const Graphics::GraphicsEntityId id, const IndexT track, const float weight) |
| set weight for track | |
| static void | SetTrackTimeFactor (const Graphics::GraphicsEntityId id, const IndexT track, const float factor) |
| set time factor for track | |
| static void | QueryClips (const Graphics::GraphicsEntityId id, Util::FixedArray< CoreAnimation::AnimClip > &outClips) |
| retrieve animation clip names and lengths | |
| static const SkeletonId | GetSkeleton (const Graphics::GraphicsEntityId id) |
| get the skeleton, invalid until it's loaded | |
| static const CoreAnimation::AnimationId | GetAnimation (const Graphics::GraphicsEntityId id) |
| get the animation, invalid until it's loaded | |
| static const Util::FixedArray< Math::mat4 > & | GetJointTransforms (const Graphics::GraphicsEntityId id) |
| get the model space transforms of the joints in the last evaluated pose, one per joint of the skeleton | |
| static const IndexT | GetPlayingClip (const Graphics::GraphicsEntityId id, const IndexT track) |
| get the clip playing on a track, InvalidIndex if none is | |
| static bool | IsTrackPaused (const Graphics::GraphicsEntityId id, const IndexT track) |
| check if the clip playing on a track is paused | |
| static Timing::Time | GetTrackTime (const Graphics::GraphicsEntityId id, const IndexT track) |
| get the time in the clip playing on a track in seconds, within its duration for looped clips, 0 if none is playing | |
| static void | SeekTrack (const Graphics::GraphicsEntityId id, const IndexT track, const Timing::Time time) |
| move the clip playing on a track to a time in it in seconds, it plays on from there, a paused one shows the pose at that time. | |
| static const Util::Array< FiredEvent > & | GetFiredEvents (const Graphics::GraphicsEntityId id) |
| get the events the clips played on the tracks passed in the last update that finished, in the order of the tracks. | |
| static void | UpdateAnimations (const Graphics::FrameContext &ctx) |
| runs before frame is updated | |
| static void | WaitForCharacterJobs (const Graphics::FrameContext &ctx) |
| run after frame | |
| static CoreAnimation::AnimSampleMask * | CreateAnimSampleMask (const Util::StringAtom &name, const Util::FixedArray< Math::scalar > &weights) |
| register anim sample mask, and return pointer | |
| static CoreAnimation::AnimSampleMask * | GetAnimSampleMask (const Util::StringAtom &name) |
| get anim sample mask by name | |
| static void | OnRenderDebug (uint32_t flags) |
| debug rendering | |
Static Public Attributes | |
| static Threading::Interlocked::AtomicCounter | ConstantUpdateCounter = 0 |
Private Types | |
| enum | { Skeleton , Animation , Loaded , TrackController , AnimTime , JointPalette , JointPaletteScaled , UserControlledJoint , JobJoints , SampleBuffer , SupportMix , EntityId , CharacterSkinNodeIndexOffset , AnimationResource , AnimationIndex , FiredEvents , PendingFiredEvents } |
| typedef Ids::IdAllocator< SkeletonId, CoreAnimation::AnimationId, LoadState, AnimationTracks, Timing::Time, Util::FixedArray< Math::mat4 >, Util::FixedArray< Math::mat4 >, Util::FixedArray< Math::mat4 >, Util::FixedArray< SkeletonJobJoint >, CoreAnimation::AnimSampleBuffer, bool, Graphics::GraphicsEntityId, IndexT, Resources::ResourceId, IndexT, Util::Array< FiredEvent >, Util::Array< FiredEvent > > | CharacterContextAllocator |
Private Member Functions | |
| __DeclareContext () | |
Static Private Member Functions | |
| static Graphics::ContextEntityId | Alloc () |
| allocate a new slice for this context | |
| static void | Dealloc (Graphics::ContextEntityId id) |
| deallocate a slice | |
Static Private Attributes | |
| static const SizeT | MaxNumTracks = 16 |
| static CharacterContextAllocator | characterContextAllocator |
| static Util::HashTable< Util::StringAtom, CoreAnimation::AnimSampleMask > | masks |
| static Threading::Event | totalCompletionEvent |
Friends | |
| struct | CharacterJobContext |
| const bool | IsExpired (const CharacterContext::AnimationRuntime &runtime, const Timing::Time time) |
| const bool | IsInfinite (const CharacterContext::AnimationRuntime &runtime) |
| Timing::Tick | GetAbsoluteStopTime (const CharacterContext::AnimationRuntime &runtime) |
| void | EvalCharacter (SizeT totalJobs, SizeT groupSize, IndexT groupIndex, SizeT invocationOffset, void *ctx) |
Additional Inherited Members | |
| Static Protected Member Functions inherited from Graphics::GraphicsContext | |
| static void | InternalRegisterEntity (const Graphics::GraphicsEntityId id, Graphics::GraphicsContextState &&state) |
| static void | InternalDeregisterEntity (const Graphics::GraphicsEntityId id, Graphics::GraphicsContextState &&state) |
| template<class ID_ALLOCATOR> | |
| static void | InternalDefragment (ID_ALLOCATOR &allocator, Graphics::GraphicsContextState &&state) |
|
private |
| Characters::CharacterContext::CharacterContext | ( | ) |
constructor
|
virtual |
destructor
|
private |
|
inlinestaticprivate |
allocate a new slice for this context
|
static |
setup character context
|
static |
register anim sample mask, and return pointer
|
inlinestaticprivate |
deallocate a slice
|
static |
get the animation, invalid until it's loaded
|
static |
get anim sample mask by name
|
static |
perform a clip name lookup
|
static |
get the events the clips played on the tracks passed in the last update that finished, in the order of the tracks.
A clip fires the events at its start when it starts, and every time it passes them while looping, a clip that stops fires the ones up to its end. Paused clips fire none
|
static |
get the model space transforms of the joints in the last evaluated pose, one per joint of the skeleton
The scaled palette holds the joints in model space, the skinning palette has the inverse bind pose applied.
|
static |
get the clip playing on a track, InvalidIndex if none is
|
static |
get the skeleton, invalid until it's loaded
|
static |
get current time of animation
|
static |
get the time in the clip playing on a track in seconds, within its duration for looped clips, 0 if none is playing
The time is taken from the time since the clip started as of the last update, or the last seek, so a seek shows right away.
|
static |
check if any animation is playing
|
static |
check if the clip playing on a track is paused
|
static |
debug rendering
|
static |
pause animation on track, which doesn't reset time
|
static |
play animation on a specific track
|
static |
retrieve animation clip names and lengths
|
static |
seek animation to a certain time, clamps to length
|
static |
move the clip playing on a track to a time in it in seconds, it plays on from there, a paused one shows the pose at that time.
The clip's start is moved, the next update gets the time since the clip started from it.
The events between the time it was at and the time it's moved to aren't fired
That keeps the time a clip that isn't looped stops at in step with the time it's moved to
|
static |
set time factor for track
|
static |
set weight for track
|
static |
setup character context, assumes there is already a model attached, by loading a skeleton and animation resource
|
static |
if the entity's model is skinned, register and setup the entity as a character using the skeleton and animation packaged with the model (folder:file:ske and folder:file:ani), and play its first clip.
The packager writes a model's skeleton and animation under the model's name, so a skinned model that's placed without naming them (like a model asset dropped in the editor) still gets skinned.
Call when the model is loaded and the entity is observable. Returns false if the model isn't skinned or doesn't have both
Without a character the skinned shaders read a joint palette that's never uploaded
|
static |
stops all animations on all tracks
|
static |
stops all animations queued on track (and resets their time)
|
static |
runs before frame is updated
|
static |
run after frame
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
staticprivate |
|
static |
|
staticprivate |
|
staticprivate |
|
staticprivate |