Build a 3D Heart X-ray Viewer

Use Claude Code and three.js to build a linked 3D heart and X-ray viewer.

Introduction

30 Second Summary

A flat picture of the heart can hide the depth behind it. Seeing the shape move beside that picture makes the viewing angle easier to understand.

In this project, you will direct Claude Code to build a one-file teaching page inspired by AngioView, created by Annas Rahman, MD. You'll use three.js to connect a draggable 3D artery scene to a flat schematic projection with shared angle controls.

What You'll Build

Picture opening one file to see red heart arteries turning beside a grey projection that shifts in sync whenever you drag the model or choose a preset.

By the end of this project, you'll have:

  • A draggable 3D artery view where you can spin or zoom around four red artery tubes over a faint heart shape.
  • A linked schematic X-ray view that changes immediately with the RAO/LAO or caudal/cranial sliders.
  • Six animated presets that keep the detector frame, angle label, sliders, and projection synchronized for a capture at RAO 30 / CAU 30.
  • Secret Mission: Replace the faint heart shell with the credited NIH 3D Heart, Male model while keeping the arteries and all six presets working.

Are there any prerequisites?

You need Claude Pro or higher ($20 if billed monthly for a new Claude Pro subscription).

Use an internet-connected Google Chrome or Microsoft Edge browser on macOS 13 or newer or Windows 10 version 1809 or newer.

Before We Start

Before any hands-on work begins, take a moment to lock in the purpose of this project. You are building a beginner-friendly schematic teaching page inspired by AngioView. It is not a medical device and must never be used for patient care or to interpret a real angiogram.

Set Up Claude Code

A verified Claude Code session must run inside heart-viewer before it can create your page.

The version check proves your terminal can find Claude Code. The folder check proves every future file will land in one known place.

In this step, get ready to:
  • Install Claude Code. Its version check succeeds.
  • Create heart-viewer on the Desktop. Claude Code starts from that folder.
  • Sign in to Claude Code. Its reported path ends in heart-viewer.
Install Claude Code

Claude Code runs in a terminal and turns plain-English requests into changes inside your project folder. The native installer adds the command your terminal needs.

macOS

  • Press Cmd+Space to open system search.
  • Type Terminal into the search bar.
  • Press Return to open Terminal.
  • Install Claude Code on macOS by running this command:
curl -fsSL https://claude.ai/install.sh | bash

What does this command do?

This runs Anthropic's native macOS installer for Claude Code.

You should see the installer finish without an error.

Windows

  • Press the Windows key to open system search.
  • Type PowerShell into the search bar.
  • Press Enter to open Windows PowerShell.

The prompt begins with PS. This confirms that you are using Windows PowerShell.

  • Install Claude Code on Windows by running this command:
irm https://claude.ai/install.ps1 | iex

What does this command do?

This runs Anthropic's native Windows installer through Windows PowerShell.

You should see the installer finish without an error. The native Windows installation does not require administrator rights.

Installer not working?

Windows needs PowerShell for this installation. The irm command is available when the prompt begins with PS.

Compare your steps with the official Claude Code setup guide.

Help me troubleshoot the Claude Code native installer on my computer.

Verify Claude Code in a fresh session

A fresh terminal session picks up the newly installed command. This check confirms the installation before you create the project folder.

  • Close the terminal window that ran the installer.
  • Start a new Terminal session on macOS or a new Windows PowerShell session on Windows.

macOS

  • Press Cmd+Space to open system search.
  • Type Terminal into the search bar.
  • Press Return to open a fresh Terminal window.

Windows

  • Press the Windows key to open system search.
  • Type PowerShell into the search bar.
  • Press Enter to open a fresh Windows PowerShell window.
  • Verify the Claude Code installation by running this command:
claude --version

What does this command do?

The claude command starts the command-line tool. The --version flag asks it to print the installed version.

You should see a version number followed by (Claude Code).

✔️ I see a version number

The fresh terminal recognizes Claude Code.

ⓧ Claude Code is not found

  • Close every Terminal or Windows PowerShell window.
  • Start a fresh terminal session for your platform.
  • Repeat the version check above.
  • Repeat your platform's installer if Claude Code is still unavailable.

That is the first setup hurdle cleared. Your terminal can now start Claude Code whenever you need it.

Create the project folder and start Claude Code

The folder where Claude Code starts becomes the workspace it uses for your request. Starting inside heart-viewer keeps the page contained on your Desktop.

The final claude command starts an interactive terminal session. On first use, Claude Code opens a browser tab for authentication.

macOS

  • Create heart-viewer on your Mac Desktop and start Claude Code from it by running these commands:
cd ~/Desktop
mkdir heart-viewer
cd heart-viewer
claude

What do these commands do?

  • The first cd moves the terminal to your Desktop.
  • The mkdir command creates the heart-viewer folder.
  • The second cd enters the new folder.
  • The claude command starts Claude Code from that location.

