common.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. vec3UE4ToBABYLON(vec) {
  9. return BABYLON.Vector3.TransformCoordinates(
  10. new BABYLON.Vector3(vec.x, vec.y, vec.z),
  11. BABYLON.Matrix.FromArray([
  12. -0.01, 0, 0, 0,
  13. 0, 0, 0.01, 0,
  14. 0, 0.01, 0, 0,
  15. 0, 0, 0, 1
  16. ])
  17. )
  18. },
  19. vec3BABYLONToUE4(vec) {
  20. return BABYLON.Vector3.TransformCoordinates(
  21. new BABYLON.Vector3(vec.x, vec.y, vec.z),
  22. BABYLON.Matrix.FromArray([
  23. -100, 0, 0, 0,
  24. 0, 0, 100, 0,
  25. 0, 100, 0, 0,
  26. 0, 0, 0, 1
  27. ])
  28. )
  29. },
  30. postData: (url, data) => {
  31. return fetch(url, {
  32. body: JSON.stringify(data),
  33. // cache: 'no-cache',
  34. // credentials: 'same-origin',
  35. headers: {
  36. // 'user-agent': 'Mozilla/4.0 MDN Example',
  37. 'content-type': 'application/json'
  38. },
  39. method: 'POST',
  40. // mode: 'cors',
  41. // redirect: 'follow',
  42. // referrer: 'no-referrer',
  43. })
  44. .then(response => response.json())
  45. },
  46. createVideoElement: (path) => {
  47. return new Promise((resolve, reject) => {
  48. let videoName = path.split("/")[path.split("/").length-1].split(".")[0]
  49. let oldVideo = document.getElementById(videoName)
  50. if(oldVideo) {
  51. oldVideo.currentTime = 0
  52. oldVideo.isLoaded = true
  53. resolve(oldVideo)
  54. }
  55. else {
  56. let video = document.createElement("video")
  57. video.id = videoName
  58. video.crossOrigin = "anonymous"
  59. // video.playsinline = "true"
  60. video.setAttribute("playsinline", "playsinline")
  61. video.setAttribute("x5-playsinline", "true")
  62. video.setAttribute("webkit-playsinline", "true")
  63. video.setAttribute("x5-video-player-type", "h5")
  64. video.setAttribute("controls", "true")
  65. // video.controls="true"
  66. video.muted = "muted"
  67. video.autoplay = "autoplay"
  68. video.preload = "auto"
  69. video.src = path
  70. // document.getElementById("videoTextureBox").appendChild(video)
  71. video.onloadeddata = () => {
  72. resolve(video);
  73. }
  74. }
  75. });
  76. },
  77. createVideoElement0: (path) => {
  78. let videoName = path.split("/")[path.split("/").length-1].split(".mp4")[0]
  79. let oldVideo = document.getElementById(videoName)
  80. if(oldVideo) {
  81. oldVideo.currentTime = 0
  82. oldVideo.isLoaded = true
  83. return oldVideo
  84. }
  85. let video = document.createElement("video")
  86. video.src = path
  87. video.id = videoName
  88. video.crossOrigin = "anonymous"
  89. video.autoplay = "autoplay"
  90. video.preload = "auto"
  91. video.muted = "muted"
  92. video.setAttribute("playsinline", "true")
  93. video.setAttribute("x5-playsinline", "true")
  94. video.setAttribute("webkit-playsinline", "true")
  95. video.setAttribute("x5-video-player-type", "h5")
  96. video.setAttribute("controls", "true")
  97. return video
  98. },
  99. getLengthBetweenVec3: (v1, v2) => {
  100. return Math.sqrt(
  101. (v1.x - v2.x) * (v1.x - v2.x) +
  102. (v1.y - v2.y) * (v1.y - v2.y) +
  103. (v1.z - v2.z) * (v1.z - v2.z)
  104. )
  105. }
  106. }