Last active
August 28, 2018 19:00
-
-
Save hyperlogic/ecb679aee4aef6d55d1e to your computer and use it in GitHub Desktop.
High Fidelity script to procedurally manipulate the hands using IK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var handlerId = 0; | |
var phi = 0.0; | |
var phi2 = 0.0; | |
var forward = true; | |
var RX90 = Quat.angleAxis(90.0, {x: 1, y: 0, z: 0}); | |
function init() { | |
var t = 0; | |
var propList = ["leftHandType", "leftHandPosition", "leftHandRotation", "rightHandType", "rightHandPosition", "rightHandPosition"]; | |
handlerId = MyAvatar.addAnimationStateHandler(function (props) { | |
// a dt would be nice here! | |
phi2 += 0.02; | |
if (forward) { | |
phi += 0.02; | |
} else { | |
phi -= 0.02; | |
} | |
if (phi > 1.0 || phi < 0.0) { | |
forward = !forward; | |
} | |
var sphi = Math.sin((Math.PI / 2) * phi) * Math.sin((Math.PI / 2) * phi) | |
var rightHandTheta = -(Math.PI / 3) + sphi * (2 * Math.PI + ((4 * Math.PI) / 6)); | |
var leftHandTheta = phi2 * (2 * Math.PI); | |
var leftHandRotation = RX90; | |
var rightHandRotation = {x: 0, y: 0, z: 0, w: 1}; | |
var z = 0.25; | |
return { | |
rightHandType: 0, | |
rightHandPosition: {x: -0.2 + 0.2 * Math.sin(rightHandTheta), y: 0.2 + 0.2 * Math.cos(rightHandTheta), z: z}, | |
rightHandRotation: rightHandRotation, | |
leftHandType: 0, | |
leftHandPosition: {x: 0.25 + 0.05 * Math.sin(2 * leftHandTheta), y: -0.1 + 0.1 * Math.cos(leftHandTheta), z: z + 0.1}, | |
leftHandRotation: leftHandRotation | |
}; | |
}, propList); | |
} | |
function shutdown() { | |
MyAvatar.removeAnimationStateHandler(handlerId); | |
} | |
init(); | |
Script.scriptEnding.connect(shutdown); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment