p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

loadModel() options break without fileType and ignore flipU/flipV

Open bhabishnu opened this issue 1 month ago • 3 comments

Most appropriate sub-area of p5.js?

  • [ ] Accessibility
  • [ ] Color
  • [ ] Core/Environment/Rendering
  • [ ] Data
  • [ ] DOM
  • [ ] Events
  • [ ] Image
  • [ ] IO
  • [ ] Math
  • [ ] Typography
  • [ ] Utilities
  • [x] WebGL
  • [ ] WebGPU
  • [ ] p5.strands
  • [ ] Build process
  • [ ] Unit testing
  • [ ] Internationalization
  • [ ] Friendly errors
  • [ ] Other (specify if possible)

p5.js version

2.3.2 / current main

Web browser and version

Chromium 151

Operating system

Fedora Linux

Steps to reproduce this

The documented loadModel(path, options) overload breaks depending on whether fileType is included.

async function setup() {
  createCanvas(100, 100, WEBGL);

  // Throws: fileType.toLowerCase is not a function
  await loadModel('model.obj', { flipU: true });

  // Loads, but flipU is ignored
  await loadModel('model.obj', {
    fileType: '.obj',
    flipU: true
  });
}

Options like { normalize: true } or {} also throw when fileType is omitted. With fileType present, flipU / flipV are ignored, although calling model.flipU() / model.flipV() afterwards works.

Expected: loadModel(path, options) should work without requiring fileType, and the flip options should be applied.

I traced it to the options parsing here:

https://github.com/processing/p5.js/blob/24a68d5c19eb70931c9a08c41b43a658978835f3/src/webgl/loading.js#L573-L581

fileType is reassigned before flipU / flipV are read, so without fileType the options object eventually reaches .toLowerCase(), while with it the flags are read from a string.

bhabishnu avatar Oct 16 '26 21:10 bhabishnu

Hi! Can I be assigned to this issue?

bababananaa avatar Oct 17 '26 02:10 bababananaa

Hi! I'd like to contribute to this issue. I've reviewed the problem with loadModel() options, including fileType, flipU, and flipV. I'd like to investigate the options parsing and add a regression test for the reported behavior. Please let me know if I can work on this. Thank you!

saniyaa-17 avatar Oct 17 '26 09:10 saniyaa-17

Thanks @bababananaa, having asked first I'll assign this to you.

davepagurek avatar Oct 27 '26 15:10 davepagurek