Skip to content
noggin

Web toon: three.js 0.186.1 for style B in the browser (2026-11-01, #194)

Question: what the page needs from three.js to draw style B (docs/model-notes.md) from Blender’s GLB: the pin and its integrity hashes, a two-step toon shadow with one highlight band, silhouette outlines and crease lines at the pictures’ 2.5 px, the look numbers carried in glTF extras, and the gestures through AnimationMixer. Rule: newest release at least two weeks old.

Sources: the three.js files at https://cdn.jsdelivr.net/npm/three@0.186.1/ (B/ below), the npm registry, MDN’s browser-compat-data (html/elements/script.json) and Blender 5.2’s bundled io_scene_gltf2, all read 2026-11-01.

  • npm view three time: 0.186.1 published 2026-09-24 (38 days old); 0.187.0 is 2026-10-30, under the two-week rule.
  • B/build/three.module.js imports ./three.core.js, so both need a hash. The addons import the bare three and their siblings: examples/jsm/loaders/GLTFLoader.js imports ../utils/BufferGeometryUtils.js and ../utils/SkeletonUtils.js; lines/LineSegments2.js imports ./LineSegmentsGeometry.js and ./LineMaterial.js; controls/OrbitControls.js and loaders/DRACOLoader.js only three. Ten files in all, each hashed with openssl dgst -sha384 -binary <file> | base64 (the values are in web/index.html’s import map).
  • Import maps carry integrity per URL: Chrome 127, Firefox 138, Safari 18 (MDN BCD html.elements.script.type.importmap.integrity); every module the page imports, directly or through an addon, is checked against it. Older browsers ignore the key and load unchecked.
  • DRACOLoader fetches its decoder (draco_wasm_wrapper.js, draco_decoder.wasm) with FileLoader from setDecoderPath (B/examples/jsm/loaders/DRACOLoader.js#_loadLibrary), so no integrity check reaches it; the wasm path needs only those two (draco_decoder.js is the no-WebAssembly fallback). sha256 of 0.186.1’s libs/draco/gltf/ copies: wrapper 8bb2952d...d76f6, wasm a680d927...df8ac (shasum -a 256; full values in web/build.py).

Toon shading: MeshToonMaterial and its gradientMap

Section titled “Toon shading: MeshToonMaterial and its gradientMap”
  • gradientmap_pars_fragment: coord = dot(normal, lightDir) * 0.5 + 0.5; with a gradient map the irradiance is texture2D(gradientMap, coord).r (without one, a built-in 0.7/1.0 step at coord 0.7). A DataTexture with NearestFilter gives hard steps.
  • lights_toon_pars_fragment: RE_Direct_Toon adds gradient * light.color * diffuse / PI, so a single DirectionalLight of intensity PI and no ambient light yield colour * gradient exactly: Blender’s toon pass (base colour times a constant ramp) in the browser.
  • What the pictures actually show (a probe: model/render/blender.py’s setup() and material() on a smooth UV sphere, orthographic, the key light placed as the pictures place it, pixels read back against N.L and N.H): the final colour over the part colour, linear, is 0.40 where N.L <= 0 and rises smoothly to 0.76 at N.L 0.95, i.e. TOON * SHADOW + (1 - TOON) * (SUN / PI) * N.L within 1% (0.396 + 0.378 N.L). The toon ramp never reaches its lit step: the 0.8 grey Diffuse BSDF under sun 2.6 peaks at 0.8 * 2.6 / PI = 0.66, under SHADOW_AT 0.7; and the world (strength 0.4) adds under 1% in the background render. The highlight band sets in between N.H 0.978 and 0.984. So the page’s gradient map is that curve, sampled from Blender’s numbers at export time, not a two-texel step.
  • No specular term: a highlight band needs a few lines through onBeforeCompile before #include <opaque_fragment>, where outgoingLight, normal, geometryViewDir (lights_fragment_begin) and directionalLights[0] are in scope.
  • examples/jsm/effects/OutlineEffect.js calculateOutline offsets each vertex by normalize(pos - projectionMatrix * modelViewMatrix * (position + normal)), i.e. it adds a unit normal in the object’s own units. Our GLBs are in metres and the Mech is 0.1 m, so that point lands a metre away, behind the camera for close views; the effect assumes scenes in larger units. An inverted hull of our own (back faces, black, pushed out along the view-space normal by a pixel width in clip space) is a few shader lines.
  • The parts carry split normals at sharp edges (weighted normals, sharp from 35 degrees): a hull pushed along them opens at every hard corner. BufferGeometryUtils.mergeVertices (tolerance 1e-4) on positions only, then computeVertexNormals, gives the hull smooth normals.
  • EdgesGeometry(geometry, thresholdAngle): an edge is kept when the angle between its faces’ normals exceeds thresholdAngle degrees (default 1); vertices are matched on positions rounded to 4 decimals (0.1 mm in metres), so split-normal seams join. 60 is Freestyle’s crease rule (crease_angle 120 degrees between the faces).
  • LineBasicMaterial.linewidth is 1 px on WebGL; lines/LineSegments2 with LineMaterial draws widths in pixels (linewidth, needs resolution). LineSegmentsGeometry.fromEdgesGeometry takes the crease edges.
  • Blender exporter (io_scene_gltf2/blender/exp/gather.py __gather_extras): with export_extras=True the scene’s custom properties become the glTF scene’s extras (also objects’, materials’ and meshes’).
  • GLTFLoader assignExtrasToUserData copies extras into userData for scenes, nodes, meshes, materials and animations, so the scene’s look is gltf.scene.userData. A material’s baseColorFactor arrives as material.color (linear), the part colour Blender already exports.
  • AnimationMixer: clipAction(clip), setLoop(LoopOnce), clampWhenFinished, and the mixer dispatches finished with {action} when a finite action ends (three.core.js AnimationAction._updateTime).

Measured against wink.gif (2026-11-01, #211)

Section titled “Measured against wink.gif (2026-11-01, #211)”

The page and a fresh Blender frame at wink.gif frame 0’s camera (600x450, the page’s camera set to the GIF’s), each part masked by a flat-colour ID render, light = linear pixel / linear part colour; W1 is the Wasserstein distance of a part’s light to the Blender frame’s, pixel-weighted over the lids, eyeballs, base plate, boards and lid linkage.

image W1 on the 0.40 plateau lit (>= 0.5)
wink.gif frame 0 (64 colours) 0.010
Blender, no cast shadows 0.033 21.4% 61.7%
Blender, no world light 0.013
page before #211 0.036 21.3% 59.4%
page with the key light’s shadows 0.023 32.9% 48.4%
Blender frame (the GIF’s source) 0 29.7% 51.4%
  • The form shading per part already matched (upper lids W1 0.01): no toon step fires, as above. The GIF’s second tone is cast shadow (lids on the eyeballs, the eyes and linkage on the base plate), a flat 0.40 like N.L <= 0; the page without shadows measured as Blender without them. The GIF’s 64-colour palette adds little (0.010).
  • What is left: the page’s shadows are harder than Eevee’s 12-degree sun (the eyeballs, W1 0.03; three.js’s PCF radius 1 to 10 moved no part’s mean), and the world light Blender adds (0.013 of the 0.023).
byYellow PineYellow Pine

noggin v0.2.26-6-g09bf9b7 · 09bf9b7