Skip to content

Fix #212: Support dynamic paths in loadImage #2259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 25, 2024

Conversation

lindapaiste
Copy link
Collaborator

Fixes #212
Fixes #2257

Changes:

  • Monkey-patch various p5 load___ methods to modify the path argument at runtime.
  • Store the relevant file data (remote files and folder structure) to window.files so that resolvePathToFile can be executed at runtime.

Notes:

  • The array of patched functions probably needs to be expanded to include methods added by various packages, like loadSound.
  • I only really tested this with loadImage. Here's the code I used:
let staticImg;
let dynamicImg;
let images = {};
let theme = 'dark';

function preload() {
  ['dark', 'light', 'contrast'].forEach((theme) => {
    images[theme] = loadImage(`/images/console-debug-${theme}.svg`);
  });
  staticImg = loadImage('images/console-debug-contrast.svg');
  dynamicImg = loadImage(`/images/console-debug-${theme}.svg`);
}

function setup() {
  createCanvas(400, 600);
}

function draw() {
  background(220);
  image(images.dark, 0, 0);
  image(images.light, 200, 0);
  image(images.contrast, 0, 200);
  image(staticImg, 0, 400);
  image(dynamicImg, 200, 400);
}

image

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123

@raclim raclim added this to the MINOR Release for 2.12.0 milestone Jan 19, 2024
Copy link
Collaborator

@raclim raclim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this!

@raclim raclim merged commit b6cb6e7 into processing:develop Jan 25, 2024
@raclim
Copy link
Collaborator

raclim commented Jan 25, 2024

Sorry! I might actually revert this for now because I noticed I get some errors (attached as image for reference) when I tried to load the 3D: Shader as a Texture example.

Screenshot 2024-01-25 at 2 03 16 PM

Down to have this reopened and merged again!

@davepagurek
Copy link
Contributor

It looks like maybe the only issue here was that for most of those load* methods, the path is just the first arg, but for loadShader, the first two arguments are paths. This same approach could maybe still work if we add a special case for that method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

load image URLs do not work with interpolation ticks loadImage and non-literal file names
3 participants