use same near-grab module to grab entities and overlays

This commit is contained in:
Seth Alves 2019-10-02 11:24:05 -07:00
parent 17ceda0d3e
commit 63dcf0e1c9
6 changed files with 66 additions and 16 deletions

View file

@ -53,6 +53,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
this.pointerManager = new PointerManager();
this.grabSphereOverlays = [null, null];
this.targetIDs = {};
this.debugPanelID = null;
this.debugLines = [];
// 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
@ -206,6 +208,18 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.setTimeout(_this.update, BASIC_TIMER_INTERVAL_MS);
};
this.addDebugLine = function(line) {
if (this.debugLines.length > 8) {
this.debugLines.shift();
}
this.debugLines.push(line);
var debugPanelText = "";
this.debugLines.forEach(function(debugLine) {
debugPanelText += debugLine + "\n";
});
Entities.editEntity(this.debugPanelID, { text: debugPanelText });
};
this.updateInternal = function () {
if (PROFILE) {
Script.beginProfileRange("dispatch.pre");
@ -309,6 +323,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
}
var nearbyEntityIDs = Entities.findEntities(controllerPosition, findRadius);
nearbyEntityIDs = nearbyEntityIDs.concat(nearbyOverlayIDs[h]); // overlays are now entities
for (var j = 0; j < nearbyEntityIDs.length; j++) {
var entityID = nearbyEntityIDs[j];
var props = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES);
@ -444,7 +460,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
_this.markSlots(candidatePlugin, orderedPluginName);
_this.pointerManager.makePointerVisible(candidatePlugin.parameters.handLaser);
if (DEBUG) {
print("controllerDispatcher running " + orderedPluginName);
_this.addDebugLine("running " + orderedPluginName);
}
}
if (PROFILE) {
@ -476,8 +492,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
if (DEBUG) {
if (JSON.stringify(_this.targetIDs[runningPluginName]) != JSON.stringify(runningness.targets)) {
print("controllerDispatcher targetIDs[" + runningPluginName + "] = " +
JSON.stringify(runningness.targets));
_this.addDebugLine("targetIDs[" + runningPluginName + "] = " +
JSON.stringify(runningness.targets));
}
}
@ -488,12 +504,12 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
delete _this.runningPluginNames[runningPluginName];
delete _this.targetIDs[runningPluginName];
if (DEBUG) {
print("controllerDispatcher deleted targetIDs[" + runningPluginName + "]");
_this.addDebugLine("deleted targetIDs[" + runningPluginName + "]");
}
_this.markSlots(plugin, false);
_this.pointerManager.makePointerInvisible(plugin.parameters.handLaser);
if (DEBUG) {
print("controllerDispatcher stopping " + runningPluginName);
_this.addDebugLine("stopping " + runningPluginName);
}
}
_this.pointerManager.lockPointerEnd(plugin.parameters.handLaser, runningness.laserLockInfo);
@ -637,7 +653,33 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Overlays.mousePressOnOverlay.disconnect(mousePress);
Entities.mousePressOnEntity.disconnect(mousePress);
Messages.messageReceived.disconnect(controllerDispatcher.handleMessage);
if (_this.debugPanelID) {
Entities.deleteEntity(_this.debugPanelID);
_this.debugPanelID = null;
}
};
if (DEBUG) {
this.debugPanelID = Entities.addEntity({
name: "controllerDispatcher debug panel",
type: "Text",
dimensions: { x: 1.0, y: 0.3, z: 0.01 },
parentID: MyAvatar.sessionUUID,
// parentJointIndex: MyAvatar.getJointIndex("_CAMERA_MATRIX"),
parentJointIndex: -1,
localPosition: { x: -0.25, y: 0.8, z: -1.2 },
textColor: { red: 255, green: 255, blue: 255},
backgroundColor: { red: 0, green: 0, blue: 0},
text: "",
lineHeight: 0.03,
leftMargin: 0.015,
topMargin: 0.01,
backgroundAlpha: 0.7,
textAlpha: 1.0,
unlit: true,
ignorePickIntersection: true
}, "local");
}
}
function mouseReleaseOnOverlay(overlayID, event) {
@ -667,6 +709,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Messages.subscribe('Hifi-Hand-RayPick-Blacklist');
Messages.messageReceived.connect(controllerDispatcher.handleMessage);
Script.scriptEnding.connect(controllerDispatcher.cleanup);
Script.scriptEnding.connect(function () {
controllerDispatcher.cleanup();
});
Script.setTimeout(controllerDispatcher.update, BASIC_TIMER_INTERVAL_MS);
}());

View file

