FIRE-30873: Tidy up code, more comments

move all lljoint stuff to llmotion derivative
master
Angeldark Raymaker 2024-10-13 13:34:12 +01:00
parent f46f2355f5
commit dcc57019fc
6 changed files with 123 additions and 32 deletions

View File

@ -58,7 +58,7 @@ typedef enum E_Columns
/// <summary>
/// A class containing the UI fiddling for the Poser Floater.
/// Please don't do LLJoint stuff here, fsposeranimator is the class for that.
/// Please don't do LLJoint stuff here, fsposingmotion (the LLMotion derivative) is the class for that.
/// </summary>
class FSFloaterPoser : public LLFloater
{
@ -265,8 +265,10 @@ class FSFloaterPoser : public LLFloater
FSPoserAnimator _poserAnimator;
/// <summary>
/// The supplied llJoint has a quaternion (and alternatively oily angles) describing its rotation.
/// This gets the kind of axial transformation required for viewing the joint's Euler angles on our UI.
/// The supplied Joint name has a quaternion describing its rotation.
/// This gets the kind of axial transformation required for 'easy' consumption of the joint's Euler angles on our UI.
/// This facilitates 'conceptual' conversion of Euler frame to up/down, left/right and roll and is rather subjective.
/// Thus, many of these 'conversions' are backed by values in the XML.
/// </summary>
/// <param name="jointName">The well-known name of the joint, eg: mChest.</param>
/// <returns>The axial translation so the oily angles make better sense in terms of up/down/left/right/roll.</returns>
@ -298,6 +300,7 @@ class FSFloaterPoser : public LLFloater
/// <summary>
/// The time when the last click of a button was made.
/// Utilized for controls needing a 'double click do' function.
/// </summary>
std::chrono::system_clock::time_point _timeLastClickedJointReset = std::chrono::system_clock::now();

View File

@ -45,11 +45,11 @@ bool FSPoserAnimator::isPosingAvatarJoint(LLVOAvatar *avatar, FSPoserJoint joint
if (posingMotion->isStopped())
return false;
LLJoint* avJoint = avatar->getJoint(JointKey::construct(joint.jointName()));
if (!avJoint)
FSPosingMotion::FSJointPose* jointPose = posingMotion->getJointPoseByJointName(joint.jointName());
if (!jointPose)
return false;
return posingMotion->currentlyPosingJoint(avJoint);
return posingMotion->currentlyPosingJoint(jointPose);
}
void FSPoserAnimator::setPosingAvatarJoint(LLVOAvatar *avatar, FSPoserJoint joint, bool shouldPose)
@ -68,14 +68,14 @@ void FSPoserAnimator::setPosingAvatarJoint(LLVOAvatar *avatar, FSPoserJoint join
if (posingMotion->isStopped())
return;
LLJoint* avJoint = avatar->getJoint(JointKey::construct(joint.jointName()));
if (!avJoint)
FSPosingMotion::FSJointPose* jointPose = posingMotion->getJointPoseByJointName(joint.jointName());
if (!jointPose)
return;
if (shouldPose)
posingMotion->addJointToState(avJoint);
posingMotion->addJointToState(jointPose);
else
posingMotion->removeJointFromState(avJoint);
posingMotion->removeJointFromState(jointPose);
}
void FSPoserAnimator::resetAvatarJoint(LLVOAvatar *avatar, FSPoserJoint joint)
@ -714,7 +714,7 @@ bool FSPoserAnimator::tryPosingAvatar(LLVOAvatar *avatar)
if (!isAvatarSafeToUse(avatar))
return false;
FSPosingMotion* posingMotion = createPosingMotion(avatar);
FSPosingMotion* posingMotion = findOrCreatePosingMotion(avatar);
if (!posingMotion)
return false;
@ -767,7 +767,7 @@ FSPosingMotion* FSPoserAnimator::getPosingMotion(LLVOAvatar* avatar)
return dynamic_cast<FSPosingMotion*>(avatar->findMotion(_avatarIdToRegisteredAnimationId[avatar->getID()]));
}
FSPosingMotion* FSPoserAnimator::createPosingMotion(LLVOAvatar* avatar)
FSPosingMotion* FSPoserAnimator::findOrCreatePosingMotion(LLVOAvatar* avatar)
{
FSPosingMotion* motion = getPosingMotion(avatar);
@ -871,11 +871,11 @@ bool FSPoserAnimator::writeBvhMotion(llofstream* fileStream, LLVOAvatar* avatar,
switch (joint->boneType())
{
case WHOLEAVATAR:
*fileStream << vec3ToXYZString(position) + " " + rotationToXZYString(rotation);
*fileStream << vec3ToXYZString(position) + " " + rotationToYZXString(rotation);
break;
default:
*fileStream << " " + rotationToXZYString(rotation);
*fileStream << " " + rotationToYZXString(rotation);
break;
}
@ -894,7 +894,7 @@ std::string FSPoserAnimator::vec3ToXYZString(LLVector3 val)
return f32ToString(val[VX]) + " " + f32ToString(val[VY]) + " " + f32ToString(val[VZ]);
}
std::string FSPoserAnimator::rotationToXZYString(LLVector3 val)
std::string FSPoserAnimator::rotationToYZXString(LLVector3 val)
{
return f32ToString(val[VY] * RAD_TO_DEG) + " " + f32ToString(val[VZ] * RAD_TO_DEG) + " " + f32ToString(val[VX] * RAD_TO_DEG);
}

View File

@ -433,7 +433,7 @@ public:
/// When a pose is created for the avatar, it is 'registered' with their character for use later on.
/// Thus we start & stop posing the same animation.
/// </remarks>
FSPosingMotion* createPosingMotion(LLVOAvatar* avatar);
FSPosingMotion* findOrCreatePosingMotion(LLVOAvatar* avatar);
/// <summary>
/// Gets the poser posing-motion for the supplied avatar.
@ -449,19 +449,51 @@ public:
/// <returns>True if the avatar is safe to manipulate, otherwise false.</returns>
bool isAvatarSafeToUse(LLVOAvatar* avatar);
/// <summary>
/// Recursively writes a fragment of a BVH file format representation of the supplied joint, then that joints BVH child(ren).
/// </summary>
/// <param name="fileStream">The stream to write the fragment to.</param>
/// <param name="avatar">The avatar owning the supplied joint.</param>
/// <param name="joint">The joint whose fragment should be written, and whose child(ren) will also be written.</param>
/// <param name="tabStops">The number of tab-stops to include for formatting purpose.</param>
/// <returns>True if the fragment wrote successfully, otherwise false.</returns>
bool writeBvhFragment(llofstream* fileStream, LLVOAvatar* avatar, const FSPoserJoint* joint, int tabStops);
/// <summary>
/// Writes a fragment of the 'single line' representing an animation frame within the BVH file respresenting the positions and/or rotations.
/// </summary>
/// <param name="fileStream">The stream to write the position and/or rotation to.</param>
/// <param name="avatar">The avatar owning the supplied joint.</param>
/// <param name="joint">The joint whose position and/or rotation should be written.</param>
/// <returns></returns>
bool writeBvhMotion(llofstream* fileStream, LLVOAvatar* avatar, const FSPoserJoint* joint);
/// <summary>
/// Converts an F32 to a nice string.
/// </summary>
std::string static f32ToString(F32 val);
/// <summary>
/// Generates a string with the supplied number of tab-chars.
/// </summary>
std::string static getTabs(int numOfTabstops);
std::string static rotationToXZYString(LLVector3 val);
/// <summary>
/// Transforms a rotation such that llbvhloader.cpp can resolve it to something vaguely approximating the supplied angle.
/// When I say vague, I mean, it's numbers, buuuuut.
/// </summary>
std::string static rotationToYZXString(LLVector3 val);
/// <summary>
/// Transforms the supplied vector into a string of three numbers, format suiting to writing into a BVH file.
/// </summary>
std::string static vec3ToXYZString(LLVector3 val);
/// <summary>
/// Maps the avatar's ID to the animation registered to them.
/// Thus we start/stop the same animation.
/// An avatar's animation exists so long as their session does, and there is consideration for renewal (like if they relog/crash).
/// Thus we start/stop the same animation, and get/set the same rotations etc.
/// Among other things this provides for the 'undo' of changes to shape/position when the poser stops animating someone.
/// An avatar's animation exists so long as their session does, and there is consideration for renewal (like if they relog/crash and their character is renewed).
/// Is static, so the animationId is not lost between sessions (such as when the UI floater is closed and reopened).
/// </summary>
static std::map<LLUUID, LLAssetID> _avatarIdToRegisteredAnimationId;

View File

@ -132,6 +132,42 @@ void FSPosingMotion::revertChangesToPositionsScalesAndCollisionVolumes()
}
}
bool FSPosingMotion::currentlyPosingJoint(FSJointPose* joint)
{
if (!joint)
return false;
LLJoint* avJoint = joint->getJointState()->getJoint();
if (!avJoint)
return false;
return currentlyPosingJoint(avJoint);
}
void FSPosingMotion::addJointToState(FSJointPose* joint)
{
if (!joint)
return;
LLJoint* avJoint = joint->getJointState()->getJoint();
if (!avJoint)
return;
setJointState(avJoint, POSER_JOINT_STATE);
}
void FSPosingMotion::removeJointFromState(FSJointPose* joint)
{
if (!joint)
return;
LLJoint* avJoint = joint->getJointState()->getJoint();
if (!avJoint)
return;
setJointState(avJoint, 0);
}
void FSPosingMotion::addJointToState(LLJoint* joint) { setJointState(joint, POSER_JOINT_STATE); }
void FSPosingMotion::removeJointFromState(LLJoint *joint) { setJointState(joint, 0); }

