common.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. export default {
  2. uuid: () => {
  3. let S4 = () => {
  4. return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
  5. }
  6. return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
  7. },
  8. postData: (url, data) => {
  9. return fetch(url, {
  10. body: JSON.stringify(data),
  11. // cache: 'no-cache',
  12. // credentials: 'same-origin',
  13. headers: {
  14. // 'user-agent': 'Mozilla/4.0 MDN Example',
  15. 'content-type': 'application/json'
  16. },
  17. method: 'POST',
  18. // mode: 'cors',
  19. // redirect: 'follow',
  20. // referrer: 'no-referrer',
  21. })
  22. .then(response => response.json())
  23. },
  24. createVideoElement: (path) => {
  25. return new Promise((resolve, reject) => {
  26. let videoName = path.split("/")[path.split("/").length-1].split(".")[0]
  27. let oldVideo = document.getElementById(videoName)
  28. if(oldVideo) {
  29. oldVideo.currentTime = 0
  30. oldVideo.isLoaded = true
  31. resolve(oldVideo)
  32. }
  33. else {
  34. let video = document.createElement("video")
  35. video.src = path
  36. video.id = videoName
  37. video.crossOrigin = "anonymous"
  38. video.playsinline = "playsinline"
  39. video.autoplay = "autoplay"
  40. video.muted = "muted"
  41. document.getElementById("videoTextureBox").appendChild(video)
  42. video.onloadeddata = () => {
  43. resolve(video);
  44. }
  45. }
  46. });
  47. },
  48. createVideoElement0: (path) => {
  49. let videoName = path.split("/")[path.split("/").length-1].split(".")[0]
  50. let oldVideo = document.getElementById(videoName)
  51. if(oldVideo) {
  52. oldVideo.currentTime = 0
  53. oldVideo.isLoaded = true
  54. return oldVideo
  55. }
  56. let video = document.createElement("video")
  57. video.src = path
  58. video.id = videoName
  59. video.crossOrigin = "anonymous"
  60. video.playsinline = "playsinline"
  61. video.autoplay = "autoplay"
  62. video.muted = "muted"
  63. document.getElementById("videoTextureBox").appendChild(video)
  64. return video
  65. },
  66. getLengthBetweenVec3: (v1, v2) => {
  67. return Math.sqrt(
  68. (v1.x - v2.x) * (v1.x - v2.x) +
  69. (v1.y - v2.y) * (v1.y - v2.y) +
  70. (v1.z - v2.z) * (v1.z - v2.z)
  71. )
  72. }
  73. }