# Scene trianglePickingPredicate?

**URL:** <https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088>\
**Category:** Questions\
**Created:** [September 25, 2021, 8:33am UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088 "2021-09-25T08:33:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [September 25, 2021, 8:33am UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/1 "2021-09-25T08:33:42Z")

</div>

ok, this feels like a dumb question but I couldn’t find a neat solution somehow and beating against the wall leaves me even more tired.

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

I have a large terrain (ie, the ground in repro). In my use case, pointermove drops my fps so by design, I made my ground not pickable by default and toggle it when needed. It works great. But pointermove now triggers when mousing over the occluded part of the sphere. So ideally, I’m looking to have renderOverlay only trigger when user mouse-over the unoccluded part of the sphere and still keep the ground not pickable. What mesh property can I use in the predicate ? Or is there a way for me to insert a custom trianglePredicate in the scene to filter out `pickedPoint.y > 0`?

---

<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:** [September 26, 2021, 4:07pm UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/2 "2021-09-26T16:07:06Z")

</div>

Your case is becoming pretty complex and I guess I would normally solve it by manually picking and such which can help with the trianglePredicate.

Or you could split your mesh in 2 to have on pickable and one unpickable part ?

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [September 28, 2021, 5:01am UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/3 "2021-09-28T05:01:33Z")

</div>

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

Managed to get the trianglepicking predicate in, but the action manager doesn’t seem to recognize it. What should I do to get the action manager to use my pickinfo for triggering? Or do I have to ditch action managers and process everything in my own pointermove observable loop? If so, wouldn’t there be 2 pointermoves triggering in the scene every mouse move (bjs default+user custom)? Is there a way to switch the default off?

---

<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:** [September 28, 2021, 10:22am UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/4 "2021-09-28T10:22:00Z")

</div>

Maybe in your custom picking you can register a boolean in your scene with true/false depending on your pick result and use this as your actions conditions.

After in you prefer to build your own custom code it might be simpler to manage and you should in this case not have overhead cause only the meshes with actionManager would go through the process.

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [September 28, 2021, 11:08am UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/5 "2021-09-28T11:08:12Z")

</div>

> [@sebavan](#):
>
> Maybe in your custom picking you can register a boolean in your scene with true/false depending on your pick result and use this as your actions conditions.

Like this ? [https://playground.babylonjs.com/#G8E6K3#2](https://playground.babylonjs.com/#G8E6K3#2)

The trigger only ever fires once and its not firing with respect to the condition…hmm

---

<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:** [September 28, 2021, 8:13pm UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/6 "2021-09-28T20:13:25Z")

</div>

Writing it this way would make it better: [https://playground.babylonjs.com/#G8E6K3#3](https://playground.babylonjs.com/#G8E6K3#3)

But it still wont be enough cause basically nothing will be checked as long as you do not truly go outside the full mesh.

So your best bet is full custom code which is by far simpler to write as well:  
[https://playground.babylonjs.com/#G8E6K3#6](https://playground.babylonjs.com/#G8E6K3#6)

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [September 29, 2021, 1:20am UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/7 "2021-09-29T01:20:48Z")

</div>

I want to avoid the custom code in the obs. When the number of spheres/objects grow, said custom code becomes monolithic very quickly. Hence the reason for action manager. I’m going to investigate if its worth a PR for `scene.trianglePickingPredicate` and modify pointerMove events in the input manager to take advantage of it.

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [September 29, 2021, 3:31am UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/8 "2021-09-29T03:31:48Z")

</div>

ok, it works. added into `scene.ts`  
`public tpp: (p0: Vector3, p1: Vector3, p2: Vector3, ray: Ray) => boolean;`  
modified `inputmanager.ts this._onPointerMove`

```auto
var pickResult;
if (!scene.tpp) {
	pickResult = scene.pick(this._unTranslatedPointerX, this._unTranslatedPointerY, scene.pointerMovePredicate, false, scene.cameraToUseForPointers);
} else {
	pickResult = scene.pick(this._unTranslatedPointerX, this._unTranslatedPointerY, scene.pointerMovePredicate, false, scene.cameraToUseForPointers, scene.tpp);
}

```

I think this is back compat? Now, the biggest question is: I don’t think `tpp` is the the best param name ever, so looking for suggestions ! And `scene.ts` already uses `trianglePredicate` and `trianglePickingPredicate` everywhere. What’s a better name than tpp? hmm…

---

<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:** [September 29, 2021, 1:28pm UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/9 "2021-09-29T13:28:22Z")

</div>

I would call it pointerMoveTrianglePredicate and place it to undefined by default, so that you can remove the if in input manager 🙂

---

<div class="post-metadata">

**Author:** ![phaselock](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@phaselock](https://forum.babylonjs.com/u/phaselock)\
**Post date:** [September 30, 2021, 3:54am UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/10 "2021-09-30T03:54:16Z")

</div>

done and done…but lint failed and my eyes are not seeing where the problem is. I need a feature request for old people with bad eyes, automatic lint correction when `PR.requester.eyes.age === "old"`.

edit: nvm, I found the magic command…ehehehe

---

<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:** [September 30, 2021, 12:21pm UTC](https://forum.babylonjs.com/t/scene-trianglepickingpredicate/24088/11 "2021-09-30T12:21:25Z")

</div>

Perfect thanks a lot @phaselock !!!
