Although this question is primarily related to Math, I believe there may be alternative solutions available within threejs for my particular issue.
My goal is to iterate through each vertex in a Box Geometry and determine whether it needs to be moved up or down by a specific value. In this case, we are only concerned with the y-values of each vertex.
var width = 200,
height = 100,
depth = 50;
var roundCornerWidth = var roundCornerHeight = 10;
var helpWidth = width - 2*roundCornerWidth,
helpHeight = height - 2*roundCornerHeight;
var boxGeometry = new THREE.BoxGeometry(width, height, depth, 100, 50, 10);
boxGeometry.vertices.forEach(v => {
if(Math.abs(v.x)>helpWidth/2){
if(Math.abs(v.y)>helpHeight/2){
let helper = Math.abs(v.x)-helperWidth/2;
v.y = Math.sign(v.y)*(helperHeight + Math.cos(helper/roundWidth * Math.PI/2)*roundHeight);
}
}
});
The current code produces corners similar to those shown in the example image, which are not aesthetically pleasing! :(
We need an alternative method other than using the cos()
function.