making overlays use precisionPicking and adjust tablet screen position

This commit is contained in:
Dante Ruiz 2018-06-06 15:40:33 -07:00
parent d57d087752
commit 6ddc768f57
18 changed files with 48 additions and 37 deletions

View file

@ -283,7 +283,7 @@ QVariant Base3DOverlay::getProperty(const QString& property) {
} }
bool Base3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool Base3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal) { float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking) {
return false; return false;
} }

View file

@ -68,11 +68,11 @@ public:
virtual QVariant getProperty(const QString& property) override; virtual QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal); BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking = false);
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction, virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal, QVariantMap& extraInfo) { float& distance, BoxFace& face, glm::vec3& surfaceNormal, QVariantMap& extraInfo, bool precisionPicking = false) {
return findRayIntersection(origin, direction, distance, face, surfaceNormal); return findRayIntersection(origin, direction, distance, face, surfaceNormal, precisionPicking);
} }
virtual SpatialParentTree* getParentTree() const override; virtual SpatialParentTree* getParentTree() const override;

View file

@ -521,7 +521,7 @@ QVariant Circle3DOverlay::getProperty(const QString& property) {
} }
bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal) { BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking) {
// Scale the dimensions by the diameter // Scale the dimensions by the diameter
glm::vec2 dimensions = getOuterRadius() * 2.0f * getDimensions(); glm::vec2 dimensions = getOuterRadius() * 2.0f * getDimensions();

View file

@ -55,7 +55,7 @@ public:
void setMinorTickMarksColor(const xColor& value) { _minorTickMarksColor = value; } void setMinorTickMarksColor(const xColor& value) { _minorTickMarksColor = value; }
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal) override; BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking = false) override;
virtual Circle3DOverlay* createClone() const override; virtual Circle3DOverlay* createClone() const override;

View file

@ -35,7 +35,7 @@ public:
virtual Grid3DOverlay* createClone() const override; virtual Grid3DOverlay* createClone() const override;
// Grids are UI tools, and may not be intersected (pickable) // Grids are UI tools, and may not be intersected (pickable)
virtual bool findRayIntersection(const glm::vec3&, const glm::vec3&, float&, BoxFace&, glm::vec3&) override { return false; } virtual bool findRayIntersection(const glm::vec3&, const glm::vec3&, float&, BoxFace&, glm::vec3&, bool precisionPicking = false) override { return false; }
protected: protected:
Transform evalRenderTransform() override; Transform evalRenderTransform() override;

View file

@ -258,7 +258,7 @@ void Image3DOverlay::setURL(const QString& url) {
} }
bool Image3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool Image3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal) { float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking) {
if (_texture && _texture->isLoaded()) { if (_texture && _texture->isLoaded()) {
// Make sure position and rotation is updated. // Make sure position and rotation is updated.
Transform transform = getTransform(); Transform transform = getTransform();

View file

@ -43,7 +43,7 @@ public:
bool isTransparent() override { return Base3DOverlay::isTransparent() || _alphaTexture; } bool isTransparent() override { return Base3DOverlay::isTransparent() || _alphaTexture; }
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal) override; BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking = false) override;
virtual Image3DOverlay* createClone() const override; virtual Image3DOverlay* createClone() const override;

View file

@ -477,16 +477,16 @@ QVariant ModelOverlay::getProperty(const QString& property) {
} }
bool ModelOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool ModelOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal) { float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking) {
QVariantMap extraInfo; QVariantMap extraInfo;
return _model->findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, surfaceNormal, extraInfo); return _model->findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, surfaceNormal, extraInfo, precisionPicking);
} }
bool ModelOverlay::findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction, bool ModelOverlay::findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal, QVariantMap& extraInfo) { float& distance, BoxFace& face, glm::vec3& surfaceNormal, QVariantMap& extraInfo, bool precisionPicking) {
return _model->findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, surfaceNormal, extraInfo); return _model->findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, surfaceNormal, extraInfo, precisionPicking);
} }
ModelOverlay* ModelOverlay::createClone() const { ModelOverlay* ModelOverlay::createClone() const {

View file

@ -44,9 +44,9 @@ public:
void setProperties(const QVariantMap& properties) override; void setProperties(const QVariantMap& properties) override;
QVariant getProperty(const QString& property) override; QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal) override; BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking = false) override;
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction, virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal, QVariantMap& extraInfo) override; float& distance, BoxFace& face, glm::vec3& surfaceNormal, QVariantMap& extraInfo, bool precisionPicking = false) override;
virtual ModelOverlay* createClone() const override; virtual ModelOverlay* createClone() const override;

