made requested changes and also allow entities/overlays to be grabbed by the grip button

This commit is contained in:
druiz17 2017-09-07 14:42:46 -07:00
parent 636e906191
commit ef050a09f9
16 changed files with 371 additions and 357 deletions

View file

@ -21,11 +21,13 @@ Script.include("/~/system/libraries/controllers.js");
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
(function() {
var _this = this;
var NEAR_MAX_RADIUS = 1.0;
var TARGET_UPDATE_HZ = 60; // 50hz good enough, but we're using update
var BASIC_TIMER_INTERVAL_MS = 1000 / TARGET_UPDATE_HZ;
function ControllerDispatcher() {
var _this = this
this.lastInterval = Date.now();
this.intervalCount = 0;
this.totalDelta = 0;
@ -41,6 +43,10 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
this.activitySlots = {
leftHand: false,
rightHand: false,
rightHandTrigger: false,
leftHandTrigger: false,
rightHandEquip: false,
leftHandEquip: false,
mouse: false
};
@ -53,9 +59,9 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
return true;
};
this.markSlots = function (plugin, used) {
this.markSlots = function (plugin, pluginName) {
for (var i = 0; i < plugin.parameters.activitySlots.length; i++) {
_this.activitySlots[plugin.parameters.activitySlots[i]] = used;
_this.activitySlots[plugin.parameters.activitySlots[i]] = pluginName;
}
};
@ -135,32 +141,31 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
};
this.update = function () {
var deltaTime = this.updateTimings();
this.setIgnoreTablet();
var deltaTime = _this.updateTimings();
_this.setIgnoreTablet();
if (controllerDispatcherPluginsNeedSort) {
this.orderedPluginNames = [];
_this.orderedPluginNames = [];
for (var pluginName in controllerDispatcherPlugins) {
if (controllerDispatcherPlugins.hasOwnProperty(pluginName)) {
this.orderedPluginNames.push(pluginName);
_this.orderedPluginNames.push(pluginName);
}
}
this.orderedPluginNames.sort(function (a, b) {
_this.orderedPluginNames.sort(function (a, b) {
return controllerDispatcherPlugins[a].parameters.priority -
controllerDispatcherPlugins[b].parameters.priority;
});
// print("controllerDispatcher -- new plugin order: " + JSON.stringify(this.orderedPluginNames));
var output = "controllerDispatcher -- new plugin order: ";
for (var k = 0; k < this.orderedPluginNames.length; k++) {
var dbgPluginName = this.orderedPluginNames[k];
for (var k = 0; k < _this.orderedPluginNames.length; k++) {
var dbgPluginName = _this.orderedPluginNames[k];
var priority = controllerDispatcherPlugins[dbgPluginName].parameters.priority;
output += dbgPluginName + ":" + priority;
if (k + 1 < this.orderedPluginNames.length) {
if (k + 1 < _this.orderedPluginNames.length) {
output += ", ";
}
}
print(output);
controllerDispatcherPluginsNeedSort = false;
}
@ -174,7 +179,7 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
var nearbyOverlayIDs = [];
var h;
for (h = LEFT_HAND; h <= RIGHT_HAND; h++) {
// todo: check controllerLocations[h].valid
if (controllerLocations[h].valid) {
var nearbyOverlays = Overlays.findOverlays(controllerLocations[h].position, NEAR_MAX_RADIUS);
nearbyOverlays.sort(function (a, b) {
var aPosition = Overlays.getProperty(a, "position");
@ -184,13 +189,16 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
return aDistance - bDistance;
});
nearbyOverlayIDs.push(nearbyOverlays);
} else {
nearbyOverlayIDs.push([]);
}
}
// find entities near each hand
var nearbyEntityProperties = [[], []];
var nearbyEntityPropertiesByID = {};
for (h = LEFT_HAND; h <= RIGHT_HAND; h++) {
// todo: check controllerLocations[h].valid
if (controllerLocations[h].valid) {
var controllerPosition = controllerLocations[h].position;
var nearbyEntityIDs = Entities.findEntities(controllerPosition, NEAR_MAX_RADIUS);
for (var j = 0; j < nearbyEntityIDs.length; j++) {
@ -201,6 +209,7 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
nearbyEntityProperties[h].push(props);
}
}
}
// raypick for each controller
var rayPicks = [
@ -254,8 +263,8 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
};
// check for plugins that would like to start. ask in order of increasing priority value
for (var pluginIndex = 0; pluginIndex < this.orderedPluginNames.length; pluginIndex++) {
var orderedPluginName = this.orderedPluginNames[pluginIndex];
for (var pluginIndex = 0; pluginIndex < _this.orderedPluginNames.length; pluginIndex++) {
var orderedPluginName = _this.orderedPluginNames[pluginIndex];
var candidatePlugin = controllerDispatcherPlugins[orderedPluginName];
if (_this.slotsAreAvailableForPlugin(candidatePlugin)) {
@ -350,17 +359,17 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
data = JSON.parse(message);
var action = data.action;
var id = data.id;
var index = this.blacklis.indexOf(id);
var index = _this.blacklis.indexOf(id);
if (action === 'add' && index === -1) {
this.blacklist.push(id);
this.setBlacklist();
_this.blacklist.push(id);
_this.setBlacklist();
}
if (action === 'remove') {
if (index > -1) {
this.blacklist.splice(index, 1);
this.setBlacklist();
_this.blacklist.splice(index, 1);
_this.setBlacklist();
}
}
}
@ -379,8 +388,11 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
RayPick.removeRayPick(_this.rightControllerHudRayPick);
RayPick.removeRayPick(_this.leftControllerHudRayPick);
};
}
var controllerDispatcher = new ControllerDispatcher();
Messages.subscribe('Hifi-Hand-RayPick-Blacklist');
Messages.messageReceived.connect(this.handleHandMessage);
Script.scriptEnding.connect(this.cleanup);
Script.update.connect(this.update);
Messages.messageReceived.connect(controllerDispatcher.handleHandMessage);
Script.scriptEnding.connect(controllerDispatcher.cleanup);
Script.update.connect(controllerDispatcher.update);
}());

View file

@ -12,7 +12,7 @@
getEnabledModuleByName
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
(function() {
function DisableModules(hand) {
@ -21,6 +21,7 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
this.parameters = makeDispatcherModuleParameters(
90,
this.hand === RIGHT_HAND ? ["rightHand", "rightHandEquip", "rightHandTrigger"] : ["leftHand", "leftHandEquip", "leftHandTrigger"],
[],
100);
this.isReady = function(controllerData) {

View file

@ -14,7 +14,7 @@
*/
Script.include("/~/system/libraries/Xform.js");
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
Script.include("/~/system/libraries/cloneEntityUtils.js");

View file

@ -17,7 +17,7 @@
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
(function() {

View file

@ -16,7 +16,7 @@
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
(function() {

View file

@ -14,7 +14,7 @@
isInEditMode
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
Script.include("/~/system/libraries/utils.js");
@ -94,6 +94,7 @@ Script.include("/~/system/libraries/utils.js");
this.parameters = makeDispatcherModuleParameters(
160,
this.hand === RIGHT_HAND ? ["rightHand", "rightHandEquip", "rightHandTrigger"] : ["leftHand", "leftHandEquip", "leftHandTrigger"],
[],
100);
this.nearTablet = function(overlays) {

View file

@ -12,7 +12,7 @@
TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS, findGroupParent, entityIsCloneable, propsAreCloneDynamic, cloneEntity
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
Script.include("/~/system/libraries/cloneEntityUtils.js");

View file

@ -13,7 +13,7 @@
findGroupParent, Vec3, cloneEntity, entityIsCloneable, propsAreCloneDynamic
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/cloneEntityUtils.js");
(function() {
@ -169,7 +169,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
this.targetEntityID = null;
this.grabbing = false;
if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE) {
if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE && controllerData.secondaryValues[this.hand] < TRIGGER_OFF_VALUE) {
return makeRunningValues(false, [], []);
}
@ -188,7 +188,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
this.run = function (controllerData, deltaTime) {
if (this.grabbing) {
if (controllerData.triggerClicks[this.hand] === 0) {
if (controllerData.triggerClicks[this.hand] === 0 && controllerData.secondaryValues[this.hand] === 0) {
this.endNearParentingGrabEntity();
return makeRunningValues(false, [], []);
}
@ -208,7 +208,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
if (!readiness.active) {
return readiness;
}
if (controllerData.triggerClicks[this.hand] === 1) {
if (controllerData.triggerClicks[this.hand] === 1 || controllerData.secondaryValues[this.hand] === 1) {
// switch to grab
var targetProps = this.getTargetProps(controllerData);
var targetCloneable = entityIsCloneable(targetProps);

View file

@ -12,7 +12,7 @@
makeDispatcherModuleParameters, Overlays, makeRunningValues
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
var GRAB_RADIUS = 0.35;
(function() {
@ -158,7 +158,7 @@ var GRAB_RADIUS = 0.35;
this.isReady = function (controllerData) {
if (controllerData.triggerClicks[this.hand] === 0) {
if (controllerData.triggerClicks[this.hand] === 0 && controllerData.secondaryValues[this.hand] === 0) {
return makeRunningValues(false, [], []);
}
@ -180,7 +180,7 @@ var GRAB_RADIUS = 0.35;
};
this.run = function (controllerData) {
if (controllerData.triggerClicks[this.hand] === 0) {
if (controllerData.triggerClicks[this.hand] === 0 && controllerData.secondaryValues[this.hand] === 0) {
this.endNearParentingGrabOverlay();
return makeRunningValues(false, [], []);
} else {

View file

@ -11,7 +11,7 @@
TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, makeRunningValues, NEAR_GRAB_RADIUS
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
(function() {

View file

@ -14,7 +14,7 @@
DISPATCHER_PROPERTIES
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
(function() {

View file

@ -11,7 +11,7 @@
AVATAR_SELF_ID, HMD, INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, Settings, getGrabPointSphereOffset
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
(function() {

View file

@ -17,7 +17,7 @@
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
Script.include("/~/system/libraries/Xform.js");
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
(function() { // BEGIN LOCAL_SCOPE
@ -27,9 +27,9 @@ var inTeleportMode = false;
var SMOOTH_ARRIVAL_SPACING = 33;
var NUMBER_OF_STEPS = 6;
var TARGET_MODEL_URL = Script.resolvePath("../assets/models/teleport-destination.fbx");
var TOO_CLOSE_MODEL_URL = Script.resolvePath("../assets/models/teleport-cancel.fbx");
var SEAT_MODEL_URL = Script.resolvePath("../assets/models/teleport-seat.fbx");
var TARGET_MODEL_URL = Script.resolvePath("../../assets/models/teleport-destination.fbx");
var TOO_CLOSE_MODEL_URL = Script.resolvePath("../../assets/models/teleport-cancel.fbx");
var SEAT_MODEL_URL = Script.resolvePath("../../assets/models/teleport-seat.fbx");
var TARGET_MODEL_DIMENSIONS = {
x: 1.15,

View file

@ -16,7 +16,7 @@
*/
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
(function() {

View file

@ -28,7 +28,7 @@ var CONTOLLER_SCRIPTS = [
"controllerModules/inEditMode.js",
"controllerModules/disableOtherModule.js",
"controllerModules/farTrigger.js",
"teleport.js"
"controllerModules/teleport.js"
];
var DEBUG_MENU_ITEM = "Debug defaultScripts.js";