import * as THREE from 'three'; import { SUBTRACTION, Brush, Evaluator } from 'three-bvh-csg'; export class 六角螺丝帽 extends THREE.BufferGeometry { constructor(radius = 1, height = 0.5, holeRadius = 0.6) { super(); this.parameters = { radius: radius, height: height, holeRadius: holeRadius }; this.buildGeometry(); } buildGeometry() { const { radius, height, holeRadius } = this.parameters; // 创建螺丝帽主体 (六棱柱) const hexagonBrush = new Brush(new THREE.CylinderGeometry(radius, radius, height, 6)); // 创建内部的孔洞 (圆柱体) const holeBrush = new Brush(new THREE.CylinderGeometry(holeRadius, holeRadius, height + 0.1, 128)); // 执行布尔运算 (差集) const resultBrush = new Evaluator().evaluate(hexagonBrush, holeBrush, SUBTRACTION); // 将布尔运算结果应用到当前 BufferGeometry this.copy(resultBrush.geometry); this.computeVertexNormals(); // 计算法线 } } export default { 六角螺丝帽 };