aframe icon indicating copy to clipboard operation
aframe copied to clipboard

Consider re-implementing THREE.VideoTexture to use `tick` since each one creates its own RAF

Open ngokevin opened this issue 8 years ago • 7 comments

Description: We could reduce the number of requestAnimationFrame if we implement THREE.VideoTexture ourselves using tick. Here is the source of three.js VideoTexture

THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {

  THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );

  this.generateMipmaps = false;

  var scope = this;

  function update() {

    requestAnimationFrame( update );

    if ( video.readyState === video.HAVE_ENOUGH_DATA ) {

      scope.needsUpdate = true;

    }

  }

  update();

};

THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;

ngokevin avatar Apr 06 '16 19:04 ngokevin

@ngokevin I'm interesting in taking this on but I'm not sure what you mean by tick.

Mrashes avatar Jan 11 '18 22:01 Mrashes

https://github.com/aframevr/aframe/blob/master/docs/core/component.md

tick | Called on each render loop or tick of the scene. Used for continuous changes or checks.

arpu avatar Jan 12 '18 02:01 arpu

(when I tried this a long time ago, there was no perceptible change in performance, so I didn't do a PR -- but things may have changed since then)

machenmusik avatar Jan 12 '18 03:01 machenmusik

@ngokevin is this still something you'd like to see happen? I assume that would entail extracting the THREE.VideoTexture bits from loadVideo(): https://github.com/aframevr/aframe/blob/0d24e4307a4c5a5e7d2a1ea80f955e83631b69b7/src/systems/material.js#L154-L155

do you envision a new component that loadVideo() could attach to the material, which implements a tick() method with most of the THREE.VideoTexture code you referenced?

@machenmusik do you still have any code you could share?

subelsky avatar May 23 '19 18:05 subelsky

Something someone could do, but not focused on video too much and the performance gain is questionable for the effort.

ngokevin avatar May 23 '19 20:05 ngokevin

@ngokevin ok thanks! Should this issue be closed? I'm looking for a small-size issue to start contributing and saw this since it's marked 'easy'. I'm pretty familiar with THREE.js, are there other places where porting THREE code over would help A-Frame performance or simplicity? (I'm following @steveklabnik's advice about open source gardening)

subelsky avatar May 24 '19 12:05 subelsky

@dmarcos @ngokevin can we close this?

foobar404 avatar Feb 08 '23 15:02 foobar404