Skip to content

Fix incorrect computation of bounding boxes #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

### ? - ?

##### Fixes :wrench:

- Fixed a bug introduced in v1.13.0 that could lead to incorrect axis-aligned bounding boxes.

### v1.13.1 - 2022-05-05

##### Breaking Changes :mega:
Expand Down
17 changes: 8 additions & 9 deletions Source/CesiumRuntime/Private/CesiumGltfPrimitiveComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,10 @@ struct CalcBoundsOperation {
glm::max(glm::length(halfAxes[0]), glm::length(halfAxes[1]));
sphereRadius = glm::max(sphereRadius, glm::length(halfAxes[2]));

FVector xs(halfAxes[0].x, halfAxes[1].x, halfAxes[2].x);
FVector ys(halfAxes[0].y, halfAxes[1].y, halfAxes[2].y);
FVector zs(halfAxes[0].z, halfAxes[1].z, halfAxes[2].z);

FBoxSphereBounds result;
result.Origin = VecMath::createVector(center);
result.SphereRadius = sphereRadius;
result.BoxExtent = FVector(xs.GetAbsMax(), ys.GetAbsMax(), zs.GetAbsMax());
result.BoxExtent = FVector(sphereRadius, sphereRadius, sphereRadius);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a comment that says the sphere only has to reach the side of the box, is that still applicable / correct?

Also is all the stuff with the half-axes necessary in the BoundingSphere conversion, can't we just convert the sphere radius from meters to centimeters? Could we assume getTilesetToUnrealWorld is a rigid transform + a meters to centimeters scaling?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to avoid making any assumptions about the transformation, since it's just a parameter to the method. So instead I construct a bounding box around the sphere, transform the box, and then build a sphere inset in the box. The comment is referring to the fact that the sphere only needs to be inset in the box, rather than fully contain it. There could very well be a better way to do this, but I think it works reasonably well.

return result;
}

Expand All @@ -207,14 +203,17 @@ struct CalcBoundsOperation {
double sphereRadius = glm::max(glm::length(corner1), glm::length(corner2));
sphereRadius = glm::max(sphereRadius, glm::length(corner3));

FVector xs(halfAxes[0].x, halfAxes[1].x, halfAxes[2].x);
FVector ys(halfAxes[0].y, halfAxes[1].y, halfAxes[2].y);
FVector zs(halfAxes[0].z, halfAxes[1].z, halfAxes[2].z);
double maxX = glm::abs(halfAxes[0].x) + glm::abs(halfAxes[1].x) +
glm::abs(halfAxes[2].x);
double maxY = glm::abs(halfAxes[0].y) + glm::abs(halfAxes[1].y) +
glm::abs(halfAxes[2].y);
double maxZ = glm::abs(halfAxes[0].z) + glm::abs(halfAxes[1].z) +
glm::abs(halfAxes[2].z);

FBoxSphereBounds result;
result.Origin = VecMath::createVector(center);
result.SphereRadius = sphereRadius;
result.BoxExtent = FVector(xs.GetAbsMax(), ys.GetAbsMax(), zs.GetAbsMax());
result.BoxExtent = FVector(maxX, maxY, maxZ);
return result;
}

Expand Down