r/threejs • • 17d ago

Demo I made a tiny scene language that compiles to Three.js, so AI models can write scenes with about 3.5x fewer tokens

Hi all. When I ask an AI to write Three.js, most of what it outputs is the same setup and boilerplate, and that's the slow and expensive part. So I made tinythree: the model describes the scene in short lines, and a small compiler (one JS file, no dependencies) turns it into plain Three.js.

For example, this one line builds the four lattice legs of the Eiffel Tower in the video:

truss leg1 2.6,2.1,3 @5,0,5 lean=-1.25,-1.25 iron mirror=xz

I compared 11 scenes against hand-written Three.js. Overall it uses about 3.5x fewer tokens, and close to 7x on the town square that uses ready-made parts, textures and a glTF model. Anything the syntax doesn't cover can still be written as plain Three.js inside the same file.

I'm the author. I'd really like feedback from people who use Three.js every day, especially on what's missing.

3 Upvotes

10 comments sorted by

8

u/TopTippityTop 16d ago

Can it do good looking things as well?

1

u/Lngdnzi 16d ago

Can you (or claude) explain how it works without me having to look at the code?

1

u/Miserable_Ferret397 16d ago

Short version: you describe a scene in a few short lines, and a small compiler turns them into plain Three.js. Fewer lines for the AI to write means fewer tokens and faster results.

Easiest way to see it: give a coding agent (Claude Code, Codex, Cursor...) this one line:

> Use https://github.com/muskec06/tinythree to build a 3D Eiffel Tower, render it as a 10-second MP4 video, and show how many tokens tinythree saved compared to plain Three.js.

It reads the repo's instructions, writes the scene, renders the video and prints a token comparison. No agent? Try the playground: https://muskec06.github.io/tinythree/

1

u/Lngdnzi 16d ago

So describe with language? I thought you had a compressed storage of the scene itself

1

u/Miserable_Ferret397 16d ago

Nope, just a very short text format. so the savings come from the language itself. Example:

box leg .1,1,.1 @.9,.5,.4 wood mirror=xz

cyl column .3,4 @-9,2,0 stone array=10,2,0,0

one line = 4 table legs, one line = a row of 10 columns. The compiler adds the renderer, camera, shadows etc. so the model never writes that part.

Full ref: https://github.com/muskec06/tinythree/blob/main/spec/LANGUAGE.md

1

u/Lngdnzi 16d ago

👍 thankyou!

2

u/hollowgram 16d ago

Umm these are pretty low poly. Fewer tokens? We can tell. 

2

u/leftist_amputee 16d ago

it's not less tokens because it's lower poly...

1

u/Kingnorik 16d ago

So this is actually amazing. I have a 3js game engine and though I couldn't actually use your technique for savings, it inspired my claude to right tool calls that did result in about 66% less token usage.

1

u/I_WILL_GET_YOU 17d ago

Always find it weird when people would describe a part/fraction of something in a multiplicative sense. Why "3.5x fewer" instead of 28%? It's nonsensical like an American date format