-
Notifications
You must be signed in to change notification settings - Fork 502
/
Copy pathkinectToAnimation.js
66 lines (51 loc) · 2.36 KB
/
kinectToAnimation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var handlerId = 0;
var ikTypes = {
RotationAndPosition: 0,
RotationOnly: 1,
HmdHead: 2,
HipsRelativeRotationAndPosition: 3,
Off: 4
};
var MAPPING_NAME = "com.highfidelity.examples.kinectToAnimation";
var mapping = Controller.newMapping(MAPPING_NAME);
var recentLeftHand;
var recentRightHand;
var recentLeftFoot;
var recentRightFoot;
mapping.from(Controller.Hardware.Kinect.LeftHand).debug(true).to(function(pose) { recentLeftHand = pose; });
mapping.from(Controller.Hardware.Kinect.RightHand).debug(true).to(function(pose) { recentRightHand = pose; });
mapping.from(Controller.Hardware.Kinect.LeftFoot).debug(true).to(function(pose) { recentLeftFoot = pose; });
mapping.from(Controller.Hardware.Kinect.RightFoot).debug(true).to(function(pose) { recentRightFoot = pose; });
function init() {
var t = 0;
var propList = [
"leftHandType", "leftHandPosition", "leftHandRotation", "rightHandType", "rightHandPosition", "rightHandRotation",
"leftFootType", "leftFootPosition", "leftFootRotation", "rightFootType", "rightFootPosition", "rightFootRotation"
];
handlerId = MyAvatar.addAnimationStateHandler(function (props) {
Vec3.print("recentRightHand.translation:", recentRightHand.translation);
Vec3.print("recentLeftHand.translation:", recentLeftHand.translation);
Vec3.print("recentRightFoot.translation:", recentRightFoot.translation);
Vec3.print("recentLeftFoot.translation:", recentLeftFoot.translation);
return {
rightHandType: ikTypes["RotationAndPosition"],
rightHandPosition: recentRightHand.translation,
rightHandRotation: recentRightHand.rotation,
leftHandType: ikTypes["RotationAndPosition"],
leftHandPosition: recentLeftHand.translation,
leftHandRotation: recentLeftHand.rotation,
rightFootType: ikTypes["RotationAndPosition"],
rightFootPosition: recentRightFoot.translation,
rightFootRotation: recentRightFoot.rotation,
leftFootType: ikTypes["RotationAndPosition"],
leftFootPosition: recentLeftFoot.translation,
leftFootRotation: recentLeftFoot.rotation,
};
}, propList);
Controller.enableMapping(MAPPING_NAME);
}
init();
Script.scriptEnding.connect(function(){
MyAvatar.removeAnimationStateHandler(handlerId);
mapping.disable();
});