From 3e6ff0eb68a92666b6df91b63908ffbca3756294 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 5 Jan 2016 19:56:56 -0800 Subject: [PATCH] Moved hand animation control into grab script. --- examples/controllers/handControllerGrab.js | 85 ++++++++++++++++++- .../defaultAvatar_full/avatar-animation.json | 6 +- libraries/animation/src/Rig.cpp | 2 + 3 files changed, 88 insertions(+), 5 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 5ba0ccd0ef..8095ebc81b 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -18,6 +18,7 @@ Script.include("../libraries/utils.js"); // add lines where the hand ray picking is happening // var WANT_DEBUG = false; +var WANT_DEBUG_STATE = true; // // these tune time-averaging and "on" value for analog trigger @@ -302,9 +303,84 @@ function MyController(hand) { this.ignoreIK = false; this.offsetPosition = Vec3.ZERO; this.offsetRotation = Quat.IDENTITY; + this.handIdleAlpha = 0; + + var HAND_IDLE_RAMP_ON_RATE = 0.1; + var HAND_IDLE_RAMP_OFF_RATE = 0.02; var _this = this; + var farGrabStates = [STATE_DISTANCE_HOLDING, STATE_CONTINUE_DISTANCE_HOLDING]; + var pointStates = [STATE_SEARCHING, STATE_EQUIP_SEARCHING, + STATE_NEAR_TRIGGER, STATE_CONTINUE_NEAR_TRIGGER, + STATE_FAR_TRIGGER, STATE_CONTINUE_FAR_TRIGGER]; + var idleStates = [STATE_OFF]; + + var propList = ["isLeftHandFarGrab", "isLeftHandPoint", "isLeftHandIdle", "isLeftHandGrab", + "isRightHandFarGrab", "isRightHandPoint", "isRightHandIdle", "isRightHandGrab"]; + + // hook up anim var handler + this.animHandlerId = MyAvatar.addAnimationStateHandler(function (props) { + var foundState = false; + var result = {}; + + var isHandPrefix = (_this.hand === RIGHT_HAND) ? "isRight" : "isLeft"; + var handPrefix = (_this.hand === RIGHT_HAND) ? "right" : "left"; + + /* + // far grab check + if (farGrabStates.indexOf(_this.state) != -1) { + result[isHandPrefix + "HandFarGrab"] = true; + foundState = true; + } else { + result[isHandPrefix + "HandFarGrab"] = false; + } + */ + + result[handPrefix + "HandGrabBlend"] = _this.triggerValue; + + // point check + if (pointStates.indexOf(_this.state) != -1) { + result[isHandPrefix + "HandPoint"] = true; + foundState = true; + } else { + result[isHandPrefix + "HandPoint"] = false; + } + + // idle check + if (idleStates.indexOf(_this.state) != -1) { + + // ramp down handIdleAlpha + if (_this.handIdleAlpha > HAND_IDLE_RAMP_OFF_RATE) { + _this.handIdleAlpha -= HAND_IDLE_RAMP_OFF_RATE; + } else { + _this.handIdleAlpha = 0; + } + result[isHandPrefix + "HandIdle"] = true; + foundState = true; + } else { + + // ramp up handIdleAlpha + if (_this.handIdleAlpha < 1 - HAND_IDLE_RAMP_ON_RATE) { + _this.handIdleAlpha += HAND_IDLE_RAMP_ON_RATE; + } else { + _this.handIdleAlpha = 1; + } + result[isHandPrefix + "HandIdle"] = false; + } + + result[handPrefix + "HandOverlayAlpha"] = _this.handIdleAlpha; + + // grab check + if (!foundState) { + result[isHandPrefix + "HandGrab"] = true; + } else { + result[isHandPrefix + "HandGrab"] = false; + } + + return result; + }, propList); + this.update = function() { this.updateSmoothedTrigger(); @@ -360,7 +436,7 @@ function MyController(hand) { }; this.setState = function(newState) { - if (WANT_DEBUG) { + if (WANT_DEBUG || WANT_DEBUG_STATE) { print("STATE: " + stateToName(this.state) + " --> " + stateToName(newState) + ", hand: " + this.hand); } this.state = newState; @@ -1686,7 +1762,7 @@ function MyController(hand) { }, angularVelocity: { x: 0, - y: 0, + y: 0, z: 0 } }) @@ -1713,6 +1789,11 @@ function MyController(hand) { Entities.deleteEntity(this.particleBeam); Entities.deleteEntity(this.spotLight); Entities.deleteEntity(this.pointLight); + + if (this.animHandlerId) { + MyAvatar.removeAnimationStateHandler(this.animHandlerId); + this.animHandlerId = undefined; + } }; this.activateEntity = function(entityID, grabbedProperties) { diff --git a/interface/resources/meshes/defaultAvatar_full/avatar-animation.json b/interface/resources/meshes/defaultAvatar_full/avatar-animation.json index d63942c510..39e8dbb84a 100644 --- a/interface/resources/meshes/defaultAvatar_full/avatar-animation.json +++ b/interface/resources/meshes/defaultAvatar_full/avatar-animation.json @@ -168,7 +168,7 @@ "interpDuration": 3, "transitions": [ { "var": "isRightHandIdle", "state": "rightHandIdle" }, - { "var": "isRightHandPoint_DISABLED", "state": "rightHandPointHold" } + { "var": "isRightHandPoint", "state": "rightHandPointHold" } ] } ] @@ -264,7 +264,7 @@ "data": { "alpha": 1.0, "boneSet": "leftHand", - "alphaVar" : "leftHandOverlay" + "alphaVar" : "leftHandOverlayAlpha" }, "children": [ { @@ -317,7 +317,7 @@ "interpDuration": 3, "transitions": [ { "var": "isLeftHandIdle", "state": "leftHandIdle" }, - { "var": "isLeftHandPoint_DISABLED", "state": "leftHandPointHold" } + { "var": "isLeftHandPoint", "state": "leftHandPointHold" } ] } ] diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index c6060d791a..8567945a87 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -981,6 +981,7 @@ void Rig::updateFromHandParameters(const HandParameters& params, float dt) { _animVars.set("rightHandType", (int)IKTarget::Type::HipsRelativeRotationAndPosition); } + /* // set leftHand grab vars _animVars.set("isLeftHandIdle", false); _animVars.set("isLeftHandPoint", false); @@ -1019,6 +1020,7 @@ void Rig::updateFromHandParameters(const HandParameters& params, float dt) { _rightHandOverlayAlpha = glm::clamp(_rightHandOverlayAlpha + (rampOut ? -1.0f : 1.0f) * OVERLAY_RAMP_OUT_SPEED * dt, 0.0f, 1.0f); _animVars.set("rightHandOverlayAlpha", _rightHandOverlayAlpha); _animVars.set("rightHandGrabBlend", params.rightTrigger); + */ } }