mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 08:06:11 +02:00
far-search rays work, but nothing else about far-grab.
This commit is contained in:
parent
505b564c62
commit
ec93172676
5 changed files with 236 additions and 2 deletions
|
@ -151,6 +151,9 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
|
|||
this.orderedPluginNames.sort(function (a, b) {
|
||||
return controllerDispatcherPlugins[a].priority < controllerDispatcherPlugins[b].priority;
|
||||
});
|
||||
|
||||
print("controllerDispatcher: new plugin order: " + JSON.stringify(this.orderedPluginNames));
|
||||
|
||||
controllerDispatcherPluginsNeedSort = false;
|
||||
}
|
||||
|
||||
|
@ -232,6 +235,7 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
|
|||
for (var pluginIndex = 0; pluginIndex < this.orderedPluginNames.length; pluginIndex++) {
|
||||
var orderedPluginName = this.orderedPluginNames[pluginIndex];
|
||||
var candidatePlugin = controllerDispatcherPlugins[orderedPluginName];
|
||||
|
||||
if (_this.slotsAreAvailableForPlugin(candidatePlugin) && candidatePlugin.isReady(controllerData, deltaTime)) {
|
||||
// this plugin will start. add it to the list of running plugins and mark the
|
||||
// activity-slots which this plugin consumes as "in use"
|
||||
|
|
|
@ -9,6 +9,13 @@
|
|||
/* global Camera, HMD, MyAvatar, controllerDispatcherPlugins,
|
||||
MSECS_PER_SEC, LEFT_HAND, RIGHT_HAND, NULL_UUID, AVATAR_SELF_ID, FORBIDDEN_GRAB_TYPES,
|
||||
HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, ZERO_VEC, ONE_VEC, DEFAULT_REGISTRATION_POINT, INCHES_TO_METERS,
|
||||
TRIGGER_OFF_VALUE,
|
||||
TRIGGER_ON_VALUE,
|
||||
PICK_MAX_DISTANCE,
|
||||
DEFAULT_SEARCH_SPHERE_DISTANCE,
|
||||
COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
|
||||
COLORS_GRAB_SEARCHING_FULL_SQUEEZE,
|
||||
COLORS_GRAB_DISTANCE_HOLD,
|
||||
makeDispatcherModuleParameters,
|
||||
enableDispatcherModule,
|
||||
disableDispatcherModule,
|
||||
|
@ -37,6 +44,17 @@ HAPTIC_PULSE_DURATION = 13.0;
|
|||
|
||||
DEFAULT_REGISTRATION_POINT = { x: 0.5, y: 0.5, z: 0.5 };
|
||||
|
||||
TRIGGER_OFF_VALUE = 0.1;
|
||||
TRIGGER_ON_VALUE = TRIGGER_OFF_VALUE + 0.05; // Squeezed just enough to activate search or near grab
|
||||
|
||||
PICK_MAX_DISTANCE = 500; // max length of pick-ray
|
||||
DEFAULT_SEARCH_SPHERE_DISTANCE = 1000; // how far from camera to search intersection?
|
||||
|
||||
COLORS_GRAB_SEARCHING_HALF_SQUEEZE = { red: 10, green: 10, blue: 255 };
|
||||
COLORS_GRAB_SEARCHING_FULL_SQUEEZE = { red: 250, green: 10, blue: 10 };
|
||||
COLORS_GRAB_DISTANCE_HOLD = { red: 238, green: 75, blue: 214 };
|
||||
|
||||
|
||||
|
||||
// priority -- a lower priority means the module will be asked sooner than one with a higher priority in a given update step
|
||||
// activitySlots -- indicates which "slots" must not yet be in use for this module to start
|
||||
|
|
|
@ -0,0 +1,213 @@
|
|||
"use strict";
|
||||
|
||||
// farActionGrabEntity.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, Controller, LaserPointers, RayPick, RIGHT_HAND, LEFT_HAND,
|
||||
getGrabPointSphereOffset, entityIsGrabbable,
|
||||
enableDispatcherModule, disableDispatcherModule,
|
||||
makeDispatcherModuleParameters,
|
||||
PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD,
|
||||
AVATAR_SELF_ID, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE,
|
||||
|
||||
*/
|
||||
|
||||
Script.include("/~/system/controllers/controllerDispatcherUtils.js");
|
||||
Script.include("/~/system/libraries/controllers.js");
|
||||
|
||||
(function() {
|
||||
|
||||
var PICK_WITH_HAND_RAY = true;
|
||||
|
||||
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: AVATAR_SELF_ID
|
||||
};
|
||||
var halfEnd = {
|
||||
type: "sphere",
|
||||
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: AVATAR_SELF_ID
|
||||
};
|
||||
var fullEnd = {
|
||||
type: "sphere",
|
||||
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: AVATAR_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 FarActionGrabEntity(hand) {
|
||||
this.hand = hand;
|
||||
this.grabbedThingID = null;
|
||||
this.actionID = null; // action this script created...
|
||||
|
||||
this.parameters = makeDispatcherModuleParameters(
|
||||
550,
|
||||
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
|
||||
[],
|
||||
100);
|
||||
|
||||
this.updateLaserPointer = function(controllerData, distanceHolding, distanceRotating) {
|
||||
var SEARCH_SPHERE_SIZE = 0.011;
|
||||
var MIN_SPHERE_SIZE = 0.0005;
|
||||
var radius = Math.max(1.2 * SEARCH_SPHERE_SIZE * this.intersectionDistance, MIN_SPHERE_SIZE);
|
||||
var dim = {x: radius, y: radius, z: radius};
|
||||
var mode = "hold";
|
||||
if (!distanceHolding && !distanceRotating) {
|
||||
// mode = (this.triggerSmoothedGrab() || this.secondarySqueezed()) ? "full" : "half";
|
||||
if (controllerData.triggerClicks[this.hand]
|
||||
// || this.secondarySqueezed() // XXX
|
||||
) {
|
||||
mode = "full";
|
||||
} else {
|
||||
mode = "half";
|
||||
}
|
||||
}
|
||||
|
||||
var laserPointerID = PICK_WITH_HAND_RAY ? this.laserPointer : this.headLaserPointer;
|
||||
if (mode === "full") {
|
||||
var fullEndToEdit = PICK_WITH_HAND_RAY ? this.fullEnd : fullEnd;
|
||||
fullEndToEdit.dimensions = dim;
|
||||
LaserPointers.editRenderState(laserPointerID, mode, {path: fullPath, end: fullEndToEdit});
|
||||
} else if (mode === "half") {
|
||||
var halfEndToEdit = PICK_WITH_HAND_RAY ? this.halfEnd : halfEnd;
|
||||
halfEndToEdit.dimensions = dim;
|
||||
LaserPointers.editRenderState(laserPointerID, mode, {path: halfPath, end: halfEndToEdit});
|
||||
}
|
||||
LaserPointers.enableLaserPointer(laserPointerID);
|
||||
LaserPointers.setRenderState(laserPointerID, mode);
|
||||
if (distanceHolding || distanceRotating) {
|
||||
LaserPointers.setLockEndUUID(laserPointerID, this.grabbedThingID, this.grabbedIsOverlay);
|
||||
} else {
|
||||
LaserPointers.setLockEndUUID(laserPointerID, null, false);
|
||||
}
|
||||
};
|
||||
|
||||
this.laserPointerOff = function() {
|
||||
var laserPointerID = PICK_WITH_HAND_RAY ? this.laserPointer : this.headLaserPointer;
|
||||
LaserPointers.disableLaserPointer(laserPointerID);
|
||||
};
|
||||
|
||||
|
||||
this.handToController = function() {
|
||||
return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
||||
};
|
||||
|
||||
this.isReady = function (controllerData) {
|
||||
if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
|
||||
this.updateLaserPointer(controllerData, false, false);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
this.run = function (controllerData) {
|
||||
if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE) {
|
||||
this.laserPointerOff();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// if we are doing a distance search and this controller moves into a position
|
||||
// where it could near-grab something, stop searching.
|
||||
var nearbyEntityProperties = controllerData.nearbyEntityProperties[this.hand];
|
||||
for (var i = 0; i < nearbyEntityProperties.length; i++) {
|
||||
var props = nearbyEntityProperties[i];
|
||||
if (entityIsGrabbable(props)) {
|
||||
this.laserPointerOff();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// this.updateLaserPointer(controllerData, false, false);
|
||||
|
||||
// var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
|
||||
// Entities.callEntityMethod(this.grabbedThingID, "continueFarGrab", args);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
this.cleanup = function () {
|
||||
LaserPointers.disableLaserPointer(this.laserPointer);
|
||||
LaserPointers.removeLaserPointer(this.laserPointer);
|
||||
};
|
||||
|
||||
this.halfEnd = halfEnd;
|
||||
this.fullEnd = fullEnd;
|
||||
this.laserPointer = LaserPointers.createLaserPointer({
|
||||
joint: (this.hand == RIGHT_HAND) ? "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" : "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND",
|
||||
filter: RayPick.PICK_ENTITIES | RayPick.PICK_OVERLAYS,
|
||||
maxDistance: PICK_MAX_DISTANCE,
|
||||
posOffset: getGrabPointSphereOffset(this.handToController()),
|
||||
renderStates: renderStates,
|
||||
faceAvatar: true,
|
||||
defaultRenderStates: defaultRenderStates
|
||||
});
|
||||
}
|
||||
|
||||
var leftFarActionGrabEntity = new FarActionGrabEntity(LEFT_HAND);
|
||||
var rightFarActionGrabEntity = new FarActionGrabEntity(RIGHT_HAND);
|
||||
|
||||
enableDispatcherModule("LeftFarActionGrabEntity", leftFarActionGrabEntity);
|
||||
enableDispatcherModule("RightFarActionGrabEntity", rightFarActionGrabEntity);
|
||||
|
||||
this.cleanup = function () {
|
||||
leftFarActionGrabEntity.cleanup();
|
||||
rightFarActionGrabEntity.cleanup();
|
||||
disableDispatcherModule("LeftFarActionGrabEntity");
|
||||
disableDispatcherModule("RightFarActionGrabEntity");
|
||||
};
|
||||
Script.scriptEnding.connect(this.cleanup);
|
||||
}());
|
|
@ -131,11 +131,9 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js");
|
|||
this.grabbedThingID = null;
|
||||
|
||||
var candidateOverlays = controllerData.nearbyOverlayIDs[this.hand];
|
||||
print("candidateOverlays.length = " + candidateOverlays.length);
|
||||
var grabbableOverlays = candidateOverlays.filter(function(overlayID) {
|
||||
return Overlays.getProperty(overlayID, "grabbable");
|
||||
});
|
||||
print("grabbableOverlays.length = " + grabbableOverlays.length);
|
||||
|
||||
if (grabbableOverlays.length > 0) {
|
||||
this.grabbedThingID = grabbableOverlays[0];
|
||||
|
|
|
@ -22,6 +22,7 @@ var CONTOLLER_SCRIPTS = [
|
|||
"controllerModules/nearParentGrabEntity.js",
|
||||
"controllerModules/nearParentGrabOverlay.js",
|
||||
"controllerModules/nearActionGrabEntity.js",
|
||||
"controllerModules/farActionGrabEntity.js",
|
||||
"controllerModules/tabletStylusInput.js"
|
||||
];
|
||||
|
||||
|
|
Loading…
Reference in a new issue