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