Skip to content

Preserve MultiMaterial output in CSG mesh merges#299

Merged
tracygardner merged 1 commit intomainfrom
codex/investigate-csg-merging-color-issue
Feb 15, 2026
Merged

Preserve MultiMaterial output in CSG mesh merges#299
tracygardner merged 1 commit intomainfrom
codex/investigate-csg-merging-color-issue

Conversation

@tracygardner
Copy link
Contributor

Motivation

  • Fix a bug where merging/CSG operations always overwrote the merged mesh material with the first input material, collapsing different colored submeshes into a single material.
  • Ensure the fallback Mesh.MergeMeshes preserves submesh/MultiMaterial output so material indices produced by CSG/merge are not lost.

Description

  • Modify flockCSG.mergeMeshes() to prefer and preserve the mergedMesh.material when CSG or Mesh.MergeMeshes produces a MultiMaterial or valid material output instead of unconditionally replacing it (file changed: api/csg.js).
  • Enable the Mesh.MergeMeshes flags that preserve submeshes/MultiMaterial data (subdivideWithSubMeshes and the other relevant boolean) when falling back from CSG.
  • Add guarded fallback logic that only replaces missing or default materials with a clone of the reference mesh material, using an isDefaultMaterial helper and preserving backFaceCulling settings.
  • Leave existing metadata, normals rebuild, and physics-shape creation flow intact.

Testing

  • Ran npm run build, which completed successfully (build produced the dist output) ✅.
  • Ran npm run test:api, which failed in this environment because Playwright browser binaries are not installed and must be fetched via npx playwright install (test runner aborted) ⚠️.

Codex Task

@tracygardner tracygardner merged commit 92cd40e into main Feb 15, 2026
5 checks passed
@tracygardner tracygardner deleted the codex/investigate-csg-merging-color-issue branch February 15, 2026 10:45
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