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

Path.setFromPoints()

The setFromPoints() method is a functionality provided by the Three.js library, which allows you to create a new path object by specifying a set of points.

This method takes an array of Three.js Vector3 objects as its input parameter, and generates a new path object that follows the path defined by the given points.

The new path object can be used for a wide range of purposes, such as creating complex shapes, designing custom animations, or defining trajectories for objects to follow in a Three.js scene.

Syntax

path.setFromPoints(pointsArray);

Parameters

  • pointsArray - An array of Three.js Vector3 objects that define the path.

Example

Here's an example of how to use setFromPoints() to create a path for a custom shape in a Three.js scene:

// Create an array of Vector3 points to define the path
var pointsArray = [
  new THREE.Vector3(-50, 0, 0),
  new THREE.Vector3(0, 50, 0),
  new THREE.Vector3(50, 0, 0),
  new THREE.Vector3(0, -50, 0),
  new THREE.Vector3(-50, 0, 0)
];

// Create a new path object using the setFromPoints method
var path = new THREE.Path().setFromPoints(pointsArray);

// Use the path to create a custom shape
var shape = new THREE.Shape(path.getPoints());

// Create a geometry and mesh for the custom shape
var geometry = new THREE.ShapeGeometry(shape);
var material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
var mesh = new THREE.Mesh(geometry, material);

// Add the mesh to the scene
scene.add(mesh);

In this example, we first create an array of Vector3 points to define the path for our custom shape. We then use the setFromPoints() method to create a Path object that follows this path.

We then use the getPoints() method of the Path object to get an array of points that define the shape, and use these to create a Shape object.

Finally, we use the ShapeGeometry class to create a geometry object from the Shape, and create a mesh object using this geometry and a basic material. We then add the mesh to our Three.js scene.

Remarks

The setFromPoints() method is a powerful tool for creating custom shapes and paths in Three.js, and can be used to create a wide range of animations and visual effects.

One important thing to note is that the order of the points in the input array matters, as this will determine the direction and orientation of the path. Make sure to order the points in a way that makes sense for your intended use of the path.