From b92652a16ff518a499767790970c5a411d43ea3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=B6=C3=B6k?= Date: Tue, 12 Jul 2016 12:40:59 +0200 Subject: [PATCH 1/5] Added option to not show back face of text Added an optional option to textcomponents, option.backface {bool}. The extrusion of the text is set to 0 if user don't want back facing text --- src/goo/geometrypack/text/TextMeshGenerator.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/goo/geometrypack/text/TextMeshGenerator.js b/src/goo/geometrypack/text/TextMeshGenerator.js index 725183bdb..454efb4cc 100644 --- a/src/goo/geometrypack/text/TextMeshGenerator.js +++ b/src/goo/geometrypack/text/TextMeshGenerator.js @@ -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} */ function meshesForText(text, font, options) { @@ -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(); @@ -400,24 +401,28 @@ function meshesForText(text, font, options) { transform.update(); meshBuilder.addMeshData(meshData, transform); } + + if (options.backface) + 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); }); } From 2ad6483198882926c123e9952462e07e055953f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=B6=C3=B6k?= Date: Tue, 12 Jul 2016 12:57:06 +0200 Subject: [PATCH 2/5] Added {} around if-else statements --- src/goo/geometrypack/text/TextMeshGenerator.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/goo/geometrypack/text/TextMeshGenerator.js b/src/goo/geometrypack/text/TextMeshGenerator.js index 454efb4cc..1832459e1 100644 --- a/src/goo/geometrypack/text/TextMeshGenerator.js +++ b/src/goo/geometrypack/text/TextMeshGenerator.js @@ -402,11 +402,11 @@ function meshesForText(text, font, options) { meshBuilder.addMeshData(meshData, transform); } - if (options.backface) - frontFace(); - else // If the back face shouldn't be visible, set extrusion to 0s + if (options.backface) { + frontFace(); + } else { // If the back face shouldn't be visible, set extrusion to 0s options.extrusion = 0; - + } backFace(); if (options.extrusion) { From 52bdeb18aab5b8394362f2e9fee5630646972eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=B6=C3=B6k?= Date: Wed, 13 Jul 2016 10:31:07 +0200 Subject: [PATCH 3/5] Update TextMeshGenerator.js --- src/goo/geometrypack/text/TextMeshGenerator.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/goo/geometrypack/text/TextMeshGenerator.js b/src/goo/geometrypack/text/TextMeshGenerator.js index 1832459e1..a7363f33f 100644 --- a/src/goo/geometrypack/text/TextMeshGenerator.js +++ b/src/goo/geometrypack/text/TextMeshGenerator.js @@ -364,6 +364,7 @@ function dataForGlyph(glyph, options) { */ function meshesForText(text, font, options) { options = options || {}; + options.backface = options.backface !== undefined ? options.backface : true; options.extrusion = options.extrusion !== undefined ? options.extrusion : 4; options.stepLength = options.stepLength || 1; options.fontSize = options.fontSize || 48; From a94dbc79c4eac44075f289afb08340e6e38c100c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=B6=C3=B6k?= Date: Thu, 14 Jul 2016 11:01:02 +0200 Subject: [PATCH 4/5] Updated the functions frontface() and backface() Updated the functions to draw correct face of glyph mesh --- .../geometrypack/text/TextMeshGenerator.js | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/goo/geometrypack/text/TextMeshGenerator.js b/src/goo/geometrypack/text/TextMeshGenerator.js index a7363f33f..bc9d7e5bd 100644 --- a/src/goo/geometrypack/text/TextMeshGenerator.js +++ b/src/goo/geometrypack/text/TextMeshGenerator.js @@ -386,15 +386,6 @@ function meshesForText(text, font, options) { function meshForGlyph(data, x, y, options) { function frontFace() { - var meshData = new FilledPolygon(data.surfaceVerts, data.surfaceIndices); - var transform = new Transform(); - transform.translation.setDirect(x, y, -options.extrusion / 2); - transform.scale.setDirect(1, -1, 1); - transform.update(); - meshBuilder.addMeshData(meshData, transform); - } - - function backFace() { var meshData = new FilledPolygon(data.surfaceVerts, invertWinding(data.surfaceIndices)); var transform = new Transform(); transform.translation.setDirect(x, y, options.extrusion / 2); @@ -402,28 +393,38 @@ function meshesForText(text, font, options) { transform.update(); meshBuilder.addMeshData(meshData, transform); } - - if (options.backface) { - frontFace(); - } else { // If the back face shouldn't be visible, set extrusion to 0s - options.extrusion = 0; - } - backFace(); + + function backFace() { + var meshData = new FilledPolygon(data.surfaceVerts, data.surfaceIndices); + var transform = new Transform(); + transform.translation.setDirect(x, y, -options.extrusion / 2); + transform.scale.setDirect(1, -1, 1); + transform.update(); + meshBuilder.addMeshData(meshData, transform); + } + + frontFace(); + + if (options.backface) { + backFace(); + } else { // If the back face shouldn't be visible, set extrusion to 0s + options.extrusion = 0; + } - if (options.extrusion) { + 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); }); } From 335eb83d618b4bcf285de3ed2ad241c60649cba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=B6=C3=B6k?= Date: Thu, 14 Jul 2016 11:34:27 +0200 Subject: [PATCH 5/5] Fixed bug For some reason, the backface has to be drawn before front face, or else the text gets all weird --- src/goo/geometrypack/text/TextMeshGenerator.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/goo/geometrypack/text/TextMeshGenerator.js b/src/goo/geometrypack/text/TextMeshGenerator.js index bc9d7e5bd..a238d00b2 100644 --- a/src/goo/geometrypack/text/TextMeshGenerator.js +++ b/src/goo/geometrypack/text/TextMeshGenerator.js @@ -393,7 +393,7 @@ function meshesForText(text, font, options) { transform.update(); meshBuilder.addMeshData(meshData, transform); } - + function backFace() { var meshData = new FilledPolygon(data.surfaceVerts, data.surfaceIndices); var transform = new Transform(); @@ -403,15 +403,14 @@ function meshesForText(text, font, options) { meshBuilder.addMeshData(meshData, transform); } - frontFace(); - - if (options.backface) { + if (options.backface) { backFace(); - } else { // If the back face shouldn't be visible, set extrusion to 0s + } else { // If the back face shouldn't be visible, set extrusion to 0s options.extrusion = 0; - } - - if (options.extrusion) { + } + frontFace(); + + if (options.extrusion) { data.extrusions.forEach(function (polygon) { var contourVerts = getVerts(polygon); contourVerts.push(contourVerts[0], contourVerts[1], contourVerts[2]); @@ -430,7 +429,6 @@ function meshesForText(text, font, options) { } } - // get the total bounds; it's enough to merge the first and last chars var firstDataSet = dataSets[0]; var minX = firstDataSet.data.boundingVolume.min.x;