Skip to content

Commit f1052e6

Browse files
committed
Fix text extrusion with proper vertex deduplication, edge detection, and normal calculation with recomended changes
1 parent 0b31fa5 commit f1052e6

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/type/p5.Font.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -545,24 +545,18 @@ export class Font {
545545
const extrude = options?.extrude || 0;
546546

547547
let contours = this.textToContours(str, x, y, width, height, options);
548-
if (!Array.isArray(contours[0][0])) {
549-
contours = [contours];
550-
}
551-
552548
// Step 2: build base flat geometry - single shape
553549
const geom = this._pInst.buildGeometry(() => {
554550
const prevValidateFaces = this._pInst._renderer._validateFaces;
555551
this._pInst._renderer._validateFaces = true;
556552

557553
this._pInst.beginShape();
558-
for (const glyphContours of contours) {
559-
for (const contour of glyphContours) {
560-
this._pInst.beginContour();
561-
for (const pt of contour) {
562-
this._pInst.vertex(pt.x, pt.y, 0);
563-
}
564-
this._pInst.endContour(this._pInst.CLOSE);
554+
for (const contour of contours) {
555+
this._pInst.beginContour();
556+
for (const pt of contour) {
557+
this._pInst.vertex(pt.x, pt.y, 0);
565558
}
559+
this._pInst.endContour(this._pInst.CLOSE);
566560
}
567561

568562
this._pInst.endShape(this._pInst.CLOSE);
@@ -626,8 +620,11 @@ export class Font {
626620
for (const [a, b] of validEdges) {
627621
const vA = newVertices[a];
628622
const vB = newVertices[b];
623+
629624
// Skip if vertices are too close (degenerate edge)
630-
// Check if the cross product of edge vectors has sufficient magnitude
625+
// We only need to check the perimeter edge length since the other edge
626+
// is the extrude direction, which is always > 0 for extruded geometry
627+
631628
const edgeVector = new Vector(vB.x - vA.x, vB.y - vA.y, vB.z - vA.z);
632629
const extrudeVector = new Vector(0, 0, extrude);
633630
const crossProduct = Vector.cross(edgeVector, extrudeVector);

0 commit comments

Comments
 (0)