Hello, everyone! Worked on creating a hole inside the geometry of the group components.
I was faced with the fact that on some sides the holes are not scaled correctly.
How can this be fixed?
Picture of right hole scaling.
Picture of wrong hole scaling.
I’m creating rectangle through THREE.Group
//Create and render rectangle at scene.
const rectangle = new Rectangle(150, 300, 500)
scene.add(rectangle)
//Set up holes parameters for each side of rectangle
const hole = {
holeX: 0,
holeY: 0,
holeRadius: 30
}
rectangle.children.forEach(child => {
createHole(child, hole)
})
For creating holes I used this functions
/*
* Creates hole in 3D-component through ShapeGeometry.
* @param component:Object3D object where need to create hole.
* @param holePamaters:Object containing parameters of creating hole such as radius and x, y position at geometry.
*/function createHole(component, holeParameters) {
//Forming new geo
const shape = new Shape().copy(component.getShape())
const path = createHoleVertices(component, holeParameters)
shape.holes.push(path)
//Delete old geo and setting up new one.
const oldGeo = component.geometry
component.geometry = new ShapeGeometry(shape)
oldGeo.dispose()
}
/*
* Creates Path of hole vertices.
* @param component:Object3D object where need to create hole.
* @param holePamaters:Object containing parameters of creating hole such as radius and x, y position at geometry.
* @return Path of hole.
*/function createHoleVertices(component, holeParameters) {
let {holeX, holeY, holeRadius} = holeParameters
//Normalizing hole parameters due to planes origin size is (width: 1, height: 1).
const {x, y} = component.getParentScale()
holeX = holeX / x
holeY = holeY / y
return new Path().absellipse(holeX, holeY, holeRadius / x, holeRadius / y, 0, 2 * Math.PI)
}
Here is codepen for demonstration: https://codepen.io/DYDOI-NSK/pen/ZEPvyde?editors=0010