Skip to content

Commit

Permalink
fixing-text-model
Browse files Browse the repository at this point in the history
  • Loading branch information
perminder-17 committed Jan 23, 2025
1 parent f6c8fcf commit 924af7b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/type/p5.Font.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,40 +119,52 @@ function font(p5, fn) {
const contours = this.textToContours(str, x, y, width, height, options);
const geom = this._pInst.buildGeometry(() => {
if (extrude === 0) {
this._pInst.push();
this._pInst.rotateX(this._pInst.PI);
this._pInst.rotateZ(-this._pInst.HALF_PI);
this._pInst.beginShape();
this._pInst.normal(0, 0, 1);
for (const contour of contours) {
this._pInst.beginContour();
for (const { x, y } of contour) {
this._pInst.vertex(x, y);
this._pInst.vertex(y, x);
}
this._pInst.endContour(this._pInst.CLOSE);
}
this._pInst.endShape();
this._pInst.pop();

} else {
// Draw front faces
for (const side of [1, -1]) {
this._pInst.beginShape();
for (const contour of contours) {
this._pInst.beginContour();
for (const { x, y } of contour) {
this._pInst.vertex(x, y, side * extrude * 0.5);
this._pInst.vertex(y, x, side * extrude * 0.5);
}
this._pInst.endContour(this._pInst.CLOSE);
}
this._pInst.push();
this._pInst.rotateX(this._pInst.PI);
this._pInst.rotateZ(-this._pInst.HALF_PI);
this._pInst.endShape();
this._pInst.beginShape();
this._pInst.pop();
}
// Draw sides
this._pInst.push();
this._pInst.rotateX(this._pInst.PI);
this._pInst.rotateZ(-this._pInst.HALF_PI);
for (const contour of contours) {
this._pInst.beginShape(this._pInst.QUAD_STRIP);
for (const v of contour) {
for (const side of [-1, 1]) {
this._pInst.vertex(v.x, v.y, side * extrude * 0.5);
this._pInst.vertex(v.y, v.x, side * extrude * 0.5);
}
}
this._pInst.endShape();
}
this._pInst.pop();
}
});
if (extrude !== 0) {
Expand Down

0 comments on commit 924af7b

Please sign in to comment.