Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Skip adding degenerate faces in textToModel
  • Loading branch information
davepagurek committed Jul 4, 2025
commit 4f81bdba44eff6c8b1b1eae9f481ab8e36ce0a1f
10 changes: 9 additions & 1 deletion src/type/p5.Font.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,11 @@ export class Font {
({ width, height, options } = this._parseArgs(width, height, options));
const extrude = options?.extrude || 0;
const contours = this.textToContours(str, x, y, width, height, options);

const geom = this._pInst.buildGeometry(() => {
if (extrude === 0) {
const prevValidateFaces = this._pInst._renderer._validateFaces;
this._pInst._renderer._validateFaces = true;
this._pInst.beginShape();
this._pInst.normal(0, 0, 1);
for (const contour of contours) {
Expand All @@ -549,7 +552,11 @@ export class Font {
this._pInst.endContour(this._pInst.CLOSE);
}
this._pInst.endShape();
this._pInst._renderer._validateFaces = prevValidateFaces;
} else {
const prevValidateFaces = this._pInst._renderer._validateFaces;
this._pInst._renderer._validateFaces = true;

// Draw front faces
for (const side of [1, -1]) {
this._pInst.beginShape();
Expand All @@ -561,8 +568,9 @@ export class Font {
this._pInst.endContour(this._pInst.CLOSE);
}
this._pInst.endShape();
this._pInst.beginShape();
}
this._pInst._renderer._validateFaces = prevValidateFaces;

// Draw sides
for (const contour of contours) {
this._pInst.beginShape(this._pInst.QUAD_STRIP);
Expand Down
11 changes: 9 additions & 2 deletions src/webgl/GeometryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class GeometryBuilder {
* Adds geometry from the renderer's immediate mode into the builder's
* combined geometry.
*/
addImmediate(geometry, shapeMode) {
addImmediate(geometry, shapeMode, { validateFaces = false } = {}) {
const faces = [];

if (this.renderer.states.fillColor) {
Expand All @@ -129,7 +129,14 @@ class GeometryBuilder {
}
} else {
for (let i = 0; i < geometry.vertices.length; i += 3) {
faces.push([i, i + 1, i + 2]);
if (
!validateFaces ||
geometry.vertices[i].copy().sub(geometry.vertices[i+1])
.cross(geometry.vertices[i].copy().sub(geometry.vertices[i+2]))
.magSq() > 0
) {
faces.push([i, i + 1, i + 2]);
}
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ class RendererGL extends Renderer {
}
return this._internalDisable.call(this.drawingContext, key);
};

// Whether or not to remove degenerate faces from geometry. This is usually
// set to false for performance.
this._validateFaces = false;
}

remove() {
Expand Down Expand Up @@ -562,7 +566,8 @@ class RendererGL extends Renderer {
if (this.geometryBuilder) {
this.geometryBuilder.addImmediate(
this.shapeBuilder.geometry,
this.shapeBuilder.shapeMode
this.shapeBuilder.shapeMode,
{ validateFaces: this._validateFaces }
);
} else if (this.states.fillColor || this.states.strokeColor) {
if (this.shapeBuilder.shapeMode === constants.POINTS) {
Expand Down Expand Up @@ -2614,7 +2619,7 @@ function rendererGL(p5, fn) {
* }
* </code>
* </div>
*
*
* <div>
* <code>
* // Now with the antialias attribute set to true.
Expand Down
Loading