Color array changes after applying CSG

I am applying csg using three-bvh-csg on a .glb model, the issue is that the .glb model has colors on it and I want to keep the colors even after the csg has been applied.

Here is the code responsible for applying the csg:

gltf.scene.traverse((e) => {
        if (e.isMesh) {
          result = e;
        }
      });
      result.geometry.center();
      result.geometry.computeVertexNormals();

      let resultMaterial = new THREE.MeshLambertMaterial({
        side: THREE.DoubleSide,
        alphaToCoverage: true,
        stencilWrite: true,
        stencilRef: 0,
        vertexColors: true,
      });

      meshBrush = new tbc.Operation(result.geometry, resultMaterial);
      {
        inside = new tbc.Operation(
          new THREE.BoxGeometry(100, 100, 30),
          resultMaterial
        );
        meshBrush.add(inside);
        inside.operation = tbc.SUBTRACTION;
        inside.position.set(0, 0, 50);
      }
      {
        const meshbrush_bounds = new THREE.Box3().setFromObject(meshBrush);
        const size = meshbrush_bounds.getSize(new THREE.Vector3());
        const maxDimension = Math.max(size.x, size.y, size.z);
        const scale = 1 / maxDimension;
        const minX = meshbrush_bounds.min.x * scale;
        const minY = meshbrush_bounds.min.y * scale;
        const minZ = meshbrush_bounds.min.z * scale;
        const maxX = meshbrush_bounds.max.x * scale;
        const maxY = meshbrush_bounds.max.y * scale;
        const maxZ = meshbrush_bounds.max.z * scale;

        const radius = 0.05;
        const height = 0.5;

        const cloneCylinderOne = new tbc.Operation(
          new THREE.CylinderGeometry(radius, radius, height * 2, 32),
          resultMaterial
        );
        meshBrush.add(cloneCylinderOne);
        cloneCylinderOne.operation = tbc.ADDITION;
        cloneCylinderOne.position.set(
          maxX - height,
          0,
          maxZ - radius - 0.025 - 0.4
        );
        cloneCylinderOne.rotation.z = Math.PI * 0.5;
      }
      console.log(meshBrush.geometry.attributes.color.array) // Glb color is present in the array
      mesh = csgEvaluator.evaluateHierarchy(meshBrush, result);
      console.log(mesh.geometry.attributes.color); // Color array is filled with 0

after the evaluation the color array is filled with 0, leaving me a really bright model, any help regarding this would be appreciated

I don’t know how you could preserve color, (unless the cutting mesh also has color information?)
If that doesn’t work, maybe you could keep a copy of the original, then map the colors from the original back to the new mesh manually… by inserting the vertices into a map so you can compare vertex positions quickly…

1 Like

Is this what you are searching for?

Here is the example from the documentation using multiple materials:
https://gkjohnson.github.io/three-bvh-csg/examples/bundle/multimaterial.html

1 Like

Actually I am not applying material, I am directly changing the colors of the vertices using the color attribute. The issue is that if I remap each individual color to the vertice either my window gets stuck or the color isnt mapping correctly

1 Like

I have raised an issue on github:

This is what I am getting after mapping:

Where as this is what it should look like: