-
Notifications
You must be signed in to change notification settings - Fork 15
Add external renderer layer for generated dancers #675
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
base: main
Are you sure you want to change the base?
Conversation
src/ExternalDancer.js
Outdated
this.graphics = this.p5.createGraphics(worldW, worldH); | ||
this.graphics.pixelDensity(1); | ||
|
||
// Hand the renderer our mid-layer 2D context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: periods at end of sentences in comments.
if (!this.externalLayer) { | ||
this.p5_.drawSprites(); | ||
} else { | ||
// Draw sprites in two passes, before and after the external layer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, would it be possible to create a regular Sprite
but override its draw
function to call the custom renderer at the right time?
); | ||
const animationLength = sprite.animation.images.length; | ||
const currentMeasure = this.getCurrentMeasure(); | ||
if (currentMeasure < 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind explaining what this is for?
Summary
Introduce a pluggable “external dancer” rendering layer that Dance Party can composite between sprites and foreground effects. This allows the main
code-dot-org
repo to supply its own renderer (e.g., a Lottie-based dancer preview) without adding that dependency to Dance Party.The external renderer layer is shown below as bull dancer that is provided by a Lottie renderer introduced with code-dot-org/code-dot-org#68250
2025-09-09.15-37-31.2025-09-09.15_38_01.mp4
We have multiple surfaces that need to render the same generated dancer JSON (Dance Party canvas, a Dancer Editor, and a Music Lab view). Centralizing the rendering logic in the main repo keeps Dance Party lean and lets other surfaces reuse the same renderer.
What changed
ExternalDancerLayer
(p5 adapter that owns ap5.Graphics buffer
and hands its 2D context to an external renderer).DanceParty
now accepts an optionalexternalRendererFactory
(constructor option). If provided,setup()
creates anExternalDancerLayer
.setExternalLayerSource(dancerName)
updates the external layer’s source JSON (or clears it).Behavioral notes
externalRendererFactory
is provided, no behavior change: sprites and effects render as before.Deployment strategy
Pairs with code-dot-org/code-dot-org#68250 (adds the concrete Lottie renderer and passes the factory into DanceParty).
Testing story