@ -28,7 +28,7 @@ Script.include("/~/system/libraries/controllers.js");
this.grabID = null;
this.parameters = makeDispatcherModuleParameters(
500,
90,
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
[],
100);

View file

@ -52,21 +52,25 @@ Script.include("/~/system/libraries/controllers.js");
this.disable = false;
this.otherModuleNeedsToRun = function(controllerData) {
var grabOverlayModuleName = this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay";
var grabOverlayModule = getEnabledModuleByName(grabOverlayModuleName);
var grabEntityModuleName = this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity";
// var grabOverlayModuleName = this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay";
// var grabOverlayModule = getEnabledModuleByName(grabOverlayModuleName);
// var grabOverlayModuleReady = grabOverlayModule ? grabOverlayModule.isReady(controllerData) : makeRunningValues(false, [], []);
var grabEntityModuleName = this.hand === RIGHT_HAND ? "RightNearGrabEntity" : "LeftNearGrabEntity";
var grabEntityModule = getEnabledModuleByName(grabEntityModuleName);
var grabOverlayModuleReady = grabOverlayModule ? grabOverlayModule.isReady(controllerData) : makeRunningValues(false, [], []);
var grabEntityModuleReady = grabEntityModule ? grabEntityModule.isReady(controllerData) : makeRunningValues(false, [], []);
var farGrabModuleName = this.hand === RIGHT_HAND ? "RightFarActionGrabEntity" : "LeftFarActionGrabEntity";
var farGrabModuleName = this.hand === RIGHT_HAND ? "RightFarGrabEntity" : "LeftFarGrabEntity";
var farGrabModule = getEnabledModuleByName(farGrabModuleName);
var farGrabModuleReady = farGrabModule ? farGrabModule.isReady(controllerData) : makeRunningValues(false, [], []);
var nearTabletHighlightModuleName =
this.hand === RIGHT_HAND ? "RightNearTabletHighlight" : "LeftNearTabletHighlight";
var nearTabletHighlightModule = getEnabledModuleByName(nearTabletHighlightModuleName);
var nearTabletHighlightModuleReady = nearTabletHighlightModule ?
nearTabletHighlightModule.isReady(controllerData) : makeRunningValues(false, [], []);
return grabOverlayModuleReady.active || farGrabModuleReady.active || grabEntityModuleReady.active
return /* grabOverlayModuleReady.active || */ farGrabModuleReady.active || grabEntityModuleReady.active
/* || nearTabletHighlightModuleReady.active */ ;
};

View file

@ -18,7 +18,7 @@ var CONTOLLER_SCRIPTS = [
//"toggleAdvancedMovementForHandControllers.js",
"handTouch.js",
"controllerDispatcher.js",
"controllerModules/nearParentGrabOverlay.js",
// "controllerModules/nearParentGrabOverlay.js",
"controllerModules/stylusInput.js",
"controllerModules/equipEntity.js",
"controllerModules/nearTrigger.js",

View file

@ -164,6 +164,7 @@ WebTablet = function (url, width, dpi, hand, location, visible) {
parentID: this.tabletEntityID,
parentJointIndex: -1,
showKeyboardFocusHighlight: false,
grabbable: false,
visible: visible
});

View file

@ -6,7 +6,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/* global module, HMD, MyAvatar, controllerDispatcherPlugins:true, Quat, Vec3, Overlays, Xform, Mat4,
Selection, Uuid,
Selection, Uuid, Controller,
MSECS_PER_SEC:true , LEFT_HAND:true, RIGHT_HAND:true, FORBIDDEN_GRAB_TYPES:true,
HAPTIC_PULSE_STRENGTH:true, HAPTIC_PULSE_DURATION:true, ZERO_VEC:true, ONE_VEC:true,
DEFAULT_REGISTRATION_POINT:true, INCHES_TO_METERS:true,
@ -56,6 +56,7 @@
TEAR_AWAY_DISTANCE:true,
TEAR_AWAY_COUNT:true,
TEAR_AWAY_CHECK_TIME:true,
TELEPORT_DEADZONE: true,
NEAR_GRAB_DISTANCE: true,
distanceBetweenPointAndEntityBoundingBox:true,
entityIsEquipped:true,
@ -604,7 +605,7 @@ worldPositionToRegistrationFrameMatrix = function(wptrProps, pos) {
handsAreTracked = function () {
return Controller.getPoseValue(Controller.Standard.LeftHandIndex3).valid ||
Controller.getPoseValue(Controller.Standard.RightHandIndex3).valid;
}
};
if (typeof module !== 'undefined') {
module.exports = {