diff --git a/examples/disableAvatarAnimations.js b/examples/disableAvatarAnimations.js new file mode 100644 index 0000000000..fc3415fb80 --- /dev/null +++ b/examples/disableAvatarAnimations.js @@ -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(); +}); + + diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index f388c275a6..ea713e2d96 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -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); } - diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index b15f812197..35caabe0f7 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -299,7 +299,7 @@ signals: void collisionWithEntity(const Collision& collision); void energyChanged(float newEnergy); void positionGoneTo(); - + void onLoadComplete(); private: diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 9e2ba46ddb..b3f5e30d40 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -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; diff --git a/libraries/animation/src/Rig.h b/libraries/animation/src/Rig.h index cbf4696723..897fa358e8 100644 --- a/libraries/animation/src/Rig.h +++ b/libraries/animation/src/Rig.h @@ -32,6 +32,7 @@ typedef std::shared_ptr RigPointer; // However only specific methods thread-safe. Noted below. class Rig : public QObject, public std::enable_shared_from_this { + 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();