Adding a new font for MeshWriter

@TheLeftover,

The font is not secret, but I just cannot share because it is what my employer owns. But there are several fonts that are very similar, such as this one.

In ideal world, I would like to have only one or two sample fonts included in the meshwriter package to present the way how they are converted. And I would like to convert my font following your documentation, because this will not be a one-time job. In the future, I will probably want to convert different fonts to use in Babylon. :wink:

I am amused and amazed so share that I have been solved many of the problems for automatic 3D font generation. There is a new font family used in this playground. See if you can spot it: https://www.babylonjs-playground.com/#NLG6KE#2 (Hint: Not the anchor.)

The new glyph was automatically generated from a font file in Javascript. No tuning by me.

There are many steps from this to a useful utility but I believe the technical risk is negligible.

Hey @Wingnut, send me a .ttf or .otf of that font you wanted me to add. I am gonna try out my auto-converter on it.

Hi TL. Unfortunately, it looks like a pay-to-play. Stefán Kjartansson's Personal Portfolio

There appears to be more than one version of Cinderblock, but this is the one I like best. Lots of face surface area to see reflected pictures upon. There may be other fonts with this same surface-area goodness. Any “bold’n’block” at least “leans-toward” high-surface.

(Wingy digs-into Deltakosh’s wallet to see if he has a Microsoft-comped Gold or Black credit card.) :slight_smile:

Sorry, TL. That’s a darned nice offer from ya, thanks!

If I had an easily-found $89.00 to drop on this, I might. I wonder if pathetic begging to its author… would work. I would need a sob-story… something about an injured puppy that can only be saved… by a FREE copy/license of Stefan’s Cinderblock webfonts. :slight_smile:

He might not believe the hurt puppy story… but he might think our attempt was worth $89 in entertainment. :smiley:

Hello Samba (or anyone else):

Would you kindly try to make your own custom MeshWriter package using the instructions provided in the repos? I would like to know that one person (other than me) has succeeded once. The key repos are MeshWriter and MeshWriter-Font.

Start here: GitHub - briantbutton/meshwriter-font: Create font files for meshwriter

Thank you.

Hi TheLeftover,

Just tried it, and was able to successfully created meshwriter.js. However, when I added it into the sample code, it produced an error. Can you tell what I did wrong? The entire code is here: https://www.babylonjs-playground.com/#PL752W#33

Font used: fonts/Inconsolata-Regular.ttf at master · google/fonts · GitHub

Thanks!!

Archive.zip (28.4 KB)

Samba, yes. I think you did it!

Minor error at the end.

In the playground there was no default font specified; so MeshWriter went to Helvetica Neue. This was no longer there. Hence the error. I added a reference to your font as the default font on line 1761 and it worked as intended.
https://www.babylonjs-playground.com/#PL752W#34

Samba, thanks for trying this out so promptly. The results worked better than anything I could have hoped for.

I would suggest leaving Helvetica Neue in future builds. That will keep that mysterious user error from happening.

With minification, the resulting module is pleasingly small. I recommend ‘terser’, per the instructions. You will need several fonts to drive the size over 100K.

I will call this mission complete. Thanks for the inspiration to figure out the next steps.

@TheLeftover, thank you so much for your hard work on this. It was super easy to make it up and run. I will definitely try terser as well. Thanks again, this is an awesome magic!

hey there @TheLeftover. i’m so psyked about your font package. just what i was looking for. couple questions. I just ran through all the steps… and successfully generated a new meshwriter.js file. Included it as per instructions, but looks like i’ve still got only the default fonts.

Output from node script was:

convertFontFile({suffix:“otf”,name:“StargazeRegular”,compress:true})
undefined
Wrote MeshWriter font file to ‘…/meshwriter/fonts/stargazeregular.js’
convertFontFile({suffix:“otf”,name:“StargazeStencil”,compress:true})
undefined
Wrote MeshWriter font file to ‘…/meshwriter/fonts/stargazestencil.js’

I don’t see it picking up those fonts in the build though…even though i can see them there in the same Dir as with all of the default fonts.

Hash: **ab76675860738ab726da**
Version: webpack **4.39.3**
Time: **187** ms
Built at: 2019-08-27 **19:17:14**
**Asset** **Size** **Chunks** **Chunk Names**
**meshwriter.js** **259 KiB** **0** **[emitted]** **[big]** main
Entrypoint **main** **[big]** = **meshwriter.js**
[0] **./index.js** 31 KiB { **0** } **[built]**
[1] **(webpack)/buildin/global.js** 472 bytes { **0** } **[built]**
[2] **./fonts/hirukopro-book.js** 48.3 KiB { **0** } **[built]**
[3] **./fonts/helveticaneue-medium.js** 48.7 KiB { **0** } **[built]**
[4] **./fonts/comicsans-normal.js** 68.4 KiB { **0** } **[built]**
[5] **./fonts/jura-demibold.js** 41.9 KiB { **0** } **[built]**
[6] **./fonts/webgl-dings.js** 14.3 KiB { **0** } **[built]**

Is there a step I’m missing?

bigrig, very pleased you like it.

I think you are about halfway there. It looks like you put the font files in the correct directory. The next step is creating the pointers to those files for your build. For that you need to edit index.js. Please view the instructions at the link below for further guidance.

What those instructions tell you is that you must take three wee, tiny steps in index.js for each font file. You can remove existing files, EXCEPT helvetica. It is the default font and removing it might cause errors.

I hope that helps. We’re here all night!

Aha! Was just about to write to say that I discovered the missing steps. Did that and the build went off fine. No luck on the front end though. Just see what looks like a play button. My “stargazer” font on left - and Jura on the right in screenshot below. Using the same BJS code (just changing the font font-family). Any suggestions?

