-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fixed geometry builder to accomodate vertexStrokeColors #7850
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: dev-2.0
Are you sure you want to change the base?
Conversation
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.
This is looking good! I left a comment about how we handle default strokes, and then think before we merge, it'd be good to add some tests (maybe a visual test where we generate a geometry without any stroke colors and then draw it later with a stroke('red')
or something, and another where we do generate it with internal stroke colors, and ensure that those colors aren't overridden when we draw the geometry?)
vertexStrokeColors.push(...this.renderer.states.curStrokeColor); | ||
} else { | ||
// Use -1, -1, -1, -1 to indicate fallback to global stroke color | ||
vertexStrokeColors.push(-1, -1, -1, -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.
this.renderer.states.strokeColor
will always exist, it might just be the default color. What we do for the fill colors is, when we start building a p5.Geometry
, set the current color to -1, -1, -1, -1
so that we only get non-negative colors when someone calls fill()
or stroke()
inside of the buildGeometry
callback:
p5.js/src/webgl/p5.RendererGL.js
Lines 483 to 491 in d51184b
beginGeometry() { | |
if (this.geometryBuilder) { | |
throw new Error( | |
"It looks like `beginGeometry()` is being called while another p5.Geometry is already being build." | |
); | |
} | |
this.geometryBuilder = new GeometryBuilder(this); | |
this.geometryBuilder.prevFillColor = this.states.fillColor; | |
this.fill(new Color([-1, -1, -1, -1])); |
Can we do the same for strokes?
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.
okay so this should look something like this if I got this right...
beginGeometry() {
if (this.geometryBuilder) {
throw new Error(
"It looks like `beginGeometry()` is being called while another p5.Geometry is already being build."
);
}
this.geometryBuilder = new GeometryBuilder(this);
this.geometryBuilder.prevFillColor = this.states.fillColor;
this.geometryBuilder.prevStrokeColor = this.states.strokeColor;
this.fill(new Color([-1, -1, -1, -1]));
this.stroke(new Color([-1, -1, -1, -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.
I think so, yep!
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.
There's also an extra step at the end where we reset the previous fill color:
p5.js/src/webgl/p5.RendererGL.js
Line 510 in d51184b
this.fill(this.geometryBuilder.prevFillColor); |
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.
Right. Got it.
Hi @davepagurek ! I've been working on implementing changes you suggested, but I'm running into some test failures that I'd like your guidance on. Changes MadeFollowing your recommendation, I added the stroke color state management similar to how fill colors are handled: In
|
It looks like we also need to update the line shader. In the fill shader, it checks that the x value of the color is at least 0 as a quick way to see if it's a real color: p5.js/src/webgl/shaders/normal.vert Line 40 in 2606c21
but currently in the stroke shader, it doesn't, it just looks like this: p5.js/src/webgl/shaders/line.vert Line 102 in 2606c21
|
Looks like this test is failing now: p5.js/test/unit/webgl/p5.RendererGL.js Lines 1406 to 1429 in 2606c21
This test should probably be a visual test since it's hard to understand what's actually failing by looking at a big array of color channel values, but I wonder if the |
Resolves #7840
Changes:
Added per-vertex stroke color handling to
GeometryBuilder.addGeometry()
method, following the same pattern as the existing fill color logic:The following screenshot shows the given fixes...
preview/index.html:
Screenshots of the change:
PR Checklist
npm run lint
passes