feature: load events for Texture
#24145
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issue: https://discourse.threejs.org/t/38533
Description
Some APIs (f.e. libs) that receive textures employ hacks (no other choice) to detect when textures are loaded. Here is an example of code from @marcofugaro's
three-projected-material
:The benefits of
Texture
s emitting events areneedsUpdate
setter in their classes and to tell end users to remember to call it after texture loadneedsUpdate = true
Win win.
Real-world bug
When using
three-projected-material
(taking into account the aboveaddLoadListener
function), without an infinite render loop but callingrequestAnimationFrame
only when needed, this happens:And so what happens is we are stuck without the texture showing up (unless we use an infinite render loop, and not all apps do that if they need to save CPU and aren't constantly animating things).
The
this.uniforms.isTextureLoaded
line I mentioned in the comments is here.