aligator / gcode-viewer

A simple gcode viewer lib using three.js
MIT License
37 stars 8 forks source link

Update aspect ratio on canvas resize #1

Closed tobychui closed 3 years ago

tobychui commented 3 years ago

Hi there!

I was trying to integrate this gcode viewer into the SlicerA and observed an issue when I attach window resize events to the canvas. 2021-05-06_10-40-08

Would it be possible for you to add an automatic logic for adjusting the aspect ratio when the DOM element resized? Thanks!

aligator commented 3 years ago

Just call renderer.resize(width, height) whenever you want to resize it. Then the camera will be recalculated. I needed the same for my website and it works just fine: https://github.com/aligator/dev/blob/45374ff9f2b1d3ac96bbfac9bd64182cf3451a4f/src/windows/gCodeViewer.tsx#L64

tobychui commented 3 years ago

I have updated the implementation of gcode viewer in SlicerA using your website source code as example. Thanks so much for the tips!