processing / processing/p5.js

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

Open
#9,094 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/webgl/loading.js at loadMaterialTextures() and its Promise.all usage, then trace how loadModel() exposes the first usable frame. Compare the proposed lazy and opt-in behaviors, including missing-map rendering and existing sketches that draw immediately after loading. Done means the chosen behavior is implemented without blocking geometry unnecessarily and its first-frame effects are covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.