From d9370c1b952502be21bbd3398ae1c4aa2971e593 Mon Sep 17 00:00:00 2001 From: Perminder Singh Date: Thu, 26 Oct 2023 16:23:32 +0530 Subject: [PATCH 01/11] ClearColors method applied --- src/webgl/3d_primitives.js | 8 ++++++++ src/webgl/GeometryBuilder.js | 15 --------------- src/webgl/p5.Geometry.js | 9 ++++++++- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/webgl/3d_primitives.js b/src/webgl/3d_primitives.js index 376231c5ab..24547013af 100644 --- a/src/webgl/3d_primitives.js +++ b/src/webgl/3d_primitives.js @@ -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 () { + return this._renderer.clearColors(); +}; + /** * Draw a plane with given a width and height * @method plane diff --git a/src/webgl/GeometryBuilder.js b/src/webgl/GeometryBuilder.js index 289786b651..502f4b2bee 100644 --- a/src/webgl/GeometryBuilder.js +++ b/src/webgl/GeometryBuilder.js @@ -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; } } diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index 768a4b2cf7..09d52c528e 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -87,7 +87,14 @@ p5.Geometry = class Geometry { this.dirtyFlags = {}; } - +/** + * @method clearColors + * @chainable + */ + clearColors() { + this.vertexColors = []; + return this; + } /** * computes faces for geometry objects based on the vertices. * @method computeFaces From 716554fd780f28390dbcfdcf4ac85304750d8211 Mon Sep 17 00:00:00 2001 From: perminder-17 <127239756+perminder-17@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:50:10 +0530 Subject: [PATCH 02/11] Update p5.Geometry.js --- src/webgl/p5.Geometry.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index 09d52c528e..c279635658 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -87,10 +87,7 @@ p5.Geometry = class Geometry { this.dirtyFlags = {}; } -/** - * @method clearColors - * @chainable - */ + clearColors() { this.vertexColors = []; return this; From e33224afcb8a2fb598f090e26769d2978cdc83d7 Mon Sep 17 00:00:00 2001 From: perminder-17 <127239756+perminder-17@users.noreply.github.com> Date: Thu, 26 Oct 2023 17:21:11 +0530 Subject: [PATCH 03/11] Removed method from 3D_primitives.js --- src/webgl/3d_primitives.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/webgl/3d_primitives.js b/src/webgl/3d_primitives.js index 24547013af..376231c5ab 100644 --- a/src/webgl/3d_primitives.js +++ b/src/webgl/3d_primitives.js @@ -180,14 +180,6 @@ p5.prototype.freeGeometry = function(geometry) { this._renderer._freeBuffers(geometry.gid); }; -/** - * Clears the internal Color of the Geometry. - * @method clearColors - */ -p5.prototype.clearColors = function () { - return this._renderer.clearColors(); -}; - /** * Draw a plane with given a width and height * @method plane From df35dc03b967063a71d7f61dfe1b4d1dec58956a Mon Sep 17 00:00:00 2001 From: perminder-17 <127239756+perminder-17@users.noreply.github.com> Date: Thu, 26 Oct 2023 23:47:46 +0530 Subject: [PATCH 04/11] Update p5.Geometry.js --- src/webgl/p5.Geometry.js | 51 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index c279635658..4b04c0f0af 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -87,7 +87,56 @@ p5.Geometry = class Geometry { this.dirtyFlags = {}; } - + /** + * Removes the internal Colors of p5.Geometry + * + * @method clearColors + * + * @example + *
+ * + * let shape01; + * let shape02; + * let points = []; + * + * function setup() { + * renderer = createCanvas(600, 600, WEBGL); + * points.push(new p5.Vector(-1, -1, 0), new p5.Vector(-1, 1, 0), new p5.Vector(1, -1, 0), new p5.Vector(-1, -1, 0)); + * buildShape01(); + * buildShape02(); + * } + * function draw() { + * background(0); + * + * fill("pink"); // shape01 retains its internal blue color, so it won't turn pink. + * model(shape01); + * + * shape02.clearColors(); // Resets shape02's colors. + * fill("yellow"); // Now, shape02 is yellow. + * model(shape02); + * } + * + * function buildShape01() { + * beginGeometry(); + * fill("blue"); // shape01's color is blue because its internal colors remain. + * beginShape(); + * for (let vec of points) vertex(vec.x * 100, vec.y * 100, vec.z * 100); + * endShape(CLOSE); + * shape01 = endGeometry(); + * } + * + * function buildShape02() { + * beginGeometry(); + * fill("red"); // shape02.clearColors() removes its internal colors. Now, shape02 is red. + * beginShape(); + * for (let vec of points) vertex(vec.x * 200, vec.y * 200, vec.z * 200); + * endShape(CLOSE); + * shape02 = endGeometry(); + * // You can also call shape02.clearColors() here. + * } + * + *
+ */ clearColors() { this.vertexColors = []; return this; From f79a6f2d26d328615e3315e15db001d32f73761f Mon Sep 17 00:00:00 2001 From: perminder-17 <127239756+perminder-17@users.noreply.github.com> Date: Thu, 26 Oct 2023 23:52:17 +0530 Subject: [PATCH 05/11] Update p5.Geometry.js --- src/webgl/p5.Geometry.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index 4b04c0f0af..13e0009f28 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -18,9 +18,9 @@ import p5 from '../core/main'; * @param {function} [callback] function to call upon object instantiation. */ p5.Geometry = class Geometry { - constructor(detailX, detailY, callback){ - //an array containing every vertex - //@type [p5.Vector] + constructor(detailX, detailY, callback) { + //an array containing every vertex + //@type [p5.Vector] this.vertices = []; //an array containing every vertex for stroke drawing @@ -164,7 +164,7 @@ p5.Geometry = class Geometry { } _getFaceNormal(faceId) { - //This assumes that vA->vB->vC is a counter-clockwise ordering + //This assumes that vA->vB->vC is a counter-clockwise ordering const face = this.faces[faceId]; const vA = this.vertices[face[0]]; const vB = this.vertices[face[1]]; @@ -249,7 +249,7 @@ p5.Geometry = class Geometry { * @chainable */ averagePoleNormals() { - //average the north pole + //average the north pole let sum = new p5.Vector(0, 0, 0); for (let i = 0; i < this.detailX; i++) { sum.add(this.vertexNormals[i]); @@ -560,7 +560,7 @@ p5.Geometry = class Geometry { */ normalize() { if (this.vertices.length > 0) { - // Find the corners of our bounding box + // Find the corners of our bounding box const maxPosition = this.vertices[0].copy(); const minPosition = this.vertices[0].copy(); From 8d042763d0ddbfa475672e9599290aeb276ea151 Mon Sep 17 00:00:00 2001 From: perminder-17 <127239756+perminder-17@users.noreply.github.com> Date: Fri, 27 Oct 2023 00:18:32 +0530 Subject: [PATCH 06/11] Update p5.Geometry.js --- src/webgl/p5.Geometry.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index 13e0009f28..5376cc9eeb 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -101,24 +101,23 @@ p5.Geometry = class Geometry { * * function setup() { * renderer = createCanvas(600, 600, WEBGL); - * points.push(new p5.Vector(-1, -1, 0), new p5.Vector(-1, 1, 0), new p5.Vector(1, -1, 0), new p5.Vector(-1, -1, 0)); + * points.push(new p5.Vector(-1, -1, 0), new p5.Vector(-1, 1, 0), + * new p5.Vector(1, -1, 0), new p5.Vector(-1, -1, 0)); * buildShape01(); * buildShape02(); * } * function draw() { * background(0); - * - * fill("pink"); // shape01 retains its internal blue color, so it won't turn pink. + * fill('pink'); // shape01 retains its internal blue color, so it won't turn pink. * model(shape01); - * * shape02.clearColors(); // Resets shape02's colors. - * fill("yellow"); // Now, shape02 is yellow. + * fill('yellow'); // Now, shape02 is yellow. * model(shape02); * } * * function buildShape01() { * beginGeometry(); - * fill("blue"); // shape01's color is blue because its internal colors remain. + * fill('blue'); // shape01's color is blue because its internal colors remain. * beginShape(); * for (let vec of points) vertex(vec.x * 100, vec.y * 100, vec.z * 100); * endShape(CLOSE); @@ -127,7 +126,7 @@ p5.Geometry = class Geometry { * * function buildShape02() { * beginGeometry(); - * fill("red"); // shape02.clearColors() removes its internal colors. Now, shape02 is red. + * fill('red'); // shape02.clearColors() removes its internal colors. Now, shape02 is red. * beginShape(); * for (let vec of points) vertex(vec.x * 200, vec.y * 200, vec.z * 200); * endShape(CLOSE); From bf98913f6d95b849466a061622cb69b7d46054e5 Mon Sep 17 00:00:00 2001 From: perminder-17 <127239756+perminder-17@users.noreply.github.com> Date: Fri, 27 Oct 2023 04:08:54 +0530 Subject: [PATCH 07/11] Update p5.Geometry.js --- src/webgl/p5.Geometry.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index 5376cc9eeb..fadf3a1260 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -89,6 +89,8 @@ p5.Geometry = class Geometry { } /** * Removes the internal Colors of p5.Geometry + * Using clearColors you can use the `fill()` to supply new colors before drawing each shape. + * If clearColors() is not used, the shapes will use their internal colors. * * @method clearColors * @@ -100,7 +102,7 @@ p5.Geometry = class Geometry { * let points = []; * * function setup() { - * renderer = createCanvas(600, 600, WEBGL); + * createCanvas(600, 600, WEBGL); * points.push(new p5.Vector(-1, -1, 0), new p5.Vector(-1, 1, 0), * new p5.Vector(1, -1, 0), new p5.Vector(-1, -1, 0)); * buildShape01(); @@ -110,7 +112,6 @@ p5.Geometry = class Geometry { * background(0); * fill('pink'); // shape01 retains its internal blue color, so it won't turn pink. * model(shape01); - * shape02.clearColors(); // Resets shape02's colors. * fill('yellow'); // Now, shape02 is yellow. * model(shape02); * } @@ -131,7 +132,7 @@ p5.Geometry = class Geometry { * for (let vec of points) vertex(vec.x * 200, vec.y * 200, vec.z * 200); * endShape(CLOSE); * shape02 = endGeometry(); - * // You can also call shape02.clearColors() here. + * shape02.clearColors(); // Resets shape02's colors. * } * * From 341d6923334c9b0013c29e4545f769c126997639 Mon Sep 17 00:00:00 2001 From: perminder-17 <127239756+perminder-17@users.noreply.github.com> Date: Fri, 27 Oct 2023 04:13:52 +0530 Subject: [PATCH 08/11] Update p5.Geometry.js --- src/webgl/p5.Geometry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index fadf3a1260..087b1120a2 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -89,7 +89,7 @@ p5.Geometry = class Geometry { } /** * Removes the internal Colors of p5.Geometry - * Using clearColors you can use the `fill()` to supply new colors before drawing each shape. + * Using clearColors, you can use 'fill()' to supply new colors before drawing each shape. * If clearColors() is not used, the shapes will use their internal colors. * * @method clearColors From 0791f46ba74a6998dae451b675bada0a1e3e0c63 Mon Sep 17 00:00:00 2001 From: perminder-17 <127239756+perminder-17@users.noreply.github.com> Date: Fri, 27 Oct 2023 04:19:24 +0530 Subject: [PATCH 09/11] Update p5.Geometry.js --- src/webgl/p5.Geometry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index 087b1120a2..50e411b3c7 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -90,7 +90,7 @@ p5.Geometry = class Geometry { /** * Removes the internal Colors of p5.Geometry * Using clearColors, you can use 'fill()' to supply new colors before drawing each shape. - * If clearColors() is not used, the shapes will use their internal colors. + * If clearColors() is not used, the shapes will use their internal colors by ignoring 'fill()'. * * @method clearColors * From c997c45064ea2922a6dedee9235215af13b1193a Mon Sep 17 00:00:00 2001 From: perminder-17 <127239756+perminder-17@users.noreply.github.com> Date: Fri, 27 Oct 2023 04:29:37 +0530 Subject: [PATCH 10/11] Update p5.Geometry.js --- src/webgl/p5.Geometry.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index 50e411b3c7..338d93e268 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -88,9 +88,9 @@ p5.Geometry = class Geometry { this.dirtyFlags = {}; } /** - * Removes the internal Colors of p5.Geometry - * Using clearColors, you can use 'fill()' to supply new colors before drawing each shape. - * If clearColors() is not used, the shapes will use their internal colors by ignoring 'fill()'. + * Removes the internal Colors of p5.Geometry. + * Using clearColors, you can use `fill()` to supply new colors before drawing each shape. + * If clearColors() is not used, the shapes will use their internal colors by ignoring `fill()`. * * @method clearColors * From 92c90d10c2efba164daa7f61510f3bf2931fcd07 Mon Sep 17 00:00:00 2001 From: perminder-17 <127239756+perminder-17@users.noreply.github.com> Date: Fri, 27 Oct 2023 04:42:06 +0530 Subject: [PATCH 11/11] Update p5.Geometry.js --- src/webgl/p5.Geometry.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index 338d93e268..825fd27efc 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -88,9 +88,9 @@ p5.Geometry = class Geometry { this.dirtyFlags = {}; } /** - * Removes the internal Colors of p5.Geometry. - * Using clearColors, you can use `fill()` to supply new colors before drawing each shape. - * If clearColors() is not used, the shapes will use their internal colors by ignoring `fill()`. + * Removes the internal colors of p5.Geometry. + * Using `clearColors()`, you can use `fill()` to supply new colors before drawing each shape. + * If `clearColors()` is not used, the shapes will use their internal colors by ignoring `fill()`. * * @method clearColors *