View File

@ -463,28 +463,23 @@ public:
// 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(LLJoint *joint);
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(LLJoint *joint);
/// <summary>
/// Queries whether the supplied joint is being animated.
/// </summary>
/// <param name="joint">The joint to query.</param>
bool currentlyPosingJoint(LLJoint *joint);
/// <summary>
/// Removes the current joint state, and adds a new one.
/// </summary>
void setJointState(LLJoint* joint, U32 state);
void removeJointFromState(FSJointPose* joint);
/// <summary>
/// Gets the joint pose by name.
@ -519,11 +514,34 @@ private:
/// </summary>
std::vector<FSJointPose> _jointPoses;
/// <summary>
/// Removes the current joint state, 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

View File

@ -95,6 +95,8 @@ width="565">
<string name="joint_transform_mTail4" translate="false">SWAP_YAW_AND_ROLL NEGATE_PITCH</string>
<string name="joint_transform_mTail5" translate="false">SWAP_YAW_AND_ROLL NEGATE_PITCH</string>
<string name="joint_transform_mTail6" translate="false">SWAP_YAW_AND_ROLL NEGATE_PITCH</string>
<string name="joint_transform_mFaceTongueBase" translate="false">SWAP_YAW_AND_ROLL NEGATE_PITCH</string>
<string name="joint_transform_mFaceTongueTip" translate="false">SWAP_YAW_AND_ROLL NEGATE_PITCH</string>
<!-- A matching bone name with the 'header_' prefix produces a sub-heading with the supplied name -->
<string name="header_mTorso" translate="false">Body</string>