This commit is contained in:
Last
2025-05-06 22:59:15 +08:00
parent 54d825ce59
commit 999168037a
2 changed files with 25 additions and 23 deletions

View File

@@ -2,7 +2,7 @@ import * as THREE from 'three';
import { SUBTRACTION, ADDITION, Brush, Evaluator } from 'three-bvh-csg';
export class 方形育苗盘 extends THREE.BufferGeometry {
constructor(width = 10, depth = 15, height = 0.25, holeDiameter = 0.25, holeRadius = 1, holeRows = 4, holeCols = 4) {
constructor(width = 0.6, depth = 0.4, height = 0.01, holeDiameter = 0.02, holeRadius = .1, holeRows = 20, holeCols = 12, rowSpacing = .01, colSpacing = .01) {
super();
this.parameters = {
@@ -12,24 +12,23 @@ export class 方形育苗盘 extends THREE.BufferGeometry {
holeDiameter: holeDiameter,
holeRadius: holeRadius,
holeRows: holeRows,
holeCols: holeCols
holeCols: holeCols,
rowSpacing: rowSpacing,
colSpacing: colSpacing
};
this.buildGeometry();
}
buildGeometry() {
const { width, depth, height, holeDiameter, holeRows, holeCols, } = this.parameters;
const { width, depth, height, holeDiameter, holeRows, holeCols, rowSpacing, colSpacing } = this.parameters;
// 创建长方体主体
const baseBrush = new Brush(new THREE.BoxGeometry(width, height, depth));
// 计算孔洞间距, (主体尺寸- 孔洞数量 * 孔洞直径) / (孔洞数量 + 1)
const rowSpacing = (width - holeRows * holeDiameter) / (holeRows + 1); // 行间距
const colSpacing = (depth - holeCols * holeDiameter) / (holeCols + 1); // 列间距
const holes = []
for (let i = 1; i <= holeRows; i++) {
for (let j = 1; j <= holeCols; j++) {
const holes = [];
for (let i = 0; i < holeRows; i++) {
for (let j = 0; j < holeCols; j++) {
// 计算每个孔洞的中心位置
const x = -(width / 2) + rowSpacing * (i + 1) + holeDiameter * (i + 0.5);
const z = -(depth / 2) + colSpacing * (j + 1) + holeDiameter * (j + 0.5);
@@ -39,6 +38,7 @@ export class 方形育苗盘 extends THREE.BufferGeometry {
holes.push(holeBrush);
}
}
// 计算所有孔洞的合并结果
let combinedHoles = holes[0];
for (let i = 1; i < holes.length; i++) {