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.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. clone() {
  19. return new this.constructor( this.image ).copy( this );
  20. }
  21. update() {
  22. const video = this.image;
  23. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  24. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  25. this.needsUpdate = true;
  26. }
  27. }
  28. }
  29. VideoTexture.prototype.isVideoTexture = true;
  30. export { VideoTexture };
粤ICP备19079148号