aframe
aframe copied to clipboard
Consider re-implementing THREE.VideoTexture to use `tick` since each one creates its own RAF
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 I'm interesting in taking this on but I'm not sure what you mean by tick.
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.
(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)
@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?
Something someone could do, but not focused on video too much and the performance gain is questionable for the effort.
@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)
@dmarcos @ngokevin can we close this?