<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: pier andrea cavaletto</title>
    <description>The latest articles on DEV Community by pier andrea cavaletto (@pier_andreacavaletto_761).</description>
    <link>https://dev.to/pier_andreacavaletto_761</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4038942%2F78eb8e55-68b3-4660-be0e-93fdf5143174.jpg</url>
      <title>DEV Community: pier andrea cavaletto</title>
      <link>https://dev.to/pier_andreacavaletto_761</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pier_andreacavaletto_761"/>
    <language>en</language>
    <item>
      <title>BRAIN STORM</title>
      <dc:creator>pier andrea cavaletto</dc:creator>
      <pubDate>Tue, 21 Jul 2026 00:17:29 +0000</pubDate>
      <link>https://dev.to/pier_andreacavaletto_761/brain-storm-49j9</link>
      <guid>https://dev.to/pier_andreacavaletto_761/brain-storm-49j9</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3oodfjhs4mmp2s0mdkkh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3oodfjhs4mmp2s0mdkkh.png" alt=" " width="800" height="694"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TL;DR — I spent the last months building &lt;strong&gt;BRAIN STORM&lt;/strong&gt;, an interactive 3D atlas of the human brain that lets you continuously drill down from the whole cortex to a single water molecule and a Bohr-model atom with quantum orbitals — all in a browser tab, at 60 fps. Real MRI data (MNI152), procedural rendering for everything below the cellular scale, and open source (MIT).&lt;/p&gt;

&lt;p&gt;💻 &lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/PierAndreaCavaletto/Brain-Storm" rel="noopener noreferrer"&gt;https://github.com/PierAndreaCavaletto/Brain-Storm&lt;/a&gt;&lt;br&gt;
DEMO: &lt;a href="https://x.com/Pierandreadev" rel="noopener noreferrer"&gt;https://x.com/Pierandreadev&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Why
&lt;/h2&gt;
&lt;/blockquote&gt;

&lt;p&gt;Most brain visualisations you find online are either static PNGs from a paper or expensive desktop software you have to install. I wanted something a curious high-schooler and a working neuroscientist could both open in one click — and once inside, actually &lt;em&gt;travel&lt;/em&gt; between scales, not just look at a picture.&lt;/p&gt;

&lt;p&gt;So the goal became: &lt;strong&gt;one continuous camera path from the whole cortex (~150 mm) to a single hydrogen orbital (~1 Å)&lt;/strong&gt; — that's ~9 orders of magnitude of zoom, seamless.&lt;/p&gt;

&lt;h2&gt;
  
  
  The scale journey
&lt;/h2&gt;

&lt;p&gt;Every layer is anatomically real, not decorative:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;What you see&lt;/th&gt;
&lt;th&gt;Where it comes from&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;L1 · Macrocosm&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Full brain mesh + Yeo-7 network ROI hubs + connectome&lt;/td&gt;
&lt;td&gt;MNI152 T1w, marching-cubes to &lt;code&gt;.glb&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;L1 · Dura Mater&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Falx cerebri, tentorium, superior sagittal sinus, middle meningeal artery, fibroblast field, capillaries, sensory nerves&lt;/td&gt;
&lt;td&gt;Procedural from anatomical reference&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;L2 · Arachnoid&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Trabecular network, CSF flow with cardiac pulsatility, Pacchioni granulations&lt;/td&gt;
&lt;td&gt;Procedural&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;L3 · Pia Mater&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Pial vessels, penetrating capillaries, astrocyte end-feet&lt;/td&gt;
&lt;td&gt;Procedural&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Molecular&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Collagen triple helix (Gly-X-Y knobs, D-banding), water molecule (104.5° H–O–H), hydrated Na⁺/K⁺ octahedral shell&lt;/td&gt;
&lt;td&gt;Procedural&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Atomic&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Bohr model with proton/neutron nucleus, K/L/M electron shells cycling through C/N/O/Ca&lt;/td&gt;
&lt;td&gt;Procedural&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Subatomic&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1s spherical + 2p dumbbell + 3d donut/cloverleaf orbitals sampled from real hydrogen-like wavefunctions&lt;/td&gt;
&lt;td&gt;Rejection sampling in JavaScript&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  The tech stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Next.js 15&lt;/strong&gt; — App Router, single page, no SSR for the canvas&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React Three Fiber&lt;/strong&gt; + &lt;strong&gt;drei&lt;/strong&gt; — declarative Three.js scene graph&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;@react-three/postprocessing&lt;/strong&gt; — Bloom + Vignette for the neon aesthetic&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zustand&lt;/strong&gt; — cross-component state (which layer, which drill-down, camera targets)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tailwind&lt;/strong&gt; — UI chrome&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;troika-three-text&lt;/strong&gt; (via drei) — SDF 3D labels that always face camera&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything runs client-side. Total bundle ~2 MB gzipped + ~20 MB of mesh assets.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bit I'm most proud of: sampling quantum orbitals
&lt;/h2&gt;

