npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

trid3d

v0.8.0

Published

A small 3D library for the HTML canvas: wireframes, filled and smooth faces, textures and shader effects, drawn with Canvas 2D or WebGL. No dependencies.

Readme


Trid gives you a scene, shapes you can model in code, lights, effects, model loading and mouse/keyboard tools, all in plain ES modules you can drop next to your page. See the docs for live demos.

Status: early (0.x): the API can still change between minor versions. See Upgrading.

Features

  • Scene — holds a canvas, a camera, lights and your objects, and runs the frame loop for you. The background can be a color or see-through ("transparent"), so a model can float over your page.
  • Groups — give any object children and they move, turn and scale with it (models made of parts, a moon orbiting a planet).
  • Shapes — cubes, boxes (sharp or rounded), spheres, cylinders, cones, tori and planes built in, lathe for round shapes (a point on the axis closes it to a tip) and extrude for flat ones, or any mesh you define as vertices, faces and edges.
  • Modeling — smooth curves through a few points (spline), shapes swept along a 3D path (sweep: tails, horns, pipes, rails), surfaces through cross-sections (loft: bodies, bottles, hulls, heads), subdivision surfaces with creases (subdivideMesh: box modeling), shapes that melt together (blobMesh: creatures, clay; or any distance field with sdfMesh), rounded or cut edges on any mesh (bevelMesh), mirror, symmetrize and array like Blender's modifiers (mirrorMesh, symmetrizeMesh, arrayMesh, radialArrayMesh, or copies of objects that share their mesh), booleans like Blender's (unionMesh, subtractMesh, intersectMesh: holes, windows, one solid from parts), taper, twist, bend and bulge deformers, sculpting brushes (sculptMesh: inflate, grab, smooth, flatten, pinch, crease, noise; around a point or along a stroke, with X mirror), voxel remeshing (remeshMesh: any shape, or overlapping parts, as one even, sculptable surface), lattice deform (makeLattice, latticeMesh: a cage of points that reshapes a mesh smoothly), a modifier stack (applyModifiers: modeling steps applied in order, kept as data), mesh cleanup and checks (weld, clean, validate, fix winding), rays, inside tests and distances against meshes and scenes (meshQuery, raycastScene), and placing objects against each other: dropped until they touch, attached to a surface facing out, aligned and spaced out (dropOnto, attachTo, alignObjects, distributeObjects).
  • Mesh helpers — clone, transform, displace, merge and measure meshes; seeded random numbers and smooth noise (fbm2, fbm3, tileable) for rocks, terrain and procedural textures.
  • Filled faces — give an object a material to fill and shade its faces, flat or smooth.
  • Lights and shadows — ambient, directional and point lights, with colors and intensities, as many as you need (up to 8 at once besides ambient). Directional and point lights can cast soft shadows (shadow maps with WebGL, ground shadows on the canvas).
  • Textures — images, canvases or videos on faces, with texture coordinates from built-in shapes and OBJ files, or made from the shape (planar, box, sphere and cylinder mapping). Repeat, offset and rotate them, or give each face its own material. Or paint one in code: wood, marble, bricks and more, all seamless.
  • Effects — stack shader effects like toon, rim and edge glow, gradients and fog on a material, or write your own in GLSL.
  • Post effects — bloom, vignette, color grading, film grain and cartoon outlines over the whole picture, or your own full-screen shaders (several passes if needed, reading the scene's depth and normals if wanted).
  • Two renderers — the canvas 2D context by default, or WebGLRenderer for exact depth and big models, with the same scene code.
  • OBJ files — load models from a URL (with their .mtl colors and textures), or let users drop their own .obj files on the canvas.
  • Export — scene.screenshot() and scene.record() save images and videos of the canvas; exportOBJ / exportModel write meshes, objects or whole scenes as OBJ files with their MTL materials and textures.
  • Camera — position, yaw, pitch and field of view (50° by default), with near-plane clipping.
  • Tools — orbit and fly cameras, object dragging, hover highlight, a selection outline, a sculpting tool (paint the brushes with the mouse), a move / rotate / scale gizmo (with a pivot of your choice), a view axes gizmo, a floor grid, an FPS meter and an OBJ uploader, one line each. Exact picking by triangles, with the hit point and texture coordinates under the mouse. Writing your own is a plain object with a few methods.
  • Pure math — every transform and projection step is exported, plus 4×4 matrices and rotations, so you can use the pipeline piece by piece.

Install

npm install trid3d

No bundler? Use the CDN with an import map, or copy the trid/ folder next to your page and import ./trid/index.js:

<script type="importmap">
  { "imports": { "trid3d": "https://cdn.jsdelivr.net/npm/[email protected]/trid/index.js" } }
</script>

Quick start

<canvas id="canvas"></canvas>
<script type="module" src="main.js"></script>
// main.js
import { Scene, makeShape, OrbitCamera } from "trid3d";

const scene = new Scene(document.getElementById("canvas"), {
  width: 800, height: 400,
  camera: { z: -1.5 }, // a step back
});

// A cube with rounded edges, filled and smoothly shaded
const cube = scene.add({
  mesh: makeShape("cube", { radius: 0.08 }),
  material: { fill: "#E9806E", smooth: true },
});

scene.use(new OrbitCamera()); // drag to orbit, scroll to zoom
scene.start((dt) => {
  cube.rot.x += dt * 0.5;
  cube.rot.y += dt * 0.35;
});

Without a bundler, serve the folder (python3 -m http.server) instead of opening the file directly: browsers block module imports from file:// pages.

Loading a model

import { loadOBJ } from "trid3d";

const mesh = await loadOBJ("models/teapot.obj", { fit: 1, materials: true }); // centered, 1 unit wide
scene.add({ mesh, material: mesh.materials }); // colors and textures from its .mtl file

Or let users load their own: scene.use(new ObjUploader()) accepts dropped .obj files, and uploader.open() shows a file dialog.

Project layout

| Folder | Content | | --- | --- | | trid/index.js | Entry file: exports everything ("trid3d") | | trid/scene.js | The Scene class | | trid/sceneGraph.js | Groups: children, world matrices | | trid/math/ | Transforms, camera directions, projection, matrices, rotations, random numbers and noise | | trid/render/ | Renderers (Canvas 2D, WebGL), lights, effects, post effects, shapes, grids, mesh helpers, procedural textures, drawing, frame loop | | trid/modeling/ | Modeling tools: curves, sweep, loft, subdivision, blobs, bevel, mirror and array, deformers, sculpting, lattice, modifier stack, cleanup, queries (rays, inside, distance), placement | | trid/loaders/ | OBJ, MTL and texture loading | | trid/export/ | Screenshots, video recording, OBJ and MTL export | | trid/tools/ | Camera, object, gizmo and overlay tools | | docs/ | Documentation site with live demos | | test/ | Tests (npm test) |

Documentation

zachr622.github.io/Trid: every class, option and function, with live demos.

To run the docs locally (Node 18+):

npm install
npm run docs:dev

See docs/README.md for building and editing the docs.

Tests

npm test

Uses Node's built-in test runner (Node 21+), so there's nothing to install. The tests cover the whole transform pipeline (rotations, camera, projection, near-plane clipping, matrices and normals), what the canvas renderer draws (order, culling, clipping, light, gradients, outlines, split faces, texture placement), shapes (lathe poles included), mesh helpers, curves, sweeps, lofts, subdivision, blobs, bevels, booleans, mirrors and arrays, deformers, sculpting brushes, remeshing, lattices, modifier stacks, mesh cleanup, mesh and scene queries, placing objects (exact contact, lifted out, attached, aligned, spaced), smooth normals, texture mapping, material and post effects, noise, procedural textures, OBJ / MTL loading and export, screenshots and downloads, picking, tools, groups, lights, shadows, grids, see-through backgrounds, and the WebGL renderer's GPU memory on a fake WebGL context.

Upgrading

From 0.7 to 0.8

Everything new comes beside what was there: booleans, mirror and array, placing objects, sculpting brushes and SculptTool, remeshing, lattices, the modifier stack, screenRay, and shadows from point lights. Two things can look different in scenes that already had them:

  • More lights cast shadows. A point light with shadows now casts them, and so does a second directional light with shadows: up to 2 directional and 2 point lights at once (MAX_SHADOWS). In 0.7, only the first directional light with shadows cast any, and shadows on the others did nothing. To keep a light as it looked, set its shadows: false.
  • In material effect GLSL, the functions tridShadowCube and tridUnpack are taken too. Only helper functions of your own with those names would clash.

From 0.6 to 0.7

Nothing changes for existing scenes: shadows, outlines and the selection outline are all off until asked for. Only names Trid now uses itself could clash with yours:

  • In post effect GLSL, Frame has two more fields (f.near, f.far), and the uniforms uNear, uFar, uGeometry, uGeoNear and uGeoRange are taken. A post effect declaring its own uniform with one of those names needs to rename it.
  • In material effect GLSL, the functions tridShadow and tridShadowDepth and the uniforms starting with uShadow (plus uReceive) are taken. Effect uniforms are renamed by Trid, so only helper functions with those names would clash.

From 0.5 to 0.6

  • The cone's tip is a single point (a pole), so the cone is closed: isClosed and validateMesh no longer report a hole there. It has fewer vertices than before (its tip ring of 32 is now 1), and its side faces are triangles. Any lathe profile point with r: 0 works the same way.
  • The default field of view is 50° (DEFAULT_FOV), instead of 90°. Scenes whose camera has no fov look about twice as close, like in most 3D tools. To keep the old view, give the camera fov: Math.PI / 2.
  • background: null is see-through, like "transparent" (it used to come out black). clear() now empties the canvas before painting the background, so see-through and half see-through backgrounds work; opaque ones look the same.

From 0.3 to 0.4

  • Lights are a list: scene.lights. A scene still starts with one directional light and an ambient level, and looks the same. scene.light and scene.ambient are now shortcuts for the first directional light's direction and the first ambient light's intensity.
  • Setting scene.ambient after the scene is made no longer dims the directional light (it used to be 1 - ambient all the time; now that's only how the default lights start). To keep the old look, also set scene.lights[1].intensity = 1 - ambient.
  • scene.light is null for a scene whose lights have no directional light.
  • Effects get s.lightColor, and toon and gradient are tinted by colored lights (no change with white lights).

From 0.2 to 0.3

  • Canvas textures are read once. A canvas used as a texture is now uploaded once (faster, and sharper with mipmaps). If you draw on it again, call updateTexture(canvas) after drawing, or give its material liveTexture: true to read it every frame. Videos still play on their own. See Changing a canvas.
  • The WebGL renderer frees unused GPU memory: meshes and textures not drawn for 300 frames are freed (and sent again if they come back). Set new WebGLRenderer({ releaseAfter: Infinity }) to keep the old behavior.
  • Objects can have children, and mesh is optional for a group. Code that walks scene.objects only sees the top level; use worldObjects(scene) to include children.
  • parseOBJ now sets materialNames / faceMaterials for a file with a single material too.

Roadmap

Roughly in order:

  • More transform options — local or world axes on the transform gizmo, snapping (grid and angle steps), finer drags, setting an object's origin (center, bottom)
  • More import and export formats — STL; basic glTF later
  • More post effects — antialiasing (FXAA)