View file

@ -554,7 +554,7 @@ RayToOverlayIntersectionResult Overlays::findRayIntersectionVector(const PickRay
glm::vec3 thisSurfaceNormal; glm::vec3 thisSurfaceNormal;
QVariantMap thisExtraInfo; QVariantMap thisExtraInfo;
if (thisOverlay->findRayIntersectionExtraInfo(ray.origin, ray.direction, thisDistance, if (thisOverlay->findRayIntersectionExtraInfo(ray.origin, ray.direction, thisDistance,
thisFace, thisSurfaceNormal, thisExtraInfo)) { thisFace, thisSurfaceNormal, thisExtraInfo, precisionPicking)) {
bool isDrawInFront = thisOverlay->getDrawInFront(); bool isDrawInFront = thisOverlay->getDrawInFront();
if ((bestIsFront && isDrawInFront && thisDistance < bestDistance) if ((bestIsFront && isDrawInFront && thisDistance < bestDistance)
|| (!bestIsFront && (isDrawInFront || thisDistance < bestDistance))) { || (!bestIsFront && (isDrawInFront || thisDistance < bestDistance))) {

View file

@ -71,7 +71,7 @@ QVariant Planar3DOverlay::getProperty(const QString& property) {
} }
bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal) { float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking) {
// FIXME - face and surfaceNormal not being returned // FIXME - face and surfaceNormal not being returned
return findRayRectangleIntersection(origin, direction, getWorldOrientation(), getWorldPosition(), getDimensions(), distance); return findRayRectangleIntersection(origin, direction, getWorldOrientation(), getWorldPosition(), getDimensions(), distance);
} }

View file

@ -31,7 +31,7 @@ public:
virtual QVariant getProperty(const QString& property) override; virtual QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal) override; BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking = false) override;
protected: protected:
glm::vec2 _dimensions; glm::vec2 _dimensions;

View file

@ -76,7 +76,7 @@ QVariant Volume3DOverlay::getProperty(const QString& property) {
} }
bool Volume3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool Volume3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal) { float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking) {
// extents is the entity relative, scaled, centered extents of the entity // extents is the entity relative, scaled, centered extents of the entity
glm::mat4 worldToEntityMatrix; glm::mat4 worldToEntityMatrix;
Transform transform = getTransform(); Transform transform = getTransform();

View file

@ -31,7 +31,7 @@ public:
QVariant getProperty(const QString& property) override; QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal) override; BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking = false) override;
protected: protected:
// Centered local bounding box // Centered local bounding box

View file

@ -622,7 +622,7 @@ void Web3DOverlay::setScriptURL(const QString& scriptURL) {
} }
} }
bool Web3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face, glm::vec3& surfaceNormal) { bool Web3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking) {
glm::vec2 dimensions = getDimensions(); glm::vec2 dimensions = getDimensions();
glm::quat rotation = getWorldOrientation(); glm::quat rotation = getWorldOrientation();
glm::vec3 position = getWorldPosition(); glm::vec3 position = getWorldPosition();

View file

@ -53,7 +53,7 @@ public:
QVariant getProperty(const QString& property) override; QVariant getProperty(const QString& property) override;
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
BoxFace& face, glm::vec3& surfaceNormal) override; BoxFace& face, glm::vec3& surfaceNormal, bool precisionPicking = false) override;
virtual Web3DOverlay* createClone() const override; virtual Web3DOverlay* createClone() const override;

View file

