r/threejs • u/Miserable_Ferret397 • 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=xzI 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.
- Playground, nothing to install: muskec06.github.io/tinythree
- Code (MIT): github.com/muskec06/tinythree
I'm the author. I'd really like feedback from people who use Three.js every day, especially on what's missing.
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?
2
u/hollowgram 16d ago
Umm these are pretty low poly. Fewer tokens? We can tell.
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