OctreeCSG icon indicating copy to clipboard operation
OctreeCSG copied to clipboard

There was a problem during the 3D boolean operation

Open yuhaozhou2000 opened this issue 2 years ago • 4 comments

image

here is the code: const geometry = new THREE.BoxGeometry(10, 10, 10); const material1 = new THREE.MeshBasicMaterial({ color: 0xff0000, transparent: true, opacity: 0.3, }); const material2 = new THREE.MeshBasicMaterial({ color: 0x00ff00, transparent: true, opacity: 0.3, }); const mesh1 = new THREE.Mesh(geometry, material1); const mesh2 = new THREE.Mesh(geometry.clone(), material2); mesh2.position.set(5, 5, 5); const octreeA = OctreeCSG.fromMesh(mesh1); const octreeB = OctreeCSG.fromMesh(mesh2); const resultOctree = OctreeCSG.subtract(octreeA, octreeB); const resultMesh = OctreeCSG.toMesh(resultOctree, mesh1.material.clone()); mesh2.position.set(-5, -5,-5); const octreeC = OctreeCSG.fromMesh(mesh2); const octreeD = OctreeCSG.fromMesh(resultMesh); const resultOctree2 = OctreeCSG.subtract(octreeD, octreeC); const resultMesh2 = OctreeCSG.toMesh(resultOctree2, mesh1.material.clone()); scene.add(resultMesh2);

yuhaozhou2000 avatar May 04 '23 01:05 yuhaozhou2000

Interesting, I will check it out.

For now the issues seems to go away if you offset the position a little -

const geometry = new THREE.BoxGeometry(10, 10, 10);
const material1 = new THREE.MeshBasicMaterial({
color: 0xff0000,
transparent: true,
opacity: 0.3,
});
const material2 = new THREE.MeshBasicMaterial({
color: 0x00ff00,
transparent: true,
opacity: 0.3,
});
const mesh1 = new THREE.Mesh(geometry, material1);
const mesh2 = new THREE.Mesh(geometry.clone(), material2);
mesh2.position.set(5.0001, 5.0001, 5.0001);
const octreeA = OctreeCSG.fromMesh(mesh1);
const octreeB = OctreeCSG.fromMesh(mesh2);
const resultOctree = OctreeCSG.subtract(octreeA, octreeB);
const resultMesh = OctreeCSG.toMesh(resultOctree, mesh1.material.clone());
mesh2.position.set(-5.0001, -5.0001,-5.0001);
const octreeC = OctreeCSG.fromMesh(mesh2);
const octreeD = OctreeCSG.fromMesh(resultMesh);
const resultOctree2 = OctreeCSG.subtract(octreeD, octreeC);
const resultMesh2 = OctreeCSG.toMesh(resultOctree2, mesh1.material.clone());
scene.add(resultMesh2);

giladdarshan avatar May 12 '23 06:05 giladdarshan

Yes, this can indeed temporarily solve this problem, but could you tell me the approximate reason for the problem? I want to fix it. Or could you fix this problem ? thanks a ton!!!

yuhaozhou2000 avatar May 16 '23 03:05 yuhaozhou2000

I may have identified the issue. The reason behind this problem is not due to accuracy but rather the deletion rules set.

Subtract:

  1. Delete all polygons in A that are: a. inside and coplanar-back b. inside and coplanar-front c. inside
  2. Delete all polygons in B that are: a. outside and coplanar-back b. outside and coplanar-front c. inside and coplanar-back d. outside

yuhaozhou2000 avatar May 29 '23 01:05 yuhaozhou2000

@yuhaozhou2000

Can you identify in the code here: https://github.com/manthrax/THREE-CSGMesh/blob/master/csg-lib.js where you see that determination being made? Interested in looking into it..

manthrax avatar Jun 08 '23 22:06 manthrax