Skip to content

Conversation

@nakednous
Copy link
Contributor

@nakednous nakednous commented Nov 25, 2025

This PR fixes issue #7837.

In p5.js v2, Matrix.mat4 is exposed via a getter that returns an internal Float32Array.
Camera.slerp() (and potentially other code) assigns to uPMatrix.mat4 which throws:

TypeError: setting getter-only property "mat4"

This change adds a set mat4(values) on Matrix that:

  • only applies to 4×4 matrices,
  • expects an array-like of length 16, and
  • copies values into the existing Float32Array instead of reassigning it.
  • Adds a symmetric set mat3(values) for 3×3 matrices.

This fixes the intended writable behavior (used by Camera.slerp()), while preserving the internal buffer identity required by WebGL bindings and other code that holds references to the matrix storage.

@welcome
Copy link

welcome bot commented Nov 25, 2025

🎉 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!

@nakednous nakednous force-pushed the fix-mat4-slerp-ortho branch from a30bb99 to d1dcd64 Compare December 8, 2025 13:38
@nakednous
Copy link
Contributor Author

Rebasing this PR onto the latest dev-2.0.
I’ve re-tested the fix locally using the built lib/p5.js, and the ortho Camera.slerp() issue is resolved.

@davepagurek
Copy link
Contributor

Hi @nakednous, sorry for the delay on this! I think this approach works, but it might be for the best to not allow these to be settable for safety? @holomorfo @limzykenneth do you have thoughts?

If we don't want to let those properties be settable, rather than cloning + updating the existing matrix here:

p5.js/src/webgl/p5.Camera.js

Lines 1593 to 1594 in a6e0b46

this._renderer.states.setValue('uPMatrix', this._renderer.states.uPMatrix.clone());
this._renderer.states.uPMatrix.mat4 = this.projMatrix.mat4.slice();

...maybe we just set the state directly to a clone of the camera's matrix?

@nakednous nakednous force-pushed the fix-mat4-slerp-ortho branch from d1dcd64 to ce3044c Compare December 16, 2025 16:29
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.

2 participants