/* USER DATA */
const videoLink = "https://threejs.org/examples/textures/sintel.mp4";
const videoVolume = 1 ;
const buttonLink = "https://mywebar-a.akamaihd.net/examples2022/Images/*Stickers/WOW_blue_red_yellow.png";
/* END OF USER DATA */
let video, videoPromise, videoTexture, videoMaterial;
let buttonContainer, buttonBlock, buttonFlag;
function init(
json,
init_callbacks
) {
videoPromise = init_callbacks
.loadVideo(videoLink,{
autoplay: false,
loop: false,
})
.then((v) => {
video = v;
video.volume = videoVolume;
videoTexture = new THREE.VideoTexture(video.target);
videoMaterial = new THREE.MeshBasicMaterial({map: videoTexture});
this.material = videoMaterial;
})
;
}
/**
* Push promises created in init() into 'init_promises'
* to wait before call start()
* @param {array} init_promises
*/
function mywebar_fill_init_promises(init_promises) {
init_promises.push(videoPromise);
}
/**
* Push HTMLMediaElements loaded in init() into 'medias'
* to properly handle pause/resume events of AR Viewer
* @param {array} medias
*/
function mywebar_fill_medias(medias) {
medias.push(video);
}
/**
* Animate a frame
*/
function update( event ) {
let {
time, // elapsed time from start
delta, // delta time from last frame
time_multiplier, // 'time' and 'delta' multiplier (1000 for milliseconds)
} = event;
time /= time_multiplier; // in seconds
delta /= time_multiplier; // in seconds
this.rotation.y = Math.cos(time) * Math.PI/16;
}
/**
* Start/resume playing scene
*/
function start() {
buttonContainer = document.createElement("div");
buttonContainer.style.cssText = `
height: 150px;
position: absolute;
bottom: 10%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
`;
buttonBlock = document.createElement("div");
buttonBlock.style.cssText = `
background-image: url(${buttonLink});
background-size: contain;
background-repeat: no-repeat;
width: 150px;
height: 150px;
`;
buttonContainer.appendChild(buttonBlock);
buttonBlock.addEventListener('click', btnClick);
document.body.appendChild(buttonContainer);
}
/**
* End/pause playing scene
*/
function stop() {
video.pause();
buttonContainer.remove();
buttonBlock.removeEventListener('click', btnClick);
}
/**
* Mouse/single touch start event
*/
function btnClick( event ) {
console.log("C");
buttonFlag = !buttonFlag;
if (buttonFlag) video.play();
else video.pause();
}
/**
* Unload event, free up memory
*/
function mywebar_destroy() {
video.destroy();
videoTexture.dispose();
}