The Shape.getPointsHoles() method in three.js returns an array of points that define holes in a shape.
Shape.getPointsHoles( divisions )
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).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.
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.
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.
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.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.Shape.getPointsHoles() are in local space. To transform them to world space, multiply them by the world matrix of the object they belong to.