mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 17:41:12 +02:00
Bug-fix for touching deleted entities or overlays.
This commit is contained in:
parent
8a678dfb04
commit
5796cbc898
1 changed files with 39 additions and 12 deletions
|
@ -28,7 +28,7 @@ Script.include("/~/system/libraries/controllers.js");
|
||||||
//
|
//
|
||||||
|
|
||||||
var WANT_DEBUG = false;
|
var WANT_DEBUG = false;
|
||||||
var WANT_DEBUG_STATE = true;
|
var WANT_DEBUG_STATE = false;
|
||||||
var WANT_DEBUG_SEARCH_NAME = null;
|
var WANT_DEBUG_SEARCH_NAME = null;
|
||||||
|
|
||||||
var FORCE_IGNORE_IK = false;
|
var FORCE_IGNORE_IK = false;
|
||||||
|
@ -670,12 +670,12 @@ function sendTouchMoveEventToStylusTarget(hand, stylusTarget) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// will return undefined if entity does not exist.
|
||||||
function calculateStylusTargetFromEntity(stylusTip, entityID) {
|
function calculateStylusTargetFromEntity(stylusTip, entityID) {
|
||||||
var props = entityPropertiesCache.getProps(entityID);
|
var props = entityPropertiesCache.getProps(entityID);
|
||||||
|
if (props.rotation === undefined) {
|
||||||
// entity could have been deleted.
|
// if rotation is missing from props object, then this entity has probably been deleted.
|
||||||
if (props === undefined) {
|
return;
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// project stylus tip onto entity plane.
|
// project stylus tip onto entity plane.
|
||||||
|
@ -706,16 +706,18 @@ function calculateStylusTargetFromEntity(stylusTip, entityID) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// will return undefined if overlayID does not exist.
|
||||||
function calculateStylusTargetFromOverlay(stylusTip, overlayID) {
|
function calculateStylusTargetFromOverlay(stylusTip, overlayID) {
|
||||||
var overlayPosition = Overlays.getProperty(overlayID, "position");
|
var overlayPosition = Overlays.getProperty(overlayID, "position");
|
||||||
|
|
||||||
// overlay could have been deleted.
|
|
||||||
if (overlayPosition === undefined) {
|
if (overlayPosition === undefined) {
|
||||||
return undefined;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// project stylusTip onto overlay plane.
|
// project stylusTip onto overlay plane.
|
||||||
var overlayRotation = Overlays.getProperty(overlayID, "rotation");
|
var overlayRotation = Overlays.getProperty(overlayID, "rotation");
|
||||||
|
if (overlayRotation === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var normal = Vec3.multiplyQbyV(overlayRotation, {x: 0, y: 0, z: 1});
|
var normal = Vec3.multiplyQbyV(overlayRotation, {x: 0, y: 0, z: 1});
|
||||||
var distance = Vec3.dot(Vec3.subtract(stylusTip.position, overlayPosition), normal);
|
var distance = Vec3.dot(Vec3.subtract(stylusTip.position, overlayPosition), normal);
|
||||||
var position = Vec3.subtract(stylusTip.position, Vec3.multiply(normal, distance));
|
var position = Vec3.subtract(stylusTip.position, Vec3.multiply(normal, distance));
|
||||||
|
@ -724,16 +726,28 @@ function calculateStylusTargetFromOverlay(stylusTip, overlayID) {
|
||||||
var invRot = Quat.inverse(overlayRotation);
|
var invRot = Quat.inverse(overlayRotation);
|
||||||
var localPos = Vec3.multiplyQbyV(invRot, Vec3.subtract(position, overlayPosition));
|
var localPos = Vec3.multiplyQbyV(invRot, Vec3.subtract(position, overlayPosition));
|
||||||
var dpi = Overlays.getProperty(overlayID, "dpi");
|
var dpi = Overlays.getProperty(overlayID, "dpi");
|
||||||
|
if (dpi === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var dimensions;
|
var dimensions;
|
||||||
if (dpi) {
|
if (dpi) {
|
||||||
// Calculate physical dimensions for web3d overlay from resolution and dpi; "dimensions" property is used as a scale.
|
// Calculate physical dimensions for web3d overlay from resolution and dpi; "dimensions" property is used as a scale.
|
||||||
var resolution = Overlays.getProperty(overlayID, "resolution");
|
var resolution = Overlays.getProperty(overlayID, "resolution");
|
||||||
|
if (resolution === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
resolution.z = 1; // Circumvent divide-by-zero.
|
resolution.z = 1; // Circumvent divide-by-zero.
|
||||||
var scale = Overlays.getProperty(overlayID, "dimensions");
|
var scale = Overlays.getProperty(overlayID, "dimensions");
|
||||||
|
if (scale === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
scale.z = 0.01; // overlay dimensions are 2D, not 3D.
|
scale.z = 0.01; // overlay dimensions are 2D, not 3D.
|
||||||
dimensions = Vec3.multiplyVbyV(Vec3.multiply(resolution, INCHES_TO_METERS / dpi), scale);
|
dimensions = Vec3.multiplyVbyV(Vec3.multiply(resolution, INCHES_TO_METERS / dpi), scale);
|
||||||
} else {
|
} else {
|
||||||
dimensions = Overlays.getProperty(overlayID, "dimensions");
|
dimensions = Overlays.getProperty(overlayID, "dimensions");
|
||||||
|
if (dimensions === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!dimensions.z) {
|
if (!dimensions.z) {
|
||||||
dimensions.z = 0.01; // sometimes overlay dimensions are 2D, not 3D.
|
dimensions.z = 0.01; // sometimes overlay dimensions are 2D, not 3D.
|
||||||
}
|
}
|
||||||
|
@ -1631,22 +1645,31 @@ function MyController(hand) {
|
||||||
var stylusTargets = [];
|
var stylusTargets = [];
|
||||||
var candidateEntities = Entities.findEntities(tipPosition, WEB_DISPLAY_STYLUS_DISTANCE);
|
var candidateEntities = Entities.findEntities(tipPosition, WEB_DISPLAY_STYLUS_DISTANCE);
|
||||||
entityPropertiesCache.addEntities(candidateEntities);
|
entityPropertiesCache.addEntities(candidateEntities);
|
||||||
var i, props;
|
var i, props, stylusTarget;
|
||||||
for (i = 0; i < candidateEntities.length; i++) {
|
for (i = 0; i < candidateEntities.length; i++) {
|
||||||
props = entityPropertiesCache.getProps(candidateEntities[i]);
|
props = entityPropertiesCache.getProps(candidateEntities[i]);
|
||||||
if (props && (props.type === "Web" || this.isTablet(candidateEntities[i]))) {
|
if (props && (props.type === "Web" || this.isTablet(candidateEntities[i]))) {
|
||||||
stylusTargets.push(calculateStylusTargetFromEntity(this.stylusTip, candidateEntities[i]));
|
stylusTarget = calculateStylusTargetFromEntity(this.stylusTip, candidateEntities[i]);
|
||||||
|
if (stylusTarget) {
|
||||||
|
stylusTargets.push(stylusTarget);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the tabletScreen, if it is valid
|
// add the tabletScreen, if it is valid
|
||||||
if (HMD.tabletScreenID && HMD.tabletScreenID !== NULL_UUID && Overlays.getProperty(HMD.tabletScreenID, "visible")) {
|
if (HMD.tabletScreenID && HMD.tabletScreenID !== NULL_UUID && Overlays.getProperty(HMD.tabletScreenID, "visible")) {
|
||||||
stylusTargets.push(calculateStylusTargetFromOverlay(this.stylusTip, HMD.tabletScreenID));
|
stylusTarget = calculateStylusTargetFromOverlay(this.stylusTip, HMD.tabletScreenID);
|
||||||
|
if (stylusTarget) {
|
||||||
|
stylusTargets.push(stylusTarget);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the tablet home button.
|
// add the tablet home button.
|
||||||
if (HMD.homeButtonID && HMD.homeButtonID !== NULL_UUID && Overlays.getProperty(HMD.homeButtonID, "visible")) {
|
if (HMD.homeButtonID && HMD.homeButtonID !== NULL_UUID && Overlays.getProperty(HMD.homeButtonID, "visible")) {
|
||||||
stylusTargets.push(calculateStylusTargetFromOverlay(this.stylusTip, HMD.homeButtonID));
|
stylusTarget = calculateStylusTargetFromOverlay(this.stylusTip, HMD.homeButtonID);
|
||||||
|
if (stylusTarget) {
|
||||||
|
stylusTargets.push(stylusTarget);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var TABLET_MIN_HOVER_DISTANCE = 0.01;
|
var TABLET_MIN_HOVER_DISTANCE = 0.01;
|
||||||
|
@ -3582,6 +3605,10 @@ function MyController(hand) {
|
||||||
|
|
||||||
this.stylusTouchingExit = function () {
|
this.stylusTouchingExit = function () {
|
||||||
|
|
||||||
|
if (this.stylusTarget === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// special case to handle home button.
|
// special case to handle home button.
|
||||||
if (this.stylusTarget.overlayID === HMD.homeButtonID) {
|
if (this.stylusTarget.overlayID === HMD.homeButtonID) {
|
||||||
Messages.sendLocalMessage("home", this.stylusTarget.overlayID);
|
Messages.sendLocalMessage("home", this.stylusTarget.overlayID);
|
||||||
|
|
Loading…
Reference in a new issue