Skip to content

Commit 546ec24

Browse files
committed
Fix textToModel extrusion and degenerate face issues
1 parent c7fd306 commit 546ec24

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/type/p5.Font.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,12 @@ export class Font {
584584
extruded.faces = [];
585585

586586
let vertexIndex = 0;
587-
587+
const Vector = this._pInst.constructor.Vector;
588588
// Helper to add a triangle with flat normal
589589
const addTriangle = (v0, v1, v2) => {
590-
const edge1 = p5.Vector.sub(v1, v0);
591-
const edge2 = p5.Vector.sub(v2, v0);
592-
const normal = p5.Vector.cross(edge1, edge2);
590+
const edge1 = Vector.sub(v1, v0);
591+
const edge2 = Vector.sub(v2, v0);
592+
const normal = Vector.cross(edge1, edge2);
593593
if (normal.magSq() > 0.0001) {
594594
normal.normalize();
595595
} else {
@@ -610,9 +610,9 @@ export class Font {
610610
const v1 = geom.vertices[face[i]];
611611
const v2 = geom.vertices[face[i + 1]];
612612
addTriangle(
613-
new p5.Vector(v0.x, v0.y, v0.z + half),
614-
new p5.Vector(v1.x, v1.y, v1.z + half),
615-
new p5.Vector(v2.x, v2.y, v2.z + half)
613+
new Vector(v0.x, v0.y, v0.z + half),
614+
new Vector(v1.x, v1.y, v1.z + half),
615+
new Vector(v2.x, v2.y, v2.z + half)
616616
);
617617
}
618618
}
@@ -624,9 +624,9 @@ export class Font {
624624
const v1 = geom.vertices[face[i]];
625625
const v2 = geom.vertices[face[i + 1]];
626626
addTriangle(
627-
new p5.Vector(v0.x, v0.y, v0.z - half),
628-
new p5.Vector(v2.x, v2.y, v2.z - half),
629-
new p5.Vector(v1.x, v1.y, v1.z - half)
627+
new Vector(v0.x, v0.y, v0.z - half),
628+
new Vector(v2.x, v2.y, v2.z - half),
629+
new Vector(v1.x, v1.y, v1.z - half)
630630
);
631631
}
632632
}
@@ -656,14 +656,14 @@ export class Font {
656656
const v0 = geom.vertices[a];
657657
const v1 = geom.vertices[b];
658658

659-
const vFront0 = new p5.Vector(v0.x, v0.y, v0.z + half);
660-
const vFront1 = new p5.Vector(v1.x, v1.y, v1.z + half);
661-
const vBack0 = new p5.Vector(v0.x, v0.y, v0.z - half);
662-
const vBack1 = new p5.Vector(v1.x, v1.y, v1.z - half);
659+
const vFront0 = new Vector(v0.x, v0.y, v0.z + half);
660+
const vFront1 = new Vector(v1.x, v1.y, v1.z + half);
661+
const vBack0 = new Vector(v0.x, v0.y, v0.z - half);
662+
const vBack1 = new Vector(v1.x, v1.y, v1.z - half);
663663

664664
// Two triangles forming the side quad
665-
addTriangle(vFront0, vFront1, vBack1);
666-
addTriangle(vFront0, vBack1, vBack0);
665+
addTriangle(vFront0, vBack0, vBack1);
666+
addTriangle(vFront0, vBack1, vFront1);
667667
}
668668
return extruded;
669669
}

0 commit comments

Comments
 (0)