walk.js 1.25 comments removal

This commit is contained in:
DaveDubUK 2015-06-22 17:51:49 +07:00
parent 54608b9cb3
commit 10d981e6d5
4 changed files with 61 additions and 71 deletions

File diff suppressed because one or more lines are too long

View file

@ -5,7 +5,7 @@
// Created by David Wooldridge, June 2015 // Created by David Wooldridge, June 2015
// Copyright © 2014 - 2015 High Fidelity, Inc. // Copyright © 2014 - 2015 High Fidelity, Inc.
// //
// Exposes API for use by walk.js version 1.2+. // Exposes API for use by walk.js version 1.2+.
// //
// Editing tools for animation data files available here: https://github.com/DaveDubUK/walkTools // Editing tools for animation data files available here: https://github.com/DaveDubUK/walkTools
// //
@ -58,7 +58,7 @@ Avatar = function() {
} }
} }
this.setAnimationSet('standardMale'); this.setAnimationSet('standardMale');
this.startTime = new Date().getTime(); this.startTime = new Date().getTime();
// calibration // calibration
@ -81,8 +81,8 @@ Avatar = function() {
} }
} }
this.calibration.hipsToFeet = MyAvatar.getJointPosition("Hips").y - MyAvatar.getJointPosition("RightToeBase").y; this.calibration.hipsToFeet = MyAvatar.getJointPosition("Hips").y - MyAvatar.getJointPosition("RightToeBase").y;
// maybe measuring before Blender pre-rotations have been applied? // maybe measuring before Blender pre-rotations have been applied?
if (this.calibration.hipsToFeet < 0 && this.isBlenderExport) { if (this.calibration.hipsToFeet < 0 && this.isBlenderExport) {
this.calibration.hipsToFeet *= -1; this.calibration.hipsToFeet *= -1;
} }
@ -189,12 +189,12 @@ Motion = function() {
this.lastYaw = Quat.safeEulerAngles(MyAvatar.orientation).y; this.lastYaw = Quat.safeEulerAngles(MyAvatar.orientation).y;
this.lastYawDelta = 0; this.lastYawDelta = 0;
this.lastYawDeltaAcceleration = 0; this.lastYawDeltaAcceleration = 0;
// Quat.safeEulerAngles(MyAvatar.orientation).y tends to repeat values between frames, so values are filtered // Quat.safeEulerAngles(MyAvatar.orientation).y tends to repeat values between frames, so values are filtered
var YAW_SMOOTHING = 22; var YAW_SMOOTHING = 22;
this.yawFilter = filter.createAveragingFilter(YAW_SMOOTHING); //createButterworthFilter(); // this.yawFilter = filter.createAveragingFilter(YAW_SMOOTHING);
this.deltaTimeFilter = filter.createAveragingFilter(YAW_SMOOTHING); //createButterworthFilter(); // this.deltaTimeFilter = filter.createAveragingFilter(YAW_SMOOTHING);
this.yawDeltaAccelerationFilter = filter.createAveragingFilter(YAW_SMOOTHING); //createButterworthFilter(); // this.yawDeltaAccelerationFilter = filter.createAveragingFilter(YAW_SMOOTHING);
// assess locomotion state // assess locomotion state
this.assess = function(deltaTime) { this.assess = function(deltaTime) {
@ -298,16 +298,16 @@ Motion = function() {
var surfaceMotion = isOnSurface && this.isMoving; var surfaceMotion = isOnSurface && this.isMoving;
var acceleratingAndAirborne = this.isAccelerating && !isOnSurface; var acceleratingAndAirborne = this.isAccelerating && !isOnSurface;
var goingTooFastToWalk = !this.isDecelerating && this.isFlyingSpeed; var goingTooFastToWalk = !this.isDecelerating && this.isFlyingSpeed;
var movingDirectlyUpOrDown = (this.direction === UP || this.direction === DOWN) // && lateralVelocity < MOVE_THRESHOLD; var movingDirectlyUpOrDown = (this.direction === UP || this.direction === DOWN)
var maybeBouncing = Math.abs(this.acceleration.y > BOUNCE_ACCELERATION_THRESHOLD) ? true : false; var maybeBouncing = Math.abs(this.acceleration.y > BOUNCE_ACCELERATION_THRESHOLD) ? true : false;
// we now have enough information to set the appropriate locomotion mode // we now have enough information to set the appropriate locomotion mode
switch (this.state) { switch (this.state) {
case STATIC: case STATIC:
var staticToAirMotion = this.isMoving && (acceleratingAndAirborne || goingTooFastToWalk || var staticToAirMotion = this.isMoving && (acceleratingAndAirborne || goingTooFastToWalk ||
(movingDirectlyUpOrDown && !isOnSurface)); (movingDirectlyUpOrDown && !isOnSurface));
var staticToSurfaceMotion = surfaceMotion && !motion.isComingToHalt && !movingDirectlyUpOrDown && var staticToSurfaceMotion = surfaceMotion && !motion.isComingToHalt && !movingDirectlyUpOrDown &&
!this.isDecelerating && lateralVelocity > MOVE_THRESHOLD; !this.isDecelerating && lateralVelocity > MOVE_THRESHOLD;
if (staticToAirMotion) { if (staticToAirMotion) {
this.nextState = AIR_MOTION; this.nextState = AIR_MOTION;
} else if (staticToSurfaceMotion) { } else if (staticToSurfaceMotion) {
@ -318,8 +318,8 @@ Motion = function() {
break; break;
case SURFACE_MOTION: case SURFACE_MOTION:
var surfaceMotionToStatic = !this.isMoving || var surfaceMotionToStatic = !this.isMoving ||
(this.isDecelerating && motion.lastDirection !== DOWN && surfaceMotion && (this.isDecelerating && motion.lastDirection !== DOWN && surfaceMotion &&
!maybeBouncing && Vec3.length(this.velocity) < MAX_WALK_SPEED); !maybeBouncing && Vec3.length(this.velocity) < MAX_WALK_SPEED);
var surfaceMotionToAirMotion = (acceleratingAndAirborne || goingTooFastToWalk || movingDirectlyUpOrDown) && var surfaceMotionToAirMotion = (acceleratingAndAirborne || goingTooFastToWalk || movingDirectlyUpOrDown) &&
(!surfaceMotion && isTakingOff) || (!surfaceMotion && isTakingOff) ||
@ -339,8 +339,7 @@ Motion = function() {
case AIR_MOTION: case AIR_MOTION:
var airMotionToSurfaceMotion = (surfaceMotion || aboutToLand) && !movingDirectlyUpOrDown; var airMotionToSurfaceMotion = (surfaceMotion || aboutToLand) && !movingDirectlyUpOrDown;
var airMotionToStatic = !this.isMoving && this.direction === this.lastDirection; //|| var airMotionToStatic = !this.isMoving && this.direction === this.lastDirection;
//this.isDeceleratingFast || isOnSurface;
if (airMotionToSurfaceMotion){ if (airMotionToSurfaceMotion){
this.nextState = SURFACE_MOTION; this.nextState = SURFACE_MOTION;
} else if (airMotionToStatic) { } else if (airMotionToStatic) {
@ -429,7 +428,7 @@ animationOperations = (function() {
} else { } else {
jointTranslations.z = joint.thrust * Math.sin jointTranslations.z = joint.thrust * Math.sin
(filter.degToRad(modifiers.thrustFrequencyMultiplier * ft + joint.thrustPhase)) + joint.thrustOffset; (filter.degToRad(modifiers.thrustFrequencyMultiplier * ft + joint.thrustPhase)) + joint.thrustOffset;
} }
return jointTranslations; return jointTranslations;
}, },
@ -621,7 +620,7 @@ TransitionParameters = function() {
// constructor for animation Transition // constructor for animation Transition
Transition = function(nextAnimation, lastAnimation, lastTransition, playTransitionReachPoses) { Transition = function(nextAnimation, lastAnimation, lastTransition, playTransitionReachPoses) {
//if (isDefined(lastAnimation) && isDefined(nextAnimation)) walkTools.toLog(lastAnimation.name + ' to '+ nextAnimation.name + ': started');
if (playTransitionReachPoses === undefined) { if (playTransitionReachPoses === undefined) {
playTransitionReachPoses = true; playTransitionReachPoses = true;
} }
@ -720,7 +719,6 @@ Transition = function(nextAnimation, lastAnimation, lastTransition, playTransiti
if (this.lastTransition !== nullTransition) { if (this.lastTransition !== nullTransition) {
this.lastTransition.incrementRecursion(); this.lastTransition.incrementRecursion();
} }
// end of transition initialisation. begin Transition public methods // end of transition initialisation. begin Transition public methods
@ -794,7 +792,6 @@ Transition = function(nextAnimation, lastAnimation, lastTransition, playTransiti
// update transition progress // update transition progress
this.filteredProgress = filter.bezier(this.progress, this.parameters.easingLower, this.parameters.easingUpper); this.filteredProgress = filter.bezier(this.progress, this.parameters.easingLower, this.parameters.easingUpper);
//if (this.progress >= 1) walkTools.toLog(this.lastAnimation.name + ' to '+ this.nextAnimation.name + ': done');
return this.progress >= 1 ? TRANSITION_COMPLETE : false; return this.progress >= 1 ? TRANSITION_COMPLETE : false;
}; };

View file

@ -118,7 +118,6 @@ WaveSynth = function(waveShape, numHarmonics, smoothing) {
HarmonicsFilter = function(magnitudes, phaseAngles) { HarmonicsFilter = function(magnitudes, phaseAngles) {
this.magnitudes = magnitudes; this.magnitudes = magnitudes;
this.phaseAngles = phaseAngles; this.phaseAngles = phaseAngles;
this.calculate = function(twoPiFT) { this.calculate = function(twoPiFT) {
var harmonics = 0; var harmonics = 0;
var numHarmonics = magnitudes.length; var numHarmonics = magnitudes.length;
@ -155,7 +154,7 @@ filter = (function() {
}, },
// these filters need instantiating, as they hold arrays of previous values // these filters need instantiating, as they hold arrays of previous values
// simple averaging (LP) filter for damping / smoothing // simple averaging (LP) filter for damping / smoothing
createAveragingFilter: function(length) { createAveragingFilter: function(length) {
var newAveragingFilter = new AveragingFilter(length); var newAveragingFilter = new AveragingFilter(length);
@ -181,7 +180,7 @@ filter = (function() {
}, },
// the following filters do not need separate instances, as they hold no previous values // the following filters do not need separate instances, as they hold no previous values
// Bezier response curve shaping for more natural transitions // Bezier response curve shaping for more natural transitions
bezier: function(input, C2, C3) { bezier: function(input, C2, C3) {
// based on script by Dan Pupius (www.pupius.net) http://13thparallel.com/archive/bezier-curves/ // based on script by Dan Pupius (www.pupius.net) http://13thparallel.com/archive/bezier-curves/

View file

@ -3,10 +3,10 @@
// version 1.25 // version 1.25
// //
// Created by David Wooldridge, June 2015 // Created by David Wooldridge, June 2015
// Copyright © 2014 - 2015 High Fidelity, Inc. // Copyright © 2014 - 2015 High Fidelity, Inc.
// //
// Animates an avatar using procedural animation techniques. // Animates an avatar using procedural animation techniques.
// //
// Editing tools for animation data files available here: https://github.com/DaveDubUK/walkTools // Editing tools for animation data files available here: https://github.com/DaveDubUK/walkTools
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
@ -67,7 +67,7 @@ Script.include([
pathToAssets + "walkAssets.js" pathToAssets + "walkAssets.js"
]); ]);
// construct Avatar and Motion // construct Avatar and Motion
var avatar = new Avatar(); var avatar = new Avatar();
var motion = new Motion(); var motion = new Motion();
@ -92,7 +92,7 @@ var flyBackwardFilter = filter.createAveragingFilter(FLY_BLEND_DAMPING);
Script.update.connect(function(deltaTime) { Script.update.connect(function(deltaTime) {
if (motion.isLive) { if (motion.isLive) {
// assess current locomotion state // assess current locomotion state
motion.assess(deltaTime); motion.assess(deltaTime);
@ -109,7 +109,7 @@ Script.update.connect(function(deltaTime) {
renderMotion(); renderMotion();
// record this frame's parameters // record this frame's parameters
motion.saveHistory(); motion.saveHistory();
} }
}); });
@ -117,29 +117,29 @@ Script.update.connect(function(deltaTime) {
function setTransition(nextAnimation, playTransitionReachPoses) { function setTransition(nextAnimation, playTransitionReachPoses) {
var lastTransition = motion.currentTransition; var lastTransition = motion.currentTransition;
var lastAnimation = avatar.currentAnimation; var lastAnimation = avatar.currentAnimation;
// if already transitioning from a blended walk need to maintain the previous walk's direction // if already transitioning from a blended walk need to maintain the previous walk's direction
if (isDefined(lastAnimation.lastDirection)) { if (isDefined(lastAnimation.lastDirection)) {
switch(lastAnimation.lastDirection) { switch(lastAnimation.lastDirection) {
case FORWARDS: case FORWARDS:
lastAnimation = avatar.selectedWalk; lastAnimation = avatar.selectedWalk;
break; break;
case BACKWARDS: case BACKWARDS:
lastAnimation = avatar.selectedWalkBackwards; lastAnimation = avatar.selectedWalkBackwards;
break; break;
case LEFT: case LEFT:
lastAnimation = avatar.selectedSideStepLeft; lastAnimation = avatar.selectedSideStepLeft;
break; break;
case RIGHT: case RIGHT:
lastAnimation = avatar.selectedSideStepRight; lastAnimation = avatar.selectedSideStepRight;
break; break;
} }
} }
motion.currentTransition = new Transition(nextAnimation, lastAnimation, lastTransition, playTransitionReachPoses); motion.currentTransition = new Transition(nextAnimation, lastAnimation, lastTransition, playTransitionReachPoses);
avatar.currentAnimation = nextAnimation; avatar.currentAnimation = nextAnimation;
@ -156,10 +156,10 @@ function selectAnimation() {
// select appropriate animation. create transitions where appropriate // select appropriate animation. create transitions where appropriate
switch (motion.nextState) { switch (motion.nextState) {
case STATIC: { case STATIC: {
if (avatar.distanceFromSurface < ON_SURFACE_THRESHOLD && if (avatar.distanceFromSurface < ON_SURFACE_THRESHOLD &&
avatar.currentAnimation !== avatar.selectedIdle) { avatar.currentAnimation !== avatar.selectedIdle) {
setTransition(avatar.selectedIdle, playTransitionReachPoses); setTransition(avatar.selectedIdle, playTransitionReachPoses);
} else if (!(avatar.distanceFromSurface < ON_SURFACE_THRESHOLD) && } else if (!(avatar.distanceFromSurface < ON_SURFACE_THRESHOLD) &&
avatar.currentAnimation !== avatar.selectedHover) { avatar.currentAnimation !== avatar.selectedHover) {
setTransition(avatar.selectedHover, playTransitionReachPoses); setTransition(avatar.selectedHover, playTransitionReachPoses);
} }
@ -172,13 +172,13 @@ function selectAnimation() {
case SURFACE_MOTION: { case SURFACE_MOTION: {
// walk transition reach poses are currently only specified for starting to walk forwards // walk transition reach poses are currently only specified for starting to walk forwards
playTransitionReachPoses = (motion.direction === FORWARDS); playTransitionReachPoses = (motion.direction === FORWARDS);
var isAlreadyWalking = (avatar.currentAnimation === avatar.selectedWalkBlend); var isAlreadyWalking = (avatar.currentAnimation === avatar.selectedWalkBlend);
switch (motion.direction) { switch (motion.direction) {
case FORWARDS: case FORWARDS:
if (avatar.selectedWalkBlend.lastDirection !== FORWARDS) { if (avatar.selectedWalkBlend.lastDirection !== FORWARDS) {
animationOperations.deepCopy(avatar.selectedWalk, avatar.selectedWalkBlend); animationOperations.deepCopy(avatar.selectedWalk, avatar.selectedWalkBlend);
avatar.calibration.strideLength = avatar.selectedWalk.calibration.strideLength; avatar.calibration.strideLength = avatar.selectedWalk.calibration.strideLength;
} }
avatar.selectedWalkBlend.lastDirection = FORWARDS; avatar.selectedWalkBlend.lastDirection = FORWARDS;
@ -186,7 +186,7 @@ function selectAnimation() {
case BACKWARDS: case BACKWARDS:
if (avatar.selectedWalkBlend.lastDirection !== BACKWARDS) { if (avatar.selectedWalkBlend.lastDirection !== BACKWARDS) {
animationOperations.deepCopy(avatar.selectedWalkBackwards, avatar.selectedWalkBlend); animationOperations.deepCopy(avatar.selectedWalkBackwards, avatar.selectedWalkBlend);
avatar.calibration.strideLength = avatar.selectedWalkBackwards.calibration.strideLength; avatar.calibration.strideLength = avatar.selectedWalkBackwards.calibration.strideLength;
} }
avatar.selectedWalkBlend.lastDirection = BACKWARDS; avatar.selectedWalkBlend.lastDirection = BACKWARDS;
@ -203,7 +203,7 @@ function selectAnimation() {
avatar.selectedWalkBlend.lastDirection = RIGHT; avatar.selectedWalkBlend.lastDirection = RIGHT;
avatar.calibration.strideLength = avatar.selectedSideStepRight.calibration.strideLength; avatar.calibration.strideLength = avatar.selectedSideStepRight.calibration.strideLength;
break; break;
default: default:
// condition occurs when the avi goes through the floor due to collision hull errors // condition occurs when the avi goes through the floor due to collision hull errors
animationOperations.deepCopy(avatar.selectedWalk, avatar.selectedWalkBlend); animationOperations.deepCopy(avatar.selectedWalk, avatar.selectedWalkBlend);
@ -211,7 +211,7 @@ function selectAnimation() {
avatar.calibration.strideLength = avatar.selectedWalk.calibration.strideLength; avatar.calibration.strideLength = avatar.selectedWalk.calibration.strideLength;
break; break;
} }
if (!isAlreadyWalking && !motion.isComingToHalt) { if (!isAlreadyWalking && !motion.isComingToHalt) {
setTransition(avatar.selectedWalkBlend, playTransitionReachPoses); setTransition(avatar.selectedWalkBlend, playTransitionReachPoses);
} }
@ -229,18 +229,18 @@ function selectAnimation() {
var velocityMagnitude = Vec3.length(motion.velocity); var velocityMagnitude = Vec3.length(motion.velocity);
var verticalProportion = motion.velocity.y / velocityMagnitude; var verticalProportion = motion.velocity.y / velocityMagnitude;
var thrustProportion = motion.velocity.z / velocityMagnitude / 2; var thrustProportion = motion.velocity.z / velocityMagnitude / 2;
// directional components // directional components
var upComponent = motion.velocity.y > 0 ? verticalProportion : 0; var upComponent = motion.velocity.y > 0 ? verticalProportion : 0;
var downComponent = motion.velocity.y < 0 ? -verticalProportion : 0; var downComponent = motion.velocity.y < 0 ? -verticalProportion : 0;
var forwardComponent = motion.velocity.z < 0 ? -thrustProportion : 0; var forwardComponent = motion.velocity.z < 0 ? -thrustProportion : 0;
var backwardComponent = motion.velocity.z > 0 ? thrustProportion : 0; var backwardComponent = motion.velocity.z > 0 ? thrustProportion : 0;
// smooth / damp directional components to add visual 'weight' // smooth / damp directional components to add visual 'weight'
upComponent = flyUpFilter.process(upComponent); upComponent = flyUpFilter.process(upComponent);
downComponent = flyDownFilter.process(downComponent); downComponent = flyDownFilter.process(downComponent);
forwardComponent = flyForwardFilter.process(forwardComponent); forwardComponent = flyForwardFilter.process(forwardComponent);
backwardComponent = flyBackwardFilter.process(backwardComponent); backwardComponent = flyBackwardFilter.process(backwardComponent);
// normalise directional components // normalise directional components
var normaliser = upComponent + downComponent + forwardComponent + backwardComponent; var normaliser = upComponent + downComponent + forwardComponent + backwardComponent;
@ -248,7 +248,7 @@ function selectAnimation() {
downComponent = downComponent / normaliser; downComponent = downComponent / normaliser;
forwardComponent = forwardComponent / normaliser; forwardComponent = forwardComponent / normaliser;
backwardComponent = backwardComponent / normaliser; backwardComponent = backwardComponent / normaliser;
// blend animations proportionally // blend animations proportionally
if (upComponent > 0) { if (upComponent > 0) {
animationOperations.blendAnimation(avatar.selectedFlyUp, animationOperations.blendAnimation(avatar.selectedFlyUp,
@ -299,7 +299,7 @@ function determineStride() {
wheelAdvance = filter.radToDeg(motion.deltaTime * ftWheelAngularVelocity); wheelAdvance = filter.radToDeg(motion.deltaTime * ftWheelAngularVelocity);
} else { } else {
// turn the frequency time wheel by the amount specified for this animation // turn the frequency time wheel by the amount specified for this animation
wheelAdvance = filter.radToDeg(avatar.currentAnimation.calibration.frequency * motion.deltaTime); wheelAdvance = filter.radToDeg(avatar.currentAnimation.calibration.frequency * motion.deltaTime);
} }
if (motion.currentTransition !== nullTransition) { if (motion.currentTransition !== nullTransition) {
@ -316,19 +316,20 @@ function determineStride() {
} }
motion.currentTransition.advancePreviousFrequencyTimeWheel(motion.deltaTime); motion.currentTransition.advancePreviousFrequencyTimeWheel(motion.deltaTime);
} }
// avoid unnaturally fast walking when landing at speed - simulates skimming / skidding // avoid unnaturally fast walking when landing at speed - simulates skimming / skidding
if (Math.abs(wheelAdvance) > MAX_FT_WHEEL_INCREMENT) { if (Math.abs(wheelAdvance) > MAX_FT_WHEEL_INCREMENT) {
wheelAdvance = 0; wheelAdvance = 0;
} }
// advance the walk wheel the appropriate amount // advance the walk wheel the appropriate amount
motion.advanceFrequencyTimeWheel(wheelAdvance); motion.advanceFrequencyTimeWheel(wheelAdvance);
// walking? then see if it's a good time to measure the stride length (needs to be at least 97% of max walking speed) // walking? then see if it's a good time to measure the stride length (needs to be at least 97% of max walking speed)
if (avatar.currentAnimation === avatar.selectedWalkBlend && var JUST_UNDER_ONE = 0.97;
(Vec3.length(motion.velocity) / MAX_WALK_SPEED > 0.97)) { if (avatar.currentAnimation === avatar.selectedWalkBlend &&
(Vec3.length(motion.velocity) / MAX_WALK_SPEED > JUST_UNDER_ONE)) {
var strideMaxAt = avatar.currentAnimation.calibration.strideMaxAt; var strideMaxAt = avatar.currentAnimation.calibration.strideMaxAt;
var tolerance = 1.0; var tolerance = 1.0;
@ -362,7 +363,6 @@ function updateTransitions() {
} }
} }
} }
// update the Transition progress
if (motion.currentTransition.updateProgress() === TRANSITION_COMPLETE) { if (motion.currentTransition.updateProgress() === TRANSITION_COMPLETE) {
motion.currentTransition = nullTransition; motion.currentTransition = nullTransition;
} }
@ -372,7 +372,7 @@ function updateTransitions() {
// helper function for renderMotion(). calculate the amount to lean forwards (or backwards) based on the avi's velocity // helper function for renderMotion(). calculate the amount to lean forwards (or backwards) based on the avi's velocity
function getLeanPitch() { function getLeanPitch() {
var leanProgress = 0; var leanProgress = 0;
if (motion.direction === DOWN || if (motion.direction === DOWN ||
motion.direction === FORWARDS || motion.direction === FORWARDS ||
motion.direction === BACKWARDS) { motion.direction === BACKWARDS) {
@ -386,8 +386,8 @@ function getLeanPitch() {
// helper function for renderMotion(). calculate the angle at which to bank into corners whilst turning // helper function for renderMotion(). calculate the angle at which to bank into corners whilst turning
function getLeanRoll() { function getLeanRoll() {
var leanRollProgress = 0; var leanRollProgress = 0;
var linearContribution = 0; var linearContribution = 0;
if (Vec3.length(motion.velocity) > 0) { if (Vec3.length(motion.velocity) > 0) {
linearContribution = (Math.log(Vec3.length(motion.velocity) / TOP_SPEED) + 8) / 8; linearContribution = (Math.log(Vec3.length(motion.velocity) / TOP_SPEED) + 8) / 8;
} }
@ -398,7 +398,7 @@ function getLeanRoll() {
leanRollProgress = filter.bezier(leanRollProgress, {x: 1, y: 0}, {x: 1, y: 0}); leanRollProgress = filter.bezier(leanRollProgress, {x: 1, y: 0}, {x: 1, y: 0});
// which way to lean? // which way to lean?
var turnSign = (motion.yawDelta >= 0) ? 1 : -1; var turnSign = (motion.yawDelta >= 0) ? 1 : -1;
if (motion.direction === BACKWARDS || if (motion.direction === BACKWARDS ||
motion.direction === LEFT) { motion.direction === LEFT) {
turnSign *= -1; turnSign *= -1;
@ -432,7 +432,6 @@ function renderMotion() {
// factor any leaning into the hips offset // factor any leaning into the hips offset
hipsTranslations.z += avatar.calibration.hipsToFeet * Math.sin(filter.degToRad(leanPitch)); hipsTranslations.z += avatar.calibration.hipsToFeet * Math.sin(filter.degToRad(leanPitch));
hipsTranslations.x += avatar.calibration.hipsToFeet * Math.sin(filter.degToRad(leanRoll)); hipsTranslations.x += avatar.calibration.hipsToFeet * Math.sin(filter.degToRad(leanRoll));
// ensure skeleton offsets are within the 1m limit // ensure skeleton offsets are within the 1m limit
hipsTranslations.x = hipsTranslations.x > 1 ? 1 : hipsTranslations.x; hipsTranslations.x = hipsTranslations.x > 1 ? 1 : hipsTranslations.x;
hipsTranslations.x = hipsTranslations.x < -1 ? -1 : hipsTranslations.x; hipsTranslations.x = hipsTranslations.x < -1 ? -1 : hipsTranslations.x;
@ -445,7 +444,7 @@ function renderMotion() {
// play footfall sound? // play footfall sound?
var producingFootstepSounds = (avatar.currentAnimation === avatar.selectedWalkBlend) && avatar.makesFootStepSounds; var producingFootstepSounds = (avatar.currentAnimation === avatar.selectedWalkBlend) && avatar.makesFootStepSounds;
if (motion.currentTransition !== nullTransition && avatar.makesFootStepSounds) { if (motion.currentTransition !== nullTransition && avatar.makesFootStepSounds) {
if (motion.currentTransition.nextAnimation === avatar.selectedWalkBlend || if (motion.currentTransition.nextAnimation === avatar.selectedWalkBlend ||
motion.currentTransition.lastAnimation === avatar.selectedWalkBlend) { motion.currentTransition.lastAnimation === avatar.selectedWalkBlend) {
@ -454,7 +453,7 @@ function renderMotion() {
} }
if (producingFootstepSounds) { if (producingFootstepSounds) {
var ftWheelPosition = motion.frequencyTimeWheelPos; var ftWheelPosition = motion.frequencyTimeWheelPos;
if (motion.currentTransition !== nullTransition && if (motion.currentTransition !== nullTransition &&
motion.currentTransition.lastAnimation === avatar.selectedWalkBlend) { motion.currentTransition.lastAnimation === avatar.selectedWalkBlend) {
ftWheelPosition = motion.currentTransition.lastFrequencyTimeWheelPos; ftWheelPosition = motion.currentTransition.lastFrequencyTimeWheelPos;
} }
@ -470,10 +469,10 @@ function renderMotion() {
var joint = walkAssets.animationReference.joints[jointName]; var joint = walkAssets.animationReference.joints[jointName];
var jointRotations = undefined; var jointRotations = undefined;
// ignore arms / head rotations if options are selected // ignore arms / head rotations if avatar options are selected
if (avatar.armsFree && (joint.IKChain === "LeftArm" || joint.IKChain === "RightArm")) { if (avatar.armsFree && (joint.IKChain === "LeftArm" || joint.IKChain === "RightArm")) {
continue; continue;
} }
if (avatar.headFree && joint.IKChain === "Head") { if (avatar.headFree && joint.IKChain === "Head") {
continue; continue;
} }
@ -489,13 +488,12 @@ function renderMotion() {
motion.frequencyTimeWheelPos, motion.frequencyTimeWheelPos,
motion.direction); motion.direction);
} }
// apply angular velocity and speed induced leaning // apply angular velocity and speed induced leaning
if (jointName === "Hips") { if (jointName === "Hips") {
jointRotations.x += leanPitch; jointRotations.x += leanPitch;
jointRotations.z += leanRoll; jointRotations.z += leanRoll;
} }
// apply rotations // apply rotations
MyAvatar.setJointData(jointName, Quat.fromVec3Degrees(jointRotations)); MyAvatar.setJointData(jointName, Quat.fromVec3Degrees(jointRotations));
} }