var VideotextureBtn = pc.createScript('videotextureBtn');
VideotextureBtn.attributes.add('materials', {
type: 'asset',
assetType: 'material',
array: true
});
VideotextureBtn.attributes.add('video', {
type: 'asset'
});
VideotextureBtn.prototype.initialize = function() {
var app = this.app;
var videoTexture = new pc.Texture(app.graphicsDevice, {
format: pc.PIXELFORMAT_R5_G6_B5,
autoMipmap: false
});
videoTexture.minFilter = pc.FILTER_LINEAR;
videoTexture.magFilter = pc.FILTER_LINEAR;
videoTexture.addressU = pc.ADDRESS_CLAMP_TO_EDGE;
videoTexture.addressV = pc.ADDRESS_CLAMP_TO_EDGE;
var video = document.createElement('video');
video.addEventListener('canplay', function (e) {
videoTexture.setSource(video);
});
video.src = this.video.getFileUrl();
video.crossOrigin = 'anonymous';
video.loop = true;
video.muted = true;
video.play();
for (var i = 0; i < this.materials.length; i++) {
var material = this.materials[i].resource;
material.emissiveMap = videoTexture;
material.update();
}
this.videoTexture = videoTexture;
this.videoDom = video;
this.upload = true;
};
VideotextureBtn.prototype.postInitialize = function() {
this.app.fire('video:playing');
this.videoDom.pause();
this.app.fire('video:paused');
this.app.on('video:play-pause-toggle', function () {
if (this.videoDom.paused) {
this.videoDom.play();
this.app.fire('video:playing');
} else {
this.videoDom.pause();
this.app.fire('video:paused');
}
}, this);
};
VideotextureBtn.prototype.update = function(dt) {
this.upload = !this.upload;
if (this.upload) {
this.videoTexture.upload();
}
};