Merge pull request #7698 from hyperlogic/tony/avatar-on-load-complete-callback

Added MyAvatar onLoadComplete Callback
This commit is contained in:
Zach Pomerantz 2016-04-19 10:36:20 -07:00
commit fc61f85bf9
5 changed files with 61 additions and 4 deletions

View file

@ -0,0 +1,50 @@
//
// disableAvatarAnimations.js
// examples
//
// Copyright 2016 High Fidelity, Inc.
//
// When launched, it will replace all of the avatars animations with a single frame idle pose.
// full body IK and hand grabbing animations will still continue to function, but all other
// animations will be replaced.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
var skeletonModelURL = "";
var jointCount = 0;
var excludedRoles = ["rightHandGraspOpen", "rightHandGraspClosed", "leftHandGraspOpen", "leftHandGraspClosed"];
var IDLE_URL = "http://hifi-content.s3.amazonaws.com/ozan/dev/anim/standard_anims_160127/idle.fbx";
function overrideAnims() {
var roles = MyAvatar.getAnimationRoles();
var i, l = roles.length;
for (i = 0; i < l; i++) {
if (excludedRoles.indexOf(roles[i]) == -1) {
MyAvatar.overrideRoleAnimation(roles[i], IDLE_URL, 30, false, 1, 1);
}
}
}
function restoreAnims() {
var roles = MyAvatar.getAnimationRoles();
var i, l = roles.length;
for (i = 0; i < l; i++) {
if (excludedRoles.indexOf(roles[i]) == -1) {
MyAvatar.restoreRoleAnimation(roles[i]);
}
}
}
overrideAnims();
MyAvatar.onLoadComplete.connect(function () {
overrideAnims();
});
Script.scriptEnding.connect(function () {
restoreAnims();
});

View file

@ -198,6 +198,8 @@ MyAvatar::MyAvatar(RigPointer rig) :
_headData->setLookAtPosition(headData->getLookAtPosition());
}
});
connect(rig.get(), SIGNAL(onLoadComplete()), this, SIGNAL(onLoadComplete()));
}
MyAvatar::~MyAvatar() {
@ -1576,6 +1578,7 @@ glm::vec3 MyAvatar::applyKeyboardMotor(float deltaTime, const glm::vec3& localVe
float speedIncreaseFactor = 1.8f;
motorSpeed *= 1.0f + glm::clamp(deltaTime / speedGrowthTimescale , 0.0f, 1.0f) * speedIncreaseFactor;
const float maxBoostSpeed = getUniformScale() * MAX_BOOST_SPEED;
if (motorSpeed < maxBoostSpeed) {
// an active keyboard motor should never be slower than this
float boostCoefficient = (maxBoostSpeed - motorSpeed) / maxBoostSpeed;
@ -2090,7 +2093,7 @@ float MyAvatar::getAccelerationEnergy() {
int changeInVelocity = abs(velocity.length() - priorVelocity.length());
float changeInEnergy = priorVelocity.length() * changeInVelocity * AVATAR_MOVEMENT_ENERGY_CONSTANT;
priorVelocity = velocity;
return changeInEnergy;
}
@ -2112,4 +2115,3 @@ bool MyAvatar::didTeleport() {
lastPosition = pos;
return (changeInPosition.length() > MAX_AVATAR_MOVEMENT_PER_FRAME);
}

View file

@ -299,7 +299,7 @@ signals:
void collisionWithEntity(const Collision& collision);
void energyChanged(float newEnergy);
void positionGoneTo();
void onLoadComplete();
private:

View file

@ -1161,6 +1161,7 @@ void Rig::initAnimGraph(const QUrl& url) {
overrideAnimation(origState.url, origState.fps, origState.loop, origState.firstFrame, origState.lastFrame);
}
emit onLoadComplete();
});
connect(_animLoader.get(), &AnimNodeLoader::error, [url](int error, QString str) {
qCCritical(animation) << "Error loading" << url.toDisplayString() << "code = " << error << "str =" << str;

View file

@ -32,6 +32,7 @@ typedef std::shared_ptr<Rig> RigPointer;
// However only specific methods thread-safe. Noted below.
class Rig : public QObject, public std::enable_shared_from_this<Rig> {
Q_OBJECT
public:
struct StateHandler {
AnimVariantMap results;
@ -223,7 +224,10 @@ public:
const glm::mat4& getGeometryToRigTransform() const { return _geometryToRigTransform; }
protected:
signals:
void onLoadComplete();
protected:
bool isIndexValid(int index) const { return _animSkeleton && index >= 0 && index < _animSkeleton->getNumJoints(); }
void updateAnimationStateHandlers();
void applyOverridePoses();