Skip to content

Commit 4c91d6e

Browse files
committed
Fix textToModel extrusion and degenerate face issues
1 parent 3e567bf commit 4c91d6e

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
@@ -583,12 +583,12 @@ export class Font {
583583
extruded.faces = [];
584584

585585
let vertexIndex = 0;
586-
586+
const Vector = this._pInst.constructor.Vector;
587587
// Helper to add a triangle with flat normal
588588
const addTriangle = (v0, v1, v2) => {
589-
const edge1 = p5.Vector.sub(v1, v0);
590-
const edge2 = p5.Vector.sub(v2, v0);
591-
const normal = p5.Vector.cross(edge1, edge2);
589+
const edge1 = Vector.sub(v1, v0);
590+
const edge2 = Vector.sub(v2, v0);
591+
const normal = Vector.cross(edge1, edge2);
592592
if (normal.magSq() > 0.0001) {
593593
normal.normalize();
594594
} else {
@@ -609,9 +609,9 @@ export class Font {
609609
const v1 = geom.vertices[face[i]];
610610
const v2 = geom.vertices[face[i + 1]];
611611
addTriangle(
612-
new p5.Vector(v0.x, v0.y, v0.z + half),
613-
new p5.Vector(v1.x, v1.y, v1.z + half),
614-
new p5.Vector(v2.x, v2.y, v2.z + half)
612+
new Vector(v0.x, v0.y, v0.z + half),
613+
new Vector(v1.x, v1.y, v1.z + half),
614+
new Vector(v2.x, v2.y, v2.z + half)
615615
);
616616
}
617617
}
@@ -623,9 +623,9 @@ export class Font {
623623
const v1 = geom.vertices[face[i]];
624624
const v2 = geom.vertices[face[i + 1]];
625625
addTriangle(
626-
new p5.Vector(v0.x, v0.y, v0.z - half),
627-
new p5.Vector(v2.x, v2.y, v2.z - half),
628-
new p5.Vector(v1.x, v1.y, v1.z - half)
626+
new Vector(v0.x, v0.y, v0.z - half),
627+
new Vector(v2.x, v2.y, v2.z - half),
628+
new Vector(v1.x, v1.y, v1.z - half)
629629
);
630630
}
631631
}
@@ -655,14 +655,14 @@ export class Font {
655655
const v0 = geom.vertices[a];
656656
const v1 = geom.vertices[b];
657657

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

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

0 commit comments

Comments
 (0)