mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
Moved hand animation control into grab script.
This commit is contained in:
parent
95f821d61a
commit
3e6ff0eb68
3 changed files with 88 additions and 5 deletions
|
@ -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) {
|
||||
|
|
|
@ -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" }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue