Back in 2013 I made phoria.js - as a learning exercise, a little 3D engine on HTML5 canvas 2D - great fun, but useless today!
So, I’ve rebuilt it from the ground up as phoria2: an open-source WebGL 2 library aimed at mostly "business" use-cases rather than games or huge shader demos – so perfect for 3D charts, labelled diagrams, dashboards, product viewers and quick demos.
See the demos - nearly 60 of them, some even fun and useful!
Same idea as the original phoria.js - simple API, easy to use but this time on WebGL 2, with proper lighting, shadows, glass and model support and aimed at the 3D that everyday apps want, or at least what I think they want, we'll see I guess.
Friendly to coding agents too
The whole API is in one page at llms-full.txt and it ships in the npm package. If you use Claude Code, there's a plugin that gives it the reference and a check that loads your page in the browser and reports any issue:
/plugin marketplace add kevinroast/phoria2 /plugin install phoria2@phoria2 It was built from scratch for both humans and agents to find easy!
A working interactive scene in a few lines
Paste this into an HTML file and open it. No build step, nothing to install:
<canvas id="c" style="width: 100%; height: 100vh; display: block"></canvas> <script type="module"> import { View, Mesh, box, DirectionalLight } from 'https://cdn.jsdelivr.net/npm/phoria2/+esm' const view = new View({ canvas: '#c', orbit: true, background: '#1c1c20' }) const cube = view.scene.add(new Mesh({ geometry: box(2), material: { color: 'orange' } })) view.scene.add(new DirectionalLight({ direction: [-1, -2, -1] })) view.start((dt) => cube.rotateY(0.6 * dt)) </script> Drag to turn it, right-drag to pan, scroll to zoom. The canvas takes its size from CSS and the camera starts fitted to whatever's in the scene, so there's nothing else to set up.
A 3D chart from a spec
This is the area I wanted to make a niche. Give chart() some rows and say which field goes where (this one's npm install phoria2 with a bundler - the README has an import map if you'd rather stay on the CDN):
import { View } from 'phoria2' import { chart } from 'phoria2/charts' const rows = [ { month: 'Jan', region: 'North', sales: 41 }, { month: 'Jan', region: 'South', sales: 26 }, { month: 'Feb', region: 'North', sales: 38 }, { month: 'Feb', region: 'South', sales: 31 }, { month: 'Mar', region: 'North', sales: 52 }, { month: 'Mar', region: 'South', sales: 35 }, ] const view = new View({ canvas: '#c', orbit: true }) view.scene.add(chart({ mark: 'bar', data: rows, x: 'month', z: 'region', y: 'sales', color: 'region', tooltip: true, })) You get axes, a legend, tooltips and hover highlights, and chart.update(newRows) animates to the new data. There are bar, point, line, area, surface, curve, vector and network marks. It plots functions too - surfaces, parametric shapes, polar curves - with parameters that tween as you change them. The maths demo and science demo are great.
Why is it different to other 3D libs?
It tells you what to write. Every option is checked, and a mistake throws an error that names the fix:
new Mesh({ geometry: box(1), material: { colour: 'red' } }) // Material: use 'color' new DirectionalLight({ castShadows: true }) // DirectionalLight: unknown option 'castShadows' - did you mean 'castShadow'? Interaction is built in. Tooltips, hover highlights, click and drag handlers and HTML labels that hide when they overlap or go behind something - each one an option or a line of code. A chart of 10,000 bars is one mesh with one click handler and each click returns you that bar row of data.
It sits still when nothing changes. A view only draws when something in it changed! So a dashboard of many views costs nothing while you're reading it. Browsers allow about 16 WebGL contexts per page, so phoria2 shares one between the views beyond the first four - each one still just a canvas in your layout. The chart lab runs over 100 of them.
It's small. About 90 KB gzipped for an interactive scene with lights. Charts, particles, glTF, motion and editing are separate imports and the heavier parts - shadows, HDR environments, glass, bloom - only load when a scene uses them. No runtime dependencies, ES modules, TypeScript types.
Model support. loadGLTF() reads glTF - Draco and meshopt geometry, KTX2, WebP and AVIF textures, instancing, material variants and animations. Try the glTF viewer. Good models kind of flatter the library.
It can look lovely when you want it to. Glass that bends what's behind it, with caustics and coloured shadows; clearcoat, cloth sheen and iridescence; softbox lights with proper soft shadow; HDR environments and bloom. Set refine: true and while nothing moves the picture keeps getting automatically refined for N samples. Have a look at the whisky tumbler or the glass demo.
Accessible. keyboard: true lets users step through bars, points and parts with the arrow keys while a screen reader says what each one is and motion follows the system reduced-motion setting.
Or no JavaScript at all
Load the element once and <phoria-view> shows a model, a chart or a scene. Its attributes are the same options as the View:
<script type="module" src="https://cdn.jsdelivr.net/npm/phoria2/dist/element.js"></script> <phoria-view src="your-model.glb" environment="studio" orbit auto-rotate ground-shadow></phoria-view> <phoria-view orbit> <script type="application/json"> { "type": "chart", "mark": "bar", "data": [{ "m": "Jan", "v": 3 }, { "m": "Feb", "v": 5 }], "x": "m", "y": "v" } </script> </phoria-view> Plays well with others
phoria2 renders - and any library built for the appropriate job take on the rest. Physics engines hand back positions and rotations that instances take as they are:
// each frame: Rapier moves the bricks, phoria2 draws them - one mesh, one draw call world.step() bodies.forEach((body, i) => bricks.setInstance(i, { position: body.translation(), quaternion: body.rotation() })) The gallery has a brick tower to knock down with Rapier, a tablecloth using Rapier's soft bodies, a metal block cut with Manifold, and little meeples finding their way round an office with recast-navigation. Rebuild The Sims! How hard can it be right?
Have a play
npm install phoria2 - Demo gallery - charts, diagrams, showcase scenes and integrations, each with source
- Getting started tutorial - a first scene, then a live dashboard of 3D charts, each step with CodePen links
- GitHub - MIT licensed
A few demos to start with:
- glTF viewer - compressed models, glass, HDR, shadows and animation
- Dashboard - eight chart tiles, each its own view, idle until touched
- Periodic table - tap an element for its atom
- Brick tower - fire a ball at it, or drop a bomb
- Fireworks - just because
It runs in any browser with WebGL2 - phones included. It's at 1.11 and follows semver, so nothing in 1.x gets removed or renamed without a deprecation warning first.
This is my first post here, so hello! If you build something fun with phoria2, or it does something daft, I'd love to hear about it in the comments or on GitHub. I am totally imagining the first comments are mostly "but threejs bruh" and yeah I'm not mad enough to go after that which is why I tried to make it "agent friendly" from day one, not target games or massive custom shaders and try to hit a few interesting niches, but regardless, I'm having a blast making it!