Windows

  • Create heart-viewer on your Windows Desktop and start Claude Code from it by running these commands:
cd $HOME\Desktop
mkdir heart-viewer
cd heart-viewer
claude

What do these commands do?

  • The first cd moves Windows PowerShell to your Desktop.
  • The mkdir command creates the heart-viewer folder.
  • The second cd enters the new folder.
  • The claude command starts Claude Code from that location.

Claude Code starts in the terminal. The first session opens a browser tab for authentication.

  • Complete the first-use sign-in with your Claude Pro or higher account.
  • Use the browser tab that Claude Code opened.
  • Follow the on-screen authentication prompts.

Claude Code should become ready for a prompt in the terminal.

  • Switch back to the terminal window that is running Claude Code.

Before you ask, what folder name do you expect Claude Code to report?

  • Confirm the active folder by pasting this prompt into Claude Code:
What folder are we in?

What does this prompt do?

The question asks Claude Code to report the folder used by the current session. This confirms where future file changes will happen.

Claude Code should answer with a path ending in heart-viewer.

You have cleared the setup hurdle. Claude Code is now ready to create the viewer inside the correct folder.

Your workspace is ready. Next up, you will describe a small 3D heart artery viewer and watch Claude Code create the first working version.

Build the 3D Heart Arteries

Your Claude Code session is ready inside heart-viewer. Now you can turn a plain-English description into the first working version of your teaching page.

A small visible version proves the one-file setup works before you add the more complex flat projection.

In this step, get ready to:
  • Create index.html with an inline three.js 0.187.0 import map, a faint heart shell, and four red artery tubes.
  • Open the page directly in Google Chrome or Microsoft Edge. See the schematic viewer render.
  • Drag to rotate the arteries. Scroll to zoom the camera.
Describe the first 3D view

A precise plain-English request gives Claude Code the boundary for this first build. It also fixes the coordinate system that every artery curve follows.

  • Switch back to the Terminal or Windows PowerShell window where Claude Code is already running.
  • Create the first version by submitting this exact request to Claude Code:
Create one file, `index.html`, with all the code inside it. Load three.js 0.187.0 with an import map: `three` from `https://cdn.jsdelivr.net/npm/three@0.187.0/build/three.module.js` and `three/addons/` from `https://cdn.jsdelivr.net/npm/three@0.187.0/examples/jsm/`. Draw schematic heart arteries as red tubes made with CatmullRomCurve3 and TubeGeometry: a short left main artery splitting into a left anterior descending artery down the front and a circumflex artery round the left side, and a right coronary artery round the right side. Put them on a faint see-through heart shape. The patient lies on their back: +Y is the head, +X is the patient's left, +Z is the chest. Add OrbitControls so I can drag to spin and scroll to zoom. Add a footer: Educational simulation, not for clinical use.

What does this request do?

  • The one-file boundary keeps the page structure, styling, and 3D code together in index.html.
  • The coordinate system gives every artery point a consistent anatomical direction.
  • THREE.CatmullRomCurve3 bends each set of points into a smooth path. THREE.TubeGeometry turns that path into a visible artery tube.
  • OrbitControls connects mouse or trackpad movement to the 3D camera.

You should see Claude Code propose one new file named index.html. Its generated code and explanation can differ from the reference implementation.

Approve and open the page

Claude Code asks before writing a proposed file. Your approval turns the generated plan into the first project artifact inside heart-viewer.

  • Approve the creation of index.html by selecting Yes.
  • Use the arrow keys to highlight Yes.
  • Press Enter.

You should see a completed file operation for index.html.

That first AI-assisted build is now on disk inside your heart-viewer folder.

The generated page is a standalone HTML file with its 3D modules loaded from the web. Opening that file in the tested browser path reveals whether the renderer and imports work together.

  • Open index.html from the Desktop heart-viewer folder in Chrome or Edge.

macOS

  • In Finder, select Desktop from the sidebar.
  • Double-click the heart-viewer folder.
  • Double-click index.html.

Windows

  • In File Explorer, select Desktop from the sidebar.
  • Double-click the heart-viewer folder.
  • Double-click index.html.
  • Return to index.html in Finder or File Explorer if a different browser opens.
  • Right-click index.html.
  • Select Open With.
  • Select Chrome or Edge.

You should see four schematic red artery tubes over a faint heart shape. The footer reads Educational simulation, not for clinical use..

Seeing a blank page?

A blank canvas usually means the browser could not load a module before rendering the scene.

  • Press Command+Option+J on macOS or Control+Shift+J on Windows to open the browser console.
  • Copy the red error from the console.
  • Paste the error into the Claude Code session from earlier.
  • Ask Claude Code to place the import map before the inline module script if the error contains Failed to resolve module specifier "three".

Get help with the generated page by sharing the error without changing the project requirements.

Test the 3D interaction

The renderer draws the scene while OrbitControls updates the camera. Dragging tests rotation. Scrolling tests camera zoom.

Before you test the controls, do you expect the arteries to move themselves or your viewpoint to move around them?

  • Drag across the 3D view with your mouse or trackpad.

You should see your viewpoint rotate around the faint heart shell and its four red artery tubes.

  • Scroll while the pointer is over the 3D view.

You should see the camera move closer to or farther from the schematic arteries.

  • Confirm the footer displays Educational simulation, not for clinical use..

Your first visible win is complete. The one-file viewer renders a draggable schematic heart artery scene directly in Chrome or Edge.

Your interactive 3D foundation is working. Next, you will turn the same schematic arteries into a linked flat projection.

Add the X-ray View

Your draggable schematic arteries are working. The next goal is a synchronized flat projection.

The current 3D view cannot show the flat detector view that changes with the viewing angles.

In this step, get ready to:
  • Confirm that the current 3D view lacks a flat detector projection.
  • Render a dark 3D view beside a light-grey X-ray view of the same arteries.
  • Control the X-ray projection with signed angle sliders that reach `AP 0 / 0`.
See the one-view limitation

Rotation helps you understand the arteries in space. However, the current page cannot show how a detector flattens those arteries into one view.

Before you check the current page, do you expect rotating the 3D model to reveal the same flat view a detector would capture?

  • Switch back to the browser tab showing index.html.
  • Refresh index.html.
  • Click the browser's Reload button.
  • Drag the left view to inspect the arteries from several angles.
  • Place your pointer over the artery model.
  • Hold the primary mouse button.
  • Move the mouse across the viewer.

You can rotate the arteries in 3D. You still have no flat projection to compare against the spatial view.

Why does this fall short?

A rotating model shows the shape from different positions. A detector projection turns that same geometry into a flat layout.

Seeing both at once makes the viewing angle easier to understand.

Split the viewer into two views

An orthographic projection keeps an object's rendered size constant as its distance changes. One three.js renderer can draw the scene twice by assigning a separate viewport to each camera.

  • Send this exact request to Claude Code:
Split the page into two halves using one renderer with setViewport and setScissor. Left: the 3D view as now. Right: an X-ray view of the same arteries from an OrthographicCamera placed at the detector, looking at the heart. Draw the X-ray view on a light grey background with the arteries in dark grey MeshBasicMaterial using MultiplyBlending, transparent true and depthWrite false, so arteries that cross look darker. Hide the faint heart shape in the X-ray view.

What does this request change?

  • The renderer uses separate viewports to place two camera views inside one canvas.
  • The OrthographicCamera creates the flat projection on the right.
  • MultiplyBlending makes overlapping transparent arteries appear darker.
  • The faint heart stays hidden from the X-ray camera.
  • Approve Claude Code's edit when it asks by selecting Yes.
  • Refresh index.html.
  • Click the browser's Reload button.

You should see a dark 3D view on the left. You should see a light-grey flat artery view on the right.

That first split is working: one canvas now carries two views of the same arteries.

Is the X-ray side empty?

The detector camera may be too close to the heart. Its near and far planes may also exclude part of the schematic.

Ask Claude Code to move the detector camera farther from the heart. Ask it to set near and far planes that contain the whole schematic.

Help me fix an empty X-ray view.

Add angle controls and test AP

C-arm angles describe where the detector sits around the patient. The two signed sliders turn those angles into a camera direction for the X-ray view.

  • Send this exact request to Claude Code:
Add two sliders under the X-ray view. Slider 1 is the primary angle from RAO 90 to LAO 90, where LAO is positive. Slider 2 is the secondary angle from caudal 45 to cranial 45, where cranial is positive. Show the angle as text like `RAO 30 / CAU 30`. Place the detector camera in direction (sin a × cos b, sin b, cos a × cos b) from the heart, where a is slider 1 and b is slider 2.

What does this request change?

  • The primary slider covers -90 to 90.
  • Negative primary values represent RAO. Positive primary values represent LAO.
  • The secondary slider covers -45 to 45.
  • Negative secondary values represent caudal positions. Positive secondary values represent cranial positions.
  • updateAngles() converts both values into the detector direction. It also updates xrayCamera and angleReadout.
  • Approve Claude Code's edit when it asks by selecting Yes.

Before you refresh, do you expect the two artery layouts to agree when both angle values reach 0?

  • Refresh index.html.
  • Click the browser's Reload button.

You should see two sliders beneath the X-ray view. You should also see an angle label above them.

  • Set the Primary angle: RAO 90 to LAO 90 slider to 0.
  • Find the first slider beneath the X-ray view.
  • Drag its thumb to 0.

You should see the primary part of the angle label change to AP 0.

  • Set the Secondary angle: caudal 45 to cranial 45 slider to 0.
  • Find the second slider beneath the X-ray view.
  • Drag its thumb to 0.

You should see the full angle label change to AP 0 / 0.

  • Drag the left 3D view until you are looking toward the chest.
  • Place your pointer over the left half of the viewer.
  • Hold the primary mouse button.
  • Move the mouse until the arteries face you from the front.

You should see the grey flat artery layout agree with the front-facing 3D layout. Moving either slider should change the right view immediately.

You now have the synchronized comparison this step set out to build: a spatial model on the left and its angle-controlled flat projection on the right.

Do the two views look wrong?

  • Ask Claude Code to keep +X as the patient's left in both views if the layouts look mirrored at AP 0 / 0.
  • Ask Claude Code to use MeshBasicMaterial if the right-side arteries react to the scene lights.

Help me diagnose a mirrored or shaded X-ray view.

Your flat projection now responds to signed viewing angles. Next up, you will add a moving detector frame and standard animated views.

Link the Views and Add Standard Views

Your two-view page now turns slider changes into a flat projection. Next, you will turn that movement into a complete teaching interaction.

The flat view moves, but the 3D scene gives no spatial cue for where that projection comes from.

In this step, get ready to:
  • Add a moving detector frame and dashed center line that stay linked to both sliders.
  • Add six animated preset buttons whose controls and views finish at exact angles.
  • Capture a verified RAO 30 / CAU 30 result after comparing its sign and detector placement with AngioView.
Test the current spatial feedback

A linked teaching view should help you connect the flat projection to a detector position around the schematic heart. First, test whether the current left view communicates that relationship.

Before you move the sliders, do you think the left view can show where the detector sits?

  • Set the Primary angle slider to -30.
  • Switch back to the existing viewer tab in Chrome or Edge.
  • Drag the Primary angle slider until the readout begins with RAO 30.

You will see the readout show RAO 30 / 0. The right projection rotates to its new primary angle.

  • Set the Secondary angle slider to -30.
  • Drag the Secondary angle slider until the readout ends with CAU 30.

You will see the readout settle on RAO 30 / CAU 30. The left view still has no detector frame or center line.

That shortfall is intentional. The projection moves correctly, but the left view cannot yet explain its position in 3D space.

A short request gives Claude Code the missing visual relationship while preserving the linked camera logic you already built.

  • Submit this exact request in the existing Claude Code session:
In the 3D view, draw a thin square frame where the X-ray detector is and a dashed line from it to the heart. Move them whenever the sliders move.

What does this prompt do?

  • The square frame gives the detector a visible position in the 3D view.
  • The dashed line connects that detector position to the schematic heart.
  • Updating both cues with the sliders keeps the left scene synchronized with the flat projection.
  • Refresh the existing index.html page after Claude Code finishes the edit.
  • Return to the existing viewer tab in Chrome or Edge.
  • Click the browser's Refresh button.

You should see a thin square frame and a dashed line in the left view. Moving either slider should move both cues around the schematic heart.

Does the RAO frame move the wrong way?

Ask Claude Code to make RAO negative if the frame moves toward the patient's left for an RAO angle.

Help me correct the detector direction.

Add the animated angle presets

The moving detector cue makes one slider position understandable. Presets turn six useful angle combinations into repeatable demonstrations while keeping every linked element synchronized.

  • Submit this exact request in the existing Claude Code session:
Add six buttons that set the sliders: AP (0, 0), RAO 30 / CAU 30 (-30, -30), Spider LAO 45 / CAU 35 (45, -35), LAO 40 / CRA 35 (40, 35), RAO 30 / CRA 30 (-30, 30), AP CRA 40 (-10, 40). Animate the change over one second so both views move together.

What does this prompt do?

  • Each button supplies one fixed pair of primary and secondary angles.
  • The one-second animation changes the slider values gradually.
  • The existing angle update logic moves the label, detector cue, and projection during that animation.
  • Refresh the existing index.html page after Claude Code finishes the edit.
  • Return to the existing viewer tab in Chrome or Edge.
  • Click the browser's Refresh button.

You should see six preset buttons below the sliders. Each button should carry the exact name from the request.

Do the views jump between presets?

Ask Claude Code to animate the slider values themselves. Changing only the cameras can leave the controls and readout out of sync.

Help me synchronize the preset animation.

Verify every linked view

The preset names alone cannot prove the interaction works. A complete check confirms that each button reaches the intended values and moves every linked visual cue.

Before you try the buttons, do you expect every linked element to arrive at each preset together?

  • Set the viewer to the AP preset.
  • Click AP in the preset button row below the sliders.

After one second, you should see the readout settle on AP 0 / 0.

  • Set the viewer to the RAO 30 / CAU 30 preset.
  • Click RAO 30 / CAU 30 in the preset button row.

