From 070660eb04328813168c938ed410e51a5de759b2 Mon Sep 17 00:00:00 2001 From: LaShonda Hopper Date: Tue, 17 Oct 2017 18:18:10 -0400 Subject: [PATCH] [WL21389] Switch to _positionView & filter dupe verts for ShapeInfo (details below). * Adjusts GeometryCache::computeSimpleHullPointListForShape to utilize ShapeData::_positionView as opposed to _normalView. ** Also filters out duplicate points or points close enough to be considered duplicate vertices. This provides ShapeFactory with better point data and should reduce hits to the dedupe pass within createConvexHull. Tested: * Octagon & Tetrahedron ** They looked better than the prior commit, behaved closer to their shape as opposed to cone or narrow cylinder like. Note: * These changes are based on debug info observations using the Octagon and discussion with Andrew Meadows via Slack & https://github.com/highfidelity/hifi/pull/11336#pullrequestreview-69939120 Changes Committed: modified: libraries/render-utils/src/GeometryCache.cpp modified: libraries/render-utils/src/GeometryCache.h --- libraries/render-utils/src/GeometryCache.cpp | 63 ++++++++++++++++++-- libraries/render-utils/src/GeometryCache.h | 1 + 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 1cbb33252a..f83e8ae14f 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -74,6 +74,23 @@ static std::array MAPPING GeometryCache::Cylinder, } }; +static const std::array GEOCACHE_SHAPE_STRINGS{ { + "Line", + "Triangle", + "Quad", + "Hexagon", + "Octagon", + "Circle", + "Cube", + "Sphere", + "Tetrahedron", + "Octahedron", + "Dodecahedron", + "Icosahedron", + "Torus", + "Cone", + "Cylinder" + } }; const int GeometryCache::UNKNOWN_ID = -1; @@ -102,16 +119,38 @@ void GeometryCache::computeSimpleHullPointListForShape(const int entityShape, co return; } - const gpu::BufferView & shapeNorms = shapeData->_normalView; - assert(shapeData->_positionView._size == shapeNorms._size); - - const gpu::BufferView::Size numItems = shapeNorms.getNumElements(); + const gpu::BufferView & shapeVerts = shapeData->_positionView; + const gpu::BufferView::Size numItems = shapeVerts.getNumElements(); outPointList.reserve((int)numItems); + QVector uniqueVerts; + uniqueVerts.reserve((int)numItems); + const float SQUARED_MAX_INCLUSIVE_FILTER_DISTANCE = 0.0025f; for (gpu::BufferView::Index i = 0; i < (gpu::BufferView::Index)numItems; ++i) { - const geometry::Vec &curNorm = shapeNorms.get(i); - outPointList.push_back(curNorm * entityHalfExtents); + const int numUniquePoints = (int)uniqueVerts.size(); + const geometry::Vec &curVert = shapeVerts.get(i); + bool isUniquePoint = true; + + for (int uniqueIndex = 0; uniqueIndex < numUniquePoints; ++uniqueIndex) { + const geometry::Vec knownVert = uniqueVerts[uniqueIndex]; + const float distToKnownPoint = glm::length2(knownVert - curVert); + + if (fabsf(distToKnownPoint) <= SQUARED_MAX_INCLUSIVE_FILTER_DISTANCE) { + isUniquePoint = false; + break; + } + } + + if (!isUniquePoint) { + + //--EARLY ITERATION EXIT-- + continue; + } + + + uniqueVerts.push_back(curVert); + outPointList.push_back(curVert * entityHalfExtents); } } @@ -515,6 +554,18 @@ GeometryCache::Shape GeometryCache::getShapeForEntityShape(int entityShape) { return MAPPING[entityShape]; } +QString GeometryCache::stringFromShape(GeometryCache::Shape geoShape) +{ + if (((int)geoShape < 0) || ((int)geoShape >= (int)GeometryCache::NUM_SHAPES)) { + qCWarning(renderutils) << "GeometryCache::stringFromShape - Invalid shape " << geoShape << " specified."; + + //--EARLY EXIT-- + return "INVALID_GEOCACHE_SHAPE"; + } + + return GEOCACHE_SHAPE_STRINGS[geoShape]; +} + gpu::Stream::FormatPointer& getSolidStreamFormat() { if (!SOLID_STREAM_FORMAT) { SOLID_STREAM_FORMAT = std::make_shared(); // 1 for everyone diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 2e81c825be..5ee627bb93 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -153,6 +153,7 @@ public: /// the GeometryCache::Shape enum which aligns with the /// specified entityShapeEnum static GeometryCache::Shape getShapeForEntityShape(int entityShapeEnum); + static QString stringFromShape(GeometryCache::Shape geoShape); static void computeSimpleHullPointListForShape(int entityShape, const glm::vec3 &entityHalfExtents, QVector &outPointList);