Hi
I need to calculate the corner coordinates of the selected object. How Can I do that?
I need it to check my object’s position that is in the selected plane.
How Can I find red star points (corners) coordinates . I need a position.
Hi
I need to calculate the corner coordinates of the selected object. How Can I do that?
I need it to check my object’s position that is in the selected plane.
How Can I find red star points (corners) coordinates . I need a position.
There’s is one way to do it using the position array from the geometry object of the mesh. This array has the position for each vertex disposed in steps of 3. We can then go over the points checking the angle it forms with the next one:
const _array = floorMesh.geometry.attributes.position.array;
const _points = [ ];
const _borders = [ ];
// The threshold refers to PI. A value of 0.5 means a 90 degrees angle with 1.0 meaning 180 degrees
const _threshold = 0.35;for (let _i = 0; _i < _array.length; _i = _i + 3) {
_points.push(new THREE.Vector3(_array[_i], _array[_i + 1], _array[_i + 2]));
// Below we check if it’s the last run
if (_i === _array.length - 3) {
_points.map((__point, __i) => {
if (__i < _points.length - 1) {
if (__point.angleTo(_points[__i + 1]) / Math.PI > _threshold) {
_borders.push(__point);
}
}
else {
if (__point.angleTo(_points[1]) / Math.PI > _threshold) {
_borders.push(__point);
}
console.log(_borders, _borders.length);
}
});
}
}
I was able to successfully get the coordinates from the model below with this method
Generating the following log
There would have to be some control over the model for this method to work across the board, since extra edges/vertexes could generate more curves for it to detect, but it’s an idea. (: