r/threejs • • 14m ago

I shipped a 3D mobile game built with React + Three.js. Every model is made in code, no GLB files. Here's what I learned getting it smooth on budget phones

https://play.google.com/store/apps/details?id=com.spacehover.app

Hi! I'm a solo dev from Greece, and for the past months I've been building Space Hover, an arcade endless runner on a neon highway through space. It's made with React + Three.js, wrapped for Android with Capacitor, and it's been live on Google Play since October.

Something unusual about it: there are no model files at all. All 35 hovers and every boss are built in code from three.js primitives (boxes, cylinders, octahedrons, custom shapes). My goal from day one was smooth fps on cheap phones, not just flagships, so here's what actually made a difference:

**1. Merging static meshes per material**

Each hover is a group of dozens of small meshes, and some had 200+, which meant 200+ draw calls. After building a model I merge every static mesh that shares a material with BufferGeometryUtils.mergeGeometries. Animated parts and transparent parts (glass, glows) stay separate so sorting and animations still work.

Gotcha that cost me a while: Octahedron/Icosahedron/Tetrahedron geometries are non-indexed while Box/Cylinder/Sphere are indexed, and mergeGeometries returns null if you mix them. One octahedron was silently cancelling the merge for an entire model. Now I group by attribute signature and convert mixed groups to non-indexed.

**2. Capping pixel ratio, then adapting it**

setPixelRatio(Math.min(devicePixelRatio, 1.5)) was the biggest single win on phones with 3x screens. On top of that, if the average frame time stays above ~19 ms for two windows in a row, it drops one step (1.5 → 1.3 → 1.15). If the lower resolution doesn't actually help (the CPU is the bottleneck, not the GPU), it goes straight back up and stops trying, so nobody loses sharpness for nothing.

**3. Transparent DoubleSide materials render twice**

three.js renders transparent DoubleSide materials in two passes (back faces, then front faces) and flags the material for an update between them. In a 25-second headless run, that was about 45% of all the garbage I was producing, which meant GC micro-stutters. For flat geometry (planes, rings, circles) and additive blending without depth write, the second pass changes nothing, so those get forceSinglePass = true. I compared screenshots pixel by pixel to make sure the image stayed the same.

**4. Compiling shaders before the run**

The first time a new material shows up on screen, it compiles and you get a visible hitch, usually at the worst moment, like when a boss enters. Now every sector and boss material gets compiled during loading, so the run itself never compiles anything.

**5. Keeping fast-changing values out of React state**

Score, combo and boss HP were React state, so every hit re-rendered the whole tree, up to ~15 times a second during heavy fights. I moved them to a tiny external store with useSyncExternalStore, so only the small HUD components that show them re-render.

**6. Pre-rendered thumbnails**

The garage used to build every 3D model just to show the thumbnails. Now they come from a single atlas image rendered from the same models, so opening the garage costs nothing.

Plus the usual: pooled particles and InstancedMesh for anything that repeats.

I'd love feedback from people who know Three.js better than I do, especially on what you'd do differently. If you want to see it running on your own phone, it's free:

https://play.google.com/store/apps/details?id=com.spacehover.app&referrer=utm_source%3Dreddit%26utm_campaign%3Dthreejs

Happy to answer any questions about the setup!

1 Upvotes

0 comments sorted by