VideoTexture.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { RGBFormat, LinearFilter } from '../constants.js';
  2. import { Texture } from './Texture.js';
  3. class VideoTexture extends Texture {
  4. constructor( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  5. super( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  6. this.format = format !== undefined ? format : RGBFormat;
  7. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  8. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  9. this.generateMipmaps = false;
  10. const scope = this;
  11. function updateVideo() {
  12. scope.needsUpdate = true;
  13. video.requestVideoFrameCallback( updateVideo );
  14. }
  15. if ( 'requestVideoFrameCallback' in video ) {
  16. video.requestVideoFrameCallback( updateVideo );
  17. }
  18. }
  19. clone() {
  20. return new this.constructor( this.image ).copy( this );
  21. }
  22. update() {
  23. const video = this.image;
  24. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  25. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  26. this.needsUpdate = true;
  27. }
  28. }
  29. }
  30. VideoTexture.prototype.isVideoTexture = true;
  31. export { VideoTexture };