Open mesh after using three-bvh-csg

I try to remove some parts of a 3d-scanned stl-file using three-bvh-csg. I am able to perform the boolean difference but the exported mesh is now a open mesh. But for the next steps i need a closed mesh. Is this possible using three-bvh-csg or is there any other tool to get the wanted result?

This is the actual state and every green line is a open edge

I have attached the file bevor and after the operation
test.stl (2.6 MB)
test_after.stl (2.0 MB)

my code is:

for (var i = 0; i < this.objects.length; i++) {
            var object = this.objects[i];
            const brush1 = new Brush( object.geometry, object.material );
            var geo1 = new BoxGeometry(200,200,40);
            const brush2 = new Brush( geo1, new MeshBasicMaterial() );
            brush2.position.set(0,0,parseFloat(this.rangePlane.value) + 20.0);
            brush2.updateMatrixWorld(true);
            const csgEvaluator = new Evaluator();
            csgEvaluator.attributes = [ 'position', 'normal' ];
            csgEvaluator.useGroups = false;
            const result = csgEvaluator.evaluate( brush1, brush2, SUBTRACTION );
            result.geometry.normalizeNormals();
            var selectedObject = this.scene.getObjectById(object.id);
            this.scene.children[1].remove( selectedObject );
            this.scene.children[1].add( result );
        }

You can use BufferGeometryUtils.mergeVertices( theGeometry ), followed by a theGeometry.computeVertexNormals()
If the mesh has other attributes you may have to remove them first for the merging to work…
so if the merging doesn’t work by itself try:

import *as BufferGeometryUtils from "three/addons/utils/BufferGeometryUtils.js"
theGeometry.deleteAttribute('normal')   //May not be needed
theGeometry.deleteAttribute('uv') //May not be needed
theGeometry.deleteAttribute('color') //May not be needed

let fixedUpGeometry = BufferGeometryUtils.mergeVertices( theGeometry );

fixedUpGeometry.computeVertexNormals(); //may not be needed

yourMesh.geometry = fixedUpGeometry;

After performing boolean operations with three-bvh-csg, your resulting mesh is open. To close it, using a library like three-solidify-geometry. Simply apply the solidification process to the mesh, adjusting font thickness as needed to fill gaps and create a closed mesh.
import { SolidifyModifier } from ‘three-solidify-geometry’;

// Assuming ‘result’ is your open mesh geometry
const solidifyModifier = new SolidifyModifier();
const thickness = 0.1; // Adjust thickness as needed
const solidGeometry = solidifyModifier.modify(result.geometry, thickness);

// Add the solidified geometry to the scene
const solidMesh = new THREE.Mesh(solidGeometry, result.material);
this.scene.add(solidMesh);

I think this would give you a completely different mesh with different dimensions… Maaybe with a thickness of 0 it would do the right thing, but… i think OP just needs to mergeVertices?

Yeah three-bvh-csg using a clipping technique that results in “T-Vertices” - or a 1-to-many mapping between edges - so this is a limitation of three-bvh-csg, right now. From your uploaded it looks like this is what’s happening but the form otherwise looks solid.

In the future I would like to address this but I can’t say exactly when I’ll have the bandwidth. Some of the other CSG libraries out there (Manifold, three-csg-ts, etc) may produce better results for 3d printing at a slower speed. For now if you need real time results you could use three-bvh-csg for intermediate results and another library for the final trim.

1 Like

@Stylish_Font_Generator : Are you using AI/LLM to auto-answer questions on here?
If so, can you please mark them as such? I have been seeing answers from you that seem out of context or auto-generated… and you don’t seem to respond to questions. I’m not personally opposed to using GPT to answer questions, but could you provide some disclaimers if that is the case?

1 Like

Thanks for the reply’s.

I already have tried to use BufferGeometryUtils.mergeVertices

but without computeVertexNormals(). No success. I will try computeVertexNormals() but since
gkjohnson said this is limitation of three-bvh-csg i will give it not much faith.

I have tried three-csg-ts(way to slow) and manifold(was not able to implement it correctly, to complex for me)

Given that my program is running backend and frontend on the same computer i have found a workaround using pymeshlab in the python-backend to calculate the boolean and transfer it back to the frontend. The speed including the transfer is comparable to using three-bvh-csg and the mesh is perfect for my usecase.

I would also suggest trying the
ConvexGeometry, to create a convex hull from your results. This will only work for convex inputs however, so a shape like a heart won’t work.

Or the simplifymodifier approach mentioned by @Stylish_Font_Generator but with a 0 thickness.

Glad you found a solution!

I think it’s a bot.

1 Like