Skip to content

Commit

Permalink
continue
Browse files Browse the repository at this point in the history
  • Loading branch information
asukaminato0721 committed May 31, 2023
1 parent 9138b37 commit 40826f0
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -1663,14 +1663,12 @@ p5.RendererGL = class RendererGL extends p5.Renderer {
//big models , load slower to avoid stack overflow
//faster non-recursive flatten via axelduch
//stackoverflow.com/questions/27266550/how-to-flatten-nested-array-in-javascript
const toString = Object.prototype.toString;
const arrayTypeStr = '[object Array]';
const result = [];
const nodes = arr.slice();
let node;
node = nodes.pop();
do {
if (toString.call(node) === arrayTypeStr) {
if (Array.isArray(node)) {
nodes.push(...node);
} else {
result.push(node);
Expand Down Expand Up @@ -1702,8 +1700,35 @@ p5.RendererGL = class RendererGL extends p5.Renderer {

return ret;
}
};

// function to calculate BezierVertex Coefficients
_bezierCoefficients (t) {
const t2 = t * t;
const t3 = t2 * t;
const mt = 1 - t;
const mt2 = mt * mt;
const mt3 = mt2 * mt;
return [mt3, 3 * mt2 * t, 3 * mt * t2, t3];
}

// function to calculate QuadraticVertex Coefficients
_quadraticCoefficients (t) {
const t2 = t * t;
const mt = 1 - t;
const mt2 = mt * mt;
return [mt2, 2 * mt * t, t2];
}

// function to convert Bezier coordinates to Catmull Rom Splines
_bezierToCatmull (w) {
const p1 = w[1];
const p2 = w[1] + (w[2] - w[0]) / this._curveTightness;
const p3 = w[2] - (w[3] - w[1]) / this._curveTightness;
const p4 = w[2];
const p = [p1, p2, p3, p4];
return p;
}
};
/**
* ensures that p5 is using a 3d renderer. throws an error if not.
*/
Expand Down Expand Up @@ -1814,32 +1839,5 @@ p5.RendererGL.prototype._triangulate = function (contours) {
return triangleVerts;
};

// function to calculate BezierVertex Coefficients
p5.RendererGL.prototype._bezierCoefficients = function (t) {
const t2 = t * t;
const t3 = t2 * t;
const mt = 1 - t;
const mt2 = mt * mt;
const mt3 = mt2 * mt;
return [mt3, 3 * mt2 * t, 3 * mt * t2, t3];
};

// function to calculate QuadraticVertex Coefficients
p5.RendererGL.prototype._quadraticCoefficients = function (t) {
const t2 = t * t;
const mt = 1 - t;
const mt2 = mt * mt;
return [mt2, 2 * mt * t, t2];
};

// function to convert Bezier coordinates to Catmull Rom Splines
p5.RendererGL.prototype._bezierToCatmull = function (w) {
const p1 = w[1];
const p2 = w[1] + (w[2] - w[0]) / this._curveTightness;
const p3 = w[2] - (w[3] - w[1]) / this._curveTightness;
const p4 = w[2];
const p = [p1, p2, p3, p4];
return p;
};

export default p5.RendererGL;

0 comments on commit 40826f0

Please sign in to comment.