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

CurvePath.getPoints()

CurvePath.getPoints()是three.js中的一个方法,用于获取曲线路径上的点。

语法

CurvePath.getPoints ( divisions: Integer ): Array<Vector3>
  • divisions: 曲线分段数,即生成的点数。默认值为12。

返回值:一个包含Vector3对象的数组。

用法

以下示例代码创建了一个SinCurve对象,然后使用 getPoints() 方法生成一组点,并在场景中绘制这些点。

//创建 sin 曲线
var curvePath = new THREE.CurvePath();
var curve = new THREE.SinCurve(50);
curvePath.add(curve);

//获取曲线上的点
var points = curvePath.getPoints(100);

//绘制曲线的点
var geometry = new THREE.BufferGeometry().setFromPoints(points);
var material = new THREE.PointsMaterial({size: 3, color: 0xff0000});
var pointsObject = new THREE.Points(geometry, material);
scene.add(pointsObject);

参数说明

divisions : 定义曲线上点的数量。为确保曲线平滑,建议增加分段数。默认值为12,但可以根据需要自由更改。

返回值

返回一个包含Vector3对象的数组,其中每个元素描述了在曲线路径上的一个点。

示例

在本示例中,我们创建了一个带顶点颜色的SplineCurve3对象,并使用 getPoints() 方法在场景中渲染这些点。

var curve = new THREE.SplineCurve3([
  new THREE.Vector3(-10, 0, 0),
  new THREE.Vector3(-5, 5, 5),
  new THREE.Vector3(0, 0, 10),
  new THREE.Vector3(5, -5, 5),
  new THREE.Vector3(10, 0, 0)
]);
var points = curve.getPoints(50);

var geometry = new THREE.BufferGeometry().setFromPoints(points);
var colors = [];

for (var i = 0; i < points.length; i++) {
  colors[i] = new THREE.Color(0xffffff);
  colors[i].setHSL(i / points.length, 1.0, 0.5);
}

geometry.addAttribute('color', new THREE.Float32BufferAttribute(colors, 3));

var material = new THREE.PointsMaterial({
  size: 0.2,
  vertexColors: THREE.VertexColors
});

var pointsObject = new THREE.Points(geometry, material);
scene.add(pointsObject);

更多资源

了解更多关于three.js库的信息,请参阅以下资源: