Hi there
I want to make something to analize a 3d model’s topology. One thing I am interested is the number of height changes on a single face of the object. The models i use are used for cncs so complex curves are out of the question.
To Achive this i was thinking of projecting a lot of perpendicular rays to the object and recording the distance from the origin point. Here comes the problem/question, for testing this i use a Box Geometry with Lambert Mesh all wrapped in an Object3D.
let geometry = new THREE.BoxGeometry(100,100,10)
let material = new THREE.MeshLambertMaterial({color: 0xcccccc})
const mesh = new THREE.Mesh(geometry, material);
const mainObject = new THREE.Object3D();
mainObject.add(mesh)
mainObject.children[0].geometry.computeBoundingBox()
mainObject.children[0].geometry.boundingBox.setFromObject(mainObject, true)
const boundingBox = mainObject.children[0].geometry.boundingBox
const boundingBoxHelper = new THREE.Box3Helper(boundingBox, 0xff0000)
To create my rays i take the extremes of the bounding box and project a perpendicular ray to the object every 5 units and if the ray intersects the object i draw an arrowHelper
for (let i = boundingBox.min.x ; i < boundingBox.max.x; i += 5) {
for (let j = boundingBox.min.z ; j < boundingBox.max.z ; j += 5) {
const origin = (new THREE.Vector3(i, 100 , j))
const direction = (new THREE.Vector3(i, -10000 , j))
direction.normalize();
reycaster.set(origin, direction)
let intr = reycaster.intersectObject(mainObject)
if (intr.length === 0) continue
console.log( j,i, intr?.[0]?.point)
const arrowHelper = new THREE.ArrowHelper(direction, origin, 1000)
scene.add(arrowHelper)
}
}
In theory i think this should work, but for some reason all the rays that intersect are clustered around a slice somewhere near the middle of the object.
This is an example of what happens, the red lines represent rays that do not intersect, green lines are rays that intersect. I am confused why that happens