After one second, you should see the readout settle on RAO 30 / CAU 30.

  • Set the viewer to the Spider LAO 45 / CAU 35 preset.
  • Click Spider LAO 45 / CAU 35 in the preset button row.

After one second, you should see the readout settle on LAO 45 / CAU 35.

  • Set the viewer to the LAO 40 / CRA 35 preset.
  • Click LAO 40 / CRA 35 in the preset button row.

After one second, you should see the readout settle on LAO 40 / CRA 35.

  • Set the viewer to the RAO 30 / CRA 30 preset.
  • Click RAO 30 / CRA 30 in the preset button row.

After one second, you should see the readout settle on RAO 30 / CRA 30.

  • Set the viewer to the AP CRA 40 preset.
  • Click AP CRA 40 in the preset button row.

After one second, you should see the readout settle on RAO 10 / CRA 40 from the preset values -10 and 40.

You have now confirmed all six presets. The sliders, angle label, detector frame, dashed beam, and flat projection move as one linked system.

AngioView provides a reference for checking the RAO and caudal sign directions without treating either schematic as a clinical tool.

  • Return your viewer to the RAO 30 / CAU 30 preset.
  • Click RAO 30 / CAU 30 in the preset button row.

You should see the readout settle on RAO 30 / CAU 30 while the detector cue and projection finish moving together.

  • Compare only the sign and detector placement between the two schematic pages.

You should see RAO use a negative primary angle and place the detector toward the patient's right. You should see caudal use a negative secondary angle and move toward the patient's feet.

Keep the Viewer Educational

Both pages are schematic teaching aids. Never use either page to interpret a real angiogram or support patient care.

  • Capture a screenshot or short clip of your page while the readout shows RAO 30 / CAU 30.

Your capture should show the linked 3D and X-ray views at RAO 30 / CAU 30 with the detector frame visible.

Claude Code can structure its generated file differently from the reference. Use the tabs below to confirm that your finished page contains the complete verified behavior.

✔️ Awesome, I've got everything!

Great work. Save index.html after confirming that all six presets animate every linked element.

