xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
728 stars 287 forks source link

AngleMeasurementsPlugin red dot is not at the position of the mouse pointer #1479

Closed Trufinol closed 6 months ago

Trufinol commented 6 months ago

Is this bug fix critical for your commercial enterprise? no

Describe the bug When a viewer is mounted inside a modal window, the red dot position of a AngleMeasurementsPlugin or DistanceMeasurementsPlugin does not match the cursor position.

To Reproduce Steps to reproduce the behavior:

  1. Mount a model inside of a modal window with some margin around the viewport.
  2. Enable the AngleMeasurementsPlugin or or DistanceMeasurementsPlugin.
  3. See that the red dot is not under the mouse cursor.

Expected behavior Red dot should be positioned on the mouse cursor.

Screenshots image

Desktop (please complete the following information):

xeolabs commented 6 months ago

Getting the red dot to appear at the right position has been a weirdly difficult thing to make work robustly for all page layouts.

All we want to do is transform a 2D position from canvas coordinates to page coordinates, but it seems that no matter what we've tried so far, there's always some layout for which our built-in function doesn't work correctly.

Therefore, I made that canvas->page 2D transformation user-configurable via a canvasToPagePos callback on the measurements plugins.

Could you see if you can implement this callback to do the transformation yourself - see this example: https://github.com/xeokit/xeokit-sdk/blob/master/examples/measurement/angle_createWithMouse_snapping_canvasToPagePos.html#L194

Then, if you find something that works, that might give us a clue on how to more correctly implement the mapping internally.

Thanks

Trufinol commented 6 months ago

Thank you for the hint. In my case, applying canvasPos to pagePos fixed the issue. However, in the typescript definition the canvasToPagePos is missing at both DistanceMeasurementsMouseControl and AngleMeasurementsMouseControl.

https://github.com/xeokit/xeokit-sdk/blob/master/types/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsMouseControl.d.ts https://github.com/xeokit/xeokit-sdk/blob/master/types/plugins/AngleMeasurementsPlugin/AngleMeasurementsMouseControl.d.ts Is it possible to include it in the next minor release or do you need any participation on this?

xeolabs commented 6 months ago

Thank you for the hint. In my case, applying canvasPos to pagePos fixed the issue. However, in the typescript definition the canvasToPagePos is missing at both DistanceMeasurementsMouseControl and AngleMeasurementsMouseControl.

https://github.com/xeokit/xeokit-sdk/blob/master/types/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsMouseControl.d.ts https://github.com/xeokit/xeokit-sdk/blob/master/types/plugins/AngleMeasurementsPlugin/AngleMeasurementsMouseControl.d.ts Is it possible to include it in the next minor release or do you need any participation on this?

Oops I'll fix that tonight - https://github.com/xeokit/xeokit-sdk/issues/1481