# EdgeGeometry Issue after CSG Union operations

**URL:** <https://discourse.threejs.org/t/edgegeometry-issue-after-csg-union-operations/79897>\
**Category:** Questions\
**Tags:** edgesgeometry, csg, geometry\
**Created:** [March 21, 2025, 11:57am UTC](https://discourse.threejs.org/t/edgegeometry-issue-after-csg-union-operations/79897 "2025-03-21T11:57:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaxx\_sparrow](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jaxx_sparrow/32/47878_2.png) [@jaxx\_sparrow](https://discourse.threejs.org/u/jaxx_sparrow)\
**Post date:** [March 21, 2025, 11:57am UTC](https://discourse.threejs.org/t/edgegeometry-issue-after-csg-union-operations/79897/1 "2025-03-21T11:57:25Z")

</div>

**Issue**

I am using **three-csg** (`import CSG from '../../csg/three-csg'`) to perform Boolean unions on multiple meshes (created by extrude geometries). However, when I generate edges using `THREE.EdgesGeometry`, the final mesh still contains edges from the original meshes instead of showing only the correct outer edges of the unioned mesh.

**Example Workflow:**

**1. Mesh1, Mesh2, Mesh3** → Three separate meshes  
**2. Union Step 1**

```javascript
const goodMesh1 = CSG.union(mesh1, mesh2);

```

**Union Step 2:**

```javascript
const finalMesh = CSG.union(goodMesh1, mesh3);

```

**4. Generating Edges:**

```javascript
const edges = new THREE.EdgesGeometry(finalMesh.geometry);
const lineMaterial = new THREE.LineBasicMaterial({ color: 0x000000 });
const edgeLines = new THREE.LineSegments(edges, lineMaterial);
scene.add(edgeLines);

```

**Problem:** The generated edges include those of `mesh1` and `mesh2`, instead of showing only the correct outer edges of `finalMesh`.

**Thing we tried**

1. Custom OutlinePass (library)
2. Increased **threshold values** for angle detection in EdgesGeometry.
3. Converted geometry to **non-indexed** (`geometry.toNonIndexed()`).  
4.Tested with async function to wait for complete union operations
4. Use mergeVertices
5. used finalMesh.geometry.computeVertexNormals();

**Question:**

How can I ensure that `EdgesGeometry` only generates the **correct external edges** after a `CSG.union()` operation using `three-csg`? Is there a way to remove internal faces before generating edges?

Any insights would be appreciated! Thanks

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/2/1/216cb577bf83776a0f1066b39c50a935259570f9.png)

---

<div class="post-metadata">

**Author:** ![manthrax](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/manthrax/32/2596_2.png) [@manthrax](https://discourse.threejs.org/u/manthrax)\
**Post date:** [March 21, 2025, 3:40pm UTC](https://discourse.threejs.org/t/edgegeometry-issue-after-csg-union-operations/79897/2 "2025-03-21T15:40:52Z")

</div>

When you did mergeVertices, did you remove the uv and normal attributes first?

---

<div class="post-metadata">

**Author:** ![yesbird](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/yesbird/32/46097_2.png) [@yesbird](https://discourse.threejs.org/u/yesbird)\
**Post date:** [March 21, 2025, 10:51pm UTC](https://discourse.threejs.org/t/edgegeometry-issue-after-csg-union-operations/79897/3 "2025-03-21T22:51:59Z")

</div>

> [@jaxx\_sparrow](#):
>
> **three-csg**

Before you get too deep into **three-csg** , try to use [Manifold](https://github.com/elalish/manifold) - the most fast/robust CSG JS library.

Not long ago I explored all JS CSG solutions for my present [GemDesign](https://gemview.yesbird.online/cad/) project and found that Manifold is the best.

Here is example how to use it from Three.js: [Manifold - three.js Example](https://manifoldcad.org/three)

---

<div class="post-metadata">

**Author:** ![jaxx\_sparrow](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jaxx_sparrow/32/47878_2.png) [@jaxx\_sparrow](https://discourse.threejs.org/u/jaxx_sparrow)\
**Post date:** [March 24, 2025, 4:36am UTC](https://discourse.threejs.org/t/edgegeometry-issue-after-csg-union-operations/79897/4 "2025-03-24T04:36:27Z")

</div>

Hi Manthrax, tried this solution still no difference.

the line is still visible.

below is the code for reference

```javascript
handleAngleBlunt(edge, opposingEdge, part) {
    const { edgeOutwardNormal, opposingEdgeOutwardNormal, angleBetween } = this.determineAngleBetweenEdgesCoreGeometry(edge, opposingEdge)
    const angleValidation = (180 - angleBetween) < 89 || (180 - angleBetween) > 91

   
    let bspCornerNext = null
    let opposingNextEdge = null
    let opposingNextEdgeCore = null
    const cornerVertices= this.createCorner(edge, opposingEdge, edgeOutwardNormal, opposingEdgeOutwardNormal, part.inputOrientationUI[0])
    const cornerGeom = new THREE.ExtrudeGeometry(new THREE.Shape(cornerVertices), { bevelEnabled: false, depth: edge.layerOccupation.height })

    if(opposingEdge.nextEdge && opposingEdge.nextEdge.originalgeometry) {
      const nextCorner = this.createCornerGeometry(opposingEdge,opposingEdge.nextEdge, part)
      const cornerMeshNext = this.createMesh(nextCorner)
      const opposingNext =this.createTransformedMesh(opposingEdge.nextEdge.originalgeometry,opposingEdge.nextEdge.originalMatrix, opposingEdge.nextEdge.originalgeometry.isCsg)
      const opposingNextCore =this.createTransformedMesh(opposingEdge.nextEdge.coreGeometry,opposingEdge.nextEdge.coreMatrix, opposingEdge.nextEdge.coreGeometry.isCsg)
      bspCornerNext = CSG.fromMesh(cornerMeshNext)
      opposingNextEdge = CSG.fromMesh(opposingNext)
      opposingNextEdgeCore = CSG.fromMesh(opposingNextCore)
      opposingEdge.nextEdge.originalgeometry.isCsg = true
      opposingEdge.nextEdge.coreGeometry.isCsg = true
    }

    const cornerMesh = this.createMesh(cornerGeom)
    const edgeMesh = this.createTransformedMesh(edge.coreGeometry,edge.coreMatrix,edge.coreGeometry.isCsg)
    const oppEdgeMesh =this.createTransformedMesh(opposingEdge.originalgeometry,opposingEdge.originalMatrix, opposingEdge.originalgeometry.isCsg)
    const extendedEdgeMesh =this.createTransformedMesh(opposingEdge.coreGeometry,opposingEdge.coreMatrix,opposingEdge.coreGeometry.isCsg)
    const extendedEdgeMeshWithoutCSG =this.createTransformedMesh(opposingEdge.originalgeometryWithoutCsg, opposingEdge.coreMatrix, true)

    const bspCornerMesh = CSG.fromMesh(cornerMesh)
    const bspEdgeMesh = CSG.fromMesh(edgeMesh)
    const bspOppEdgeMesh = CSG.fromMesh(oppEdgeMesh)
    const bspExtendedEdgeMesh = CSG.fromMesh(extendedEdgeMesh)
    const bspExtendedEdgeMeshWithoutCSG = CSG.fromMesh(extendedEdgeMeshWithoutCSG)

    opposingEdge.originalgeometry.isCsg = true

     if ((180 - angleBetween) > 91 ) {
      // find intersector with next edge and current edge
      const bspIntersector = bspMeshNext.intersect(bspEdgeMesh)
      const finalMesh = bspIntersector.union(bspCornerMesh)
      let bspUnion = finalMesh.union(bspOppEdgeMesh)
      let finalMeshNextEdge = bspUnion

      const nextEdge = this.convertToMesh(finalMeshNextEdge)
      const currentEdge = this.convertToMesh(finalMeshCurrentEdge)
      nextEdge.geometry.deleteAttribute('uv');
      nextEdge.geometry.deleteAttribute('normal');
     // currentEdge.geometry.deleteAttribute('uv');
      //currentEdge.geometry.deleteAttribute('normal');
   
      mergeVertices(nextEdge.geometry);
      mergeVertices(currentEdge.geometry);

      // Recompute normals for better shading
      nextEdge.geometry.computeVertexNormals();
      currentEdge.geometry.computeVertexNormals();
      // Update opposingEdge's coreGeometry
      const opposingGeometry = nextEdge.geometry
      opposingEdge.coreGeometry = opposingGeometry
      // Update currentEdge's coreGeometry
      const edgeGeometry = currentEdge.geometry
      edge.coreGeometry = edgeGeometry

    }

  }

  createTransformedMesh(geometry, matrix, isCsg = false) {
    const mesh = this.createMesh(geometry)
    if(!isCsg) mesh.geometry.applyMatrix4(matrix)
    return mesh
  }

   createMesh(geometry) {
      return new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({ color: new THREE.Color('green') }))
    }

```

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/1/7/178d81b24cfdf4bcedc2893da06a489b3bd9bc1a.png)

---

<div class="post-metadata">

**Author:** ![jaxx\_sparrow](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jaxx_sparrow/32/47878_2.png) [@jaxx\_sparrow](https://discourse.threejs.org/u/jaxx_sparrow)\
**Post date:** [March 24, 2025, 4:37am UTC](https://discourse.threejs.org/t/edgegeometry-issue-after-csg-union-operations/79897/5 "2025-03-24T04:37:44Z")

</div>

Thanks yesbird for you time will try this and get back to you .

---

<div class="post-metadata">

**Author:** ![yesbird](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/yesbird/32/46097_2.png) [@yesbird](https://discourse.threejs.org/u/yesbird)\
**Post date:** [March 24, 2025, 2:39pm UTC](https://discourse.threejs.org/t/edgegeometry-issue-after-csg-union-operations/79897/6 "2025-03-24T14:39:27Z")

</div>

I had the similar issue and increasing subdivision was the cure, then I switched to Manifold to increase performance, details are here:

> [@Unwanted edge in CSG result](https://discourse.threejs.org/t/unwanted-edge-in-csg-result/79184):
>
> I am trying to apply wireframe on result of CSG subtract operation, library is [THREE-CSGMesh](https://github.com/manthrax/THREE-CSGMesh) by @manthrax (btw, many thanks for this port). Doing it this way I am getting strange artifact (please see attached image). wireframe = new THREE.LineSegments( new THREE.EdgesGeometry( mesh.geometry, 1 ), new THREE.LineBasicMaterial( { color: 0x888888, linewidth: 2 } ) ); scene.add(wireframe); Examining this mesh in console I found nothing special, so I am completely sta…

---

<div class="post-metadata">

**Author:** ![manthrax](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/manthrax/32/2596_2.png) [@manthrax](https://discourse.threejs.org/u/manthrax)\
**Post date:** [March 25, 2025, 3:02am UTC](https://discourse.threejs.org/t/edgegeometry-issue-after-csg-union-operations/79897/7 "2025-03-25T03:02:04Z")

</div>

mergeVertices returns a new geometry.. it doesn’t merge in place.

And you need to mergeVertices Before you do the CSG.. to make the mesh more watertight/manifold, which is the whole point.

(Not saying its guaranteed to work… but doing it after the fact, and not using the result definitely won’t work. 😃 )

I suspect you will have the same issues with manifold or mesh-bvh-csg unless you clean up the input meshes.
