mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 06:49:47 +02:00
[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
This commit is contained in:
parent
d3e4d22ce1
commit
070660eb04
2 changed files with 58 additions and 6 deletions
|
@ -74,6 +74,23 @@ static std::array<GeometryCache::Shape, (GeometryCache::NUM_SHAPES - 1)> MAPPING
|
|||
GeometryCache::Cylinder,
|
||||
} };
|
||||
|
||||
static const std::array<const char * const, GeometryCache::NUM_SHAPES> 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<glm::vec3> 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<geometry::Vec>(i);
|
||||
outPointList.push_back(curNorm * entityHalfExtents);
|
||||
const int numUniquePoints = (int)uniqueVerts.size();
|
||||
const geometry::Vec &curVert = shapeVerts.get<geometry::Vec>(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<gpu::Stream::Format>(); // 1 for everyone
|
||||
|
|
|
@ -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<glm::vec3> &outPointList);
|
||||
|
||||
|
|
Loading…
Reference in a new issue