Skip to content

load model textures lazily instead of blocking loadModel() on all of them #9094

Description

@Nixxx19

Increasing access

a model with several materials can reference a lot of images, and right now loadModel() waits for all of them before it returns anything. on a slow connection that's a long blank screen, and someone on a phone pays for textures they may never see. showing the model as soon as its geometry is ready makes heavier models usable on more connections and devices.

Most appropriate sub-area of p5.js?

  • WebGL
  • IO

Feature request details

follow up from the texture map work in #9066, #9067 and #9089.

loadMaterialTextures() in src/webgl/loading.js kicks off every texture in a model's .mtl and then does await Promise.all(jobs), so loadModel() doesn't resolve until the last image lands. a model with diffuse, specular, ambient, shininess and normal maps across several materials can easily be a dozen requests.

some options worth weighing:

  • resolve the model once the geometry is ready and let each map attach as it arrives, so the shape appears untextured and fills in
  • or keep the current behaviour as the default and add an opt in, so existing sketches don't change when they first draw
  • either way a part should draw sensibly with a map still missing, which it already does since a texture that fails to load is skipped

worth checking what this does to the first drawn frame before changing the default, since sketches that draw immediately after loading currently expect everything to be there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions