From 834e44dd3a6d91cf7dc4d4cb67c116d060f3416f Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 30 Jan 2019 11:02:24 -0800 Subject: [PATCH] make polyline's with faceCamera not depend on normal --- interface/src/raypick/LaserPointer.cpp | 5 +++-- .../src/RenderablePolyLineEntityItem.cpp | 19 +++++++++++++------ .../entities-renderer/src/paintStroke.slv | 15 +++++++-------- .../system/libraries/entitySelectionTool.js | 4 +++- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index 694c420426..aeed65fbad 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -165,8 +165,9 @@ void LaserPointer::RenderState::update(const glm::vec3& origin, const glm::vec3& if (!getPathID().isNull()) { EntityItemProperties properties; QVector points; - points.append(origin); - points.append(end); + points.append(glm::vec3(0.0f)); + points.append(end - origin); + properties.setPosition(origin); properties.setLinePoints(points); properties.setVisible(true); properties.setIgnorePickIntersection(doesPathIgnorePicks()); diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 68371e4e13..7ad050e86c 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -128,7 +128,8 @@ void PolyLineEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPo } // Data - if (faceCamera != _faceCamera || glow != _glow) { + bool faceCameraChanged = faceCamera != _faceCamera; + if (faceCameraChanged || glow != _glow) { _faceCamera = faceCamera; _glow = glow; updateData(); @@ -148,7 +149,7 @@ void PolyLineEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPo _colors = entity->getStrokeColors(); _color = toGlm(entity->getColor()); } - if (_isUVModeStretch != isUVModeStretch || pointsChanged || widthsChanged || normalsChanged || colorsChanged || textureChanged) { + if (_isUVModeStretch != isUVModeStretch || pointsChanged || widthsChanged || normalsChanged || colorsChanged || textureChanged || faceCameraChanged) { _isUVModeStretch = isUVModeStretch; updateGeometry(); } @@ -220,11 +221,17 @@ void PolyLineEntityRenderer::updateGeometry() { // For last point we can assume binormals are the same since it represents the last two vertices of quad if (i < maxNumVertices - 1) { glm::vec3 tangent = _points[i + 1] - point; - binormal = glm::normalize(glm::cross(tangent, normal)); - // Check to make sure binormal is not a NAN. If it is, don't add to vertices vector - if (binormal.x != binormal.x) { - continue; + if (_faceCamera) { + // In faceCamera mode, we actually pass the tangent, and recompute the binormal in the shader + binormal = tangent; + } else { + binormal = glm::normalize(glm::cross(tangent, normal)); + + // Check to make sure binormal is not a NAN. If it is, don't add to vertices vector + if (binormal.x != binormal.x) { + continue; + } } } diff --git a/libraries/entities-renderer/src/paintStroke.slv b/libraries/entities-renderer/src/paintStroke.slv index c033d2c247..f591370186 100644 --- a/libraries/entities-renderer/src/paintStroke.slv +++ b/libraries/entities-renderer/src/paintStroke.slv @@ -36,24 +36,23 @@ void main(void) { TransformObject obj = getTransformObject(); _distanceFromCenter = -1.0 + 2.0 * evenVertex; vec4 position = vec4(vertex.positionAndUCoord.xyz, 1.0); - vec3 normal = vertex.normal.xyz; vec3 binormal = vertex.binormalAndHalfWidth.xyz; if (_polylineData.faceCameraGlow.x != 0.0) { vec4 posEye; - vec3 normalEye; - vec3 binormalEye; + vec3 tangentEye; <$transformModelToEyePos(cam, obj, position, posEye)$> - <$transformModelToEyeDir(cam, obj, normal, normalEye)$> - <$transformModelToEyeDir(cam, obj, binormal, binormalEye)$> + // See comment in RenderablePolyLineEntityItem.cpp: we actually pass in the tangent in faceCamera mode + <$transformModelToEyeDir(cam, obj, binormal, tangentEye)$> - vec3 tangentEye = cross(binormalEye, normalEye); // new normal faces the camera - normalEye = normalize(posEye.xyz); - binormalEye = normalize(cross(normalEye, tangentEye)); + vec3 normalEye = normalize(posEye.xyz); + + vec3 binormalEye = normalize(cross(normalEye, tangentEye)); posEye.xyz += _distanceFromCenter * vertex.binormalAndHalfWidth.w * binormalEye; <$transformEyeToClipPos(cam, posEye, gl_Position)$> <$transformEyeToWorldDir(cam, normalEye, _normalWS)$> } else { + vec3 normal = vertex.normal.xyz; position.xyz += _distanceFromCenter * vertex.binormalAndHalfWidth.w * binormal; <$transformModelToClipPos(cam, obj, position, gl_Position)$> <$transformModelToWorldDir(cam, obj, normal, _normalWS)$> diff --git a/scripts/system/libraries/entitySelectionTool.js b/scripts/system/libraries/entitySelectionTool.js index 4cbc44bc2b..c9f171b0aa 100644 --- a/scripts/system/libraries/entitySelectionTool.js +++ b/scripts/system/libraries/entitySelectionTool.js @@ -1013,6 +1013,8 @@ SelectionDisplay = (function() { return null; } + // We want to first check the drawInFront overlays (i.e. the handles, but really everything except the selectionBoxes) + // so that you can click on them even when they're behind things var overlayIncludesLayered = overlayIncludes.filter(function (value, index, arr) { return value != selectionBox && value != iconSelectionBox; }); @@ -1023,7 +1025,7 @@ SelectionDisplay = (function() { return value == selectionBox || value == iconSelectionBox; }); if (overlayIncludesNonLayered.length > 0) { - intersectObj = Overlays.findRayIntersection(queryRay, true, [], overlayExcludes); + intersectObj = Overlays.findRayIntersection(queryRay, true, overlayIncludesNonLayered, overlayExcludes); } }