← All notes

FIELD NOTE 3D RENDERING · TEXT LAYOUT

Why did widening a 3D text box stretch the letters?

At JigSpace we build tools for making interactive 3D presentations called Jigs. In 2022, Jig authors asked to edit labels directly in the app.

// How I work · Problem solving

What the box needed to do

Until then, authors had to turn their words into an image and apply it to the surface of a 3D object. Even fixing a typo meant editing the text, generating a new image and replacing the old one. They wanted to change the word right there in the JigSpace app.

I worked on the viewer, the web app people used to play Jigs in their browser. My job was to make the text box display correctly there using Babylon.js. An author could put an instruction on the front of a box, then make the box wider or taller in the next step of the Jig. The words had to follow the box, stay on that face and wrap to fit the new space.

I could get a label looking right while the box stood still. My test was to pull the box wider. Did I get more room for words, or just wider letters? Look at the O in OPEN VALVE as you move the slider.

Try changing the width

One box, two ways to draw its text
Before · Inherited scaleOPEN VALVE
After · Compensated planeOPEN VALVE
1.85×

Move the slider or use the arrow keys to change the width. At 1×, both drawings match. Below 1×, watch where “OPEN VALVE” wraps. The dotted outline shows the square that carries the text.

Illustrative reconstruction in 2D. Both boxes have the same dimensions at every slider position.

What I tried in the Playground

I started with a Babylon.js 3D button because it already had a label. The label stretched when I resized the button. I tried a custom mesh button so I could choose its dimensions, but my prototype showed an empty box. MeshWriter gave me visible letters, only now they were sitting somewhere inside the box.

Drawing the words onto the box as a texture got them onto the right face. I kept that prototype as a fallback. To make a long instruction wrap, I’d have to measure and draw every line myself.

I posted the small examples on the Babylon.js forum. Carol suggested using Babylon’s GUI in texture mode so its TextBlock could do the wrapping. When I applied the texture to the box, the words appeared on several faces. I attached a flat plane to the front and put the text there instead.

That prototype worked when I changed the box’s width and height directly. In our viewer, a Jig could change those proportions by scaling the box between steps. The plane was attached to the box, so it inherited that stretch. I had the words in the right place and wrapping. Now I needed to keep the letters in proportion while their parent moved.

A square for the letters

The text was on its own plane now. What if I let the box change shape but kept the plane square? For a wide box, I made the plane as tall as the box was wide. The letters kept their proportions. The square did stick out above and below the box, so I added padding to keep the words inside the visible face. For a tall box, the extra space and the padding went on the sides. Babylon’s GUI could handle the line breaks from there.

My first version updated the layout when the box stopped moving. The words looked right at the end of a step but still stretched on the way there. I moved that calculation into the animation so it ran on every frame. When a wide box became a tall one, the padding had to switch sides as the box passed through a square. I drew the two directions in my code comments (▬▬ → █ and █ → ▬▬) so I could see which dimension to adjust.

Presenting the viewer work in a Jig

For our team meeting, I made a Jig about the viewer and presented it in the viewer itself. I showed the finished text box first. By the time I brought the square plane into view, everyone had seen the behaviour it explained. You could follow what happened to the letters even if you’d never opened a 3D editor. I showed the scaling cases that still looked wrong, too.

People in marketing, sales and engineering all enjoyed that demo. I think I’m good at these presentations, and I love giving them. Part of the fun for me is finding something everyone can see for themselves. A developer might call the bug “inherited scale.” Anyone who’d watched the Jig could point to the same moment and say, “That’s where the letters stretch.” I want to close those gaps in what we know about each other’s work.

Steps 1–7 show the finished text box. From step 8, I walk through the prototypes and the workaround. View the original team Jig. If it won’t load, you can open the backup Jig.

Open the Babylon.js Playground example to explore the text and its parent in a 3D scene.

I used a different demo when I needed to explain the work behind our AI platform to people outside the backend team. Read “How I explained the work behind Generate.”

What stayed with me

I’d never worked with WebGL before, and Babylon.js was new to me. What helped was having something small enough to check on screen every time I got stuck. Even the prototype with text on every face told me something useful. I could leave the wrapping alone and experiment with where I put the text.

A little over a week after I posted those prototypes on the forum, we merged the first version into the viewer. I still think keeping the text plane square was a clever workaround. Getting an ordinary line of text to behave that way was the part I enjoyed most.

What I’d ask earlier

I asked our Unity developers and another teammate for advice. Looking back, I wish I’d also shown the stretching O to our 3D artists. Some of them had worked on games. “Have you ever had to keep a label readable while the object underneath it changes shape?” They might have recognised the problem from a completely different engine and saved me a few rounds in the Playground.

I’d also ask the Babylon.js community about text layout libraries explicitly. (I’d searched the forum and tried MeshWriter. It gave me 3D letters, but I still needed a label that could reflow.) Unity had tools for that. I’d have liked to hear from someone who’d used a third-party library for a similar label in Babylon.js before deciding how much to build myself.

Postscript: If I built it today

In 2026, I revisited the scaling code. A box could go from narrow to wide and back again, and the letters could come back a slightly different shape. Each step adjusted the text plane from its previous scale, so small errors could add up. I changed the calculation to use the box’s original proportions and its current ones. Now returning to the same proportions gives the same result, however many steps it takes.

Our newer viewer runs on Three.js. It uses troika-three-text, a library that puts text directly in the scene. Our viewer works out how much room the label has as the box changes shape. We pass that width, the words and a font size to Troika, and it wraps the lines and draws the letters.

If I built this in Three.js today, I’d start with Troika. I’d still use the same test I used in 2022. Stretch the box and watch the O.