gkjohnson / three-bvh-csg

A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh
MIT License
623 stars 49 forks source link

How to use multiple ExtrudeGeometry holes #197

Closed yodfz closed 10 months ago

yodfz commented 10 months ago
const g1 = new THREE.ExtrudeGeometry(boxShape1, extrudeSettings)
const g2= new THREE.ExtrudeGeometry(boxShape2, extrudeSettings)
const g3 = new THREE.ExtrudeGeometry(boxShape3, extrudeSettings)

  const csgEvaluator = new Evaluator();
  const brush1 = new Brush(geometry);
  const brush2 = new Brush(g1);
  const result = csgEvaluator.evaluate(brush1, brush2, SUBTRACTION);
  newGeometry = result.geometry;
  const brush= new Brush(newGeometry);
  const brush3 = new Brush(g2);
const result2= csgEvaluator.evaluate(brush1, brush3, SUBTRACTION);

I can't do that。Something's wrong with him。

yodfz commented 10 months ago
// basic pieces
const cylinder1 = new Brush( new THREE.CylinderGeometry( 0.5, 0.5, 6, 45 ), blueMaterial );
cylinder1.updateMatrixWorld();

const cylinder2 = new Brush( new THREE.CylinderGeometry( 0.5, 0.5, 6, 45 ), blueMaterial );
cylinder2.rotation.x = Math.PI / 2;
cylinder2.updateMatrixWorld();

const cylinder3 = new Brush( new THREE.CylinderGeometry( 0.5, 0.5, 6, 45 ), blueMaterial );
cylinder3.rotation.z = Math.PI / 2;
cylinder3.updateMatrixWorld();

const sphere = new Brush( new THREE.SphereGeometry( 1, 50, 50 ), greenMaterial );
sphere.updateMatrixWorld();

const box = new Brush( new THREE.BoxGeometry( 1.5, 1.5, 1.5 ), redMaterial );
box.updateMatrixWorld();

// processing
const evaluator = new Evaluator();
let result;
result = evaluator.evaluate( cylinder1, cylinder2, ADDITION );
result = evaluator.evaluate( result, cylinder3, ADDITION );
result = evaluator.evaluate( sphere, result, SUBTRACTION );
result = evaluator.evaluate( box, result, INTERSECTION );

i know!can't read geometry,load brush?

gkjohnson commented 10 months ago
 const brush= new Brush(newGeometry);
 const brush3 = new Brush(g2);
 const result2= csgEvaluator.evaluate(brush1, brush3, SUBTRACTION);

You are using brush1 again in the second evaluation.

i know!can't read geometry,load brush?

I'm not sure what you mean by this.