common.js 2.3 KB

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