# New feature: Mesh Hotspots

**URL:** <https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103>\
**Category:** Announcements\
**Tags:** mesh\
**Created:** [October 14, 2024, 9:56am UTC](https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103 "2024-10-14T09:56:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [October 14, 2024, 9:56am UTC](https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103/1 "2024-10-14T09:56:32Z")

</div>

Mesh hotspot is a new feature aiming at computing a world coordinate from a surface info of an animated and deformed mesh. Basically, from a triangle and barycentric infos, it computes the world coordinates of that point, for skinned, morphed or static meshes.

Soon to be merged documentation, with code is here : [Mesh hotspot by CedricGuillemet · Pull Request #1215 · BabylonJS/Documentation · GitHub](https://github.com/BabylonJS/Documentation/pull/1215)

And 2 examples with animated mesh are visible here :

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/5/9543235b8f3ef789cdd58806a4ff538a6b9f9844.png)

> **[Babylon.js Playground](https://playground.babylonjs.com/#BQOFIX%2317)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/9/59638f3fba8bba07ed2f7319ea9681ed1be069d6.jpeg)

> **[Babylon.js Playground](https://playground.babylonjs.com/#BQOFIX%2318)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

---

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [October 14, 2024, 1:31pm UTC](https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103/2 "2024-10-14T13:31:27Z")

</div>

I love it ! 😁  
I remember helping @alexandremottet when he was trying exactly this, manually, in [this topic](https://forum.babylonjs.com/t/compute-surface-faceid-world-position-from-pickwithray/50234)  
Compared to [such manual solution](https://playground.babylonjs.com/#F9NNOF#21) (double click on surface) :

```javascript
const indices = pickedMesh.getIndices();
let bw = 1 - bu - bv;
// run the following on each render :
let pointPosition = BABYLON.Vector3.Zero();
pointPosition.addInPlace(facePositions[0].scale(bu));
pointPosition.addInPlace(facePositions[1].scale(bv));
pointPosition.addInPlace(facePositions[2].scale(bw));
// etc, etc...

```

We will save a lot of code ! 😁

* * *

> [@Cedric](#):
>
> And 2 examples with animated mesh are visible here :

Is it supposed to work as well at picking time or not ? Because what I can notice, is that on my side, even tough it works after picking (tracking of the point along animated surface), the picking itself seems to happen on the static mesh (picking multiple times at the same 2D spot won’t change the picked point, while the animation is running. Also, sometimes picking outside in the background actually picks the mesh, etc…)

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [October 30, 2024, 6:31pm UTC](https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103/3 "2024-10-30T18:31:49Z")

</div>

> [@Tricotou](#):
>
> Is it supposed to work as well at picking time or not ? Because what I can notice, is that on my side, even tough it works after picking (tracking of the point along animated surface), the picking itself seems to happen on the static mesh (picking multiple times at the same 2D spot won’t change the picked point, while the animation is running. Also, sometimes picking outside in the background actually picks the mesh, etc…)

Yes there is a little more work needed to make sure picking is accurate while skeletal or morph target animations are running. Specifically, `refreshBoundingInfo` must be called at the end of a frame right before picking. Here is an updated PG: [https://playground.babylonjs.com/#BQOFIX#16](https://playground.babylonjs.com/#BQOFIX#16)

---

<div class="post-metadata">

**Author:** ![Forsaken](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/forsaken/32/21296_2.png) [@Forsaken](https://forum.babylonjs.com/u/Forsaken)\
**Post date:** [October 31, 2024, 9:35am UTC](https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103/4 "2024-10-31T09:35:06Z")

</div>

Neat!

Something I noticed, when you open the inspector, the hotspot seems to be off.

I also had this issue with my own version of this functionality, just never bothered fixing it since it’s a niche scenario. But curious on how one would fix this.

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [October 31, 2024, 9:41am UTC](https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103/5 "2024-10-31T09:41:27Z")

</div>

This is due to the viewport not being updated with new rendering sizes.  
Once the update is done everyframe, it works fine.

> **[Babylon.js Playground](https://playground.babylonjs.com/#BQOFIX%2314)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

---

<div class="post-metadata">

**Author:** ![leo\_h](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/leo_h/32/39859_2.png) [@leo\_h](https://forum.babylonjs.com/u/leo_h)\
**Post date:** [November 25, 2024, 6:57pm UTC](https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103/6 "2024-11-25T18:57:17Z")

</div>

@ryantrem I see you added a `interpolateTo` method to the ArcRotateCamera (to make use of with the hotspots), however when testing it out it doesn’t seem to… interpolate, and rather just instantly jumps to the given position. Is this intentional? And if so may I ask why you chose to name it `interpolateTo` rather than e.g. `moveTo` or `jumpTo` even though it doesn’t interpolate? It’s slightly confusing 😅

```auto
camera.interpolateTo(angle[0], angle[1], angle[2] + (window.innerWidth < 756 ? (angle[6] != undefined ? angle[6] : 4) : 0), new Vector3(angle[3], angle[4], angle[5]));

```

Thanks for your great work as always 🙂

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [November 27, 2024, 10:38pm UTC](https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103/7 "2024-11-27T22:38:51Z")

</div>

Hey @leo_h - thanks for the feedback, much appreciated! `ArcRotateCamera` already had behavior to interpolate its pose when resetting to the previously saved state (e.g. `storeState` and `restoreState`), so when I introduced the `interpolateTo` function it was a bit of refactoring of the existing code (so that you could specify the new camera pose to interpolate to rather than only being able to interpolate to the single stored state). For `storeState` and `restoreState`, the interpolation relies on the `restoreStateInterpolationFactor` property, which is 0 by default (for back compat). The new `interpolateTo` function also relies on this property, and you can see an example here: [Babylon.js Playground](https://playground.babylonjs.com/#TGU13J)

That said, I realize now that this is confusing, and I’m trying to think of the best way to improve the API while maintaining back compat. I think maybe what would be best would be to add one more (optional) parameter to `interpolateTo` for the `interpolationFactor`. I think the behavior that would make sense would be:

1. If an argument is explicitly passed in for the `interpolationFactor` parameter, that would be the factor used.
2. If an argument is not explicitly passed in for the `interpolationFactor` parameter, then it would default to the `restoreStateInterpolationFactor` if it is non-zero, otherwise it would default to some “reasonable value” (~0.1).

Let me know if you have thoughts on this!

---

<div class="post-metadata">

**Author:** ![leo\_h](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/leo_h/32/39859_2.png) [@leo\_h](https://forum.babylonjs.com/u/leo_h)\
**Post date:** [November 27, 2024, 11:26pm UTC](https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103/8 "2024-11-27T23:26:12Z")

</div>

That does sound like a good solution, yes! That way it leaves both options open - and allows for the functionality of directly using `interpolateTo` to interpolate as the name suggests rather than relying on other factors being set beforehand.

Also - I know it’s super new so no rush, but it would be great to have it added into the documentation as well at some point! Having an easy-to-use camera interpolation function I think is great - it’s something which I imagine is quite common to want and until now relied on either “misusing” state restoration (at least from a naming - and therefore readability - perspective) or having to implement a bunch of animation and easing stuff. So I think it should definitely be included in the documentation so people know about it!

Thanks as always for being open to feedback - I was chatting with some PhD students + lecturer the other day about babylon.js and the activeness of you and the other devs on this forum was a very strong point in its favor 😄

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [December 2, 2024, 9:54pm UTC](https://forum.babylonjs.com/t/new-feature-mesh-hotspots/54103/9 "2024-12-02T21:54:37Z")

</div>

PR for this change is here: [Add param for interpolation factor to ArcRotateCamera.interpolateTo by ryantrem · Pull Request #15923 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/pull/15923)
