# Determining internal objects

**URL:** <https://discourse.threejs.org/t/determining-internal-objects/56336>\
**Category:** Questions\
**Tags:** geometry\
**Created:** [September 23, 2023, 8:14pm UTC](https://discourse.threejs.org/t/determining-internal-objects/56336 "2023-09-23T20:14:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![user123](https://avatars.discourse-cdn.com/v4/letter/u/ed655f/32.png) [@user123](https://discourse.threejs.org/u/user123)\
**Post date:** [September 23, 2023, 8:14pm UTC](https://discourse.threejs.org/t/determining-internal-objects/56336/1 "2023-09-23T20:14:33Z")

</div>

I wondering the best approach to determine which meshes are internal to another. For example, if I had a model of a PC, I would want to easily find all the internals (motherboard, power supply etc).

The only way I can think of doing this is to raycast from points around a sphere and see what parts get hit. If an object is never intersected then it must be internal(?). The more ray casts/points on the sphere that I do the tighter the tolerance.

This could lead to doing a lot of ray casts which seem inefficient, is there a better approach?

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [September 23, 2023, 9:35pm UTC](https://discourse.threejs.org/t/determining-internal-objects/56336/2 "2023-09-23T21:35:05Z")

</div>

Maybe better to use `Box3`s to determine, if a an object is inside of another one, calling, for example, the `.containsBox()` method 🤔

---

<div class="post-metadata">

**Author:** ![Lawrence3DPK](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lawrence3dpk/32/29184_2.png) [@Lawrence3DPK](https://discourse.threejs.org/u/Lawrence3DPK)\
**Post date:** [September 23, 2023, 10:00pm UTC](https://discourse.threejs.org/t/determining-internal-objects/56336/3 "2023-09-23T22:00:01Z")

</div>

to add to this… if a `box3` ever partially falls outside the bounds of the containing box3 due to object orientation / AABB mismaches the `box3` class also has a “[`containsPoint`](https://threejs.org/docs/#api/en/math/Box3.containsPoint)” method which can check if all points of a mesh are absolutely contained in the containing `box3`…

---

<div class="post-metadata">

**Author:** ![user123](https://avatars.discourse-cdn.com/v4/letter/u/ed655f/32.png) [@user123](https://discourse.threejs.org/u/user123)\
**Post date:** [September 23, 2023, 10:29pm UTC](https://discourse.threejs.org/t/determining-internal-objects/56336/4 "2023-09-23T22:29:57Z")

</div>

I guess this method assumes I know the containing part(s)? Otherwise, you would have the check every box3 against every other box3.

What if it could be any complex model that is inserted in the scene e.g. a Car, where there are mulitple parts (bonnet, boot, doors, etc) that make up the external and then multiple interior parts (engine, steering wheel, seats etc) would the box3 method still be suitable?

---

<div class="post-metadata">

**Author:** ![Lawrence3DPK](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lawrence3dpk/32/29184_2.png) [@Lawrence3DPK](https://discourse.threejs.org/u/Lawrence3DPK)\
**Post date:** [September 23, 2023, 10:39pm UTC](https://discourse.threejs.org/t/determining-internal-objects/56336/5 "2023-09-23T22:39:07Z")

</div>

You’d want to use extended libraries for detecting if complex shapes such as a car contains all points / bounding tree of another mesh for instance… [shape intersection](https://gkjohnson.github.io/three-mesh-bvh/example/bundle/shapecast.html) as part of the three-mesh-bvh library, whereby you can rapidly check if a box3 / all points of / all parts of a mesh are contained within a bounding volume hierarchy.

---

<div class="post-metadata">

**Author:** ![PavelBoytchev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/pavelboytchev/32/38639_2.png) [@PavelBoytchev](https://discourse.threejs.org/u/PavelBoytchev)\
**Post date:** [September 23, 2023, 11:15pm UTC](https://discourse.threejs.org/t/determining-internal-objects/56336/6 "2023-09-23T23:15:50Z")

</div>

If you have control over the creation of the models, you can put inner objects as children of their outer objects. Thus, a small change in the input data will simplify the calculations.

This will also help you answer the question: _is the rice inside the bowl, if it rises above the rim of the bowl?_

![istockphoto-860931464-612x612](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/c/6/c6802167c102b5c7f6e9c2469cac668855fa14ef.jpeg)

---

<div class="post-metadata">

**Author:** ![user123](https://avatars.discourse-cdn.com/v4/letter/u/ed655f/32.png) [@user123](https://discourse.threejs.org/u/user123)\
**Post date:** [September 24, 2023, 8:25am UTC](https://discourse.threejs.org/t/determining-internal-objects/56336/7 "2023-09-24T08:25:24Z")

</div>

I don’t have control over the creation of the model. For your rice example, in my use case, I would not treat that as internal. I’m looking to find parts that cannot be seen and hence can be discarded. Sounds like @Lawrence3DPK suggestion of three-mesh-bvh may be the best option

---

<div class="post-metadata">

**Author:** ![oldman](https://avatars.discourse-cdn.com/v4/letter/o/b2d939/32.png) [@oldman](https://discourse.threejs.org/u/oldman)\
**Post date:** [September 29, 2023, 10:10pm UTC](https://discourse.threejs.org/t/determining-internal-objects/56336/8 "2023-09-29T22:10:11Z")

</div>

Just curious to know if you have decided on an approach and whether it has yielded the intended results. I have need for something - not exactly the same - but on similar lines.

Thanks much

OLDMAN

---

<div class="post-metadata">

**Author:** ![user123](https://avatars.discourse-cdn.com/v4/letter/u/ed655f/32.png) [@user123](https://discourse.threejs.org/u/user123)\
**Post date:** [October 3, 2023, 8:01am UTC](https://discourse.threejs.org/t/determining-internal-objects/56336/9 "2023-10-03T08:01:53Z")

</div>

Unfortunately not yet, so if you get anywhere let me know!

---

<div class="post-metadata">

**Author:** ![oldman](https://avatars.discourse-cdn.com/v4/letter/o/b2d939/32.png) [@oldman](https://discourse.threejs.org/u/oldman)\
**Post date:** [October 5, 2023, 6:36am UTC](https://discourse.threejs.org/t/determining-internal-objects/56336/10 "2023-10-05T06:36:51Z")

</div>

I have an idea: a combination of ray-casting and something I call “face chasing”. Will need to try this out at some point and will keep you posted. But the idea is sort of opposite your problem statement:

- find external objects
- all those that are not external are internal
