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

Shape.getPointsHoles()

The Shape.getPointsHoles() method in three.js returns an array of points that define holes in a shape.

Syntax

Shape.getPointsHoles( divisions )

Parameters

  • divisions — Optional. The number of times to divide each segment of the shape when creating the points. Higher values result in smoother curves (default is 12).

Return Value

An array of arrays of THREE.Vector2 objects. Each inner array represents a hole in the shape, and each THREE.Vector2 represents a point in 2D space.

Description

Shape.getPointsHoles() creates an array of points that define holes in a shape, based on the holes property of the THREE.Shape object. The holes property is an array of THREE.Path objects, which define the contours of the holes. Each THREE.Path object is essentially a list of THREE.Vector2 objects that define the points of the contour.

The Shape.getPointsHoles() method iterates over the holes array, and for each hole, it calls the THREE.Path.getPoints() method to create an array of points that define the hole. It then adds this array to the output array.

Examples

Here's an example of how to use Shape.getPointsHoles():

// Create a shape with a hole
const shape = new THREE.Shape();
shape.moveTo( 0, 0 );
shape.lineTo( 0, 10 );
shape.lineTo( 10, 10 );
shape.lineTo( 10, 0 );
const hole = new THREE.Path();
hole.moveTo( 2, 2 );
hole.lineTo( 2, 8 );
hole.lineTo( 8, 8 );
hole.lineTo( 8, 2 );
shape.holes.push( hole );

// Get the points of the shape and its holes
const shapePoints = shape.getPoints();
const holePoints = shape.getPointsHoles();

// Turn the points into geometry
const shapeGeometry = new THREE.ShapeGeometry( shapePoints );
const holeGeomety = new THREE.ShapeGeometry( holePoints[ 0 ] );

// Create mesh
const mesh = new THREE.Mesh( shapeGeometry, material );
scene.add( mesh );

In this example, we create a shape with a hole, and then we call Shape.getPoints() and Shape.getPointsHoles() to get the points of the shape and its hole. We then create two THREE.ShapeGeometry objects from these points, and create two meshes to display them.

Notes

  • The Shape.getPointsHoles() method is only useful if the shape has holes. If the shape does not have holes, this method will return an empty array.
  • The Shape.getPointsHoles() method does not return the points of the main shape. To get the points of the main shape, use the Shape.getPoints() method.
  • The points returned by Shape.getPointsHoles() are in local space. To transform them to world space, multiply them by the world matrix of the object they belong to.