Skip to content

Commit

Permalink
done with issue processing#6383
Browse files Browse the repository at this point in the history
  • Loading branch information
SoniNisha committed Oct 20, 2023
1 parent 186553b commit 1d858ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/webgl/3d_primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ p5.RendererGL.prototype.quad = function(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4,
}
quadGeom
.computeNormals()
._makeTriangleEdges()
._makeQuadEdges()
._edgesToVertices();
this.createBuffers(gId, quadGeom);
}
Expand Down
31 changes: 25 additions & 6 deletions src/webgl/p5.Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -111,7 +111,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]];
Expand Down Expand Up @@ -196,7 +196,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]);
Expand Down Expand Up @@ -227,6 +227,25 @@ p5.Geometry = class Geometry {
}
return this;
}
/**
* Create a 2D array for establishing stroke connections
* @private
* @chainable
*/
_makeQuadEdges() {
this.edges.length = 0;

const vertexOrder = [0, 2, 3, 1];

for (let i = 0; i < vertexOrder.length; i++) {
const startVertex = vertexOrder[i];
const endVertex = vertexOrder[(i + 1) % vertexOrder.length];

this.edges.push([startVertex, endVertex]);
}

return this;
}

/**
* Create a 2D array for establishing stroke connections
Expand Down Expand Up @@ -507,7 +526,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();

Expand Down

0 comments on commit 1d858ef

Please sign in to comment.