Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to not show back face of text #38

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
17 changes: 11 additions & 6 deletions src/goo/geometrypack/text/TextMeshGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ function dataForGlyph(glyph, options) {
* @param {number} [options.extrusion=4] Extrusion amount
* @param {number} [options.fontSize=48]
* @param {number} [options.stepLength=1] Lower values result in a more detailed mesh
* @param {bool} [options.backface=true] If text should be backfaced
* @returns {Array<MeshData>}
*/
function meshesForText(text, font, options) {
Expand Down Expand Up @@ -391,7 +392,7 @@ function meshesForText(text, font, options) {
transform.update();
meshBuilder.addMeshData(meshData, transform);
}

function backFace() {
var meshData = new FilledPolygon(data.surfaceVerts, invertWinding(data.surfaceIndices));
var transform = new Transform();
Expand All @@ -400,24 +401,28 @@ function meshesForText(text, font, options) {
transform.update();
meshBuilder.addMeshData(meshData, transform);
}

if (options.backface)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add { }

frontFace();
else // If the back face shouldn't be visible, set extrusion to 0s
options.extrusion = 0;

frontFace();
backFace();
backFace();

if (options.extrusion) {
data.extrusions.forEach(function (polygon) {
var contourVerts = getVerts(polygon);
contourVerts.push(contourVerts[0], contourVerts[1], contourVerts[2]);

var contourPolyLine = new PolyLine(contourVerts, true);
var extrusionPolyLine = new PolyLine([0, 0, -options.extrusion / 2, 0, 0, options.extrusion / 2]);
var meshData = contourPolyLine.mul(extrusionPolyLine);

var transform = new Transform();
transform.translation.setDirect(x, y, 0);
transform.scale.setDirect(1, -1, -1);
transform.update();

meshBuilder.addMeshData(meshData, transform);
});
}
Expand Down