phoenix-firestorm/indra/newview/fsposingmotion.h

181 lines
6.4 KiB
C++

/**
* @file fsposingmotion.h
* @brief Model for posing your (and other) avatar(s).
*
* $LicenseInfo:firstyear=2024&license=viewerlgpl$
* Phoenix Firestorm Viewer Source Code
* Copyright (c) 2024 Angeldark Raymaker @ Second Life
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef FS_POSINGMOTION_H
#define FS_POSINGMOTION_H
//-----------------------------------------------------------------------------
// Header files
//-----------------------------------------------------------------------------
#include "llmotion.h"
#include "fsjointpose.h"
#define MIN_REQUIRED_PIXEL_AREA_POSING 500.f
//-----------------------------------------------------------------------------
// class FSPosingMotion
//-----------------------------------------------------------------------------
class FSPosingMotion :
public LLMotion
{
public:
FSPosingMotion(const LLUUID &id);
virtual ~FSPosingMotion(){};
public:
static LLMotion *create(const LLUUID &id) { return new FSPosingMotion(id); }
virtual bool getLoop() { return true; }
virtual F32 getDuration() { return 0.0; }
virtual F32 getEaseInDuration() { return 0.0f; }
virtual F32 getEaseOutDuration() { return 0.5f; }
virtual LLJoint::JointPriority getPriority() { return LLJoint::ADDITIVE_PRIORITY; }
virtual LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
// called to determine when a motion should be activated/deactivated based on avatar pixel coverage
virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_POSING; }
// run-time (post constructor) initialization,
// called after parameters have been set
// must return true to indicate success and be available for activation
virtual LLMotionInitStatus onInitialize(LLCharacter *character);
// called when a motion is activated
// must return TRUE to indicate success, or else
// it will be deactivated
virtual bool onActivate();
// called per time step
// must return TRUE while it is active, and
// must return FALSE when the motion is completed.
virtual bool onUpdate(F32 time, U8 *joint_mask);
// called when a motion is deactivated
virtual void onDeactivate();
/// <summary>
/// Queries whether the supplied joint is being animated.
/// </summary>
/// <param name="joint">The joint to query.</param>
bool currentlyPosingJoint(FSJointPose* joint);
/// <summary>
/// Adds the supplied joint to the current animation-state.
/// </summary>
/// <param name="joint">The joint to animate.</param>
void addJointToState(FSJointPose* joint);
/// <summary>
/// Removes the supplied joint to the current animation-state.
/// </summary>
/// <param name="joint">The joint to stop animating.</param>
void removeJointFromState(FSJointPose* joint);
/// <summary>
/// Gets the joint pose by name.
/// </summary>
/// <param name="name">The name of the joint to get the pose for.</param>
/// <returns>The matching joint pose, if found, otherwise null.</returns>
FSJointPose* getJointPoseByJointName(const std::string& name);
/// <summary>
/// Gets the motion identity for this animation.
/// </summary>
/// <returns>The unique, per-session, per-character motion identity.</returns>
LLAssetID motionId() const { return mMotionID; }
/// <summary>
/// Gets whether all starting rotations are zero.
/// </summary>
/// <returns>True if all starting rotations are zero, otherwise false.</returns>
bool allStartingRotationsAreZero() const;
/// <summary>
/// Sets all of the non-Collision Volume rotations to zero.
/// </summary>
void setAllRotationsToZero();
private:
/// <summary>
/// The kind of joint state this animation is concerned with changing.
/// </summary>
static const U32 POSER_JOINT_STATE = LLJointState::POS | LLJointState::ROT | LLJointState::SCALE;
/// <summary>
/// The unique identity of this motion.
/// </summary>
LLAssetID mMotionID;
/// <summary>
/// The amount of time, in seconds, we use for transitioning between one animation-state to another; this affects the 'fluidity'
/// of motion between changes to a joint.
/// Use caution making this larger than the subjective amount of time between adjusting a joint and then choosing to use 'undo' it.
/// Undo-function waits a similar amount of time after the last user-incited joint change to add a 'restore point'.
/// </summary>
const F32 mInterpolationTime = 0.25f;
/// <summary>
/// The collection of joint poses this motion uses to pose the joints of the character this is animating.
/// </summary>
std::vector<FSJointPose> mJointPoses;
/// <summary>
/// Removes the current joint state for the supplied joint, and adds a new one.
/// </summary>
void setJointState(LLJoint* joint, U32 state);
/// <summary>
/// Because changes to positions, scales and collision volumes do not end when the animation stops,
/// this is required to revert them manually.
/// </summary>
void revertChangesToPositionsScalesAndCollisionVolumes();
/// <summary>
/// Queries whether the supplied joint is being animated.
/// </summary>
/// <param name="joint">The joint to query.</param>
bool currentlyPosingJoint(LLJoint* joint);
/// <summary>
/// Adds the supplied joint to the current animation-state.
/// </summary>
/// <param name="joint">The joint to animate.</param>
void addJointToState(LLJoint* joint);
/// <summary>
/// Removes the supplied joint to the current animation-state.
/// </summary>
/// <param name="joint">The joint to stop animating.</param>
void removeJointFromState(LLJoint* joint);
};
#endif // FS_POSINGMOTION_H