From 0f3722a05cc0793b385592182b88d4939672be76 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 3 Dec 2015 13:14:22 +1300 Subject: [PATCH 1/4] Fix Leap Motion calibration avatar pose --- examples/controllers/leap/leapHands.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/examples/controllers/leap/leapHands.js b/examples/controllers/leap/leapHands.js index 7835df7452..96c3c05adf 100644 --- a/examples/controllers/leap/leapHands.js +++ b/examples/controllers/leap/leapHands.js @@ -166,10 +166,8 @@ var leapHands = (function () { MyAvatar.clearJointData("LeftHand"); MyAvatar.clearJointData("LeftForeArm"); - MyAvatar.clearJointData("LeftArm"); MyAvatar.clearJointData("RightHand"); MyAvatar.clearJointData("RightForeArm"); - MyAvatar.clearJointData("RightArm"); calibrationStatus = CALIBRATED; print("Leap Motion: Calibrated"); @@ -193,12 +191,10 @@ var leapHands = (function () { } // Set avatar arms vertical, forearms horizontal, as "zero" position for calibration - MyAvatar.setJointRotation("LeftArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 0.0)); - MyAvatar.setJointRotation("LeftForeArm", Quat.fromPitchYawRollDegrees(0.0, 90.0, 90.0)); - MyAvatar.setJointRotation("LeftHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0)); - MyAvatar.setJointRotation("RightArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 0.0)); - MyAvatar.setJointRotation("RightForeArm", Quat.fromPitchYawRollDegrees(0.0, -90.0, -90.0)); - MyAvatar.setJointRotation("RightHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0)); + MyAvatar.setJointRotation("LeftForeArm", Quat.fromPitchYawRollDegrees(0.0, 0.0, 90.0)); + MyAvatar.setJointRotation("LeftHand", Quat.fromPitchYawRollDegrees(0.0, 90.0, 0.0)); + MyAvatar.setJointRotation("RightForeArm", Quat.fromPitchYawRollDegrees(0.0, 0.0, -90.0)); + MyAvatar.setJointRotation("RightHand", Quat.fromPitchYawRollDegrees(0.0, -90.0, 0.0)); // Wait for arms to assume their positions before calculating Script.setTimeout(finishCalibration, CALIBRATION_TIME); From a0dcf72a3bb249f5b645be8338d9bcecb5c62296 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 3 Dec 2015 14:09:46 +1300 Subject: [PATCH 2/4] Use animation handlers to control hand position and orientation --- examples/controllers/leap/leapHands.js | 50 +++++++++++++++++++++----- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/examples/controllers/leap/leapHands.js b/examples/controllers/leap/leapHands.js index 96c3c05adf..bd8765e376 100644 --- a/examples/controllers/leap/leapHands.js +++ b/examples/controllers/leap/leapHands.js @@ -20,6 +20,9 @@ var leapHands = (function () { hasHandAndWristJoints, handToWristOffset = [], // For avatars without a wrist joint we control an estimate of a proper hand joint position HAND_OFFSET = 0.4, // Relative distance of wrist to hand versus wrist to index finger knuckle + handAnimationStateHandlers, + handAnimationStateFunctions, + handAnimationStateProperties, hands, wrists, NUM_HANDS = 2, // 0 = left; 1 = right @@ -125,6 +128,26 @@ var leapHands = (function () { */ } + function animateLeftHand() { + var ROTATION_AND_POSITION = 0; + + return { + leftHandType: ROTATION_AND_POSITION, + leftHandPosition: hands[0].position, + leftHandRotation: hands[0].rotation + }; + } + + function animateRightHand() { + var ROTATION_AND_POSITION = 0; + + return { + rightHandType: ROTATION_AND_POSITION, + rightHandPosition: hands[1].position, + rightHandRotation: hands[1].rotation + }; + } + function finishCalibration() { var avatarPosition, handPosition, @@ -315,6 +338,13 @@ var leapHands = (function () { ] ]; + handAnimationStateHandlers = [null, null]; + handAnimationStateFunctions = [animateLeftHand, animateRightHand]; + handAnimationStateProperties = [ + ["leftHandType", "leftHandPosition", "leftHandRotation"], + ["rightHandType", "rightHandPosition", "rightHandPosition"] + ]; + setIsOnHMD(); settingsTimer = Script.setInterval(checkSettings, 2000); @@ -344,6 +374,12 @@ var leapHands = (function () { return; } + // Hand animation handlers ... + if (handAnimationStateHandlers[h] === null) { + handAnimationStateHandlers[h] = MyAvatar.addAnimationStateHandler(handAnimationStateFunctions[h], + handAnimationStateProperties[h]); + } + // Hand position ... handOffset = hands[h].controller.getAbsTranslation(); handRotation = hands[h].controller.getAbsRotation(); @@ -454,14 +490,9 @@ var leapHands = (function () { hands[h].inactiveCount += 1; if (hands[h].inactiveCount === MAX_HAND_INACTIVE_COUNT) { - if (h === 0) { - MyAvatar.clearJointData("LeftHand"); - MyAvatar.clearJointData("LeftForeArm"); - MyAvatar.clearJointData("LeftArm"); - } else { - MyAvatar.clearJointData("RightHand"); - MyAvatar.clearJointData("RightForeArm"); - MyAvatar.clearJointData("RightArm"); + if (handAnimationStateHandlers[h] !== null) { + MyAvatar.removeAnimationStateHandler(handAnimationStateHandlers[h]); + handAnimationStateHandlers[h] = null; } } } @@ -479,6 +510,9 @@ var leapHands = (function () { for (h = 0; h < NUM_HANDS; h += 1) { Controller.releaseInputController(hands[h].controller); Controller.releaseInputController(wrists[h].controller); + if (handAnimationStateHandlers[h] !== null) { + MyAvatar.removeAnimationStateHandler(handAnimationStateHandlers[h]); + } for (i = 0; i < NUM_FINGERS; i += 1) { for (j = 0; j < NUM_FINGER_JOINTS; j += 1) { if (fingers[h][i][j].controller !== null) { From 560b9f012fecf6069e0e6c0e4392079881fd0bf0 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 5 Dec 2015 16:25:28 +1300 Subject: [PATCH 3/4] Get hand positioning and orientation working again --- examples/controllers/leap/leapHands.js | 49 ++++++++++++++++---------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/examples/controllers/leap/leapHands.js b/examples/controllers/leap/leapHands.js index bd8765e376..424ab81948 100644 --- a/examples/controllers/leap/leapHands.js +++ b/examples/controllers/leap/leapHands.js @@ -40,7 +40,13 @@ var leapHands = (function () { avatarScale, avatarFaceModelURL, avatarSkeletonModelURL, - settingsTimer; + settingsTimer, + HMD_CAMERA_TO_AVATAR_ROTATION = [ + Quat.angleAxis(180.0, { x: 0, y: 0, z: 1 }), + Quat.angleAxis(-180.0, { x: 0, y: 0, z: 1 }) + ], + DESKTOP_CAMERA_TO_AVATAR_ROTATION = + Quat.multiply(Quat.angleAxis(180.0, { x: 0, y: 1, z: 0 }), Quat.angleAxis(90.0, { x: 0, y: 0, z: 1 })); function printSkeletonJointNames() { var jointNames, @@ -394,37 +400,41 @@ var leapHands = (function () { // Hand offset in camera coordinates ... handOffset = { - x: hands[h].zeroPosition.x - handOffset.x, - y: hands[h].zeroPosition.y - handOffset.z, - z: hands[h].zeroPosition.z + handOffset.y + x: -handOffset.x, + y: -handOffset.z, + z: -handOffset.y - hands[h].zeroPosition.z }; - handOffset.z = -handOffset.z; // Hand offset in world coordinates ... cameraOrientation = Camera.getOrientation(); handOffset = Vec3.sum(Camera.getPosition(), Vec3.multiplyQbyV(cameraOrientation, handOffset)); - // Hand offset in avatar coordinates ... + // Hand offset in avatar coordinates ... inverseAvatarOrientation = Quat.inverse(MyAvatar.orientation); handOffset = Vec3.subtract(handOffset, MyAvatar.position); handOffset = Vec3.multiplyQbyV(inverseAvatarOrientation, handOffset); handOffset.z = -handOffset.z; handOffset.x = -handOffset.x; + // Hand rotation in camera coordinates ... handRotation = { - x: -handRotation.x, + x: -handRotation.y, y: -handRotation.z, - z: -handRotation.y, + z: -handRotation.x, w: handRotation.w }; // Hand rotation in avatar coordinates ... - handRotation = Quat.multiply(Quat.angleAxis(180.0, { x: 0, y: 1, z: 0 }), handRotation); - cameraOrientation.x = -cameraOrientation.x; - cameraOrientation.z = -cameraOrientation.z; - handRotation = Quat.multiply(cameraOrientation, handRotation); - handRotation = Quat.multiply(inverseAvatarOrientation, handRotation); + handRotation = Quat.multiply(HMD_CAMERA_TO_AVATAR_ROTATION[h], handRotation); + cameraOrientation = { + x: cameraOrientation.z, + y: cameraOrientation.y, + z: cameraOrientation.x, + w: cameraOrientation.w + }; + cameraOrientation = Quat.multiply(cameraOrientation, Quat.inverse(MyAvatar.orientation)); + handRotation = Quat.multiply(handRotation, cameraOrientation); // Works!!! } else { @@ -443,18 +453,19 @@ var leapHands = (function () { // Hand rotation in camera coordinates ... handRotation = { - x: -handRotation.x, - y: -handRotation.z, - z: -handRotation.y, + x: handRotation.z, + y: handRotation.y, + z: handRotation.x, w: handRotation.w }; // Hand rotation in avatar coordinates ... - handRotation = Quat.multiply(Quat.angleAxis(90.0, { x: 1, y: 0, z: 0 }), handRotation); + handRotation = Quat.multiply(DESKTOP_CAMERA_TO_AVATAR_ROTATION, handRotation); } - // Set hand position and orientation ... - MyAvatar.setJointModelPositionAndOrientation(hands[h].jointName, handOffset, handRotation, true); + // Set hand position and orientation for animation state handler ... + hands[h].position = handOffset; + hands[h].rotation = handRotation; // Set finger joints ... for (i = 0; i < NUM_FINGERS; i += 1) { From 404deba78d67689320487693f672504e8035a0cb Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 5 Dec 2015 16:26:21 +1300 Subject: [PATCH 4/4] Adjust avatar thumb root joint angle to look better --- examples/controllers/leap/leapHands.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/controllers/leap/leapHands.js b/examples/controllers/leap/leapHands.js index 424ab81948..a77fa44e1c 100644 --- a/examples/controllers/leap/leapHands.js +++ b/examples/controllers/leap/leapHands.js @@ -46,7 +46,8 @@ var leapHands = (function () { Quat.angleAxis(-180.0, { x: 0, y: 0, z: 1 }) ], DESKTOP_CAMERA_TO_AVATAR_ROTATION = - Quat.multiply(Quat.angleAxis(180.0, { x: 0, y: 1, z: 0 }), Quat.angleAxis(90.0, { x: 0, y: 0, z: 1 })); + Quat.multiply(Quat.angleAxis(180.0, { x: 0, y: 1, z: 0 }), Quat.angleAxis(90.0, { x: 0, y: 0, z: 1 })), + LEAP_THUMB_ROOT_ADJUST = [Quat.fromPitchYawRollDegrees(0, 0, 20), Quat.fromPitchYawRollDegrees(0, 0, -20)]; function printSkeletonJointNames() { var jointNames, @@ -479,6 +480,10 @@ var leapHands = (function () { z: side * -locRotation.x, w: locRotation.w }; + if (j === 0) { + // Adjust avatar thumb root joint rotation to make avatar hands look better + locRotation = Quat.multiply(LEAP_THUMB_ROOT_ADJUST[h], locRotation); + } } else { locRotation = { x: -locRotation.x,