Repository navigation
IS-R1: WebGL2 brain mesh and contact renderer - #547
Merged
neuromechanist merged 11 commits intoNov 18, 2026
Merged
Conversation
Deploying nemar-website with
|
| Latest commit: |
be9b1f3
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://05b3a154.nemar-website.pages.dev |
| Branch Preview URL: | https://feat-is-r1-renderer.nemar-website.pages.dev |
neuromechanist
merged commit Nov 18, 2026
055e1c7
into
feature/issue-537-epic-spatial
5 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Card IS-R1 of the iEEG spatial view plan (the intracranial track of epic #537).
What changed
Three new modules under
src/lib/ieeg-spatial/, each with its tests. Nothing imports them yet; the panel that mounts the renderer is card IS-V1.camera.ts: turntable orbit camera in right-anterior-superior (RAS) millimeters with +z up; six view presets (left,right,front,back,top,bottom); view and projection matrices;projectandscreenRay; fit, orbit and zoom with bounds;rescaleForAspect, which keeps a fit valid when the canvas changes shape.mesh-format.ts: thebrain-mesh v1reader, a matching encoder for tests and tools,vertexNormals, andicosphere. The reader refuses any file whose bytes it cannot account for.brain-gl.ts:createBrainRenderer(canvas, themeColors), returningnullwhen WebGL2 or shader compilation is missing. Methods:setMesh,setContacts,setColors,setSelected,setView,pick,render,resize,snapshot,dispose, plussetTheme. Translucent Lambert plus rim mesh (alpha 0.25, depth writes off, drawn after the opaque contacts), one instanced icosphere for up to 2,000 contacts (radiussqrt(size / pi)clamped to 0.5 to 3 mm, 1.5 mm whensizeis n/a), a selection ring drawn on top, CPU ray picking (never a second render pass), drawing on demand only (no loop when idle), context loss and restore rebuilt from the last inputs, device pixel ratio capped at 2.Additions beyond the card's method list (accepted in review round 1):
setTheme(colors)withBrainTheme=background,outline,mesh,contact;setMesh(mesh, alpha = 0.25); a pick floor of 4 CSS pixels; swallowing the click that ends a drag;sizemissing, null, NaN, zero or negative counts as n/a (1.5 mm); more than 2,000 contacts throwsRangeError.Review round 1 (this push)
resize()now rescalesdistance,minDistanceandmaxDistanceby the ratio of the fit's half-angle sines whenmin(1, aspect)changed since the last fit (a 0 x 0 canvas counts as aspect 1), so a brain loaded into a hidden or landscape canvas still fits when the canvas turns portrait, and the user's zoom is kept. Measured in headless Chromium: before, the brain filled the whole 300 px width (x 2 to 297); after, x 74 to 225.pick(x, y, minPx = MIN_PICK_PX)takes a larger floor for coarse pointers;MIN_PICK_PXis exported for that.packContactsandBrainContactdocument that the caller filters contacts without a position (IS-C1'sContact.positionisVec3 | null) and keeps its own index map; a null or non-finite position throwsRangeError, tested.travelledis nowtraveled; docblocks say that afterdispose()or a failedcreateBrainRendererthe canvas holds a deliberately lost context, so each renderer needs a fresh canvas element.Notes for IS-T1 and IS-V1
brain-mesh v1header, little-endian, as implemented and pinned by a hand-built known-answer test: bytes 0 to 3 magicNMBM; byte 4u16version (1); byte 6u16index width in bits (16 or 32); byte 8u32vertex count; byte 12u32index count; byte 16f32scale x, y, z; byte 28f32offset x, y, z; byte 40i16positions (x, y, z per vertex, position = q * scale + offset, q within -32767 to 32767), then the indices. No padding, no normals.setMeshtakes one mesh, so IS-V1 merges them (concatenate positions, offset the second index list) before the call.Gates (head be9b1f3, the epic tip 366e4d4 merged in)
bun install --frozen-lockfile:Checked 416 installs across 568 packages (no changes)bun run typecheck:0 errors, 0 warnings, 19 hints(494 files)bun run lint:Checked 427 files in 200ms. No fixes applied.bun run test src/lib/ieeg-spatial:Test Files 4 passed (4), Tests 85 passed (85)(the 64 of this card plus 21 of IS-M1'sactivity.test.ts)bun run test:Test Files 179 passed | 3 skipped (182), Tests 5050 passed | 14 skipped (5064)astro buildof the epic tip (517bfee) and of this branch with a temporary importer ofcreateBrainRendereranddecodeBrainMeshinviewer.ts(not committed). The lazy chunkviewer.*.jsgoes from 161,956 to 179,085 bytes raw and from 56,848 to 62,747 bytes withgzip -9c <chunk> | wc -c, a gain of 5,899 bytes gzipped against the 14 KB budget. The threegenerate:*Open Graph image steps ofbun run buildwere skipped (they render thousands of cards from the live catalog and do not touch JavaScript chunks).Mutation checks
Each test was shown to fail under a one-line mutation, reverted afterwards (
git status --porcelainempty after each). The card's three: swapping theleftandrightpreset vectors fails 5 tests; returning the first exact hit instead of the nearest fails 2; dropping the offset in the decoder fails 5. Round 1 adds 13 more, one or more per new test: floor hit beating an exact hit, first floor hit instead of the closest,minPxignored, translucent order ascending, opaque or hidden contacts in the translucent list, translucent depth sign flipped, null position not refused, rescale not moving the distance, inverted ratio, bounds left unscaled, aspect clamp dropped. Round 2 strengthened the closest-floor-hit test to run in both array orders, so neither "first floor hit wins" nor "last wins" (the comparison replaced bytrue) passes. In all, 63 of 64 mutations are caught. The survivor is equivalent: removing the flat-axis guard in the encoder still writes 0, becauseDataView.setInt16(NaN)stores 0.Real-browser evidence (scratch, not committed)
Not the IS-QA1 harness. A headless Chromium run on software GL against a bundle of these modules, outside the repository:
setSelecteddraws exactly 1 frame.dispose(), buffers, vertex arrays, programs and shaders created equal those deleted.loseContext()thenrestoreContext()gives a pixel-identical frame with no console warnings;snapshot()while lost throws.createBrainRendererreturnsnull.Not run, would check
gh pr checks.Card IS-R1. Part of #537.