# Analyze object topology

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.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)

}
}
``````

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

As there is no live example to play with, I made my own example and rays work as expected. I hope it will help you find the bug in your code.

Some major difference in my code are:

• the model is not wrapped in an `Object3D` as it is not needed (line 64)
• `Box3` is used instead of bounding boxes (line 76)
• raycasting is recursive, so subobjects of the model are also checked (line 89)
• the direction vector is the same for all rays (line 78)
• (optional) the initial orientation of the model can be changed (line 53)

https://codepen.io/boytchev/full/ZEVXgbw