Skip to content

[WIP] Docs: Add reference entries for p5.strands hooks (feedback wanted) #7920

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

Closed
wants to merge 1 commit into from

Conversation

Abhayaj247
Copy link

This draft PR adds new JSDoc reference entries for a few p5.strands hooks, following the feedback in #7919.

  • The new doc comments use JavaScript-only examples and describe the callback signature as discussed.

  • I’ve included examples for :

  • getWorldInputs

  • combineColors

  • getPointSize

  • The doc comments are currently placed in a new file :

src/webgl/p5.strands.js

(Open to moving them if you prefer a different location.)

Could you please review the style, level of detail, and file location?

Once confirmed, I’ll update the rest of the hooks in the same format.

Thanks for your guidance!

Copy link

welcome bot commented Jun 18, 2025

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

Copy link
Member

@lukeplowden lukeplowden left a comment

Choose a reason for hiding this comment

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

I would be inclined to give a little bit more context for each of the hook functions. For now this is the only presence of p5.strands in the documentation. I would mention where these functions can be used, and explain what world space is, for example. Let me know if you need help with that as it's a newer feature

* myShader = baseMaterialShader().modify(() => {
* getWorldInputs((inputs) => {
* // Move the vertex up and down in a wave
* inputs.position.y += 20 * Math.sin(millis() * 0.001 + inputs.position.x * 0.05);
Copy link
Member

Choose a reason for hiding this comment

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

In this case, you have to use sin() not Math.sin!

Copy link
Author

Choose a reason for hiding this comment

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

Updated the example to use sin() instead of Math.sin() as suggested.

// Before:
inputs.position.y += 20 * Math.sin(millis() * 0.001 + inputs.position.x * 0.05);

// After:
inputs.position.y += 20 * sin(millis() * 0.001 + inputs.position.x * 0.05);

* @function getWorldInputs
* @experimental
* @description
* Registers a callback to modify world-space vertex inputs for each vertex.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe 'vertex inputs for each vertex' is a bit redundant here. I would remove the 'for each vertex' part or reword slightly

Copy link
Author

Choose a reason for hiding this comment

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

Reworded the description to remove redundancy and improve clarity.

// Before:
 * Registers a callback to modify world-space vertex inputs for each vertex.

// After:
 * Registers a callback to modify the world-space properties of each vertex in a shader.
 

* - {@link p5.baseStrokeShader}
*
* @param {function(inputs: { position: {x: number, y: number, z: number}, normal: {x: number, y: number, z: number}, texCoord: {x: number, y: number}, color: {r: number, g: number, b: number, a: number} }): object} callback
* A function that receives the current inputs and returns the modified inputs.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like "a callback function which receives and returns a Vertex struct."

Copy link
Author

Choose a reason for hiding this comment

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

Updated the callback parameter description to reference a Vertex struct and added a @typedef for clarity.


/**
 * @typedef {Object} Vertex
 * @property {{x: number, y: number, z: number}} position - The position of the vertex in world space.
 * @property {{x: number, y: number, z: number}} normal - The normal vector at the vertex in world space.
 * @property {{x: number, y: number}} texCoord - The texture coordinates (x, y) for the vertex.
 * @property {{r: number, g: number, b: number, a: number}} color - The color at the vertex.
 */

/**
 * @param {function(Vertex): Vertex} callback
 *        A callback function which receives and returns a Vertex struct.
 */
 

* The callback receives the current point size (number) and should return the new size (number).
*
* This hook is available in:
* - {@link p5.pointShader}
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a point shader?

Copy link
Author

Choose a reason for hiding this comment

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

Removed the reference to p5.pointShader and only listed the correct shaders for each hook.


// Before:
 * This hook is available in:
 * - {@link p5.pointShader}

// After:
 * This hook is available in:
 * - {@link p5.baseMaterialShader}
 * - {@link p5.baseNormalShader}
 * - {@link p5.baseColorShader}
 * - {@link p5.baseStrokeShader}
 

@Abhayaj247
Copy link
Author

Abhayaj247 commented Jun 20, 2025

Thank you for the review and detailed feedback @lukeplowden .

I have made the following updates to address all the points :

  • Added more context and explanations for each hook, including where these functions can be used (e.g., inside baseMaterialShader().modify()) and an explanation of what “world space” means.

  • Updated all code examples to use sin() instead of Math.sin().

  • Reworded the phrase “vertex inputs for each vertex” for clarity and to avoid redundancy.

  • Callback parameters are now described as receiving and returning a Vertex struct, and I have added a @typedef for Vertex at the top of the file.

  • Removed the reference to p5.pointShader and only listed the correct shaders for each hook.

Please let me know if there’s anything else I should update. Thank you!

@Abhayaj247
Copy link
Author

Hi @lukeplowden ,

I have addressed all the feedback and updated the documentation accordingly. If everything looks good and the changes are correct, please let me know so I can proceed with documenting the remaining hooks in the same style.

Or, if any further changes are needed, please let me know and I will update accordingly.

Thank you!

@Abhayaj247 Abhayaj247 reopened this Jun 20, 2025
@Abhayaj247
Copy link
Author

Also, just to note, @lukeplowden : my previous commit was mistakenly deleted. All the updates mentioned above are now included in my current commit. Thank you for your understanding!

@perminder-17 perminder-17 self-requested a review June 22, 2025 18:04
@Abhayaj247
Copy link
Author

Hi @lukeplowden , just following up on this PR.

I’ve made all the updates you suggested (details in my previous comment). Please let me know if there’s anything else I should update, or if this is good to go. Thank you!

Copy link
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

Hi @Abhayaj247 thankyou for taking this task. I haven’t reviewed it in detail yet, but have you created a separate file for the documentation? Do you think we could generate the reference pages by adding a doc-comment block at the end of the file that describes each method?

Copy link
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

I also noticed that you added the reference documentation to the main branch, but p5.Strands is implemented in the dev-2.0 branch.

Could you please retarget your PR to the dev-2.0 branch and re-base your work on top of it?

Steps:

  1. In the PR, click Edit ➜ change the base from main to dev-2.0 ➜ Save (Already I did)

Locally:

git fetch origin
git checkout strands-docs-draft
git rebase origin/dev-2.0
git push --force-with-lease

This will make the PR show only your intended changes against dev-2.0, with conflicts resolved. Thanks!

@perminder-17 perminder-17 changed the base branch from main to dev-2.0 June 23, 2025 07:22
@Abhayaj247
Copy link
Author

Abhayaj247 commented Jun 23, 2025

Hi @Abhayaj247 thankyou for taking this task. I haven’t reviewed it in detail yet, but have you created a separate file for the documentation? Do you think we could generate the reference pages by adding a doc-comment block at the end of the file that describes each method?

Hi @perminder-17 , thank you for your response!

I haven’t created a separate file for the documentation - instead, I’ve added detailed doc-comment blocks directly above each method within the p5.strands.js file. This approach is consistent with how documentation is handled elsewhere in the codebase and should allow the reference pages to be generated automatically.

If you’d prefer, I can also add a summary doc-comment block at the end of the file that describes each method, or create a separate documentation file as needed. Please let me know your preference, and I’ll be happy to make the adjustments!

Thank you!

@Abhayaj247
Copy link
Author

Abhayaj247 commented Jun 23, 2025

I also noticed that you added the reference documentation to the main branch, but p5.Strands is implemented in the dev-2.0 branch.

Could you please retarget your PR to the dev-2.0 branch and re-base your work on top of it?

Steps:

  1. In the PR, click Edit ➜ change the base from main to dev-2.0 ➜ Save (Already I did)

Locally:

git fetch origin
git checkout strands-docs-draft
git rebase origin/dev-2.0
git push --force-with-lease

This will make the PR show only your intended changes against dev-2.0, with conflicts resolved. Thanks!

Hi @perminder-17,
I’m following the steps to rebase my branch onto dev-2.0 as suggested :


git fetch origin
git checkout strands-docs-draft
git rebase origin/dev-2.0
git push --force-with-lease

However, While rebasing onto dev-2.0 locally, I’m encountering repeated merge conflicts in files like README.md and .all-contributorsrc. Should I need resolve each conflict manually, or is it acceptable to skip these commits if they’re not relevant to my changes? Please advise on the preferred approach. Thank you!

Here’s an example of the error I’m seeing:

For

For  .all-contributorsrc :

CONFLICT (content): Merge conflict in .all-contributorsrc
error: could not apply 8b7f6f252... docs: update .all-contributorsrc [skip ci]
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 8b7f6f252... docs: update .all-contributorsrc [skip ci]

For  README.md :

CONFLICT (content): Merge conflict in README.md
error: could not apply ef7104d6e... docs: update README.md [skip ci]
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".       
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply ef7104d6e... docs: update README.md [skip ci]

@Abhayaj247
Copy link
Author

Abhayaj247 commented Jun 24, 2025

Hi @perminder-17,

Just following up on my previous question regarding the repeated merge conflicts while rebasing onto dev-2.0 (specifically in files like README.md and .all-contributorsrc).

Should I resolve each conflict manually, or is it acceptable to skip these commits if they’re not relevant to my changes?

Would appreciate your advice on the preferred approach. Thank you!

@perminder-17
Copy link
Collaborator

Just following up on my previous question regarding the repeated merge conflicts while rebasing onto dev-2.0 (specifically in files like README.md and .all-contributorsrc).

Would it be okay for you to open a new PR targeting dev-2.0 branch if you're facing issues? The idea is not to solve the merge conflicts manually, but the easiest way for now would be to close this one and open a new PR copying the changes from this PR and pasting it to the dev-2.0 ones?

@perminder-17 perminder-17 changed the base branch from dev-2.0 to main June 24, 2025 14:01
@Abhayaj247
Copy link
Author

Just following up on my previous question regarding the repeated merge conflicts while rebasing onto dev-2.0 (specifically in files like README.md and .all-contributorsrc).

Would it be okay for you to open a new PR targeting dev-2.0 branch if you're facing issues? The idea is not to solve the merge conflicts manually, but the easiest way for now would be to close this one and open a new PR copying the changes from this PR and pasting it to the dev-2.0 ones?

Thank you for the suggestion @perminder-17 !
I’ll go ahead and open a new PR targeting dev-2.0 by copying my changes over, and will close the current one.
Appreciate your help!

@perminder-17
Copy link
Collaborator

Thanks for your patience and really sorry for the delay in reviewing.

@Abhayaj247
Copy link
Author

Thanks for your patience and really sorry for the delay in reviewing.

No problem at all, and thanks for taking the time to review!

@Abhayaj247
Copy link
Author

Closing this PR in favor of #7940, which ports these changes to the dev-2.0 branch as suggested by the maintainers. The new PR avoids the previous merge conflicts and follows the recommended workflow.

Thank you to everyone who reviewed and provided feedback here!

@Abhayaj247 Abhayaj247 closed this Jun 24, 2025
@Abhayaj247 Abhayaj247 deleted the strands-docs-draft branch June 24, 2025 15:08
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.

3 participants