moveing controllerDispatchaer pointers to pointerUtils.js

This commit is contained in:
Dante Ruiz 2017-11-09 16:48:52 -08:00
parent 86439eff07
commit ef55e3181d
4 changed files with 206 additions and 227 deletions
scripts/system

View file

@ -20,6 +20,7 @@ controllerDispatcherPluginsNeedSort = false;
Script.include("/~/system/libraries/utils.js");
Script.include("/~/system/libraries/controllers.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/pointersUtils.js");
(function() {
var NEAR_MAX_RADIUS = 0.1;
@ -34,77 +35,6 @@ 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();
@ -115,6 +45,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
this.veryhighVarianceCount = 0;
this.tabletID = null;
this.blacklist = [];
this.pointerManager = new PointerManager();
// a module can occupy one or more "activity" slots while it's running. If all the required slots for a module are
// not set to false (not in use), a module cannot start. When a module is using a slot, that module's name
@ -147,39 +78,6 @@ 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) {
@ -255,50 +153,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
}
};
this.updateRenderStateForVisibleLasers = function() {
// update left hand laser
var HUD_LASER_OFFSET = 2;
var laserLocked;
if (_this.laserVisibleStatus[LEFT_HAND]) {
laserLocked = _this.laserLockStatus[LEFT_HAND];
_this.updateLaserRenderState(_this.leftControllerPointer,_this.leftTriggerClicked, _this.leftTriggerValue, laserLocked);
} else {
Pointers.setRenderState(_this.leftControllerPointer, "");
}
if (_this.laserVisibleStatus[RIGHT_HAND]) {
laserLocked = _this.laserLockStatus[RIGHT_HAND];
_this.updateLaserRenderState(_this.rightControllerPointer, _this.rightTriggerClicked, _this.rightTriggerValue, laserLocked);
} else {
Pointers.setRenderState(_this.rightControllerPointer, "");
}
if (_this.laserVisibleStatus[LEFT_HAND + HUD_LASER_OFFSET]) {
_this.updateLaserRenderState(_this.leftControllerHudRayPick, _this.leftTriggerClicked, _this.leftTriggerValue, false);
} else {
Pointers.setRenderState(_this.leftControllerHudRayPick, "");
}
if (_this.laserVisibleStatus[RIGHT_HAND + HUD_LASER_OFFSET]) {
_this.updateLaserRenderState(_this.rightControllerHudRayPick, _this.rightTriggerClicked, _this.rightTriggerValue, false);
} else {
Pointers.setRenderState(_this.rightControllerHudRayPick, "");
}
};
this.updateLaserRenderState = function(laser, triggerClicked, triggerValue, laserLocked) {
var mode = "";
if (laserLocked) {
mode = "hold";
} else if (triggerClicked) {
mode = "full";
} else if (triggerValue > TRIGGER_ON_VALUE) {
mode = "half";
}
Pointers.setRenderState(laser, mode);
};
this.update = function () {
if (PROFILE) {
Script.beginProfileRange("dispatch.pre");
@ -518,7 +372,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
}
}
}
_this.updateRenderStateForVisibleLasers();
_this.pointerManager.updatePoiniterRenderStates(false, 0);
if (PROFILE) {
Script.endProfileRange("dispatch.run");
}
@ -543,40 +397,32 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Controller.enableMapping(MAPPING_NAME);
this.leftControllerPointer = Pointers.createPointer(PickType.Ray, {
this.pointerManager.createPointer(false, PickType.Ray, {
joint: "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND",
filter: Picks.PICK_OVERLAYS | Picks.PICK_ENTITIES,
renderStates: renderStates,
defaultRenderStates: defaultRenderStates,
triggers: [{action: Controller.Standard.LTClick, button: "Focus"}, {action: Controller.Standard.LTClick, button: "Primary"}],
posOffset: getGrabPointSphereOffset(Controller.Standard.LeftHand, true),
hover: true
});
this.leftControllerHudRayPick = Pointers.createPointer(PickType.Ray, {
joint: "_CONTROLLER_LEFTHAND",
filter: Picks.PICK_HUD,
maxDistance: DEFAULT_SEARCH_SPHERE_DISTANCE,
renderStates: renderStates,
defaultRenderStates: defaultRenderStates,
posOffset: getGrabPointSphereOffset(Controller.Standard.LeftHand, true),
triggers: [{action: Controller.Standard.LTClick, button: "Focus"}, {action: Controller.Standard.LTClick, button: "Primary"}],
hover: true
});
this.rightControllerPointer = Pointers.createPointer(PickType.Ray, {
this.pointerManager.createPointer(false, 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"}],
posOffset: getGrabPointSphereOffset(Controller.Standard.RightHand, true),
hover: true
});
this.rightControllerHudRayPick = Pointers.createPointer(PickType.Ray, {
this.pointerManager.createPointer(true, PickType.Ray, {
joint: "_CONTROLLER_LEFTHAND",
filter: Picks.PICK_HUD,
maxDistance: DEFAULT_SEARCH_SPHERE_DISTANCE,
posOffset: getGrabPointSphereOffset(Controller.Standard.LeftHand, true),
triggers: [{action: Controller.Standard.LTClick, button: "Focus"}, {action: Controller.Standard.LTClick, button: "Primary"}],
hover: true
});
this.pointerManager.createPointer(true, PickType.Ray, {
joint: "_CONTROLLER_RIGHTHAND",
filter: Picks.PICK_HUD,
maxDistance: DEFAULT_SEARCH_SPHERE_DISTANCE,
renderStates: renderStates,
defaultRenderStates: defaultRenderStates,
posOffset: getGrabPointSphereOffset(Controller.Standard.RightHand, true),
triggers: [{action: Controller.Standard.RTClick, button: "Focus"}, {action: Controller.Standard.RTClick, button: "Primary"}],
hover: true
@ -586,16 +432,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
filter: Picks.PICK_ENTITIES | Picks.PICK_OVERLAYS,
enabled: true
});
Pointers.setRenderState(this.leftControllerPointer, "");
Pointers.setRenderState(this.leftControllerHudRayPick, "");
Pointers.setRenderState(this.rightControllerPointer, "");
Pointers.setRenderState(this.rightControllerHudRayPick, "");
Pointers.enablePointer(this.leftControllerPointer);
Pointers.enablePointer(this.leftControllerHudRayPick);
Pointers.enablePointer(this.rightControllerPointer);
Pointers.enablePointer(this.rightControllerHudRayPick);
this.handleHandMessage = function(channel, message, sender) {
var data;
if (sender === MyAvatar.sessionUUID) {

View file

@ -42,32 +42,6 @@ Script.include("/~/system/libraries/utils.js");
return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
};
<<<<<<< HEAD
=======
this.processControllerTriggers = function(controllerData) {
if (controllerData.triggerClicks[this.hand]) {
this.mode = "full";
} else if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
this.mode = "half";
} else {
this.mode = "none";
}
};
this.updateLaserPointer = function(controllerData) {
LaserPointers.enableLaserPointer(this.laserPointer);
LaserPointers.setRenderState(this.laserPointer, this.mode);
if (HMD.tabletID !== this.tabletID || HMD.homeButtonID !== this.homeButtonID || HMD.tabletScreenID !== this.tabletScreenID) {
this.tabletID = HMD.tabletID;
this.homeButtonID = HMD.homeButtonID;
this.tabletScreenID = HMD.tabletScreenID;
LaserPointers.setIgnoreItems(this.laserPointer, [HMD.tabletID, HMD.homeButtonID, HMD.tabletScreenID]);
}
};
>>>>>>> 5a78c9ebfee6685c32abcef652fb6b3b3f7dc348
this.pointingAtTablet = function(objectID) {
if (objectID === HMD.tabletScreenID || objectID === HMD.homeButtonID) {
return true;
@ -146,26 +120,6 @@ Script.include("/~/system/libraries/utils.js");
this.sendPickData(controllerData);
return this.isReady(controllerData);
};
<<<<<<< HEAD
=======
this.cleanup = function() {
LaserPointers.disableLaserPointer(this.laserPointer);
LaserPointers.removeLaserPointer(this.laserPointer);
};
this.laserPointer = LaserPointers.createLaserPointer({
joint: (this.hand === RIGHT_HAND) ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND",
filter: Picks.PICK_ENTITIES | Picks.PICK_OVERLAYS,
maxDistance: PICK_MAX_DISTANCE,
posOffset: getGrabPointSphereOffset(this.handToController(), true),
renderStates: renderStates,
faceAvatar: true,
defaultRenderStates: defaultRenderStates
});
LaserPointers.setIgnoreItems(this.laserPointer, [HMD.tabletID, HMD.homeButtonID, HMD.tabletScreenID]);
>>>>>>> 5a78c9ebfee6685c32abcef652fb6b3b3f7dc348
}
var leftHandInEditMode = new InEditMode(LEFT_HAND);
@ -175,8 +129,6 @@ Script.include("/~/system/libraries/utils.js");
enableDispatcherModule("RightHandInEditMode", rightHandInEditMode);
function cleanup() {
leftHandInEditMode.cleanup();
rightHandInEditMode.cleanup();
disableDispatcherModule("LeftHandInEditMode");
disableDispatcherModule("RightHandInEditMode");
}

View file

@ -345,7 +345,7 @@ Grabber.prototype.pressEvent = function(event) {
}
Pointers.setRenderState(this.mouseRayEntities, "grabbed");
Pointers.setLockEndUid(this.mouseRayEntities, pickResults.objectID, false);
Pointers.setLockEndUUID(this.mouseRayEntities, pickResults.objectID, false);
mouse.startDrag(event);

View file

@ -0,0 +1,191 @@
"use strict";
// pointerUtils.js
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/* jslint bitwise: true */
/* global Script, Entities, Overlays, Controller, Vec3, Quat, getControllerWorldLocation, RayPick,
controllerDispatcherPlugins:true, controllerDispatcherPluginsNeedSort:true,
LEFT_HAND, RIGHT_HAND, NEAR_GRAB_PICK_RADIUS, DEFAULT_SEARCH_SPHERE_DISTANCE, DISPATCHER_PROPERTIES,
getGrabPointSphereOffset, HMD, MyAvatar, Messages, findHandChildEntities, Pointers, PickType, COLORS_GRAB_SEARCHING_HALF_SQUEEZE
COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, Picks, TRIGGER_ON_VALUE
*/
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
function Pointer(hudLayer, pickType, pointerData) {
this.SEARCH_SPHERE_SIZE = 0.0132;
this.dim = {x: this.SEARCH_SPHERE_SIZE, y: this.SEARCH_SPHERE_SIZE, z: this.SEARCH_SPHERE_SIZE};
this.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.
drawHUDLayer: hudLayer,
parentID: MyAvatar.SELF_ID
};
this.halfEnd = {
type: "sphere",
dimensions: this.dim,
solid: true,
color: COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
alpha: 0.9,
ignoreRayIntersection: true,
drawInFront: true, // Even when burried inside of something, show it.
drawHUDLayer: hudLayer,
visible: true
};
this.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.
drawHUDLayer: hudLayer,
parentID: MyAvatar.SELF_ID
};
this.fullEnd = {
type: "sphere",
dimensions: this.dim,
solid: true,
color: COLORS_GRAB_SEARCHING_FULL_SQUEEZE,
alpha: 0.9,
ignoreRayIntersection: true,
drawInFront: true, // Even when burried inside of something, show it.
drawHUDLayer: hudLayer,
visible: true
};
this.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.
drawHUDLayer: hudLayer,
parentID: MyAvatar.SELF_ID
};
this.renderStates = [
{name: "half", path: this.halfPath, end: this.halfEnd},
{name: "full", path: this.fullPath, end: this.fullEnd},
{name: "hold", path: this.holdPath}
];
this.defaultRenderStates = [
{name: "half", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: this.halfPath},
{name: "full", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: this.fullPath},
{name: "hold", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: this.holdPath}
];
this.pointerID = null;
this.triggers = [];
this.joint = null;
this.visible = false;
this.locked = false;
function createPointer(pickType, pointerData) {
if (this.pointerID) {
Pointers.removePointer(this.pointerID);
}
this.pointerID = Pointers.createPointer(pickType, pointerData);
Pointers.setRenderState(this.pointerID, "");
Pointers.enablePointer(this.pointerID);
}
this.enable = function() {
};
this.disable = function() {
};
this.makeVisible = function() {
this.visible = true;
};
this.makeInvisible = function() {
this.visible = false;
};
this.lockEnd = function(lockData) {
if (lockData !== undefined) {
var hand = lockData.hand;
if (this.visible) {
var targetID = lockData.targetID;
var targetIsOverlay = lockData.isOverlay;
Pointers.setLockEndUUID(this.pointer, targetID, targetIsOverlay);
this.locked = targetID;
}
} else {
this.locked = false;
}
};
this.updateRenderState = function(triggerClicked, triggerValue) {
var mode = "";
if (this.visible) {
if (this.locked) {
mode = "hold";
} else if (triggerClicked) {
mode = "full";
} else if (triggerValue > TRIGGER_ON_VALUE) {
mode = "half";
}
}
Pointers.setRenderState(this.pointerID, mode);
};
pointerData.renderStates = this.renderStates;
pointerData.defualtRenderStates = this.defualtRenderStates;
createPointer(pickType, pointerData);
}
function PointerManager() {
this.pointers = [];
this.createPointer = function(hudLayer, pickType, pointerData) {
var pointer = new Pointer(hudLayer, pickType, pointerData);
this.pointers.push(pointer);
};
this.makePointerVisible = function(index) {
if (index < this.pointers.length) {
this.pointers[index].makeVisible();
}
};
this.makePointerInvisible = function(index) {
if (index < this.pointers.length) {
this.pointers[index].makeInvisible();
}
};
this.lockPointerEnd = function(index, lockData) {
if (index < this.pointers.length) {
this.pointers[index].lockEnd(lockData);
}
};
this.updatePointersRenderState = function(triggerClicked, triggerValue) {
for (var index = 0; index < this.pointers.length; index++) {
this.pointers[index].updateRenderState(triggerClicked, triggerValue);
}
};
}