Path.splineThru() 方法用于在路径上生成一系列点,这些点通过贝塞尔曲线相互连接。使用这些点可以绘制平滑的曲线。
splineThru(pts : Vector2[])
pts
一个数组,包含要生成曲线的点。
以下示例演示如何使用 splineThru()
方法生成一条曲线。
// 创建一个工作区
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
// 定义路径点
const points = [
new THREE.Vector2( 0, 0 ),
new THREE.Vector2( 10, 10 ),
new THREE.Vector2( 20, -2 ),
new THREE.Vector2( 30, 20 ),
new THREE.Vector2( 40, -4 )
];
// 创建路径
const path = new THREE.Path().splineThru( points );
// 创建材料
const material = new THREE.LineBasicMaterial( { color : 0xFF0000 } );
const geometry = path.createPointsGeometry(); // 生成点的几何体
const line = new THREE.Line( geometry, material );
// 将线添加到场景中
scene.add( line );
camera.position.z = 50;
// 渲染场景
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
}
animate();