Skip to content

Harden mergeMeshes by preparing candidates and improving diagnostics#300

Merged
tracygardner merged 1 commit intomainfrom
codex/update-mergemeshes-to-prepare-candidate-meshes
Feb 15, 2026
Merged

Harden mergeMeshes by preparing candidates and improving diagnostics#300
tracygardner merged 1 commit intomainfrom
codex/update-mergemeshes-to-prepare-candidate-meshes

Conversation

@tracygardner
Copy link
Contributor

Motivation

  • mergeMeshes should normalize candidate meshes the same way intersectMeshes does so composite/child-only meshes and non-indexed geometry are handled reliably.
  • Provide clear, per-mesh diagnostics when CSG conversions fail to make multi-merge failures actionable.
  • Avoid running costly or fragile CSG loops when only zero or one valid mesh remains.

Description

  • Updated flockCSG.mergeMeshes(modelId, meshList) to run each candidate through prepareMeshForCSG before further checks and skipped meshes that return null with a mesh-name warning via console.warn.
  • Short-circuited prepared-mesh count: return null when none remain, and return/clone the single prepared mesh when exactly one remains (preserving metadata and blockKey) without entering the CSG add loop.
  • Wrapped each flock.BABYLON.CSG2.FromMesh(...) call (base mesh and each additional mesh) in targeted try/catch blocks that log which mesh failed conversion before re-throwing to trigger fallback cleanup.
  • Preserved the fallback BABYLON.Mesh.MergeMeshes path and ensured it only receives prepared meshes.
  • Added integration tests in tests/materials.test.js covering: single simple mesh merge, multiple valid meshes merge, one valid + one composite/child-only merge, and one valid + one invalid mesh (asserts warning and a valid result). Files changed: api/csg.js, tests/materials.test.js.

Testing

  • Added new integration coverage in tests/materials.test.js for the four scenarios described above (tests present but not fully executed here).
  • Performed syntax checks with node --check api/csg.js and node --check tests/materials.test.js which succeeded.
  • Attempted to run npm run test:api materials but it failed in this environment because Playwright’s Chromium browser binary is not installed (npx playwright install required), so browser-based tests could not be executed here.

Codex Task

@tracygardner tracygardner merged commit 2b1dfca into main Feb 15, 2026
5 checks passed
@tracygardner tracygardner deleted the codex/update-mergemeshes-to-prepare-candidate-meshes branch February 15, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant