Merge pull request #12546 from druiz17/fix-hyperlink

Fix hyperlink when far/near grabbing enitities
This commit is contained in:
John Conklin II 2018-03-05 08:23:51 -08:00 committed by GitHub
commit 3f751bb5ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 110 additions and 7 deletions

View file

@ -6146,6 +6146,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe
scriptEngine->registerGlobalObject("Selection", DependencyManager::get<SelectionScriptingInterface>().data());
scriptEngine->registerGlobalObject("ContextOverlay", DependencyManager::get<ContextOverlayInterface>().data());
scriptEngine->registerGlobalObject("Wallet", DependencyManager::get<WalletScriptingInterface>().data());
scriptEngine->registerGlobalObject("AddressManager", DependencyManager::get<AddressManager>().data());
qScriptRegisterMetaType(scriptEngine.data(), OverlayIDtoScriptValue, OverlayIDfromScriptValue);

View file

@ -14,7 +14,7 @@
PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD,
DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE, ZERO_VEC, ensureDynamic,
getControllerWorldLocation, projectOntoEntityXYPlane, ContextOverlay, HMD, Reticle, Overlays, isPointingAtUI
Picks, makeLaserLockInfo Xform, makeLaserParams
Picks, makeLaserLockInfo Xform, makeLaserParams, AddressManager, getEntityParents
*/
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
@ -375,7 +375,7 @@ Script.include("/~/system/libraries/Xform.js");
return true;
}
return false;
}
};
this.isReady = function (controllerData) {
if (HMD.active) {
@ -449,11 +449,16 @@ Script.include("/~/system/libraries/Xform.js");
if (rayPickInfo.type === Picks.INTERSECTED_ENTITY) {
if (controllerData.triggerClicks[this.hand]) {
var entityID = rayPickInfo.objectID;
var targetProps = Entities.getEntityProperties(entityID, [
"dynamic", "shapeType", "position",
"rotation", "dimensions", "density",
"userData", "locked", "type"
"userData", "locked", "type", "href"
]);
if (targetProps.href !== "") {
AddressManager.handleLookupString(targetProps.href);
return makeRunningValues(false, [], []);
}
this.targetObject = new TargetObject(entityID, targetProps);
this.targetObject.parentProps = getEntityParents(targetProps);
@ -480,7 +485,8 @@ Script.include("/~/system/libraries/Xform.js");
this.grabbedDistance = rayPickInfo.distance;
}
if (otherFarGrabModule.grabbedThingID === this.grabbedThingID && otherFarGrabModule.distanceHolding) {
if (otherFarGrabModule.grabbedThingID === this.grabbedThingID &&
otherFarGrabModule.distanceHolding) {
this.prepareDistanceRotatingData(controllerData);
this.distanceRotate(otherFarGrabModule);
} else {

View file

@ -0,0 +1,95 @@
"use strict";
// nearGrabHyperLinkEntity.js
//
// Created by Dante Ruiz on 03/02/2018
//
// 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, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND,
getControllerJointIndex, getGrabbableData, enableDispatcherModule, disableDispatcherModule,
propsArePhysical, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, entityIsGrabbable,
Quat, Vec3, MSECS_PER_SEC, getControllerWorldLocation, makeDispatcherModuleParameters, makeRunningValues,
TRIGGER_OFF_VALUE, NEAR_GRAB_RADIUS, findGroupParent, entityIsCloneable, propsAreCloneDynamic, cloneEntity,
HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, BUMPER_ON_VALUE, AddressManager
*/
(function() {
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
Script.include("/~/system/libraries/controllers.js");
function NearGrabHyperLinkEntity(hand) {
this.hand = hand;
this.targetEntityID = null;
this.hyperlink = "";
this.parameters = makeDispatcherModuleParameters(
485,
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
[],
100);
this.getTargetProps = function(controllerData) {
var nearbyEntitiesProperties = controllerData.nearbyEntityProperties[this.hand];
var sensorScaleFactor = MyAvatar.sensorToWorldScale;
for (var i = 0; i < nearbyEntitiesProperties.length; i++) {
var props = nearbyEntitiesProperties[i];
if (props.distance > NEAR_GRAB_RADIUS * sensorScaleFactor) {
continue;
}
if (props.href !== "" && props.href !== undefined) {
return props;
}
}
return null;
};
this.isReady = function(controllerData) {
this.targetEntityID = null;
if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE &&
controllerData.secondaryValues[this.hand] < TRIGGER_OFF_VALUE) {
return makeRunningValues(false, [], []);
}
var targetProps = this.getTargetProps(controllerData);
if (targetProps) {
this.hyperlink = targetProps.href;
this.targetEntityID = targetProps.id;
return makeRunningValues(true, [], []);
}
return makeRunningValues(false, [], []);
};
this.run = function(controllerData) {
if ((controllerData.triggerClicks[this.hand] < TRIGGER_OFF_VALUE &&
controllerData.secondaryValues[this.hand] < TRIGGER_OFF_VALUE) || this.hyperlink === "") {
return makeRunningValues(false, [], []);
}
if (controllerData.triggerClicks[this.hand] ||
controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE) {
AddressManager.handleLookupString(this.hyperlink);
return makeRunningValues(false, [], []);
}
return makeRunningValues(true, [], []);
};
}
var leftNearGrabHyperLinkEntity = new NearGrabHyperLinkEntity(LEFT_HAND);
var rightNearGrabHyperLinkEntity = new NearGrabHyperLinkEntity(RIGHT_HAND);
enableDispatcherModule("LeftNearGrabHyperLink", leftNearGrabHyperLinkEntity);
enableDispatcherModule("RightNearGrabHyperLink", rightNearGrabHyperLinkEntity);
function cleanup() {
disableDispatcherModule("LeftNearGrabHyperLink");
disableDispatcherModule("RightNearGrabHyperLink");
}
Script.scriptEnding.connect(cleanup);
}());

View file

@ -31,7 +31,8 @@ var CONTOLLER_SCRIPTS = [
"controllerModules/scaleAvatar.js",
"controllerModules/hudOverlayPointer.js",
"controllerModules/mouseHMD.js",
"controllerModules/scaleEntity.js"
"controllerModules/scaleEntity.js",
"controllerModules/nearGrabHyperLinkEntity.js"
];
var DEBUG_MENU_ITEM = "Debug defaultScripts.js";

View file

@ -105,7 +105,8 @@ DISPATCHER_PROPERTIES = [
"density",
"dimensions",
"userData",
"type"
"type",
"href"
];
// priority -- a lower priority means the module will be asked sooner than one with a higher priority in a given update step
@ -233,7 +234,6 @@ entityIsDistanceGrabbable = function(props) {
return true;
};
getControllerJointIndex = function (hand) {
if (HMD.isHandControllerAvailable()) {
var controllerJointIndex = -1;