123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- export default {
- uuid: () => {
- let S4 = () => {
- return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
- }
- return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
- },
- vec3UE4ToBABYLON(vec) {
- return BABYLON.Vector3.TransformCoordinates(
- new BABYLON.Vector3(vec.x, vec.y, vec.z),
- BABYLON.Matrix.FromArray([
- -0.01, 0, 0, 0,
- 0, 0, 0.01, 0,
- 0, 0.01, 0, 0,
- 0, 0, 0, 1
- ])
- )
- },
- vec3BABYLONToUE4(vec) {
- return BABYLON.Vector3.TransformCoordinates(
- new BABYLON.Vector3(vec.x, vec.y, vec.z),
- BABYLON.Matrix.FromArray([
- -100, 0, 0, 0,
- 0, 0, 100, 0,
- 0, 100, 0, 0,
- 0, 0, 0, 1
- ])
- )
- },
-
- postData: (url, data) => {
- return fetch(url, {
- body: JSON.stringify(data),
- // cache: 'no-cache',
- // credentials: 'same-origin',
- headers: {
- // 'user-agent': 'Mozilla/4.0 MDN Example',
- 'content-type': 'application/json'
- },
- method: 'POST',
- // mode: 'cors',
- // redirect: 'follow',
- // referrer: 'no-referrer',
- })
- .then(response => response.json())
- },
- createVideoElement: (path) => {
- return new Promise((resolve, reject) => {
-
- let videoName = path.split("/")[path.split("/").length-1].split(".")[0]
- let oldVideo = document.getElementById(videoName)
- if(oldVideo) {
- oldVideo.currentTime = 0
- oldVideo.isLoaded = true
- resolve(oldVideo)
- }
- else {
- let video = document.createElement("video")
- video.id = videoName
- video.crossOrigin = "anonymous"
- // video.playsinline = "true"
- video.setAttribute("playsinline", "playsinline")
- video.setAttribute("x5-playsinline", "true")
- video.setAttribute("webkit-playsinline", "true")
- video.setAttribute("x5-video-player-type", "h5")
- video.setAttribute("controls", "true")
- // video.controls="true"
- video.muted = "muted"
- video.autoplay = "autoplay"
- video.preload = "auto"
- video.src = path
- // document.getElementById("videoTextureBox").appendChild(video)
- video.onloadeddata = () => {
- resolve(video);
- }
- }
-
- });
- },
-
- createVideoElement0: (path) => {
- let videoName = path.split("/")[path.split("/").length-1].split(".mp4")[0]
- let oldVideo = document.getElementById(videoName)
- if(oldVideo) {
- oldVideo.currentTime = 0
- oldVideo.isLoaded = true
- return oldVideo
- }
- let video = document.createElement("video")
- video.src = path
- video.id = videoName
- video.crossOrigin = "anonymous"
- video.autoplay = "autoplay"
- video.preload = "auto"
- video.muted = "muted"
- video.setAttribute("playsinline", "true")
- video.setAttribute("x5-playsinline", "true")
- video.setAttribute("webkit-playsinline", "true")
- video.setAttribute("x5-video-player-type", "h5")
- video.setAttribute("controls", "true")
-
- return video
- },
- getLengthBetweenVec3: (v1, v2) => {
- return Math.sqrt(
- (v1.x - v2.x) * (v1.x - v2.x) +
- (v1.y - v2.y) * (v1.y - v2.y) +
- (v1.z - v2.z) * (v1.z - v2.z)
- )
- }
- }
|