Build: 
Hash: **4bf3c7ca622059a36a1b**

Version: webpack **4.39.3**

Time: **167** ms

Built at: 2019-08-27 **20:53:37**

**Asset** **Size** **Chunks** **Chunk Names**

**meshwriter.js** **269 KiB** **0** **[emitted]** **[big]** main

Entrypoint **main** **[big]** = **meshwriter.js**

[0] **./index.js** 31.3 KiB { **0** } **[built]**

[1] **(webpack)/buildin/global.js** 472 bytes { **0** } **[built]**

[2] **./fonts/hirukopro-book.js** 48.3 KiB { **0** } **[built]**

[3] **./fonts/helveticaneue-medium.js** 48.7 KiB { **0** } **[built]**

[4] **./fonts/comicsans-normal.js** 68.4 KiB { **0** } **[built]**

[5] **./fonts/jura-demibold.js** 41.9 KiB { **0** } **[built]**

[6] **./fonts/webgl-dings.js** 14.3 KiB { **0** } **[built]**

[7] **./fonts/stargazeregular.js** 4.62 KiB { **0** } **[built]**

[8] **./fonts/stargazestencil.js** 4.62 KiB { **0** } **[built]**

 // >>>>>  STEP 1 <<<<<
  ['./fonts/hirukopro-book','./fonts/helveticaneue-medium','./fonts/comicsans-normal','./fonts/jura-demibold','./fonts/webgl-dings','./fonts/stargazeregular','./fonts/stargazestencil'],
  function(HPB,HNM,CSN,JUR,WGD,SGR,SGS){
  // >>>>>  STEP 1 <<<<<

var scene,FONTS,defaultColor,defaultOpac,naturalLetterHeight,curveSampleSize,Γ=Math.floor,hpb,hnm,csn,jur,wgd,sgr,sgs,debug;
var b128back,b128digits;
prepArray();
// >>>>>  STEP 2 <<<<<
hpb                          = HPB(codeList);
hnm                          = HNM(codeList);                         // Do not remove
csn                          = CSN(codeList);
jur                          = JUR(codeList);
wgd                          = WGD(codeList);
sgr                          = SGR(codeList);
sgs                          = SGS(codeList);	
// >>>>>  STEP 2 <<<<<
FONTS                        = {};
// >>>>>  STEP 3 <<<<<
FONTS["HirukoPro-Book"]      = hpb;
FONTS["HelveticaNeue-Medium"]= hnm;                                   // Do not remove
FONTS["Helvetica"]           = hnm;
FONTS["Arial"]               = hnm;
FONTS["sans-serif"]          = hnm;
FONTS["Comic"]               = csn;
FONTS["comic"]               = csn;
FONTS["ComicSans"]           = csn;
FONTS["Jura"]                = jur;
FONTS["jura"]                = jur;
FONTS["WebGL-Dings"]         = wgd;
FONTS["Web-dings"]           = wgd;
FONTS["StargazerRegular"]    = sgr;
FONTS["StargazerStencil"]    = sgs;
// >>>>>  STEP 3 <<<<<
defaultColor                 = "#808080";
defaultOpac                  = 1;
curveSampleSize              = 6;
naturalLetterHeight          = 1000;

Well, I will first say that you did everything perfectly in index.js. That’s good.

I also think I know what the problem is. Also good.

Thanks for sending all the detailed information. I noticed that the new fonts were both 4.62K. This tells me that they did not build correctly. You can see the others are about ten times as large.

The obvious suspect is MeshWriter-Font in combination with stargazer. I tested on five or six different types of font files but it doesn’t have a long history. Font files have different major formats and variations within formats.

I am probably gonna hafta pop the hood now. If you could tell me where to find the original .ttf or .otf stargazer font files, I can take a look myself.

This may take a couple days. Sorry.

Hey, no worries! This is just so awesome to begin with… I’ll DM you the fonts (since I purchased them… better not to post a public link).

bigrig, your comment – that only numbers are built by meshwriter-font – indicates to me that perhaps there is something wrong with the config file.

The config file specifies default glyphs. But if it isn’t there, then meshwriter-font just builds the digits. I did run a build just now on StarGaze and the output files looked OK. I didn’t try to render them but I am sending them to you.

The only thing I did was to replace the space in the file name with a dash.

Anyway try out the font files I sent you. Check whether your config file is loading properly. Lemme know.

Oh, I think I DMed you and meant to post here… Reposting last message (for future public benefit):

I compiled your build and got interesting results. Playgrounds here:

Note that you gotta shift refresh, or cache doesn’t clear, even with caching set to false and with changing playground numbers.

ps. know you said you were busy to weekend, so no rush! i just got interested in debugging a bit.

Thanks bigrig, I am not feeling rushed.

Before I dash off to other stuff, let me do some drive-by troubleshooting. It looks like the side textures are facing inward, not outward.

There are two flags at the top of each font file, reverseShapes and reverseHoles. Play with changing one or the other or both. If something interesting emerges, lemme know.

.otf fonts are wound a particular way. Maybe these don’t follow a convention that I thought was universal.

Looks like that did something For the letters that it does render, they are looking better.
https://www.babylonjs-playground.com/#PL752W#61
On Regular (bottom one in screenshot), i’ve got: var font={reverseHoles:false,reverseShapes:false}
On Stencil, I’ve got: var font={reverseHoles:true,reverseShapes:true}

And Voila!
The magic combo: var font={reverseHoles:true,reverseShapes:false}
https://www.babylonjs-playground.com/#PL752W#64

It’s looking kickass.
Thanks TheLeftover for sharing this phenomenal piece of code.

57%20PM