Skip to content

Commit 32ee39f

Browse files
authored
Merge pull request #841 from CesiumGS/boundingbox
Fix incorrect computation of bounding boxes
2 parents 76d013a + 3b73e88 commit 32ee39f

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
### ? - ?
4+
5+
##### Fixes :wrench:
6+
7+
- Fixed a bug introduced in v1.13.0 that could lead to incorrect axis-aligned bounding boxes.
8+
39
### v1.13.1 - 2022-05-05
410

511
##### Breaking Changes :mega:

Source/CesiumRuntime/Private/CesiumGltfPrimitiveComponent.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,10 @@ struct CalcBoundsOperation {
183183
glm::max(glm::length(halfAxes[0]), glm::length(halfAxes[1]));
184184
sphereRadius = glm::max(sphereRadius, glm::length(halfAxes[2]));
185185

186-
FVector xs(halfAxes[0].x, halfAxes[1].x, halfAxes[2].x);
187-
FVector ys(halfAxes[0].y, halfAxes[1].y, halfAxes[2].y);
188-
FVector zs(halfAxes[0].z, halfAxes[1].z, halfAxes[2].z);
189-
190186
FBoxSphereBounds result;
191187
result.Origin = VecMath::createVector(center);
192188
result.SphereRadius = sphereRadius;
193-
result.BoxExtent = FVector(xs.GetAbsMax(), ys.GetAbsMax(), zs.GetAbsMax());
189+
result.BoxExtent = FVector(sphereRadius, sphereRadius, sphereRadius);
194190
return result;
195191
}
196192

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

210-
FVector xs(halfAxes[0].x, halfAxes[1].x, halfAxes[2].x);
211-
FVector ys(halfAxes[0].y, halfAxes[1].y, halfAxes[2].y);
212-
FVector zs(halfAxes[0].z, halfAxes[1].z, halfAxes[2].z);
206+
double maxX = glm::abs(halfAxes[0].x) + glm::abs(halfAxes[1].x) +
207+
glm::abs(halfAxes[2].x);
208+
double maxY = glm::abs(halfAxes[0].y) + glm::abs(halfAxes[1].y) +
209+
glm::abs(halfAxes[2].y);
210+
double maxZ = glm::abs(halfAxes[0].z) + glm::abs(halfAxes[1].z) +
211+
glm::abs(halfAxes[2].z);
213212

214213
FBoxSphereBounds result;
215214
result.Origin = VecMath::createVector(center);
216215
result.SphereRadius = sphereRadius;
217-
result.BoxExtent = FVector(xs.GetAbsMax(), ys.GetAbsMax(), zs.GetAbsMax());
216+
result.BoxExtent = FVector(maxX, maxY, maxZ);
218217
return result;
219218
}
220219

0 commit comments

Comments
 (0)