Skip to content
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

Made a new method to return Geometry with no internal colors. #6498

Merged
merged 11 commits into from
Oct 26, 2023
8 changes: 8 additions & 0 deletions src/webgl/3d_primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ p5.prototype.freeGeometry = function(geometry) {
this._renderer._freeBuffers(geometry.gid);
};

/**
* Clears the internal Color of the Geometry.
* @method clearColors
*/
p5.prototype.clearColors = function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe we can take out this method now that we have one on p5.Geometry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

return this._renderer.clearColors();
};

/**
* Draw a plane with given a width and height
* @method plane
Expand Down
15 changes: 0 additions & 15 deletions src/webgl/GeometryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,6 @@ class GeometryBuilder {
*/
finish() {
this.renderer._pInst.pop();

// If all vertices are the same color (no per-vertex colors were
// supplied), remove the vertex color data so that one may override the
// fill when drawing the geometry with `model()`
let allVertexColorsSame = true;
for (let i = 4; i < this.geometry.vertexColors.length; i++) {
if (this.geometry.vertexColors[i] !== this.geometry.vertexColors[i % 4]) {
allVertexColorsSame = false;
break;
}
}
if (allVertexColorsSame) {
this.geometry.vertexColors = [];
}

return this.geometry;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/webgl/p5.Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ p5.Geometry = class Geometry {
this.dirtyFlags = {};
}

clearColors() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think you can add a doc comment around this one? It would be nice to add your example in the video in your PR description. Maybe we can add two examples: one showing the behaviour without clearColors(), and one showing the behaviour with clearColors()?

Here's an example of a doc comment with an example sketch on another class. Adding one here would look similar:

/**
* Removes the framebuffer and frees its resources.
*
* @method remove
*
* @example
* <div>
* <code>
* let framebuffer;
* function setup() {
* createCanvas(100, 100, WEBGL);
* }
*
* function draw() {
* const useFramebuffer = (frameCount % 120) > 60;
* if (useFramebuffer && !framebuffer) {
* // Create a new framebuffer for us to use
* framebuffer = createFramebuffer();
* } else if (!useFramebuffer && framebuffer) {
* // Free the old framebuffer's resources
* framebuffer.remove();
* framebuffer = undefined;
* }
*
* background(255);
* if (useFramebuffer) {
* // Draw to the framebuffer
* framebuffer.begin();
* background(255);
* rotateX(frameCount * 0.01);
* rotateY(frameCount * 0.01);
* fill(255, 0, 0);
* box(30);
* framebuffer.end();
*
* image(framebuffer, -width/2, -height/2);
* }
* }
* </code>
* </div>
*
* @alt
* A rotating red cube blinks on and off every second.
*/
remove() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will add a doc comment around this one.

this.vertexColors = [];
return this;
}
/**
* computes faces for geometry objects based on the vertices.
* @method computeFaces
Expand Down