From 00b13ff17c21d9de5489422b40266a1bc24c238b Mon Sep 17 00:00:00 2001 From: Garima Date: Sat, 28 Oct 2023 19:07:03 +0530 Subject: [PATCH 1/4] Solves issue #6502 --- src/webgl/p5.RendererGL.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index 3542584674..90162f00bc 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -1127,6 +1127,9 @@ p5.RendererGL = class RendererGL extends p5.Renderer { } // draw pg contents onto main renderer this._pInst.push(); + this._pInst.resetMatrix(); // Reset the transformation matrix to identity + this._pInst.clear(); // Clear the canvas + this._pInst.blendMode(this._pInst.BLEND); // Set blend mode to BLEND this._pInst.noStroke(); this._pInst.image(pg, -this.width/2, -this.height/2, this.width, this.height); From 9eb16710deffd56d31439ec3b3a3b5cf0286a4f9 Mon Sep 17 00:00:00 2001 From: Garima Date: Mon, 6 Nov 2023 19:14:08 +0530 Subject: [PATCH 2/4] Addresses issue #6519 --- src/webgl/p5.Camera.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 2a9d42eb18..c5f959c216 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -127,16 +127,31 @@ p5.prototype.camera = function (...args) { * vertical field of view, aspect ratio (usually width/height), and near and far * clipping planes. * - * If no parameters are given, the following default is used: - * perspective(PI/3, width/height, eyeZ/10, eyeZ*10), - * where eyeZ is equal to ((height/2) / tan(PI/6)). + * If no parameters are given, the default values are used, with a fixed location and a variable field of view. * @method perspective * @for p5 - * @param {Number} [fovy] camera frustum vertical field of view, - * from bottom to top of view, in angleMode units - * @param {Number} [aspect] camera frustum aspect ratio - * @param {Number} [near] frustum near plane length - * @param {Number} [far] frustum far plane length + * @param {Number} [fovy] - camera frustum vertical field of view, + * from bottom to top of view, in angleMode units. + * The default value is now variable and based on the canvas size as: + * this.defaultEyeZ = 800; + * defaultCameraFOV = 2 * Math.atan(this._renderer.height / 2 / this.defaultEyeZ); + * + * @param {Number} [aspect] camera frustum aspect ratio .The default value = this._renderer.width / this._renderer.height; + * @param {Number} [near] frustum near plane length or the near clipping plane. The default value = this.defaultEyeZ * 0.1; + * @param {Number} [far] frustum far plane length or the far clipping plane. The default value = this.defaultEyeZ * 10; + * + * However,If you prefer a fixed field of view, you can use the old defaults: + * + * - Field of view: PI/3 (60 degrees) + * - Canvas aspect ratio: width / height + * - Near clipping plane: eyeZ / 10 + * - Far clipping plane: eyeZ * 10 + * + * @example + * Set a fixed field of view + * perspective(PI/3, width / height, eyeZ / 10, eyeZ * 10); + * where eyeZ is equal to ((height/2) / tan(PI/6)). + * * @chainable * @example *
From 9d478f34874088bcaeacad63703ccaa4da6cfff9 Mon Sep 17 00:00:00 2001 From: Garima Date: Fri, 10 Nov 2023 21:30:49 +0530 Subject: [PATCH 3/4] Solves issue #6519 --- src/webgl/p5.Camera.js | 48 ++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index fb79df9341..8ef9fb2a74 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -122,36 +122,42 @@ p5.prototype.camera = function (...args) { * that are close to the camera appear their actual size while those * that are further away from the camera appear smaller. * + * * The parameters to this function define the viewing frustum * (the truncated pyramid within which objects are seen by the camera) through * vertical field of view, aspect ratio (usually width/height), and near and far * clipping planes. * - * If no parameters are given, the default values are used, with a fixed location and a variable field of view. - * @method perspective - * @for p5 - * @param {Number} [fovy] - camera frustum vertical field of view, - * from bottom to top of view, in angleMode units. - * The default value is now variable and based on the canvas size as: - * this.defaultEyeZ = 800; - * defaultCameraFOV = 2 * Math.atan(this._renderer.height / 2 / this.defaultEyeZ); + * If no parameters are given, the default values are used as: * - * @param {Number} [aspect] camera frustum aspect ratio .The default value = this._renderer.width / this._renderer.height; - * @param {Number} [near] frustum near plane length or the near clipping plane. The default value = this.defaultEyeZ * 0.1; - * @param {Number} [far] frustum far plane length or the far clipping plane. The default value = this.defaultEyeZ * 10; * - * However,If you prefer a fixed field of view, you can use the old defaults: + * fov- The default field of view for the camera is such that the full height of renderer is visible when it is positioned at a default distance of 800 units from the camera. * - * - Field of view: PI/3 (60 degrees) - * - Canvas aspect ratio: width / height - * - Near clipping plane: eyeZ / 10 - * - Far clipping plane: eyeZ * 10 + * aspect- The default aspect ratio is the ratio of renderer's width to renderer's height. * - * @example - * Set a fixed field of view - * perspective(PI/3, width / height, eyeZ / 10, eyeZ * 10); - * where eyeZ is equal to ((height/2) / tan(PI/6)). + * near - The default value for the near clipping plane is 0.1 times the default distance from the camera to the point it is looking at i.e 800. + * + * far - The default value for the far clipping plane is 10 times the default distance from the camera to the point it is looking at i.e 800. + * + * If you prefer a fixed field of view, follow these steps: * + * 1.Choose your desired field of view angle (`fovy`). This is how wide the camera can see. + * + * 2.To position the camera correctly, use the formula: + * cameraDistance = (height / 2) / tan(fovy / 2); + * This ensures that you can see the entire width across horizontally and height across vertically at the fixed field of view. + * + * 3.Set the near value to cameraDistance / 10 and the far value to cameraDistance * 10 . + * + * 4.Simply, call perspective with the chosen field of view, canvas aspect ratio, and near/far values: + * perspective(fovy, width / height, cameraDistance / 10, cameraDistance * 10); + * @method perspective + * @for p5 + * @param {Number} [fovy] camera frustum vertical field of view, + * from bottom to top of view, in angleMode units. + * @param {Number} [aspect] camera frustum aspect ratio + * @param {Number} [near] frustum near plane length + * @param {Number} [far] frustum far plane length * @chainable * @example *
@@ -171,7 +177,7 @@ p5.prototype.camera = function (...args) { * * rotateX(-0.3); * rotateY(-0.2); - * translate(0, 0, -50); + * translate(0, 0, -100); * * push(); * translate(-15, 0, sin(frameCount / 30) * 95); From 7ad21afe66497111ec01a92cf09aaf5c9791c4fb Mon Sep 17 00:00:00 2001 From: Perminder Singh Date: Thu, 26 Oct 2023 16:23:32 +0530 Subject: [PATCH 4/4] 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 83bcef7468..58c5999d08 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