mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 10:00:18 +02:00
viveMotionCapture.js: updated to route pucks through input system
Removed use of animationStateHandler() to set IK targets.
This commit is contained in:
parent
1fc9f4c93d
commit
1b9e609447
1 changed files with 58 additions and 61 deletions
|
@ -11,18 +11,20 @@ var TRACKED_OBJECT_POSES = [
|
||||||
var triggerPressHandled = false;
|
var triggerPressHandled = false;
|
||||||
var rightTriggerPressed = false;
|
var rightTriggerPressed = false;
|
||||||
var leftTriggerPressed = false;
|
var leftTriggerPressed = false;
|
||||||
|
var calibrationCount = 0;
|
||||||
|
|
||||||
var MAPPING_NAME = "com.highfidelity.viveMotionCapture";
|
var TRIGGER_MAPPING_NAME = "com.highfidelity.viveMotionCapture.triggers";
|
||||||
|
var triggerMapping = Controller.newMapping(TRIGGER_MAPPING_NAME);
|
||||||
var mapping = Controller.newMapping(MAPPING_NAME);
|
triggerMapping.from([Controller.Standard.RTClick]).peek().to(function (value) {
|
||||||
mapping.from([Controller.Standard.RTClick]).peek().to(function (value) {
|
|
||||||
rightTriggerPressed = (value !== 0) ? true : false;
|
rightTriggerPressed = (value !== 0) ? true : false;
|
||||||
});
|
});
|
||||||
mapping.from([Controller.Standard.LTClick]).peek().to(function (value) {
|
triggerMapping.from([Controller.Standard.LTClick]).peek().to(function (value) {
|
||||||
leftTriggerPressed = (value !== 0) ? true : false;
|
leftTriggerPressed = (value !== 0) ? true : false;
|
||||||
});
|
});
|
||||||
|
Controller.enableMapping(TRIGGER_MAPPING_NAME);
|
||||||
|
|
||||||
Controller.enableMapping(MAPPING_NAME);
|
var CONTROLLER_MAPPING_NAME = "com.highfidelity.viveMotionCapture.controller";
|
||||||
|
var controllerMapping;
|
||||||
|
|
||||||
var leftFoot;
|
var leftFoot;
|
||||||
var rightFoot;
|
var rightFoot;
|
||||||
|
@ -92,7 +94,8 @@ function calibrate() {
|
||||||
if (pose.valid) {
|
if (pose.valid) {
|
||||||
poses.push({
|
poses.push({
|
||||||
channel: channel,
|
channel: channel,
|
||||||
pose: pose
|
pose: pose,
|
||||||
|
lastestPose: pose
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -177,85 +180,76 @@ var ikTypes = {
|
||||||
|
|
||||||
var handlerId;
|
var handlerId;
|
||||||
|
|
||||||
function computeIKTargetXform(jointInfo) {
|
function convertJointInfoToPose(jointInfo) {
|
||||||
var pose = Controller.getPoseValue(jointInfo.channel);
|
var latestPose = jointInfo.latestPose;
|
||||||
var offsetXform = jointInfo.offsetXform;
|
var offsetXform = jointInfo.offsetXform;
|
||||||
return Xform.mul(Y_180_XFORM, Xform.mul(new Xform(pose.rotation, pose.translation), offsetXform));
|
var xform = Xform.mul(new Xform(latestPose.rotation, latestPose.translation), offsetXform);
|
||||||
|
return {
|
||||||
|
valid: true,
|
||||||
|
translation: xform.pos,
|
||||||
|
rotation: xform.rot,
|
||||||
|
velocity: Vec3.sum(latestPose.velocity, Vec3.cross(latestPose.angularVelocity, Vec3.subtract(xform.pos, latestPose.translation))),
|
||||||
|
angularVelocity: latestPose.angularVelocity
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function update(dt) {
|
function update(dt) {
|
||||||
if (rightTriggerPressed && leftTriggerPressed) {
|
if (rightTriggerPressed && leftTriggerPressed) {
|
||||||
if (!triggerPressHandled) {
|
if (!triggerPressHandled) {
|
||||||
triggerPressHandled = true;
|
triggerPressHandled = true;
|
||||||
if (handlerId) {
|
if (controllerMapping) {
|
||||||
print("AJT: UN-CALIBRATE!");
|
|
||||||
|
|
||||||
// go back to normal, vive pucks will be ignored.
|
// go back to normal, vive pucks will be ignored.
|
||||||
|
print("AJT: UN-CALIBRATE!");
|
||||||
|
|
||||||
leftFoot = undefined;
|
leftFoot = undefined;
|
||||||
rightFoot = undefined;
|
rightFoot = undefined;
|
||||||
hips = undefined;
|
hips = undefined;
|
||||||
spine2 = undefined;
|
spine2 = undefined;
|
||||||
if (handlerId) {
|
|
||||||
print("AJT: un-hooking animation state handler");
|
Controller.disableMapping(CONTROLLER_MAPPING_NAME + calibrationCount);
|
||||||
MyAvatar.removeAnimationStateHandler(handlerId);
|
controllerMapping = undefined;
|
||||||
handlerId = undefined;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
print("AJT: CALIBRATE!");
|
print("AJT: CALIBRATE!");
|
||||||
calibrate();
|
calibrate();
|
||||||
|
calibrationCount++;
|
||||||
|
|
||||||
var animVars = [];
|
controllerMapping = Controller.newMapping(CONTROLLER_MAPPING_NAME + calibrationCount);
|
||||||
|
|
||||||
if (leftFoot) {
|
if (leftFoot) {
|
||||||
animVars.push("leftFootType");
|
controllerMapping.from(leftFoot.channel).to(function (pose) {
|
||||||
animVars.push("leftFootPosition");
|
leftFoot.latestPose = pose;
|
||||||
animVars.push("leftFootRotation");
|
});
|
||||||
|
controllerMapping.from(function () {
|
||||||
|
return convertJointInfoToPose(leftFoot);
|
||||||
|
}).to(Controller.Standard.LeftFoot);
|
||||||
}
|
}
|
||||||
if (rightFoot) {
|
if (rightFoot) {
|
||||||
animVars.push("rightFootType");
|
controllerMapping.from(rightFoot.channel).to(function (pose) {
|
||||||
animVars.push("rightFootPosition");
|
rightFoot.latestPose = pose;
|
||||||
animVars.push("rightFootRotation");
|
});
|
||||||
|
controllerMapping.from(function () {
|
||||||
|
return convertJointInfoToPose(rightFoot);
|
||||||
|
}).to(Controller.Standard.RightFoot);
|
||||||
}
|
}
|
||||||
if (hips) {
|
if (hips) {
|
||||||
animVars.push("hipsType");
|
controllerMapping.from(hips.channel).to(function (pose) {
|
||||||
animVars.push("hipsPosition");
|
hips.latestPose = pose;
|
||||||
animVars.push("hipsRotation");
|
});
|
||||||
|
controllerMapping.from(function () {
|
||||||
|
return convertJointInfoToPose(hips);
|
||||||
|
}).to(Controller.Standard.Hips);
|
||||||
}
|
}
|
||||||
if (spine2) {
|
if (spine2) {
|
||||||
animVars.push("spine2Type");
|
controllerMapping.from(spine2.channel).to(function (pose) {
|
||||||
animVars.push("spine2Position");
|
spine2.latestPose = pose;
|
||||||
animVars.push("spine2Rotation");
|
});
|
||||||
|
controllerMapping.from(function () {
|
||||||
|
return convertJointInfoToPose(spine2);
|
||||||
|
}).to(Controller.Standard.Spine2);
|
||||||
}
|
}
|
||||||
|
Controller.enableMapping(CONTROLLER_MAPPING_NAME + calibrationCount);
|
||||||
// hook up new anim state handler that maps vive pucks to ik system.
|
|
||||||
handlerId = MyAvatar.addAnimationStateHandler(function (props) {
|
|
||||||
var result = {}, xform;
|
|
||||||
if (rightFoot) {
|
|
||||||
xform = computeIKTargetXform(rightFoot);
|
|
||||||
result.rightFootType = ikTypes.RotationAndPosition;
|
|
||||||
result.rightFootPosition = xform.pos;
|
|
||||||
result.rightFootRotation = xform.rot;
|
|
||||||
}
|
|
||||||
if (leftFoot) {
|
|
||||||
xform = computeIKTargetXform(leftFoot);
|
|
||||||
result.leftFootType = ikTypes.RotationAndPosition;
|
|
||||||
result.leftFootPosition = xform.pos;
|
|
||||||
result.leftFootRotation = xform.rot;
|
|
||||||
}
|
|
||||||
if (hips) {
|
|
||||||
xform = computeIKTargetXform(hips);
|
|
||||||
result.hipsType = ikTypes.RotationAndPosition;
|
|
||||||
result.hipsPosition = xform.pos;
|
|
||||||
result.hipsRotation = xform.rot;
|
|
||||||
}
|
|
||||||
if (spine2) {
|
|
||||||
xform = computeIKTargetXform(spine2);
|
|
||||||
result.spine2Type = ikTypes.RotationAndPosition;
|
|
||||||
result.spine2Position = xform.pos;
|
|
||||||
result.spine2Rotation = xform.rot;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}, animVars);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -301,7 +295,10 @@ function update(dt) {
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
Controller.disableMapping(MAPPING_NAME);
|
Controller.disableMapping(TRIGGER_MAPPING_NAME);
|
||||||
|
if (controllerMapping) {
|
||||||
|
Controller.disableMapping(CONTROLLER_MAPPING_NAME + calibrationCount);
|
||||||
|
}
|
||||||
Script.update.disconnect(update);
|
Script.update.disconnect(update);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue