BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Curve.getPointAt()

概述

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 );

参考资料