重排
This commit is contained in:
30
index.html
30
index.html
@@ -30,19 +30,21 @@
|
|||||||
//);
|
//);
|
||||||
//scene.add(cube);
|
//scene.add(cube);
|
||||||
|
|
||||||
// 添加螺丝帽
|
//// 添加螺丝帽
|
||||||
const 螺丝帽模型 = new THREE.Mesh(
|
//const 螺丝帽模型 = new THREE.Mesh(
|
||||||
new 六角螺丝帽(1, 0.5, 0.6),
|
// new 六角螺丝帽(1, 0.5, 0.6),
|
||||||
new THREE.MeshStandardMaterial({ color: 0x00ff00, roughness: 0.5, metalness: 0.8 })
|
// new THREE.MeshStandardMaterial({ color: 0x00ff00, roughness: 0.5, metalness: 0.8 })
|
||||||
);
|
//);
|
||||||
scene.add(螺丝帽模型);
|
//scene.add(螺丝帽模型);
|
||||||
|
|
||||||
// 添加育苗盘
|
// 添加育苗盘
|
||||||
const 育苗盘模型 = new THREE.Mesh(
|
const 育苗盘模型 = new THREE.Mesh(
|
||||||
new 方形育苗盘(),
|
new 方形育苗盘(),
|
||||||
new THREE.MeshStandardMaterial({ color: 0x0000ff, roughness: 0.5, metalness: 0.8 })
|
new THREE.MeshStandardMaterial({ color: 0x0000ff, roughness: 0.5, metalness: 0.8 })
|
||||||
);
|
);
|
||||||
//育苗盘模型.position.set(0, -1, 0); // 设置育苗盘位置
|
// 旋转育苗盘
|
||||||
|
育苗盘模型.rotation.x += 1.57;
|
||||||
|
育苗盘模型.rotation.y += 0;
|
||||||
scene.add(育苗盘模型);
|
scene.add(育苗盘模型);
|
||||||
|
|
||||||
// 添加光源
|
// 添加光源
|
||||||
@@ -51,7 +53,7 @@
|
|||||||
directionalLight.position.set(5, 5, 5); // 设置光源位置
|
directionalLight.position.set(5, 5, 5); // 设置光源位置
|
||||||
scene.add(directionalLight);
|
scene.add(directionalLight);
|
||||||
|
|
||||||
camera.position.z = 5;
|
camera.position.z = .75;
|
||||||
|
|
||||||
// 3. 动画循环
|
// 3. 动画循环
|
||||||
function animate() {
|
function animate() {
|
||||||
@@ -59,13 +61,13 @@
|
|||||||
//cube.rotation.x += 0.01;
|
//cube.rotation.x += 0.01;
|
||||||
//cube.rotation.y += 0.01;
|
//cube.rotation.y += 0.01;
|
||||||
|
|
||||||
// 旋转育苗盘
|
//// 旋转育苗盘
|
||||||
育苗盘模型.rotation.x += 0.01;
|
//育苗盘模型.rotation.x += 0.01;
|
||||||
育苗盘模型.rotation.y += 0.01;
|
//育苗盘模型.rotation.y += 0.01;
|
||||||
|
|
||||||
// 旋转螺丝帽
|
//// 旋转螺丝帽
|
||||||
螺丝帽模型.rotation.x += 0.01;
|
//螺丝帽模型.rotation.x += 0.01;
|
||||||
螺丝帽模型.rotation.y += 0.01;
|
//螺丝帽模型.rotation.y += 0.01;
|
||||||
|
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ import * as THREE from 'three';
|
|||||||
import { SUBTRACTION, ADDITION, Brush, Evaluator } from 'three-bvh-csg';
|
import { SUBTRACTION, ADDITION, Brush, Evaluator } from 'three-bvh-csg';
|
||||||
|
|
||||||
export class 方形育苗盘 extends THREE.BufferGeometry {
|
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();
|
super();
|
||||||
|
|
||||||
this.parameters = {
|
this.parameters = {
|
||||||
@@ -12,24 +12,23 @@ export class 方形育苗盘 extends THREE.BufferGeometry {
|
|||||||
holeDiameter: holeDiameter,
|
holeDiameter: holeDiameter,
|
||||||
holeRadius: holeRadius,
|
holeRadius: holeRadius,
|
||||||
holeRows: holeRows,
|
holeRows: holeRows,
|
||||||
holeCols: holeCols
|
holeCols: holeCols,
|
||||||
|
rowSpacing: rowSpacing,
|
||||||
|
colSpacing: colSpacing
|
||||||
};
|
};
|
||||||
|
|
||||||
this.buildGeometry();
|
this.buildGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
const baseBrush = new Brush(new THREE.BoxGeometry(width, height, depth));
|
||||||
|
|
||||||
// 计算孔洞间距, (主体尺寸- 孔洞数量 * 孔洞直径) / (孔洞数量 + 1)
|
const holes = [];
|
||||||
const rowSpacing = (width - holeRows * holeDiameter) / (holeRows + 1); // 行间距
|
for (let i = 0; i < holeRows; i++) {
|
||||||
const colSpacing = (depth - holeCols * holeDiameter) / (holeCols + 1); // 列间距
|
for (let j = 0; j < holeCols; j++) {
|
||||||
const holes = []
|
|
||||||
for (let i = 1; i <= holeRows; i++) {
|
|
||||||
for (let j = 1; j <= holeCols; j++) {
|
|
||||||
// 计算每个孔洞的中心位置
|
// 计算每个孔洞的中心位置
|
||||||
const x = -(width / 2) + rowSpacing * (i + 1) + holeDiameter * (i + 0.5);
|
const x = -(width / 2) + rowSpacing * (i + 1) + holeDiameter * (i + 0.5);
|
||||||
const z = -(depth / 2) + colSpacing * (j + 1) + holeDiameter * (j + 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);
|
holes.push(holeBrush);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算所有孔洞的合并结果
|
// 计算所有孔洞的合并结果
|
||||||
let combinedHoles = holes[0];
|
let combinedHoles = holes[0];
|
||||||
for (let i = 1; i < holes.length; i++) {
|
for (let i = 1; i < holes.length; i++) {
|
||||||
|
Reference in New Issue
Block a user