cleanup, model performance improvements

This commit is contained in:
SamGondelman 2018-07-24 13:25:49 -07:00
parent 318ef907b8
commit 645f905239
8 changed files with 93 additions and 95 deletions

View file

@ -566,12 +566,13 @@ bool Circle3DOverlay::findParabolaIntersection(const glm::vec3& origin, const gl
if (getInnerRadius() <= distanceToHit && distanceToHit <= getOuterRadius()) { if (getInnerRadius() <= distanceToHit && distanceToHit <= getOuterRadius()) {
float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance; float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance;
glm::vec3 forward = rotation * Vectors::FRONT;
if (localIntersectionVelocityZ > 0.0f) { if (localIntersectionVelocityZ > 0.0f) {
face = MIN_Z_FACE; face = MIN_Z_FACE;
surfaceNormal = rotation * Vectors::FRONT; surfaceNormal = forward;
} else { } else {
face = MAX_Z_FACE; face = MAX_Z_FACE;
surfaceNormal = rotation * -Vectors::FRONT; surfaceNormal = -forward;
} }
return true; return true;
} }

View file

@ -306,12 +306,13 @@ bool Image3DOverlay::findParabolaIntersection(const glm::vec3& origin, const glm
if (findParabolaRectangleIntersection(localOrigin, localVelocity, localAcceleration, dimensions, parabolicDistance)) { if (findParabolaRectangleIntersection(localOrigin, localVelocity, localAcceleration, dimensions, parabolicDistance)) {
float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance; float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance;
glm::vec3 forward = rotation * Vectors::FRONT;
if (localIntersectionVelocityZ > 0.0f) { if (localIntersectionVelocityZ > 0.0f) {
face = MIN_Z_FACE; face = MIN_Z_FACE;
surfaceNormal = rotation * Vectors::FRONT; surfaceNormal = forward;
} else { } else {
face = MAX_Z_FACE; face = MAX_Z_FACE;
surfaceNormal = rotation * -Vectors::FRONT; surfaceNormal = -forward;
} }
return true; return true;
} }

View file

@ -103,12 +103,13 @@ bool Planar3DOverlay::findParabolaIntersection(const glm::vec3& origin, const gl
if (findParabolaRectangleIntersection(localOrigin, localVelocity, localAcceleration, xyDimensions, parabolicDistance)) { if (findParabolaRectangleIntersection(localOrigin, localVelocity, localAcceleration, xyDimensions, parabolicDistance)) {
float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance; float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance;
glm::vec3 forward = rotation * Vectors::FRONT;
if (localIntersectionVelocityZ > 0.0f) { if (localIntersectionVelocityZ > 0.0f) {
face = MIN_Z_FACE; face = MIN_Z_FACE;
surfaceNormal = rotation * Vectors::FRONT; surfaceNormal = forward;
} else { } else {
face = MAX_Z_FACE; face = MAX_Z_FACE;
surfaceNormal = rotation * -Vectors::FRONT; surfaceNormal = -forward;
} }
return true; return true;
} }

View file

@ -105,7 +105,12 @@ bool Volume3DOverlay::findParabolaIntersection(const glm::vec3& origin, const gl
// we can use the AABox's ray intersection by mapping our origin and direction into the overlays frame // we can use the AABox's ray intersection by mapping our origin and direction into the overlays frame
// and testing intersection there. // and testing intersection there.
return _localBoundingBox.findParabolaIntersection(overlayFrameOrigin, overlayFrameVelocity, overlayFrameAcceleration, parabolicDistance, face, surfaceNormal); bool hit = _localBoundingBox.findParabolaIntersection(overlayFrameOrigin, overlayFrameVelocity, overlayFrameAcceleration, parabolicDistance, face, surfaceNormal);
if (hit) {
surfaceNormal = transform.getRotation() * surfaceNormal;
}
return hit;
} }
Transform Volume3DOverlay::evalRenderTransform() { Transform Volume3DOverlay::evalRenderTransform() {

View file

@ -165,12 +165,13 @@ bool TextEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, c
if (findParabolaRectangleIntersection(localOrigin, localVelocity, localAcceleration, xyDimensions, parabolicDistance)) { if (findParabolaRectangleIntersection(localOrigin, localVelocity, localAcceleration, xyDimensions, parabolicDistance)) {
float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance; float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance;
glm::vec3 forward = rotation * Vectors::FRONT;
if (localIntersectionVelocityZ > 0.0f) { if (localIntersectionVelocityZ > 0.0f) {
face = MIN_Z_FACE; face = MIN_Z_FACE;
surfaceNormal = rotation * Vectors::FRONT; surfaceNormal = forward;
} else { } else {
face = MAX_Z_FACE; face = MAX_Z_FACE;
surfaceNormal = rotation * -Vectors::FRONT; surfaceNormal = -forward;
} }
return true; return true;
} }

View file

@ -143,12 +143,13 @@ bool WebEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, co
if (findParabolaRectangleIntersection(localOrigin, localVelocity, localAcceleration, xyDimensions, parabolicDistance)) { if (findParabolaRectangleIntersection(localOrigin, localVelocity, localAcceleration, xyDimensions, parabolicDistance)) {
float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance; float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance;
glm::vec3 forward = rotation * Vectors::FRONT;
if (localIntersectionVelocityZ > 0.0f) { if (localIntersectionVelocityZ > 0.0f) {
face = MIN_Z_FACE; face = MIN_Z_FACE;
surfaceNormal = rotation * Vectors::FRONT; surfaceNormal = forward;
} else { } else {
face = MAX_Z_FACE; face = MAX_Z_FACE;
surfaceNormal = rotation * -Vectors::FRONT; surfaceNormal = -forward;
} }
return true; return true;
} else { } else {

View file

@ -67,7 +67,7 @@ protected:
PickCacheOptimizer<StylusTip> _stylusPickCacheOptimizer; PickCacheOptimizer<StylusTip> _stylusPickCacheOptimizer;
PickCacheOptimizer<PickParabola> _parabolaPickCacheOptimizer; PickCacheOptimizer<PickParabola> _parabolaPickCacheOptimizer;
static const unsigned int DEFAULT_PER_FRAME_TIME_BUDGET = 2 * USECS_PER_MSEC; static const unsigned int DEFAULT_PER_FRAME_TIME_BUDGET = 3 * USECS_PER_MSEC;
unsigned int _perFrameTimeBudget { DEFAULT_PER_FRAME_TIME_BUDGET }; unsigned int _perFrameTimeBudget { DEFAULT_PER_FRAME_TIME_BUDGET };
}; };

View file

@ -115,83 +115,65 @@ void TriangleSet::balanceOctree() {
// Determine of the given ray (origin/direction) in model space intersects with any triangles // Determine of the given ray (origin/direction) in model space intersects with any triangles
// in the set. If an intersection occurs, the distance and surface normal will be provided. // in the set. If an intersection occurs, the distance and surface normal will be provided.
bool TriangleSet::TriangleOctreeCell::findRayIntersectionInternal(const glm::vec3& origin, const glm::vec3& direction, bool TriangleSet::TriangleOctreeCell::findRayIntersectionInternal(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, Triangle& triangle, bool precision, int& trianglesTouched, bool allowBackface) { float& distance, BoxFace& face, Triangle& triangle, bool precision,
int& trianglesTouched, bool allowBackface) {
bool intersectedSomething = false; bool intersectedSomething = false;
float boxDistance = distance; float bestDistance = FLT_MAX;
float bestDistance = distance;
glm::vec3 surfaceNormal;
if (_bounds.findRayIntersection(origin, direction, boxDistance, face, surfaceNormal)) { if (precision) {
for (const auto& triangleIndex : _triangleIndices) {
// if our bounding box intersects at a distance greater than the current known const auto& thisTriangle = _allTriangles[triangleIndex];
// best distance, and our origin isn't inside the boounds, then we can safely float thisTriangleDistance;
// not check any of our triangles trianglesTouched++;
if (boxDistance > bestDistance && !_bounds.contains(origin)) { if (findRayTriangleIntersection(origin, direction, thisTriangle, thisTriangleDistance, allowBackface)) {
return false; if (thisTriangleDistance < bestDistance) {
} bestDistance = thisTriangleDistance;
intersectedSomething = true;
if (precision) { triangle = thisTriangle;
for (const auto& triangleIndex : _triangleIndices) {
const auto& thisTriangle = _allTriangles[triangleIndex];
float thisTriangleDistance;
trianglesTouched++;
if (findRayTriangleIntersection(origin, direction, thisTriangle, thisTriangleDistance, allowBackface)) {
if (thisTriangleDistance < bestDistance) {
bestDistance = thisTriangleDistance;
intersectedSomething = true;
triangle = thisTriangle;
distance = bestDistance;
}
} }
} }
} else {
intersectedSomething = true;
// FIXME: this needs to set triangle to something or it will carry the previous value
distance = boxDistance;
} }
} else {
intersectedSomething = true;
// FIXME: this needs to set triangle to something or it will carry the previous value
bestDistance = distance;
}
if (intersectedSomething) {
distance = bestDistance;
} }
return intersectedSomething; return intersectedSomething;
} }
bool TriangleSet::TriangleOctreeCell::findParabolaIntersectionInternal(const glm::vec3& origin, const glm::vec3& velocity, bool TriangleSet::TriangleOctreeCell::findParabolaIntersectionInternal(const glm::vec3& origin, const glm::vec3& velocity,
const glm::vec3& acceleration, float& parabolicDistance, BoxFace& face, Triangle& triangle, bool precision, const glm::vec3& acceleration, float& parabolicDistance,
int& trianglesTouched, bool allowBackface) { BoxFace& face, Triangle& triangle, bool precision,
int& trianglesTouched, bool allowBackface) {
bool intersectedSomething = false; bool intersectedSomething = false;
float boxDistance = parabolicDistance; float bestDistance = FLT_MAX;
float bestDistance = parabolicDistance;
glm::vec3 surfaceNormal;
if (_bounds.findParabolaIntersection(origin, velocity, acceleration, boxDistance, face, surfaceNormal)) { if (precision) {
for (const auto& triangleIndex : _triangleIndices) {
// if our bounding box intersects at a distance greater than the current known const auto& thisTriangle = _allTriangles[triangleIndex];
// best distance, and our origin isn't inside the boounds, then we can safely float thisTriangleDistance;
// not check any of our triangles trianglesTouched++;
if (boxDistance > bestDistance && !_bounds.contains(origin)) { if (findParabolaTriangleIntersection(origin, velocity, acceleration, thisTriangle, thisTriangleDistance, allowBackface)) {
return false; if (thisTriangleDistance < bestDistance) {
} bestDistance = thisTriangleDistance;
intersectedSomething = true;
if (precision) { triangle = thisTriangle;
for (const auto& triangleIndex : _triangleIndices) {
const auto& thisTriangle = _allTriangles[triangleIndex];
float thisTriangleDistance;
trianglesTouched++;
if (findParabolaTriangleIntersection(origin, velocity, acceleration, thisTriangle, thisTriangleDistance, allowBackface)) {
if (thisTriangleDistance < bestDistance) {
bestDistance = thisTriangleDistance;
intersectedSomething = true;
triangle = thisTriangle;
parabolicDistance = bestDistance;
}
} }
} }
} else {
intersectedSomething = true;
// FIXME: this needs to set triangle to something or it will carry the previous value
parabolicDistance = boxDistance;
} }
} else {
intersectedSomething = true;
// FIXME: this needs to set triangle to something or it will carry the previous value
bestDistance = parabolicDistance;
}
if (intersectedSomething) {
parabolicDistance = bestDistance;
} }
return intersectedSomething; return intersectedSomething;
@ -267,26 +249,24 @@ void TriangleSet::TriangleOctreeCell::insert(size_t triangleIndex) {
_triangleIndices.push_back(triangleIndex); _triangleIndices.push_back(triangleIndex);
} }
bool TriangleSet::TriangleOctreeCell::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool TriangleSet::TriangleOctreeCell::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
float& distance, BoxFace& face, Triangle& triangle, bool precision, int& trianglesTouched, BoxFace& face, Triangle& triangle, bool precision, int& trianglesTouched,
bool allowBackface) { bool allowBackface) {
if (_population < 1) { if (_population < 1) {
return false; // no triangles below here, so we can't intersect return false; // no triangles below here, so we can't intersect
} }
float bestLocalDistance = distance; float bestLocalDistance = FLT_MAX;
BoxFace bestLocalFace; BoxFace bestLocalFace;
Triangle bestLocalTriangle; Triangle bestLocalTriangle;
glm::vec3 bestLocalNormal; glm::vec3 bestLocalNormal;
bool intersects = false; bool intersects = false;
float boxDistance = FLT_MAX;
// if the ray intersects our bounding box, then continue // if the ray intersects our bounding box, then continue
if (getBounds().findRayIntersection(origin, direction, bestLocalDistance, bestLocalFace, bestLocalNormal)) { if (getBounds().findRayIntersection(origin, direction, boxDistance, bestLocalFace, bestLocalNormal)) {
// if the intersection with our bounding box, is greater than the current best distance (the distance passed in) // if the intersection with our bounding box, is greater than the current best distance (the distance passed in)
// then we know that none of our triangles can represent a better intersection and we can return // then we know that none of our triangles can represent a better intersection and we can return
if (bestLocalDistance > distance) { if (bestLocalDistance > distance) {
return false; return false;
} }
@ -314,11 +294,14 @@ bool TriangleSet::TriangleOctreeCell::findRayIntersection(const glm::vec3& origi
} }
} }
// also check our local triangle set // also check our local triangle set
if (findRayIntersectionInternal(origin, direction, childDistance, childFace, childTriangle, precision, trianglesTouched, allowBackface)) { float internalDistance = boxDistance;
if (childDistance < bestLocalDistance) { BoxFace internalFace;
bestLocalDistance = childDistance; Triangle internalTriangle;
bestLocalFace = childFace; if (findRayIntersectionInternal(origin, direction, internalDistance, internalFace, internalTriangle, precision, trianglesTouched, allowBackface)) {
bestLocalTriangle = childTriangle; if (internalDistance < childDistance) {
bestLocalDistance = internalDistance;
bestLocalFace = internalFace;
bestLocalTriangle = internalTriangle;
intersects = true; intersects = true;
} }
} }
@ -332,20 +315,22 @@ bool TriangleSet::TriangleOctreeCell::findRayIntersection(const glm::vec3& origi
} }
bool TriangleSet::TriangleOctreeCell::findParabolaIntersection(const glm::vec3& origin, const glm::vec3& velocity, bool TriangleSet::TriangleOctreeCell::findParabolaIntersection(const glm::vec3& origin, const glm::vec3& velocity,
const glm::vec3& acceleration, float& parabolicDistance, BoxFace& face, Triangle& triangle, bool precision, const glm::vec3& acceleration, float& parabolicDistance,
int& trianglesTouched, bool allowBackface) { BoxFace& face, Triangle& triangle, bool precision,
int& trianglesTouched, bool allowBackface) {
if (_population < 1) { if (_population < 1) {
return false; // no triangles below here, so we can't intersect return false; // no triangles below here, so we can't intersect
} }
float bestLocalDistance = parabolicDistance; float bestLocalDistance = FLT_MAX;
BoxFace bestLocalFace; BoxFace bestLocalFace;
Triangle bestLocalTriangle; Triangle bestLocalTriangle;
glm::vec3 bestLocalNormal; glm::vec3 bestLocalNormal;
bool intersects = false; bool intersects = false;
float boxDistance = FLT_MAX;
// if the ray intersects our bounding box, then continue // if the ray intersects our bounding box, then continue
if (getBounds().findParabolaIntersection(origin, velocity, acceleration, bestLocalDistance, bestLocalFace, bestLocalNormal)) { if (getBounds().findParabolaIntersection(origin, velocity, acceleration, boxDistance, bestLocalFace, bestLocalNormal)) {
// if the intersection with our bounding box, is greater than the current best distance (the distance passed in) // if the intersection with our bounding box, is greater than the current best distance (the distance passed in)
// then we know that none of our triangles can represent a better intersection and we can return // then we know that none of our triangles can represent a better intersection and we can return
if (bestLocalDistance > parabolicDistance) { if (bestLocalDistance > parabolicDistance) {
@ -375,11 +360,14 @@ bool TriangleSet::TriangleOctreeCell::findParabolaIntersection(const glm::vec3&
} }
} }
// also check our local triangle set // also check our local triangle set
if (findParabolaIntersectionInternal(origin, velocity, acceleration, childDistance, childFace, childTriangle, precision, trianglesTouched, allowBackface)) { float internalDistance = boxDistance;
if (childDistance < bestLocalDistance) { BoxFace internalFace;
bestLocalDistance = childDistance; Triangle internalTriangle;
bestLocalFace = childFace; if (findParabolaIntersectionInternal(origin, velocity, acceleration, internalDistance, internalFace, internalTriangle, precision, trianglesTouched, allowBackface)) {
bestLocalTriangle = childTriangle; if (internalDistance < childDistance) {
bestLocalDistance = internalDistance;
bestLocalFace = internalFace;
bestLocalTriangle = internalTriangle;
intersects = true; intersects = true;
} }
} }