Extensions icon indicating copy to clipboard operation
Extensions copied to clipboard

HtmlMesh Renders Incorrectly When Browser Window is Resized

Open Dorado8 opened this issue 1 year ago • 1 comments

In the example [https://www.babylonjs-playground.com/#Y2LIXI#44], when you drag to resize the right-side canvas, you will notice that the overlayMesh and overlayMeshDiv are misaligned. After reviewing the source code, I found that the issue lies in the createGetCanvasRectGenerator function in the utils.ts file. This method uses updateInterval for throttling, which causes the final render to be misaligned. This issue is most noticeable when the browser is zoomed in or out. My solution is to use lodash.throttle(boundOnResize, 500, { leading: true, trailing: true }) for throttling.

https://github.com/user-attachments/assets/f863c15b-b271-4666-99d6-cc0dea4fea73

Dorado8 avatar Jul 26 '24 09:07 Dorado8

After making this change, the HtmlMesh renders correctly. I initially positioned it on the yellow sphere, and no matter how the canvas size is changed, it remains properly aligned.

https://github.com/user-attachments/assets/6e9fd3ac-24eb-41c8-8dc3-7738aa7a2247

Dorado8 avatar Jul 26 '24 09:07 Dorado8

for anyone looking for a solution that does the resizing immediately by the next render, I wrote about another hacky workaround to solve this in https://github.com/BabylonJS/Babylon.js/issues/15788

PSI497 avatar Oct 25 '24 23:10 PSI497

Closing as we will tackle it with https://github.com/BabylonJS/Babylon.js/issues/15788

deltakosh avatar Nov 07 '24 17:11 deltakosh