-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Overhaul custom shapes for p5.js 2.0 #7373
Merged
Merged
Conversation
This file contains 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
…v-2.0 Updating my local repo before pushing to origin.
davepagurek
reviewed
Nov 22, 2024
Merge changes from other PR contributor into local branch.
This was referenced Dec 14, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves
Resolves #6560 (main issue)
Resolves #6766 (main issue)
Resolves #3352 (resolved by main issues)
Resolves #906 (resolved by main issues)
Resolves #6555 (resolved by main issues)
Resolves #5722 (resolved by main issues)
Resolves #2274 (resolved by main issues)
Addresses
Addresses #6459 (facilitates addition of
arcVertex()
)Addresses #3651 (partially addressed?)
Addresses #3509 (makes
shapeMode()
possible in the future)Addresses #5670 (may facilitate progress via a
PointAtLengthGetter
visitor class)Addresses #6679 (adds new named defaults, including
OPEN
for contours andPATH
for shapes)Addresses #4630 (new
Shape
class may facilitate SVG import and export)Addresses #4086 (see this comment for relationship to
textToPoints()
)Addresses #7026 (may help in relation to
textToPoints()
; anything else?)Addresses #7016 (allows custom shapes to be constructed on base renderer)
Changes
Summary
This PR provides a new foundation for custom shapes in p5.js, an enhanced feature set and API, and streamlined shape rendering.
Foundation: Shape -> Contours -> Primitives -> Vertices
The foundation for all changes is a new
Shape
class, which consists ofContour
objects. Contours may be thought of as general subshapes; they may be of any shape kind, includingPATH
,POINTS
,LINES
,TRIANGLES
, etc.Each contour is built from primitive objects, which are instances of classes such as
BezierSegment
andTriangle
. Finally, each primitive consists of one or moreVertex
instances. Vertex properties are generated dynamically, so a vertex may have just a position, or it may have other properties such as texture coordinates, a normal vector, a fill color, and a stroke color.Features and API
Shapes allow mixing path segments of different kinds within a single path, as well as mixing contours of different kinds within a shape. (Although, support for mixing contours in WebGL may need to be added later.) Texture coordinates are supported by all vertex functions. Splines are now more flexible (with different end modes) and more intuitive (with interpolated endpoints by default). Users have access to these features through a revamped API for the vertex functions, with clear and consistent default values.
Processing, exporting, and rendering
Shapes may be processed or exported to other formats using visitor classes. For example, they may be converted to
Path2D
objects for 2D rendering, or other formats for 3D rendering.Shapes can also be constructed and used independently of any renderer. For rendering, an abstract base renderer now handles all shape construction in one place, while concrete renderers customize shapes by selecting the vertex properties they support.
Itemized changes
The main changes are listed below.
Path2D
objects or vertices)Shape
instances and to apply visitors for rendering)stroke()
returns current stroke, for example)curve()
andcurveTightness()
withspline()
andsplineTightness()
curveDetail()
and removesbezierDetail()
(replaces count with density, for custom shapes)beginGeometry()
/endGeometry()
in favor ofbuildGeometry()
PATH
,OPEN
, andSHOW
for shapes, contours, and spline ends, respectivelyx, y, [u], [v]
andx, y, z, [u], [v]
for all vertex functionsbezierOrder(n)
provides an extensible way to support multiple orders of BéziersquadraticVertex()
, new signature forbezierVertex()
, replacement ofcurveVertex()
withsplineVertex()
, newOPEN
default for contours, and newSHOW
default for spline ends.Notes:
beginGeometry()
/endGeometry()
eliminates an inconsistency withbeginShape()
/endShape()
, reduces the size of the user-facing API, and prevents confusion (endGeometry()
is effectively used as a constructor, in contrast with how objects are usually created in p5).PR Checklist
Some areas are in progress during the draft phase of this PR.
npm run lint
passes