&lt;p&gt;At the deepest zoom you can pick "Un elettrone in orbita" and see actual &lt;strong&gt;hydrogen-like probability clouds&lt;/strong&gt;, not stylised planetary orbits. Each orbital shape (1s, 2px, 2py, 2pz, 3d_z², 3d_xy) comes from rejection sampling on the wavefunction's angular part:&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
typescript
function sample3d_z2(rng: () =&amp;gt; number, a0: number): [number, number, number] {
  // Radial: gamma(shape=5, scale=a₀/3) → r⁴ exp(−2r/3a₀)
  const r = -(a0 / 3) * (
    Math.log(Math.max(1e-8, rng())) +
    Math.log(Math.max(1e-8, rng())) +
    Math.log(Math.max(1e-8, rng())) +
    Math.log(Math.max(1e-8, rng())) +
    Math.log(Math.max(1e-8, rng()))
  );
  // Angular: (3cos²θ − 1)² — the donut shape
  for (let tries = 0; tries &amp;lt; 40; tries++) {
    const theta = Math.acos(2 * rng() - 1);
    const phi = 2 * Math.PI * rng();
    const ct = Math.cos(theta);
    const factor = (3 * ct * ct - 1);
    const density = factor * factor / 4;
    if (rng() &amp;lt; density) {
      return [
        r * Math.sin(theta) * Math.cos(phi),
        r * Math.sin(theta) * Math.sin(phi),
        r * ct,
      ];
    }
  }
  return [0, 0, r];
}
I sample ~2700 points per site, colour them per orbital type, and render as THREE.Points with a radial-gradient sprite for the additive glow. What you see isn't "art"; it's the real |ψ|² of a hydrogen electron.

The performance journey (from 4 fps to 60 fps)
The naïve implementation had every layer always mounted. When you clicked "L2 · Aracnoide" the previous layer's 1250+ tube meshes were still being drawn in the depth buffer. FPS floor was ~4.

Three fixes that mattered most:

Conditionally mount — heavy layer components (DuraMicroscopy, ArachnoidView, PiaView) unmount entirely when you're not focused on them. Sounds obvious, was not.
InstancedMesh everywhere — 1560 individual meningothelial-cell meshes became one InstancedMesh. Same for 40 mast cells, 26 000 fibroblasts, 31 000 atoms. Cost went from ~1600 draw calls to ~10.
Split visibility per entity — a single microT opacity meant "hide fibroblasts" also hid capillaries. Splitting into fibT/vesselT/nerveT lets each drill-down mute the crowd without hiding the subject.
Ended up at 40-60 fps on a mid-range GPU with the full scene loaded.

Bug I only found while recording the demo reel
While filming the video I noticed one shell label rendered "undefinede-" in the Bohr view. Traced to a useMemo in SingleAtomView that copied r, label, color from each shell but dropped the electrons field — the JSX below then read s.electrons and got undefined. Two-line fix, but a great reminder that TypeScript's compile-time checks stop at object shape — they can't stop you from forgetting to copy a field. The nasty ones are always the field-drop bugs.

What's next
The project is v0.3-alpha and I'm still shipping. Roadmap:

L3 Pia hero drill-downs (single artery, vein, capillary, astrocyte)
L4 Glia limitans (aquaporin-4, glymphatic clearance)
L5 Cerebral cortex (6 laminae, pyramidal + GABAergic neurons)
L6 Synapse (vesicle exocytosis, neurotransmitter binding)
Try it
If you're a neuroscientist, dev, teacher, or just curious: try it, break it, tell me what's wrong.

💻 GitHub: https://github.com/PierAndreaCavaletto/Brain-Storm
🎥 60-second reel: https://x.com/Pierandreadev
Feedback and scientific corrections are the fuel. Especially interested if you're a neuroanatomy prof and something's wrong — open an issue and I'll fix it.

Built with Next.js, React Three Fiber, MNI152, and too much coffee. MIT licensed. If you enjoyed this article, a ⭐ on the repo helps a lot.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
