# How can I make a mesh sit on the surface of another mesh?

**URL:** <https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315>\
**Category:** Questions\
**Created:** [December 18, 2018, 9:01pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315 "2018-12-18T21:01:26Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjshipe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tjshipe/32/194_2.png) [@tjshipe](https://forum.babylonjs.com/u/tjshipe)\
**Post date:** [December 18, 2018, 9:01pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/1 "2018-12-18T21:01:26Z")

</div>

I am importing STL objects into my scene. Once the scene is loaded with the imported STL, I am trying to place “pins” (a sphere and cube joined mesh) on the imported stl item by double clicking in the scene. The problem is currently the “pins” are upright and therefore sometimes hidden inside the imported STL item.

Is there something I can do so that the pins are touching the stl mesh but always point away from it?

For example, the red pin in the upper right of the image is vertical but I want it to be more horizontal so it looks like it is coming out of the side of the imported stl mesh.

Playground: [Babylon.js Playground](https://playground.babylonjs.com/#RDLDNZ)

---

<div class="post-metadata">

**Author:** ![tjshipe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tjshipe/32/194_2.png) [@tjshipe](https://forum.babylonjs.com/u/tjshipe)\
**Post date:** [December 18, 2018, 9:19pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/2 "2018-12-18T21:19:20Z")

</div>

I’ve looked into using a combination of `lookAt` and collision checks but neither have worked for me so far.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [December 18, 2018, 10:21pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/3 "2018-12-18T22:21:12Z")

</div>

i guess you can use [scene.pickWithRay](https://doc.babylonjs.com/babylon101/raycasts) in order to find the surface point of contact.  
pickWithRay will return a [PickingInfo](https://doc.babylonjs.com/api/classes/babylon.pickinginfo) where you can get the surface normal. Then just align your pin with the normal and place it at surface contact point 🙂

---

<div class="post-metadata">

**Author:** ![tjshipe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tjshipe/32/194_2.png) [@tjshipe](https://forum.babylonjs.com/u/tjshipe)\
**Post date:** [December 18, 2018, 10:58pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/4 "2018-12-18T22:58:42Z")

</div>

Thanks for the suggestion!

Is pickWithRay the same as `scene.pick`? I’m currently using the scene.pick function to get the x,y,z coords on dbl click to know where to place the “pin”.

I made a playground so you can see:  
[https://playground.babylonjs.com/#RDLDNZ](https://playground.babylonjs.com/#RDLDNZ)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [December 18, 2018, 11:03pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/5 "2018-12-18T23:03:41Z")

</div>

It is kind of the same except that you can give a ray instead of a 2d coordinates

---

<div class="post-metadata">

**Author:** ![tjshipe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tjshipe/32/194_2.png) [@tjshipe](https://forum.babylonjs.com/u/tjshipe)\
**Post date:** [December 18, 2018, 11:22pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/6 "2018-12-18T23:22:55Z")

</div>

Okay, making progress. Thanks again. I now have the surface normal but I’m struggling with aligning the pin by placing it at the surface contact point. Can you give me an example of how to do this with a mesh given I have the surface normal?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [December 18, 2018, 11:28pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/7 "2018-12-18T23:28:06Z")

</div>

this could help: [Babylon.js Documentation](https://doc.babylonjs.com/how_to/rotate#how-to-generate-a-rotation-from-a-target-system)

---

<div class="post-metadata">

**Author:** ![tjshipe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tjshipe/32/194_2.png) [@tjshipe](https://forum.babylonjs.com/u/tjshipe)\
**Post date:** [December 19, 2018, 12:23am UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/8 "2018-12-19T00:23:05Z")

</div>

Thanks. Are you suggesting I look at using Euler Angles or using Quaternions? This whole section of the docs is new to me.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [December 19, 2018, 12:27am UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/9 "2018-12-19T00:27:59Z")

</div>

both are fine here. Please pick the one you prefer 😉

a good read as well: [Babylon.js Documentation](https://doc.babylonjs.com/features/position,_rotation,_scaling)

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [December 19, 2018, 12:32am UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/10 "2018-12-19T00:32:01Z")

</div>

Hi guys. I think a key term here is “orthogonal”.  
[A search of old forum for “orthogonal”](http://www.html5gamedevs.com/search/?&q=orthogonal&type=forums_topic&page=2&nodes=28,29,30,31,38&search_and_or=or) does okay.

Interesting playgrounds found…  
[https://www.babylonjs-playground.com/#2C8LVE#16](https://www.babylonjs-playground.com/#2C8LVE#16)  
[https://playground.babylonjs.com/#2A0HNY](https://playground.babylonjs.com/#2A0HNY)  
[https://www.babylonjs-playground.com/#MZDDK#7](https://www.babylonjs-playground.com/#MZDDK#7)

@jerome has made a BUNCH of posts about “direction to rotation”… which is really what you want, @tjshipe. Aligning the object… to the normal of the clicked face. I’m not very good at it.

In that #2A0HNY playground, look carefully at lines 23+.

I hope I’m helpful. I assume you can already get the normal of the double-clicked point. IF you have that, maybe these playground will teach how to convert the normal’s axis… to an object rotation. Maybe. 🙂

---

<div class="post-metadata">

**Author:** ![tjshipe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tjshipe/32/194_2.png) [@tjshipe](https://forum.babylonjs.com/u/tjshipe)\
**Post date:** [December 19, 2018, 3:54am UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/12 "2018-12-19T03:54:46Z")

</div>

@Wingnut @Deltakosh This is what I was able to come up with. Let me know if you have any feedback or suggestions.

[https://playground.babylonjs.com/#TZTHV1#1](https://playground.babylonjs.com/#TZTHV1#1)

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [December 19, 2018, 9:38am UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/13 "2018-12-19T09:38:00Z")

</div>

Hi tjshipe! I think you’ve done it! Cool. Every double-click I try… works great! Well done.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [December 19, 2018, 1:59pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/14 "2018-12-19T13:59:19Z")

</div>

Looks good to me 🙂

---

<div class="post-metadata">

**Author:** ![Rah](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rah/32/201_2.png) [@Rah](https://forum.babylonjs.com/u/Rah)\
**Post date:** [December 19, 2018, 5:28pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/15 "2018-12-19T17:28:00Z")

</div>

This is really cool!  
Not sure if it is intended but you can double click points.  
I made a tower of points! 🙂

---

<div class="post-metadata">

**Author:** ![jhadenfeldt](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jhadenfeldt](https://forum.babylonjs.com/u/jhadenfeldt)\
**Post date:** [December 19, 2018, 6:49pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/16 "2018-12-19T18:49:24Z")

</div>

I noticed that too, super easy to prevent though: [https://playground.babylonjs.com/#TZTHV1#2](https://playground.babylonjs.com/#TZTHV1#2)

---

<div class="post-metadata">

**Author:** ![tjshipe](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tjshipe/32/194_2.png) [@tjshipe](https://forum.babylonjs.com/u/tjshipe)\
**Post date:** [December 19, 2018, 11:59pm UTC](https://forum.babylonjs.com/t/how-can-i-make-a-mesh-sit-on-the-surface-of-another-mesh/315/17 "2018-12-19T23:59:31Z")

</div>

Good catch! I actually didn’t intend to double click points.
