two.js icon indicating copy to clipboard operation
two.js copied to clipboard

In ZUI, surfaceToClient calculation does not take translateSurface into account.

Open alper-batioglu opened this issue 3 years ago • 2 comments

Describe the bug surfaceToClient of ZUI does not get affected by prior translateSurface (aka. panning)

To Reproduce Steps to reproduce the behavior:

  1. Go to https://codepen.io/jonobr1/pen/PobMKwb
  2. Write console.log(JSON.stringify(zui.surfaceToClient({x:10, y:10}))) on line 62 (below zui.translateSurface(dx, dy);)
  3. Pan the surface with mouse
  4. Observe surfaceToClient calculation of x:10, y:10 is not affected by translateSurface on the new x, y coordinates on console
  5. Also observe how zoom-in and zoom-out by mouse wheel affects surfaceToClient calculation. (zoom-in and then pan the surface)

Expected behavior surfaceToClient calculation should be affected by translateSurface (aka. panning)

Environment (please select one):

  • [X] Code executes in browser (e.g: using script tag to load library)
  • [ ] Packaged software (e.g: ES6 imports, react, angular, vue.js)
  • [ ] Running headless (usually Node.js)

Desktop (please complete the following information):

  • OS: Mac Os Monterey 12.4
  • Browser: Microsoft Edge
  • Version: 104.0.1293.54 (Official build) (arm64)

alper-batioglu avatar Aug 16 '22 09:08 alper-batioglu

Thanks for posting. This fixes that issue: https://github.com/jonobr1/two.js/pull/661

If you're using an NPM version of Two.js. An interim fix you can make on your end (until the latest version is published to NPM) is to also pass a z component where z = 1.

E.g: console.log(JSON.stringify(zui.surfaceToClient({ x: 10, y: 10, z: 1 })));

jonobr1 avatar Aug 16 '22 17:08 jonobr1

omg, how did I not try that. Thanks. :)

alper-batioglu avatar Aug 18 '22 14:08 alper-batioglu