fix lazy collider (#1540)

* fix

* add test
This commit is contained in:
Trzeth
2026-02-24 14:24:18 +08:00
committed by GitHub
parent 6c9da566cc
commit 7332399d5e
2 changed files with 23 additions and 3 deletions
+5 -3
View File
@@ -23,6 +23,7 @@ LazyCollider::LazyCollider(LeafData&& leafData)
LazyCollider::LazyCollider(std::shared_ptr<const LazyCollider> base,
const mat3x4& transform) {
DEBUG_ASSERT(base != nullptr, logicErr, "invalid base ptr");
// keeps as an optimization
mat3x4 composed = transform;
// attempt to unwrap one level, if the base is also a transformed collider
// we do not unwrap if the base has updatedLeafBox
@@ -103,9 +104,10 @@ const LazyCollider::Built& LazyCollider::EnsureBuilt() const {
if (base_) {
const Built& baseBuilt = base_->base->EnsureBuilt();
// no need to propagate transform from built, we already computed the
// composed transform in the constructor
built_ = {baseBuilt.collider, base_->transform};
// propagate transform when collider was built after construct
mat3x4 composed = base_->transform;
if (baseBuilt.transform) composed = composed * Mat4(*baseBuilt.transform);
built_ = {baseBuilt.collider, composed};
if (base_->updatedLeafBox) {
auto leafBox = std::move(base_->updatedLeafBox.value());
base_ = std::nullopt;
+18
View File
@@ -1519,6 +1519,24 @@ TEST(BooleanComplex, HullMask) {
MeshGL mesh = ret.GetMeshGL();
}
TEST(BooleanComplex, LazyCollider) {
Manifold ele1 = Manifold::Cylinder(50, 50);
Manifold ele2 = Manifold::Cylinder(60, 30);
Manifold ele3 = Manifold::Cylinder(60, 40).Mirror(vec3{0, 0, 1});
Manifold ele4 = (ele1 + ele2).Mirror(vec3{0, 0, 1});
EXPECT_NEAR(ele4.Volume(), 418839, 1);
Manifold r1 = ele4 - ele2.Translate(vec3{0, 0, -20});
EXPECT_NEAR(r1.Volume(), 362577, 1);
Manifold r2 = ele4.Translate(vec3{0, 0, 1}) - ele3;
EXPECT_NEAR(r2.Volume(), 145656, 1);
}
#ifdef MANIFOLD_DEBUG
TEST(BooleanComplex, OffsetTriangulationFailure) {
ManifoldParamGuard guard;