ⓧ I'd like to double check the full code

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Schematic Heart Artery Viewer</title>
  <style>
    :root {
      color-scheme: dark;
      font-family: Inter, ui-sans-serif, system-ui, sans-serif;
    }
    * { box-sizing: border-box; }
    body {
      margin: 0;
      min-height: 100vh;
      background: #020617;
      color: #e2e8f0;
    }
    header, footer, .controls, .credit {
      width: min(1100px, calc(100% - 24px));
      margin-inline: auto;
    }
    header { padding: 18px 0 12px; }
    h1 { margin: 0 0 6px; font-size: clamp(1.35rem, 3vw, 2rem); }
    header p, .credit { margin: 0; color: #94a3b8; }
    .viewer {
      position: relative;
      width: min(1100px, calc(100% - 24px));
      height: clamp(360px, 58vh, 620px);
      margin: 0 auto;
      border: 1px solid #334155;
      border-radius: 14px;
      overflow: hidden;
      background: #0f172a;
    }
    canvas { display: block; width: 100%; height: 100%; }
    .view-labels {
      position: absolute;
      inset: 12px 14px auto 14px;
      display: grid;
      grid-template-columns: 1fr 1fr;
      pointer-events: none;
      font-weight: 700;
    }
    .view-labels span:last-child { color: #27272a; text-align: right; }
    .controls {
      display: grid;
      gap: 14px;
      padding: 16px 0;
    }
    .angle-readout {
      text-align: center;
      font-size: 1.15rem;
      font-weight: 800;
    }
    .sliders {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 16px;
    }
    label { display: grid; gap: 7px; color: #cbd5e1; }
    input[type="range"] { width: 100%; }
    .presets { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
    button {
      border: 1px solid #475569;
      border-radius: 999px;
      padding: 8px 12px;
      background: #1e293b;
      color: #f8fafc;
      cursor: pointer;
    }
    button:hover, button:focus-visible { background: #334155; }
    .credit { padding: 4px 0 12px; font-size: 0.9rem; }
    .credit a { color: #93c5fd; }
    footer { padding: 10px 0 20px; text-align: center; color: #cbd5e1; }
    @media (max-width: 700px) {
      .sliders { grid-template-columns: 1fr; }
      .viewer { height: 430px; }
    }
  </style>
  <script type="importmap">
  {
    "imports": {
      "three": "https://cdn.jsdelivr.net/npm/three@0.187.0/build/three.module.js",
      "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.187.0/examples/jsm/"
    }
  }
  </script>
</head>
<body>
  <header>
    <h1>Schematic Heart Artery Viewer</h1>
    <p>Drag the left view. Use the controls to change the schematic projection.</p>
  </header>

  <div class="viewer">
    <canvas id="viewer"></canvas>
    <div class="view-labels" aria-hidden="true">
      <span>3D view</span>
      <span>Schematic X-ray view</span>
    </div>
  </div>

  <section class="controls" aria-label="C-arm angle controls">
    <div class="angle-readout" id="angleReadout">RAO 30 / CAU 30</div>
    <div class="sliders">
      <label>
        Primary angle: RAO 90 to LAO 90
        <input id="primary" type="range" min="-90" max="90" value="-30" step="1">
      </label>
      <label>
        Secondary angle: caudal 45 to cranial 45
        <input id="secondary" type="range" min="-45" max="45" value="-30" step="1">
      </label>
    </div>
    <div class="presets" id="presets"></div>
  </section>

  <p class="credit">
    Inspired by <a href="https://angioview.com/" target="_blank" rel="noreferrer">AngioView</a>, created by Annas Rahman, MD. See his <a href="https://x.com/AnnasRahmanMD/status/2107153860271706177" target="_blank" rel="noreferrer">project post</a>.
  </p>
  <footer>Educational simulation, not for clinical use.</footer>

  <script type="module">
    import * as THREE from 'three';
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

    const canvas = document.querySelector('#viewer');
    const primarySlider = document.querySelector('#primary');
    const secondarySlider = document.querySelector('#secondary');
    const angleReadout = document.querySelector('#angleReadout');
    const presetsElement = document.querySelector('#presets');

    const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
    renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
    renderer.autoClear = false;
    renderer.setScissorTest(true);

    const scene = new THREE.Scene();
    const origin = new THREE.Vector3(0, 0, 0);

    const leftCamera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
    leftCamera.position.set(7, 4, 10);
    leftCamera.layers.set(0);

    const xrayCamera = new THREE.OrthographicCamera(-4, 4, 4, -4, 0.1, 100);
    xrayCamera.layers.set(1);

    const controls = new OrbitControls(leftCamera, renderer.domElement);
    controls.target.set(0, 0, 0);
    controls.enableDamping = true;
    controls.update();

    const ambient = new THREE.AmbientLight(0xffffff, 1.5);
    ambient.layers.set(0);
    scene.add(ambient);

    const keyLight = new THREE.DirectionalLight(0xffffff, 3);
    keyLight.position.set(5, 8, 8);
    keyLight.layers.set(0);
    scene.add(keyLight);

    const heartMaterial = new THREE.MeshPhongMaterial({
      color: 0xfb7185,
      transparent: true,
      opacity: 0.13,
      depthWrite: false,
      side: THREE.DoubleSide
    });
    const heart = new THREE.Mesh(new THREE.SphereGeometry(2.65, 48, 32), heartMaterial);
    heart.scale.set(0.9, 1.12, 0.78);
    heart.position.y = -0.15;
    heart.layers.set(0);
    scene.add(heart);

    const arteryMaterial = new THREE.MeshStandardMaterial({
      color: 0xef4444,
      roughness: 0.4,
      metalness: 0.05
    });
    const xrayMaterial = new THREE.MeshBasicMaterial({
      color: 0x4b5563,
      transparent: true,
      opacity: 0.58,
      blending: THREE.MultiplyBlending,
      premultipliedAlpha: true,
      depthWrite: false,
      depthTest: false
    });

    const arteryPointSets = [
      [
        [-0.35, 1.45, 1.72],
        [-0.05, 1.35, 1.93],
        [0.35, 1.10, 2.02]
      ],
      [
        [0.35, 1.10, 2.02],
        [0.55, 0.35, 2.23],
        [0.42, -0.55, 2.08],
        [0.12, -1.45, 1.55],
        [-0.10, -2.05, 0.82]
      ],
      [
        [0.35, 1.10, 2.02],
        [0.95, 0.88, 1.84],
        [1.55, 0.52, 1.38],
        [1.98, 0.02, 0.62],
        [1.82, -0.58, -0.02]
      ],
      [
        [-0.42, 1.28, 1.72],
        [-1.03, 1.02, 1.73],
        [-1.62, 0.58, 1.30],
        [-1.93, -0.10, 0.67],
        [-1.72, -0.86, 0.42],
        [-1.08, -1.43, 0.78]
      ]
    ];

    function addArtery(pointTriples) {
      const points = pointTriples.map(([x, y, z]) => new THREE.Vector3(x, y, z));
      const curve = new THREE.CatmullRomCurve3(points);
      const geometry = new THREE.TubeGeometry(curve, 72, 0.105, 12, false);

      const artery = new THREE.Mesh(geometry, arteryMaterial);
      artery.layers.set(0);
      scene.add(artery);

      const xrayArtery = new THREE.Mesh(geometry, xrayMaterial);
      xrayArtery.layers.set(1);
      xrayArtery.renderOrder = 1;
      scene.add(xrayArtery);
    }

    arteryPointSets.forEach(addArtery);

    const frameSize = 2.6;
    const frameGeometry = new THREE.BufferGeometry().setFromPoints([
      new THREE.Vector3(-frameSize, -frameSize, 0),
      new THREE.Vector3(frameSize, -frameSize, 0),
      new THREE.Vector3(frameSize, -frameSize, 0),
      new THREE.Vector3(frameSize, frameSize, 0),
      new THREE.Vector3(frameSize, frameSize, 0),
      new THREE.Vector3(-frameSize, frameSize, 0),
      new THREE.Vector3(-frameSize, frameSize, 0),
      new THREE.Vector3(-frameSize, -frameSize, 0)
    ]);
    const detectorFrame = new THREE.LineSegments(
      frameGeometry,
      new THREE.LineBasicMaterial({ color: 0x38bdf8 })
    );
    detectorFrame.layers.set(0);
    scene.add(detectorFrame);

    const beamGeometry = new THREE.BufferGeometry().setFromPoints([
      new THREE.Vector3(),
      new THREE.Vector3()
    ]);
    const beamLine = new THREE.Line(
      beamGeometry,
      new THREE.LineDashedMaterial({ color: 0x7dd3fc, dashSize: 0.22, gapSize: 0.14 })
    );
    beamLine.layers.set(0);
    scene.add(beamLine);

    const zAxis = new THREE.Vector3(0, 0, 1);
    const detectorDirection = new THREE.Vector3();
    const detectorPosition = new THREE.Vector3();
    let presetAnimation = null;

    function formatPrimary(value) {
      if (value === 0) return 'AP 0';
      return value > 0 ? `LAO ${Math.abs(value)}` : `RAO ${Math.abs(value)}`;
    }

    function formatSecondary(value) {
      if (value === 0) return '0';
      return value > 0 ? `CRA ${Math.abs(value)}` : `CAU ${Math.abs(value)}`;
    }

    function updateAngles() {
      const primary = Number(primarySlider.value);
      const secondary = Number(secondarySlider.value);
      angleReadout.textContent = primary === 0 && secondary === 0
        ? 'AP 0 / 0'
        : `${formatPrimary(primary)} / ${formatSecondary(secondary)}`;

      const a = THREE.MathUtils.degToRad(primary);
      const b = THREE.MathUtils.degToRad(secondary);
      detectorDirection.set(
        Math.sin(a) * Math.cos(b),
        Math.sin(b),
        Math.cos(a) * Math.cos(b)
      ).normalize();

      xrayCamera.position.copy(detectorDirection).multiplyScalar(9);
      xrayCamera.up.set(0, 1, 0);
      xrayCamera.lookAt(origin);
      xrayCamera.updateMatrixWorld();

      detectorPosition.copy(detectorDirection).multiplyScalar(6.5);
      detectorFrame.position.copy(detectorPosition);
      detectorFrame.quaternion.setFromUnitVectors(zAxis, detectorDirection);

      const positions = beamGeometry.attributes.position;
      positions.setXYZ(0, detectorPosition.x, detectorPosition.y, detectorPosition.z);
      positions.setXYZ(1, 0, 0, 0);
      positions.needsUpdate = true;
      beamGeometry.computeBoundingSphere();
      beamLine.computeLineDistances();
    }

    primarySlider.addEventListener('input', () => {
      presetAnimation = null;
      updateAngles();
    });
    secondarySlider.addEventListener('input', () => {
      presetAnimation = null;
      updateAngles();
    });

    const presets = [
      ['AP', 0, 0],
      ['RAO 30 / CAU 30', -30, -30],
      ['Spider LAO 45 / CAU 35', 45, -35],
      ['LAO 40 / CRA 35', 40, 35],
      ['RAO 30 / CRA 30', -30, 30],
      ['AP CRA 40', -10, 40]
    ];

    function animateTo(targetPrimary, targetSecondary) {
      presetAnimation = {
        fromPrimary: Number(primarySlider.value),
        fromSecondary: Number(secondarySlider.value),
        targetPrimary,
        targetSecondary,
        start: performance.now(),
        duration: 1000
      };
    }

    for (const [name, primary, secondary] of presets) {
      const button = document.createElement('button');
      button.type = 'button';
      button.textContent = name;
      button.addEventListener('click', () => animateTo(primary, secondary));
      presetsElement.appendChild(button);
    }

    function resizeRenderer() {
      const width = canvas.clientWidth;
      const height = canvas.clientHeight;
      const pixelWidth = Math.floor(width * renderer.getPixelRatio());
      const pixelHeight = Math.floor(height * renderer.getPixelRatio());
      if (canvas.width !== pixelWidth || canvas.height !== pixelHeight) {
        renderer.setSize(width, height, false);
      }

      const halfWidth = width / 2;
      leftCamera.aspect = halfWidth / height;
      leftCamera.updateProjectionMatrix();

      const viewHeight = 6.2;
      const viewWidth = viewHeight * (halfWidth / height);
      xrayCamera.left = -viewWidth / 2;
      xrayCamera.right = viewWidth / 2;
      xrayCamera.top = viewHeight / 2;
      xrayCamera.bottom = -viewHeight / 2;
      xrayCamera.updateProjectionMatrix();
    }

    function render(now) {
      requestAnimationFrame(render);
      resizeRenderer();

      if (presetAnimation) {
        const elapsed = Math.min((now - presetAnimation.start) / presetAnimation.duration, 1);
        const eased = elapsed < 0.5
          ? 2 * elapsed * elapsed
          : 1 - Math.pow(-2 * elapsed + 2, 2) / 2;
        primarySlider.value = THREE.MathUtils.lerp(
          presetAnimation.fromPrimary,
          presetAnimation.targetPrimary,
          eased
        );
        secondarySlider.value = THREE.MathUtils.lerp(
          presetAnimation.fromSecondary,
          presetAnimation.targetSecondary,
          eased
        );
        updateAngles();
        if (elapsed === 1) presetAnimation = null;
      }

      controls.update();
      const width = canvas.clientWidth;
      const height = canvas.clientHeight;
      const halfWidth = width / 2;

      renderer.setViewport(0, 0, halfWidth, height);
      renderer.setScissor(0, 0, halfWidth, height);
      renderer.setClearColor(0x0f172a, 1);
      renderer.clear(true, true, true);
      renderer.render(scene, leftCamera);

      renderer.setViewport(halfWidth, 0, halfWidth, height);
      renderer.setScissor(halfWidth, 0, halfWidth, height);
      renderer.setClearColor(0xd4d4d8, 1);
      renderer.clear(true, true, true);
      renderer.render(scene, xrayCamera);
    }

    updateAngles();
    requestAnimationFrame(render);
  </script>
</body>
</html>

Your one-file viewer is complete. Next, an optional Secret Mission pushes the experience beyond its schematic heart shell.

Secret mission

Swap in a Real Heart Model

Replace the viewer's faint schematic shell with the credited NIH 3D Heart, Male model. Serve the new local asset with Python. Preserve every existing interaction plus the exact safety footer.

Clean Up Your Resources

Clean Up Your Resources

Your viewer and model asset live on your computer, so keeping them creates no ongoing cloud costs. Choose whether to keep the server running, pause it, or remove the project files entirely.

Resources you used:

  • A running Python HTTP server that makes the viewer available at http://localhost:8000.
  • The Desktop heart-viewer folder containing index.html and the downloaded NIH 3D Heart, Male model.

Keep everything running

No action needed. Choose this if you are still using the viewer or refining the model integration.

  • Leave the terminal window running to keep the viewer available at http://localhost:8000.
  • Keep the heart-viewer folder on your Desktop so the model asset and attribution stay with the viewer.

Pause - I'll come back to this later

Shut down the local server to free the terminal while preserving every project file.

  • Return to the terminal window running the local server.
  • Press Ctrl+C to stop the server.

The server stops responding at http://localhost:8000. Your complete heart-viewer folder remains ready for your next session.

Delete - I don't want to use this again

Deleting the folder permanently removes the viewer and downloaded model from your computer. Your Claude account and Python installation remain untouched.

  • Return to the terminal window running the local server.
  • Press Ctrl+C to stop the server.

macOS

  • Locate the heart-viewer folder on your Desktop.
  • Drag the heart-viewer folder into the Trash in the Dock.
  • Empty the Trash to remove the local files permanently.

You should no longer see heart-viewer on your Desktop.

Windows

  • Locate the heart-viewer folder on your Desktop.
  • Drag the heart-viewer folder into the Recycle Bin.
  • Empty the Recycle Bin to remove the local files permanently.

You should no longer see heart-viewer on your Desktop.

Nice Work!

Nice Work!

You did it! Your interactive 3D visualization links a draggable artery model to a schematic X-ray view while a credited NIH heart model surrounds the arteries.

You've learned how to:

  • Directed Claude Code with plain-English prompts to create a one-file index.html page powered by three.js. It displays four schematic artery tubes. You can drag or zoom the 3D view.
  • Built linked 3D and schematic X-ray views with DICOM-sign C-arm angles. The sliders synchronize an orthographic projection with the detector frame. They also synchronize the dashed beam with the angle label.
  • Added six animated presets. Captured RAO 30 / CAU 30 to prove both views move together. Preserved the exact safety footer: Educational simulation, not for clinical use. Credited AngioView and Annas Rahman, MD as inspiration.
  • Secret Mission: Replaced only the faint shell with the credited CC BY 4.0 Heart, Male model from NIH 3D entry 3DPX-021000. Selected a compatible three.js loader for the downloaded format. Served the model from the heart-viewer folder through a local Python HTTP server. Confirmed all six presets still work.

Ready to quiz yourself?