gkjohnson / three-bvh-csg

A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh
MIT License
552 stars 45 forks source link

Keep root operand's material groups in boolean result? #132

Closed cptSwing closed 10 months ago

cptSwing commented 10 months ago

This isn't a bug, so please excuse me if this isn't the right place to ask!

Basically I am trying to bool shapes with useGroups = true, with the caveat that the resulting shape should retain the original material allocations - meaning, if I have a multi-material Mesh as root operand, and I subtract from it, I'd like the resulting carved-out portion to not have another, extra material, but to keep the respective materials assigned to the boolean root.

I've whipped up a quick CSB to demonstrate what I mean: https://codesandbox.io/s/eager-shamir-5zk5zf?file=%2Fsrc%2Findex.js

Instead of the having the faces of the square set to wholly different material, I'd like the red, green, hotpink materials to persist in the carved-out portion. Would it be possible to somehow take the underlying root's materials into account somehow?

Thanks for any pointers!

gkjohnson commented 10 months ago

How are you expecting this to look? There's no obvious way to apply the materials to the subtracted objects in a general case.