THREE.TorusGeometry(radius, tube, radialSegments, tubularSegments)
- radius: 圆环的整体半径;
- tube: 管道半径,即环的管道的半径;
- radialSegments: 可选参数,表示环的管道的分段数,即管道被切割成多少段。默认值为 8;
- tubularSegments: 可选参数,表示环的整体的分段数,即整个圆环被切割成多少段。默认值为 32。
const radius = 2;
const tube = 1;
const radialSegments = 8;
const tubularSegments = 32;
const torusGeometry = new THREE.TorusGeometry(radius, tube, radialSegments, tubularSegments);
const material = new THREE.MeshBasicMaterial({ color: 0x00ffff, wireframe: true });
const myGeometry = new THREE.Mesh(torusGeometry, material);
scene.add(myGeometry);
THREE.TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q)
- radius: 环面结扣的整体半径;
- tube: 管道半径,即环面结扣的管道的半径;
- tubularSegments: 管道的分段数,即管道被切割成多少段;
- radialSegments: 环面的分段数,即整个环面被切割成多少段;
- p 和 q: 可选参数,控制环面结扣的形状。它们是整数值,用于确定结扣的形状。默认值为 p = 2 和 q = 3。
const radius = 5;
const tube = 1;
const tubularSegments = 64;
const radialSegments = 8;
const p = 2;
const q = 3;
const torusKnotGeometry = new THREE.TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00, wireframe: true });
const torusKnot = new THREE.Mesh(torusKnotGeometry, material);
scene.add(torusKnot);
TubeGeometry(path,tubularSegments ,radius,radialSegments, closed )
- path — Curve - 一条继承自 Curve 基类的 3D 路径。默认为二次贝塞尔曲线;
- tubularSegments — Integer - 构成管道的段数。默认为 64;
- radius — Float - 管道的半径。默认为 1;
- radialSegments — Integer - 构成横截面的段数。默认为 8;
- closed — Boolean - 管道是否是开放或封闭的。默认为 false。
class CustomSinCurve extends THREE.Curve {
constructor( scale = 1 ) {
super();
this.scale = scale;
}
getPoint( t, optionalTarget = new THREE.Vector3() ) {
const tx = t * 3 - 1.5;
const ty = Math.sin( 2 * Math.PI * t );
const tz = 0;
return optionalTarget.set( tx, ty, tz ).multiplyScalar( this.scale );
}
}
const path = new CustomSinCurve( 10 );
const geometry = new THREE.TubeGeometry( path, 20, 2, 8, false );
const material = new THREE.MeshPhongMaterial( { color: 0x00ffff } );
const myGeometry = new THREE.Mesh( geometry, material );
scene.add( myGeometry );
THREE.WireframeGeometry(geometry)
参数 geometry是原始的几何体。
2.14.2 示例const geometry = new THREE.SphereGeometry( 10, 10, 10 );
const wireframe = new THREE.WireframeGeometry( geometry );
const myGeometry = new THREE.LineSegments( wireframe );
myGeometry.material.depthTest = false;
myGeometry.material.opacity = 0.5;
myGeometry.material.transparent = true;
scene.add( myGeometry );