From 7c4869eb730d4dc4c7f93717218fdbb13f8e3add Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 1 Mar 2017 16:10:07 -0800 Subject: [PATCH 1/6] fix up parenting for 3d line overlays, have handControllerGrab use a child overlay for search/far-grab so the updates are smoother --- interface/src/ui/overlays/Line3DOverlay.cpp | 92 +++++++++++++------ interface/src/ui/overlays/Line3DOverlay.h | 12 ++- .../system/controllers/handControllerGrab.js | 82 ++++++++++------- 3 files changed, 124 insertions(+), 62 deletions(-) diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 23668bcc25..3c62a4b7a9 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -23,10 +23,13 @@ Line3DOverlay::Line3DOverlay() : Line3DOverlay::Line3DOverlay(const Line3DOverlay* line3DOverlay) : Base3DOverlay(line3DOverlay), - _start(line3DOverlay->_start), - _end(line3DOverlay->_end), _geometryCacheID(DependencyManager::get()->allocateID()) { + setParentID(line3DOverlay->getParentID()); + setParentJointIndex(line3DOverlay->getParentJointIndex()); + setLocalTransform(line3DOverlay->getLocalTransform()); + _direction = line3DOverlay->getDirection(); + _length = line3DOverlay->getLength(); } Line3DOverlay::~Line3DOverlay() { @@ -37,17 +40,14 @@ Line3DOverlay::~Line3DOverlay() { } glm::vec3 Line3DOverlay::getStart() const { - bool success; - glm::vec3 worldStart = localToWorld(_start, getParentID(), getParentJointIndex(), success); - if (!success) { - qDebug() << "Line3DOverlay::getStart failed"; - } - return worldStart; + return getPosition(); } glm::vec3 Line3DOverlay::getEnd() const { bool success; - glm::vec3 worldEnd = localToWorld(_end, getParentID(), getParentJointIndex(), success); + + glm::vec3 localEnd = getLocalEnd(); + glm::vec3 worldEnd = localToWorld(localEnd, getParentID(), getParentJointIndex(), success); if (!success) { qDebug() << "Line3DOverlay::getEnd failed"; } @@ -55,25 +55,28 @@ glm::vec3 Line3DOverlay::getEnd() const { } void Line3DOverlay::setStart(const glm::vec3& start) { - bool success; - _start = worldToLocal(start, getParentID(), getParentJointIndex(), success); - if (!success) { - qDebug() << "Line3DOverlay::setStart failed"; - } + setPosition(start); } void Line3DOverlay::setEnd(const glm::vec3& end) { bool success; - _end = worldToLocal(end, getParentID(), getParentJointIndex(), success); + + glm::vec3 localStart = getLocalStart(); + glm::vec3 localEnd = worldToLocal(end, getParentID(), getParentJointIndex(), success); if (!success) { qDebug() << "Line3DOverlay::setEnd failed"; + return; } + + glm::vec3 offset = localEnd - localStart; + _direction = glm::normalize(offset); + _length = glm::length(offset); } AABox Line3DOverlay::getBounds() const { auto extents = Extents{}; - extents.addPoint(_start); - extents.addPoint(_end); + extents.addPoint(getStart()); + extents.addPoint(getEnd()); extents.transform(getTransform()); return AABox(extents); @@ -90,18 +93,19 @@ void Line3DOverlay::render(RenderArgs* args) { glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); auto batch = args->_batch; if (batch) { - batch->setModelTransform(getTransform()); + // batch->setModelTransform(getTransform()); auto geometryCache = DependencyManager::get(); if (getIsDashedLine()) { // TODO: add support for color to renderDashedLine() geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); - geometryCache->renderDashedLine(*batch, _start, _end, colorv4, _geometryCacheID); + geometryCache->renderDashedLine(*batch, getStart(), getEnd(), colorv4, _geometryCacheID); } else if (_glow > 0.0f) { - geometryCache->renderGlowLine(*batch, _start, _end, colorv4, _glow, _glowWidth, _geometryCacheID); + geometryCache->renderGlowLine(*batch, getStart(), getEnd(), + colorv4, _glow, _glowWidth, _geometryCacheID); } else { geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); - geometryCache->renderLine(*batch, _start, _end, colorv4, _geometryCacheID); + geometryCache->renderLine(*batch, getStart(), getEnd(), colorv4, _geometryCacheID); } } } @@ -116,6 +120,10 @@ const render::ShapeKey Line3DOverlay::getShapeKey() { void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { QVariantMap properties = originalProperties; + glm::vec3 newStart(0.0f); + bool newStartSet { false }; + glm::vec3 newEnd(0.0f); + bool newEndSet { false }; auto start = properties["start"]; // if "start" property was not there, check to see if they included aliases: startPoint @@ -123,13 +131,18 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { start = properties["startPoint"]; } if (start.isValid()) { - setStart(vec3FromVariant(start)); + newStart = vec3FromVariant(start); + newStartSet = true; } properties.remove("start"); // so that Base3DOverlay doesn't respond to it auto localStart = properties["localStart"]; if (localStart.isValid()) { - _start = vec3FromVariant(localStart); + setLocalPosition(vec3FromVariant(localStart)); + // in case "end" isn't updated... + glm::vec3 offset = getLocalEnd() - getLocalStart(); + _direction = glm::normalize(offset); + _length = glm::length(offset); } properties.remove("localStart"); // so that Base3DOverlay doesn't respond to it @@ -139,15 +152,34 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { end = properties["endPoint"]; } if (end.isValid()) { - setEnd(vec3FromVariant(end)); + newEnd = vec3FromVariant(end); + newEndSet = true; } + properties.remove("end"); // so that Base3DOverlay doesn't respond to it auto localEnd = properties["localEnd"]; if (localEnd.isValid()) { - _end = vec3FromVariant(localEnd); + glm::vec3 offset = vec3FromVariant(localEnd) - getLocalStart(); + _direction = glm::normalize(offset); + _length = glm::length(offset); } properties.remove("localEnd"); // so that Base3DOverlay doesn't respond to it + auto length = properties["length"]; + if (length.isValid()) { + _length = length.toFloat(); + } + + Base3DOverlay::setProperties(properties); + + // these are saved until after Base3DOverlay::setProperties so parenting infomation can be set, first + if (newStartSet) { + setStart(newStart); + } + if (newEndSet) { + setEnd(newEnd); + } + auto glow = properties["glow"]; if (glow.isValid()) { setGlow(glow.toFloat()); @@ -161,7 +193,6 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { setGlow(glowWidth.toFloat()); } - Base3DOverlay::setProperties(properties); } QVariant Line3DOverlay::getProperty(const QString& property) { @@ -171,6 +202,15 @@ QVariant Line3DOverlay::getProperty(const QString& property) { if (property == "end" || property == "endPoint" || property == "p2") { return vec3toVariant(getEnd()); } + if (property == "localStart") { + return vec3toVariant(getLocalStart()); + } + if (property == "localEnd") { + return vec3toVariant(getLocalEnd()); + } + if (property == "length") { + return QVariant(getLength()); + } return Base3DOverlay::getProperty(property); } diff --git a/interface/src/ui/overlays/Line3DOverlay.h b/interface/src/ui/overlays/Line3DOverlay.h index b4e2ba8168..b67e5a0254 100644 --- a/interface/src/ui/overlays/Line3DOverlay.h +++ b/interface/src/ui/overlays/Line3DOverlay.h @@ -47,13 +47,17 @@ public: virtual void locationChanged(bool tellPhysics = true) override; -protected: - glm::vec3 _start; - glm::vec3 _end; + glm::vec3 getDirection() const { return _direction; } + float getLength() const { return _length; } + glm::vec3 getLocalStart() const { return getLocalPosition(); } + glm::vec3 getLocalEnd() const { return getLocalStart() + _direction * _length; } + +private: + glm::vec3 _direction; // in parent frame + float _length { 1.0 }; // in parent frame float _glow { 0.0 }; float _glowWidth { 0.0 }; int _geometryCacheID; }; - #endif // hifi_Line3DOverlay_h diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index ea76490b7b..c98793fc51 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -739,6 +739,10 @@ function MyController(hand) { this.stylus = null; this.homeButtonTouched = false; + this.controllerJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? + "_CONTROLLER_RIGHTHAND" : + "_CONTROLLER_LEFTHAND"); + // Until there is some reliable way to keep track of a "stack" of parentIDs, we'll have problems // when more than one avatar does parenting grabs on things. This script tries to work // around this with two associative arrays: previousParentID and previousParentJointIndex. If @@ -913,9 +917,7 @@ function MyController(hand) { ignoreRayIntersection: true, drawInFront: false, parentID: AVATAR_SELF_ID, - parentJointIndex: MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? - "_CONTROLLER_RIGHTHAND" : - "_CONTROLLER_LEFTHAND") + parentJointIndex: this.controllerJointIndex }); } }; @@ -999,29 +1001,51 @@ function MyController(hand) { this.overlayLineOn = function(closePoint, farPoint, color) { if (this.overlayLine === null) { - var lineProperties = { - glow: 1.0, - start: closePoint, - end: farPoint, - color: color, - ignoreRayIntersection: true, // always ignore this - drawInFront: true, // Even when burried inside of something, show it. - visible: true, - alpha: 1 - }; + var lineProperties; + if (this.hand === RIGHT_HAND) { + lineProperties = { + glow: 1.0, + lineWidth: 5, + start: closePoint, + end: farPoint, + color: color, + ignoreRayIntersection: true, // always ignore this + drawInFront: true, // Even when burried inside of something, show it. + visible: true, + alpha: 1, + parentID: AVATAR_SELF_ID, + parentJointIndex: this.controllerJointIndex + }; + } else { + lineProperties = { + glow: 1.0, + lineWidth: 5, + start: closePoint, + end: farPoint, + color: color, + ignoreRayIntersection: true, // always ignore this + drawInFront: true, // Even when burried inside of something, show it. + visible: true, + alpha: 1, + }; + } this.overlayLine = Overlays.addOverlay("line3d", lineProperties); } else { - Overlays.editOverlay(this.overlayLine, { - lineWidth: 5, - start: closePoint, - end: farPoint, - color: color, - visible: true, - ignoreRayIntersection: true, // always ignore this - drawInFront: true, // Even when burried inside of something, show it. - alpha: 1 - }); + if (this.hand === RIGHT_HAND) { + Overlays.editOverlay(this.overlayLine, { + // start: closePoint, + // end: farPoint, + length: Vec3.distance(farPoint, closePoint), + color: color, + }); + } else { + Overlays.editOverlay(this.overlayLine, { + start: closePoint, + end: farPoint, + color: color, + }); + } } }; @@ -2342,9 +2366,7 @@ function MyController(hand) { this.actionID = null; var handJointIndex; if (this.ignoreIK) { - handJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? - "_CONTROLLER_RIGHTHAND" : - "_CONTROLLER_LEFTHAND"); + handJointIndex = this.controllerJointIndex; } else { handJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "RightHand" : "LeftHand"); } @@ -3055,9 +3077,7 @@ function MyController(hand) { return true; } - var controllerJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? - "_CONTROLLER_RIGHTHAND" : - "_CONTROLLER_LEFTHAND"); + var controllerJointIndex = this.controllerJointIndex; if (props.parentJointIndex == controllerJointIndex) { return true; } @@ -3083,9 +3103,7 @@ function MyController(hand) { children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, handJointIndex)); // find children of faux controller joint - var controllerJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? - "_CONTROLLER_RIGHTHAND" : - "_CONTROLLER_LEFTHAND"); + var controllerJointIndex = this.controllerJointIndex; children = children.concat(Entities.getChildrenIDsOfJoint(MyAvatar.sessionUUID, controllerJointIndex)); children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, controllerJointIndex)); From 7f6b80365228a76c7c0e9a8a3deb3ae8bfc5e79e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 1 Mar 2017 17:27:32 -0800 Subject: [PATCH 2/6] 3d-line-overlays can now have an endParentID and endParentJointIndex --- interface/src/ui/overlays/Line3DOverlay.cpp | 78 +++++++++++++------ interface/src/ui/overlays/Line3DOverlay.h | 14 +++- .../system/controllers/handControllerGrab.js | 26 ++++--- 3 files changed, 85 insertions(+), 33 deletions(-) diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 3c62a4b7a9..99e418bf4f 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -30,6 +30,8 @@ Line3DOverlay::Line3DOverlay(const Line3DOverlay* line3DOverlay) : setLocalTransform(line3DOverlay->getLocalTransform()); _direction = line3DOverlay->getDirection(); _length = line3DOverlay->getLength(); + _endParentID = line3DOverlay->getEndParentID(); + _endParentJointIndex = line3DOverlay->getEndJointIndex(); } Line3DOverlay::~Line3DOverlay() { @@ -45,9 +47,18 @@ glm::vec3 Line3DOverlay::getStart() const { glm::vec3 Line3DOverlay::getEnd() const { bool success; + glm::vec3 localEnd; + glm::vec3 worldEnd; - glm::vec3 localEnd = getLocalEnd(); - glm::vec3 worldEnd = localToWorld(localEnd, getParentID(), getParentJointIndex(), success); + if (_endParentID != QUuid()) { + glm::vec3 localOffset = _direction * _length; + bool success; + worldEnd = localToWorld(localOffset, _endParentID, _endParentJointIndex, success); + return worldEnd; + } + + localEnd = getLocalEnd(); + worldEnd = localToWorld(localEnd, getParentID(), getParentJointIndex(), success); if (!success) { qDebug() << "Line3DOverlay::getEnd failed"; } @@ -60,15 +71,33 @@ void Line3DOverlay::setStart(const glm::vec3& start) { void Line3DOverlay::setEnd(const glm::vec3& end) { bool success; + glm::vec3 localStart; + glm::vec3 localEnd; + glm::vec3 offset; - glm::vec3 localStart = getLocalStart(); - glm::vec3 localEnd = worldToLocal(end, getParentID(), getParentJointIndex(), success); + if (_endParentID != QUuid()) { + offset = worldToLocal(end, _endParentID, _endParentJointIndex, success); + } else { + localStart = getLocalStart(); + localEnd = worldToLocal(end, getParentID(), getParentJointIndex(), success); + offset = localEnd - localStart; + } if (!success) { qDebug() << "Line3DOverlay::setEnd failed"; return; } + _direction = glm::normalize(offset); + _length = glm::length(offset); +} - glm::vec3 offset = localEnd - localStart; +void Line3DOverlay::setLocalEnd(const glm::vec3& localEnd) { + glm::vec3 offset; + if (_endParentID != QUuid()) { + offset = localEnd; + } else { + glm::vec3 localStart = getLocalStart(); + offset = localEnd - localStart; + } _direction = glm::normalize(offset); _length = glm::length(offset); } @@ -136,16 +165,6 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { } properties.remove("start"); // so that Base3DOverlay doesn't respond to it - auto localStart = properties["localStart"]; - if (localStart.isValid()) { - setLocalPosition(vec3FromVariant(localStart)); - // in case "end" isn't updated... - glm::vec3 offset = getLocalEnd() - getLocalStart(); - _direction = glm::normalize(offset); - _length = glm::length(offset); - } - properties.remove("localStart"); // so that Base3DOverlay doesn't respond to it - auto end = properties["end"]; // if "end" property was not there, check to see if they included aliases: endPoint if (!end.isValid()) { @@ -157,14 +176,6 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { } properties.remove("end"); // so that Base3DOverlay doesn't respond to it - auto localEnd = properties["localEnd"]; - if (localEnd.isValid()) { - glm::vec3 offset = vec3FromVariant(localEnd) - getLocalStart(); - _direction = glm::normalize(offset); - _length = glm::length(offset); - } - properties.remove("localEnd"); // so that Base3DOverlay doesn't respond to it - auto length = properties["length"]; if (length.isValid()) { _length = length.toFloat(); @@ -172,6 +183,27 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { Base3DOverlay::setProperties(properties); + auto endParentIDProp = properties["endParentID"]; + if (endParentIDProp.isValid()) { + _endParentID = QUuid(endParentIDProp.toString()); + } + auto endParentJointIndexProp = properties["endParentJointIndex"]; + if (endParentJointIndexProp.isValid()) { + _endParentJointIndex = endParentJointIndexProp.toInt(); + } + + auto localStart = properties["localStart"]; + if (localStart.isValid()) { + glm::vec3 tmpLocalEnd = getLocalEnd(); + setLocalStart(vec3FromVariant(localStart)); + setLocalEnd(tmpLocalEnd); + } + + auto localEnd = properties["localEnd"]; + if (localEnd.isValid()) { + setLocalEnd(vec3FromVariant(localEnd)); + } + // these are saved until after Base3DOverlay::setProperties so parenting infomation can be set, first if (newStartSet) { setStart(newStart); diff --git a/interface/src/ui/overlays/Line3DOverlay.h b/interface/src/ui/overlays/Line3DOverlay.h index b67e5a0254..aceecff6b2 100644 --- a/interface/src/ui/overlays/Line3DOverlay.h +++ b/interface/src/ui/overlays/Line3DOverlay.h @@ -15,7 +15,7 @@ class Line3DOverlay : public Base3DOverlay { Q_OBJECT - + public: static QString const TYPE; virtual QString getType() const override { return TYPE; } @@ -37,6 +37,9 @@ public: void setStart(const glm::vec3& start); void setEnd(const glm::vec3& end); + void setLocalStart(const glm::vec3& localStart) { setLocalPosition(localStart); } + void setLocalEnd(const glm::vec3& localEnd); + void setGlow(const float& glow) { _glow = glow; } void setGlowWidth(const float& glowWidth) { _glowWidth = glowWidth; } @@ -51,10 +54,19 @@ public: float getLength() const { return _length; } glm::vec3 getLocalStart() const { return getLocalPosition(); } glm::vec3 getLocalEnd() const { return getLocalStart() + _direction * _length; } + QUuid getEndParentID() const { return _endParentID; } + quint16 getEndJointIndex() const { return _endParentJointIndex; } private: + QUuid _endParentID; + quint16 _endParentJointIndex { INVALID_JOINT_INDEX }; + + // _direction and _length are in the parent's frame. If _endParentID is set, they are + // relative to that. Otherwise, they are relative to the local-start-position (which is the + // same as localPosition) glm::vec3 _direction; // in parent frame float _length { 1.0 }; // in parent frame + float _glow { 0.0 }; float _glowWidth { 0.0 }; int _geometryCacheID; diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index c98793fc51..ad5ab5e883 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -999,7 +999,7 @@ function MyController(hand) { } }; - this.overlayLineOn = function(closePoint, farPoint, color) { + this.overlayLineOn = function(closePoint, farPoint, color, farParentID) { if (this.overlayLine === null) { var lineProperties; if (this.hand === RIGHT_HAND) { @@ -1014,7 +1014,8 @@ function MyController(hand) { visible: true, alpha: 1, parentID: AVATAR_SELF_ID, - parentJointIndex: this.controllerJointIndex + parentJointIndex: this.controllerJointIndex, + endParentID: farParentID }; } else { lineProperties = { @@ -1033,12 +1034,16 @@ function MyController(hand) { } else { if (this.hand === RIGHT_HAND) { - Overlays.editOverlay(this.overlayLine, { - // start: closePoint, - // end: farPoint, - length: Vec3.distance(farPoint, closePoint), - color: color, - }); + if (farParentID && farParentID != NULL_UUID) { + Overlays.editOverlay(this.overlayLine, { + color: color, + }); + } else { + Overlays.editOverlay(this.overlayLine, { + length: Vec3.distance(farPoint, closePoint), + color: color, + }); + } } else { Overlays.editOverlay(this.overlayLine, { start: closePoint, @@ -2191,7 +2196,10 @@ function MyController(hand) { var rayPickInfo = this.calcRayPickInfo(this.hand); - this.overlayLineOn(rayPickInfo.searchRay.origin, Vec3.subtract(grabbedProperties.position, this.offsetPosition), COLORS_GRAB_DISTANCE_HOLD); + this.overlayLineOn(rayPickInfo.searchRay.origin, + Vec3.subtract(grabbedProperties.position, this.offsetPosition), + COLORS_GRAB_DISTANCE_HOLD, + this.grabbedEntity); var distanceToObject = Vec3.length(Vec3.subtract(MyAvatar.position, this.currentObjectPosition)); var success = Entities.updateAction(this.grabbedEntity, this.actionID, { From 93055a67a8809dbcade1151d60e478d877de1dad Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 2 Mar 2017 10:01:08 -0800 Subject: [PATCH 3/6] use new-style hand-lasers for both hands --- .../system/controllers/handControllerGrab.js | 61 ++++++------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index ad5ab5e883..49ef69c7b3 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -1001,53 +1001,30 @@ function MyController(hand) { this.overlayLineOn = function(closePoint, farPoint, color, farParentID) { if (this.overlayLine === null) { - var lineProperties; - if (this.hand === RIGHT_HAND) { - lineProperties = { - glow: 1.0, - lineWidth: 5, - start: closePoint, - end: farPoint, - color: color, - ignoreRayIntersection: true, // always ignore this - drawInFront: true, // Even when burried inside of something, show it. - visible: true, - alpha: 1, - parentID: AVATAR_SELF_ID, - parentJointIndex: this.controllerJointIndex, - endParentID: farParentID - }; - } else { - lineProperties = { - glow: 1.0, - lineWidth: 5, - start: closePoint, - end: farPoint, - color: color, - ignoreRayIntersection: true, // always ignore this - drawInFront: true, // Even when burried inside of something, show it. - visible: true, - alpha: 1, - }; - } + var lineProperties = { + glow: 1.0, + lineWidth: 5, + start: closePoint, + end: farPoint, + color: color, + ignoreRayIntersection: true, // always ignore this + drawInFront: true, // Even when burried inside of something, show it. + visible: true, + alpha: 1, + parentID: AVATAR_SELF_ID, + parentJointIndex: this.controllerJointIndex, + endParentID: farParentID + }; this.overlayLine = Overlays.addOverlay("line3d", lineProperties); } else { - if (this.hand === RIGHT_HAND) { - if (farParentID && farParentID != NULL_UUID) { - Overlays.editOverlay(this.overlayLine, { - color: color, - }); - } else { - Overlays.editOverlay(this.overlayLine, { - length: Vec3.distance(farPoint, closePoint), - color: color, - }); - } + if (farParentID && farParentID != NULL_UUID) { + Overlays.editOverlay(this.overlayLine, { + color: color, + }); } else { Overlays.editOverlay(this.overlayLine, { - start: closePoint, - end: farPoint, + length: Vec3.distance(farPoint, closePoint), color: color, }); } From 9b3c16d489902e1f46426d3125420b4e7cbaa588 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 2 Mar 2017 11:02:06 -0800 Subject: [PATCH 4/6] get handControllerGrab overlay lines working again --- scripts/system/controllers/handControllerGrab.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index f06cf0cead..b15100c699 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -795,9 +795,6 @@ function MyController(hand) { // for visualizations this.overlayLine = null; - - // for lights - this.overlayLine = null; this.searchSphere = null; this.waitForTriggerRelease = false; @@ -1032,11 +1029,13 @@ function MyController(hand) { if (farParentID && farParentID != NULL_UUID) { Overlays.editOverlay(this.overlayLine, { color: color, + endParentID: farParentID }); } else { Overlays.editOverlay(this.overlayLine, { length: Vec3.distance(farPoint, closePoint), color: color, + endParentID: farParentID }); } } @@ -2222,7 +2221,7 @@ function MyController(hand) { this.overlayLineOn(rayPickInfo.searchRay.origin, Vec3.subtract(grabbedProperties.position, this.offsetPosition), COLORS_GRAB_DISTANCE_HOLD, - this.grabbedEntity); + this.grabbedThingID); var distanceToObject = Vec3.length(Vec3.subtract(MyAvatar.position, this.currentObjectPosition)); var success = Entities.updateAction(this.grabbedThingID, this.actionID, { @@ -3194,7 +3193,8 @@ function MyController(hand) { children = children.concat(Entities.getChildrenIDsOfJoint(AVATAR_SELF_ID, controllerCRJointIndex)); children.forEach(function(childID) { - if (childID !== _this.stylus) { + if (childID !== _this.stylus && + childID !== _this.overlayLine) { // we appear to be holding something and this script isn't in a state that would be holding something. // unhook it. if we previously took note of this entity's parent, put it back where it was. This // works around some problems that happen when more than one hand or avatar is passing something around. From 5f570c1ba85d93f508587a30fa53de8f4b1e1532 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 2 Mar 2017 16:15:41 -0800 Subject: [PATCH 5/6] fix up bounds handling in Line3DOverlay --- interface/src/ui/overlays/Line3DOverlay.cpp | 28 ++++++++++++------- .../render-utils/src/RenderDeferredTask.cpp | 3 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 99e418bf4f..6c7ab3f411 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -53,7 +53,7 @@ glm::vec3 Line3DOverlay::getEnd() const { if (_endParentID != QUuid()) { glm::vec3 localOffset = _direction * _length; bool success; - worldEnd = localToWorld(localOffset, _endParentID, _endParentJointIndex, success); + worldEnd = localToWorld(getLocalStart() + localOffset, _endParentID, _endParentJointIndex, success); return worldEnd; } @@ -86,8 +86,13 @@ void Line3DOverlay::setEnd(const glm::vec3& end) { qDebug() << "Line3DOverlay::setEnd failed"; return; } - _direction = glm::normalize(offset); + _length = glm::length(offset); + if (_length > 0.0f) { + _direction = glm::normalize(offset); + } else { + _direction = glm::vec3(0.0f); + } } void Line3DOverlay::setLocalEnd(const glm::vec3& localEnd) { @@ -98,16 +103,18 @@ void Line3DOverlay::setLocalEnd(const glm::vec3& localEnd) { glm::vec3 localStart = getLocalStart(); offset = localEnd - localStart; } - _direction = glm::normalize(offset); _length = glm::length(offset); + if (_length > 0.0f) { + _direction = glm::normalize(offset); + } else { + _direction = glm::vec3(0.0f); + } } AABox Line3DOverlay::getBounds() const { auto extents = Extents{}; extents.addPoint(getStart()); extents.addPoint(getEnd()); - extents.transform(getTransform()); - return AABox(extents); } @@ -122,19 +129,20 @@ void Line3DOverlay::render(RenderArgs* args) { glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); auto batch = args->_batch; if (batch) { - // batch->setModelTransform(getTransform()); + batch->setModelTransform(Transform()); + glm::vec3 start = getStart(); + glm::vec3 end = getEnd(); auto geometryCache = DependencyManager::get(); if (getIsDashedLine()) { // TODO: add support for color to renderDashedLine() geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); - geometryCache->renderDashedLine(*batch, getStart(), getEnd(), colorv4, _geometryCacheID); + geometryCache->renderDashedLine(*batch, start, end, colorv4, _geometryCacheID); } else if (_glow > 0.0f) { - geometryCache->renderGlowLine(*batch, getStart(), getEnd(), - colorv4, _glow, _glowWidth, _geometryCacheID); + geometryCache->renderGlowLine(*batch, start, end, colorv4, _glow, _glowWidth, _geometryCacheID); } else { geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); - geometryCache->renderLine(*batch, getStart(), getEnd(), colorv4, _geometryCacheID); + geometryCache->renderLine(*batch, start, end, colorv4, _geometryCacheID); } } } diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 55a9c8b9e4..8ab65efd24 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -160,13 +160,14 @@ RenderDeferredTask::RenderDeferredTask(RenderFetchCullSortTask::Output items) { addJob("DrawOverlay3DOpaque", overlayOpaquesInputs, true); addJob("DrawOverlay3DTransparent", overlayTransparentsInputs, false); - // Debugging stages { // Bounds do not draw on stencil buffer, so they must come last addJob("DrawMetaBounds", metas); + addJob("DrawOverlayOpaqueBounds", overlayOpaques); + addJob("DrawOverlayTransparentBounds", overlayTransparents); // Debugging Deferred buffer job const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer)); From 88d6fe6a0421e1d252f85114af338a039588363f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 2 Mar 2017 16:26:56 -0800 Subject: [PATCH 6/6] fix offset relative to endParent --- interface/src/ui/overlays/Line3DOverlay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 6c7ab3f411..e1ea06c599 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -53,7 +53,7 @@ glm::vec3 Line3DOverlay::getEnd() const { if (_endParentID != QUuid()) { glm::vec3 localOffset = _direction * _length; bool success; - worldEnd = localToWorld(getLocalStart() + localOffset, _endParentID, _endParentJointIndex, success); + worldEnd = localToWorld(localOffset, _endParentID, _endParentJointIndex, success); return worldEnd; }