one universal controller pointer for all modules

This commit is contained in:
Dante Ruiz 2017-10-30 16:58:14 -07:00
parent e6582a0370
commit e5600e4f1e
4 changed files with 186 additions and 145 deletions

View file

@ -32,8 +32,8 @@ var DEFAULT_SCRIPTS_COMBINED = [
"system/tablet-ui/tabletUI.js"
];
var DEFAULT_SCRIPTS_SEPARATE = [
//"system/controllers/controllerScripts.js"
// "system/chat.js"
"system/controllers/controllerScripts.js"
//"system/chat.js"
];
// add a menu item for debugging

View file

@ -33,6 +33,77 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
PROFILE = true;
}
var SEARCH_SPHERE_SIZE = 0.0132;
var dim = {x: SEARCH_SPHERE_SIZE, y: SEARCH_SPHERE_SIZE, z: SEARCH_SPHERE_SIZE};
var halfPath = {
type: "line3d",
color: COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
visible: true,
alpha: 1,
solid: true,
glow: 1.0,
lineWidth: 5,
ignoreRayIntersection: true, // always ignore this
drawInFront: true, // Even when burried inside of something, show it.
parentID: MyAvatar.SELF_ID
};
var halfEnd = {
type: "sphere",
dimensions: dim,
solid: true,
color: COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
alpha: 0.9,
ignoreRayIntersection: true,
drawInFront: true, // Even when burried inside of something, show it.
visible: true
};
var fullPath = {
type: "line3d",
color: COLORS_GRAB_SEARCHING_FULL_SQUEEZE,
visible: true,
alpha: 1,
solid: true,
glow: 1.0,
lineWidth: 5,
ignoreRayIntersection: true, // always ignore this
drawInFront: true, // Even when burried inside of something, show it.
parentID: MyAvatar.SELF_ID
};
var fullEnd = {
type: "sphere",
dimensions: dim,
solid: true,
color: COLORS_GRAB_SEARCHING_FULL_SQUEEZE,
alpha: 0.9,
ignoreRayIntersection: true,
drawInFront: true, // Even when burried inside of something, show it.
visible: true
};
var holdPath = {
type: "line3d",
color: COLORS_GRAB_DISTANCE_HOLD,
visible: true,
alpha: 1,
solid: true,
glow: 1.0,
lineWidth: 5,
ignoreRayIntersection: true, // always ignore this
drawInFront: true, // Even when burried inside of something, show it.
parentID: MyAvatar.SELF_ID
};
var renderStates = [
{name: "half", path: halfPath, end: halfEnd},
{name: "full", path: fullPath, end: fullEnd},
{name: "hold", path: holdPath}
];
var defaultRenderStates = [
{name: "half", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: halfPath},
{name: "full", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: fullPath},
{name: "hold", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: holdPath}
];
function ControllerDispatcher() {
var _this = this;
this.lastInterval = Date.now();
@ -57,6 +128,9 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
mouse: false
};
this.laserVisibleStatus = [false, false];
this.laserLockStatus = [false, false];
this.slotsAreAvailableForPlugin = function (plugin) {
for (var i = 0; i < plugin.parameters.activitySlots.length; i++) {
if (_this.activitySlots[plugin.parameters.activitySlots[i]]) {
@ -72,6 +146,39 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
}
};
this.enableLaserForPlugin = function(plugin) {
var handLaser = plugin.parameters.handLaser;
if (handLaser !== undefined) {
_this.laserVisibleStatus[handLaser] = true;
}
};
this.disableLaserForPlugin = function(plugin) {
var handLaser = plugin.parameters.handLaser;
if (handLaser !== undefined) {
_this.laserVisibleStatus[handLaser] = false;
_this.laserLockStatus[handLaser] = false;
}
};
this.lockLaserToTarget = function(laserLockInfo, plugin) {
if (laserLockInfo !== undefined) {
var hand = laserLockInfo.hand;
if (_this.laserVisibleStatus[laserLockInfo.hand]) {
var pointer = (hand === RIGHT_HAND) ? _this.rightControllerPointer : _this.leftControllerPointer;
var targetID = laserLockInfo.targetID;
var targetIsOverlay = laserLockInfo.isOverlay;
Pointers.setLockEndUUID(pointer, targetID, targetIsOverlay);
_this.laserLockStatus[hand] = targetID;
}
} else {
var handLaser = plugin.parameters.handLaser;
if (handLaser !== undefined) {
_this.laserLockStatus[handLaser] = false;
}
}
};
this.unmarkSlotsForPluginName = function (runningPluginName) {
// this is used to free activity-slots when a plugin is deactivated while it's running.
for (var activitySlot in _this.activitySlots) {
@ -108,7 +215,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
_this.rightSecondaryValue = value;
};
this.dataGatherers = {};
this.dataGatherers.leftControllerLocation = function () {
return getControllerWorldLocation(Controller.Standard.LeftHand, true);
@ -148,6 +254,37 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
}
};
this.updateRenderStateForVisibleLasers = function() {
// update left hand laser
if (_this.laserVisibleStatus[LEFT_HAND]) {
var laserLocked = _this.laserLockStatus[LEFT_HAND];
_this.updateLaserRenderState(_this.leftControllerPointer,_this.leftTriggerClicked, laserLocked);
} else {
Pointers.setRenderState(_this.leftControllerPointer, "");
}
//update right hand laser
if (_this.laserVisibleStatus[RIGHT_HAND]) {
var laserLocked = _this.laserLockStatus[RIGHT_HAND];
_this.updateLaserRenderState(_this.rightControllerPointer, _this.rightTriggerClicked, laserLocked);
} else {
Pointers.setRenderState(_this.rightControllerPointer, "");
}
};
this.updateLaserRenderState = function(laser, triggerClicked, laserLocked) {
var mode = "hold";
if (!laserLocked) {
if (triggerClicked) {
mode = "full";
} else {
mode = "half";
}
}
Pointers.setRenderState(laser, mode);
};
this.update = function () {
if (PROFILE) {
Script.beginProfileRange("dispatch.pre");
@ -234,8 +371,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
// raypick for each controller
var rayPicks = [
RayPick.getPrevRayPickResult(_this.leftControllerRayPick),
RayPick.getPrevRayPickResult(_this.rightControllerRayPick)
Pointers.getPrevPickResult(_this.leftControllerPointer),
Pointers.getPrevPickResult(_this.rightControllerPointer)
];
var hudRayPicks = [
RayPick.getPrevRayPickResult(_this.leftControllerHudRayPick),
@ -319,6 +456,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
// activity-slots which this plugin consumes as "in use"
_this.runningPluginNames[orderedPluginName] = true;
_this.markSlots(candidatePlugin, orderedPluginName);
_this.enableLaserForPlugin(candidatePlugin);
if (DEBUG) {
print("controllerDispatcher running " + orderedPluginName);
}
@ -354,16 +492,19 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
// of running plugins and mark its activity-slots as "not in use"
delete _this.runningPluginNames[runningPluginName];
_this.markSlots(plugin, false);
_this.disableLaserForPlugin(plugin);
if (DEBUG) {
print("controllerDispatcher stopping " + runningPluginName);
}
}
_this.lockLaserToTarget(runningness.laserLockInfo, plugin);
if (PROFILE) {
Script.endProfileRange("dispatch.run." + runningPluginName);
}
}
}
}
_this.updateRenderStateForVisibleLasers();
if (PROFILE) {
Script.endProfileRange("dispatch.run");
}
@ -388,12 +529,13 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Controller.enableMapping(MAPPING_NAME);
this.leftControllerRayPick = RayPick.createRayPick({
joint: "_CONTROLLER_LEFTHAND",
filter: Picks.PICK_ENTITIES | Picks.PICK_OVERLAYS,
enabled: true,
maxDistance: DEFAULT_SEARCH_SPHERE_DISTANCE,
posOffset: getGrabPointSphereOffset(Controller.Standard.LeftHand, true)
this.leftControllerPointer = Pointers.createPointer(PickType.Ray, {
joint: "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND",
filter: Picks.PICK_OVERLAYS | Picks.PICK_ENTITIES,
renderStates: renderStates,
defaultRenderStates: defaultRenderStates,
triggers: [{action: Controller.Standard.RTClick, button: "Focus"}, {action: Controller.Standard.RTClick, button: "Primary"}],
hover: true
});
this.leftControllerHudRayPick = RayPick.createRayPick({
joint: "_CONTROLLER_LEFTHAND",
@ -402,12 +544,13 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
maxDistance: DEFAULT_SEARCH_SPHERE_DISTANCE,
posOffset: getGrabPointSphereOffset(Controller.Standard.LeftHand, true)
});
this.rightControllerRayPick = RayPick.createRayPick({
joint: "_CONTROLLER_RIGHTHAND",
filter: Picks.PICK_ENTITIES | Picks.PICK_OVERLAYS,
enabled: true,
maxDistance: DEFAULT_SEARCH_SPHERE_DISTANCE,
posOffset: getGrabPointSphereOffset(Controller.Standard.RightHand, true)
this.rightControllerPointer = Pointers.createPointer(PickType.Ray, {
joint: "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND",
filter: Picks.PICK_OVERLAYS | Picks.PICK_ENTITIES,
renderStates: renderStates,
defaultRenderStates: defaultRenderStates,
triggers: [{action: Controller.Standard.RTClick, button: "Focus"}, {action: Controller.Standard.RTClick, button: "Primary"}],
hover: true
});
this.rightControllerHudRayPick = RayPick.createRayPick({
joint: "_CONTROLLER_RIGHTHAND",
@ -422,6 +565,11 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
enabled: true
});
Pointers.setRenderState(this.leftControllerPointer, "");
Pointers.setRenderState(this.rightControllerPointer, "");
Pointers.enablePointer(this.leftControllerPointer);
Pointers.enablePointer(this.rightControllerPointer);
this.handleHandMessage = function(channel, message, sender) {
var data;
if (sender === MyAvatar.sessionUUID) {

View file

@ -22,78 +22,6 @@ Script.include("/~/system/libraries/controllers.js");
(function() {
var PICK_WITH_HAND_RAY = true;
var SEARCH_SPHERE_SIZE = 0.0132;
var dim = {x: SEARCH_SPHERE_SIZE, y: SEARCH_SPHERE_SIZE, z: SEARCH_SPHERE_SIZE};
var halfPath = {
type: "line3d",
color: COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
visible: true,
alpha: 1,
solid: true,
glow: 1.0,
lineWidth: 5,
ignoreRayIntersection: true, // always ignore this
drawInFront: true, // Even when burried inside of something, show it.
parentID: MyAvatar.SELF_ID
};
var halfEnd = {
type: "sphere",
dimensions: dim,
solid: true,
color: COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
alpha: 0.9,
ignoreRayIntersection: true,
drawInFront: true, // Even when burried inside of something, show it.
visible: true
};
var fullPath = {
type: "line3d",
color: COLORS_GRAB_SEARCHING_FULL_SQUEEZE,
visible: true,
alpha: 1,
solid: true,
glow: 1.0,
lineWidth: 5,
ignoreRayIntersection: true, // always ignore this
drawInFront: true, // Even when burried inside of something, show it.
parentID: MyAvatar.SELF_ID
};
var fullEnd = {
type: "sphere",
dimensions: dim,
solid: true,
color: COLORS_GRAB_SEARCHING_FULL_SQUEEZE,
alpha: 0.9,
ignoreRayIntersection: true,
drawInFront: true, // Even when burried inside of something, show it.
visible: true
};
var holdPath = {
type: "line3d",
color: COLORS_GRAB_DISTANCE_HOLD,
visible: true,
alpha: 1,
solid: true,
glow: 1.0,
lineWidth: 5,
ignoreRayIntersection: true, // always ignore this
drawInFront: true, // Even when burried inside of something, show it.
parentID: MyAvatar.SELF_ID
};
var renderStates = [
{name: "half", path: halfPath, end: halfEnd},
{name: "full", path: fullPath, end: fullEnd},
{name: "hold", path: holdPath}
];
var defaultRenderStates = [
{name: "half", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: halfPath},
{name: "full", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: fullPath},
{name: "hold", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: holdPath}
];
var GRABBABLE_PROPERTIES = [
"position",
"registrationPoint",
@ -137,37 +65,8 @@ Script.include("/~/system/libraries/controllers.js");
550,
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
[],
100);
this.updateLaserPointer = function(controllerData) {
var mode = "hold";
if (!this.distanceHolding && !this.distanceRotating) {
if (controllerData.triggerClicks[this.hand]) {
mode = "full";
} else {
mode = "half";
}
}
var laserPointerID = PICK_WITH_HAND_RAY ? this.laserPointer : this.headLaserPointer;
if (mode === "full") {
this.contextOverlayTimer = false;
this.destroyContextOverlay();
}
LaserPointers.enableLaserPointer(laserPointerID);
LaserPointers.setRenderState(laserPointerID, mode);
if (this.distanceHolding || this.distanceRotating) {
LaserPointers.setLockEndUUID(laserPointerID, this.grabbedThingID, this.grabbedIsOverlay);
} else {
LaserPointers.setLockEndUUID(laserPointerID, null, false);
}
};
this.laserPointerOff = function() {
LaserPointers.disableLaserPointer(this.laserPointer);
LaserPointers.disableLaserPointer(this.headLaserPointer);
};
100,
this.hand);
this.handToController = function() {
@ -307,9 +206,6 @@ Script.include("/~/system/libraries/controllers.js");
// XXX
// this.maybeScale(grabbedProperties);
// visualizations
this.updateLaserPointer(controllerData);
var distanceToObject = Vec3.length(Vec3.subtract(MyAvatar.position, this.currentObjectPosition));
this.linearTimeScale = (this.linearTimeScale / 2);
@ -445,11 +341,9 @@ Script.include("/~/system/libraries/controllers.js");
if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE ||
this.notPointingAtEntity(controllerData)) {
this.endNearGrabAction();
this.laserPointerOff();
return makeRunningValues(false, [], []);
}
this.intersectionDistance = controllerData.rayPicks[this.hand].distance;
this.updateLaserPointer(controllerData);
var otherModuleName =this.hand === RIGHT_HAND ? "LeftFarActionGrabEntity" : "RightFarActionGrabEntity";
var otherFarGrabModule = getEnabledModuleByName(otherModuleName);
@ -475,7 +369,6 @@ Script.include("/~/system/libraries/controllers.js");
// stop the far-grab so the near-grab or equip can take over.
for (var k = 0; k < nearGrabReadiness.length; k++) {
if (nearGrabReadiness[k].active && nearGrabReadiness[k].targets[0] === this.grabbedThingID) {
this.laserPointerOff();
this.endNearGrabAction();
return makeRunningValues(false, [], []);
}
@ -563,29 +456,18 @@ Script.include("/~/system/libraries/controllers.js");
var disableModule = getEnabledModuleByName(moduleName);
if (disableModule) {
if (disableModule.disableModules) {
this.laserPointerOff();
this.endNearGrabAction();
return makeRunningValues(false, [], []);
}
}
return makeRunningValues(true, [], []);
var grabbedThing = (this.distanceHolding || this.distanceRotating) ? this.grabbedThingID : null;
var grabbedIsOverlay = (this.distanceHolding || this.distanceRotating) ? this.grabbedIsOverlay : false;
var laserLockInfo = makeLaserLockInfo(grabbedThing, grabbedIsOverlay, this.hand);
return makeRunningValues(true, [], [], laserLockInfo);
};
this.cleanup = function () {
LaserPointers.disableLaserPointer(this.laserPointer);
LaserPointers.removeLaserPointer(this.laserPointer);
};
this.laserPointer = LaserPointers.createLaserPointer({
joint: (this.hand === RIGHT_HAND) ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND",
filter: Picks.PICK_ENTITIES | Picks.PICK_OVERLAYS,
maxDistance: PICK_MAX_DISTANCE,
posOffset: getGrabPointSphereOffset(this.handToController(), true),
renderStates: renderStates,
faceAvatar: true,
distanceScaleEnd: true,
defaultRenderStates: defaultRenderStates
});
}
var leftFarActionGrabEntity = new FarActionGrabEntity(LEFT_HAND);

View file

@ -37,6 +37,7 @@
projectOntoXYPlane:true,
projectOntoEntityXYPlane:true,
projectOntoOverlayXYPlane:true,
makeLaserLockInfo:true,
entityHasActions:true,
ensureDynamic:true,
findGroupParent:true,
@ -107,20 +108,30 @@ DISPATCHER_PROPERTIES = [
// activitySlots -- indicates which "slots" must not yet be in use for this module to start
// requiredDataForReady -- which "situation" parts this module looks at to decide if it will start
// sleepMSBetweenRuns -- how long to wait between calls to this module's "run" method
makeDispatcherModuleParameters = function (priority, activitySlots, requiredDataForReady, sleepMSBetweenRuns) {
makeDispatcherModuleParameters = function (priority, activitySlots, requiredDataForReady, sleepMSBetweenRuns, enableLaserForHand) {
return {
priority: priority,
activitySlots: activitySlots,
requiredDataForReady: requiredDataForReady,
sleepMSBetweenRuns: sleepMSBetweenRuns
sleepMSBetweenRuns: sleepMSBetweenRuns,
handLaser: enableLaserForHand
};
};
makeRunningValues = function (active, targets, requiredDataForRun) {
makeLaserLockInfo = function(targetID, isOverlay, hand) {
return {
targetID: targetID,
isOverlay: isOverlay,
hand: hand
};
};
makeRunningValues = function (active, targets, requiredDataForRun, laserLockInfo) {
return {
active: active,
targets: targets,
requiredDataForRun: requiredDataForRun
requiredDataForRun: requiredDataForRun,
laserLockInfo: laserLockInfo
};
};