122 lines
5.4 KiB
JavaScript
Raw Normal View History

2017-08-31 18:06:55 -07:00
"use strict";
2017-08-23 17:32:41 -07:00
2017-11-13 13:37:53 -08:00
// webSurfaceLaserInput.js
2017-08-23 17:32:41 -07:00
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/* global Script, Entities, Controller, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule,
makeRunningValues, Messages, Quat, Vec3, makeDispatcherModuleParameters, Overlays, ZERO_VEC, HMD,
INCHES_TO_METERS, DEFAULT_REGISTRATION_POINT, getGrabPointSphereOffset, COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_ON_VALUE,
2017-11-28 15:37:36 -08:00
TRIGGER_OFF_VALUE, getEnabledModuleByName, PICK_MAX_DISTANCE, LaserPointers, RayPick, ContextOverlay, Picks, makeLaserParams
2017-08-23 17:32:41 -07:00
*/
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
2017-08-23 17:32:41 -07:00
Script.include("/~/system/libraries/controllers.js");
(function() {
2017-11-14 13:04:09 -08:00
function WebSurfaceLaserInput(hand) {
2017-08-23 17:32:41 -07:00
this.hand = hand;
2017-11-13 13:37:53 -08:00
this.running = false;
2017-08-23 17:32:41 -07:00
this.parameters = makeDispatcherModuleParameters(
120,
2017-08-23 17:32:41 -07:00
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
[],
2017-10-31 14:13:42 -07:00
100,
2017-11-28 15:37:36 -08:00
makeLaserParams(hand, true));
2017-08-23 17:32:41 -07:00
2017-09-20 14:10:10 -07:00
this.grabModuleWantsNearbyOverlay = function(controllerData) {
if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
var nearGrabName = this.hand === RIGHT_HAND ? "RightNearParentingGrabOverlay" : "LeftNearParentingGrabOverlay";
var nearGrabModule = getEnabledModuleByName(nearGrabName);
if (nearGrabModule) {
var candidateOverlays = controllerData.nearbyOverlayIDs[this.hand];
var grabbableOverlays = candidateOverlays.filter(function(overlayID) {
return Overlays.getProperty(overlayID, "grabbable");
});
var target = nearGrabModule.getTargetID(grabbableOverlays, controllerData);
if (target) {
return true;
}
}
}
return false;
};
2017-11-13 13:37:53 -08:00
this.getOtherModule = function() {
return this.hand === RIGHT_HAND ? leftOverlayLaserInput : rightOverlayLaserInput;
};
this.isPointingAtWebEntity = function(controllerData) {
2017-08-25 17:40:30 -07:00
var intersection = controllerData.rayPicks[this.hand];
var entityProperty = Entities.getEntityProperties(intersection.objectID);
var entityType = entityProperty.type;
if ((intersection.type === Picks.INTERSECTED_ENTITY && entityType === "Web")) {
return true;
2017-09-22 13:19:52 -07:00
}
return false;
};
this.isPointingAtOverlay = function(controllerData) {
var intersection = controllerData.rayPicks[this.hand];
return intersection.type === Picks.INTERSECTED_OVERLAY;
2017-08-31 18:06:55 -07:00
};
2017-08-25 14:20:31 -07:00
this.deleteContextOverlay = function() {
var farGrabModule = getEnabledModuleByName(this.hand === RIGHT_HAND ? "RightFarActionGrabEntity" : "LeftFarActionGrabEntity");
if (farGrabModule) {
var entityWithContextOverlay = farGrabModule.entityWithContextOverlay;
if (entityWithContextOverlay) {
ContextOverlay.destroyContextOverlay(entityWithContextOverlay);
farGrabModule.entityWithContextOverlay = false;
}
}
};
2018-01-04 15:00:17 +13:00
this.updateAllwaysOn = function () {
var PREFER_STYLUS_OVER_LASER = "preferStylusOverLaser";
this.parameters.handLaser.allwaysOn = !Settings.getValue(PREFER_STYLUS_OVER_LASER, false);
};
2017-08-25 14:20:31 -07:00
this.isReady = function (controllerData) {
2017-11-13 13:37:53 -08:00
var otherModuleRunning = this.getOtherModule().running;
if ((this.isPointingAtOverlay(controllerData) || this.isPointingAtWebEntity(controllerData)) &&
!otherModuleRunning) {
2018-01-04 15:00:17 +13:00
this.updateAllwaysOn();
if (this.parameters.handLaser.allwaysOn || controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE) {
return makeRunningValues(true, [], []);
}
2017-08-25 14:20:31 -07:00
}
return makeRunningValues(false, [], []);
};
2017-08-24 17:42:27 -07:00
2017-08-25 14:20:31 -07:00
this.run = function (controllerData, deltaTime) {
var grabModuleNeedsToRun = this.grabModuleWantsNearbyOverlay(controllerData);
2018-01-04 15:00:17 +13:00
if (!grabModuleNeedsToRun && (controllerData.triggerValues[this.hand] > TRIGGER_OFF_VALUE
|| this.parameters.handLaser.allwaysOn
&& (this.isPointingAtOverlay(controllerData) || this.isPointingAtWebEntity(controllerData)))) {
2017-11-13 13:37:53 -08:00
this.running = true;
return makeRunningValues(true, [], []);
}
this.deleteContextOverlay();
2017-11-13 13:37:53 -08:00
this.running = false;
return makeRunningValues(false, [], []);
2017-08-23 17:32:41 -07:00
};
2017-08-31 18:06:55 -07:00
}
2017-08-25 14:20:31 -07:00
2017-11-14 13:04:09 -08:00
var leftOverlayLaserInput = new WebSurfaceLaserInput(LEFT_HAND);
var rightOverlayLaserInput = new WebSurfaceLaserInput(RIGHT_HAND);
2017-08-23 17:32:41 -07:00
2017-11-14 13:04:09 -08:00
enableDispatcherModule("LeftWebSurfaceLaserInput", leftOverlayLaserInput);
enableDispatcherModule("RightWebSurfaceLaserInput", rightOverlayLaserInput);
2017-08-23 17:32:41 -07:00
2017-10-31 14:13:42 -07:00
function cleanup() {
2017-11-14 13:04:09 -08:00
disableDispatcherModule("LeftWebSurfaceLaserInput");
disableDispatcherModule("RightWebSurfaceLaserInput");
2017-11-01 11:36:36 -07:00
}
2017-10-31 14:13:42 -07:00
Script.scriptEnding.connect(cleanup);
2017-08-23 17:32:41 -07:00
}());