Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9595 lines
254 KiB

5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('three')) :
  3. typeof define === 'function' && define.amd ? define(['exports', 'three'], factory) :
  4. (global = global || self, factory(global.PANOLENS = {}, global.THREE));
  5. }(this, function (exports, THREE) { 'use strict';
  6. const version="0.12.1";const dependencies={three:"^0.105.2"};
  7. /**
  8. * REVISION
  9. * @module REVISION
  10. * @example PANOLENS.REVISION
  11. * @type {string} revision
  12. */
  13. const REVISION = version.split( '.' )[ 1 ];
  14. /**
  15. * VERSION
  16. * @module VERSION
  17. * @example PANOLENS.VERSION
  18. * @type {string} version
  19. */
  20. const VERSION = version;
  21. /**
  22. * THREEJS REVISION
  23. * @module THREE_REVISION
  24. * @example PANOLENS.THREE_REVISION
  25. * @type {string} threejs revision
  26. */
  27. const THREE_REVISION = dependencies.three.split( '.' )[ 1 ];
  28. /**
  29. * THREEJS VERSION
  30. * @module THREE_VERSION
  31. * @example PANOLENS.THREE_VERSION
  32. * @type {string} threejs version
  33. */
  34. const THREE_VERSION = dependencies.three.replace( /[^0-9.]/g, '' );
  35. /**
  36. * CONTROLS
  37. * @module CONTROLS
  38. * @example PANOLENS.CONTROLS.ORBIT
  39. * @property {number} ORBIT 0
  40. * @property {number} DEVICEORIENTATION 1
  41. */
  42. const CONTROLS = { ORBIT: 0, DEVICEORIENTATION: 1 };
  43. /**
  44. * MODES
  45. * @module MODES
  46. * @example PANOLENS.MODES.UNKNOWN
  47. * @property {number} UNKNOWN 0
  48. * @property {number} NORMAL 1
  49. * @property {number} CARDBOARD 2
  50. * @property {number} STEREO 3
  51. */
  52. const MODES = { UNKNOWN: 0, NORMAL: 1, CARDBOARD: 2, STEREO: 3 };
  53. /**
  54. * Data URI Images
  55. * @module DataImage
  56. * @example PANOLENS.DataImage.Info
  57. * @property {string} Info Information Icon
  58. * @property {string} Arrow Arrow Icon
  59. * @property {string} FullscreenEnter Fullscreen Enter Icon
  60. * @property {string} FullscreenLeave Fullscreen Leave Icon
  61. * @property {string} VideoPlay Video Play Icon
  62. * @property {string} VideoPause Video Pause Icon
  63. * @property {string} WhiteTile White Tile Icon
  64. * @property {string} Setting Settings Icon
  65. * @property {string} ChevronRight Chevron Right Icon
  66. * @property {string} Check Check Icon
  67. * @property {string} ViewIndicator View Indicator Icon
  68. */
  69. const DataImage = {
  70. Info: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAABAAAAAQADq8/hgAAADBklEQVR42u2bP08UQRiHnzFaSYCI/xoksdBIqGwIiYWRUBISExpCQ0ej38FWOmlIKKhoMPEbaCxsrrHiYrQgOSlQEaICrT+LHSPZzNzt3s3c3Hn7lHvLzvv82L2dm30XKioqKgYY062BJF0HpoA7wARwBbhsPz4DjoEG8AnYNcZ8Sx1Op8IXJM1KWpdUV3nq9m9nJV1I7VNGfEzSM0mNNqR9NOwxx1L7NRMflbQm6SSgeJ4TO8Zoat+8/LKkg4jieQ4kLaf2RtKwpJ0uiufZkTScSn5S0l5C+b/sSZrstvyMpKPU5uc4kjTTjkvpeYCkaeA1/+7hvcIZMGuMqUULQNIU8Aa4ltrWwyHwyBizGzwASSPAe+B2assW7AH3jTE/i+xcZoa12Qfy2Bo3i+5cKABl99zF1GYlWFTBeULLS0DZrOsDcDNggTXgc27bLWA64BhfgHvGmB8dHUXZ1DM0S45xliKMs9bKr+klIOkqsBrwv9JtVq1DewEAT4Ch1BYdMGQdygeg7Df4SmqDAKyoyXpCszPgITCeuvoAjFuX0gE8jljUdv7bCtiOOJ7XpdUZ8L/gdXHOA5QtYH5NXXVgbrgWWn1nwFTqaiPgdPIFcDd1tRFwOl307DwRuZgXwLvctgfA04hjOp18AcReZ6sZY16e3yDpUuQxnU6+S2AkcjEpcDr1zxOXSPgCKLSa0mc4nXwB/EpdbQScTr4AGqmrjYDTyRfAx9TVRsDp5Aug8LJyH+F0cgZg58z11BUHpO5ruGh2G3ybuuqAeF2aBfAqddUB8bq0OgP2U1cegH3aOQOMMb+BrdTVB2DLupQLwLIOnKY26IBT6+ClaQDGmO/ARmqLDtiwDn7HVkcY+EdjNoTlCI+tYhO2iUppm6HKslPUq2qQKHpUe8AFsjaUXuUQWCgqXyoAG8IuME/WkNRrnAHzZfqDSgdgQ6gBc2Td3b3CMTBXtkOsIzTIjZLnQhjcVtlcEIPZLJ0LoVvt8s/Va+3yuSAG84UJRxB98cpM9dJURUVFxSDzBxKde4Lk3/h2AAAAAElFTkSuQmCC',
  71. Arrow: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAABAAAAAQADq8/hgAAADPklEQVR42u2bMUscQRiG30/SRaJEI1ZKUiRErNIELRUbQYSAnX8hpVUgkDYp0wgWVjYW+QcJaQzYpLojJIXhtDDEKBpj65ti58ixmdmb2ZvZ7+T2AUHudmfmeXf2bnb3O6CmpqZmgJGqOiI5AWAWwEMA0wDuArht3r4CcAagBeAbgIaI/NQOp1fhIZKLJN+SbDKcptl3keSQtk+I+BjJVyRbJaRdtEybY9p+ReKjJN+QvIwonufS9DGq7ZuXXyd5nFA8zzHJdW1vkLxDcrdC8Ty7JO9oyc+QPFCUb3NAcqZq+TmSp9rmHZySnCvjErwOIPkUwHv8+w7vF64ALIrIfrIASM4C+ADgnratgxMACyLSiB4AyREAnwE80LbswgGAJyJy4bNxyApr6wbIw4xxy3djrwCYfeeuaZsFsEbPdULXU4DZqusLgMkEA21P05EEbf8A8FhEzos28pkBLxLKL5s/r/M1kEkz9vKQHGeatf05yfmOfubNa7G5JDle5NhtBjwHMBz5yFwAWBaRT+0XzP8pZsKwcQiH2fX8Ycojb+kzxUw4ZJn7CSQXqpRPHMKCq7+iZJ71Mvdy/DftXSQ6HcJdSDaqPPKW/mPOBO+lcbvzCU35RCFM2PpwnQKzZQfdgfe0dxH5dLA6uQJ4pC2fIASrkyuA6X6QjxyC1ckVQNn7bNHlI4ZgdXIFUObiJJl8pBCsTjGfuIwA2Cv4FN7xbYjkjqsRAHuIePXoCiDF1Zk2VidXAL+1R5sAq5MrgJb2aBNgdXIF8FV7tAmwOrkCCFs73wysTtYATHFCU3vEEWm6Ci6KvgY/ao86Ik6XogDeaY86Ik6XbjPgSHvkEThCwQy45XpDRK5JbgN4GWkgUyR9H65MRQxgW0SunZ5FezK7pfwd8e8MV8UfAPdF5Jdrg8JrAbPjprZFD2wWyQP6j8ZSEufRmGlgQ9umBBvd5IOgbjFUKLu+XnWBhG+rpsFVZGUo/coJgFVf+aAATAgNACvICpL6jSsAKyH1QcEBmBD2ASwhq+7uF84ALIVWiPUEB7lQsiOEwS2VzQUxmMXSuRCqKpd/zX4rl88FMZg/mLAEcSN+MlP/aKqmpqZmkPkL0hSjwOpNKxwAAAAASUVORK5CYII=',
  72. FullscreenEnter: 'data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjRkZGRkZGIiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHdpZHRoPSIyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICAgIDxwYXRoIGQ9Ik0wIDBoMjR2MjRIMHoiIGZpbGw9Im5vbmUiLz4KICAgIDxwYXRoIGQ9Ik03IDE0SDV2NWg1di0ySDd2LTN6bS0yLTRoMlY3aDNWNUg1djV6bTEyIDdoLTN2Mmg1di01aC0ydjN6TTE0IDV2MmgzdjNoMlY1aC01eiIvPgo8L3N2Zz4=',
  73. FullscreenLeave: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggc3R5bGU9ImZpbGw6I2ZmZiIgZD0iTTE0LDE0SDE5VjE2SDE2VjE5SDE0VjE0TTUsMTRIMTBWMTlIOFYxNkg1VjE0TTgsNUgxMFYxMEg1VjhIOFY1TTE5LDhWMTBIMTRWNUgxNlY4SDE5WiIgLz48L3N2Zz4=',
  74. VideoPlay: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggc3R5bGU9ImZpbGw6I2ZmZiIgZD0iTTgsNS4xNFYxOS4xNEwxOSwxMi4xNEw4LDUuMTRaIiAvPjwvc3ZnPg==',
  75. VideoPause: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggc3R5bGU9ImZpbGw6I2ZmZiIgZD0iTTE0LDE5LjE0SDE4VjUuMTRIMTRNNiwxOS4xNEgxMFY1LjE0SDZWMTkuMTRaIiAvPjwvc3ZnPg==',
  76. WhiteTile: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIABAMAAAAGVsnJAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAB1WlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDx0aWZmOkNvbXByZXNzaW9uPjE8L3RpZmY6Q29tcHJlc3Npb24+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgICAgIDx0aWZmOlBob3RvbWV0cmljSW50ZXJwcmV0YXRpb24+MjwvdGlmZjpQaG90b21ldHJpY0ludGVycHJldGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KAtiABQAAACRQTFRFAAAAAAAABgYGBwcHHh4eKysrx8fHy8vLzMzM7OzsAAAABgYG+q7SZgAAAAp0Uk5TAP7+/v7+/v7+/iJx/a8AAAOwSURBVHja7d0hbsNAEAVQo6SFI6XEcALDcgNLvUBvEBQVhpkWVYWlhSsVFS7t5QIshRt695lEASZP+8c7a1kzDL1fz+/zyuvzp6FbvoddrL6uDd1yGZ5eXldeb18N3fIx7A+58prmhm65DfvDcd0952lu6JabFbD/zVprZj1lzcys+fj9z8xTZtbT8rv8yWlu6BYAIgAAAAAAAAAAAABAM6QXEAEAAAAAAAAAgJ2gnaAIiIA3Q2qAGgAAAAAAAAAAAAAAAAAAAAAAAAAAQJsADkVFAAAAAAA8Bj0GRUAEREAEREAEREAEREAEAAAAAAAAAAB2gnaCIiACPplRA9QANUAERAAAAEVQERQBERCBVlfAcZ3aeZobusUKMGBhV6KUElHGKBERJR6/fxExRkQZl9/lT8S1oVsuhqyYMmPKjCkzvfcCpsxohrwY0Q06EAEAAAAAAAAAAACgGdILiAAAAAAAAAAAwE7QTlAERMCbITVADQAAAAAAAAAAAAAAAAAAAAAAAAAAwKmwQ1ERAAAAAACPQY9BERABERABERABERABERABAAAAAAAAAICdoJ2gCIiAT2bUADVADRABEQAAQBFUBEVABERgEyvAlJm+V4ApM6bMmDJjyowpM6bMdN0LmDKjGfJiRDfoQAQAAAAAAAAAAACAZkgvIAIAAAAAAAAAADtBO0EREAFvhtQANQAAAAAAAAAAAAAAAAAAAAAAAAAAAKfCDkVFAAAAAAA8Bj0GRUAEREAEREAEREAEREAEAAAAAAAAAAB2gnaCIiACPplRA9QANUAERAAAAEVQERQBERCBTawAU2b6XgGmzJgyY8qMKTOmzJgy03UvYMqMZsiLEd2gAxEAAAAAAAAAAAAAmiG9gAgAAAAAAAAAAOwE7QRFQAS8GVID1AAAAAAAAAAAAAAAAAAAAAAAAAAAAJwKOxQVAQAAAADwGPQYFAEREAEREAEREAEREAERAAAAAAAAAADYCdoJioAI+GRGDVAD1AAREAEAABRBRVAEREAENrECTJnpewWYMmPKjCkzpsyYMmPKTNe9gCkzmiEvRnSDDkQAAAAAAAAAAAAAaIb0AiIAAAAAAAAAALATtBMUARHwZkgNUAMAAAAAAAAAAAAAAAAAAAAAAAAAAHAq7FBUBAAAAADAY9BjUAREQAREQAREQAREQAREAAAAAAAAAABgJ2gnKAIi4JMZNUANUANEQAQAAFAEFUEREAER2MQKMGWm7xVgyowpM50PWen9ugNGXz1XaocAFgAAAABJRU5ErkJggg==',
  77. Setting: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAABAAAAAQADq8/hgAAADn0lEQVR42u2bzUsVURjGnyO6CPzAMnTjppAo3LTwH1CqTfaxbeOiRS37A0wXtROFVi1aRBs3LWohSIGbQAQXViBGRhG0UIRKUCpK7q/FnOB2uc6cOXNmRnGe3eW+H8/7zLln3vNxpQoVKlQ4wjBFJAFOSRqX1O7osivpvjHmU1nChBZglvSYLYJbS0EanCvIJzWK+gnsyH34/8OuMaYjb265jwCgz6N4SWq3vodbAEmnS/KtBDgoAgyU5BteAOAkMAPcBroc7PskDWfgN+wyDwBdltMMcDI3tYBnde/pHeARMNTErgd4APzweP834oeN1dMkz5DlsFNn/yyv4kdiSK4At4AO4CqwGaDwRmza2B0210qM7YhrXU59ANAq6bWkwQTTn5KO5fIE0uVYlXTeGLOXFMx1DrjlULwKKN41x6DlnIjEEQCckPRe0okCiguJr5LOGGO+xhm5jICJQ1i8LOeJJKPYEQAMKvrtt5ZdjSf2FM0Fq/sZJI2A6UNcvCz36TiDfUcAcE1SPu/U6Mm8k/TFfu6XdFb5iX3dGPM8lQfwNod3+TowBnQ3yddtv1vPIe+b1JIBiwEJ1IAJ208k5W21trWA+V/5CHAcmAtU/A2P/DcCiTAHHE8tgCVhgLvAXgYCk17Jo/yTGfLuWe7Zd72AC8CWB4n3OAz7mLytNkZabAEXMhfeQKYfWEpJZCxA3rGUOZeA/qDF15FpAz47EvlNk9neI2e3jeWCz0BbmvipNkSMMX8kuSZYM8Z8zyqAjbHmaN5mOeYjgIXrU93MWrxHrNQjrqiDkQMLHwG+OdqF3NN3jeXKzU8AoF1SzdH8XKhJUO7HZDXLMbwAwICkJUULFxe0SbqSVQAbw3Xi7Ze0ZLmGAzAKbHs0JGU1QtvAaIjCW4B7ZOvJy2qFa5a730RPtBiaz0CgnkiZi6F5fBZDVMvho7EhcuS3xJJ2hV9IupgTqaLw0hhzab8vq23xOG/r+LDsKjLgYVzxUnU0ltwK2wDezUyJmEwqXgp/PL4rvxthaeCSI+zxuA10J8ZkWdJNSb2SLkvayKHwDRu71+ZajrG941J8agALDQ3GU/a/IvMkYCPzmCbtLNEVmacNtgs5iP9fYVNEV1Q6Hez7yNZSL+J2SarTcpqiyV2iUkG0IvPFvbz5FbEn+KEk3wMjwMeSfCsBXFBdly9CAPk9ydyffpECuB5tZfVJjaKWueOSfinln6YK4lahQoUKRxd/AcRPGTcQCAUQAAAAAElFTkSuQmCC',
  78. ChevronRight: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTguNTksMTYuNThMMTMuMTcsMTJMOC41OSw3LjQxTDEwLDZMMTYsMTJMMTAsMThMOC41OSwxNi41OFoiIC8+PC9zdmc+',
  79. Check: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTIxLDdMOSwxOUwzLjUsMTMuNUw0LjkxLDEyLjA5TDksMTYuMTdMMTkuNTksNS41OUwyMSw3WiIgLz48L3N2Zz4=',
  80. ViewIndicator: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBpZD0idmlldy1pbmRpY2F0b3IiIGhlaWdodD0iMzAiIHdpZHRoPSIzMCIgdmlld0JveD0iLTIuNSAtMSAzMCAzMCI+Cgk8c3R5bGUgdHlwZT0idGV4dC9jc3MiPi5zdDB7c3Ryb2tlLXdpZHRoOjI7c3Ryb2tlLW1pdGVybGltaXQ6MTA7ZmlsbDpub25lO30uc3Qxe3N0cm9rZS13aWR0aDo2O3N0cm9rZS1taXRlcmxpbWl0OjEwO30KCTwvc3R5bGU+Cgk8Zz4KCQk8cGF0aCBjbGFzcz0ic3QwIiBkPSJNIDEyLjUgMCBBIDEyLjUgMTIuNSAwIDAgMCAtMTIuNSAwIEEgMTIuNSAxMi41IDAgMCAwIDEyLjUgMCIgdHJhbnNmb3JtPSJtYXRyaXgoMSwwLDAsMSwxMywxNS41KSI+PC9wYXRoPgoJCTxwYXRoIGNsYXNzPSJzdDIiIGQ9Ik0gMTMgMCBMIDEwIDIgTCAxNiAyIFoiPjwvcGF0aD4KCQk8cGF0aCBjbGFzcz0ic3QyIiBkPSJNIDIgMCBBIDIgMiAwIDAgMCAtMiAwIEEgMiAyIDAgMCAwIDIgMCIgdHJhbnNmb3JtPSJtYXRyaXgoMSwwLDAsMSwxMywxNS41KSI+PC9wYXRoPgoJCTxwYXRoIGNsYXNzPSJzdDEiIGlkPSJpbmRpY2F0b3IiIHRyYW5zZm9ybT0ibWF0cml4KDEsMCwwLDEsMTMsMTUuNSkiPjwvcGF0aD4KCTwvZz4KPC9zdmc+'
  81. };
  82. /**
  83. * @module ImageLoader
  84. * @description Image loader with progress based on {@link https://github.com/mrdoob/three.js/blob/master/src/loaders/ImageLoader.js}
  85. */
  86. const ImageLoader = {
  87. /**
  88. * Load image
  89. * @example PANOLENS.ImageLoader.load( IMAGE_URL )
  90. * @method load
  91. * @param {string} url - An image url
  92. * @param {function} onLoad - On load callback
  93. * @param {function} onProgress - In progress callback
  94. * @param {function} onError - On error callback
  95. */
  96. load: function ( url, onLoad = () => {}, onProgress = () => {}, onError = () => {} ) {
  97. // Enable cache
  98. THREE.Cache.enabled = true;
  99. let cached, request, arrayBufferView, blob, urlCreator, image, reference;
  100. // Reference key
  101. for (let iconName in DataImage) {
  102. if (DataImage.hasOwnProperty(iconName) && url === DataImage[iconName]) {
  103. reference = iconName;
  104. }
  105. }
  106. // Cached
  107. cached = THREE.Cache.get(reference ? reference : url);
  108. if (cached !== undefined) {
  109. if (onLoad) {
  110. setTimeout(function () {
  111. onProgress({loaded: 1, total: 1});
  112. onLoad(cached);
  113. }, 0);
  114. }
  115. return cached;
  116. }
  117. // Construct a new XMLHttpRequest
  118. urlCreator = window.URL || window.webkitURL;
  119. image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  120. // Add to cache
  121. THREE.Cache.add(reference ? reference : url, image);
  122. const onImageLoaded = () => {
  123. urlCreator.revokeObjectURL(image.src);
  124. onLoad(image);
  125. };
  126. if (url.indexOf('data:') === 0) {
  127. image.addEventListener('load', onImageLoaded, false);
  128. image.src = url;
  129. return image;
  130. }
  131. image.crossOrigin = this.crossOrigin !== undefined ? this.crossOrigin : '';
  132. request = new window.XMLHttpRequest();
  133. request.open('GET', url, true);
  134. if (process.env.npm_lifecycle_event !== 'test') {
  135. request.onreadystatechange = function () {
  136. if (this.readyState === 4 && this.status >= 400) {
  137. onError();
  138. }
  139. };
  140. }
  141. request.responseType = 'arraybuffer';
  142. request.addEventListener( 'error', onError );
  143. request.addEventListener( 'progress', event => {
  144. if ( !event ) return;
  145. const { loaded, total, lengthComputable } = event;
  146. if ( lengthComputable ) {
  147. onProgress( { loaded, total } );
  148. }
  149. } );
  150. request.addEventListener( 'loadend', event => {
  151. if ( !event ) return;
  152. const { currentTarget: { response } } = event;
  153. arrayBufferView = new Uint8Array( response );
  154. blob = new window.Blob( [ arrayBufferView ] );
  155. image.addEventListener( 'load', onImageLoaded, false );
  156. image.src = urlCreator.createObjectURL( blob );
  157. } );
  158. request.send(null);
  159. }
  160. };
  161. /**
  162. * @module TextureLoader
  163. * @description Texture loader based on {@link https://github.com/mrdoob/three.js/blob/master/src/loaders/TextureLoader.js}
  164. */
  165. const TextureLoader = {
  166. /**
  167. * Load image texture
  168. * @example PANOLENS.TextureLoader.load( IMAGE_URL )
  169. * @method load
  170. * @param {string} url - An image url
  171. * @param {function} onLoad - On load callback
  172. * @param {function} onProgress - In progress callback
  173. * @param {function} onError - On error callback
  174. * @return {THREE.Texture} - Image texture
  175. */
  176. load: function ( url, onLoad = () => {}, onProgress, onError ) {
  177. var texture = new THREE.Texture();
  178. ImageLoader.load( url, function ( image ) {
  179. texture.image = image;
  180. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  181. const isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  182. texture.format = isJPEG ? THREE.RGBFormat : THREE.RGBAFormat;
  183. texture.needsUpdate = true;
  184. onLoad( texture );
  185. }, onProgress, onError );
  186. return texture;
  187. }
  188. };
  189. /**
  190. * @module CubeTextureLoader
  191. * @description Cube Texture Loader based on {@link https://github.com/mrdoob/three.js/blob/master/src/loaders/CubeTextureLoader.js}
  192. */
  193. const CubeTextureLoader = {
  194. /**
  195. * Load 6 images as a cube texture
  196. * @example PANOLENS.CubeTextureLoader.load( [ 'px.png', 'nx.png', 'py.png', 'ny.png', 'pz.png', 'nz.png' ] )
  197. * @method load
  198. * @param {array} urls - array of 6 urls to images, one for each side of the CubeTexture. The urls should be specified in the following order: pos-x, neg-x, pos-y, neg-y, pos-z, neg-z
  199. * @param {function} onLoad - On load callback
  200. * @param {function} onProgress - In progress callback
  201. * @param {function} onError - On error callback
  202. * @return {THREE.CubeTexture} - Cube texture
  203. */
  204. load: function ( urls, onLoad = () => {}, onProgress = () => {}, onError ) {
  205. var texture, loaded, progress, all, loadings;
  206. texture = new THREE.CubeTexture( [] );
  207. loaded = 0;
  208. progress = {};
  209. all = {};
  210. urls.map( function ( url, index ) {
  211. ImageLoader.load( url, function ( image ) {
  212. texture.images[ index ] = image;
  213. loaded++;
  214. if ( loaded === 6 ) {
  215. texture.needsUpdate = true;
  216. onLoad( texture );
  217. }
  218. }, function ( event ) {
  219. progress[ index ] = { loaded: event.loaded, total: event.total };
  220. all.loaded = 0;
  221. all.total = 0;
  222. loadings = 0;
  223. for ( var i in progress ) {
  224. loadings++;
  225. all.loaded += progress[ i ].loaded;
  226. all.total += progress[ i ].total;
  227. }
  228. if ( loadings < 6 ) {
  229. all.total = all.total / loadings * 6;
  230. }
  231. onProgress( all );
  232. }, onError );
  233. } );
  234. return texture;
  235. }
  236. };
  237. /**
  238. * @classdesc User Media
  239. * @constructor
  240. * @param {object} [constraints={ video: { width: { ideal: 1920 }, height: { ideal: 1080 }, facingMode: { exact: 'environment' } }, audio: false }]
  241. */
  242. function Media ( constraints ) {
  243. const defaultConstraints = { video: { width: { ideal: 1920 }, height: { ideal: 1080 }, facingMode: { exact: 'environment' } }, audio: false };
  244. this.constraints = Object.assign( defaultConstraints, constraints );
  245. this.container = null;
  246. this.scene = null;
  247. this.element = null;
  248. this.devices = [];
  249. this.stream = null;
  250. this.ratioScalar = 1;
  251. this.videoDeviceIndex = 0;
  252. }
  253. Media.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype ), {
  254. setContainer: function ( container ) {
  255. this.container = container;
  256. },
  257. setScene: function ( scene ) {
  258. this.scene = scene;
  259. },
  260. /**
  261. * Enumerate devices
  262. * @memberOf Media
  263. * @instance
  264. * @returns {Promise}
  265. */
  266. enumerateDevices: function () {
  267. const devices = this.devices;
  268. const resolvedPromise = new Promise( resolve => { resolve( devices ); } );
  269. return devices.length > 0 ? resolvedPromise : window.navigator.mediaDevices.enumerateDevices();
  270. },
  271. /**
  272. * Switch to next available video device
  273. * @memberOf Media
  274. * @instance
  275. */
  276. switchNextVideoDevice: function () {
  277. const stop = this.stop.bind( this );
  278. const start = this.start.bind( this );
  279. const setVideDeviceIndex = this.setVideDeviceIndex.bind( this );
  280. let index = this.videoDeviceIndex;
  281. this.getDevices( 'video' )
  282. .then( devices => {
  283. stop();
  284. index++;
  285. if ( index >= devices.length ) {
  286. setVideDeviceIndex( 0 );
  287. index--;
  288. } else {
  289. setVideDeviceIndex( index );
  290. }
  291. start( devices[ index ] );
  292. } );
  293. },
  294. /**
  295. * Get devices
  296. * @param {string} type - type keyword to match device.kind
  297. * @memberOf Media
  298. * @instance
  299. */
  300. getDevices: function ( type = 'video' ) {
  301. const devices = this.devices;
  302. const validate = _devices => {
  303. return _devices.map( device => {
  304. if ( !devices.includes( device ) ) { devices.push( device ); }
  305. return device;
  306. } );
  307. };
  308. const filter = _devices => {
  309. const reg = new RegExp( type, 'i' );
  310. return _devices.filter( device => reg.test( device.kind ) );
  311. };
  312. return this.enumerateDevices()
  313. .then( validate )
  314. .then( filter );
  315. },
  316. /**
  317. * Get user media
  318. * @param {MediaStreamConstraints} constraints
  319. * @memberOf Media
  320. * @instance
  321. */
  322. getUserMedia: function ( constraints ) {
  323. const setMediaStream = this.setMediaStream.bind( this );
  324. const playVideo = this.playVideo.bind( this );
  325. const onCatchError = error => { console.warn( `PANOLENS.Media: ${error}` ); };
  326. return window.navigator.mediaDevices.getUserMedia( constraints )
  327. .then( setMediaStream )
  328. .then( playVideo )
  329. .catch( onCatchError );
  330. },
  331. /**
  332. * Set video device index
  333. * @param {number} index
  334. * @memberOf Media
  335. * @instance
  336. */
  337. setVideDeviceIndex: function ( index ) {
  338. this.videoDeviceIndex = index;
  339. },
  340. /**
  341. * Start streaming
  342. * @param {MediaDeviceInfo} [targetDevice]
  343. * @memberOf Media
  344. * @instance
  345. */
  346. start: function( targetDevice ) {
  347. const constraints = this.constraints;
  348. const getUserMedia = this.getUserMedia.bind( this );
  349. const onVideoDevices = devices => {
  350. if ( !devices || devices.length === 0 ) {
  351. throw Error( 'no video device found' );
  352. }
  353. const device = targetDevice || devices[ 0 ];
  354. constraints.video.deviceId = device.deviceId;
  355. return getUserMedia( constraints );
  356. };
  357. this.element = this.createVideoElement();
  358. return this.getDevices().then( onVideoDevices );
  359. },
  360. /**
  361. * Stop streaming
  362. * @memberOf Media
  363. * @instance
  364. */
  365. stop: function () {
  366. const stream = this.stream;
  367. if ( stream && stream.active ) {
  368. const track = stream.getTracks()[ 0 ];
  369. track.stop();
  370. window.removeEventListener( 'resize', this.onWindowResize.bind( this ) );
  371. this.element = null;
  372. this.stream = null;
  373. }
  374. },
  375. /**
  376. * Set media stream
  377. * @param {MediaStream} stream
  378. * @memberOf Media
  379. * @instance
  380. */
  381. setMediaStream: function ( stream ) {
  382. this.stream = stream;
  383. this.element.srcObject = stream;
  384. if ( this.scene ) {
  385. this.scene.background = this.createVideoTexture();
  386. }
  387. window.addEventListener( 'resize', this.onWindowResize.bind( this ) );
  388. },
  389. /**
  390. * Play video element
  391. * @memberOf Media
  392. * @instance
  393. */
  394. playVideo: function () {
  395. const { element } = this;
  396. if ( element ) {
  397. element.play();
  398. this.dispatchEvent( { type: 'play' } );
  399. }
  400. },
  401. /**
  402. * Pause video element
  403. * @memberOf Media
  404. * @instance
  405. */
  406. pauseVideo: function () {
  407. const { element } = this;
  408. if ( element ) {
  409. element.pause();
  410. this.dispatchEvent( { type: 'pause' } );
  411. }
  412. },
  413. /**
  414. * Create video texture
  415. * @memberOf Media
  416. * @instance
  417. * @returns {THREE.VideoTexture}
  418. */
  419. createVideoTexture: function () {
  420. const video = this.element;
  421. const texture = new THREE.VideoTexture( video );
  422. texture.generateMipmaps = false;
  423. texture.minFilter = THREE.LinearFilter;
  424. texture.magFilter = THREE.LinearFilter;
  425. texture.format = THREE.RGBFormat;
  426. texture.center.set( 0.5, 0.5 );
  427. video.addEventListener( 'canplay', this.onWindowResize.bind( this ) );
  428. return texture;
  429. },
  430. /**
  431. * Create video element
  432. * @memberOf Media
  433. * @instance
  434. * @returns {HTMLVideoElement}
  435. * @fires Media#canplay
  436. */
  437. createVideoElement: function() {
  438. const dispatchEvent = this.dispatchEvent.bind( this );
  439. const video = document.createElement( 'video' );
  440. /**
  441. * Video can play event
  442. * @type {object}
  443. * @event Media#canplay
  444. */
  445. const canPlay = () => dispatchEvent( { type: 'canplay' } );
  446. video.setAttribute( 'autoplay', '' );
  447. video.setAttribute( 'muted', '' );
  448. video.setAttribute( 'playsinline', '' );
  449. video.style.position = 'absolute';
  450. video.style.top = '0';
  451. video.style.left = '0';
  452. video.style.width = '100%';
  453. video.style.height = '100%';
  454. video.style.objectPosition = 'center';
  455. video.style.objectFit = 'cover';
  456. video.style.display = this.scene ? 'none' : '';
  457. video.addEventListener( 'canplay', canPlay );
  458. return video;
  459. },
  460. /**
  461. * On window resize event
  462. * @param {Event} event
  463. * @memberOf Media
  464. * @instance
  465. */
  466. onWindowResize: function () {
  467. if ( this.element && this.element.videoWidth && this.element.videoHeight && this.scene ) {
  468. const { clientWidth: width, clientHeight: height } = this.container;
  469. const texture = this.scene.background;
  470. const { videoWidth, videoHeight } = this.element;
  471. const cameraRatio = videoHeight / videoWidth;
  472. const viewportRatio = this.container ? width / height : 1.0;
  473. const ratio = cameraRatio * viewportRatio * this.ratioScalar;
  474. if ( width > height ) {
  475. texture.repeat.set( ratio, 1 );
  476. } else {
  477. texture.repeat.set( 1, 1 / ratio );
  478. }
  479. }
  480. }
  481. } );
  482. /**
  483. * @classdesc Reticle 3D Sprite
  484. * @constructor
  485. * @param {THREE.Color} [color=0xffffff] - Color of the reticle sprite
  486. * @param {boolean} [autoSelect=true] - Auto selection
  487. * @param {number} [dwellTime=1500] - Duration for dwelling sequence to complete
  488. */
  489. function Reticle ( color = 0xffffff, autoSelect = true, dwellTime = 1500 ) {
  490. this.dpr = window.devicePixelRatio;
  491. const { canvas, context } = this.createCanvas();
  492. const material = new THREE.SpriteMaterial( { color, map: this.createCanvasTexture( canvas ) } );
  493. THREE.Sprite.call( this, material );
  494. this.canvasWidth = canvas.width;
  495. this.canvasHeight = canvas.height;
  496. this.context = context;
  497. this.color = color instanceof THREE.Color ? color : new THREE.Color( color );
  498. this.autoSelect = autoSelect;
  499. this.dwellTime = dwellTime;
  500. this.rippleDuration = 500;
  501. this.position.z = -10;
  502. this.center.set( 0.5, 0.5 );
  503. this.scale.set( 0.5, 0.5, 1 );
  504. this.startTimestamp = null;
  505. this.timerId = null;
  506. this.callback = null;
  507. this.frustumCulled = false;
  508. this.updateCanvasArcByProgress( 0 );
  509. }
  510. Reticle.prototype = Object.assign( Object.create( THREE.Sprite.prototype ), {
  511. constructor: Reticle,
  512. /**
  513. * Set material color
  514. * @param {THREE.Color} color
  515. * @memberOf Reticle
  516. * @instance
  517. */
  518. setColor: function ( color ) {
  519. this.material.color.copy( color instanceof THREE.Color ? color : new THREE.Color( color ) );
  520. },
  521. /**
  522. * Create canvas texture
  523. * @param {HTMLCanvasElement} canvas
  524. * @memberOf Reticle
  525. * @instance
  526. * @returns {THREE.CanvasTexture}
  527. */
  528. createCanvasTexture: function ( canvas ) {
  529. const texture = new THREE.CanvasTexture( canvas );
  530. texture.minFilter = THREE.LinearFilter;
  531. texture.magFilter = THREE.LinearFilter;
  532. texture.generateMipmaps = false;
  533. return texture;
  534. },
  535. /**
  536. * Create canvas element
  537. * @memberOf Reticle
  538. * @instance
  539. * @returns {object} object
  540. * @returns {HTMLCanvasElement} object.canvas
  541. * @returns {CanvasRenderingContext2D} object.context
  542. */
  543. createCanvas: function () {
  544. const width = 32;
  545. const height = 32;
  546. const canvas = document.createElement( 'canvas' );
  547. const context = canvas.getContext( '2d' );
  548. const dpr = this.dpr;
  549. canvas.width = width * dpr;
  550. canvas.height = height * dpr;
  551. context.scale( dpr, dpr );
  552. context.shadowBlur = 5;
  553. context.shadowColor = 'rgba(200,200,200,0.9)';
  554. return { canvas, context };
  555. },
  556. /**
  557. * Update canvas arc by progress
  558. * @param {number} progress
  559. * @memberOf Reticle
  560. * @instance
  561. */
  562. updateCanvasArcByProgress: function ( progress ) {
  563. const context = this.context;
  564. const { canvasWidth, canvasHeight, material } = this;
  565. const dpr = this.dpr;
  566. const degree = progress * Math.PI * 2;
  567. const color = this.color.getStyle();
  568. const x = canvasWidth * 0.5 / dpr;
  569. const y = canvasHeight * 0.5 / dpr;
  570. const lineWidth = 3;
  571. context.clearRect( 0, 0, canvasWidth, canvasHeight );
  572. context.beginPath();
  573. if ( progress === 0 ) {
  574. context.arc( x, y, canvasWidth / 16, 0, 2 * Math.PI );
  575. context.fillStyle = color;
  576. context.fill();
  577. } else {
  578. context.arc( x, y, canvasWidth / 4 - lineWidth, -Math.PI / 2, -Math.PI / 2 + degree );
  579. context.strokeStyle = color;
  580. context.lineWidth = lineWidth;
  581. context.stroke();
  582. }
  583. context.closePath();
  584. material.map.needsUpdate = true;
  585. },
  586. /**
  587. * Ripple effect
  588. * @memberOf Reticle
  589. * @instance
  590. * @fires Reticle#reticle-ripple-start
  591. * @fires Reticle#reticle-ripple-end
  592. */
  593. ripple: function () {
  594. const context = this.context;
  595. const { canvasWidth, canvasHeight, material } = this;
  596. const duration = this.rippleDuration;
  597. const timestamp = performance.now();
  598. const color = this.color;
  599. const dpr = this.dpr;
  600. const x = canvasWidth * 0.5 / dpr;
  601. const y = canvasHeight * 0.5 / dpr;
  602. const update = () => {
  603. const timerId = window.requestAnimationFrame( update );
  604. const elapsed = performance.now() - timestamp;
  605. const progress = elapsed / duration;
  606. const opacity = 1.0 - progress > 0 ? 1.0 - progress : 0;
  607. const radius = progress * canvasWidth * 0.5 / dpr;
  608. context.clearRect( 0, 0, canvasWidth, canvasHeight );
  609. context.beginPath();
  610. context.arc( x, y, radius, 0, Math.PI * 2 );
  611. context.fillStyle = `rgba(${color.r * 255}, ${color.g * 255}, ${color.b * 255}, ${opacity})`;
  612. context.fill();
  613. context.closePath();
  614. if ( progress >= 1.0 ) {
  615. window.cancelAnimationFrame( timerId );
  616. this.updateCanvasArcByProgress( 0 );
  617. /**
  618. * Reticle ripple end event
  619. * @type {object}
  620. * @event Reticle#reticle-ripple-end
  621. */
  622. this.dispatchEvent( { type: 'reticle-ripple-end' } );
  623. }
  624. material.map.needsUpdate = true;
  625. };
  626. /**
  627. * Reticle ripple start event
  628. * @type {object}
  629. * @event Reticle#reticle-ripple-start
  630. */
  631. this.dispatchEvent( { type: 'reticle-ripple-start' } );
  632. update();
  633. },
  634. /**
  635. * Make reticle visible
  636. * @memberOf Reticle
  637. * @instance
  638. */
  639. show: function () {
  640. this.visible = true;
  641. },
  642. /**
  643. * Make reticle invisible
  644. * @memberOf Reticle
  645. * @instance
  646. */
  647. hide: function () {
  648. this.visible = false;
  649. },
  650. /**
  651. * Start dwelling
  652. * @param {function} callback
  653. * @memberOf Reticle
  654. * @instance
  655. * @fires Reticle#reticle-start
  656. */
  657. start: function ( callback ) {
  658. if ( !this.autoSelect ) {
  659. return;
  660. }
  661. /**
  662. * Reticle start event
  663. * @type {object}
  664. * @event Reticle#reticle-start
  665. */
  666. this.dispatchEvent( { type: 'reticle-start' } );
  667. this.startTimestamp = performance.now();
  668. this.callback = callback;
  669. this.update();
  670. },
  671. /**
  672. * End dwelling
  673. * @memberOf Reticle
  674. * @instance
  675. * @fires Reticle#reticle-end
  676. */
  677. end: function(){
  678. if ( !this.startTimestamp ) { return; }
  679. window.cancelAnimationFrame( this.timerId );
  680. this.updateCanvasArcByProgress( 0 );
  681. this.callback = null;
  682. this.timerId = null;
  683. this.startTimestamp = null;
  684. /**
  685. * Reticle end event
  686. * @type {object}
  687. * @event Reticle#reticle-end
  688. */
  689. this.dispatchEvent( { type: 'reticle-end' } );
  690. },
  691. /**
  692. * Update dwelling
  693. * @memberOf Reticle
  694. * @instance
  695. * @fires Reticle#reticle-update
  696. */
  697. update: function () {
  698. this.timerId = window.requestAnimationFrame( this.update.bind( this ) );
  699. const elapsed = performance.now() - this.startTimestamp;
  700. const progress = elapsed / this.dwellTime;
  701. this.updateCanvasArcByProgress( progress );
  702. /**
  703. * Reticle update event
  704. * @type {object}
  705. * @event Reticle#reticle-update
  706. */
  707. this.dispatchEvent( { type: 'reticle-update', progress } );
  708. if ( progress >= 1.0 ) {
  709. window.cancelAnimationFrame( this.timerId );
  710. if ( this.callback ) { this.callback(); }
  711. this.end();
  712. this.ripple();
  713. }
  714. }
  715. } );
  716. function createCommonjsModule(fn, module) {
  717. return module = { exports: {} }, fn(module, module.exports), module.exports;
  718. }
  719. var Tween = createCommonjsModule(function (module, exports) {
  720. /**
  721. * Tween.js - Licensed under the MIT license
  722. * https://github.com/tweenjs/tween.js
  723. * ----------------------------------------------
  724. *
  725. * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
  726. * Thank you all, you're awesome!
  727. */
  728. var _Group = function () {
  729. this._tweens = {};
  730. this._tweensAddedDuringUpdate = {};
  731. };
  732. _Group.prototype = {
  733. getAll: function () {
  734. return Object.keys(this._tweens).map(function (tweenId) {
  735. return this._tweens[tweenId];
  736. }.bind(this));
  737. },
  738. removeAll: function () {
  739. this._tweens = {};
  740. },
  741. add: function (tween) {
  742. this._tweens[tween.getId()] = tween;
  743. this._tweensAddedDuringUpdate[tween.getId()] = tween;
  744. },
  745. remove: function (tween) {
  746. delete this._tweens[tween.getId()];
  747. delete this._tweensAddedDuringUpdate[tween.getId()];
  748. },
  749. update: function (time, preserve) {
  750. var tweenIds = Object.keys(this._tweens);
  751. if (tweenIds.length === 0) {
  752. return false;
  753. }
  754. time = time !== undefined ? time : TWEEN.now();
  755. // Tweens are updated in "batches". If you add a new tween during an update, then the
  756. // new tween will be updated in the next batch.
  757. // If you remove a tween during an update, it may or may not be updated. However,
  758. // if the removed tween was added during the current batch, then it will not be updated.
  759. while (tweenIds.length > 0) {
  760. this._tweensAddedDuringUpdate = {};
  761. for (var i = 0; i < tweenIds.length; i++) {
  762. var tween = this._tweens[tweenIds[i]];
  763. if (tween && tween.update(time) === false) {
  764. tween._isPlaying = false;
  765. if (!preserve) {
  766. delete this._tweens[tweenIds[i]];
  767. }
  768. }
  769. }
  770. tweenIds = Object.keys(this._tweensAddedDuringUpdate);
  771. }
  772. return true;
  773. }
  774. };
  775. var TWEEN = new _Group();
  776. TWEEN.Group = _Group;
  777. TWEEN._nextId = 0;
  778. TWEEN.nextId = function () {
  779. return TWEEN._nextId++;
  780. };
  781. // Include a performance.now polyfill.
  782. // In node.js, use process.hrtime.
  783. if (typeof (self) === 'undefined' && typeof (process) !== 'undefined' && process.hrtime) {
  784. TWEEN.now = function () {
  785. var time = process.hrtime();
  786. // Convert [seconds, nanoseconds] to milliseconds.
  787. return time[0] * 1000 + time[1] / 1000000;
  788. };
  789. }
  790. // In a browser, use self.performance.now if it is available.
  791. else if (typeof (self) !== 'undefined' &&
  792. self.performance !== undefined &&
  793. self.performance.now !== undefined) {
  794. // This must be bound, because directly assigning this function
  795. // leads to an invocation exception in Chrome.
  796. TWEEN.now = self.performance.now.bind(self.performance);
  797. }
  798. // Use Date.now if it is available.
  799. else if (Date.now !== undefined) {
  800. TWEEN.now = Date.now;
  801. }
  802. // Otherwise, use 'new Date().getTime()'.
  803. else {
  804. TWEEN.now = function () {
  805. return new Date().getTime();
  806. };
  807. }
  808. TWEEN.Tween = function (object, group) {
  809. this._object = object;
  810. this._valuesStart = {};
  811. this._valuesEnd = {};
  812. this._valuesStartRepeat = {};
  813. this._duration = 1000;
  814. this._repeat = 0;
  815. this._repeatDelayTime = undefined;
  816. this._yoyo = false;
  817. this._isPlaying = false;
  818. this._reversed = false;
  819. this._delayTime = 0;
  820. this._startTime = null;
  821. this._easingFunction = TWEEN.Easing.Linear.None;
  822. this._interpolationFunction = TWEEN.Interpolation.Linear;
  823. this._chainedTweens = [];
  824. this._onStartCallback = null;
  825. this._onStartCallbackFired = false;
  826. this._onUpdateCallback = null;
  827. this._onRepeatCallback = null;
  828. this._onCompleteCallback = null;
  829. this._onStopCallback = null;
  830. this._group = group || TWEEN;
  831. this._id = TWEEN.nextId();
  832. };
  833. TWEEN.Tween.prototype = {
  834. getId: function () {
  835. return this._id;
  836. },
  837. isPlaying: function () {
  838. return this._isPlaying;
  839. },
  840. to: function (properties, duration) {
  841. this._valuesEnd = Object.create(properties);
  842. if (duration !== undefined) {
  843. this._duration = duration;
  844. }
  845. return this;
  846. },
  847. duration: function duration(d) {
  848. this._duration = d;
  849. return this;
  850. },
  851. start: function (time) {
  852. this._group.add(this);
  853. this._isPlaying = true;
  854. this._onStartCallbackFired = false;
  855. this._startTime = time !== undefined ? typeof time === 'string' ? TWEEN.now() + parseFloat(time) : time : TWEEN.now();
  856. this._startTime += this._delayTime;
  857. for (var property in this._valuesEnd) {
  858. // Check if an Array was provided as property value
  859. if (this._valuesEnd[property] instanceof Array) {
  860. if (this._valuesEnd[property].length === 0) {
  861. continue;
  862. }
  863. // Create a local copy of the Array with the start value at the front
  864. this._valuesEnd[property] = [this._object[property]].concat(this._valuesEnd[property]);
  865. }
  866. // If `to()` specifies a property that doesn't exist in the source object,
  867. // we should not set that property in the object
  868. if (this._object[property] === undefined) {
  869. continue;
  870. }
  871. // Save the starting value.
  872. this._valuesStart[property] = this._object[property];
  873. if ((this._valuesStart[property] instanceof Array) === false) {
  874. this._valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
  875. }
  876. this._valuesStartRepeat[property] = this._valuesStart[property] || 0;
  877. }
  878. return this;
  879. },
  880. stop: function () {
  881. if (!this._isPlaying) {
  882. return this;
  883. }
  884. this._group.remove(this);
  885. this._isPlaying = false;
  886. if (this._onStopCallback !== null) {
  887. this._onStopCallback(this._object);
  888. }
  889. this.stopChainedTweens();
  890. return this;
  891. },
  892. end: function () {
  893. this.update(Infinity);
  894. return this;
  895. },
  896. stopChainedTweens: function () {
  897. for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
  898. this._chainedTweens[i].stop();
  899. }
  900. },
  901. group: function (group) {
  902. this._group = group;
  903. return this;
  904. },
  905. delay: function (amount) {
  906. this._delayTime = amount;
  907. return this;
  908. },
  909. repeat: function (times) {
  910. this._repeat = times;
  911. return this;
  912. },
  913. repeatDelay: function (amount) {
  914. this._repeatDelayTime = amount;
  915. return this;
  916. },
  917. yoyo: function (yoyo) {
  918. this._yoyo = yoyo;
  919. return this;
  920. },
  921. easing: function (easingFunction) {
  922. this._easingFunction = easingFunction;
  923. return this;
  924. },
  925. interpolation: function (interpolationFunction) {
  926. this._interpolationFunction = interpolationFunction;
  927. return this;
  928. },
  929. chain: function () {
  930. this._chainedTweens = arguments;
  931. return this;
  932. },
  933. onStart: function (callback) {
  934. this._onStartCallback = callback;
  935. return this;
  936. },
  937. onUpdate: function (callback) {
  938. this._onUpdateCallback = callback;
  939. return this;
  940. },
  941. onRepeat: function onRepeat(callback) {
  942. this._onRepeatCallback = callback;
  943. return this;
  944. },
  945. onComplete: function (callback) {
  946. this._onCompleteCallback = callback;
  947. return this;
  948. },
  949. onStop: function (callback) {
  950. this._onStopCallback = callback;
  951. return this;
  952. },
  953. update: function (time) {
  954. var property;
  955. var elapsed;
  956. var value;
  957. if (time < this._startTime) {
  958. return true;
  959. }
  960. if (this._onStartCallbackFired === false) {
  961. if (this._onStartCallback !== null) {
  962. this._onStartCallback(this._object);
  963. }
  964. this._onStartCallbackFired = true;
  965. }
  966. elapsed = (time - this._startTime) / this._duration;
  967. elapsed = (this._duration === 0 || elapsed > 1) ? 1 : elapsed;
  968. value = this._easingFunction(elapsed);
  969. for (property in this._valuesEnd) {
  970. // Don't update properties that do not exist in the source object
  971. if (this._valuesStart[property] === undefined) {
  972. continue;
  973. }
  974. var start = this._valuesStart[property] || 0;
  975. var end = this._valuesEnd[property];
  976. if (end instanceof Array) {
  977. this._object[property] = this._interpolationFunction(end, value);
  978. } else {
  979. // Parses relative end values with start as base (e.g.: +10, -3)
  980. if (typeof (end) === 'string') {
  981. if (end.charAt(0) === '+' || end.charAt(0) === '-') {
  982. end = start + parseFloat(end);
  983. } else {
  984. end = parseFloat(end);
  985. }
  986. }
  987. // Protect against non numeric properties.
  988. if (typeof (end) === 'number') {
  989. this._object[property] = start + (end - start) * value;
  990. }
  991. }
  992. }
  993. if (this._onUpdateCallback !== null) {
  994. this._onUpdateCallback(this._object, elapsed);
  995. }
  996. if (elapsed === 1) {
  997. if (this._repeat > 0) {
  998. if (isFinite(this._repeat)) {
  999. this._repeat--;
  1000. }
  1001. // Reassign starting values, restart by making startTime = now
  1002. for (property in this._valuesStartRepeat) {
  1003. if (typeof (this._valuesEnd[property]) === 'string') {
  1004. this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
  1005. }
  1006. if (this._yoyo) {
  1007. var tmp = this._valuesStartRepeat[property];
  1008. this._valuesStartRepeat[property] = this._valuesEnd[property];
  1009. this._valuesEnd[property] = tmp;
  1010. }
  1011. this._valuesStart[property] = this._valuesStartRepeat[property];
  1012. }
  1013. if (this._yoyo) {
  1014. this._reversed = !this._reversed;
  1015. }
  1016. if (this._repeatDelayTime !== undefined) {
  1017. this._startTime = time + this._repeatDelayTime;
  1018. } else {
  1019. this._startTime = time + this._delayTime;
  1020. }
  1021. if (this._onRepeatCallback !== null) {
  1022. this._onRepeatCallback(this._object);
  1023. }
  1024. return true;
  1025. } else {
  1026. if (this._onCompleteCallback !== null) {
  1027. this._onCompleteCallback(this._object);
  1028. }
  1029. for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
  1030. // Make the chained tweens start exactly at the time they should,
  1031. // even if the `update()` method was called way past the duration of the tween
  1032. this._chainedTweens[i].start(this._startTime + this._duration);
  1033. }
  1034. return false;
  1035. }
  1036. }
  1037. return true;
  1038. }
  1039. };
  1040. TWEEN.Easing = {
  1041. Linear: {
  1042. None: function (k) {
  1043. return k;
  1044. }
  1045. },
  1046. Quadratic: {
  1047. In: function (k) {
  1048. return k * k;
  1049. },
  1050. Out: function (k) {
  1051. return k * (2 - k);
  1052. },
  1053. InOut: function (k) {
  1054. if ((k *= 2) < 1) {
  1055. return 0.5 * k * k;
  1056. }
  1057. return - 0.5 * (--k * (k - 2) - 1);
  1058. }
  1059. },
  1060. Cubic: {
  1061. In: function (k) {
  1062. return k * k * k;
  1063. },
  1064. Out: function (k) {
  1065. return --k * k * k + 1;
  1066. },
  1067. InOut: function (k) {
  1068. if ((k *= 2) < 1) {
  1069. return 0.5 * k * k * k;
  1070. }
  1071. return 0.5 * ((k -= 2) * k * k + 2);
  1072. }
  1073. },
  1074. Quartic: {
  1075. In: function (k) {
  1076. return k * k * k * k;
  1077. },
  1078. Out: function (k) {
  1079. return 1 - (--k * k * k * k);
  1080. },
  1081. InOut: function (k) {
  1082. if ((k *= 2) < 1) {
  1083. return 0.5 * k * k * k * k;
  1084. }
  1085. return - 0.5 * ((k -= 2) * k * k * k - 2);
  1086. }
  1087. },
  1088. Quintic: {
  1089. In: function (k) {
  1090. return k * k * k * k * k;
  1091. },
  1092. Out: function (k) {
  1093. return --k * k * k * k * k + 1;
  1094. },
  1095. InOut: function (k) {
  1096. if ((k *= 2) < 1) {
  1097. return 0.5 * k * k * k * k * k;
  1098. }
  1099. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  1100. }
  1101. },
  1102. Sinusoidal: {
  1103. In: function (k) {
  1104. return 1 - Math.cos(k * Math.PI / 2);
  1105. },
  1106. Out: function (k) {
  1107. return Math.sin(k * Math.PI / 2);
  1108. },
  1109. InOut: function (k) {
  1110. return 0.5 * (1 - Math.cos(Math.PI * k));
  1111. }
  1112. },
  1113. Exponential: {
  1114. In: function (k) {
  1115. return k === 0 ? 0 : Math.pow(1024, k - 1);
  1116. },
  1117. Out: function (k) {
  1118. return k === 1 ? 1 : 1 - Math.pow(2, - 10 * k);
  1119. },
  1120. InOut: function (k) {
  1121. if (k === 0) {
  1122. return 0;
  1123. }
  1124. if (k === 1) {
  1125. return 1;
  1126. }
  1127. if ((k *= 2) < 1) {
  1128. return 0.5 * Math.pow(1024, k - 1);
  1129. }
  1130. return 0.5 * (- Math.pow(2, - 10 * (k - 1)) + 2);
  1131. }
  1132. },
  1133. Circular: {
  1134. In: function (k) {
  1135. return 1 - Math.sqrt(1 - k * k);
  1136. },
  1137. Out: function (k) {
  1138. return Math.sqrt(1 - (--k * k));
  1139. },
  1140. InOut: function (k) {
  1141. if ((k *= 2) < 1) {
  1142. return - 0.5 * (Math.sqrt(1 - k * k) - 1);
  1143. }
  1144. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  1145. }
  1146. },
  1147. Elastic: {
  1148. In: function (k) {
  1149. if (k === 0) {
  1150. return 0;
  1151. }
  1152. if (k === 1) {
  1153. return 1;
  1154. }
  1155. return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);
  1156. },
  1157. Out: function (k) {
  1158. if (k === 0) {
  1159. return 0;
  1160. }
  1161. if (k === 1) {
  1162. return 1;
  1163. }
  1164. return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1;
  1165. },
  1166. InOut: function (k) {
  1167. if (k === 0) {
  1168. return 0;
  1169. }
  1170. if (k === 1) {
  1171. return 1;
  1172. }
  1173. k *= 2;
  1174. if (k < 1) {
  1175. return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI);
  1176. }
  1177. return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1;
  1178. }
  1179. },
  1180. Back: {
  1181. In: function (k) {
  1182. var s = 1.70158;
  1183. return k * k * ((s + 1) * k - s);
  1184. },
  1185. Out: function (k) {
  1186. var s = 1.70158;
  1187. return --k * k * ((s + 1) * k + s) + 1;
  1188. },
  1189. InOut: function (k) {
  1190. var s = 1.70158 * 1.525;
  1191. if ((k *= 2) < 1) {
  1192. return 0.5 * (k * k * ((s + 1) * k - s));
  1193. }
  1194. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  1195. }
  1196. },
  1197. Bounce: {
  1198. In: function (k) {
  1199. return 1 - TWEEN.Easing.Bounce.Out(1 - k);
  1200. },
  1201. Out: function (k) {
  1202. if (k < (1 / 2.75)) {
  1203. return 7.5625 * k * k;
  1204. } else if (k < (2 / 2.75)) {
  1205. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  1206. } else if (k < (2.5 / 2.75)) {
  1207. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  1208. } else {
  1209. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  1210. }
  1211. },
  1212. InOut: function (k) {
  1213. if (k < 0.5) {
  1214. return TWEEN.Easing.Bounce.In(k * 2) * 0.5;
  1215. }
  1216. return TWEEN.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
  1217. }
  1218. }
  1219. };
  1220. TWEEN.Interpolation = {
  1221. Linear: function (v, k) {
  1222. var m = v.length - 1;
  1223. var f = m * k;
  1224. var i = Math.floor(f);
  1225. var fn = TWEEN.Interpolation.Utils.Linear;
  1226. if (k < 0) {
  1227. return fn(v[0], v[1], f);
  1228. }
  1229. if (k > 1) {
  1230. return fn(v[m], v[m - 1], m - f);
  1231. }
  1232. return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
  1233. },
  1234. Bezier: function (v, k) {
  1235. var b = 0;
  1236. var n = v.length - 1;
  1237. var pw = Math.pow;
  1238. var bn = TWEEN.Interpolation.Utils.Bernstein;
  1239. for (var i = 0; i <= n; i++) {
  1240. b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
  1241. }
  1242. return b;
  1243. },
  1244. CatmullRom: function (v, k) {
  1245. var m = v.length - 1;
  1246. var f = m * k;
  1247. var i = Math.floor(f);
  1248. var fn = TWEEN.Interpolation.Utils.CatmullRom;
  1249. if (v[0] === v[m]) {
  1250. if (k < 0) {
  1251. i = Math.floor(f = m * (1 + k));
  1252. }
  1253. return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
  1254. } else {
  1255. if (k < 0) {
  1256. return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
  1257. }
  1258. if (k > 1) {
  1259. return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
  1260. }
  1261. return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
  1262. }
  1263. },
  1264. Utils: {
  1265. Linear: function (p0, p1, t) {
  1266. return (p1 - p0) * t + p0;
  1267. },
  1268. Bernstein: function (n, i) {
  1269. var fc = TWEEN.Interpolation.Utils.Factorial;
  1270. return fc(n) / fc(i) / fc(n - i);
  1271. },
  1272. Factorial: (function () {
  1273. var a = [1];
  1274. return function (n) {
  1275. var s = 1;
  1276. if (a[n]) {
  1277. return a[n];
  1278. }
  1279. for (var i = n; i > 1; i--) {
  1280. s *= i;
  1281. }
  1282. a[n] = s;
  1283. return s;
  1284. };
  1285. })(),
  1286. CatmullRom: function (p0, p1, p2, p3, t) {
  1287. var v0 = (p2 - p0) * 0.5;
  1288. var v1 = (p3 - p1) * 0.5;
  1289. var t2 = t * t;
  1290. var t3 = t * t2;
  1291. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (- 3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  1292. }
  1293. }
  1294. };
  1295. // UMD (Universal Module Definition)
  1296. (function (root) {
  1297. {
  1298. // Node.js
  1299. module.exports = TWEEN;
  1300. }
  1301. })();
  1302. });
  1303. /**
  1304. * @classdesc Information spot attached to panorama
  1305. * @constructor
  1306. * @param {number} [scale=300] - Default scale
  1307. * @param {string} [imageSrc=PANOLENS.DataImage.Info] - Image overlay info
  1308. * @param {boolean} [animated=true] - Enable default hover animation
  1309. */
  1310. function Infospot ( scale = 300, imageSrc, animated ) {
  1311. const duration = 500, scaleFactor = 1.3;
  1312. imageSrc = imageSrc || DataImage.Info;
  1313. THREE.Sprite.call( this );
  1314. this.type = 'infospot';
  1315. this.animated = animated !== undefined ? animated : true;
  1316. this.isHovering = false;
  1317. /*
  1318. * TODO: Three.js bug hotfix for sprite raycasting r104
  1319. * https://github.com/mrdoob/three.js/issues/14624
  1320. */
  1321. this.frustumCulled = false;
  1322. this.element = null;
  1323. this.toPanorama = null;
  1324. this.cursorStyle = null;
  1325. this.mode = MODES.NORMAL;
  1326. this.scale.set( scale, scale, 1 );
  1327. this.rotation.y = Math.PI;
  1328. this.container = null;
  1329. this.originalRaycast = this.raycast;
  1330. // Event Handler
  1331. this.HANDLER_FOCUS = null;
  1332. this.material.side = THREE.DoubleSide;
  1333. this.material.depthTest = false;
  1334. this.material.transparent = true;
  1335. this.material.opacity = 0;
  1336. this.scaleUpAnimation = new Tween.Tween();
  1337. this.scaleDownAnimation = new Tween.Tween();
  1338. const postLoad = function ( texture ) {
  1339. if ( !this.material ) { return; }
  1340. const ratio = texture.image.width / texture.image.height;
  1341. const textureScale = new THREE.Vector3();
  1342. texture.image.width = texture.image.naturalWidth || 64;
  1343. texture.image.height = texture.image.naturalHeight || 64;
  1344. this.scale.set( ratio * scale, scale, 1 );
  1345. textureScale.copy( this.scale );
  1346. this.scaleUpAnimation = new Tween.Tween( this.scale )
  1347. .to( { x: textureScale.x * scaleFactor, y: textureScale.y * scaleFactor }, duration )
  1348. .easing( Tween.Easing.Elastic.Out );
  1349. this.scaleDownAnimation = new Tween.Tween( this.scale )
  1350. .to( { x: textureScale.x, y: textureScale.y }, duration )
  1351. .easing( Tween.Easing.Elastic.Out );
  1352. this.material.map = texture;
  1353. this.material.needsUpdate = true;
  1354. }.bind( this );
  1355. // Add show and hide animations
  1356. this.showAnimation = new Tween.Tween( this.material )
  1357. .to( { opacity: 1 }, duration )
  1358. .onStart( this.enableRaycast.bind( this, true ) )
  1359. .easing( Tween.Easing.Quartic.Out );
  1360. this.hideAnimation = new Tween.Tween( this.material )
  1361. .to( { opacity: 0 }, duration )
  1362. .onStart( this.enableRaycast.bind( this, false ) )
  1363. .easing( Tween.Easing.Quartic.Out );
  1364. // Attach event listeners
  1365. this.addEventListener( 'click', this.onClick );
  1366. this.addEventListener( 'hover', this.onHover );
  1367. this.addEventListener( 'hoverenter', this.onHoverStart );
  1368. this.addEventListener( 'hoverleave', this.onHoverEnd );
  1369. this.addEventListener( 'panolens-dual-eye-effect', this.onDualEyeEffect );
  1370. this.addEventListener( 'panolens-container', this.setContainer.bind( this ) );
  1371. this.addEventListener( 'dismiss', this.onDismiss );
  1372. this.addEventListener( 'panolens-infospot-focus', this.setFocusMethod );
  1373. TextureLoader.load( imageSrc, postLoad );
  1374. }
  1375. Infospot.prototype = Object.assign( Object.create( THREE.Sprite.prototype ), {
  1376. constructor: Infospot,
  1377. /**
  1378. * Set infospot container
  1379. * @param {HTMLElement|object} data - Data with container information
  1380. * @memberOf Infospot
  1381. * @instance
  1382. */
  1383. setContainer: function ( data ) {
  1384. let container;
  1385. if ( data instanceof HTMLElement ) {
  1386. container = data;
  1387. } else if ( data && data.container ) {
  1388. container = data.container;
  1389. }
  1390. // Append element if exists
  1391. if ( container && this.element ) {
  1392. container.appendChild( this.element );
  1393. }
  1394. this.container = container;
  1395. },
  1396. /**
  1397. * Get container
  1398. * @memberOf Infospot
  1399. * @instance
  1400. * @return {HTMLElement} - The container of this infospot
  1401. */
  1402. getContainer: function () {
  1403. return this.container;
  1404. },
  1405. /**
  1406. * This will be called by a click event
  1407. * Translate and lock the hovering element if any
  1408. * @param {object} event - Event containing mouseEvent with clientX and clientY
  1409. * @memberOf Infospot
  1410. * @instance
  1411. */
  1412. onClick: function ( event ) {
  1413. if ( this.element && this.getContainer() ) {
  1414. this.onHoverStart( event );
  1415. // Lock element
  1416. this.lockHoverElement();
  1417. }
  1418. },
  1419. /**
  1420. * Dismiss current element if any
  1421. * @param {object} event - Dismiss event
  1422. * @memberOf Infospot
  1423. * @instance
  1424. */
  1425. onDismiss: function () {
  1426. if ( this.element ) {
  1427. this.unlockHoverElement();
  1428. this.onHoverEnd();
  1429. }
  1430. },
  1431. /**
  1432. * This will be called by a mouse hover event
  1433. * Translate the hovering element if any
  1434. * @param {object} event - Event containing mouseEvent with clientX and clientY
  1435. * @memberOf Infospot
  1436. * @instance
  1437. */
  1438. onHover: function () {},
  1439. /**
  1440. * This will be called on a mouse hover start
  1441. * Sets cursor style to 'pointer', display the element and scale up the infospot
  1442. * @param {object} event
  1443. * @memberOf Infospot
  1444. * @instance
  1445. */
  1446. onHoverStart: function ( event ) {
  1447. if ( !this.getContainer() ) { return; }
  1448. const cursorStyle = this.cursorStyle || ( this.mode === MODES.NORMAL ? 'pointer' : 'default' );
  1449. const { scaleDownAnimation, scaleUpAnimation, element } = this;
  1450. this.isHovering = true;
  1451. this.container.style.cursor = cursorStyle;
  1452. if ( this.animated ) {
  1453. scaleDownAnimation.stop();
  1454. scaleUpAnimation.start();
  1455. }
  1456. if ( element && event.mouseEvent.clientX >= 0 && event.mouseEvent.clientY >= 0 ) {
  1457. const { left, right, style } = element;
  1458. if ( this.mode === MODES.CARDBOARD || this.mode === MODES.STEREO ) {
  1459. style.display = 'none';
  1460. left.style.display = 'block';
  1461. right.style.display = 'block';
  1462. // Store element width for reference
  1463. element._width = left.clientWidth;
  1464. element._height = left.clientHeight;
  1465. } else {
  1466. style.display = 'block';
  1467. if ( left ) { left.style.display = 'none'; }
  1468. if ( right ) { right.style.display = 'none'; }
  1469. // Store element width for reference
  1470. element._width = element.clientWidth;
  1471. element._height = element.clientHeight;
  1472. }
  1473. }
  1474. },
  1475. /**
  1476. * This will be called on a mouse hover end
  1477. * Sets cursor style to 'default', hide the element and scale down the infospot
  1478. * @memberOf Infospot
  1479. * @instance
  1480. */
  1481. onHoverEnd: function () {
  1482. if ( !this.getContainer() ) { return; }
  1483. const { scaleDownAnimation, scaleUpAnimation, element } = this;
  1484. this.isHovering = false;
  1485. this.container.style.cursor = 'default';
  1486. if ( this.animated ) {
  1487. scaleUpAnimation.stop();
  1488. scaleDownAnimation.start();
  1489. }
  1490. if ( element && !this.element.locked ) {
  1491. const { left, right, style } = element;
  1492. style.display = 'none';
  1493. if ( left ) { left.style.display = 'none'; }
  1494. if ( right ) { right.style.display = 'none'; }
  1495. this.unlockHoverElement();
  1496. }
  1497. },
  1498. /**
  1499. * On dual eye effect handler
  1500. * Creates duplicate left and right element
  1501. * @param {object} event - panolens-dual-eye-effect event
  1502. * @memberOf Infospot
  1503. * @instance
  1504. */
  1505. onDualEyeEffect: function ( event ) {
  1506. if ( !this.getContainer() ) { return; }
  1507. let element, halfWidth, halfHeight;
  1508. this.mode = event.mode;
  1509. element = this.element;
  1510. halfWidth = this.container.clientWidth / 2;
  1511. halfHeight = this.container.clientHeight / 2;
  1512. if ( !element ) {
  1513. return;
  1514. }
  1515. if ( !element.left && !element.right ) {
  1516. element.left = element.cloneNode( true );
  1517. element.right = element.cloneNode( true );
  1518. }
  1519. if ( this.mode === MODES.CARDBOARD || this.mode === MODES.STEREO ) {
  1520. element.left.style.display = element.style.display;
  1521. element.right.style.display = element.style.display;
  1522. element.style.display = 'none';
  1523. } else {
  1524. element.style.display = element.left.style.display;
  1525. element.left.style.display = 'none';
  1526. element.right.style.display = 'none';
  1527. }
  1528. // Update elements translation
  1529. this.translateElement( halfWidth, halfHeight );
  1530. this.container.appendChild( element.left );
  1531. this.container.appendChild( element.right );
  1532. },
  1533. /**
  1534. * Translate the hovering element by css transform
  1535. * @param {number} x - X position on the window screen
  1536. * @param {number} y - Y position on the window screen
  1537. * @memberOf Infospot
  1538. * @instance
  1539. */
  1540. translateElement: function ( x, y ) {
  1541. if ( !this.element._width || !this.element._height || !this.getContainer() ) {
  1542. return;
  1543. }
  1544. let left, top, element, width, height, delta, container;
  1545. container = this.container;
  1546. element = this.element;
  1547. width = element._width / 2;
  1548. height = element._height / 2;
  1549. delta = element.verticalDelta !== undefined ? element.verticalDelta : 40;
  1550. left = x - width;
  1551. top = y - height - delta;
  1552. if ( ( this.mode === MODES.CARDBOARD || this.mode === MODES.STEREO )
  1553. && element.left && element.right
  1554. && !( x === container.clientWidth / 2 && y === container.clientHeight / 2 ) ) {
  1555. left = container.clientWidth / 4 - width + ( x - container.clientWidth / 2 );
  1556. top = container.clientHeight / 2 - height - delta + ( y - container.clientHeight / 2 );
  1557. this.setElementStyle( 'transform', element.left, 'translate(' + left + 'px, ' + top + 'px)' );
  1558. left += container.clientWidth / 2;
  1559. this.setElementStyle( 'transform', element.right, 'translate(' + left + 'px, ' + top + 'px)' );
  1560. } else {
  1561. this.setElementStyle( 'transform', element, 'translate(' + left + 'px, ' + top + 'px)' );
  1562. }
  1563. },
  1564. /**
  1565. * Set vendor specific css
  1566. * @param {string} type - CSS style name
  1567. * @param {HTMLElement} element - The element to be modified
  1568. * @param {string} value - Style value
  1569. * @memberOf Infospot
  1570. * @instance
  1571. */
  1572. setElementStyle: function ( type, element, value ) {
  1573. const style = element.style;
  1574. if ( type === 'transform' ) {
  1575. style.webkitTransform = style.msTransform = style.transform = value;
  1576. }
  1577. },
  1578. /**
  1579. * Set hovering text content
  1580. * @param {string} text - Text to be displayed
  1581. * @memberOf Infospot
  1582. * @instance
  1583. */
  1584. setText: function ( text ) {
  1585. if ( this.element ) {
  1586. this.element.textContent = text;
  1587. }
  1588. },
  1589. /**
  1590. * Set cursor css style on hover
  1591. * @memberOf Infospot
  1592. * @instance
  1593. */
  1594. setCursorHoverStyle: function ( style ) {
  1595. this.cursorStyle = style;
  1596. },
  1597. /**
  1598. * Add hovering text element
  1599. * @param {string} text - Text to be displayed
  1600. * @param {number} [delta=40] - Vertical delta to the infospot
  1601. * @memberOf Infospot
  1602. * @instance
  1603. */
  1604. addHoverText: function ( text, delta = 40 ) {
  1605. if ( !this.element ) {
  1606. this.element = document.createElement( 'div' );
  1607. this.element.style.display = 'none';
  1608. this.element.style.color = '#fff';
  1609. this.element.style.top = 0;
  1610. this.element.style.maxWidth = '50%';
  1611. this.element.style.maxHeight = '50%';
  1612. this.element.style.textShadow = '0 0 3px #000000';
  1613. this.element.style.fontFamily = '"Trebuchet MS", Helvetica, sans-serif';
  1614. this.element.style.position = 'absolute';
  1615. this.element.classList.add( 'panolens-infospot' );
  1616. this.element.verticalDelta = delta;
  1617. }
  1618. this.setText( text );
  1619. },
  1620. /**
  1621. * Add hovering element by cloning an element
  1622. * @param {HTMLDOMElement} el - Element to be cloned and displayed
  1623. * @param {number} [delta=40] - Vertical delta to the infospot
  1624. * @memberOf Infospot
  1625. * @instance
  1626. */
  1627. addHoverElement: function ( el, delta = 40 ) {
  1628. if ( !this.element ) {
  1629. this.element = el.cloneNode( true );
  1630. this.element.style.display = 'none';
  1631. this.element.style.top = 0;
  1632. this.element.style.position = 'absolute';
  1633. this.element.classList.add( 'panolens-infospot' );
  1634. this.element.verticalDelta = delta;
  1635. }
  1636. },
  1637. /**
  1638. * Remove hovering element
  1639. * @memberOf Infospot
  1640. * @instance
  1641. */
  1642. removeHoverElement: function () {
  1643. if ( this.element ) {
  1644. if ( this.element.left ) {
  1645. this.container.removeChild( this.element.left );
  1646. this.element.left = null;
  1647. }
  1648. if ( this.element.right ) {
  1649. this.container.removeChild( this.element.right );
  1650. this.element.right = null;
  1651. }
  1652. this.container.removeChild( this.element );
  1653. this.element = null;
  1654. }
  1655. },
  1656. /**
  1657. * Lock hovering element
  1658. * @memberOf Infospot
  1659. * @instance
  1660. */
  1661. lockHoverElement: function () {
  1662. if ( this.element ) {
  1663. this.element.locked = true;
  1664. }
  1665. },
  1666. /**
  1667. * Unlock hovering element
  1668. * @memberOf Infospot
  1669. * @instance
  1670. */
  1671. unlockHoverElement: function () {
  1672. if ( this.element ) {
  1673. this.element.locked = false;
  1674. }
  1675. },
  1676. /**
  1677. * Enable raycasting
  1678. * @param {boolean} [enabled=true]
  1679. * @memberOf Infospot
  1680. * @instance
  1681. */
  1682. enableRaycast: function ( enabled = true ) {
  1683. if ( enabled ) {
  1684. this.raycast = this.originalRaycast;
  1685. } else {
  1686. this.raycast = () => {};
  1687. }
  1688. },
  1689. /**
  1690. * Show infospot
  1691. * @param {number} [delay=0] - Delay time to show
  1692. * @memberOf Infospot
  1693. * @instance
  1694. */
  1695. show: function ( delay = 0 ) {
  1696. const { animated, hideAnimation, showAnimation, material } = this;
  1697. if ( animated ) {
  1698. hideAnimation.stop();
  1699. showAnimation.delay( delay ).start();
  1700. } else {
  1701. this.enableRaycast( true );
  1702. material.opacity = 1;
  1703. }
  1704. },
  1705. /**
  1706. * Hide infospot
  1707. * @param {number} [delay=0] - Delay time to hide
  1708. * @memberOf Infospot
  1709. * @instance
  1710. */
  1711. hide: function ( delay = 0 ) {
  1712. const { animated, hideAnimation, showAnimation, material, element } = this;
  1713. if ( element ) {
  1714. const { style } = element;
  1715. style.display = 'none';
  1716. }
  1717. if ( animated ) {
  1718. showAnimation.stop();
  1719. hideAnimation.delay( delay ).start();
  1720. } else {
  1721. this.enableRaycast( false );
  1722. material.opacity = 0;
  1723. }
  1724. },
  1725. /**
  1726. * Set focus event handler
  1727. * @memberOf Infospot
  1728. * @instance
  1729. */
  1730. setFocusMethod: function ( event ) {
  1731. if ( event ) {
  1732. this.HANDLER_FOCUS = event.method;
  1733. }
  1734. },
  1735. /**
  1736. * Focus camera center to this infospot
  1737. * @param {number} [duration=1000] - Duration to tween
  1738. * @param {function} [easing=TWEEN.Easing.Exponential.Out] - Easing function
  1739. * @memberOf Infospot
  1740. * @instance
  1741. */
  1742. focus: function ( duration, easing ) {
  1743. if ( this.HANDLER_FOCUS ) {
  1744. this.HANDLER_FOCUS( this.position, duration, easing );
  1745. this.onDismiss();
  1746. }
  1747. },
  1748. /**
  1749. * Dispose
  1750. * @memberOf Infospot
  1751. * @instance
  1752. */
  1753. dispose: function () {
  1754. const { geometry, material } = this;
  1755. const { map } = material;
  1756. this.removeHoverElement();
  1757. if ( this.parent ) {
  1758. this.parent.remove( this );
  1759. }
  1760. if ( map ) { map.dispose(); material.map = null; }
  1761. if ( geometry ) { geometry.dispose(); this.geometry = null; }
  1762. if ( material ) { material.dispose(); this.material = null; }
  1763. }
  1764. } );
  1765. /**
  1766. * @classdesc Widget for controls
  1767. * @constructor
  1768. * @param {HTMLElement} container - A domElement where default control widget will be attached to
  1769. */
  1770. function Widget ( container ) {
  1771. if ( !container ) {
  1772. console.warn( 'PANOLENS.Widget: No container specified' );
  1773. }
  1774. THREE.EventDispatcher.call( this );
  1775. this.DEFAULT_TRANSITION = 'all 0.27s ease';
  1776. this.TOUCH_ENABLED = !!(( 'ontouchstart' in window ) || window.DocumentTouch && document instanceof DocumentTouch);
  1777. this.PREVENT_EVENT_HANDLER = function ( event ) {
  1778. event.preventDefault();
  1779. event.stopPropagation();
  1780. };
  1781. this.container = container;
  1782. this.barElement = null;
  1783. this.fullscreenElement = null;
  1784. this.videoElement = null;
  1785. this.settingElement = null;
  1786. this.mainMenu = null;
  1787. this.activeMainItem = null;
  1788. this.activeSubMenu = null;
  1789. this.mask = null;
  1790. }
  1791. Widget.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype ), {
  1792. constructor: Widget,
  1793. /**
  1794. * Add control bar
  1795. * @memberOf Widget
  1796. * @instance
  1797. */
  1798. addControlBar: function () {
  1799. if ( !this.container ) {
  1800. console.warn( 'Widget container not set' );
  1801. return;
  1802. }
  1803. var scope = this, bar, styleTranslate, styleOpacity, gradientStyle;
  1804. gradientStyle = 'linear-gradient(bottom, rgba(0,0,0,0.2), rgba(0,0,0,0))';
  1805. bar = document.createElement( 'div' );
  1806. bar.style.width = '100%';
  1807. bar.style.height = '44px';
  1808. bar.style.float = 'left';
  1809. bar.style.transform = bar.style.webkitTransform = bar.style.msTransform = 'translateY(-100%)';
  1810. bar.style.background = '-webkit-' + gradientStyle;
  1811. bar.style.background = '-moz-' + gradientStyle;
  1812. bar.style.background = '-o-' + gradientStyle;
  1813. bar.style.background = '-ms-' + gradientStyle;
  1814. bar.style.background = gradientStyle;
  1815. bar.style.transition = this.DEFAULT_TRANSITION;
  1816. bar.style.pointerEvents = 'none';
  1817. bar.isHidden = false;
  1818. bar.toggle = function () {
  1819. bar.isHidden = !bar.isHidden;
  1820. styleTranslate = bar.isHidden ? 'translateY(0)' : 'translateY(-100%)';
  1821. styleOpacity = bar.isHidden ? 0 : 1;
  1822. bar.style.transform = bar.style.webkitTransform = bar.style.msTransform = styleTranslate;
  1823. bar.style.opacity = styleOpacity;
  1824. };
  1825. // Menu
  1826. var menu = this.createDefaultMenu();
  1827. this.mainMenu = this.createMainMenu( menu );
  1828. bar.appendChild( this.mainMenu );
  1829. // Mask
  1830. var mask = this.createMask();
  1831. this.mask = mask;
  1832. this.container.appendChild( mask );
  1833. // Dispose
  1834. bar.dispose = function () {
  1835. if ( scope.fullscreenElement ) {
  1836. bar.removeChild( scope.fullscreenElement );
  1837. scope.fullscreenElement.dispose();
  1838. scope.fullscreenElement = null;
  1839. }
  1840. if ( scope.settingElement ) {
  1841. bar.removeChild( scope.settingElement );
  1842. scope.settingElement.dispose();
  1843. scope.settingElement = null;
  1844. }
  1845. if ( scope.videoElement ) {
  1846. bar.removeChild( scope.videoElement );
  1847. scope.videoElement.dispose();
  1848. scope.videoElement = null;
  1849. }
  1850. };
  1851. this.container.appendChild( bar );
  1852. // Mask events
  1853. this.mask.addEventListener( 'mousemove', this.PREVENT_EVENT_HANDLER, true );
  1854. this.mask.addEventListener( 'mouseup', this.PREVENT_EVENT_HANDLER, true );
  1855. this.mask.addEventListener( 'mousedown', this.PREVENT_EVENT_HANDLER, true );
  1856. this.mask.addEventListener( scope.TOUCH_ENABLED ? 'touchend' : 'click', function ( event ) {
  1857. event.preventDefault();
  1858. event.stopPropagation();
  1859. scope.mask.hide();
  1860. scope.settingElement.deactivate();
  1861. }, false );
  1862. // Event listener
  1863. this.addEventListener( 'control-bar-toggle', bar.toggle );
  1864. this.barElement = bar;
  1865. },
  1866. /**
  1867. * Create default menu
  1868. * @memberOf Widget
  1869. * @instance
  1870. */
  1871. createDefaultMenu: function () {
  1872. var scope = this, handler;
  1873. handler = function ( method, data ) {
  1874. return function () {
  1875. scope.dispatchEvent( {
  1876. type: 'panolens-viewer-handler',
  1877. method: method,
  1878. data: data
  1879. } );
  1880. };
  1881. };
  1882. return [
  1883. {
  1884. title: 'Control',
  1885. subMenu: [
  1886. {
  1887. title: this.TOUCH_ENABLED ? 'Touch' : 'Mouse',
  1888. handler: handler( 'enableControl', CONTROLS.ORBIT )
  1889. },
  1890. {
  1891. title: 'Sensor',
  1892. handler: handler( 'enableControl', CONTROLS.DEVICEORIENTATION )
  1893. }
  1894. ]
  1895. },
  1896. {
  1897. title: 'Mode',
  1898. subMenu: [
  1899. {
  1900. title: 'Normal',
  1901. handler: handler( 'disableEffect' )
  1902. },
  1903. {
  1904. title: 'Cardboard',
  1905. handler: handler( 'enableEffect', MODES.CARDBOARD )
  1906. },
  1907. {
  1908. title: 'Stereoscopic',
  1909. handler: handler( 'enableEffect', MODES.STEREO )
  1910. }
  1911. ]
  1912. }
  1913. ];
  1914. },
  1915. /**
  1916. * Add buttons on top of control bar
  1917. * @param {string} name - The control button name to be created
  1918. * @memberOf Widget
  1919. * @instance
  1920. */
  1921. addControlButton: function ( name ) {
  1922. let element;
  1923. switch( name ) {
  1924. case 'fullscreen':
  1925. element = this.createFullscreenButton();
  1926. this.fullscreenElement = element;
  1927. break;
  1928. case 'setting':
  1929. element = this.createSettingButton();
  1930. this.settingElement = element;
  1931. break;
  1932. case 'video':
  1933. element = this.createVideoControl();
  1934. this.videoElement = element;
  1935. break;
  1936. default:
  1937. return;
  1938. }
  1939. if ( !element ) {
  1940. return;
  1941. }
  1942. this.barElement.appendChild( element );
  1943. },
  1944. /**
  1945. * Create modal mask
  1946. * @memberOf Widget
  1947. * @instance
  1948. */
  1949. createMask: function () {
  1950. const element = document.createElement( 'div' );
  1951. element.style.position = 'absolute';
  1952. element.style.top = 0;
  1953. element.style.left = 0;
  1954. element.style.width = '100%';
  1955. element.style.height = '100%';
  1956. element.style.background = 'transparent';
  1957. element.style.display = 'none';
  1958. element.show = function () {
  1959. this.style.display = 'block';
  1960. };
  1961. element.hide = function () {
  1962. this.style.display = 'none';
  1963. };
  1964. return element;
  1965. },
  1966. /**
  1967. * Create Setting button to toggle menu
  1968. * @memberOf Widget
  1969. * @instance
  1970. */
  1971. createSettingButton: function () {
  1972. let scope = this, item;
  1973. function onTap ( event ) {
  1974. event.preventDefault();
  1975. event.stopPropagation();
  1976. scope.mainMenu.toggle();
  1977. if ( this.activated ) {
  1978. this.deactivate();
  1979. } else {
  1980. this.activate();
  1981. }
  1982. }
  1983. item = this.createCustomItem( {
  1984. style: {
  1985. backgroundImage: 'url("' + DataImage.Setting + '")',
  1986. webkitTransition: this.DEFAULT_TRANSITION,
  1987. transition: this.DEFAULT_TRANSITION
  1988. },
  1989. onTap: onTap
  1990. } );
  1991. item.activate = function () {
  1992. this.style.transform = 'rotate3d(0,0,1,90deg)';
  1993. this.activated = true;
  1994. scope.mask.show();
  1995. };
  1996. item.deactivate = function () {
  1997. this.style.transform = 'rotate3d(0,0,0,0)';
  1998. this.activated = false;
  1999. scope.mask.hide();
  2000. if ( scope.mainMenu && scope.mainMenu.visible ) {
  2001. scope.mainMenu.hide();
  2002. }
  2003. if ( scope.activeSubMenu && scope.activeSubMenu.visible ) {
  2004. scope.activeSubMenu.hide();
  2005. }
  2006. if ( scope.mainMenu && scope.mainMenu._width ) {
  2007. scope.mainMenu.changeSize( scope.mainMenu._width );
  2008. scope.mainMenu.unslideAll();
  2009. }
  2010. };
  2011. item.activated = false;
  2012. return item;
  2013. },
  2014. /**
  2015. * Create Fullscreen button
  2016. * @return {HTMLSpanElement} - The dom element icon for fullscreen
  2017. * @memberOf Widget
  2018. * @instance
  2019. * @fires Widget#panolens-viewer-handler
  2020. */
  2021. createFullscreenButton: function () {
  2022. let scope = this, item, isFullscreen = false, tapSkipped = true, stylesheetId;
  2023. const { container } = this;
  2024. stylesheetId = 'panolens-style-addon';
  2025. // Don't create button if no support
  2026. if ( !document.fullscreenEnabled &&
  2027. !document.webkitFullscreenEnabled &&
  2028. !document.mozFullScreenEnabled &&
  2029. !document.msFullscreenEnabled ) {
  2030. return;
  2031. }
  2032. function onTap ( event ) {
  2033. event.preventDefault();
  2034. event.stopPropagation();
  2035. tapSkipped = false;
  2036. if ( !isFullscreen ) {
  2037. if ( container.requestFullscreen ) { container.requestFullscreen(); }
  2038. if ( container.msRequestFullscreen ) { container.msRequestFullscreen(); }
  2039. if ( container.mozRequestFullScreen ) { container.mozRequestFullScreen(); }
  2040. if ( container.webkitRequestFullscreen ) { container.webkitRequestFullscreen( Element.ALLOW_KEYBOARD_INPUT ); }
  2041. isFullscreen = true;
  2042. } else {
  2043. if ( document.exitFullscreen ) { document.exitFullscreen(); }
  2044. if ( document.msExitFullscreen ) { document.msExitFullscreen(); }
  2045. if ( document.mozCancelFullScreen ) { document.mozCancelFullScreen(); }
  2046. if ( document.webkitExitFullscreen ) { document.webkitExitFullscreen( ); }
  2047. isFullscreen = false;
  2048. }
  2049. this.style.backgroundImage = ( isFullscreen )
  2050. ? 'url("' + DataImage.FullscreenLeave + '")'
  2051. : 'url("' + DataImage.FullscreenEnter + '")';
  2052. }
  2053. function onFullScreenChange () {
  2054. if ( tapSkipped ) {
  2055. isFullscreen = !isFullscreen;
  2056. item.style.backgroundImage = ( isFullscreen )
  2057. ? 'url("' + DataImage.FullscreenLeave + '")'
  2058. : 'url("' + DataImage.FullscreenEnter + '")';
  2059. }
  2060. /**
  2061. * Viewer handler event
  2062. * @type {object}
  2063. * @event Widget#panolens-viewer-handler
  2064. * @property {string} method - 'onWindowResize' function call on Viewer
  2065. */
  2066. scope.dispatchEvent( { type: 'panolens-viewer-handler', method: 'onWindowResize' } );
  2067. tapSkipped = true;
  2068. }
  2069. document.addEventListener( 'fullscreenchange', onFullScreenChange, false );
  2070. document.addEventListener( 'webkitfullscreenchange', onFullScreenChange, false );
  2071. document.addEventListener( 'mozfullscreenchange', onFullScreenChange, false );
  2072. document.addEventListener( 'MSFullscreenChange', onFullScreenChange, false );
  2073. item = this.createCustomItem( {
  2074. style: {
  2075. backgroundImage: 'url("' + DataImage.FullscreenEnter + '")'
  2076. },
  2077. onTap: onTap
  2078. } );
  2079. // Add fullscreen stlye if not exists
  2080. if ( !document.querySelector( stylesheetId ) ) {
  2081. const sheet = document.createElement( 'style' );
  2082. sheet.id = stylesheetId;
  2083. sheet.innerHTML = ':-webkit-full-screen { width: 100% !important; height: 100% !important }';
  2084. document.body.appendChild( sheet );
  2085. }
  2086. return item;
  2087. },
  2088. /**
  2089. * Create video control container
  2090. * @memberOf Widget
  2091. * @instance
  2092. * @return {HTMLSpanElement} - The dom element icon for video control
  2093. */
  2094. createVideoControl: function () {
  2095. const item = document.createElement( 'span' );
  2096. item.style.display = 'none';
  2097. item.show = function () {
  2098. item.style.display = '';
  2099. };
  2100. item.hide = function () {
  2101. item.style.display = 'none';
  2102. item.controlButton.paused = true;
  2103. item.controlButton.update();
  2104. };
  2105. item.controlButton = this.createVideoControlButton();
  2106. item.seekBar = this.createVideoControlSeekbar();
  2107. item.appendChild( item.controlButton );
  2108. item.appendChild( item.seekBar );
  2109. item.dispose = function () {
  2110. item.removeChild( item.controlButton );
  2111. item.removeChild( item.seekBar );
  2112. item.controlButton.dispose();
  2113. item.controlButton = null;
  2114. item.seekBar.dispose();
  2115. item.seekBar = null;
  2116. };
  2117. this.addEventListener( 'video-control-show', item.show );
  2118. this.addEventListener( 'video-control-hide', item.hide );
  2119. return item;
  2120. },
  2121. /**
  2122. * Create video control button
  2123. * @memberOf Widget
  2124. * @instance
  2125. * @return {HTMLSpanElement} - The dom element icon for video control
  2126. * @fires Widget#panolens-viewer-handler
  2127. */
  2128. createVideoControlButton: function () {
  2129. const scope = this;
  2130. function onTap ( event ) {
  2131. event.preventDefault();
  2132. event.stopPropagation();
  2133. /**
  2134. * Viewer handler event
  2135. * @type {object}
  2136. * @event Widget#panolens-viewer-handler
  2137. * @property {string} method - 'toggleVideoPlay' function call on Viewer
  2138. */
  2139. scope.dispatchEvent( { type: 'panolens-viewer-handler', method: 'toggleVideoPlay', data: !this.paused } );
  2140. this.paused = !this.paused;
  2141. item.update();
  2142. }
  2143. const item = this.createCustomItem( {
  2144. style: {
  2145. float: 'left',
  2146. backgroundImage: 'url("' + DataImage.VideoPlay + '")'
  2147. },
  2148. onTap: onTap
  2149. } );
  2150. item.paused = true;
  2151. item.update = function ( paused ) {
  2152. this.paused = paused !== undefined ? paused : this.paused;
  2153. this.style.backgroundImage = 'url("' + ( this.paused
  2154. ? DataImage.VideoPlay
  2155. : DataImage.VideoPause ) + '")';
  2156. };
  2157. return item;
  2158. },
  2159. /**
  2160. * Create video seekbar
  2161. * @memberOf Widget
  2162. * @instance
  2163. * @return {HTMLSpanElement} - The dom element icon for video seekbar
  2164. * @fires Widget#panolens-viewer-handler
  2165. */
  2166. createVideoControlSeekbar: function () {
  2167. let scope = this, item, progressElement, progressElementControl,
  2168. isDragging = false, mouseX, percentageNow, percentageNext;
  2169. progressElement = document.createElement( 'div' );
  2170. progressElement.style.width = '0%';
  2171. progressElement.style.height = '100%';
  2172. progressElement.style.backgroundColor = '#fff';
  2173. progressElementControl = document.createElement( 'div' );
  2174. progressElementControl.style.float = 'right';
  2175. progressElementControl.style.width = '14px';
  2176. progressElementControl.style.height = '14px';
  2177. progressElementControl.style.transform = 'translate(7px, -5px)';
  2178. progressElementControl.style.borderRadius = '50%';
  2179. progressElementControl.style.backgroundColor = '#ddd';
  2180. progressElementControl.addEventListener( 'mousedown', onMouseDown, { passive: true } );
  2181. progressElementControl.addEventListener( 'touchstart', onMouseDown, { passive: true } );
  2182. function onMouseDown ( event ) {
  2183. event.stopPropagation();
  2184. isDragging = true;
  2185. mouseX = event.clientX || ( event.changedTouches && event.changedTouches[0].clientX );
  2186. percentageNow = parseInt( progressElement.style.width ) / 100;
  2187. addControlListeners();
  2188. }
  2189. function onVideoControlDrag ( event ) {
  2190. if( isDragging ){
  2191. const clientX = event.clientX || ( event.changedTouches && event.changedTouches[0].clientX );
  2192. percentageNext = ( clientX - mouseX ) / item.clientWidth;
  2193. percentageNext = percentageNow + percentageNext;
  2194. percentageNext = percentageNext > 1 ? 1 : ( ( percentageNext < 0 ) ? 0 : percentageNext );
  2195. item.setProgress ( percentageNext );
  2196. /**
  2197. * Viewer handler event
  2198. * @type {object}
  2199. * @event Widget#panolens-viewer-handler
  2200. * @property {string} method - 'setVideoCurrentTime' function call on Viewer
  2201. * @property {number} data - Percentage of current video. Range from 0.0 to 1.0
  2202. */
  2203. scope.dispatchEvent( { type: 'panolens-viewer-handler', method: 'setVideoCurrentTime', data: percentageNext } );
  2204. }
  2205. }
  2206. function onVideoControlStop ( event ) {
  2207. event.stopPropagation();
  2208. isDragging = false;
  2209. removeControlListeners();
  2210. }
  2211. function addControlListeners () {
  2212. scope.container.addEventListener( 'mousemove', onVideoControlDrag, { passive: true } );
  2213. scope.container.addEventListener( 'mouseup', onVideoControlStop, { passive: true } );
  2214. scope.container.addEventListener( 'touchmove', onVideoControlDrag, { passive: true } );
  2215. scope.container.addEventListener( 'touchend', onVideoControlStop, { passive: true } );
  2216. }
  2217. function removeControlListeners () {
  2218. scope.container.removeEventListener( 'mousemove', onVideoControlDrag, false );
  2219. scope.container.removeEventListener( 'mouseup', onVideoControlStop, false );
  2220. scope.container.removeEventListener( 'touchmove', onVideoControlDrag, false );
  2221. scope.container.removeEventListener( 'touchend', onVideoControlStop, false );
  2222. }
  2223. function onTap ( event ) {
  2224. event.preventDefault();
  2225. event.stopPropagation();
  2226. if ( event.target === progressElementControl ) { return; }
  2227. const percentage = ( event.changedTouches && event.changedTouches.length > 0 )
  2228. ? ( event.changedTouches[0].pageX - event.target.getBoundingClientRect().left ) / this.clientWidth
  2229. : event.offsetX / this.clientWidth;
  2230. /**
  2231. * Viewer handler event
  2232. * @type {object}
  2233. * @property {string} method - 'setVideoCurrentTime' function call on Viewer
  2234. * @property {number} data - Percentage of current video. Range from 0.0 to 1.0
  2235. */
  2236. scope.dispatchEvent( { type: 'panolens-viewer-handler', method: 'setVideoCurrentTime', data: percentage } );
  2237. item.setProgress( event.offsetX / this.clientWidth );
  2238. }
  2239. function onDispose () {
  2240. removeControlListeners();
  2241. progressElement = null;
  2242. progressElementControl = null;
  2243. }
  2244. progressElement.appendChild( progressElementControl );
  2245. item = this.createCustomItem( {
  2246. style: {
  2247. float: 'left',
  2248. width: '30%',
  2249. height: '4px',
  2250. marginTop: '20px',
  2251. backgroundColor: 'rgba(188,188,188,0.8)'
  2252. },
  2253. onTap: onTap,
  2254. onDispose: onDispose
  2255. } );
  2256. item.appendChild( progressElement );
  2257. item.setProgress = function( percentage ) {
  2258. progressElement.style.width = percentage * 100 + '%';
  2259. };
  2260. this.addEventListener( 'video-update', function ( event ) {
  2261. item.setProgress( event.percentage );
  2262. } );
  2263. item.progressElement = progressElement;
  2264. item.progressElementControl = progressElementControl;
  2265. return item;
  2266. },
  2267. /**
  2268. * Create menu item
  2269. * @param {string} title - Title to display
  2270. * @memberOf Widget
  2271. * @instance
  2272. * @return {HTMLElement} - An anchor tag element
  2273. */
  2274. createMenuItem: function ( title ) {
  2275. const scope = this;
  2276. const item = document.createElement( 'a' );
  2277. item.textContent = title;
  2278. item.style.display = 'block';
  2279. item.style.padding = '10px';
  2280. item.style.textDecoration = 'none';
  2281. item.style.cursor = 'pointer';
  2282. item.style.pointerEvents = 'auto';
  2283. item.style.transition = this.DEFAULT_TRANSITION;
  2284. item.slide = function ( right ) {
  2285. this.style.transform = 'translateX(' + ( right ? '' : '-' ) + '100%)';
  2286. };
  2287. item.unslide = function () {
  2288. this.style.transform = 'translateX(0)';
  2289. };
  2290. item.setIcon = function ( url ) {
  2291. if ( this.icon ) {
  2292. this.icon.style.backgroundImage = 'url(' + url + ')';
  2293. }
  2294. };
  2295. item.setSelectionTitle = function ( title ) {
  2296. if ( this.selection ) {
  2297. this.selection.textContent = title;
  2298. }
  2299. };
  2300. item.addSelection = function ( name ) {
  2301. const selection = document.createElement( 'span' );
  2302. selection.style.fontSize = '13px';
  2303. selection.style.fontWeight = '300';
  2304. selection.style.float = 'right';
  2305. this.selection = selection;
  2306. this.setSelectionTitle( name );
  2307. this.appendChild( selection );
  2308. return this;
  2309. };
  2310. item.addIcon = function ( url = DataImage.ChevronRight, left = false, flip = false ) {
  2311. const element = document.createElement( 'span' );
  2312. element.style.float = left ? 'left' : 'right';
  2313. element.style.width = '17px';
  2314. element.style.height = '17px';
  2315. element.style[ 'margin' + ( left ? 'Right' : 'Left' ) ] = '12px';
  2316. element.style.backgroundSize = 'cover';
  2317. if ( flip ) {
  2318. element.style.transform = 'rotateZ(180deg)';
  2319. }
  2320. this.icon = element;
  2321. this.setIcon( url );
  2322. this.appendChild( element );
  2323. return this;
  2324. };
  2325. item.addSubMenu = function ( title, items ) {
  2326. this.subMenu = scope.createSubMenu( title, items );
  2327. return this;
  2328. };
  2329. item.addEventListener( 'mouseenter', function () {
  2330. this.style.backgroundColor = '#e0e0e0';
  2331. }, false );
  2332. item.addEventListener( 'mouseleave', function () {
  2333. this.style.backgroundColor = '#fafafa';
  2334. }, false );
  2335. return item;
  2336. },
  2337. /**
  2338. * Create menu item header
  2339. * @param {string} title - Title to display
  2340. * @memberOf Widget
  2341. * @instance
  2342. * @return {HTMLElement} - An anchor tag element
  2343. */
  2344. createMenuItemHeader: function ( title ) {
  2345. const header = this.createMenuItem( title );
  2346. header.style.borderBottom = '1px solid #333';
  2347. header.style.paddingBottom = '15px';
  2348. return header;
  2349. },
  2350. /**
  2351. * Create main menu
  2352. * @param {array} menus - Menu array list
  2353. * @memberOf Widget
  2354. * @instance
  2355. * @return {HTMLElement} - A span element
  2356. */
  2357. createMainMenu: function ( menus ) {
  2358. let scope = this, menu = this.createMenu();
  2359. menu._width = 200;
  2360. menu.changeSize( menu._width );
  2361. function onTap ( event ) {
  2362. event.preventDefault();
  2363. event.stopPropagation();
  2364. let mainMenu = scope.mainMenu, subMenu = this.subMenu;
  2365. function onNextTick () {
  2366. mainMenu.changeSize( subMenu.clientWidth );
  2367. subMenu.show();
  2368. subMenu.unslideAll();
  2369. }
  2370. mainMenu.hide();
  2371. mainMenu.slideAll();
  2372. mainMenu.parentElement.appendChild( subMenu );
  2373. scope.activeMainItem = this;
  2374. scope.activeSubMenu = subMenu;
  2375. window.requestAnimationFrame( onNextTick );
  2376. }
  2377. for ( var i = 0; i < menus.length; i++ ) {
  2378. var item = menu.addItem( menus[ i ].title );
  2379. item.style.paddingLeft = '20px';
  2380. item.addIcon()
  2381. .addEventListener( scope.TOUCH_ENABLED ? 'touchend' : 'click', onTap, false );
  2382. if ( menus[ i ].subMenu && menus[ i ].subMenu.length > 0 ) {
  2383. var title = menus[ i ].subMenu[ 0 ].title;
  2384. item.addSelection( title )
  2385. .addSubMenu( menus[ i ].title, menus[ i ].subMenu );
  2386. }
  2387. }
  2388. return menu;
  2389. },
  2390. /**
  2391. * Create sub menu
  2392. * @param {string} title - Sub menu title
  2393. * @param {array} items - Item array list
  2394. * @memberOf Widget
  2395. * @instance
  2396. * @return {HTMLElement} - A span element
  2397. */
  2398. createSubMenu: function ( title, items ) {
  2399. let scope = this, menu, subMenu = this.createMenu();
  2400. subMenu.items = items;
  2401. subMenu.activeItem = null;
  2402. function onTap ( event ) {
  2403. event.preventDefault();
  2404. event.stopPropagation();
  2405. menu = scope.mainMenu;
  2406. menu.changeSize( menu._width );
  2407. menu.unslideAll();
  2408. menu.show();
  2409. subMenu.slideAll( true );
  2410. subMenu.hide();
  2411. if ( this.type !== 'header' ) {
  2412. subMenu.setActiveItem( this );
  2413. scope.activeMainItem.setSelectionTitle( this.textContent );
  2414. if ( this.handler ) { this.handler(); }
  2415. }
  2416. }
  2417. subMenu.addHeader( title ).addIcon( undefined, true, true ).addEventListener( scope.TOUCH_ENABLED ? 'touchend' : 'click', onTap, false );
  2418. for ( let i = 0; i < items.length; i++ ) {
  2419. const item = subMenu.addItem( items[ i ].title );
  2420. item.style.fontWeight = 300;
  2421. item.handler = items[ i ].handler;
  2422. item.addIcon( ' ', true );
  2423. item.addEventListener( scope.TOUCH_ENABLED ? 'touchend' : 'click', onTap, false );
  2424. if ( !subMenu.activeItem ) {
  2425. subMenu.setActiveItem( item );
  2426. }
  2427. }
  2428. subMenu.slideAll( true );
  2429. return subMenu;
  2430. },
  2431. /**
  2432. * Create general menu
  2433. * @memberOf Widget
  2434. * @instance
  2435. * @return {HTMLElement} - A span element
  2436. */
  2437. createMenu: function () {
  2438. const scope = this;
  2439. const menu = document.createElement( 'span' );
  2440. const style = menu.style;
  2441. style.padding = '5px 0';
  2442. style.position = 'fixed';
  2443. style.bottom = '100%';
  2444. style.right = '14px';
  2445. style.backgroundColor = '#fafafa';
  2446. style.fontFamily = 'Helvetica Neue';
  2447. style.fontSize = '14px';
  2448. style.visibility = 'hidden';
  2449. style.opacity = 0;
  2450. style.boxShadow = '0 0 12pt rgba(0,0,0,0.25)';
  2451. style.borderRadius = '2px';
  2452. style.overflow = 'hidden';
  2453. style.willChange = 'width, height, opacity';
  2454. style.pointerEvents = 'auto';
  2455. style.transition = this.DEFAULT_TRANSITION;
  2456. menu.visible = false;
  2457. menu.changeSize = function ( width, height ) {
  2458. if ( width ) {
  2459. this.style.width = width + 'px';
  2460. }
  2461. if ( height ) {
  2462. this.style.height = height + 'px';
  2463. }
  2464. };
  2465. menu.show = function () {
  2466. this.style.opacity = 1;
  2467. this.style.visibility = 'visible';
  2468. this.visible = true;
  2469. };
  2470. menu.hide = function () {
  2471. this.style.opacity = 0;
  2472. this.style.visibility = 'hidden';
  2473. this.visible = false;
  2474. };
  2475. menu.toggle = function () {
  2476. if ( this.visible ) {
  2477. this.hide();
  2478. } else {
  2479. this.show();
  2480. }
  2481. };
  2482. menu.slideAll = function ( right ) {
  2483. for ( let i = 0; i < menu.children.length; i++ ){
  2484. if ( menu.children[ i ].slide ) {
  2485. menu.children[ i ].slide( right );
  2486. }
  2487. }
  2488. };
  2489. menu.unslideAll = function () {
  2490. for ( let i = 0; i < menu.children.length; i++ ){
  2491. if ( menu.children[ i ].unslide ) {
  2492. menu.children[ i ].unslide();
  2493. }
  2494. }
  2495. };
  2496. menu.addHeader = function ( title ) {
  2497. const header = scope.createMenuItemHeader( title );
  2498. header.type = 'header';
  2499. this.appendChild( header );
  2500. return header;
  2501. };
  2502. menu.addItem = function ( title ) {
  2503. const item = scope.createMenuItem( title );
  2504. item.type = 'item';
  2505. this.appendChild( item );
  2506. return item;
  2507. };
  2508. menu.setActiveItem = function ( item ) {
  2509. if ( this.activeItem ) {
  2510. this.activeItem.setIcon( ' ' );
  2511. }
  2512. item.setIcon( DataImage.Check );
  2513. this.activeItem = item;
  2514. };
  2515. menu.addEventListener( 'mousemove', this.PREVENT_EVENT_HANDLER, true );
  2516. menu.addEventListener( 'mouseup', this.PREVENT_EVENT_HANDLER, true );
  2517. menu.addEventListener( 'mousedown', this.PREVENT_EVENT_HANDLER, true );
  2518. return menu;
  2519. },
  2520. /**
  2521. * Create custom item element
  2522. * @memberOf Widget
  2523. * @instance
  2524. * @return {HTMLSpanElement} - The dom element icon
  2525. */
  2526. createCustomItem: function ( options = {} ) {
  2527. const scope = this;
  2528. const item = options.element || document.createElement( 'span' );
  2529. const { onDispose } = options;
  2530. item.style.cursor = 'pointer';
  2531. item.style.float = 'right';
  2532. item.style.width = '44px';
  2533. item.style.height = '100%';
  2534. item.style.backgroundSize = '60%';
  2535. item.style.backgroundRepeat = 'no-repeat';
  2536. item.style.backgroundPosition = 'center';
  2537. item.style.webkitUserSelect =
  2538. item.style.MozUserSelect =
  2539. item.style.userSelect = 'none';
  2540. item.style.position = 'relative';
  2541. item.style.pointerEvents = 'auto';
  2542. // White glow on icon
  2543. item.addEventListener( scope.TOUCH_ENABLED ? 'touchstart' : 'mouseenter', function() {
  2544. item.style.filter =
  2545. item.style.webkitFilter = 'drop-shadow(0 0 5px rgba(255,255,255,1))';
  2546. }, { passive: true });
  2547. item.addEventListener( scope.TOUCH_ENABLED ? 'touchend' : 'mouseleave', function() {
  2548. item.style.filter =
  2549. item.style.webkitFilter = '';
  2550. }, { passive: true });
  2551. this.mergeStyleOptions( item, options.style );
  2552. if ( options.onTap ) {
  2553. item.addEventListener( scope.TOUCH_ENABLED ? 'touchend' : 'click', options.onTap, false );
  2554. }
  2555. item.dispose = function () {
  2556. item.removeEventListener( scope.TOUCH_ENABLED ? 'touchend' : 'click', options.onTap, false );
  2557. if ( onDispose ) { options.onDispose(); }
  2558. };
  2559. return item;
  2560. },
  2561. /**
  2562. * Merge item css style
  2563. * @param {HTMLElement} element - The element to be merged with style
  2564. * @param {object} options - The style options
  2565. * @memberOf Widget
  2566. * @instance
  2567. * @return {HTMLElement} - The same element with merged styles
  2568. */
  2569. mergeStyleOptions: function ( element, options = {} ) {
  2570. for ( let property in options ){
  2571. if ( options.hasOwnProperty( property ) ) {
  2572. element.style[ property ] = options[ property ];
  2573. }
  2574. }
  2575. return element;
  2576. },
  2577. /**
  2578. * Dispose widgets by detaching dom elements from container
  2579. * @memberOf Widget
  2580. * @instance
  2581. */
  2582. dispose: function () {
  2583. if ( this.barElement ) {
  2584. this.container.removeChild( this.barElement );
  2585. this.barElement.dispose();
  2586. this.barElement = null;
  2587. }
  2588. }
  2589. } );
  2590. /**
  2591. * @classdesc Base Panorama
  2592. * @constructor
  2593. * @param {THREE.Geometry} geometry - The geometry for this panorama
  2594. * @param {THREE.Material} material - The material for this panorama
  2595. */
  2596. function Panorama ( geometry, material ) {
  2597. THREE.Mesh.call( this, geometry, material );
  2598. this.type = 'panorama';
  2599. this.ImageQualityLow = 1;
  2600. this.ImageQualityFair = 2;
  2601. this.ImageQualityMedium = 3;
  2602. this.ImageQualityHigh = 4;
  2603. this.ImageQualitySuperHigh = 5;
  2604. this.animationDuration = 1000;
  2605. this.defaultInfospotSize = 350;
  2606. this.container = undefined;
  2607. this.loaded = false;
  2608. this.linkedSpots = [];
  2609. this.isInfospotVisible = false;
  2610. this.linkingImageURL = undefined;
  2611. this.linkingImageScale = undefined;
  2612. this.material.side = THREE.BackSide;
  2613. this.material.opacity = 0;
  2614. this.scale.x *= -1;
  2615. this.renderOrder = -1;
  2616. this.active = false;
  2617. this.infospotAnimation = new Tween.Tween( this ).to( {}, this.animationDuration / 2 );
  2618. this.addEventListener( 'load', this.fadeIn.bind( this ) );
  2619. this.addEventListener( 'panolens-container', this.setContainer.bind( this ) );
  2620. this.addEventListener( 'click', this.onClick.bind( this ) );
  2621. this.setupTransitions();
  2622. }
  2623. Panorama.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
  2624. constructor: Panorama,
  2625. /**
  2626. * Adding an object
  2627. * To counter the scale.x = -1, it will automatically add an
  2628. * empty object with inverted scale on x
  2629. * @memberOf Panorama
  2630. * @instance
  2631. * @param {THREE.Object3D} object - The object to be added
  2632. */
  2633. add: function ( object ) {
  2634. let invertedObject;
  2635. if ( arguments.length > 1 ) {
  2636. for ( var i = 0; i < arguments.length; i ++ ) {
  2637. this.add( arguments[ i ] );
  2638. }
  2639. return this;
  2640. }
  2641. // In case of infospots
  2642. if ( object instanceof Infospot ) {
  2643. invertedObject = object;
  2644. if ( object.dispatchEvent ) {
  2645. const { container } = this;
  2646. if ( container ) { object.dispatchEvent( { type: 'panolens-container', container } ); }
  2647. object.dispatchEvent( { type: 'panolens-infospot-focus', method: function ( vector, duration, easing ) {
  2648. /**
  2649. * Infospot focus handler event
  2650. * @type {object}
  2651. * @event Panorama#panolens-viewer-handler
  2652. * @property {string} method - Viewer function name
  2653. * @property {*} data - The argument to be passed into the method
  2654. */
  2655. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'tweenControlCenter', data: [ vector, duration, easing ] } );
  2656. }.bind( this ) } );
  2657. }
  2658. } else {
  2659. // Counter scale.x = -1 effect
  2660. invertedObject = new THREE.Object3D();
  2661. invertedObject.scale.x = -1;
  2662. invertedObject.scalePlaceHolder = true;
  2663. invertedObject.add( object );
  2664. }
  2665. THREE.Object3D.prototype.add.call( this, invertedObject );
  2666. },
  2667. load: function () {
  2668. this.onLoad();
  2669. },
  2670. /**
  2671. * Click event handler
  2672. * @param {object} event - Click event
  2673. * @memberOf Panorama
  2674. * @instance
  2675. * @fires Infospot#dismiss
  2676. */
  2677. onClick: function ( event ) {
  2678. if ( event.intersects && event.intersects.length === 0 ) {
  2679. this.traverse( function ( object ) {
  2680. /**
  2681. * Dimiss event
  2682. * @type {object}
  2683. * @event Infospot#dismiss
  2684. */
  2685. object.dispatchEvent( { type: 'dismiss' } );
  2686. } );
  2687. }
  2688. },
  2689. /**
  2690. * Set container of this panorama
  2691. * @param {HTMLElement|object} data - Data with container information
  2692. * @memberOf Panorama
  2693. * @instance
  2694. * @fires Infospot#panolens-container
  2695. */
  2696. setContainer: function ( data ) {
  2697. let container;
  2698. if ( data instanceof HTMLElement ) {
  2699. container = data;
  2700. } else if ( data && data.container ) {
  2701. container = data.container;
  2702. }
  2703. if ( container ) {
  2704. this.children.forEach( function ( child ) {
  2705. if ( child instanceof Infospot && child.dispatchEvent ) {
  2706. /**
  2707. * Set container event
  2708. * @type {object}
  2709. * @event Infospot#panolens-container
  2710. * @property {HTMLElement} container - The container of this panorama
  2711. */
  2712. child.dispatchEvent( { type: 'panolens-container', container: container } );
  2713. }
  2714. } );
  2715. this.container = container;
  2716. }
  2717. },
  2718. /**
  2719. * This will be called when panorama is loaded
  2720. * @memberOf Panorama
  2721. * @instance
  2722. * @fires Panorama#load
  2723. */
  2724. onLoad: function () {
  2725. this.loaded = true;
  2726. /**
  2727. * Load panorama event
  2728. * @type {object}
  2729. * @event Panorama#load
  2730. */
  2731. this.dispatchEvent( { type: 'load' } );
  2732. },
  2733. /**
  2734. * This will be called when panorama is in progress
  2735. * @memberOf Panorama
  2736. * @instance
  2737. * @fires Panorama#progress
  2738. */
  2739. onProgress: function ( progress ) {
  2740. /**
  2741. * Loading panorama progress event
  2742. * @type {object}
  2743. * @event Panorama#progress
  2744. * @property {object} progress - The progress object containing loaded and total amount
  2745. */
  2746. this.dispatchEvent( { type: 'progress', progress: progress } );
  2747. },
  2748. /**
  2749. * This will be called when panorama loading has error
  2750. * @memberOf Panorama
  2751. * @instance
  2752. * @fires Panorama#error
  2753. */
  2754. onError: function () {
  2755. /**
  2756. * Loading panorama error event
  2757. * @type {object}
  2758. * @event Panorama#error
  2759. */
  2760. this.dispatchEvent( { type: 'error' } );
  2761. },
  2762. /**
  2763. * Get zoom level based on window width
  2764. * @memberOf Panorama
  2765. * @instance
  2766. * @return {number} zoom level indicating image quality
  2767. */
  2768. getZoomLevel: function () {
  2769. let zoomLevel;
  2770. if ( window.innerWidth <= 800 ) {
  2771. zoomLevel = this.ImageQualityFair;
  2772. } else if ( window.innerWidth > 800 && window.innerWidth <= 1280 ) {
  2773. zoomLevel = this.ImageQualityMedium;
  2774. } else if ( window.innerWidth > 1280 && window.innerWidth <= 1920 ) {
  2775. zoomLevel = this.ImageQualityHigh;
  2776. } else if ( window.innerWidth > 1920 ) {
  2777. zoomLevel = this.ImageQualitySuperHigh;
  2778. } else {
  2779. zoomLevel = this.ImageQualityLow;
  2780. }
  2781. return zoomLevel;
  2782. },
  2783. /**
  2784. * Update texture of a panorama
  2785. * @memberOf Panorama
  2786. * @instance
  2787. * @param {THREE.Texture} texture - Texture to be updated
  2788. */
  2789. updateTexture: function ( texture ) {
  2790. this.material.map = texture;
  2791. this.material.needsUpdate = true;
  2792. },
  2793. /**
  2794. * Toggle visibility of infospots in this panorama
  2795. * @param {boolean} isVisible - Visibility of infospots
  2796. * @param {number} delay - Delay in milliseconds to change visibility
  2797. * @memberOf Panorama
  2798. * @instance
  2799. * @fires Panorama#infospot-animation-complete
  2800. */
  2801. toggleInfospotVisibility: function ( isVisible, delay ) {
  2802. delay = ( delay !== undefined ) ? delay : 0;
  2803. const visible = ( isVisible !== undefined ) ? isVisible : ( this.isInfospotVisible ? false : true );
  2804. this.traverse( function ( object ) {
  2805. if ( object instanceof Infospot ) {
  2806. if ( visible ) {
  2807. object.show( delay );
  2808. } else {
  2809. object.hide( delay );
  2810. }
  2811. }
  2812. } );
  2813. this.isInfospotVisible = visible;
  2814. // Animation complete event
  2815. this.infospotAnimation.onComplete( function () {
  2816. /**
  2817. * Complete toggling infospot visibility
  2818. * @event Panorama#infospot-animation-complete
  2819. * @type {object}
  2820. */
  2821. this.dispatchEvent( { type: 'infospot-animation-complete', visible: visible } );
  2822. }.bind( this ) ).delay( delay ).start();
  2823. },
  2824. /**
  2825. * Set image of this panorama's linking infospot
  2826. * @memberOf Panorama
  2827. * @instance
  2828. * @param {string} url - Url to the image asset
  2829. * @param {number} scale - Scale factor of the infospot
  2830. */
  2831. setLinkingImage: function ( url, scale ) {
  2832. this.linkingImageURL = url;
  2833. this.linkingImageScale = scale;
  2834. },
  2835. /**
  2836. * Link one-way panorama
  2837. * @param {Panorama} pano - The panorama to be linked to
  2838. * @param {THREE.Vector3} position - The position of infospot which navigates to the pano
  2839. * @param {number} [imageScale=300] - Image scale of linked infospot
  2840. * @param {string} [imageSrc=DataImage.Arrow] - The image source of linked infospot
  2841. * @memberOf Panorama
  2842. * @instance
  2843. */
  2844. link: function ( pano, position, imageScale, imageSrc ) {
  2845. let scale, img;
  2846. this.visible = true;
  2847. if ( !position ) {
  2848. console.warn( 'Please specify infospot position for linking' );
  2849. return;
  2850. }
  2851. // Infospot scale
  2852. if ( imageScale !== undefined ) {
  2853. scale = imageScale;
  2854. } else if ( pano.linkingImageScale !== undefined ) {
  2855. scale = pano.linkingImageScale;
  2856. } else {
  2857. scale = 300;
  2858. }
  2859. // Infospot image
  2860. if ( imageSrc ) {
  2861. img = imageSrc;
  2862. } else if ( pano.linkingImageURL ) {
  2863. img = pano.linkingImageURL;
  2864. } else {
  2865. img = DataImage.Arrow;
  2866. }
  2867. // Creates a new infospot
  2868. const spot = new Infospot( scale, img );
  2869. spot.position.copy( position );
  2870. spot.toPanorama = pano;
  2871. spot.addEventListener( 'click', function () {
  2872. /**
  2873. * Viewer handler event
  2874. * @type {object}
  2875. * @event Panorama#panolens-viewer-handler
  2876. * @property {string} method - Viewer function name
  2877. * @property {*} data - The argument to be passed into the method
  2878. */
  2879. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'setPanorama', data: pano } );
  2880. }.bind( this ) );
  2881. this.linkedSpots.push( spot );
  2882. this.add( spot );
  2883. this.visible = false;
  2884. },
  2885. reset: function () {
  2886. this.children.length = 0;
  2887. },
  2888. setupTransitions: function () {
  2889. this.fadeInAnimation = new Tween.Tween( this.material )
  2890. .easing( Tween.Easing.Quartic.Out )
  2891. .onStart( function () {
  2892. this.visible = true;
  2893. // this.material.visible = true;
  2894. /**
  2895. * Enter panorama fade in start event
  2896. * @event Panorama#enter-fade-start
  2897. * @type {object}
  2898. */
  2899. this.dispatchEvent( { type: 'enter-fade-start' } );
  2900. }.bind( this ) );
  2901. this.fadeOutAnimation = new Tween.Tween( this.material )
  2902. .easing( Tween.Easing.Quartic.Out )
  2903. .onComplete( function () {
  2904. this.visible = false;
  2905. // this.material.visible = true;
  2906. /**
  2907. * Leave panorama complete event
  2908. * @event Panorama#leave-complete
  2909. * @type {object}
  2910. */
  2911. this.dispatchEvent( { type: 'leave-complete' } );
  2912. }.bind( this ) );
  2913. this.enterTransition = new Tween.Tween( this )
  2914. .easing( Tween.Easing.Quartic.Out )
  2915. .onComplete( function () {
  2916. /**
  2917. * Enter panorama and animation complete event
  2918. * @event Panorama#enter-complete
  2919. * @type {object}
  2920. */
  2921. this.dispatchEvent( { type: 'enter-complete' } );
  2922. }.bind ( this ) )
  2923. .start();
  2924. this.leaveTransition = new Tween.Tween( this )
  2925. .easing( Tween.Easing.Quartic.Out );
  2926. },
  2927. onFadeAnimationUpdate: function () {
  2928. const alpha = this.material.opacity;
  2929. const { uniforms } = this.material;
  2930. if ( uniforms && uniforms.opacity ) {
  2931. uniforms.opacity.value = alpha;
  2932. }
  2933. },
  2934. /**
  2935. * Start fading in animation
  2936. * @memberOf Panorama
  2937. * @instance
  2938. * @fires Panorama#enter-fade-complete
  2939. */
  2940. fadeIn: function ( duration ) {
  2941. duration = duration >= 0 ? duration : this.animationDuration;
  2942. this.fadeOutAnimation.stop();
  2943. this.fadeInAnimation
  2944. .to( { opacity: 1 }, duration )
  2945. .onUpdate( this.onFadeAnimationUpdate.bind( this ) )
  2946. .onComplete( function () {
  2947. this.toggleInfospotVisibility( true, duration / 2 );
  2948. /**
  2949. * Enter panorama fade complete event
  2950. * @event Panorama#enter-fade-complete
  2951. * @type {object}
  2952. */
  2953. this.dispatchEvent( { type: 'enter-fade-complete' } );
  2954. }.bind( this ) )
  2955. .start();
  2956. },
  2957. /**
  2958. * Start fading out animation
  2959. * @memberOf Panorama
  2960. * @instance
  2961. */
  2962. fadeOut: function ( duration ) {
  2963. duration = duration >= 0 ? duration : this.animationDuration;
  2964. this.fadeInAnimation.stop();
  2965. this.fadeOutAnimation
  2966. .to( { opacity: 0 }, duration )
  2967. .onUpdate( this.onFadeAnimationUpdate.bind( this ) )
  2968. .start();
  2969. },
  2970. /**
  2971. * This will be called when entering a panorama
  2972. * @memberOf Panorama
  2973. * @instance
  2974. * @fires Panorama#enter
  2975. * @fires Panorama#enter-start
  2976. */
  2977. onEnter: function () {
  2978. const duration = this.animationDuration;
  2979. this.leaveTransition.stop();
  2980. this.enterTransition
  2981. .to( {}, duration )
  2982. .onStart( function () {
  2983. /**
  2984. * Enter panorama and animation starting event
  2985. * @event Panorama#enter-start
  2986. * @type {object}
  2987. */
  2988. this.dispatchEvent( { type: 'enter-start' } );
  2989. if ( this.loaded ) {
  2990. this.fadeIn( duration );
  2991. } else {
  2992. this.load();
  2993. }
  2994. }.bind( this ) )
  2995. .start();
  2996. /**
  2997. * Enter panorama event
  2998. * @event Panorama#enter
  2999. * @type {object}
  3000. */
  3001. this.dispatchEvent( { type: 'enter' } );
  3002. this.children.forEach( child => {
  3003. child.dispatchEvent( { type: 'panorama-enter' } );
  3004. } );
  3005. this.active = true;
  3006. },
  3007. /**
  3008. * This will be called when leaving a panorama
  3009. * @memberOf Panorama
  3010. * @instance
  3011. * @fires Panorama#leave
  3012. */
  3013. onLeave: function () {
  3014. const duration = this.animationDuration;
  3015. this.enterTransition.stop();
  3016. this.leaveTransition
  3017. .to( {}, duration )
  3018. .onStart( function () {
  3019. /**
  3020. * Leave panorama and animation starting event
  3021. * @event Panorama#leave-start
  3022. * @type {object}
  3023. */
  3024. this.dispatchEvent( { type: 'leave-start' } );
  3025. this.fadeOut( duration );
  3026. this.toggleInfospotVisibility( false );
  3027. }.bind( this ) )
  3028. .start();
  3029. /**
  3030. * Leave panorama event
  3031. * @event Panorama#leave
  3032. * @type {object}
  3033. */
  3034. this.dispatchEvent( { type: 'leave' } );
  3035. this.children.forEach( child => {
  3036. child.dispatchEvent( { type: 'panorama-leave' } );
  3037. } );
  3038. this.active = false;
  3039. },
  3040. /**
  3041. * Dispose panorama
  3042. * @memberOf Panorama
  3043. * @instance
  3044. */
  3045. dispose: function () {
  3046. this.infospotAnimation.stop();
  3047. this.fadeInAnimation.stop();
  3048. this.fadeOutAnimation.stop();
  3049. this.enterTransition.stop();
  3050. this.leaveTransition.stop();
  3051. /**
  3052. * On panorama dispose handler
  3053. * @type {object}
  3054. * @event Panorama#panolens-viewer-handler
  3055. * @property {string} method - Viewer function name
  3056. * @property {*} data - The argument to be passed into the method
  3057. */
  3058. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'onPanoramaDispose', data: this } );
  3059. // recursive disposal on 3d objects
  3060. function recursiveDispose ( object ) {
  3061. const { geometry, material } = object;
  3062. for ( var i = object.children.length - 1; i >= 0; i-- ) {
  3063. recursiveDispose( object.children[i] );
  3064. object.remove( object.children[i] );
  3065. }
  3066. if ( object instanceof Infospot ) {
  3067. object.dispose();
  3068. }
  3069. if ( geometry ) { geometry.dispose(); object.geometry = null; }
  3070. if ( material ) { material.dispose(); object.material = null; }
  3071. }
  3072. recursiveDispose( this );
  3073. if ( this.parent ) {
  3074. this.parent.remove( this );
  3075. }
  3076. }
  3077. } );
  3078. /**
  3079. * @classdesc Equirectangular based image panorama
  3080. * @constructor
  3081. * @param {string} image - Image url or HTMLImageElement
  3082. */
  3083. function ImagePanorama ( image, _geometry, _material ) {
  3084. const radius = 5000;
  3085. const geometry = _geometry || new THREE.SphereBufferGeometry( radius, 60, 40 );
  3086. const material = _material || new THREE.MeshBasicMaterial( { opacity: 0, transparent: true } );
  3087. Panorama.call( this, geometry, material );
  3088. this.src = image;
  3089. this.radius = radius;
  3090. }
  3091. ImagePanorama.prototype = Object.assign( Object.create( Panorama.prototype ), {
  3092. constructor: ImagePanorama,
  3093. /**
  3094. * Load image asset
  3095. * @param {*} src - Url or image element
  3096. * @memberOf ImagePanorama
  3097. * @instance
  3098. */
  3099. load: function ( src ) {
  3100. src = src || this.src;
  3101. if ( !src ) {
  3102. console.warn( 'Image source undefined' );
  3103. return;
  3104. } else if ( typeof src === 'string' ) {
  3105. TextureLoader.load( src, this.onLoad.bind( this ), this.onProgress.bind( this ), this.onError.bind( this ) );
  3106. } else if ( src instanceof HTMLImageElement ) {
  3107. this.onLoad( new THREE.Texture( src ) );
  3108. }
  3109. },
  3110. /**
  3111. * This will be called when image is loaded
  3112. * @param {THREE.Texture} texture - Texture to be updated
  3113. * @memberOf ImagePanorama
  3114. * @instance
  3115. */
  3116. onLoad: function ( texture ) {
  3117. texture.minFilter = texture.magFilter = THREE.LinearFilter;
  3118. texture.needsUpdate = true;
  3119. this.updateTexture( texture );
  3120. window.requestAnimationFrame( Panorama.prototype.onLoad.bind( this ) );
  3121. },
  3122. /**
  3123. * Reset
  3124. * @memberOf ImagePanorama
  3125. * @instance
  3126. */
  3127. reset: function () {
  3128. Panorama.prototype.reset.call( this );
  3129. },
  3130. /**
  3131. * Dispose
  3132. * @memberOf ImagePanorama
  3133. * @instance
  3134. */
  3135. dispose: function () {
  3136. const { material: { map } } = this;
  3137. // Release cached image
  3138. THREE.Cache.remove( this.src );
  3139. if ( map ) { map.dispose(); }
  3140. Panorama.prototype.dispose.call( this );
  3141. }
  3142. } );
  3143. /**
  3144. * @classdesc Empty panorama
  3145. * @constructor
  3146. */
  3147. function EmptyPanorama () {
  3148. const geometry = new THREE.BufferGeometry();
  3149. const material = new THREE.MeshBasicMaterial( { color: 0x000000, opacity: 0, transparent: true } );
  3150. geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array(), 1 ) );
  3151. Panorama.call( this, geometry, material );
  3152. }
  3153. EmptyPanorama.prototype = Object.assign( Object.create( Panorama.prototype ), {
  3154. constructor: EmptyPanorama
  3155. } );
  3156. /**
  3157. * @classdesc Cubemap-based panorama
  3158. * @constructor
  3159. * @param {array} images - Array of 6 urls to images, one for each side of the CubeTexture. The urls should be specified in the following order: pos-x, neg-x, pos-y, neg-y, pos-z, neg-z
  3160. */
  3161. function CubePanorama ( images = [] ){
  3162. const edgeLength = 10000;
  3163. const shader = Object.assign( {}, THREE.ShaderLib[ 'cube' ] );
  3164. const geometry = new THREE.BoxBufferGeometry( edgeLength, edgeLength, edgeLength );
  3165. const material = new THREE.ShaderMaterial( {
  3166. fragmentShader: shader.fragmentShader,
  3167. vertexShader: shader.vertexShader,
  3168. uniforms: shader.uniforms,
  3169. side: THREE.BackSide,
  3170. transparent: true
  3171. } );
  3172. Panorama.call( this, geometry, material );
  3173. this.images = images;
  3174. this.edgeLength = edgeLength;
  3175. this.material.uniforms.opacity.value = 0;
  3176. }
  3177. CubePanorama.prototype = Object.assign( Object.create( Panorama.prototype ), {
  3178. constructor: CubePanorama,
  3179. /**
  3180. * Load 6 images and bind listeners
  3181. * @memberOf CubePanorama
  3182. * @instance
  3183. */
  3184. load: function () {
  3185. CubeTextureLoader.load(
  3186. this.images,
  3187. this.onLoad.bind( this ),
  3188. this.onProgress.bind( this ),
  3189. this.onError.bind( this )
  3190. );
  3191. },
  3192. /**
  3193. * This will be called when 6 textures are ready
  3194. * @param {THREE.CubeTexture} texture - Cube texture
  3195. * @memberOf CubePanorama
  3196. * @instance
  3197. */
  3198. onLoad: function ( texture ) {
  3199. this.material.uniforms[ 'tCube' ].value = texture;
  3200. Panorama.prototype.onLoad.call( this );
  3201. },
  3202. /**
  3203. * Dispose
  3204. * @memberOf CubePanorama
  3205. * @instance
  3206. */
  3207. dispose: function () {
  3208. const { value } = this.material.uniforms.tCube;
  3209. this.images.forEach( ( image ) => { THREE.Cache.remove( image ); } );
  3210. if ( value instanceof THREE.CubeTexture ) {
  3211. value.dispose();
  3212. }
  3213. Panorama.prototype.dispose.call( this );
  3214. }
  3215. } );
  3216. /**
  3217. * @classdesc Basic panorama with 6 pre-defined grid images
  3218. * @constructor
  3219. */
  3220. function BasicPanorama () {
  3221. const images = [];
  3222. for ( let i = 0; i < 6; i++ ) {
  3223. images.push( DataImage.WhiteTile );
  3224. }
  3225. CubePanorama.call( this, images );
  3226. }
  3227. BasicPanorama.prototype = Object.assign( Object.create( CubePanorama.prototype ), {
  3228. constructor: BasicPanorama
  3229. } );
  3230. /**
  3231. * @classdesc Video Panorama
  3232. * @constructor
  3233. * @param {string} src - Equirectangular video url
  3234. * @param {object} [options] - Option for video settings
  3235. * @param {HTMLElement} [options.videoElement] - HTML5 video element contains the video
  3236. * @param {boolean} [options.loop=true] - Specify if the video should loop in the end
  3237. * @param {boolean} [options.muted=true] - Mute the video or not. Need to be true in order to autoplay on some browsers
  3238. * @param {boolean} [options.autoplay=false] - Specify if the video should auto play
  3239. * @param {boolean} [options.playsinline=true] - Specify if video should play inline for iOS. If you want it to auto play inline, set both autoplay and muted options to true
  3240. * @param {string} [options.crossOrigin="anonymous"] - Sets the cross-origin attribute for the video, which allows for cross-origin videos in some browsers (Firefox, Chrome). Set to either "anonymous" or "use-credentials".
  3241. * @param {number} [radius=5000] - The minimum radius for this panoram
  3242. */
  3243. function VideoPanorama ( src, options = {} ) {
  3244. const radius = 5000;
  3245. const geometry = new THREE.SphereBufferGeometry( radius, 60, 40 );
  3246. const material = new THREE.MeshBasicMaterial( { opacity: 0, transparent: true } );
  3247. Panorama.call( this, geometry, material );
  3248. this.src = src;
  3249. this.options = {
  3250. videoElement: document.createElement( 'video' ),
  3251. loop: true,
  3252. muted: true,
  3253. autoplay: false,
  3254. playsinline: true,
  3255. crossOrigin: 'anonymous'
  3256. };
  3257. Object.assign( this.options, options );
  3258. this.videoElement = this.options.videoElement;
  3259. this.videoProgress = 0;
  3260. this.radius = radius;
  3261. this.addEventListener( 'leave', this.pauseVideo.bind( this ) );
  3262. this.addEventListener( 'enter-fade-start', this.resumeVideoProgress.bind( this ) );
  3263. this.addEventListener( 'video-toggle', this.toggleVideo.bind( this ) );
  3264. this.addEventListener( 'video-time', this.setVideoCurrentTime.bind( this ) );
  3265. }
  3266. VideoPanorama.prototype = Object.assign( Object.create( Panorama.prototype ), {
  3267. constructor: VideoPanorama,
  3268. isMobile: function () {
  3269. let check = false;
  3270. (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})( window.navigator.userAgent || window.navigator.vendor || window.opera );
  3271. return check;
  3272. },
  3273. /**
  3274. * Load video panorama
  3275. * @memberOf VideoPanorama
  3276. * @instance
  3277. * @fires Panorama#panolens-viewer-handler
  3278. */
  3279. load: function () {
  3280. const { muted, loop, autoplay, playsinline, crossOrigin } = this.options;
  3281. const video = this.videoElement;
  3282. const material = this.material;
  3283. const onProgress = this.onProgress.bind( this );
  3284. const onLoad = this.onLoad.bind( this );
  3285. video.loop = loop;
  3286. video.autoplay = autoplay;
  3287. video.playsinline = playsinline;
  3288. video.crossOrigin = crossOrigin;
  3289. video.muted = muted;
  3290. if ( playsinline ) {
  3291. video.setAttribute( 'playsinline', '' );
  3292. video.setAttribute( 'webkit-playsinline', '' );
  3293. }
  3294. const onloadeddata = function() {
  3295. this.setVideoTexture( video );
  3296. if ( autoplay ) {
  3297. /**
  3298. * Viewer handler event
  3299. * @type {object}
  3300. * @property {string} method - 'updateVideoPlayButton'
  3301. * @property {boolean} data - Pause video or not
  3302. */
  3303. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'updateVideoPlayButton', data: false } );
  3304. }
  3305. // For mobile silent autoplay
  3306. if ( this.isMobile() ) {
  3307. video.pause();
  3308. if ( autoplay && muted ) {
  3309. /**
  3310. * Viewer handler event
  3311. * @type {object}
  3312. * @property {string} method - 'updateVideoPlayButton'
  3313. * @property {boolean} data - Pause video or not
  3314. */
  3315. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'updateVideoPlayButton', data: false } );
  3316. } else {
  3317. /**
  3318. * Viewer handler event
  3319. * @type {object}
  3320. * @property {string} method - 'updateVideoPlayButton'
  3321. * @property {boolean} data - Pause video or not
  3322. */
  3323. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'updateVideoPlayButton', data: true } );
  3324. }
  3325. }
  3326. const loaded = () => {
  3327. // Fix for threejs r89 delayed update
  3328. material.map.needsUpdate = true;
  3329. onProgress( { loaded: 1, total: 1 } );
  3330. onLoad();
  3331. };
  3332. window.requestAnimationFrame( loaded );
  3333. };
  3334. /**
  3335. * Ready state of the audio/video element
  3336. * 0 = HAVE_NOTHING - no information whether or not the audio/video is ready
  3337. * 1 = HAVE_METADATA - metadata for the audio/video is ready
  3338. * 2 = HAVE_CURRENT_DATA - data for the current playback position is available, but not enough data to play next frame/millisecond
  3339. * 3 = HAVE_FUTURE_DATA - data for the current and at least the next frame is available
  3340. * 4 = HAVE_ENOUGH_DATA - enough data available to start playing
  3341. */
  3342. if ( video.readyState > 2 ) {
  3343. onloadeddata.call( this );
  3344. } else {
  3345. if ( video.querySelectorAll( 'source' ).length === 0 ) {
  3346. const source = document.createElement( 'source' );
  3347. source.src = this.src;
  3348. video.appendChild( source );
  3349. }
  3350. video.load();
  3351. }
  3352. video.addEventListener( 'loadeddata', onloadeddata.bind( this ) );
  3353. video.addEventListener( 'timeupdate', function () {
  3354. this.videoProgress = video.duration >= 0 ? video.currentTime / video.duration : 0;
  3355. /**
  3356. * Viewer handler event
  3357. * @type {object}
  3358. * @property {string} method - 'onVideoUpdate'
  3359. * @property {number} data - The percentage of video progress. Range from 0.0 to 1.0
  3360. */
  3361. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'onVideoUpdate', data: this.videoProgress } );
  3362. }.bind( this ) );
  3363. video.addEventListener( 'ended', function () {
  3364. if ( !loop ) {
  3365. this.resetVideo();
  3366. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'updateVideoPlayButton', data: true } );
  3367. }
  3368. }.bind( this ), false );
  3369. },
  3370. /**
  3371. * Set video texture
  3372. * @memberOf VideoPanorama
  3373. * @instance
  3374. * @param {HTMLVideoElement} video - The html5 video element
  3375. * @fires Panorama#panolens-viewer-handler
  3376. */
  3377. setVideoTexture: function ( video ) {
  3378. if ( !video ) return;
  3379. const videoTexture = new THREE.VideoTexture( video );
  3380. videoTexture.minFilter = THREE.LinearFilter;
  3381. videoTexture.magFilter = THREE.LinearFilter;
  3382. videoTexture.format = THREE.RGBFormat;
  3383. this.updateTexture( videoTexture );
  3384. },
  3385. /**
  3386. * Reset
  3387. * @memberOf VideoPanorama
  3388. * @instance
  3389. */
  3390. reset: function () {
  3391. this.videoElement = undefined;
  3392. Panorama.prototype.reset.call( this );
  3393. },
  3394. /**
  3395. * Check if video is paused
  3396. * @memberOf VideoPanorama
  3397. * @instance
  3398. * @return {boolean} - is video paused or not
  3399. */
  3400. isVideoPaused: function () {
  3401. return this.videoElement.paused;
  3402. },
  3403. /**
  3404. * Toggle video to play or pause
  3405. * @memberOf VideoPanorama
  3406. * @instance
  3407. */
  3408. toggleVideo: function () {
  3409. const video = this.videoElement;
  3410. if ( !video ) { return; }
  3411. video[ video.paused ? 'play' : 'pause' ]();
  3412. },
  3413. /**
  3414. * Set video currentTime
  3415. * @memberOf VideoPanorama
  3416. * @instance
  3417. * @param {object} event - Event contains percentage. Range from 0.0 to 1.0
  3418. */
  3419. setVideoCurrentTime: function ( { percentage } ) {
  3420. const video = this.videoElement;
  3421. if ( video && !Number.isNaN( percentage ) && percentage !== 1 ) {
  3422. video.currentTime = video.duration * percentage;
  3423. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'onVideoUpdate', data: percentage } );
  3424. }
  3425. },
  3426. /**
  3427. * Play video
  3428. * @memberOf VideoPanorama
  3429. * @instance
  3430. * @fires VideoPanorama#play
  3431. * @fires VideoPanorama#play-error
  3432. */
  3433. playVideo: function () {
  3434. const video = this.videoElement;
  3435. const playVideo = this.playVideo.bind( this );
  3436. const dispatchEvent = this.dispatchEvent.bind( this );
  3437. const onSuccess = () => {
  3438. /**
  3439. * Play event
  3440. * @type {object}
  3441. * @event VideoPanorama#play
  3442. *
  3443. */
  3444. dispatchEvent( { type: 'play' } );
  3445. };
  3446. const onError = ( error ) => {
  3447. // Error playing video. Retry next frame. Possibly Waiting for user interaction
  3448. window.requestAnimationFrame( playVideo );
  3449. /**
  3450. * Play event
  3451. * @type {object}
  3452. * @event VideoPanorama#play-error
  3453. *
  3454. */
  3455. dispatchEvent( { type: 'play-error', error } );
  3456. };
  3457. if ( video && video.paused ) {
  3458. video.play().then( onSuccess ).catch( onError );
  3459. }
  3460. },
  3461. /**
  3462. * Pause video
  3463. * @memberOf VideoPanorama
  3464. * @instance
  3465. * @fires VideoPanorama#pause
  3466. */
  3467. pauseVideo: function () {
  3468. const video = this.videoElement;
  3469. if ( video && !video.paused ) {
  3470. video.pause();
  3471. }
  3472. /**
  3473. * Pause event
  3474. * @type {object}
  3475. * @event VideoPanorama#pause
  3476. *
  3477. */
  3478. this.dispatchEvent( { type: 'pause' } );
  3479. },
  3480. /**
  3481. * Resume video
  3482. * @memberOf VideoPanorama
  3483. * @instance
  3484. */
  3485. resumeVideoProgress: function () {
  3486. const video = this.videoElement;
  3487. if ( video.readyState >= 4 && video.autoplay && !this.isMobile() ) {
  3488. this.playVideo();
  3489. /**
  3490. * Viewer handler event
  3491. * @type {object}
  3492. * @property {string} method - 'updateVideoPlayButton'
  3493. * @property {boolean} data - Pause video or not
  3494. */
  3495. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'updateVideoPlayButton', data: false } );
  3496. } else {
  3497. this.pauseVideo();
  3498. /**
  3499. * Viewer handler event
  3500. * @type {object}
  3501. * @property {string} method - 'updateVideoPlayButton'
  3502. * @property {boolean} data - Pause video or not
  3503. */
  3504. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'updateVideoPlayButton', data: true } );
  3505. }
  3506. this.setVideoCurrentTime( { percentage: this.videoProgress } );
  3507. },
  3508. /**
  3509. * Reset video at stating point
  3510. * @memberOf VideoPanorama
  3511. * @instance
  3512. */
  3513. resetVideo: function () {
  3514. const video = this.videoElement;
  3515. if ( video ) {
  3516. this.setVideoCurrentTime( { percentage: 0 } );
  3517. }
  3518. },
  3519. /**
  3520. * Check if video is muted
  3521. * @memberOf VideoPanorama
  3522. * @instance
  3523. * @return {boolean} - is video muted or not
  3524. */
  3525. isVideoMuted: function () {
  3526. return this.videoElement.muted;
  3527. },
  3528. /**
  3529. * Mute video
  3530. * @memberOf VideoPanorama
  3531. * @instance
  3532. */
  3533. muteVideo: function () {
  3534. const video = this.videoElement;
  3535. if ( video && !video.muted ) {
  3536. video.muted = true;
  3537. }
  3538. this.dispatchEvent( { type: 'volumechange' } );
  3539. },
  3540. /**
  3541. * Unmute video
  3542. * @memberOf VideoPanorama
  3543. * @instance
  3544. */
  3545. unmuteVideo: function () {
  3546. const video = this.videoElement;
  3547. if ( video && this.isVideoMuted() ) {
  3548. video.muted = false;
  3549. }
  3550. this.dispatchEvent( { type: 'volumechange' } );
  3551. },
  3552. /**
  3553. * Returns the video element
  3554. * @memberOf VideoPanorama
  3555. * @instance
  3556. * @returns {HTMLElement}
  3557. */
  3558. getVideoElement: function () {
  3559. return this.videoElement;
  3560. },
  3561. /**
  3562. * Dispose video panorama
  3563. * @memberOf VideoPanorama
  3564. * @instance
  3565. */
  3566. dispose: function () {
  3567. const { material: { map } } = this;
  3568. this.pauseVideo();
  3569. this.removeEventListener( 'leave', this.pauseVideo.bind( this ) );
  3570. this.removeEventListener( 'enter-fade-start', this.resumeVideoProgress.bind( this ) );
  3571. this.removeEventListener( 'video-toggle', this.toggleVideo.bind( this ) );
  3572. this.removeEventListener( 'video-time', this.setVideoCurrentTime.bind( this ) );
  3573. if ( map ) { map.dispose(); }
  3574. Panorama.prototype.dispose.call( this );
  3575. }
  3576. } );
  3577. /**
  3578. * @classdesc Google Street View Loader
  3579. * @constructor
  3580. * @param {object} parameters
  3581. */
  3582. function GoogleStreetviewLoader ( parameters = {} ) {
  3583. this._parameters = parameters;
  3584. this._zoom = null;
  3585. this._panoId = null;
  3586. this._panoClient = new google.maps.StreetViewService();
  3587. this._count = 0;
  3588. this._total = 0;
  3589. this._canvas = [];
  3590. this._ctx = [];
  3591. this._wc = 0;
  3592. this._hc = 0;
  3593. this.result = null;
  3594. this.rotation = 0;
  3595. this.copyright = '';
  3596. this.onSizeChange = null;
  3597. this.onPanoramaLoad = null;
  3598. this.levelsW = [ 1, 2, 4, 7, 13, 26 ];
  3599. this.levelsH = [ 1, 1, 2, 4, 7, 13 ];
  3600. this.widths = [ 416, 832, 1664, 3328, 6656, 13312 ];
  3601. this.heights = [ 416, 416, 832, 1664, 3328, 6656 ];
  3602. this.maxW = 6656;
  3603. this.maxH = 6656;
  3604. let gl;
  3605. try {
  3606. const canvas = document.createElement( 'canvas' );
  3607. gl = canvas.getContext( 'experimental-webgl' );
  3608. if( !gl ) {
  3609. gl = canvas.getContext( 'webgl' );
  3610. }
  3611. }
  3612. catch ( error ) {
  3613. }
  3614. this.maxW = Math.max( gl.getParameter( gl.MAX_TEXTURE_SIZE ), this.maxW );
  3615. this.maxH = Math.max( gl.getParameter( gl.MAX_TEXTURE_SIZE ), this.maxH );
  3616. }
  3617. Object.assign( GoogleStreetviewLoader.prototype, {
  3618. constructor: GoogleStreetviewLoader,
  3619. /**
  3620. * Set progress
  3621. * @param {number} loaded
  3622. * @param {number} total
  3623. * @memberOf GoogleStreetviewLoader
  3624. * @instance
  3625. */
  3626. setProgress: function ( loaded, total ) {
  3627. if ( this.onProgress ) {
  3628. this.onProgress( { loaded: loaded, total: total } );
  3629. }
  3630. },
  3631. /**
  3632. * Adapt texture to zoom
  3633. * @memberOf GoogleStreetviewLoader
  3634. * @instance
  3635. */
  3636. adaptTextureToZoom: function () {
  3637. const w = this.widths [ this._zoom ];
  3638. const h = this.heights[ this._zoom ];
  3639. const maxW = this.maxW;
  3640. const maxH = this.maxH;
  3641. this._wc = Math.ceil( w / maxW );
  3642. this._hc = Math.ceil( h / maxH );
  3643. for( let y = 0; y < this._hc; y++ ) {
  3644. for( let x = 0; x < this._wc; x++ ) {
  3645. const c = document.createElement( 'canvas' );
  3646. if( x < ( this._wc - 1 ) ) c.width = maxW; else c.width = w - ( maxW * x );
  3647. if( y < ( this._hc - 1 ) ) c.height = maxH; else c.height = h - ( maxH * y );
  3648. this._canvas.push( c );
  3649. this._ctx.push( c.getContext( '2d' ) );
  3650. }
  3651. }
  3652. },
  3653. /**
  3654. * Compose from tile
  3655. * @param {number} x
  3656. * @param {number} y
  3657. * @param {*} texture
  3658. * @memberOf GoogleStreetviewLoader
  3659. * @instance
  3660. */
  3661. composeFromTile: function ( x, y, texture ) {
  3662. const maxW = this.maxW;
  3663. const maxH = this.maxH;
  3664. x *= 512;
  3665. y *= 512;
  3666. const px = Math.floor( x / maxW );
  3667. const py = Math.floor( y / maxH );
  3668. x -= px * maxW;
  3669. y -= py * maxH;
  3670. this._ctx[ py * this._wc + px ].drawImage( texture, 0, 0, texture.width, texture.height, x, y, 512, 512 );
  3671. this.progress();
  3672. },
  3673. /**
  3674. * Progress
  3675. * @memberOf GoogleStreetviewLoader
  3676. * @instance
  3677. */
  3678. progress: function() {
  3679. this._count++;
  3680. this.setProgress( this._count, this._total );
  3681. if ( this._count === this._total) {
  3682. this.canvas = this._canvas;
  3683. this.panoId = this._panoId;
  3684. this.zoom = this._zoom;
  3685. if ( this.onPanoramaLoad ) {
  3686. this.onPanoramaLoad( this._canvas[ 0 ] );
  3687. }
  3688. }
  3689. },
  3690. /**
  3691. * Compose panorama
  3692. * @memberOf GoogleStreetviewLoader
  3693. * @instance
  3694. */
  3695. composePanorama: function () {
  3696. this.setProgress( 0, 1 );
  3697. const w = this.levelsW[ this._zoom ];
  3698. const h = this.levelsH[ this._zoom ];
  3699. const self = this;
  3700. this._count = 0;
  3701. this._total = w * h;
  3702. const { useWebGL } = this._parameters;
  3703. for( let y = 0; y < h; y++ ) {
  3704. for( let x = 0; x < w; x++ ) {
  3705. const url = 'https://geo0.ggpht.com/cbk?cb_client=maps_sv.tactile&authuser=0&hl=en&output=tile&zoom=' + this._zoom + '&x=' + x + '&y=' + y + '&panoid=' + this._panoId + '&nbt&fover=2';
  3706. ( function( x, y ) {
  3707. if( useWebGL ) {
  3708. const texture = TextureLoader.load( url, null, function() {
  3709. self.composeFromTile( x, y, texture );
  3710. } );
  3711. } else {
  3712. const img = new Image();
  3713. img.addEventListener( 'load', function() {
  3714. self.composeFromTile( x, y, this );
  3715. } );
  3716. img.crossOrigin = '';
  3717. img.src = url;
  3718. }
  3719. } )( x, y );
  3720. }
  3721. }
  3722. },
  3723. /**
  3724. * Load
  3725. * @param {string} panoid
  3726. * @memberOf GoogleStreetviewLoader
  3727. * @instance
  3728. */
  3729. load: function ( panoid ) {
  3730. this.loadPano( panoid );
  3731. },
  3732. /**
  3733. * Load panorama
  3734. * @param {string} id
  3735. * @memberOf GoogleStreetviewLoader
  3736. * @instance
  3737. */
  3738. loadPano: function( id ) {
  3739. const self = this;
  3740. this._panoClient.getPanoramaById( id, function (result, status) {
  3741. if (status === google.maps.StreetViewStatus.OK) {
  3742. self.result = result;
  3743. self.copyright = result.copyright;
  3744. self._panoId = result.location.pano;
  3745. self.composePanorama();
  3746. }
  3747. });
  3748. },
  3749. /**
  3750. * Set zoom level
  3751. * @param {number} z
  3752. * @memberOf GoogleStreetviewLoader
  3753. * @instance
  3754. */
  3755. setZoom: function( z ) {
  3756. this._zoom = z;
  3757. this.adaptTextureToZoom();
  3758. }
  3759. } );
  3760. /**
  3761. * @classdesc Google streetview panorama
  3762. * @description [How to get Panorama ID]{@link http://stackoverflow.com/questions/29916149/google-maps-streetview-how-to-get-panorama-id}
  3763. * @constructor
  3764. * @param {string} panoId - Panorama id from Google Streetview
  3765. * @param {string} [apiKey] - Google Street View API Key
  3766. */
  3767. function GoogleStreetviewPanorama ( panoId, apiKey ) {
  3768. ImagePanorama.call( this );
  3769. this.panoId = panoId;
  3770. this.gsvLoader = null;
  3771. this.loadRequested = false;
  3772. this.setupGoogleMapAPI( apiKey );
  3773. }
  3774. GoogleStreetviewPanorama.prototype = Object.assign( Object.create( ImagePanorama.prototype ), {
  3775. constructor: GoogleStreetviewPanorama,
  3776. /**
  3777. * Load Google Street View by panorama id
  3778. * @param {string} panoId - Gogogle Street View panorama id
  3779. * @memberOf GoogleStreetviewPanorama
  3780. * @instance
  3781. */
  3782. load: function ( panoId ) {
  3783. this.loadRequested = true;
  3784. panoId = ( panoId || this.panoId ) || {};
  3785. if ( panoId && this.gsvLoader ) {
  3786. this.loadGSVLoader( panoId );
  3787. }
  3788. },
  3789. /**
  3790. * Setup Google Map API
  3791. * @param {string} apiKey
  3792. * @memberOf GoogleStreetviewPanorama
  3793. * @instance
  3794. */
  3795. setupGoogleMapAPI: function ( apiKey ) {
  3796. const script = document.createElement( 'script' );
  3797. script.src = 'https://maps.googleapis.com/maps/api/js?';
  3798. script.src += apiKey ? 'key=' + apiKey : '';
  3799. script.onreadystatechange = this.setGSVLoader.bind( this );
  3800. script.onload = this.setGSVLoader.bind( this );
  3801. document.querySelector( 'head' ).appendChild( script );
  3802. },
  3803. /**
  3804. * Set GSV Loader
  3805. * @memberOf GoogleStreetviewPanorama
  3806. * @instance
  3807. */
  3808. setGSVLoader: function () {
  3809. this.gsvLoader = new GoogleStreetviewLoader();
  3810. if ( this.loadRequested ) {
  3811. this.load();
  3812. }
  3813. },
  3814. /**
  3815. * Get GSV Loader
  3816. * @memberOf GoogleStreetviewPanorama
  3817. * @instance
  3818. * @return {GoogleStreetviewLoader} GSV Loader instance
  3819. */
  3820. getGSVLoader: function () {
  3821. return this.gsvLoader;
  3822. },
  3823. /**
  3824. * Load GSV Loader
  3825. * @param {string} panoId - Gogogle Street View panorama id
  3826. * @memberOf GoogleStreetviewPanorama
  3827. * @instance
  3828. */
  3829. loadGSVLoader: function ( panoId ) {
  3830. this.loadRequested = false;
  3831. this.gsvLoader.onProgress = this.onProgress.bind( this );
  3832. this.gsvLoader.onPanoramaLoad = this.onLoad.bind( this );
  3833. this.gsvLoader.setZoom( this.getZoomLevel() );
  3834. this.gsvLoader.load( panoId );
  3835. this.gsvLoader.loaded = true;
  3836. },
  3837. /**
  3838. * This will be called when panorama is loaded
  3839. * @param {HTMLCanvasElement} canvas - Canvas where the tiles have been drawn
  3840. * @memberOf GoogleStreetviewPanorama
  3841. * @instance
  3842. */
  3843. onLoad: function ( canvas ) {
  3844. ImagePanorama.prototype.onLoad.call( this, new THREE.Texture( canvas ) );
  3845. },
  3846. /**
  3847. * Reset
  3848. * @memberOf GoogleStreetviewPanorama
  3849. * @instance
  3850. */
  3851. reset: function () {
  3852. this.gsvLoader = undefined;
  3853. ImagePanorama.prototype.reset.call( this );
  3854. }
  3855. } );
  3856. /**
  3857. * Stereographic projection shader
  3858. * based on http://notlion.github.io/streetview-stereographic
  3859. * @author pchen66
  3860. */
  3861. /**
  3862. * @description Stereograhpic Shader
  3863. * @module StereographicShader
  3864. * @property {object} uniforms
  3865. * @property {THREE.Texture} uniforms.tDiffuse diffuse map
  3866. * @property {number} uniforms.resolution image resolution
  3867. * @property {THREE.Matrix4} uniforms.transform transformation matrix
  3868. * @property {number} uniforms.zoom image zoom factor
  3869. * @property {number} uniforms.opacity image opacity
  3870. * @property {string} vertexShader vertex shader
  3871. * @property {string} fragmentShader fragment shader
  3872. */
  3873. const StereographicShader = {
  3874. uniforms: {
  3875. 'tDiffuse': { value: new THREE.Texture() },
  3876. 'resolution': { value: 1.0 },
  3877. 'transform': { value: new THREE.Matrix4() },
  3878. 'zoom': { value: 1.0 },
  3879. 'opacity': { value: 1.0 }
  3880. },
  3881. vertexShader: [
  3882. 'varying vec2 vUv;',
  3883. 'void main() {',
  3884. 'vUv = uv;',
  3885. 'gl_Position = vec4( position, 1.0 );',
  3886. '}'
  3887. ].join( '\n' ),
  3888. fragmentShader: [
  3889. 'uniform sampler2D tDiffuse;',
  3890. 'uniform float resolution;',
  3891. 'uniform mat4 transform;',
  3892. 'uniform float zoom;',
  3893. 'uniform float opacity;',
  3894. 'varying vec2 vUv;',
  3895. 'const float PI = 3.141592653589793;',
  3896. 'void main(){',
  3897. 'vec2 position = -1.0 + 2.0 * vUv;',
  3898. 'position *= vec2( zoom * resolution, zoom * 0.5 );',
  3899. 'float x2y2 = position.x * position.x + position.y * position.y;',
  3900. 'vec3 sphere_pnt = vec3( 2. * position, x2y2 - 1. ) / ( x2y2 + 1. );',
  3901. 'sphere_pnt = vec3( transform * vec4( sphere_pnt, 1.0 ) );',
  3902. 'vec2 sampleUV = vec2(',
  3903. '(atan(sphere_pnt.y, sphere_pnt.x) / PI + 1.0) * 0.5,',
  3904. '(asin(sphere_pnt.z) / PI + 0.5)',
  3905. ');',
  3906. 'gl_FragColor = texture2D( tDiffuse, sampleUV );',
  3907. 'gl_FragColor.a *= opacity;',
  3908. '}'
  3909. ].join( '\n' )
  3910. };
  3911. /**
  3912. * @classdesc Little Planet
  3913. * @constructor
  3914. * @param {string} type - Type of little planet basic class
  3915. * @param {string} source - URL for the image source
  3916. * @param {number} [size=10000] - Size of plane geometry
  3917. * @param {number} [ratio=0.5] - Ratio of plane geometry's height against width
  3918. */
  3919. function LittlePlanet ( type = 'image', source, size = 10000, ratio = 0.5 ) {
  3920. if ( type === 'image' ) {
  3921. ImagePanorama.call( this, source, this.createGeometry( size, ratio ), this.createMaterial( size ) );
  3922. }
  3923. this.size = size;
  3924. this.ratio = ratio;
  3925. this.EPS = 0.000001;
  3926. this.frameId = null;
  3927. this.dragging = false;
  3928. this.userMouse = new THREE.Vector2();
  3929. this.quatA = new THREE.Quaternion();
  3930. this.quatB = new THREE.Quaternion();
  3931. this.quatCur = new THREE.Quaternion();
  3932. this.quatSlerp = new THREE.Quaternion();
  3933. this.vectorX = new THREE.Vector3( 1, 0, 0 );
  3934. this.vectorY = new THREE.Vector3( 0, 1, 0 );
  3935. this.addEventListener( 'window-resize', this.onWindowResize );
  3936. }
  3937. LittlePlanet.prototype = Object.assign( Object.create( ImagePanorama.prototype ), {
  3938. constructor: LittlePlanet,
  3939. add: function ( object ) {
  3940. if ( arguments.length > 1 ) {
  3941. for ( let i = 0; i < arguments.length; i ++ ) {
  3942. this.add( arguments[ i ] );
  3943. }
  3944. return this;
  3945. }
  3946. if ( object instanceof Infospot ) {
  3947. object.material.depthTest = false;
  3948. }
  3949. ImagePanorama.prototype.add.call( this, object );
  3950. },
  3951. createGeometry: function ( size, ratio ) {
  3952. return new THREE.PlaneBufferGeometry( size, size * ratio );
  3953. },
  3954. createMaterial: function ( size ) {
  3955. const shader = Object.assign( {}, StereographicShader ), uniforms = shader.uniforms;
  3956. uniforms.zoom.value = size;
  3957. uniforms.opacity.value = 0.0;
  3958. return new THREE.ShaderMaterial( {
  3959. uniforms: uniforms,
  3960. vertexShader: shader.vertexShader,
  3961. fragmentShader: shader.fragmentShader,
  3962. side: THREE.BackSide,
  3963. transparent: true
  3964. } );
  3965. },
  3966. registerMouseEvents: function () {
  3967. this.container.addEventListener( 'mousedown', this.onMouseDown.bind( this ), { passive: true } );
  3968. this.container.addEventListener( 'mousemove', this.onMouseMove.bind( this ), { passive: true } );
  3969. this.container.addEventListener( 'mouseup', this.onMouseUp.bind( this ), { passive: true } );
  3970. this.container.addEventListener( 'touchstart', this.onMouseDown.bind( this ), { passive: true } );
  3971. this.container.addEventListener( 'touchmove', this.onMouseMove.bind( this ), { passive: true } );
  3972. this.container.addEventListener( 'touchend', this.onMouseUp.bind( this ), { passive: true } );
  3973. this.container.addEventListener( 'mousewheel', this.onMouseWheel.bind( this ), { passive: false } );
  3974. this.container.addEventListener( 'DOMMouseScroll', this.onMouseWheel.bind( this ), { passive: false } );
  3975. this.container.addEventListener( 'contextmenu', this.onContextMenu.bind( this ), { passive: true } );
  3976. },
  3977. unregisterMouseEvents: function () {
  3978. this.container.removeEventListener( 'mousedown', this.onMouseDown.bind( this ), false );
  3979. this.container.removeEventListener( 'mousemove', this.onMouseMove.bind( this ), false );
  3980. this.container.removeEventListener( 'mouseup', this.onMouseUp.bind( this ), false );
  3981. this.container.removeEventListener( 'touchstart', this.onMouseDown.bind( this ), false );
  3982. this.container.removeEventListener( 'touchmove', this.onMouseMove.bind( this ), false );
  3983. this.container.removeEventListener( 'touchend', this.onMouseUp.bind( this ), false );
  3984. this.container.removeEventListener( 'mousewheel', this.onMouseWheel.bind( this ), false );
  3985. this.container.removeEventListener( 'DOMMouseScroll', this.onMouseWheel.bind( this ), false );
  3986. this.container.removeEventListener( 'contextmenu', this.onContextMenu.bind( this ), false );
  3987. },
  3988. onMouseDown: function ( event ) {
  3989. const inputCount = ( event.touches && event.touches.length ) || 1 ;
  3990. switch ( inputCount ) {
  3991. case 1:
  3992. const x = ( event.clientX >= 0 ) ? event.clientX : event.touches[ 0 ].clientX;
  3993. const y = ( event.clientY >= 0 ) ? event.clientY : event.touches[ 0 ].clientY;
  3994. this.dragging = true;
  3995. this.userMouse.set( x, y );
  3996. break;
  3997. case 2:
  3998. const dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
  3999. const dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
  4000. const distance = Math.sqrt( dx * dx + dy * dy );
  4001. this.userMouse.pinchDistance = distance;
  4002. break;
  4003. default:
  4004. break;
  4005. }
  4006. this.onUpdateCallback();
  4007. },
  4008. onMouseMove: function ( event ) {
  4009. const inputCount = ( event.touches && event.touches.length ) || 1 ;
  4010. switch ( inputCount ) {
  4011. case 1:
  4012. const x = ( event.clientX >= 0 ) ? event.clientX : event.touches[ 0 ].clientX;
  4013. const y = ( event.clientY >= 0 ) ? event.clientY : event.touches[ 0 ].clientY;
  4014. const angleX = THREE.Math.degToRad( x - this.userMouse.x ) * 0.4;
  4015. const angleY = THREE.Math.degToRad( y - this.userMouse.y ) * 0.4;
  4016. if ( this.dragging ) {
  4017. this.quatA.setFromAxisAngle( this.vectorY, angleX );
  4018. this.quatB.setFromAxisAngle( this.vectorX, angleY );
  4019. this.quatCur.multiply( this.quatA ).multiply( this.quatB );
  4020. this.userMouse.set( x, y );
  4021. }
  4022. break;
  4023. case 2:
  4024. const dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
  4025. const dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
  4026. const distance = Math.sqrt( dx * dx + dy * dy );
  4027. this.addZoomDelta( this.userMouse.pinchDistance - distance );
  4028. break;
  4029. default:
  4030. break;
  4031. }
  4032. },
  4033. onMouseUp: function () {
  4034. this.dragging = false;
  4035. },
  4036. onMouseWheel: function ( event ) {
  4037. event.preventDefault();
  4038. event.stopPropagation();
  4039. let delta = 0;
  4040. if ( event.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9
  4041. delta = event.wheelDelta;
  4042. } else if ( event.detail !== undefined ) { // Firefox
  4043. delta = - event.detail;
  4044. }
  4045. this.addZoomDelta( delta );
  4046. this.onUpdateCallback();
  4047. },
  4048. addZoomDelta: function ( delta ) {
  4049. const uniforms = this.material.uniforms;
  4050. const lowerBound = this.size * 0.1;
  4051. const upperBound = this.size * 10;
  4052. uniforms.zoom.value += delta;
  4053. if ( uniforms.zoom.value <= lowerBound ) {
  4054. uniforms.zoom.value = lowerBound;
  4055. } else if ( uniforms.zoom.value >= upperBound ) {
  4056. uniforms.zoom.value = upperBound;
  4057. }
  4058. },
  4059. onUpdateCallback: function () {
  4060. this.frameId = window.requestAnimationFrame( this.onUpdateCallback.bind( this ) );
  4061. this.quatSlerp.slerp( this.quatCur, 0.1 );
  4062. if ( this.material ) {
  4063. this.material.uniforms.transform.value.makeRotationFromQuaternion( this.quatSlerp );
  4064. }
  4065. if ( !this.dragging && 1.0 - this.quatSlerp.clone().dot( this.quatCur ) < this.EPS ) {
  4066. window.cancelAnimationFrame( this.frameId );
  4067. }
  4068. },
  4069. reset: function () {
  4070. this.quatCur.set( 0, 0, 0, 1 );
  4071. this.quatSlerp.set( 0, 0, 0, 1 );
  4072. this.onUpdateCallback();
  4073. },
  4074. onLoad: function ( texture ) {
  4075. this.material.uniforms.resolution.value = this.container.clientWidth / this.container.clientHeight;
  4076. this.registerMouseEvents();
  4077. this.onUpdateCallback();
  4078. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'disableControl' } );
  4079. ImagePanorama.prototype.onLoad.call( this, texture );
  4080. },
  4081. onLeave: function () {
  4082. this.unregisterMouseEvents();
  4083. this.dispatchEvent( { type: 'panolens-viewer-handler', method: 'enableControl', data: CONTROLS.ORBIT } );
  4084. window.cancelAnimationFrame( this.frameId );
  4085. ImagePanorama.prototype.onLeave.call( this );
  4086. },
  4087. onWindowResize: function () {
  4088. this.material.uniforms.resolution.value = this.container.clientWidth / this.container.clientHeight;
  4089. },
  4090. onContextMenu: function () {
  4091. this.dragging = false;
  4092. },
  4093. dispose: function () {
  4094. this.unregisterMouseEvents();
  4095. ImagePanorama.prototype.dispose.call( this );
  4096. }
  4097. });
  4098. /**
  4099. * @classdesc Image Little Planet
  4100. * @constructor
  4101. * @param {string} source - URL for the image source
  4102. * @param {number} [size=10000] - Size of plane geometry
  4103. * @param {number} [ratio=0.5] - Ratio of plane geometry's height against width
  4104. */
  4105. function ImageLittlePlanet ( source, size, ratio ) {
  4106. LittlePlanet.call( this, 'image', source, size, ratio );
  4107. }
  4108. ImageLittlePlanet.prototype = Object.assign( Object.create( LittlePlanet.prototype ), {
  4109. constructor: ImageLittlePlanet,
  4110. /**
  4111. * On loaded with texture
  4112. * @param {THREE.Texture} texture
  4113. * @memberOf ImageLittlePlanet
  4114. * @instance
  4115. */
  4116. onLoad: function ( texture ) {
  4117. this.updateTexture( texture );
  4118. LittlePlanet.prototype.onLoad.call( this, texture );
  4119. },
  4120. /**
  4121. * Update texture
  4122. * @param {THREE.Texture} texture
  4123. * @memberOf ImageLittlePlanet
  4124. * @instance
  4125. */
  4126. updateTexture: function ( texture ) {
  4127. texture.minFilter = texture.magFilter = THREE.LinearFilter;
  4128. this.material.uniforms[ 'tDiffuse' ].value = texture;
  4129. },
  4130. /**
  4131. * Dispose
  4132. * @memberOf ImageLittlePlanet
  4133. * @instance
  4134. */
  4135. dispose: function () {
  4136. const tDiffuse = this.material.uniforms[ 'tDiffuse' ];
  4137. if ( tDiffuse && tDiffuse.value ) {
  4138. tDiffuse.value.dispose();
  4139. }
  4140. LittlePlanet.prototype.dispose.call( this );
  4141. }
  4142. } );
  4143. /**
  4144. * @classdesc Camera panorama
  4145. * @description See {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints|MediaStreamConstraints} for constraints
  4146. * @param {object} - camera constraints
  4147. * @constructor
  4148. */
  4149. function CameraPanorama ( constraints ) {
  4150. const radius = 5000;
  4151. const geometry = new THREE.SphereBufferGeometry( radius, 60, 40 );
  4152. const material = new THREE.MeshBasicMaterial( { visible: false });
  4153. Panorama.call( this, geometry, material );
  4154. this.media = new Media( constraints );
  4155. this.radius = radius;
  4156. this.addEventListener( 'enter', this.start.bind( this ) );
  4157. this.addEventListener( 'leave', this.stop.bind( this ) );
  4158. this.addEventListener( 'panolens-container', this.onPanolensContainer.bind( this ) );
  4159. this.addEventListener( 'panolens-scene', this.onPanolensScene.bind( this ) );
  4160. }
  4161. CameraPanorama.prototype = Object.assign( Object.create( Panorama.prototype ), {
  4162. constructor: CameraPanorama,
  4163. /**
  4164. * On container event
  4165. * @param {object} event
  4166. * @memberOf CameraPanorama
  4167. * @instance
  4168. */
  4169. onPanolensContainer: function ( { container } ) {
  4170. this.media.setContainer( container );
  4171. },
  4172. /**
  4173. * On scene event
  4174. * @param {object} event
  4175. * @memberOf CameraPanorama
  4176. * @instance
  4177. */
  4178. onPanolensScene: function ( { scene } ) {
  4179. this.media.setScene( scene );
  4180. },
  4181. /**
  4182. * Start camera streaming
  4183. * @memberOf CameraPanorama
  4184. * @instance
  4185. * @returns {Promise}
  4186. */
  4187. start: function () {
  4188. return this.media.start();
  4189. },
  4190. /**
  4191. * Stop camera streaming
  4192. * @memberOf CameraPanorama
  4193. * @instance
  4194. */
  4195. stop: function () {
  4196. this.media.stop();
  4197. },
  4198. } );
  4199. /**
  4200. * @classdesc Orbit Controls
  4201. * @constructor
  4202. * @external OrbitControls
  4203. * @param {THREE.Object} object
  4204. * @param {HTMLElement} domElement
  4205. */
  4206. function OrbitControls ( object, domElement ) {
  4207. this.object = object;
  4208. this.domElement = ( domElement !== undefined ) ? domElement : document;
  4209. this.frameId = null;
  4210. // API
  4211. // Set to false to disable this control
  4212. this.enabled = true;
  4213. /*
  4214. * "target" sets the location of focus, where the control orbits around
  4215. * and where it pans with respect to.
  4216. */
  4217. this.target = new THREE.Vector3();
  4218. // center is old, deprecated; use "target" instead
  4219. this.center = this.target;
  4220. /*
  4221. * This option actually enables dollying in and out; left as "zoom" for
  4222. * backwards compatibility
  4223. */
  4224. this.noZoom = false;
  4225. this.zoomSpeed = 1.0;
  4226. // Limits to how far you can dolly in and out ( PerspectiveCamera only )
  4227. this.minDistance = 0;
  4228. this.maxDistance = Infinity;
  4229. // Limits to how far you can zoom in and out ( OrthographicCamera only )
  4230. this.minZoom = 0;
  4231. this.maxZoom = Infinity;
  4232. // Set to true to disable this control
  4233. this.noRotate = false;
  4234. this.rotateSpeed = -0.15;
  4235. // Set to true to disable this control
  4236. this.noPan = true;
  4237. this.keyPanSpeed = 7.0; // pixels moved per arrow key push
  4238. // Set to true to automatically rotate around the target
  4239. this.autoRotate = false;
  4240. this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
  4241. /*
  4242. * How far you can orbit vertically, upper and lower limits.
  4243. * Range is 0 to Math.PI radians.
  4244. */
  4245. this.minPolarAngle = 0; // radians
  4246. this.maxPolarAngle = Math.PI; // radians
  4247. // Momentum
  4248. this.momentumDampingFactor = 0.90;
  4249. this.momentumScalingFactor = -0.005;
  4250. this.momentumKeydownFactor = 20;
  4251. // Fov
  4252. this.minFov = 30;
  4253. this.maxFov = 120;
  4254. /*
  4255. * How far you can orbit horizontally, upper and lower limits.
  4256. * If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
  4257. */
  4258. this.minAzimuthAngle = - Infinity; // radians
  4259. this.maxAzimuthAngle = Infinity; // radians
  4260. // Set to true to disable use of the keys
  4261. this.noKeys = false;
  4262. // The four arrow keys
  4263. this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
  4264. // Mouse buttons
  4265. this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
  4266. /*
  4267. * //////////
  4268. * internals
  4269. */
  4270. var scope = this;
  4271. var EPS = 10e-8;
  4272. var MEPS = 10e-5;
  4273. var rotateStart = new THREE.Vector2();
  4274. var rotateEnd = new THREE.Vector2();
  4275. var rotateDelta = new THREE.Vector2();
  4276. var panStart = new THREE.Vector2();
  4277. var panEnd = new THREE.Vector2();
  4278. var panDelta = new THREE.Vector2();
  4279. var panOffset = new THREE.Vector3();
  4280. var offset = new THREE.Vector3();
  4281. var dollyStart = new THREE.Vector2();
  4282. var dollyEnd = new THREE.Vector2();
  4283. var dollyDelta = new THREE.Vector2();
  4284. var theta = 0;
  4285. var phi = 0;
  4286. var phiDelta = 0;
  4287. var thetaDelta = 0;
  4288. var scale = 1;
  4289. var pan = new THREE.Vector3();
  4290. var lastPosition = new THREE.Vector3();
  4291. var lastQuaternion = new THREE.Quaternion();
  4292. var momentumLeft = 0, momentumUp = 0;
  4293. var eventPrevious;
  4294. var momentumOn = false;
  4295. var keyUp, keyBottom, keyLeft, keyRight;
  4296. var STATE = { NONE: -1, ROTATE: 0, DOLLY: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_DOLLY: 4, TOUCH_PAN: 5 };
  4297. var state = STATE.NONE;
  4298. // for reset
  4299. this.target0 = this.target.clone();
  4300. this.position0 = this.object.position.clone();
  4301. this.zoom0 = this.object.zoom;
  4302. // so camera.up is the orbit axis
  4303. var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
  4304. var quatInverse = quat.clone().inverse();
  4305. // events
  4306. var changeEvent = { type: 'change' };
  4307. var startEvent = { type: 'start' };
  4308. var endEvent = { type: 'end' };
  4309. this.setLastQuaternion = function ( quaternion ) {
  4310. lastQuaternion.copy( quaternion );
  4311. scope.object.quaternion.copy( quaternion );
  4312. };
  4313. this.getLastPosition = function () {
  4314. return lastPosition;
  4315. };
  4316. this.rotateLeft = function ( angle ) {
  4317. if ( angle === undefined ) {
  4318. angle = getAutoRotationAngle();
  4319. }
  4320. thetaDelta -= angle;
  4321. };
  4322. this.rotateUp = function ( angle ) {
  4323. if ( angle === undefined ) {
  4324. angle = getAutoRotationAngle();
  4325. }
  4326. phiDelta -= angle;
  4327. };
  4328. // pass in distance in world space to move left
  4329. this.panLeft = function ( distance ) {
  4330. var te = this.object.matrix.elements;
  4331. // get X column of matrix
  4332. panOffset.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  4333. panOffset.multiplyScalar( - distance );
  4334. pan.add( panOffset );
  4335. };
  4336. // pass in distance in world space to move up
  4337. this.panUp = function ( distance ) {
  4338. var te = this.object.matrix.elements;
  4339. // get Y column of matrix
  4340. panOffset.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  4341. panOffset.multiplyScalar( distance );
  4342. pan.add( panOffset );
  4343. };
  4344. /*
  4345. * pass in x,y of change desired in pixel space,
  4346. * right and down are positive
  4347. */
  4348. this.pan = function ( deltaX, deltaY ) {
  4349. var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
  4350. if ( scope.object instanceof THREE.PerspectiveCamera ) {
  4351. // perspective
  4352. var position = scope.object.position;
  4353. var offset = position.clone().sub( scope.target );
  4354. var targetDistance = offset.length();
  4355. // half of the fov is center to top of screen
  4356. targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
  4357. // we actually don't use screenWidth, since perspective camera is fixed to screen height
  4358. scope.panLeft( 2 * deltaX * targetDistance / element.clientHeight );
  4359. scope.panUp( 2 * deltaY * targetDistance / element.clientHeight );
  4360. } else if ( scope.object instanceof THREE.OrthographicCamera ) {
  4361. // orthographic
  4362. scope.panLeft( deltaX * (scope.object.right - scope.object.left) / element.clientWidth );
  4363. scope.panUp( deltaY * (scope.object.top - scope.object.bottom) / element.clientHeight );
  4364. } else {
  4365. // camera neither orthographic or perspective
  4366. console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
  4367. }
  4368. };
  4369. this.momentum = function(){
  4370. if ( !momentumOn ) return;
  4371. if ( Math.abs( momentumLeft ) < MEPS && Math.abs( momentumUp ) < MEPS ) {
  4372. momentumOn = false;
  4373. return;
  4374. }
  4375. momentumUp *= this.momentumDampingFactor;
  4376. momentumLeft *= this.momentumDampingFactor;
  4377. thetaDelta -= this.momentumScalingFactor * momentumLeft;
  4378. phiDelta -= this.momentumScalingFactor * momentumUp;
  4379. };
  4380. this.dollyIn = function ( dollyScale ) {
  4381. if ( dollyScale === undefined ) {
  4382. dollyScale = getZoomScale();
  4383. }
  4384. if ( scope.object instanceof THREE.PerspectiveCamera ) {
  4385. scale /= dollyScale;
  4386. } else if ( scope.object instanceof THREE.OrthographicCamera ) {
  4387. scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom * dollyScale ) );
  4388. scope.object.updateProjectionMatrix();
  4389. scope.dispatchEvent( changeEvent );
  4390. } else {
  4391. console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
  4392. }
  4393. };
  4394. this.dollyOut = function ( dollyScale ) {
  4395. if ( dollyScale === undefined ) {
  4396. dollyScale = getZoomScale();
  4397. }
  4398. if ( scope.object instanceof THREE.PerspectiveCamera ) {
  4399. scale *= dollyScale;
  4400. } else if ( scope.object instanceof THREE.OrthographicCamera ) {
  4401. scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / dollyScale ) );
  4402. scope.object.updateProjectionMatrix();
  4403. scope.dispatchEvent( changeEvent );
  4404. } else {
  4405. console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
  4406. }
  4407. };
  4408. this.update = function ( ignoreUpdate ) {
  4409. var position = this.object.position;
  4410. offset.copy( position ).sub( this.target );
  4411. // rotate offset to "y-axis-is-up" space
  4412. offset.applyQuaternion( quat );
  4413. // angle from z-axis around y-axis
  4414. theta = Math.atan2( offset.x, offset.z );
  4415. // angle from y-axis
  4416. phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
  4417. if ( this.autoRotate && state === STATE.NONE ) {
  4418. this.rotateLeft( getAutoRotationAngle() );
  4419. }
  4420. this.momentum();
  4421. theta += thetaDelta;
  4422. phi += phiDelta;
  4423. // restrict theta to be between desired limits
  4424. theta = Math.max( this.minAzimuthAngle, Math.min( this.maxAzimuthAngle, theta ) );
  4425. // restrict phi to be between desired limits
  4426. phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
  4427. // restrict phi to be betwee EPS and PI-EPS
  4428. phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
  4429. var radius = offset.length() * scale;
  4430. // restrict radius to be between desired limits
  4431. radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
  4432. // move target to panned location
  4433. this.target.add( pan );
  4434. offset.x = radius * Math.sin( phi ) * Math.sin( theta );
  4435. offset.y = radius * Math.cos( phi );
  4436. offset.z = radius * Math.sin( phi ) * Math.cos( theta );
  4437. // rotate offset back to "camera-up-vector-is-up" space
  4438. offset.applyQuaternion( quatInverse );
  4439. position.copy( this.target ).add( offset );
  4440. this.object.lookAt( this.target );
  4441. thetaDelta = 0;
  4442. phiDelta = 0;
  4443. scale = 1;
  4444. pan.set( 0, 0, 0 );
  4445. /*
  4446. * update condition is:
  4447. * min(camera displacement, camera rotation in radians)^2 > EPS
  4448. * using small-angle approximation cos(x/2) = 1 - x^2 / 8
  4449. */
  4450. if ( lastPosition.distanceToSquared( this.object.position ) > EPS
  4451. || 8 * (1 - lastQuaternion.dot(this.object.quaternion)) > EPS ) {
  4452. if ( ignoreUpdate !== true ) { this.dispatchEvent( changeEvent ); }
  4453. lastPosition.copy( this.object.position );
  4454. lastQuaternion.copy (this.object.quaternion );
  4455. }
  4456. };
  4457. this.reset = function () {
  4458. state = STATE.NONE;
  4459. this.target.copy( this.target0 );
  4460. this.object.position.copy( this.position0 );
  4461. this.object.zoom = this.zoom0;
  4462. this.object.updateProjectionMatrix();
  4463. this.dispatchEvent( changeEvent );
  4464. this.update();
  4465. };
  4466. this.getPolarAngle = function () {
  4467. return phi;
  4468. };
  4469. this.getAzimuthalAngle = function () {
  4470. return theta;
  4471. };
  4472. function getAutoRotationAngle() {
  4473. return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
  4474. }
  4475. function getZoomScale() {
  4476. return Math.pow( 0.95, scope.zoomSpeed );
  4477. }
  4478. function onMouseDown( event ) {
  4479. momentumOn = false;
  4480. momentumLeft = momentumUp = 0;
  4481. if ( scope.enabled === false ) return;
  4482. event.preventDefault();
  4483. if ( event.button === scope.mouseButtons.ORBIT ) {
  4484. if ( scope.noRotate === true ) return;
  4485. state = STATE.ROTATE;
  4486. rotateStart.set( event.clientX, event.clientY );
  4487. } else if ( event.button === scope.mouseButtons.ZOOM ) {
  4488. if ( scope.noZoom === true ) return;
  4489. state = STATE.DOLLY;
  4490. dollyStart.set( event.clientX, event.clientY );
  4491. } else if ( event.button === scope.mouseButtons.PAN ) {
  4492. if ( scope.noPan === true ) return;
  4493. state = STATE.PAN;
  4494. panStart.set( event.clientX, event.clientY );
  4495. }
  4496. if ( state !== STATE.NONE ) {
  4497. document.addEventListener( 'mousemove', onMouseMove, false );
  4498. document.addEventListener( 'mouseup', onMouseUp, false );
  4499. scope.dispatchEvent( startEvent );
  4500. }
  4501. scope.update();
  4502. }
  4503. function onMouseMove( event ) {
  4504. if ( scope.enabled === false ) return;
  4505. event.preventDefault();
  4506. var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
  4507. if ( state === STATE.ROTATE ) {
  4508. if ( scope.noRotate === true ) return;
  4509. rotateEnd.set( event.clientX, event.clientY );
  4510. rotateDelta.subVectors( rotateEnd, rotateStart );
  4511. // rotating across whole screen goes 360 degrees around
  4512. scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
  4513. // rotating up and down along whole screen attempts to go 360, but limited to 180
  4514. scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
  4515. rotateStart.copy( rotateEnd );
  4516. if( eventPrevious ){
  4517. momentumLeft = event.clientX - eventPrevious.clientX;
  4518. momentumUp = event.clientY - eventPrevious.clientY;
  4519. }
  4520. eventPrevious = event;
  4521. } else if ( state === STATE.DOLLY ) {
  4522. if ( scope.noZoom === true ) return;
  4523. dollyEnd.set( event.clientX, event.clientY );
  4524. dollyDelta.subVectors( dollyEnd, dollyStart );
  4525. if ( dollyDelta.y > 0 ) {
  4526. scope.dollyIn();
  4527. } else if ( dollyDelta.y < 0 ) {
  4528. scope.dollyOut();
  4529. }
  4530. dollyStart.copy( dollyEnd );
  4531. } else if ( state === STATE.PAN ) {
  4532. if ( scope.noPan === true ) return;
  4533. panEnd.set( event.clientX, event.clientY );
  4534. panDelta.subVectors( panEnd, panStart );
  4535. scope.pan( panDelta.x, panDelta.y );
  4536. panStart.copy( panEnd );
  4537. }
  4538. if ( state !== STATE.NONE ) scope.update();
  4539. }
  4540. function onMouseUp( /* event */ ) {
  4541. momentumOn = true;
  4542. eventPrevious = undefined;
  4543. if ( scope.enabled === false ) return;
  4544. document.removeEventListener( 'mousemove', onMouseMove, false );
  4545. document.removeEventListener( 'mouseup', onMouseUp, false );
  4546. scope.dispatchEvent( endEvent );
  4547. state = STATE.NONE;
  4548. }
  4549. function onMouseWheel( event ) {
  4550. if ( scope.enabled === false || scope.noZoom === true || state !== STATE.NONE ) return;
  4551. event.preventDefault();
  4552. event.stopPropagation();
  4553. var delta = 0;
  4554. if ( event.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9
  4555. delta = event.wheelDelta;
  4556. } else if ( event.detail !== undefined ) { // Firefox
  4557. delta = - event.detail;
  4558. }
  4559. if ( delta > 0 ) {
  4560. // scope.dollyOut();
  4561. scope.object.fov = ( scope.object.fov < scope.maxFov )
  4562. ? scope.object.fov + 1
  4563. : scope.maxFov;
  4564. scope.object.updateProjectionMatrix();
  4565. } else if ( delta < 0 ) {
  4566. // scope.dollyIn();
  4567. scope.object.fov = ( scope.object.fov > scope.minFov )
  4568. ? scope.object.fov - 1
  4569. : scope.minFov;
  4570. scope.object.updateProjectionMatrix();
  4571. }
  4572. scope.update();
  4573. scope.dispatchEvent( changeEvent );
  4574. scope.dispatchEvent( startEvent );
  4575. scope.dispatchEvent( endEvent );
  4576. }
  4577. function onKeyUp ( event ) {
  4578. switch ( event.keyCode ) {
  4579. case scope.keys.UP:
  4580. keyUp = false;
  4581. break;
  4582. case scope.keys.BOTTOM:
  4583. keyBottom = false;
  4584. break;
  4585. case scope.keys.LEFT:
  4586. keyLeft = false;
  4587. break;
  4588. case scope.keys.RIGHT:
  4589. keyRight = false;
  4590. break;
  4591. }
  4592. }
  4593. function onKeyDown( event ) {
  4594. if ( scope.enabled === false || scope.noKeys === true || scope.noRotate === true ) return;
  4595. switch ( event.keyCode ) {
  4596. case scope.keys.UP:
  4597. keyUp = true;
  4598. break;
  4599. case scope.keys.BOTTOM:
  4600. keyBottom = true;
  4601. break;
  4602. case scope.keys.LEFT:
  4603. keyLeft = true;
  4604. break;
  4605. case scope.keys.RIGHT:
  4606. keyRight = true;
  4607. break;
  4608. }
  4609. if (keyUp || keyBottom || keyLeft || keyRight) {
  4610. momentumOn = true;
  4611. if (keyUp) momentumUp = - scope.rotateSpeed * scope.momentumKeydownFactor;
  4612. if (keyBottom) momentumUp = scope.rotateSpeed * scope.momentumKeydownFactor;
  4613. if (keyLeft) momentumLeft = - scope.rotateSpeed * scope.momentumKeydownFactor;
  4614. if (keyRight) momentumLeft = scope.rotateSpeed * scope.momentumKeydownFactor;
  4615. }
  4616. }
  4617. function touchstart( event ) {
  4618. momentumOn = false;
  4619. momentumLeft = momentumUp = 0;
  4620. if ( scope.enabled === false ) return;
  4621. switch ( event.touches.length ) {
  4622. case 1: // one-fingered touch: rotate
  4623. if ( scope.noRotate === true ) return;
  4624. state = STATE.TOUCH_ROTATE;
  4625. rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  4626. break;
  4627. case 2: // two-fingered touch: dolly
  4628. if ( scope.noZoom === true ) return;
  4629. state = STATE.TOUCH_DOLLY;
  4630. var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
  4631. var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
  4632. var distance = Math.sqrt( dx * dx + dy * dy );
  4633. dollyStart.set( 0, distance );
  4634. break;
  4635. case 3: // three-fingered touch: pan
  4636. if ( scope.noPan === true ) return;
  4637. state = STATE.TOUCH_PAN;
  4638. panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  4639. break;
  4640. default:
  4641. state = STATE.NONE;
  4642. }
  4643. if ( state !== STATE.NONE ) scope.dispatchEvent( startEvent );
  4644. }
  4645. function touchmove( event ) {
  4646. if ( scope.enabled === false ) return;
  4647. event.preventDefault();
  4648. event.stopPropagation();
  4649. var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
  4650. switch ( event.touches.length ) {
  4651. case 1: // one-fingered touch: rotate
  4652. if ( scope.noRotate === true ) return;
  4653. if ( state !== STATE.TOUCH_ROTATE ) return;
  4654. rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  4655. rotateDelta.subVectors( rotateEnd, rotateStart );
  4656. // rotating across whole screen goes 360 degrees around
  4657. scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
  4658. // rotating up and down along whole screen attempts to go 360, but limited to 180
  4659. scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
  4660. rotateStart.copy( rotateEnd );
  4661. if( eventPrevious ){
  4662. momentumLeft = event.touches[ 0 ].pageX - eventPrevious.pageX;
  4663. momentumUp = event.touches[ 0 ].pageY - eventPrevious.pageY;
  4664. }
  4665. eventPrevious = {
  4666. pageX: event.touches[ 0 ].pageX,
  4667. pageY: event.touches[ 0 ].pageY,
  4668. };
  4669. scope.update();
  4670. break;
  4671. case 2: // two-fingered touch: dolly
  4672. if ( scope.noZoom === true ) return;
  4673. if ( state !== STATE.TOUCH_DOLLY ) return;
  4674. var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
  4675. var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
  4676. var distance = Math.sqrt( dx * dx + dy * dy );
  4677. dollyEnd.set( 0, distance );
  4678. dollyDelta.subVectors( dollyEnd, dollyStart );
  4679. if ( dollyDelta.y < 0 ) {
  4680. scope.object.fov = ( scope.object.fov < scope.maxFov )
  4681. ? scope.object.fov + 1
  4682. : scope.maxFov;
  4683. scope.object.updateProjectionMatrix();
  4684. } else if ( dollyDelta.y > 0 ) {
  4685. scope.object.fov = ( scope.object.fov > scope.minFov )
  4686. ? scope.object.fov - 1
  4687. : scope.minFov;
  4688. scope.object.updateProjectionMatrix();
  4689. }
  4690. dollyStart.copy( dollyEnd );
  4691. scope.update();
  4692. scope.dispatchEvent( changeEvent );
  4693. break;
  4694. case 3: // three-fingered touch: pan
  4695. if ( scope.noPan === true ) return;
  4696. if ( state !== STATE.TOUCH_PAN ) return;
  4697. panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  4698. panDelta.subVectors( panEnd, panStart );
  4699. scope.pan( panDelta.x, panDelta.y );
  4700. panStart.copy( panEnd );
  4701. scope.update();
  4702. break;
  4703. default:
  4704. state = STATE.NONE;
  4705. }
  4706. }
  4707. function touchend( /* event */ ) {
  4708. momentumOn = true;
  4709. eventPrevious = undefined;
  4710. if ( scope.enabled === false ) return;
  4711. scope.dispatchEvent( endEvent );
  4712. state = STATE.NONE;
  4713. }
  4714. this.dispose = function() {
  4715. this.domElement.removeEventListener( 'mousedown', onMouseDown );
  4716. this.domElement.removeEventListener( 'mousewheel', onMouseWheel );
  4717. this.domElement.removeEventListener( 'DOMMouseScroll', onMouseWheel );
  4718. this.domElement.removeEventListener( 'touchstart', touchstart );
  4719. this.domElement.removeEventListener( 'touchend', touchend );
  4720. this.domElement.removeEventListener( 'touchmove', touchmove );
  4721. window.removeEventListener( 'keyup', onKeyUp );
  4722. window.removeEventListener( 'keydown', onKeyDown );
  4723. };
  4724. // this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
  4725. this.domElement.addEventListener( 'mousedown', onMouseDown, { passive: false } );
  4726. this.domElement.addEventListener( 'mousewheel', onMouseWheel, { passive: false } );
  4727. this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, { passive: false } ); // firefox
  4728. this.domElement.addEventListener( 'touchstart', touchstart, { passive: false } );
  4729. this.domElement.addEventListener( 'touchend', touchend, { passive: false } );
  4730. this.domElement.addEventListener( 'touchmove', touchmove, { passive: false } );
  4731. window.addEventListener( 'keyup', onKeyUp, { passive: false } );
  4732. window.addEventListener( 'keydown', onKeyDown, { passive: false } );
  4733. // force an update at start
  4734. this.update();
  4735. }
  4736. OrbitControls.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype ), {
  4737. constructor: OrbitControls
  4738. } );
  4739. /**
  4740. * @classdesc Device Orientation Control
  4741. * @constructor
  4742. * @external DeviceOrientationControls
  4743. * @param {THREE.Camera} camera
  4744. * @param {HTMLElement} domElement
  4745. */
  4746. function DeviceOrientationControls ( camera, domElement ) {
  4747. var scope = this;
  4748. var changeEvent = { type: 'change' };
  4749. var rotY = 0;
  4750. var rotX = 0;
  4751. var tempX = 0;
  4752. var tempY = 0;
  4753. this.camera = camera;
  4754. this.camera.rotation.reorder( 'YXZ' );
  4755. this.domElement = ( domElement !== undefined ) ? domElement : document;
  4756. this.enabled = true;
  4757. this.deviceOrientation = {};
  4758. this.screenOrientation = 0;
  4759. this.alpha = 0;
  4760. this.alphaOffsetAngle = 0;
  4761. var onDeviceOrientationChangeEvent = function( event ) {
  4762. scope.deviceOrientation = event;
  4763. };
  4764. var onScreenOrientationChangeEvent = function() {
  4765. scope.screenOrientation = window.orientation || 0;
  4766. };
  4767. var onTouchStartEvent = function (event) {
  4768. event.preventDefault();
  4769. event.stopPropagation();
  4770. tempX = event.touches[ 0 ].pageX;
  4771. tempY = event.touches[ 0 ].pageY;
  4772. };
  4773. var onTouchMoveEvent = function (event) {
  4774. event.preventDefault();
  4775. event.stopPropagation();
  4776. rotY += THREE.Math.degToRad( ( event.touches[ 0 ].pageX - tempX ) / 4 );
  4777. rotX += THREE.Math.degToRad( ( tempY - event.touches[ 0 ].pageY ) / 4 );
  4778. scope.updateAlphaOffsetAngle( rotY );
  4779. tempX = event.touches[ 0 ].pageX;
  4780. tempY = event.touches[ 0 ].pageY;
  4781. };
  4782. // The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''
  4783. var setCameraQuaternion = function( quaternion, alpha, beta, gamma, orient ) {
  4784. var zee = new THREE.Vector3( 0, 0, 1 );
  4785. var euler = new THREE.Euler();
  4786. var q0 = new THREE.Quaternion();
  4787. var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis
  4788. var vectorFingerY;
  4789. var fingerQY = new THREE.Quaternion();
  4790. var fingerQX = new THREE.Quaternion();
  4791. if ( scope.screenOrientation == 0 ) {
  4792. vectorFingerY = new THREE.Vector3( 1, 0, 0 );
  4793. fingerQY.setFromAxisAngle( vectorFingerY, -rotX );
  4794. } else if ( scope.screenOrientation == 180 ) {
  4795. vectorFingerY = new THREE.Vector3( 1, 0, 0 );
  4796. fingerQY.setFromAxisAngle( vectorFingerY, rotX );
  4797. } else if ( scope.screenOrientation == 90 ) {
  4798. vectorFingerY = new THREE.Vector3( 0, 1, 0 );
  4799. fingerQY.setFromAxisAngle( vectorFingerY, rotX );
  4800. } else if ( scope.screenOrientation == - 90) {
  4801. vectorFingerY = new THREE.Vector3( 0, 1, 0 );
  4802. fingerQY.setFromAxisAngle( vectorFingerY, -rotX );
  4803. }
  4804. q1.multiply( fingerQY );
  4805. q1.multiply( fingerQX );
  4806. euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us
  4807. quaternion.setFromEuler( euler ); // orient the device
  4808. quaternion.multiply( q1 ); // camera looks out the back of the device, not the top
  4809. quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation
  4810. };
  4811. this.connect = function() {
  4812. onScreenOrientationChangeEvent(); // run once on load
  4813. window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent, { passive: true } );
  4814. window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, { passive: true } );
  4815. window.addEventListener( 'deviceorientation', this.update.bind( this ), { passive: true } );
  4816. scope.domElement.addEventListener( 'touchstart', onTouchStartEvent, { passive: false } );
  4817. scope.domElement.addEventListener( 'touchmove', onTouchMoveEvent, { passive: false } );
  4818. scope.enabled = true;
  4819. };
  4820. this.disconnect = function() {
  4821. window.removeEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );
  4822. window.removeEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );
  4823. window.removeEventListener( 'deviceorientation', this.update.bind( this ), false );
  4824. scope.domElement.removeEventListener( 'touchstart', onTouchStartEvent, false );
  4825. scope.domElement.removeEventListener( 'touchmove', onTouchMoveEvent, false );
  4826. scope.enabled = false;
  4827. };
  4828. this.update = function( ignoreUpdate ) {
  4829. if ( scope.enabled === false ) return;
  4830. var alpha = scope.deviceOrientation.alpha ? THREE.Math.degToRad( scope.deviceOrientation.alpha ) + scope.alphaOffsetAngle : 0; // Z
  4831. var beta = scope.deviceOrientation.beta ? THREE.Math.degToRad( scope.deviceOrientation.beta ) : 0; // X'
  4832. var gamma = scope.deviceOrientation.gamma ? THREE.Math.degToRad( scope.deviceOrientation.gamma ) : 0; // Y''
  4833. var orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O
  4834. setCameraQuaternion( scope.camera.quaternion, alpha, beta, gamma, orient );
  4835. scope.alpha = alpha;
  4836. if ( ignoreUpdate !== true ) { scope.dispatchEvent( changeEvent ); }
  4837. };
  4838. this.updateAlphaOffsetAngle = function( angle ) {
  4839. this.alphaOffsetAngle = angle;
  4840. this.update();
  4841. };
  4842. this.dispose = function() {
  4843. this.disconnect();
  4844. };
  4845. this.connect();
  4846. }
  4847. DeviceOrientationControls.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype), {
  4848. constructor: DeviceOrientationControls
  4849. } );
  4850. /**
  4851. * @classdesc Google Cardboard Effect Composer
  4852. * @constructor
  4853. * @external CardboardEffect
  4854. * @param {THREE.WebGLRenderer} renderer
  4855. */
  4856. function CardboardEffect ( renderer ) {
  4857. var _camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  4858. var _scene = new THREE.Scene();
  4859. var _stereo = new THREE.StereoCamera();
  4860. _stereo.aspect = 0.5;
  4861. var _params = { minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  4862. var _renderTarget = new THREE.WebGLRenderTarget( 512, 512, _params );
  4863. _renderTarget.scissorTest = true;
  4864. _renderTarget.texture.generateMipmaps = false;
  4865. /*
  4866. * Distortion Mesh ported from:
  4867. * https://github.com/borismus/webvr-boilerplate/blob/master/src/distortion/barrel-distortion-fragment.js
  4868. */
  4869. var distortion = new THREE.Vector2( 0.441, 0.156 );
  4870. var geometry = new THREE.PlaneBufferGeometry( 1, 1, 10, 20 ).removeAttribute( 'normal' ).toNonIndexed();
  4871. var positions = geometry.attributes.position.array;
  4872. var uvs = geometry.attributes.uv.array;
  4873. // duplicate
  4874. geometry.attributes.position.count *= 2;
  4875. geometry.attributes.uv.count *= 2;
  4876. var positions2 = new Float32Array( positions.length * 2 );
  4877. positions2.set( positions );
  4878. positions2.set( positions, positions.length );
  4879. var uvs2 = new Float32Array( uvs.length * 2 );
  4880. uvs2.set( uvs );
  4881. uvs2.set( uvs, uvs.length );
  4882. var vector = new THREE.Vector2();
  4883. var length = positions.length / 3;
  4884. for ( var i = 0, l = positions2.length / 3; i < l; i ++ ) {
  4885. vector.x = positions2[ i * 3 + 0 ];
  4886. vector.y = positions2[ i * 3 + 1 ];
  4887. var dot = vector.dot( vector );
  4888. var scalar = 1.5 + ( distortion.x + distortion.y * dot ) * dot;
  4889. var offset = i < length ? 0 : 1;
  4890. positions2[ i * 3 + 0 ] = ( vector.x / scalar ) * 1.5 - 0.5 + offset;
  4891. positions2[ i * 3 + 1 ] = ( vector.y / scalar ) * 3.0;
  4892. uvs2[ i * 2 ] = ( uvs2[ i * 2 ] + offset ) * 0.5;
  4893. }
  4894. geometry.attributes.position.array = positions2;
  4895. geometry.attributes.uv.array = uvs2;
  4896. //
  4897. var material = new THREE.MeshBasicMaterial( { map: _renderTarget.texture } );
  4898. var mesh = new THREE.Mesh( geometry, material );
  4899. _scene.add( mesh );
  4900. //
  4901. this.setSize = function ( width, height ) {
  4902. renderer.setSize( width, height );
  4903. var pixelRatio = renderer.getPixelRatio();
  4904. _renderTarget.setSize( width * pixelRatio, height * pixelRatio );
  4905. };
  4906. this.render = function ( scene, camera ) {
  4907. scene.updateMatrixWorld();
  4908. if ( camera.parent === null ) camera.updateMatrixWorld();
  4909. _stereo.update( camera );
  4910. var width = _renderTarget.width / 2;
  4911. var height = _renderTarget.height;
  4912. if ( renderer.autoClear ) renderer.clear();
  4913. _renderTarget.scissor.set( 0, 0, width, height );
  4914. _renderTarget.viewport.set( 0, 0, width, height );
  4915. renderer.setRenderTarget( _renderTarget );
  4916. renderer.render( scene, _stereo.cameraL );
  4917. renderer.clearDepth();
  4918. _renderTarget.scissor.set( width, 0, width, height );
  4919. _renderTarget.viewport.set( width, 0, width, height );
  4920. renderer.setRenderTarget( _renderTarget );
  4921. renderer.render( scene, _stereo.cameraR );
  4922. renderer.clearDepth();
  4923. renderer.setRenderTarget( null );
  4924. renderer.render( _scene, _camera );
  4925. };
  4926. }
  4927. /**
  4928. * @classdesc Stereo Effect Composer
  4929. * @constructor
  4930. * @external StereoEffect
  4931. * @param {THREE.WebGLRenderer} renderer
  4932. */
  4933. const StereoEffect = function ( renderer ) {
  4934. var _stereo = new THREE.StereoCamera();
  4935. _stereo.aspect = 0.5;
  4936. var size = new THREE.Vector2();
  4937. this.setEyeSeparation = function ( eyeSep ) {
  4938. _stereo.eyeSep = eyeSep;
  4939. };
  4940. this.setSize = function ( width, height ) {
  4941. renderer.setSize( width, height );
  4942. };
  4943. this.render = function ( scene, camera ) {
  4944. scene.updateMatrixWorld();
  4945. if ( camera.parent === null ) camera.updateMatrixWorld();
  4946. _stereo.update( camera );
  4947. renderer.getSize( size );
  4948. if ( renderer.autoClear ) renderer.clear();
  4949. renderer.setScissorTest( true );
  4950. renderer.setScissor( 0, 0, size.width / 2, size.height );
  4951. renderer.setViewport( 0, 0, size.width / 2, size.height );
  4952. renderer.render( scene, _stereo.cameraL );
  4953. renderer.setScissor( size.width / 2, 0, size.width / 2, size.height );
  4954. renderer.setViewport( size.width / 2, 0, size.width / 2, size.height );
  4955. renderer.render( scene, _stereo.cameraR );
  4956. renderer.setScissorTest( false );
  4957. };
  4958. };
  4959. /**
  4960. * @classdesc Viewer contains pre-defined scene, camera and renderer
  4961. * @constructor
  4962. * @param {object} [options] - Use custom or default config options
  4963. * @param {HTMLElement} [options.container] - A HTMLElement to host the canvas
  4964. * @param {THREE.Scene} [options.scene=THREE.Scene] - A THREE.Scene which contains panorama and 3D objects
  4965. * @param {THREE.Camera} [options.camera=THREE.PerspectiveCamera] - A THREE.Camera to view the scene
  4966. * @param {THREE.WebGLRenderer} [options.renderer=THREE.WebGLRenderer] - A THREE.WebGLRenderer to render canvas
  4967. * @param {boolean} [options.controlBar=true] - Show/hide control bar on the bottom of the container
  4968. * @param {array} [options.controlButtons=[]] - Button names to mount on controlBar if controlBar exists, Defaults to ['fullscreen', 'setting', 'video']
  4969. * @param {boolean} [options.autoHideControlBar=false] - Auto hide control bar when click on non-active area
  4970. * @param {boolean} [options.autoHideInfospot=true] - Auto hide infospots when click on non-active area
  4971. * @param {boolean} [options.horizontalView=false] - Allow only horizontal camera control
  4972. * @param {number} [options.clickTolerance=10] - Distance tolerance to tigger click / tap event
  4973. * @param {number} [options.cameraFov=60] - Camera field of view value
  4974. * @param {boolean} [options.reverseDragging=false] - Reverse dragging direction
  4975. * @param {boolean} [options.enableReticle=false] - Enable reticle for mouseless interaction other than VR mode
  4976. * @param {number} [options.dwellTime=1500] - Dwell time for reticle selection in ms
  4977. * @param {boolean} [options.autoReticleSelect=true] - Auto select a clickable target after dwellTime
  4978. * @param {boolean} [options.viewIndicator=false] - Adds an angle view indicator in upper left corner
  4979. * @param {number} [options.indicatorSize=30] - Size of View Indicator
  4980. * @param {string} [options.output='none'] - Whether and where to output raycast position. Could be 'event', 'console' or 'overlay'.
  4981. * @param {boolean} [options.autoRotate=false] - Auto rotate
  4982. * @param {number} [options.autoRotateSpeed=2.0] - Auto rotate speed as in degree per second. Positive is counter-clockwise and negative is clockwise.
  4983. * @param {number} [options.autoRotateActivationDuration=5000] - Duration before auto rotatation when no user interactivity in ms
  4984. */
  4985. function Viewer ( options ) {
  4986. let container;
  4987. options = options || {};
  4988. options.controlBar = options.controlBar !== undefined ? options.controlBar : true;
  4989. options.controlButtons = options.controlButtons || [ 'fullscreen', 'setting', 'video' ];
  4990. options.autoHideControlBar = options.autoHideControlBar !== undefined ? options.autoHideControlBar : false;
  4991. options.autoHideInfospot = options.autoHideInfospot !== undefined ? options.autoHideInfospot : true;
  4992. options.horizontalView = options.horizontalView !== undefined ? options.horizontalView : false;
  4993. options.clickTolerance = options.clickTolerance || 10;
  4994. options.cameraFov = options.cameraFov || 60;
  4995. options.reverseDragging = options.reverseDragging || false;
  4996. options.enableReticle = options.enableReticle || false;
  4997. options.dwellTime = options.dwellTime || 1500;
  4998. options.autoReticleSelect = options.autoReticleSelect !== undefined ? options.autoReticleSelect : true;
  4999. options.viewIndicator = options.viewIndicator !== undefined ? options.viewIndicator : false;
  5000. options.indicatorSize = options.indicatorSize || 30;
  5001. options.output = options.output ? options.output : 'none';
  5002. options.autoRotate = options.autoRotate || false;
  5003. options.autoRotateSpeed = options.autoRotateSpeed || 2.0;
  5004. options.autoRotateActivationDuration = options.autoRotateActivationDuration || 5000;
  5005. this.options = options;
  5006. /*
  5007. * CSS Icon
  5008. * const styleLoader = new StyleLoader();
  5009. * styleLoader.inject( 'icono' );
  5010. */
  5011. // Container
  5012. if ( options.container ) {
  5013. container = options.container;
  5014. container._width = container.clientWidth;
  5015. container._height = container.clientHeight;
  5016. } else {
  5017. container = document.createElement( 'div' );
  5018. container.classList.add( 'panolens-container' );
  5019. container.style.width = '100%';
  5020. container.style.height = '100%';
  5021. container._width = window.innerWidth;
  5022. container._height = window.innerHeight;
  5023. document.body.appendChild( container );
  5024. }
  5025. this.container = container;
  5026. this.camera = options.camera || new THREE.PerspectiveCamera( this.options.cameraFov, this.container.clientWidth / this.container.clientHeight, 1, 10000 );
  5027. this.scene = options.scene || new THREE.Scene();
  5028. this.renderer = options.renderer || new THREE.WebGLRenderer( { alpha: true, antialias: false } );
  5029. this.sceneReticle = new THREE.Scene();
  5030. this.viewIndicatorSize = this.options.indicatorSize;
  5031. this.reticle = {};
  5032. this.tempEnableReticle = this.options.enableReticle;
  5033. this.mode = MODES.NORMAL;
  5034. this.panorama = null;
  5035. this.widget = null;
  5036. this.hoverObject = null;
  5037. this.infospot = null;
  5038. this.pressEntityObject = null;
  5039. this.pressObject = null;
  5040. this.raycaster = new THREE.Raycaster();
  5041. this.raycasterPoint = new THREE.Vector2();
  5042. this.userMouse = new THREE.Vector2();
  5043. this.updateCallbacks = [];
  5044. this.requestAnimationId = null;
  5045. this.cameraFrustum = new THREE.Frustum();
  5046. this.cameraViewProjectionMatrix = new THREE.Matrix4();
  5047. this.autoRotateRequestId = null;
  5048. this.outputDivElement = null;
  5049. this.touchSupported = 'ontouchstart' in window || window.DocumentTouch && document instanceof DocumentTouch;
  5050. // Handler references
  5051. this.HANDLER_MOUSE_DOWN = this.onMouseDown.bind( this );
  5052. this.HANDLER_MOUSE_UP = this.onMouseUp.bind( this );
  5053. this.HANDLER_MOUSE_MOVE = this.onMouseMove.bind( this );
  5054. this.HANDLER_WINDOW_RESIZE = this.onWindowResize.bind( this );
  5055. this.HANDLER_KEY_DOWN = this.onKeyDown.bind( this );
  5056. this.HANDLER_KEY_UP = this.onKeyUp.bind( this );
  5057. this.HANDLER_TAP = this.onTap.bind( this, {
  5058. clientX: this.container.clientWidth / 2,
  5059. clientY: this.container.clientHeight / 2
  5060. } );
  5061. // Flag for infospot output
  5062. this.OUTPUT_INFOSPOT = false;
  5063. // Animations
  5064. this.tweenLeftAnimation = new Tween.Tween();
  5065. this.tweenUpAnimation = new Tween.Tween();
  5066. // Renderer
  5067. this.renderer.setPixelRatio( window.devicePixelRatio );
  5068. this.renderer.setSize( this.container.clientWidth, this.container.clientHeight );
  5069. this.renderer.setClearColor( 0x000000, 0 );
  5070. this.renderer.autoClear = false;
  5071. // Append Renderer Element to container
  5072. this.renderer.domElement.classList.add( 'panolens-canvas' );
  5073. this.renderer.domElement.style.display = 'block';
  5074. this.container.style.backgroundColor = '#000';
  5075. this.container.appendChild( this.renderer.domElement );
  5076. // Camera Controls
  5077. this.OrbitControls = new OrbitControls( this.camera, this.container );
  5078. this.OrbitControls.id = 'orbit';
  5079. this.OrbitControls.minDistance = 1;
  5080. this.OrbitControls.noPan = true;
  5081. this.OrbitControls.autoRotate = this.options.autoRotate;
  5082. this.OrbitControls.autoRotateSpeed = this.options.autoRotateSpeed;
  5083. this.DeviceOrientationControls = new DeviceOrientationControls( this.camera, this.container );
  5084. this.DeviceOrientationControls.id = 'device-orientation';
  5085. this.DeviceOrientationControls.enabled = false;
  5086. this.camera.position.z = 1;
  5087. // Register change event if passiveRenering
  5088. if ( this.options.passiveRendering ) {
  5089. console.warn( 'passiveRendering is now deprecated' );
  5090. }
  5091. // Controls
  5092. this.controls = [ this.OrbitControls, this.DeviceOrientationControls ];
  5093. this.control = this.OrbitControls;
  5094. // Cardboard effect
  5095. this.CardboardEffect = new CardboardEffect( this.renderer );
  5096. this.CardboardEffect.setSize( this.container.clientWidth, this.container.clientHeight );
  5097. // Stereo effect
  5098. this.StereoEffect = new StereoEffect( this.renderer );
  5099. this.StereoEffect.setSize( this.container.clientWidth, this.container.clientHeight );
  5100. this.effect = this.CardboardEffect;
  5101. // Add default hidden reticle
  5102. this.addReticle();
  5103. // Lock horizontal view
  5104. if ( this.options.horizontalView ) {
  5105. this.OrbitControls.minPolarAngle = Math.PI / 2;
  5106. this.OrbitControls.maxPolarAngle = Math.PI / 2;
  5107. }
  5108. // Add Control UI
  5109. if ( this.options.controlBar !== false ) {
  5110. this.addDefaultControlBar( this.options.controlButtons );
  5111. }
  5112. // Add View Indicator
  5113. if ( this.options.viewIndicator ) {
  5114. this.addViewIndicator();
  5115. }
  5116. // Reverse dragging direction
  5117. if ( this.options.reverseDragging ) {
  5118. this.reverseDraggingDirection();
  5119. }
  5120. // Register event if reticle is enabled, otherwise defaults to mouse
  5121. if ( this.options.enableReticle ) {
  5122. this.enableReticleControl();
  5123. } else {
  5124. this.registerMouseAndTouchEvents();
  5125. }
  5126. // Output infospot position to an overlay container if specified
  5127. if ( this.options.output === 'overlay' ) {
  5128. this.addOutputElement();
  5129. }
  5130. // Register dom event listeners
  5131. this.registerEventListeners();
  5132. // Animate
  5133. this.animate.call( this );
  5134. }
  5135. Viewer.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype ), {
  5136. constructor: Viewer,
  5137. /**
  5138. * Add an object to the scene
  5139. * Automatically hookup with panolens-viewer-handler listener
  5140. * to communicate with viewer method
  5141. * @param {THREE.Object3D} object - The object to be added
  5142. * @memberOf Viewer
  5143. * @instance
  5144. */
  5145. add: function ( object ) {
  5146. if ( arguments.length > 1 ) {
  5147. for ( let i = 0; i < arguments.length; i ++ ) {
  5148. this.add( arguments[ i ] );
  5149. }
  5150. return this;
  5151. }
  5152. this.scene.add( object );
  5153. // All object added to scene has 'panolens-viewer-handler' event to handle viewer communication
  5154. if ( object.addEventListener ) {
  5155. object.addEventListener( 'panolens-viewer-handler', this.eventHandler.bind( this ) );
  5156. }
  5157. // All object added to scene being passed with container
  5158. if ( object instanceof Panorama && object.dispatchEvent ) {
  5159. object.dispatchEvent( { type: 'panolens-container', container: this.container } );
  5160. }
  5161. if ( object instanceof CameraPanorama ) {
  5162. object.dispatchEvent( { type: 'panolens-scene', scene: this.scene } );
  5163. }
  5164. // Hookup default panorama event listeners
  5165. if ( object.type === 'panorama' ) {
  5166. this.addPanoramaEventListener( object );
  5167. if ( !this.panorama ) {
  5168. this.setPanorama( object );
  5169. }
  5170. }
  5171. },
  5172. /**
  5173. * Remove an object from the scene
  5174. * @param {THREE.Object3D} object - Object to be removed
  5175. * @memberOf Viewer
  5176. * @instance
  5177. */
  5178. remove: function ( object ) {
  5179. if ( object.removeEventListener ) {
  5180. object.removeEventListener( 'panolens-viewer-handler', this.eventHandler.bind( this ) );
  5181. }
  5182. this.scene.remove( object );
  5183. },
  5184. /**
  5185. * Add default control bar
  5186. * @param {array} array - The control buttons array
  5187. * @memberOf Viewer
  5188. * @instance
  5189. */
  5190. addDefaultControlBar: function ( array ) {
  5191. if ( this.widget ) {
  5192. console.warn( 'Default control bar exists' );
  5193. return;
  5194. }
  5195. const widget = new Widget( this.container );
  5196. widget.addEventListener( 'panolens-viewer-handler', this.eventHandler.bind( this ) );
  5197. widget.addControlBar();
  5198. array.forEach( buttonName => {
  5199. widget.addControlButton( buttonName );
  5200. } );
  5201. this.widget = widget;
  5202. },
  5203. /**
  5204. * Set a panorama to be the current one
  5205. * @param {Panorama} pano - Panorama to be set
  5206. * @memberOf Viewer
  5207. * @instance
  5208. */
  5209. setPanorama: function ( pano ) {
  5210. const leavingPanorama = this.panorama;
  5211. if ( pano.type === 'panorama' && leavingPanorama !== pano ) {
  5212. // Clear exisiting infospot
  5213. this.hideInfospot();
  5214. const afterEnterComplete = function () {
  5215. if ( leavingPanorama ) { leavingPanorama.onLeave(); }
  5216. pano.removeEventListener( 'enter-fade-start', afterEnterComplete );
  5217. };
  5218. pano.addEventListener( 'enter-fade-start', afterEnterComplete );
  5219. // Assign and enter panorama
  5220. (this.panorama = pano).onEnter();
  5221. }
  5222. },
  5223. /**
  5224. * Event handler to execute commands from child objects
  5225. * @param {object} event - The dispatched event with method as function name and data as an argument
  5226. * @memberOf Viewer
  5227. * @instance
  5228. */
  5229. eventHandler: function ( event ) {
  5230. if ( event.method && this[ event.method ] ) {
  5231. this[ event.method ]( event.data );
  5232. }
  5233. },
  5234. /**
  5235. * Dispatch event to all descendants
  5236. * @param {object} event - Event to be passed along
  5237. * @memberOf Viewer
  5238. * @instance
  5239. */
  5240. dispatchEventToChildren: function ( event ) {
  5241. this.scene.traverse( function ( object ) {
  5242. if ( object.dispatchEvent ) {
  5243. object.dispatchEvent( event );
  5244. }
  5245. });
  5246. },
  5247. /**
  5248. * Set widget content
  5249. * @method activateWidgetItem
  5250. * @param {integer} controlIndex - Control index
  5251. * @param {integer} mode - Modes for effects
  5252. * @memberOf Viewer
  5253. * @instance
  5254. */
  5255. activateWidgetItem: function ( controlIndex, mode ) {
  5256. const mainMenu = this.widget.mainMenu;
  5257. const ControlMenuItem = mainMenu.children[ 0 ];
  5258. const ModeMenuItem = mainMenu.children[ 1 ];
  5259. let item;
  5260. if ( controlIndex !== undefined ) {
  5261. switch ( controlIndex ) {
  5262. case 0:
  5263. item = ControlMenuItem.subMenu.children[ 1 ];
  5264. break;
  5265. case 1:
  5266. item = ControlMenuItem.subMenu.children[ 2 ];
  5267. break;
  5268. default:
  5269. item = ControlMenuItem.subMenu.children[ 1 ];
  5270. break;
  5271. }
  5272. ControlMenuItem.subMenu.setActiveItem( item );
  5273. ControlMenuItem.setSelectionTitle( item.textContent );
  5274. }
  5275. if ( mode !== undefined ) {
  5276. switch( mode ) {
  5277. case MODES.CARDBOARD:
  5278. item = ModeMenuItem.subMenu.children[ 2 ];
  5279. break;
  5280. case MODES.STEREO:
  5281. item = ModeMenuItem.subMenu.children[ 3 ];
  5282. break;
  5283. default:
  5284. item = ModeMenuItem.subMenu.children[ 1 ];
  5285. break;
  5286. }
  5287. ModeMenuItem.subMenu.setActiveItem( item );
  5288. ModeMenuItem.setSelectionTitle( item.textContent );
  5289. }
  5290. },
  5291. /**
  5292. * Enable rendering effect
  5293. * @param {MODES} mode - Modes for effects
  5294. * @memberOf Viewer
  5295. * @instance
  5296. */
  5297. enableEffect: function ( mode ) {
  5298. if ( this.mode === mode ) { return; }
  5299. if ( mode === MODES.NORMAL ) { this.disableEffect(); return; }
  5300. else { this.mode = mode; }
  5301. const fov = this.camera.fov;
  5302. switch( mode ) {
  5303. case MODES.CARDBOARD:
  5304. this.effect = this.CardboardEffect;
  5305. this.enableReticleControl();
  5306. break;
  5307. case MODES.STEREO:
  5308. this.effect = this.StereoEffect;
  5309. this.enableReticleControl();
  5310. break;
  5311. default:
  5312. this.effect = null;
  5313. this.disableReticleControl();
  5314. break;
  5315. }
  5316. this.activateWidgetItem( undefined, this.mode );
  5317. /**
  5318. * Dual eye effect event
  5319. * @type {object}
  5320. * @event Infospot#panolens-dual-eye-effect
  5321. * @property {MODES} mode - Current display mode
  5322. */
  5323. this.dispatchEventToChildren( { type: 'panolens-dual-eye-effect', mode: this.mode } );
  5324. // Force effect stereo camera to update by refreshing fov
  5325. this.camera.fov = fov + 10e-3;
  5326. this.effect.setSize( this.container.clientWidth, this.container.clientHeight );
  5327. this.render();
  5328. this.camera.fov = fov;
  5329. /**
  5330. * Dispatch mode change event
  5331. * @type {object}
  5332. * @event Viewer#mode-change
  5333. * @property {MODES} mode - Current display mode
  5334. */
  5335. this.dispatchEvent( { type: 'mode-change', mode: this.mode } );
  5336. },
  5337. /**
  5338. * Disable additional rendering effect
  5339. * @memberOf Viewer
  5340. * @instance
  5341. */
  5342. disableEffect: function () {
  5343. if ( this.mode === MODES.NORMAL ) { return; }
  5344. this.mode = MODES.NORMAL;
  5345. this.disableReticleControl();
  5346. this.activateWidgetItem( undefined, this.mode );
  5347. /**
  5348. * Dual eye effect event
  5349. * @type {object}
  5350. * @event Infospot#panolens-dual-eye-effect
  5351. * @property {MODES} mode - Current display mode
  5352. */
  5353. this.dispatchEventToChildren( { type: 'panolens-dual-eye-effect', mode: this.mode } );
  5354. this.renderer.setSize( this.container.clientWidth, this.container.clientHeight );
  5355. this.render();
  5356. /**
  5357. * Dispatch mode change event
  5358. * @type {object}
  5359. * @event Viewer#mode-change
  5360. * @property {MODES} mode - Current display mode
  5361. */
  5362. this.dispatchEvent( { type: 'mode-change', mode: this.mode } );
  5363. },
  5364. /**
  5365. * Enable reticle control
  5366. * @memberOf Viewer
  5367. * @instance
  5368. */
  5369. enableReticleControl: function () {
  5370. if ( this.reticle.visible ) { return; }
  5371. this.tempEnableReticle = true;
  5372. // Register reticle event and unregister mouse event
  5373. this.unregisterMouseAndTouchEvents();
  5374. this.reticle.show();
  5375. this.registerReticleEvent();
  5376. this.updateReticleEvent();
  5377. },
  5378. /**
  5379. * Disable reticle control
  5380. * @memberOf Viewer
  5381. * @instance
  5382. */
  5383. disableReticleControl: function () {
  5384. this.tempEnableReticle = false;
  5385. // Register mouse event and unregister reticle event
  5386. if ( !this.options.enableReticle ) {
  5387. this.reticle.hide();
  5388. this.unregisterReticleEvent();
  5389. this.registerMouseAndTouchEvents();
  5390. } else {
  5391. this.updateReticleEvent();
  5392. }
  5393. },
  5394. /**
  5395. * Enable auto rotation
  5396. * @memberOf Viewer
  5397. * @instance
  5398. */
  5399. enableAutoRate: function () {
  5400. this.options.autoRotate = true;
  5401. this.OrbitControls.autoRotate = true;
  5402. },
  5403. /**
  5404. * Disable auto rotation
  5405. * @memberOf Viewer
  5406. * @instance
  5407. */
  5408. disableAutoRate: function () {
  5409. clearTimeout( this.autoRotateRequestId );
  5410. this.options.autoRotate = false;
  5411. this.OrbitControls.autoRotate = false;
  5412. },
  5413. /**
  5414. * Toggle video play or stop
  5415. * @param {boolean} pause
  5416. * @memberOf Viewer
  5417. * @instance
  5418. * @fires Viewer#video-toggle
  5419. */
  5420. toggleVideoPlay: function ( pause ) {
  5421. if ( this.panorama instanceof VideoPanorama ) {
  5422. /**
  5423. * Toggle video event
  5424. * @type {object}
  5425. * @event Viewer#video-toggle
  5426. */
  5427. this.panorama.dispatchEvent( { type: 'video-toggle', pause: pause } );
  5428. }
  5429. },
  5430. /**
  5431. * Set currentTime in a video
  5432. * @param {number} percentage - Percentage of a video. Range from 0.0 to 1.0
  5433. * @memberOf Viewer
  5434. * @instance
  5435. * @fires Viewer#video-time
  5436. */
  5437. setVideoCurrentTime: function ( percentage ) {
  5438. if ( this.panorama instanceof VideoPanorama ) {
  5439. /**
  5440. * Setting video time event
  5441. * @type {object}
  5442. * @event Viewer#video-time
  5443. * @property {number} percentage - Percentage of a video. Range from 0.0 to 1.0
  5444. */
  5445. this.panorama.dispatchEvent( { type: 'video-time', percentage: percentage } );
  5446. }
  5447. },
  5448. /**
  5449. * This will be called when video updates if an widget is present
  5450. * @param {number} percentage - Percentage of a video. Range from 0.0 to 1.0
  5451. * @memberOf Viewer
  5452. * @instance
  5453. * @fires Viewer#video-update
  5454. */
  5455. onVideoUpdate: function ( percentage ) {
  5456. const { widget } = this;
  5457. /**
  5458. * Video update event
  5459. * @type {object}
  5460. * @event Viewer#video-update
  5461. * @property {number} percentage - Percentage of a video. Range from 0.0 to 1.0
  5462. */
  5463. if( widget ) { widget.dispatchEvent( { type: 'video-update', percentage: percentage } ); }
  5464. },
  5465. /**
  5466. * Add update callback to be called every animation frame
  5467. * @param {function} callback
  5468. * @memberOf Viewer
  5469. * @instance
  5470. */
  5471. addUpdateCallback: function ( fn ) {
  5472. if ( fn ) {
  5473. this.updateCallbacks.push( fn );
  5474. }
  5475. },
  5476. /**
  5477. * Remove update callback
  5478. * @param {function} fn - The function to be removed
  5479. * @memberOf Viewer
  5480. * @instance
  5481. */
  5482. removeUpdateCallback: function ( fn ) {
  5483. const index = this.updateCallbacks.indexOf( fn );
  5484. if ( fn && index >= 0 ) {
  5485. this.updateCallbacks.splice( index, 1 );
  5486. }
  5487. },
  5488. /**
  5489. * Show video widget
  5490. * @memberOf Viewer
  5491. * @instance
  5492. */
  5493. showVideoWidget: function () {
  5494. const { widget } = this;
  5495. /**
  5496. * Show video widget event
  5497. * @type {object}
  5498. * @event Viewer#video-control-show
  5499. */
  5500. if( widget ) { widget.dispatchEvent( { type: 'video-control-show' } ); }
  5501. },
  5502. /**
  5503. * Hide video widget
  5504. * @memberOf Viewer
  5505. * @instance
  5506. */
  5507. hideVideoWidget: function () {
  5508. const { widget } = this;
  5509. /**
  5510. * Hide video widget
  5511. * @type {object}
  5512. * @event Viewer#video-control-hide
  5513. */
  5514. if( widget ) { widget.dispatchEvent( { type: 'video-control-hide' } ); }
  5515. },
  5516. /**
  5517. * Update video play button
  5518. * @param {boolean} paused
  5519. * @memberOf Viewer
  5520. * @instance
  5521. */
  5522. updateVideoPlayButton: function ( paused ) {
  5523. const { widget } = this;
  5524. if ( widget && widget.videoElement && widget.videoElement.controlButton ) {
  5525. widget.videoElement.controlButton.update( paused );
  5526. }
  5527. },
  5528. /**
  5529. * Add default panorama event listeners
  5530. * @param {Panorama} pano - The panorama to be added with event listener
  5531. * @memberOf Viewer
  5532. * @instance
  5533. */
  5534. addPanoramaEventListener: function ( pano ) {
  5535. // Set camera control on every panorama
  5536. pano.addEventListener( 'enter-fade-start', this.setCameraControl.bind( this ) );
  5537. // Show and hide widget event only when it's VideoPanorama
  5538. if ( pano instanceof VideoPanorama ) {
  5539. pano.addEventListener( 'enter-fade-start', this.showVideoWidget.bind( this ) );
  5540. pano.addEventListener( 'leave', function () {
  5541. if ( !(this.panorama instanceof VideoPanorama) ) {
  5542. this.hideVideoWidget.call( this );
  5543. }
  5544. }.bind( this ) );
  5545. }
  5546. },
  5547. /**
  5548. * Set camera control
  5549. * @memberOf Viewer
  5550. * @instance
  5551. */
  5552. setCameraControl: function () {
  5553. this.OrbitControls.target.copy( this.panorama.position );
  5554. },
  5555. /**
  5556. * Get current camera control
  5557. * @return {object} - Current navigation control
  5558. * @memberOf Viewer
  5559. * @instance
  5560. * @returns {THREE.OrbitControls|THREE.DeviceOrientationControls}
  5561. */
  5562. getControl: function () {
  5563. return this.control;
  5564. },
  5565. /**
  5566. * Get scene
  5567. * @memberOf Viewer
  5568. * @instance
  5569. * @return {THREE.Scene} - Current scene which the viewer is built on
  5570. */
  5571. getScene: function () {
  5572. return this.scene;
  5573. },
  5574. /**
  5575. * Get camera
  5576. * @memberOf Viewer
  5577. * @instance
  5578. * @return {THREE.Camera} - The scene camera
  5579. */
  5580. getCamera: function () {
  5581. return this.camera;
  5582. },
  5583. /**
  5584. * Get renderer
  5585. * @memberOf Viewer
  5586. * @instance
  5587. * @return {THREE.WebGLRenderer} - The renderer using webgl
  5588. */
  5589. getRenderer: function () {
  5590. return this.renderer;
  5591. },
  5592. /**
  5593. * Get container
  5594. * @memberOf Viewer
  5595. * @instance
  5596. * @return {HTMLElement} - The container holds rendererd canvas
  5597. */
  5598. getContainer: function () {
  5599. return this.container;
  5600. },
  5601. /**
  5602. * Get control id
  5603. * @memberOf Viewer
  5604. * @instance
  5605. * @return {string} - Control id. 'orbit' or 'device-orientation'
  5606. */
  5607. getControlId: function () {
  5608. return this.control.id;
  5609. },
  5610. /**
  5611. * Get next navigation control id
  5612. * @memberOf Viewer
  5613. * @instance
  5614. * @return {string} - Next control id
  5615. */
  5616. getNextControlId: function () {
  5617. return this.controls[ this.getNextControlIndex() ].id;
  5618. },
  5619. /**
  5620. * Get next navigation control index
  5621. * @memberOf Viewer
  5622. * @instance
  5623. * @return {number} - Next control index
  5624. */
  5625. getNextControlIndex: function () {
  5626. const controls = this.controls;
  5627. const control = this.control;
  5628. const nextIndex = controls.indexOf( control ) + 1;
  5629. return ( nextIndex >= controls.length ) ? 0 : nextIndex;
  5630. },
  5631. /**
  5632. * Set field of view of camera
  5633. * @param {number} fov
  5634. * @memberOf Viewer
  5635. * @instance
  5636. */
  5637. setCameraFov: function ( fov ) {
  5638. this.camera.fov = fov;
  5639. this.camera.updateProjectionMatrix();
  5640. },
  5641. /**
  5642. * Enable control by index
  5643. * @param {CONTROLS} index - Index of camera control
  5644. * @memberOf Viewer
  5645. * @instance
  5646. */
  5647. enableControl: function ( index ) {
  5648. index = ( index >= 0 && index < this.controls.length ) ? index : 0;
  5649. this.control.enabled = false;
  5650. this.control = this.controls[ index ];
  5651. this.control.enabled = true;
  5652. switch ( index ) {
  5653. case CONTROLS.ORBIT:
  5654. this.camera.position.copy( this.panorama.position );
  5655. this.camera.position.z += 1;
  5656. break;
  5657. case CONTROLS.DEVICEORIENTATION:
  5658. this.camera.position.copy( this.panorama.position );
  5659. break;
  5660. default:
  5661. break;
  5662. }
  5663. this.control.update();
  5664. this.activateWidgetItem( index, undefined );
  5665. },
  5666. /**
  5667. * Disable current control
  5668. * @memberOf Viewer
  5669. * @instance
  5670. */
  5671. disableControl: function () {
  5672. this.control.enabled = false;
  5673. },
  5674. /**
  5675. * Toggle next control
  5676. * @memberOf Viewer
  5677. * @instance
  5678. */
  5679. toggleNextControl: function () {
  5680. this.enableControl( this.getNextControlIndex() );
  5681. },
  5682. /**
  5683. * Screen Space Projection
  5684. * @memberOf Viewer
  5685. * @instance
  5686. */
  5687. getScreenVector: function ( worldVector ) {
  5688. const vector = worldVector.clone();
  5689. const widthHalf = ( this.container.clientWidth ) / 2;
  5690. const heightHalf = this.container.clientHeight / 2;
  5691. vector.project( this.camera );
  5692. vector.x = ( vector.x * widthHalf ) + widthHalf;
  5693. vector.y = - ( vector.y * heightHalf ) + heightHalf;
  5694. vector.z = 0;
  5695. return vector;
  5696. },
  5697. /**
  5698. * Check Sprite in Viewport
  5699. * @memberOf Viewer
  5700. * @instance
  5701. */
  5702. checkSpriteInViewport: function ( sprite ) {
  5703. this.camera.matrixWorldInverse.getInverse( this.camera.matrixWorld );
  5704. this.cameraViewProjectionMatrix.multiplyMatrices( this.camera.projectionMatrix, this.camera.matrixWorldInverse );
  5705. this.cameraFrustum.setFromMatrix( this.cameraViewProjectionMatrix );
  5706. return sprite.visible && this.cameraFrustum.intersectsSprite( sprite );
  5707. },
  5708. /**
  5709. * Reverse dragging direction
  5710. * @memberOf Viewer
  5711. * @instance
  5712. */
  5713. reverseDraggingDirection: function () {
  5714. this.OrbitControls.rotateSpeed *= -1;
  5715. this.OrbitControls.momentumScalingFactor *= -1;
  5716. },
  5717. /**
  5718. * Add reticle
  5719. * @memberOf Viewer
  5720. * @instance
  5721. */
  5722. addReticle: function () {
  5723. this.reticle = new Reticle( 0xffffff, true, this.options.dwellTime );
  5724. this.reticle.hide();
  5725. this.camera.add( this.reticle );
  5726. this.sceneReticle.add( this.camera );
  5727. },
  5728. /**
  5729. * Tween control looking center
  5730. * @param {THREE.Vector3} vector - Vector to be looked at the center
  5731. * @param {number} [duration=1000] - Duration to tween
  5732. * @param {function} [easing=TWEEN.Easing.Exponential.Out] - Easing function
  5733. * @memberOf Viewer
  5734. * @instance
  5735. */
  5736. tweenControlCenter: function ( vector, duration, easing ) {
  5737. if ( this.control !== this.OrbitControls ) {
  5738. return;
  5739. }
  5740. // Pass in arguments as array
  5741. if ( vector instanceof Array ) {
  5742. duration = vector[ 1 ];
  5743. easing = vector[ 2 ];
  5744. vector = vector[ 0 ];
  5745. }
  5746. duration = duration !== undefined ? duration : 1000;
  5747. easing = easing || Tween.Easing.Exponential.Out;
  5748. let scope, ha, va, chv, cvv, hv, vv, vptc, ov, nv;
  5749. scope = this;
  5750. chv = this.camera.getWorldDirection( new THREE.Vector3() );
  5751. cvv = chv.clone();
  5752. vptc = this.panorama.getWorldPosition( new THREE.Vector3() ).sub( this.camera.getWorldPosition( new THREE.Vector3() ) );
  5753. hv = vector.clone();
  5754. // Scale effect
  5755. hv.x *= -1;
  5756. hv.add( vptc ).normalize();
  5757. vv = hv.clone();
  5758. chv.y = 0;
  5759. hv.y = 0;
  5760. ha = Math.atan2( hv.z, hv.x ) - Math.atan2( chv.z, chv.x );
  5761. ha = ha > Math.PI ? ha - 2 * Math.PI : ha;
  5762. ha = ha < -Math.PI ? ha + 2 * Math.PI : ha;
  5763. va = Math.abs( cvv.angleTo( chv ) + ( cvv.y * vv.y <= 0 ? vv.angleTo( hv ) : -vv.angleTo( hv ) ) );
  5764. va *= vv.y < cvv.y ? 1 : -1;
  5765. ov = { left: 0, up: 0 };
  5766. nv = { left: 0, up: 0 };
  5767. this.tweenLeftAnimation.stop();
  5768. this.tweenUpAnimation.stop();
  5769. this.tweenLeftAnimation = new Tween.Tween( ov )
  5770. .to( { left: ha }, duration )
  5771. .easing( easing )
  5772. .onUpdate(function(ov){
  5773. scope.control.rotateLeft( ov.left - nv.left );
  5774. nv.left = ov.left;
  5775. })
  5776. .start();
  5777. this.tweenUpAnimation = new Tween.Tween( ov )
  5778. .to( { up: va }, duration )
  5779. .easing( easing )
  5780. .onUpdate(function(ov){
  5781. scope.control.rotateUp( ov.up - nv.up );
  5782. nv.up = ov.up;
  5783. })
  5784. .start();
  5785. },
  5786. /**
  5787. * Tween control looking center by object
  5788. * @param {THREE.Object3D} object - Object to be looked at the center
  5789. * @param {number} [duration=1000] - Duration to tween
  5790. * @param {function} [easing=TWEEN.Easing.Exponential.Out] - Easing function
  5791. * @memberOf Viewer
  5792. * @instance
  5793. */
  5794. tweenControlCenterByObject: function ( object, duration, easing ) {
  5795. let isUnderScalePlaceHolder = false;
  5796. object.traverseAncestors( function ( ancestor ) {
  5797. if ( ancestor.scalePlaceHolder ) {
  5798. isUnderScalePlaceHolder = true;
  5799. }
  5800. } );
  5801. if ( isUnderScalePlaceHolder ) {
  5802. const invertXVector = new THREE.Vector3( -1, 1, 1 );
  5803. this.tweenControlCenter( object.getWorldPosition( new THREE.Vector3() ).multiply( invertXVector ), duration, easing );
  5804. } else {
  5805. this.tweenControlCenter( object.getWorldPosition( new THREE.Vector3() ), duration, easing );
  5806. }
  5807. },
  5808. /**
  5809. * This is called when window size is changed
  5810. * @fires Viewer#window-resize
  5811. * @param {number} [windowWidth] - Specify if custom element has changed width
  5812. * @param {number} [windowHeight] - Specify if custom element has changed height
  5813. * @memberOf Viewer
  5814. * @instance
  5815. */
  5816. onWindowResize: function ( windowWidth, windowHeight ) {
  5817. let width, height;
  5818. const expand = this.container.classList.contains( 'panolens-container' ) || this.container.isFullscreen;
  5819. if ( windowWidth !== undefined && windowHeight !== undefined ) {
  5820. width = windowWidth;
  5821. height = windowHeight;
  5822. this.container._width = windowWidth;
  5823. this.container._height = windowHeight;
  5824. } else {
  5825. const isAndroid = /(android)/i.test(window.navigator.userAgent);
  5826. const adjustWidth = isAndroid
  5827. ? Math.min(document.documentElement.clientWidth, window.innerWidth || 0)
  5828. : Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  5829. const adjustHeight = isAndroid
  5830. ? Math.min(document.documentElement.clientHeight, window.innerHeight || 0)
  5831. : Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
  5832. width = expand ? adjustWidth : this.container.clientWidth;
  5833. height = expand ? adjustHeight : this.container.clientHeight;
  5834. this.container._width = width;
  5835. this.container._height = height;
  5836. }
  5837. this.camera.aspect = width / height;
  5838. this.camera.updateProjectionMatrix();
  5839. this.renderer.setSize( width, height );
  5840. // Update reticle
  5841. if ( this.options.enableReticle || this.tempEnableReticle ) {
  5842. this.updateReticleEvent();
  5843. }
  5844. /**
  5845. * Window resizing event
  5846. * @type {object}
  5847. * @event Viewer#window-resize
  5848. * @property {number} width - Width of the window
  5849. * @property {number} height - Height of the window
  5850. */
  5851. this.dispatchEvent( { type: 'window-resize', width: width, height: height });
  5852. this.scene.traverse( function ( object ) {
  5853. if ( object.dispatchEvent ) {
  5854. object.dispatchEvent( { type: 'window-resize', width: width, height: height });
  5855. }
  5856. } );
  5857. },
  5858. /**
  5859. * Add output element
  5860. * @memberOf Viewer
  5861. * @instance
  5862. */
  5863. addOutputElement: function () {
  5864. const element = document.createElement( 'div' );
  5865. element.style.position = 'absolute';
  5866. element.style.right = '10px';
  5867. element.style.top = '10px';
  5868. element.style.color = '#fff';
  5869. this.container.appendChild( element );
  5870. this.outputDivElement = element;
  5871. },
  5872. /**
  5873. * Output position in developer console by holding down Ctrl button
  5874. * @memberOf Viewer
  5875. * @instance
  5876. */
  5877. outputPosition: function () {
  5878. const intersects = this.raycaster.intersectObject( this.panorama, true );
  5879. if ( intersects.length > 0 ) {
  5880. const point = intersects[ 0 ].point.clone();
  5881. const converter = new THREE.Vector3( -1, 1, 1 );
  5882. const world = this.panorama.getWorldPosition( new THREE.Vector3() );
  5883. point.sub( world ).multiply( converter );
  5884. const position = {
  5885. x: point.x.toFixed(2),
  5886. y: point.y.toFixed(2),
  5887. z: point.z.toFixed(2),
  5888. };
  5889. const message = `${position.x}, ${position.y}, ${position.z}`;
  5890. if ( point.length() === 0 ) { return; }
  5891. switch ( this.options.output ) {
  5892. case 'event':
  5893. /**
  5894. * Dispatch raycast position as event
  5895. * @type {object}
  5896. * @event Viewer#position-output
  5897. */
  5898. this.dispatchEvent( { type: 'position-output', position: position } );
  5899. break;
  5900. case 'console':
  5901. console.info( message );
  5902. break;
  5903. case 'overlay':
  5904. this.outputDivElement.textContent = message;
  5905. break;
  5906. default:
  5907. break;
  5908. }
  5909. }
  5910. },
  5911. /**
  5912. * On mouse down
  5913. * @param {MouseEvent} event
  5914. * @memberOf Viewer
  5915. * @instance
  5916. */
  5917. onMouseDown: function ( event ) {
  5918. event.preventDefault();
  5919. this.userMouse.x = ( event.clientX >= 0 ) ? event.clientX : event.touches[0].clientX;
  5920. this.userMouse.y = ( event.clientY >= 0 ) ? event.clientY : event.touches[0].clientY;
  5921. this.userMouse.type = 'mousedown';
  5922. this.onTap( event );
  5923. },
  5924. /**
  5925. * On mouse move
  5926. * @param {MouseEvent} event
  5927. * @memberOf Viewer
  5928. * @instance
  5929. */
  5930. onMouseMove: function ( event ) {
  5931. event.preventDefault();
  5932. this.userMouse.type = 'mousemove';
  5933. this.onTap( event );
  5934. },
  5935. /**
  5936. * On mouse up
  5937. * @param {MouseEvent} event
  5938. * @memberOf Viewer
  5939. * @instance
  5940. */
  5941. onMouseUp: function ( event ) {
  5942. let onTarget = false;
  5943. this.userMouse.type = 'mouseup';
  5944. const type = ( this.userMouse.x >= event.clientX - this.options.clickTolerance
  5945. && this.userMouse.x <= event.clientX + this.options.clickTolerance
  5946. && this.userMouse.y >= event.clientY - this.options.clickTolerance
  5947. && this.userMouse.y <= event.clientY + this.options.clickTolerance )
  5948. || ( event.changedTouches
  5949. && this.userMouse.x >= event.changedTouches[0].clientX - this.options.clickTolerance
  5950. && this.userMouse.x <= event.changedTouches[0].clientX + this.options.clickTolerance
  5951. && this.userMouse.y >= event.changedTouches[0].clientY - this.options.clickTolerance
  5952. && this.userMouse.y <= event.changedTouches[0].clientY + this.options.clickTolerance )
  5953. ? 'click' : undefined;
  5954. // Event should happen on canvas
  5955. if ( event && event.target && !event.target.classList.contains( 'panolens-canvas' ) ) { return; }
  5956. event.preventDefault();
  5957. if ( event.changedTouches && event.changedTouches.length === 1 ) {
  5958. onTarget = this.onTap( { clientX: event.changedTouches[0].clientX, clientY: event.changedTouches[0].clientY }, type );
  5959. } else {
  5960. onTarget = this.onTap( event, type );
  5961. }
  5962. this.userMouse.type = 'none';
  5963. if ( onTarget ) {
  5964. return;
  5965. }
  5966. if ( type === 'click' ) {
  5967. const { options: { autoHideInfospot, autoHideControlBar }, panorama, toggleControlBar } = this;
  5968. if ( autoHideInfospot && panorama ) {
  5969. panorama.toggleInfospotVisibility();
  5970. }
  5971. if ( autoHideControlBar ) {
  5972. toggleControlBar();
  5973. }
  5974. }
  5975. },
  5976. /**
  5977. * On tap eveny frame
  5978. * @param {MouseEvent} event
  5979. * @param {string} type
  5980. * @memberOf Viewer
  5981. * @instance
  5982. */
  5983. onTap: function ( event, type ) {
  5984. const { left, top } = this.container.getBoundingClientRect();
  5985. const { clientWidth, clientHeight } = this.container;
  5986. this.raycasterPoint.x = ( ( event.clientX - left ) / clientWidth ) * 2 - 1;
  5987. this.raycasterPoint.y = - ( ( event.clientY - top ) / clientHeight ) * 2 + 1;
  5988. this.raycaster.setFromCamera( this.raycasterPoint, this.camera );
  5989. // Return if no panorama
  5990. if ( !this.panorama ) {
  5991. return;
  5992. }
  5993. // output infospot information
  5994. if ( event.type !== 'mousedown' && this.touchSupported || this.OUTPUT_INFOSPOT ) {
  5995. this.outputPosition();
  5996. }
  5997. const intersects = this.raycaster.intersectObjects( this.panorama.children, true );
  5998. const intersect_entity = this.getConvertedIntersect( intersects );
  5999. const intersect = ( intersects.length > 0 ) ? intersects[0].object : undefined;
  6000. if ( this.userMouse.type === 'mouseup' ) {
  6001. if ( intersect_entity && this.pressEntityObject === intersect_entity && this.pressEntityObject.dispatchEvent ) {
  6002. this.pressEntityObject.dispatchEvent( { type: 'pressstop-entity', mouseEvent: event } );
  6003. }
  6004. this.pressEntityObject = undefined;
  6005. }
  6006. if ( this.userMouse.type === 'mouseup' ) {
  6007. if ( intersect && this.pressObject === intersect && this.pressObject.dispatchEvent ) {
  6008. this.pressObject.dispatchEvent( { type: 'pressstop', mouseEvent: event } );
  6009. }
  6010. this.pressObject = undefined;
  6011. }
  6012. if ( type === 'click' ) {
  6013. this.panorama.dispatchEvent( { type: 'click', intersects: intersects, mouseEvent: event } );
  6014. if ( intersect_entity && intersect_entity.dispatchEvent ) {
  6015. intersect_entity.dispatchEvent( { type: 'click-entity', mouseEvent: event } );
  6016. }
  6017. if ( intersect && intersect.dispatchEvent ) {
  6018. intersect.dispatchEvent( { type: 'click', mouseEvent: event } );
  6019. }
  6020. } else {
  6021. this.panorama.dispatchEvent( { type: 'hover', intersects: intersects, mouseEvent: event } );
  6022. if ( ( this.hoverObject && intersects.length > 0 && this.hoverObject !== intersect_entity )
  6023. || ( this.hoverObject && intersects.length === 0 ) ){
  6024. if ( this.hoverObject.dispatchEvent ) {
  6025. this.hoverObject.dispatchEvent( { type: 'hoverleave', mouseEvent: event } );
  6026. this.reticle.end();
  6027. }
  6028. this.hoverObject = undefined;
  6029. }
  6030. if ( intersect_entity && intersects.length > 0 ) {
  6031. if ( this.hoverObject !== intersect_entity ) {
  6032. this.hoverObject = intersect_entity;
  6033. if ( this.hoverObject.dispatchEvent ) {
  6034. this.hoverObject.dispatchEvent( { type: 'hoverenter', mouseEvent: event } );
  6035. // Start reticle timer
  6036. if ( this.options.autoReticleSelect && this.options.enableReticle || this.tempEnableReticle ) {
  6037. this.reticle.start( this.onTap.bind( this, event, 'click' ) );
  6038. }
  6039. }
  6040. }
  6041. if ( this.userMouse.type === 'mousedown' && this.pressEntityObject != intersect_entity ) {
  6042. this.pressEntityObject = intersect_entity;
  6043. if ( this.pressEntityObject.dispatchEvent ) {
  6044. this.pressEntityObject.dispatchEvent( { type: 'pressstart-entity', mouseEvent: event } );
  6045. }
  6046. }
  6047. if ( this.userMouse.type === 'mousedown' && this.pressObject != intersect ) {
  6048. this.pressObject = intersect;
  6049. if ( this.pressObject.dispatchEvent ) {
  6050. this.pressObject.dispatchEvent( { type: 'pressstart', mouseEvent: event } );
  6051. }
  6052. }
  6053. if ( this.userMouse.type === 'mousemove' || this.options.enableReticle ) {
  6054. if ( intersect && intersect.dispatchEvent ) {
  6055. intersect.dispatchEvent( { type: 'hover', mouseEvent: event } );
  6056. }
  6057. if ( this.pressEntityObject && this.pressEntityObject.dispatchEvent ) {
  6058. this.pressEntityObject.dispatchEvent( { type: 'pressmove-entity', mouseEvent: event } );
  6059. }
  6060. if ( this.pressObject && this.pressObject.dispatchEvent ) {
  6061. this.pressObject.dispatchEvent( { type: 'pressmove', mouseEvent: event } );
  6062. }
  6063. }
  6064. }
  6065. if ( !intersect_entity && this.pressEntityObject && this.pressEntityObject.dispatchEvent ) {
  6066. this.pressEntityObject.dispatchEvent( { type: 'pressstop-entity', mouseEvent: event } );
  6067. this.pressEntityObject = undefined;
  6068. }
  6069. if ( !intersect && this.pressObject && this.pressObject.dispatchEvent ) {
  6070. this.pressObject.dispatchEvent( { type: 'pressstop', mouseEvent: event } );
  6071. this.pressObject = undefined;
  6072. }
  6073. }
  6074. // Infospot handler
  6075. if ( intersect && intersect instanceof Infospot ) {
  6076. this.infospot = intersect;
  6077. if ( type === 'click' ) {
  6078. return true;
  6079. }
  6080. } else if ( this.infospot ) {
  6081. this.hideInfospot();
  6082. }
  6083. // Auto rotate
  6084. if ( this.options.autoRotate && this.userMouse.type !== 'mousemove' ) {
  6085. // Auto-rotate idle timer
  6086. clearTimeout( this.autoRotateRequestId );
  6087. if ( this.control === this.OrbitControls ) {
  6088. this.OrbitControls.autoRotate = false;
  6089. this.autoRotateRequestId = window.setTimeout( this.enableAutoRate.bind( this ), this.options.autoRotateActivationDuration );
  6090. }
  6091. }
  6092. },
  6093. /**
  6094. * Get converted intersect
  6095. * @param {array} intersects
  6096. * @memberOf Viewer
  6097. * @instance
  6098. */
  6099. getConvertedIntersect: function ( intersects ) {
  6100. let intersect;
  6101. for ( let i = 0; i < intersects.length; i++ ) {
  6102. if ( intersects[i].distance >= 0 && intersects[i].object && !intersects[i].object.passThrough ) {
  6103. if ( intersects[i].object.entity && intersects[i].object.entity.passThrough ) {
  6104. continue;
  6105. } else if ( intersects[i].object.entity && !intersects[i].object.entity.passThrough ) {
  6106. intersect = intersects[i].object.entity;
  6107. break;
  6108. } else {
  6109. intersect = intersects[i].object;
  6110. break;
  6111. }
  6112. }
  6113. }
  6114. return intersect;
  6115. },
  6116. /**
  6117. * Hide infospot
  6118. * @memberOf Viewer
  6119. * @instance
  6120. */
  6121. hideInfospot: function () {
  6122. if ( this.infospot ) {
  6123. this.infospot.onHoverEnd();
  6124. this.infospot = undefined;
  6125. }
  6126. },
  6127. /**
  6128. * Toggle control bar
  6129. * @memberOf Viewer
  6130. * @instance
  6131. * @fires Viewer#control-bar-toggle
  6132. */
  6133. toggleControlBar: function () {
  6134. const { widget } = this;
  6135. /**
  6136. * Toggle control bar event
  6137. * @type {object}
  6138. * @event Viewer#control-bar-toggle
  6139. */
  6140. if ( widget ) {
  6141. widget.dispatchEvent( { type: 'control-bar-toggle' } );
  6142. }
  6143. },
  6144. /**
  6145. * On key down
  6146. * @param {KeyboardEvent} event
  6147. * @memberOf Viewer
  6148. * @instance
  6149. */
  6150. onKeyDown: function ( event ) {
  6151. if ( this.options.output && this.options.output !== 'none' && event.key === 'Control' ) {
  6152. this.OUTPUT_INFOSPOT = true;
  6153. }
  6154. },
  6155. /**
  6156. * On key up
  6157. * @param {KeyboardEvent} event
  6158. * @memberOf Viewer
  6159. * @instance
  6160. */
  6161. onKeyUp: function () {
  6162. this.OUTPUT_INFOSPOT = false;
  6163. },
  6164. /**
  6165. * Update control and callbacks
  6166. * @memberOf Viewer
  6167. * @instance
  6168. */
  6169. update: function () {
  6170. Tween.update();
  6171. this.updateCallbacks.forEach( function( callback ){ callback(); } );
  6172. this.control.update();
  6173. this.scene.traverse( function( child ){
  6174. if ( child instanceof Infospot
  6175. && child.element
  6176. && ( this.hoverObject === child
  6177. || child.element.style.display !== 'none'
  6178. || (child.element.left && child.element.left.style.display !== 'none')
  6179. || (child.element.right && child.element.right.style.display !== 'none') ) ) {
  6180. if ( this.checkSpriteInViewport( child ) ) {
  6181. const { x, y } = this.getScreenVector( child.getWorldPosition( new THREE.Vector3() ) );
  6182. child.translateElement( x, y );
  6183. } else {
  6184. child.onDismiss();
  6185. }
  6186. }
  6187. }.bind( this ) );
  6188. },
  6189. /**
  6190. * Rendering function to be called on every animation frame
  6191. * Render reticle last
  6192. * @memberOf Viewer
  6193. * @instance
  6194. */
  6195. render: function () {
  6196. if ( this.mode === MODES.CARDBOARD || this.mode === MODES.STEREO ) {
  6197. this.renderer.clear();
  6198. this.effect.render( this.scene, this.camera );
  6199. this.effect.render( this.sceneReticle, this.camera );
  6200. } else {
  6201. this.renderer.clear();
  6202. this.renderer.render( this.scene, this.camera );
  6203. this.renderer.clearDepth();
  6204. this.renderer.render( this.sceneReticle, this.camera );
  6205. }
  6206. },
  6207. /**
  6208. * Animate
  6209. * @memberOf Viewer
  6210. * @instance
  6211. */
  6212. animate: function () {
  6213. this.requestAnimationId = window.requestAnimationFrame( this.animate.bind( this ) );
  6214. this.onChange();
  6215. },
  6216. /**
  6217. * On change
  6218. * @memberOf Viewer
  6219. * @instance
  6220. */
  6221. onChange: function () {
  6222. this.update();
  6223. this.render();
  6224. },
  6225. /**
  6226. * Register mouse and touch event on container
  6227. * @memberOf Viewer
  6228. * @instance
  6229. */
  6230. registerMouseAndTouchEvents: function () {
  6231. const options = { passive: false };
  6232. this.container.addEventListener( 'mousedown' , this.HANDLER_MOUSE_DOWN, options );
  6233. this.container.addEventListener( 'mousemove' , this.HANDLER_MOUSE_MOVE, options );
  6234. this.container.addEventListener( 'mouseup' , this.HANDLER_MOUSE_UP , options );
  6235. this.container.addEventListener( 'touchstart', this.HANDLER_MOUSE_DOWN, options );
  6236. this.container.addEventListener( 'touchend' , this.HANDLER_MOUSE_UP , options );
  6237. },
  6238. /**
  6239. * Unregister mouse and touch event on container
  6240. * @memberOf Viewer
  6241. * @instance
  6242. */
  6243. unregisterMouseAndTouchEvents: function () {
  6244. this.container.removeEventListener( 'mousedown' , this.HANDLER_MOUSE_DOWN, false );
  6245. this.container.removeEventListener( 'mousemove' , this.HANDLER_MOUSE_MOVE, false );
  6246. this.container.removeEventListener( 'mouseup' , this.HANDLER_MOUSE_UP , false );
  6247. this.container.removeEventListener( 'touchstart', this.HANDLER_MOUSE_DOWN, false );
  6248. this.container.removeEventListener( 'touchend' , this.HANDLER_MOUSE_UP , false );
  6249. },
  6250. /**
  6251. * Register reticle event
  6252. * @memberOf Viewer
  6253. * @instance
  6254. */
  6255. registerReticleEvent: function () {
  6256. this.addUpdateCallback( this.HANDLER_TAP );
  6257. },
  6258. /**
  6259. * Unregister reticle event
  6260. * @memberOf Viewer
  6261. * @instance
  6262. */
  6263. unregisterReticleEvent: function () {
  6264. this.removeUpdateCallback( this.HANDLER_TAP );
  6265. },
  6266. /**
  6267. * Update reticle event
  6268. * @memberOf Viewer
  6269. * @instance
  6270. */
  6271. updateReticleEvent: function () {
  6272. const clientX = this.container.clientWidth / 2 + this.container.offsetLeft;
  6273. const clientY = this.container.clientHeight / 2;
  6274. this.removeUpdateCallback( this.HANDLER_TAP );
  6275. this.HANDLER_TAP = this.onTap.bind( this, { clientX, clientY } );
  6276. this.addUpdateCallback( this.HANDLER_TAP );
  6277. },
  6278. /**
  6279. * Register container and window listeners
  6280. * @memberOf Viewer
  6281. * @instance
  6282. */
  6283. registerEventListeners: function () {
  6284. // Resize Event
  6285. window.addEventListener( 'resize' , this.HANDLER_WINDOW_RESIZE, true );
  6286. // Keyboard Event
  6287. window.addEventListener( 'keydown', this.HANDLER_KEY_DOWN, true );
  6288. window.addEventListener( 'keyup' , this.HANDLER_KEY_UP , true );
  6289. },
  6290. /**
  6291. * Unregister container and window listeners
  6292. * @memberOf Viewer
  6293. * @instance
  6294. */
  6295. unregisterEventListeners: function () {
  6296. // Resize Event
  6297. window.removeEventListener( 'resize' , this.HANDLER_WINDOW_RESIZE, true );
  6298. // Keyboard Event
  6299. window.removeEventListener( 'keydown', this.HANDLER_KEY_DOWN, true );
  6300. window.removeEventListener( 'keyup' , this.HANDLER_KEY_UP , true );
  6301. },
  6302. /**
  6303. * Dispose all scene objects and clear cache
  6304. * @memberOf Viewer
  6305. * @instance
  6306. */
  6307. dispose: function () {
  6308. this.tweenLeftAnimation.stop();
  6309. this.tweenUpAnimation.stop();
  6310. // Unregister dom event listeners
  6311. this.unregisterEventListeners();
  6312. // recursive disposal on 3d objects
  6313. function recursiveDispose ( object ) {
  6314. for ( let i = object.children.length - 1; i >= 0; i-- ) {
  6315. recursiveDispose( object.children[i] );
  6316. object.remove( object.children[i] );
  6317. }
  6318. if ( object instanceof Panorama || object instanceof Infospot ) {
  6319. object.dispose();
  6320. object = null;
  6321. } else if ( object.dispatchEvent ){
  6322. object.dispatchEvent( 'dispose' );
  6323. }
  6324. }
  6325. recursiveDispose( this.scene );
  6326. // dispose widget
  6327. if ( this.widget ) {
  6328. this.widget.dispose();
  6329. this.widget = null;
  6330. }
  6331. // clear cache
  6332. if ( THREE.Cache && THREE.Cache.enabled ) {
  6333. THREE.Cache.clear();
  6334. }
  6335. },
  6336. /**
  6337. * Destroy viewer by disposing and stopping requestAnimationFrame
  6338. * @memberOf Viewer
  6339. * @instance
  6340. */
  6341. destroy: function () {
  6342. this.dispose();
  6343. this.render();
  6344. window.cancelAnimationFrame( this.requestAnimationId );
  6345. },
  6346. /**
  6347. * On panorama dispose
  6348. * @memberOf Viewer
  6349. * @instance
  6350. */
  6351. onPanoramaDispose: function ( panorama ) {
  6352. if ( panorama instanceof VideoPanorama ) {
  6353. this.hideVideoWidget();
  6354. }
  6355. if ( panorama === this.panorama ) {
  6356. this.panorama = null;
  6357. }
  6358. },
  6359. /**
  6360. * Load ajax call
  6361. * @param {string} url - URL to be requested
  6362. * @param {function} [callback] - Callback after request completes
  6363. * @memberOf Viewer
  6364. * @instance
  6365. */
  6366. loadAsyncRequest: function ( url, callback = () => {} ) {
  6367. const request = new window.XMLHttpRequest();
  6368. request.onloadend = function ( event ) {
  6369. callback( event );
  6370. };
  6371. request.open( 'GET', url, true );
  6372. request.send( null );
  6373. },
  6374. /**
  6375. * View indicator in upper left
  6376. * @memberOf Viewer
  6377. * @instance
  6378. */
  6379. addViewIndicator: function () {
  6380. const scope = this;
  6381. function loadViewIndicator ( asyncEvent ) {
  6382. if ( asyncEvent.loaded === 0 ) return;
  6383. const viewIndicatorDiv = asyncEvent.target.responseXML.documentElement;
  6384. viewIndicatorDiv.style.width = scope.viewIndicatorSize + 'px';
  6385. viewIndicatorDiv.style.height = scope.viewIndicatorSize + 'px';
  6386. viewIndicatorDiv.style.position = 'absolute';
  6387. viewIndicatorDiv.style.top = '10px';
  6388. viewIndicatorDiv.style.left = '10px';
  6389. viewIndicatorDiv.style.opacity = '0.5';
  6390. viewIndicatorDiv.style.cursor = 'pointer';
  6391. viewIndicatorDiv.id = 'panolens-view-indicator-container';
  6392. scope.container.appendChild( viewIndicatorDiv );
  6393. const indicator = viewIndicatorDiv.querySelector( '#indicator' );
  6394. const setIndicatorD = function () {
  6395. scope.radius = scope.viewIndicatorSize * 0.225;
  6396. scope.currentPanoAngle = scope.camera.rotation.y - THREE.Math.degToRad( 90 );
  6397. scope.fovAngle = THREE.Math.degToRad( scope.camera.fov ) ;
  6398. scope.leftAngle = -scope.currentPanoAngle - scope.fovAngle / 2;
  6399. scope.rightAngle = -scope.currentPanoAngle + scope.fovAngle / 2;
  6400. scope.leftX = scope.radius * Math.cos( scope.leftAngle );
  6401. scope.leftY = scope.radius * Math.sin( scope.leftAngle );
  6402. scope.rightX = scope.radius * Math.cos( scope.rightAngle );
  6403. scope.rightY = scope.radius * Math.sin( scope.rightAngle );
  6404. scope.indicatorD = 'M ' + scope.leftX + ' ' + scope.leftY + ' A ' + scope.radius + ' ' + scope.radius + ' 0 0 1 ' + scope.rightX + ' ' + scope.rightY;
  6405. if ( scope.leftX && scope.leftY && scope.rightX && scope.rightY && scope.radius ) {
  6406. indicator.setAttribute( 'd', scope.indicatorD );
  6407. }
  6408. };
  6409. scope.addUpdateCallback( setIndicatorD );
  6410. const indicatorOnMouseEnter = function () {
  6411. this.style.opacity = '1';
  6412. };
  6413. const indicatorOnMouseLeave = function () {
  6414. this.style.opacity = '0.5';
  6415. };
  6416. viewIndicatorDiv.addEventListener( 'mouseenter', indicatorOnMouseEnter );
  6417. viewIndicatorDiv.addEventListener( 'mouseleave', indicatorOnMouseLeave );
  6418. }
  6419. this.loadAsyncRequest( DataImage.ViewIndicator, loadViewIndicator );
  6420. },
  6421. /**
  6422. * Append custom control item to existing control bar
  6423. * @param {object} [option={}] - Style object to overwirte default element style. It takes 'style', 'onTap' and 'group' properties.
  6424. * @memberOf Viewer
  6425. * @instance
  6426. */
  6427. appendControlItem: function ( option ) {
  6428. const item = this.widget.createCustomItem( option );
  6429. if ( option.group === 'video' ) {
  6430. this.widget.videoElement.appendChild( item );
  6431. } else {
  6432. this.widget.barElement.appendChild( item );
  6433. }
  6434. return item;
  6435. },
  6436. /**
  6437. * Clear all cached files
  6438. * @memberOf Viewer
  6439. * @instance
  6440. */
  6441. clearAllCache: function () {
  6442. THREE.Cache.clear();
  6443. }
  6444. } );
  6445. if ( THREE.REVISION != THREE_REVISION ) {
  6446. console.warn( `three.js version is not matched. Please consider use the target revision ${THREE_REVISION}` );
  6447. }
  6448. /**
  6449. * Panolens.js
  6450. * @author pchen66
  6451. * @namespace PANOLENS
  6452. */
  6453. window.TWEEN = Tween;
  6454. exports.BasicPanorama = BasicPanorama;
  6455. exports.CONTROLS = CONTROLS;
  6456. exports.CameraPanorama = CameraPanorama;
  6457. exports.CubePanorama = CubePanorama;
  6458. exports.CubeTextureLoader = CubeTextureLoader;
  6459. exports.DataImage = DataImage;
  6460. exports.EmptyPanorama = EmptyPanorama;
  6461. exports.GoogleStreetviewPanorama = GoogleStreetviewPanorama;
  6462. exports.ImageLittlePlanet = ImageLittlePlanet;
  6463. exports.ImageLoader = ImageLoader;
  6464. exports.ImagePanorama = ImagePanorama;
  6465. exports.Infospot = Infospot;
  6466. exports.LittlePlanet = LittlePlanet;
  6467. exports.MODES = MODES;
  6468. exports.Media = Media;
  6469. exports.Panorama = Panorama;
  6470. exports.REVISION = REVISION;
  6471. exports.Reticle = Reticle;
  6472. exports.THREE_REVISION = THREE_REVISION;
  6473. exports.THREE_VERSION = THREE_VERSION;
  6474. exports.TextureLoader = TextureLoader;
  6475. exports.VERSION = VERSION;
  6476. exports.VideoPanorama = VideoPanorama;
  6477. exports.Viewer = Viewer;
  6478. exports.Widget = Widget;
  6479. Object.defineProperty(exports, '__esModule', { value: true });
  6480. }));