@ -41,6 +41,8 @@ var LOCAL_BEZEL_HIGHLIGHT = Script.resourcesPath() + "images/buttonBezel_highlig
var LOCAL_NORMAL_BEZEL = Script.resourcesPath() + "images/buttonBezel.png"; var LOCAL_NORMAL_BEZEL = Script.resourcesPath() + "images/buttonBezel.png";
var LOCAL_TABLET_MODEL_PATH = Script.resourcesPath() + "meshes/tablet-with-home-button-small-bezel.fbx"; var LOCAL_TABLET_MODEL_PATH = Script.resourcesPath() + "meshes/tablet-with-home-button-small-bezel.fbx";
var HIGH_PRIORITY = 1;
var LOW_PRIORITY = 0;
var SUBMESH = 3; var SUBMESH = 3;
// returns object with two fields: // returns object with two fields:
@ -138,8 +140,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
Overlays.deleteOverlay(this.webOverlayID); Overlays.deleteOverlay(this.webOverlayID);
} }
var RAYPICK_OFFSET = 0.0007; // Sufficient for raypick to reliably intersect tablet screen before tablet model. var WEB_ENTITY_Z_OFFSET = (tabletDepth / 2.5) / sensorScaleFactor;
var WEB_ENTITY_Z_OFFSET = (tabletDepth / 2.0) / sensorScaleFactor + RAYPICK_OFFSET;
var WEB_ENTITY_Y_OFFSET = 1 * tabletScaleFactor; var WEB_ENTITY_Y_OFFSET = 1 * tabletScaleFactor;
var screenWidth = 0.9275 * tabletWidth; var screenWidth = 0.9275 * tabletWidth;
var screenHeight = 0.8983 * tabletHeight; var screenHeight = 0.8983 * tabletHeight;
@ -147,7 +148,7 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
name: "WebTablet Web", name: "WebTablet Web",
url: url, url: url,
localPosition: { x: 0, y: WEB_ENTITY_Y_OFFSET, z: -WEB_ENTITY_Z_OFFSET }, localPosition: { x: 0, y: WEB_ENTITY_Y_OFFSET, z: -WEB_ENTITY_Z_OFFSET },
localRotation: Quat.multiply(Quat.angleAxis(-0.25, X_AXIS), Quat.angleAxis(180, Y_AXIS)), localRotation: Quat.multiply(Quat.angleAxis(-0.5, X_AXIS), Quat.angleAxis(180, Y_AXIS)),
dimensions: {x: screenWidth, y: screenHeight, z: 0.1}, dimensions: {x: screenWidth, y: screenHeight, z: 0.1},
dpi: tabletDpi, dpi: tabletDpi,
color: { red: 255, green: 255, blue: 255 }, color: { red: 255, green: 255, blue: 255 },
@ -184,6 +185,9 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
albedoMap: HOME_BUTTON_TEXTURE albedoMap: HOME_BUTTON_TEXTURE
} }
}), }),
userData: JSON.stringify({
"grabbableKey": {"grabbable": false}
}),
parentMaterialName: 4, parentMaterialName: 4,
parentID: this.tabletEntityID parentID: this.tabletEntityID
}); });
@ -191,13 +195,17 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
this.homeButtonUnhighlightMaterial = Entities.addEntity({ this.homeButtonUnhighlightMaterial = Entities.addEntity({
type: "Material", type: "Material",
materialURL: "materialData", materialURL: "materialData",
priority: 1, localPosition: { x: 0.0, y: 0.0, z: 0.0 },
priority: HIGH_PRIORITY,
materialData: JSON.stringify({ materialData: JSON.stringify({
materials: { materials: {
albedoMap: LOCAL_NORMAL_BEZEL albedoMap: LOCAL_NORMAL_BEZEL
} }
}), }),
userData: JSON.stringify({
"grabbableKey": {"grabbable": false}
}),
visible: false, visible: false,
parentMaterialName: SUBMESH, parentMaterialName: SUBMESH,
parentID: this.tabletEntityID parentID: this.tabletEntityID
@ -206,7 +214,8 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
this.homeButtonHighlightMaterial = Entities.addEntity({ this.homeButtonHighlightMaterial = Entities.addEntity({
type: "Material", type: "Material",
materialURL: "materialData", materialURL: "materialData",
priority: 1, localPosition: { x: 0.0, y: 0.0, z: 0.0 },
priority: LOW_PRIORITY,
visible: false, visible: false,
materialData: JSON.stringify({ materialData: JSON.stringify({
materials: { materials: {
@ -214,8 +223,11 @@ WebTablet = function (url, width, dpi, hand, clientOnly, location, visible) {
} }
}), }),
userData: JSON.stringify({
"grabbableKey": {"grabbable": false}
}),
parentMaterialName: SUBMESH, parentMaterialName: SUBMESH,
parentID: null parentID: this.tabletEntityID
}, true); }, true);
this.receive = function (channel, senderID, senderUUID, localOnly) { this.receive = function (channel, senderID, senderUUID, localOnly) {
@ -467,22 +479,22 @@ WebTablet.prototype.calculateWorldAttitudeRelativeToCamera = function (windowPos
WebTablet.prototype.onHoverEnterOverlay = function (overlayID, pointerEvent) { WebTablet.prototype.onHoverEnterOverlay = function (overlayID, pointerEvent) {
if (overlayID === this.homeButtonID) { if (overlayID === this.homeButtonID) {
Entities.editEntity(this.homeButtonUnhighlightMaterial, {parentID: null}); Entities.editEntity(this.homeButtonUnhighlightMaterial, {priority: LOW_PRIORITY});
Entities.editEntity(this.homeButtonHighlightMaterial, {parentID: this.tabletEntityID}); Entities.editEntity(this.homeButtonHighlightMaterial, {priority: HIGH_PRIORITY});
} }
}; };
WebTablet.prototype.onHoverOverOverlay = function (overlayID, pointerEvent) { WebTablet.prototype.onHoverOverOverlay = function (overlayID, pointerEvent) {
if (overlayID !== this.homeButtonID) { if (overlayID !== this.homeButtonID) {
Entities.editEntity(this.homeButtonUnhighlightMaterial, {parentID: this.tabletEntityID}); Entities.editEntity(this.homeButtonUnhighlightMaterial, {priority: HIGH_PRIORITY});
Entities.editEntity(this.homeButtonHighlightMaterial, {parentID: null}); Entities.editEntity(this.homeButtonHighlightMaterial, {priority: LOW_PRIORITY});
} }
}; };
WebTablet.prototype.onHoverLeaveOverlay = function (overlayID, pointerEvent) { WebTablet.prototype.onHoverLeaveOverlay = function (overlayID, pointerEvent) {
if (overlayID === this.homeButtonID) { if (overlayID === this.homeButtonID) {
Entities.editEntity(this.homeButtonUnhighlightMaterial, {parentID: this.tabletEntityID}); Entities.editEntity(this.homeButtonUnhighlightMaterial, {priority: HIGH_PRIORITY});
Entities.editEntity(this.homeButtonHighlightMaterial, {parentID: null}); Entities.editEntity(this.homeButtonHighlightMaterial, {priority: LOW_PRIORITY});
} }
}; };

View file

@ -400,14 +400,13 @@ resizeTablet = function (width, newParentJointIndex, sensorToWorldScaleOverride)
}); });
// update webOverlay // update webOverlay
var RAYPICK_OFFSET = 0.0007; // Sufficient for raypick to reliably intersect tablet screen before tablet model. var WEB_ENTITY_Z_OFFSET = (tabletDepth / 2.5) * sensorScaleOffsetOverride;
var WEB_ENTITY_Z_OFFSET = (tabletDepth / 2.0) * sensorScaleOffsetOverride + RAYPICK_OFFSET;
var WEB_ENTITY_Y_OFFSET = 1 * tabletScaleFactor * sensorScaleOffsetOverride; var WEB_ENTITY_Y_OFFSET = 1 * tabletScaleFactor * sensorScaleOffsetOverride;
var screenWidth = 0.9275 * tabletWidth; var screenWidth = 0.9275 * tabletWidth;
var screenHeight = 0.8983 * tabletHeight; var screenHeight = 0.8983 * tabletHeight;
var landscape = Tablet.getTablet("com.highfidelity.interface.tablet.system").landscape; var landscape = Tablet.getTablet("com.highfidelity.interface.tablet.system").landscape;
Overlays.editOverlay(HMD.tabletScreenID, { Overlays.editOverlay(HMD.tabletScreenID, {
localPosition: { x: 0, y: WEB_ENTITY_Y_OFFSET, z: -WEB_ENTITY_Z_OFFSET }, localPosition: { x: 0, y: WEB_ENTITY_Y_OFFSET, z: -WEB_ENTITY_Z_OFFSET},
dimensions: {x: landscape ? screenHeight : screenWidth, y: landscape ? screenWidth : screenHeight, z: 0.1}, dimensions: {x: landscape ? screenHeight : screenWidth, y: landscape ? screenWidth : screenHeight, z: 0.1},
dpi: tabletDpi dpi: tabletDpi
}); });