mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:12:53 +02:00
Hooked up fly animation to json and Rig
This commit is contained in:
parent
9ec2cf1ab9
commit
7af20e90c8
6 changed files with 98 additions and 40 deletions
|
@ -246,7 +246,8 @@
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" },
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
{ "var": "isAway", "state": "awayIntro" }
|
{ "var": "isAway", "state": "awayIntro" },
|
||||||
|
{ "var": "isFlying", "state": "fly" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -261,7 +262,8 @@
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" },
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
{ "var": "isAway", "state": "awayIntro" }
|
{ "var": "isAway", "state": "awayIntro" },
|
||||||
|
{ "var": "isFlying", "state": "fly" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -275,7 +277,8 @@
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" },
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
{ "var": "isAway", "state": "awayIntro" }
|
{ "var": "isAway", "state": "awayIntro" },
|
||||||
|
{ "var": "isFlying", "state": "fly" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -289,7 +292,8 @@
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" },
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
{ "var": "isAway", "state": "awayIntro" }
|
{ "var": "isAway", "state": "awayIntro" },
|
||||||
|
{ "var": "isFlying", "state": "fly" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -303,7 +307,8 @@
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" },
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
{ "var": "isAway", "state": "awayIntro" }
|
{ "var": "isAway", "state": "awayIntro" },
|
||||||
|
{ "var": "isFlying", "state": "fly" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -317,7 +322,8 @@
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" },
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
{ "var": "isAway", "state": "awayIntro" }
|
{ "var": "isAway", "state": "awayIntro" },
|
||||||
|
{ "var": "isFlying", "state": "fly" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -331,7 +337,8 @@
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningLeft", "state": "turnLeft" },
|
{ "var": "isTurningLeft", "state": "turnLeft" },
|
||||||
{ "var": "isAway", "state": "awayIntro" }
|
{ "var": "isAway", "state": "awayIntro" },
|
||||||
|
{ "var": "isFlying", "state": "fly" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -345,7 +352,8 @@
|
||||||
{ "var": "isMovingRight", "state": "strafeRight" },
|
{ "var": "isMovingRight", "state": "strafeRight" },
|
||||||
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
{ "var": "isMovingLeft", "state": "strafeLeft" },
|
||||||
{ "var": "isTurningRight", "state": "turnRight" },
|
{ "var": "isTurningRight", "state": "turnRight" },
|
||||||
{ "var": "isAway", "state": "awayIntro" }
|
{ "var": "isAway", "state": "awayIntro" },
|
||||||
|
{ "var": "isFlying", "state": "fly" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -371,6 +379,14 @@
|
||||||
"transitions": [
|
"transitions": [
|
||||||
{ "var": "awayOutroOnDone", "state": "idle" }
|
{ "var": "awayOutroOnDone", "state": "idle" }
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "fly",
|
||||||
|
"interpTarget": 6,
|
||||||
|
"interpDuration": 6,
|
||||||
|
"transitions": [
|
||||||
|
{ "var": "isNotFlying", "state": "idle" }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -657,6 +673,18 @@
|
||||||
"loopFlag": false
|
"loopFlag": false
|
||||||
},
|
},
|
||||||
"children": []
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "fly",
|
||||||
|
"type": "clip",
|
||||||
|
"data": {
|
||||||
|
"url": "https://hifi-content.s3.amazonaws.com/ozan/dev/anim/standard_anims/fly.fbx",
|
||||||
|
"startFrame": 1.0,
|
||||||
|
"endFrame": 80.0,
|
||||||
|
"timeScale": 1.0,
|
||||||
|
"loopFlag": true
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1538,9 +1538,7 @@ void MyAvatar::updatePosition(float deltaTime) {
|
||||||
// rotate velocity into camera frame
|
// rotate velocity into camera frame
|
||||||
glm::quat rotation = getHead()->getCameraOrientation();
|
glm::quat rotation = getHead()->getCameraOrientation();
|
||||||
glm::vec3 localVelocity = glm::inverse(rotation) * _targetVelocity;
|
glm::vec3 localVelocity = glm::inverse(rotation) * _targetVelocity;
|
||||||
|
glm::vec3 newLocalVelocity = applyKeyboardMotor(deltaTime, localVelocity, isHovering());
|
||||||
bool isHovering = _characterController.isHovering();
|
|
||||||
glm::vec3 newLocalVelocity = applyKeyboardMotor(deltaTime, localVelocity, isHovering);
|
|
||||||
newLocalVelocity = applyScriptedMotor(deltaTime, newLocalVelocity);
|
newLocalVelocity = applyScriptedMotor(deltaTime, newLocalVelocity);
|
||||||
|
|
||||||
// rotate back into world-frame
|
// rotate back into world-frame
|
||||||
|
@ -1636,6 +1634,10 @@ void MyAvatar::doUpdateBillboard() {
|
||||||
sendBillboardPacket();
|
sendBillboardPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MyAvatar::isHovering() const {
|
||||||
|
return _characterController.isHovering();
|
||||||
|
}
|
||||||
|
|
||||||
void MyAvatar::increaseSize() {
|
void MyAvatar::increaseSize() {
|
||||||
if ((1.0f + SCALING_RATIO) * _targetScale < MAX_AVATAR_SCALE) {
|
if ((1.0f + SCALING_RATIO) * _targetScale < MAX_AVATAR_SCALE) {
|
||||||
_targetScale *= (1.0f + SCALING_RATIO);
|
_targetScale *= (1.0f + SCALING_RATIO);
|
||||||
|
|
|
@ -231,6 +231,8 @@ public:
|
||||||
glm::quat getCustomListenOrientation() { return _customListenOrientation; }
|
glm::quat getCustomListenOrientation() { return _customListenOrientation; }
|
||||||
void setCustomListenOrientation(glm::quat customListenOrientation) { _customListenOrientation = customListenOrientation; }
|
void setCustomListenOrientation(glm::quat customListenOrientation) { _customListenOrientation = customListenOrientation; }
|
||||||
|
|
||||||
|
bool isHovering() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void increaseSize();
|
void increaseSize();
|
||||||
void decreaseSize();
|
void decreaseSize();
|
||||||
|
|
|
@ -133,7 +133,7 @@ void SkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
||||||
|
|
||||||
_rig->updateFromHandParameters(handParams, deltaTime);
|
_rig->updateFromHandParameters(handParams, deltaTime);
|
||||||
|
|
||||||
_rig->computeMotionAnimationState(deltaTime, _owningAvatar->getPosition(), _owningAvatar->getVelocity(), _owningAvatar->getOrientation());
|
_rig->computeMotionAnimationState(deltaTime, _owningAvatar->getPosition(), _owningAvatar->getVelocity(), _owningAvatar->getOrientation(), myAvatar->isHovering());
|
||||||
|
|
||||||
// evaluate AnimGraph animation and update jointStates.
|
// evaluate AnimGraph animation and update jointStates.
|
||||||
Model::updateRig(deltaTime, parentTransform);
|
Model::updateRig(deltaTime, parentTransform);
|
||||||
|
|
|
@ -500,7 +500,7 @@ static const std::vector<float> FORWARD_SPEEDS = { 0.4f, 1.4f, 4.5f }; // m/s
|
||||||
static const std::vector<float> BACKWARD_SPEEDS = { 0.6f, 1.45f }; // m/s
|
static const std::vector<float> BACKWARD_SPEEDS = { 0.6f, 1.45f }; // m/s
|
||||||
static const std::vector<float> LATERAL_SPEEDS = { 0.2f, 0.65f }; // m/s
|
static const std::vector<float> LATERAL_SPEEDS = { 0.2f, 0.65f }; // m/s
|
||||||
|
|
||||||
void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation) {
|
void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation, bool isHovering) {
|
||||||
|
|
||||||
glm::vec3 front = worldRotation * IDENTITY_FRONT;
|
glm::vec3 front = worldRotation * IDENTITY_FRONT;
|
||||||
|
|
||||||
|
@ -568,36 +568,43 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
const float TURN_ENTER_SPEED_THRESHOLD = 0.5f; // rad/sec
|
const float TURN_ENTER_SPEED_THRESHOLD = 0.5f; // rad/sec
|
||||||
const float TURN_EXIT_SPEED_THRESHOLD = 0.2f; // rad/sec
|
const float TURN_EXIT_SPEED_THRESHOLD = 0.2f; // rad/sec
|
||||||
|
|
||||||
float moveThresh;
|
if (isHovering) {
|
||||||
if (_state != RigRole::Move) {
|
if (_desiredState != RigRole::Hover) {
|
||||||
moveThresh = MOVE_ENTER_SPEED_THRESHOLD;
|
|
||||||
} else {
|
|
||||||
moveThresh = MOVE_EXIT_SPEED_THRESHOLD;
|
|
||||||
}
|
|
||||||
|
|
||||||
float turnThresh;
|
|
||||||
if (_state != RigRole::Turn) {
|
|
||||||
turnThresh = TURN_ENTER_SPEED_THRESHOLD;
|
|
||||||
} else {
|
|
||||||
turnThresh = TURN_EXIT_SPEED_THRESHOLD;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glm::length(localVel) > moveThresh) {
|
|
||||||
if (_desiredState != RigRole::Move) {
|
|
||||||
_desiredStateAge = 0.0f;
|
_desiredStateAge = 0.0f;
|
||||||
}
|
}
|
||||||
_desiredState = RigRole::Move;
|
_desiredState = RigRole::Hover;
|
||||||
} else {
|
} else {
|
||||||
if (fabsf(turningSpeed) > turnThresh) {
|
float moveThresh;
|
||||||
if (_desiredState != RigRole::Turn) {
|
if (_state != RigRole::Move) {
|
||||||
|
moveThresh = MOVE_ENTER_SPEED_THRESHOLD;
|
||||||
|
} else {
|
||||||
|
moveThresh = MOVE_EXIT_SPEED_THRESHOLD;
|
||||||
|
}
|
||||||
|
|
||||||
|
float turnThresh;
|
||||||
|
if (_state != RigRole::Turn) {
|
||||||
|
turnThresh = TURN_ENTER_SPEED_THRESHOLD;
|
||||||
|
} else {
|
||||||
|
turnThresh = TURN_EXIT_SPEED_THRESHOLD;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glm::length(localVel) > moveThresh) {
|
||||||
|
if (_desiredState != RigRole::Move) {
|
||||||
_desiredStateAge = 0.0f;
|
_desiredStateAge = 0.0f;
|
||||||
}
|
}
|
||||||
_desiredState = RigRole::Turn;
|
_desiredState = RigRole::Move;
|
||||||
} else { // idle
|
} else {
|
||||||
if (_desiredState != RigRole::Idle) {
|
if (fabsf(turningSpeed) > turnThresh) {
|
||||||
_desiredStateAge = 0.0f;
|
if (_desiredState != RigRole::Turn) {
|
||||||
|
_desiredStateAge = 0.0f;
|
||||||
|
}
|
||||||
|
_desiredState = RigRole::Turn;
|
||||||
|
} else { // idle
|
||||||
|
if (_desiredState != RigRole::Idle) {
|
||||||
|
_desiredStateAge = 0.0f;
|
||||||
|
}
|
||||||
|
_desiredState = RigRole::Idle;
|
||||||
}
|
}
|
||||||
_desiredState = RigRole::Idle;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,6 +656,8 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
_animVars.set("isTurningLeft", false);
|
_animVars.set("isTurningLeft", false);
|
||||||
_animVars.set("isTurningRight", false);
|
_animVars.set("isTurningRight", false);
|
||||||
_animVars.set("isNotTurning", true);
|
_animVars.set("isNotTurning", true);
|
||||||
|
_animVars.set("isFlying", false);
|
||||||
|
_animVars.set("isNotFlying", true);
|
||||||
}
|
}
|
||||||
} else if (_state == RigRole::Turn) {
|
} else if (_state == RigRole::Turn) {
|
||||||
if (turningSpeed > 0.0f) {
|
if (turningSpeed > 0.0f) {
|
||||||
|
@ -667,7 +676,9 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
_animVars.set("isMovingRight", false);
|
_animVars.set("isMovingRight", false);
|
||||||
_animVars.set("isMovingLeft", false);
|
_animVars.set("isMovingLeft", false);
|
||||||
_animVars.set("isNotMoving", true);
|
_animVars.set("isNotMoving", true);
|
||||||
} else {
|
_animVars.set("isFlying", false);
|
||||||
|
_animVars.set("isNotFlying", true);
|
||||||
|
} else if (_state == RigRole::Idle ) {
|
||||||
// default anim vars to notMoving and notTurning
|
// default anim vars to notMoving and notTurning
|
||||||
_animVars.set("isMovingForward", false);
|
_animVars.set("isMovingForward", false);
|
||||||
_animVars.set("isMovingBackward", false);
|
_animVars.set("isMovingBackward", false);
|
||||||
|
@ -677,6 +688,20 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
|
||||||
_animVars.set("isTurningLeft", false);
|
_animVars.set("isTurningLeft", false);
|
||||||
_animVars.set("isTurningRight", false);
|
_animVars.set("isTurningRight", false);
|
||||||
_animVars.set("isNotTurning", true);
|
_animVars.set("isNotTurning", true);
|
||||||
|
_animVars.set("isFlying", false);
|
||||||
|
_animVars.set("isNotFlying", true);
|
||||||
|
} else {
|
||||||
|
// flying.
|
||||||
|
_animVars.set("isMovingForward", false);
|
||||||
|
_animVars.set("isMovingBackward", false);
|
||||||
|
_animVars.set("isMovingLeft", false);
|
||||||
|
_animVars.set("isMovingRight", false);
|
||||||
|
_animVars.set("isNotMoving", true);
|
||||||
|
_animVars.set("isTurningLeft", false);
|
||||||
|
_animVars.set("isTurningRight", false);
|
||||||
|
_animVars.set("isNotTurning", true);
|
||||||
|
_animVars.set("isFlying", true);
|
||||||
|
_animVars.set("isNotFlying", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
t += deltaTime;
|
t += deltaTime;
|
||||||
|
|
|
@ -141,7 +141,7 @@ public:
|
||||||
glm::mat4 getJointTransform(int jointIndex) const;
|
glm::mat4 getJointTransform(int jointIndex) const;
|
||||||
|
|
||||||
// Start or stop animations as needed.
|
// Start or stop animations as needed.
|
||||||
void computeMotionAnimationState(float deltaTime, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation);
|
void computeMotionAnimationState(float deltaTime, const glm::vec3& worldPosition, const glm::vec3& worldVelocity, const glm::quat& worldRotation, bool isHovering);
|
||||||
|
|
||||||
// Regardless of who started the animations or how many, update the joints.
|
// Regardless of who started the animations or how many, update the joints.
|
||||||
void updateAnimations(float deltaTime, glm::mat4 rootTransform);
|
void updateAnimations(float deltaTime, glm::mat4 rootTransform);
|
||||||
|
@ -268,7 +268,8 @@ public:
|
||||||
enum class RigRole {
|
enum class RigRole {
|
||||||
Idle = 0,
|
Idle = 0,
|
||||||
Turn,
|
Turn,
|
||||||
Move
|
Move,
|
||||||
|
Hover
|
||||||
};
|
};
|
||||||
RigRole _state { RigRole::Idle };
|
RigRole _state { RigRole::Idle };
|
||||||
RigRole _desiredState { RigRole::Idle };
|
RigRole _desiredState { RigRole::Idle };
|
||||||
|
|
Loading…
Reference in a new issue