Custom control linked to a mesh is not cached and redraws every frame (+dubious workaround)

Hi.

I’m trying to implement custom controls. I’m gonna have lots of controls linked to mesh and concerned about performance.

With my naive implementation of just overriding _draw the control is being redrawn on every frame, even when scene is still.

In the playground dev console is spammed with “redraw” logs from MyDot control.


The reason seems to be that linked controls are subject for _moveToProjectedPosition and it unconditionally marks them dirty (three times in a row per frame).

I’ve implemented a workaround in MyCachingDot class and that seems working, it only redraws control when target mesh dances (on spacebar) or when camera turning.

But that looks way too hackish and I’m not sure that’s the right way to do things.

Any better suggestions?

cc @amoebachant

Hey @qwiglydee - I looked into this today and it does look like the control is getting marked dirty when it shouldn’t be due to an old change which was fixing an unrelated bug. I’m investigating a better way to fix that bug that doesn’t have this side effect, but I won’t be online tomorrow so it may be a few days. Your workaround seems like a reasonable thing to do to stay unblocked, and I’ll let you know what I learn when I dig further.

Thanks!

Hi @qwiglydee - I was able to find a better fix to the old bug which allows the optimization to work again which prevents redraw if the position doesn’t change. It’s now in PR here: Fix GUI 2D optimization and consistently apply states when measuring by AmoebaChant · Pull Request #16945 · BabylonJS/Babylon.js · GitHub

With this fix I’m only seeing your console log when the position of the control moves.
Thanks for reporting this!

Nice!

Thanks for your efforts!

Is the patch already in the yesterday’s release?

(playground shows it runs 8.20 but release info for 8.20 doesn’t list the patch)

Patch should be live in the playground right now, but it’s not in the published 8.20.0 package.

Thanks @alexchuber, yes I just confirmed the playground was updated after the fix went in, and I no longer repro the issue in the playground. @qwiglydee is it working for you now?