p5.js
p5.js copied to clipboard
Feature/8097
Resolves #8097
Changes:
This PR adds a new activeCamera() function that provides a standard joint getter/setter API for accessing and modifying the current active camera in p5.js WebGL mode.
Implementation Details:
-
Added
activeCamera()function: A joint getter/setter that follows the pattern used by other p5.js functions likelinePerspective()- When called with no arguments: returns the current active
p5.Cameraobject - When called with a camera argument: sets that camera as the active camera and returns
thisfor chaining - Includes
_assert3d()validation to ensure it's only used in WebGL mode
- When called with no arguments: returns the current active
-
Added
RendererGL.prototype.activeCamera()method: Implements the same getter/setter pattern at the renderer level, reusing existingsetCamera()logic -
Comprehensive test suite: Added 5 test cases covering:
- Getting the current camera (no arguments)
- Setting the camera (with argument)
- Multiple camera switching scenarios
- Chaining behavior
- Correct camera object reference handling
Benefits:
- Provides a standard API for camera access that's consistent with other p5.js functions
- Enables library creators to write code that works with both V1 and V2 (when V1 support is added)
- Maintains full backward compatibility with existing
setCamera()function - Follows established p5.js patterns for joint getter/setter functions
Files Modified:
-
src/webgl/p5.Camera.js: Addedfn.activeCamera()andRendererGL.prototype.activeCamera()with full JSDoc documentation and examples -
test/unit/webgl/p5.Camera.js: Added comprehensive test suite foractiveCamera()functionality
Screenshots of the change:
N/A - This is a code-only change that adds a new API function. No visual changes.
PR Checklist
-
[x]
npm run lintpasses -
[x] Inline reference is included / updated
-
[x] Unit tests are included / updated