Auto return shader hooks by vietnguyen2358 · Pull Request #8384 · processing/p5.js
Resolves #7994
Addresses #7992
Changes:
- Added auto-return behavior for shader hooks with matching input and return types, allows users to omit
return inputswhen modifying struct properties in place - Implemented type checking to ensure auto-return only applies to struct-returning hooks with a single parameter of matching type
PR Checklist
-
npm run lintpasses - Inline reference is included / updated
- Unit tests are included / updated
🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !
Thank You!
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks for making these changes and also adding tests!
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh actually it looks like the tests are failing:
FAIL |unit-tests| test/unit/visual/cases/webgl.js > WebGL > p5.strands > auto-return for shader hooks > auto-return works with getObjectInputs > matches expected screenshots
TypeError: Cannot read properties of undefined (reading 'position')
❯ p5.hookImplementation src/strands/strands_api.js:446:50
444| const expectedProp = expectedProperties[i];
445| const propName = expectedProp.name;
446| const receivedValue = effectiveReturn[propName];
| ^
447| if (receivedValue === undefined) {
448| FES.userError('type error', `You've returned an incomple…
❯ eval src/strands/strands_transpiler.js:1078:39
❯ src/strands/strands_transpiler.js:1087:20
❯ p5.Shader.modify src/strands/p5.strands.js:114:9
❯ test/unit/visual/cases/webgl.js:965:48
❯ test/unit/visual/visualTest.js:432:13
Possibly the isStructType check is failing? Maybe try adding some logging and then run npm run test test/unit/visual/cases/webgl.js to see what the types are?
Hi @vietnguyen2358! We're working on some updates to the p5.strands API for the next release in #8314 and we don't want to put any time pressure on you related to that, so I'm going to integrate your PR into that branch and fix the tests there, since other parts of the code are moving around too. Thanks for your help on this so far, I'm excited to have this functionality in the next version 🙂
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters