three.js
is a 3D library and can’t help you with this task. Maybe this article gives you some insights . There is also a section about implementing an experimental HTML5 compass.
https://mobiforge.com/design-development/html5-mobile-web-device-orientation-events