VideoTexture.js 1.2 KB

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