榫卯体又称为旋转体,是通过旋转二维轮廓形状而成的三维几何体。LatheGeometry 的构造函数接受两个主要参数:路径(轮廓)和细分层级。
构造函数:
THREE.LatheGeometry(points, segments, phiStart, phiLength)
参数说明:
- points: 描述轮廓形状的点的数组。每个点是一个 Vector2 对象,表示二维平面上的坐标;
- segments: 可选参数,表示榫卯体的细分层级,即绕轴旋转的次数。默认值为 12;
- phiStart: 可选参数,表示旋转的起始角度,以弧度为单位。默认值为 0;
- phiLength: 可选参数,表示旋转的角度范围,以弧度为单位。默认值为 Math.PI * 2,表示完整的 360 度。
// 定义轮廓的点
const points = [];
for (let i = 0; i < 10; i ) {
const x = Math.sin(i) * 2;
const y = (i - 10)*0.5 ;
points.push(new THREE.Vector2(x, y));
}
// 创建线条几何体,这个几体体只是为了方便查看轮廓点的位置
const geometry = new THREE.BufferGeometry().setFromPoints(points);
// 创建线条材质
const material1 = new THREE.LineBasicMaterial({ color: 0x00ff00 });
// 创建线条对象
const line = new THREE.Line(geometry, material1);
scene.add(line);
line.rotation.x = 1;
line.rotation.y = 0;
line.rotation.z = 0;
// 完成线条几何体的创建
// 基于上面的线段创建 LatheGeometry
const latheGeometry = new THREE.LatheGeometry(points, 50);
const material = new THREE.MeshBasicMaterial({ color: 0xFF2222, wireframe: true });
const myGeometry = new THREE.Mesh(latheGeometry, material);
scene.add(myGeometry);
THREE.OctahedronGeometry(radius, detail)
2.8.2 代码
const radius =1;
const detail = 0;
const octahedronGeometry = new THREE.OctahedronGeometry(radius, detail);
const material = new THREE.MeshBasicMaterial({ color: 0x00ffff, wireframe: true });
const myGeometry = new THREE.Mesh(octahedronGeometry, material);
scene.add(myGeometry);
THREE.RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments)
参数说明:
- innerRadius: 内半径,即环的内圆的半径;
- outerRadius: 外半径,即环的外圆的半径;
- thetaSegments: 可选参数,表示环的分段数,即环被切割成多少段。默认值为 8;
- phiSegments: 可选参数,表示环的纵向分段数,即环的高度被切割成多少段。默认值为 8;
- thetaStart: 可选参数,表示环的起始角度,以弧度为单位。默认值为 0;
- thetaLength: 可选参数,表示环的中央角度,以弧度为单位。默认值为 Math.PI * 2,即完整的 360 度。
const innerRadius = 1;
const outerRadius = 2;
const thetaSegments = 8;
const phiSegments = 8;
const ringGeometry = new THREE.RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00, wireframe: true });
const myGeometry = new THREE.Mesh(ringGeometry, material);
scene.add(myGeometry);
THREE.TetrahedronGeometry(radius, detail, type)
- radius: 四面体的外接球的半径;
- detail: 可选参数,控制几何体的细分层级。可以是整数值,表示将每个三角面细分为更小的三角形的次数。默认值为 0;
- type: 可选参数,表示四面体的类型。可以是 ‘regular’(正四面体)或 ‘geodesic’(几何四面体)。默认值为 ‘regular’。
const radius = 2;
const detail = 0;
const type = 'regular';
const tetrahedronGeometry = new THREE.TetrahedronGeometry(radius, detail, type);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00, wireframe: true });
const myGeometry = new THREE.Mesh(tetrahedronGeometry, material);
scene.add(myGeometry);