I have used three-bvh-csg to subtract a cube from a 3d model and added the result outside the render or animation function. The issue is that I want to change the operation method from SUBTRACTION to ADDITION using GUI, before changing the operation when I do console.log(inside.operation)
the output that I get is 1, which I figure means that the operation is for SUBTRACTION and after changing the inside.operation = tbc.ADDITION
the console.log(inside. operation)
gives an output of 0 which means that the operation has been changed to ADDITION.
The only issue is that nothing is getting changes inside the scene only the console results are being changed.
The source code for this is quite long but here’s the geometry snippet that I am using to render the operation:
function loadLeePerrySmith() {
const loader = new GLTFLoader();
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath("/examples/jsm/libs/draco/");
loader.setDRACOLoader(dracoLoader);
loader.load(
"THE LINK IS PRIVATE CHANGE IT ACCORDINGLY",
function (gltf) {
result = gltf.scene.children[0];
let resultMaterial = new THREE.MeshPhongMaterial({
specular: 0x111111,
shininess: 5,
side: THREE.DoubleSide,
alphaToCoverage: true,
stencilWrite: true,
stencilRef: 0,
vertexColors: true,
});
result.material = resultMaterial.clone()
meshBrush = new tbc.Operation(result.geometry, resultMaterial);
{
inside = new tbc.Operation(
new THREE.BoxGeometry(10, 10, 10),
resultMaterial
);
meshBrush.add(inside);
inside.operation = tbc.ADDITION;
inside.position.set(0, -14, 15);
}
mesh = csgEvaluator.evaluateHierarchy(meshBrush);
{
const colorArray = new Uint8Array(
mesh.geometry.attributes.position.count * 3
);
colorArray.fill(255);
const colorAttr = new THREE.BufferAttribute(colorArray, 3, true);
colorAttr.setUsage(THREE.DynamicDrawUsage);
mesh.geometry.setAttribute("color", colorAttr);
mesh.geometry.boundsTree = mesh.geometry.computeBoundsTree();
//Center the model
mesh.scale.set(1, 1, 1);
let bounds = new THREE.Box3();
bounds.setFromObject(mesh);
mesh.position.sub(bounds.getCenter(new THREE.Vector3()));
mesh.updateMatrixWorld(true);
//Scale model to 100
bounds = new THREE.Box3().setFromObject(mesh);
let size = bounds.getSize(new THREE.Vector3());
let { max } = Math;
let maxsz = max(size.x, max(size.y, size.z));
mesh.scale.multiplyScalar(1 / maxsz);
mesh.needsAutoUpdate = true;
bounds.setFromObject(mesh);
mesh.position.sub(bounds.getCenter(new THREE.Vector3()));
}
mesh.material = result.material.clone();
mesh.geometry.computeBoundingBox()
scene.add(point);
point.add(mesh);
}
);
};