common.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.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. video.onloadeddata = () => {
  65. resolve(video);
  66. }
  67. }
  68. });
  69. },
  70. createVideoElement0: (path) => {
  71. let videoName = path.split("/")[path.split("/").length-1].split(".")[0]
  72. let oldVideo = document.getElementById(videoName)
  73. if(oldVideo) {
  74. oldVideo.currentTime = 0
  75. oldVideo.isLoaded = true
  76. return oldVideo
  77. }
  78. let video = document.createElement("video")
  79. video.src = path
  80. video.id = videoName
  81. video.crossOrigin = "anonymous"
  82. video.playsinline = "playsinline"
  83. video.autoplay = "autoplay"
  84. video.muted = "muted"
  85. document.getElementById("videoTextureBox").appendChild(video)
  86. return video
  87. },
  88. getLengthBetweenVec3: (v1, v2) => {
  89. return Math.sqrt(
  90. (v1.x - v2.x) * (v1.x - v2.x) +
  91. (v1.y - v2.y) * (v1.y - v2.y) +
  92. (v1.z - v2.z) * (v1.z - v2.z)
  93. )
  94. }
  95. }