Curve.getPointAt()
是 Three.js 中的一个方法,用于返回曲线对象上给定位置的点。该方法可用于计算曲线上的点、路径长度和引导点。
getPointAt(u: Float): Vector3;
u
:表示曲线上的位置,范围为 0.0 (曲线起点)到 1.0(曲线终点)之间的浮点数。Vector3
:表示曲线上给定位置的点坐标。以下示例展示了如何使用 Curve.getPointAt()
方法在三维空间内绘制曲线。
// 创建一条 CatmullRomCurve3 曲线
const curve = new THREE.CatmullRomCurve3( [
new THREE.Vector3( -10, 0, 10 ),
new THREE.Vector3( -5, 5, 5 ),
new THREE.Vector3( 0, 0, 0 ),
new THREE.Vector3( 5, -5, 5 ),
new THREE.Vector3( 10, 0, 10 )
]);
// 绘制曲线
const points = curve.getPoints( 50 );
const geometry = new THREE.BufferGeometry().setFromPoints( points );
const material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
const curveObject = new THREE.Line( geometry, material );
scene.add( curveObject );
// 计算曲线上的点
const pointOnCurve = curve.getPointAt( 0.5 ); // 得到曲线中心点
const geometry2 = new THREE.SphereGeometry( 0.1 );
const material2 = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
const pointObject = new THREE.Mesh( geometry2, material2 );
pointObject.position.copy( pointOnCurve );
scene.add( pointObject );