VideoTexture.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { 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.isVideoTexture = true;
  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. export { VideoTexture };
粤ICP备19079148号