Communitygithub.com

kg-to-3d

Turns a P&ID knowledge graph (the graph.json produced by the pid-to-kg skill) into a 3D Blender scene where every item rises out of its own symbol on the drawing, with field instruments and the control system on layers above. Renders a still image or a short vertical video that lights up a flow path and a control loop. Use when the user wants a 3D view, image, animation or video of a P&ID, a process knowledge graph, a flow path or a control loop.

What is kg-to-3d?

kg-to-3d is a Claude Code agent skill that turns a P&ID knowledge graph (the graph.json produced by the pid-to-kg skill) into a 3D Blender scene where every item rises out of its own symbol on the drawing, with field instruments and the control system on layers above. Renders a still image or a short vertical video that lights up a flow path and a control loop. Use when the user wants a 3D view, image, animation or video of a P&ID, a process knowledge graph, a flow path or a control loop.

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/AtelierPlatonAI/kg-to-3d/tree/HEAD/skills/kg-to-3d

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

Knowledge graph to 3D

This skill shows the drawing in volume. It does not rebuild the plant layout: a P&ID records what is connected to what, not where things stand. Say so whenever you present a render.

Work is split the same way as in pid-to-kg:

  • Scripts compute the layout (scripts/layout.py, plain Python) and build and render the scene (scripts/build_scene.py, run inside Blender).
  • You choose what the video should show (one flow path, one control loop), check the stills, and report.

The interface between the two scripts is references/scene_contract.md. Read it before changing either script.

Setup

  • Python 3.10+ with networkx (pip install -r <skill dir>/scripts/requirements.txt, in a virtual environment if the user's Python is shared).

  • Blender 4.2 or newer. Look for it in this order: the BLENDER environment variable, blender on the PATH, ~/opt/blender-*/blender, /Applications/Blender.app/Contents/MacOS/Blender, C:\Program Files\Blender Foundation\Blender*\blender.exe. Check it with <blender> --version.

    If none is found, offer to install it. Many users are engineers, not programmers: say in one sentence what you will install and where, and run the command only after the user agrees.

    SystemCommand
    Windowswinget install BlenderFoundation.Blender (Windows may ask for administrator approval)
    macOSbrew install --cask blender if Homebrew is present; otherwise point the user to the .dmg on blender.org
    Linuxthe official archive, no sudo: list https://download.blender.org/release/, take the latest LTS blender-<version>-linux-x64.tar.xz and its blender-<version>.sha256, check the archive with sha256sum -c --ignore-missing (the .sha256 file lists every platform), extract it into ~/opt/, then use ~/opt/blender-<version>-linux-x64/blender

    If the user declines, or the install fails, stop and say how to install it from blender.org.

  • ffmpeg for the video. Without it, deliver stills only and say why.

  • No graphics card is required: without one, renders fall back to Cycles on the CPU and the video takes much longer.

Workflow

- [ ] 1. Inputs:  find <kg dir> (graph.json, summary.md) and, if available, the pid-to-kg <work dir> (page images)
- [ ] 2. Choose:  one flow path and one control loop worth showing (from summary.md)
- [ ] 3. Layout:  python <skill dir>/scripts/layout.py <kg dir> --work <work dir> --out <out dir>
                  --path FROM TO --path-label "<question or title>" [--path FROM TO --path-label "..."] [--loop LOOP:<key>]
- [ ] 4. Stills:  <blender> -b -P <skill dir>/scripts/build_scene.py -- <out dir>/scene.json --out <out dir> --stills
- [ ] 5. Review:  open every still and fix what looks wrong (see Review)
- [ ] 6. Video:   <blender> -b -P <skill dir>/scripts/build_scene.py -- <out dir>/scene.json --out <out dir> --video
- [ ] 7. Report:  files, what the video shows, and the layout caveat
- [ ] 8. Web (optional): <blender> -b <out dir>/scene.blend -P <skill dir>/scripts/export_web.py -- <out dir>/scene.json
                  --out <web dir> --name path:1 "<short name>" [--name ...] [--credit TEXT --credit-url URL]

2. Choose what to show

  • Path: a flow path the user's audience can follow, crossing at least two sheets when possible (e.g. from a basin to the tank it ultimately feeds). Prefer equipment-to-equipment paths from the FEEDS edges in summary.md.
    • --path is repeatable, with one --path-label per path. The paths play in the order given, so put the gas path (e.g. blower air) before the liquid path it acts on.
    • Gas or liquid is detected from the line services along the path: gas when most of them name a gas (air, oxygen, nitrogen, hydrogen, argon, CO2, steam, vapor, biogas), else liquid. A gas path is pale blue and makes bubbles rise in the basins it reaches; a liquid path is amber.
  • Loop: a control loop with a sensor, a controller and a final element (loop_type control or interlock). A monitoring-only loop makes a weak animation. Without --loop, layout.py keeps one default loop: the control, interlock or on_off loop with a final element and the longest chain. Pass --loop LOOP:<key> to choose another.
  • If the user named a question ("what feeds the equalization tank?"), pick the path that answers it and pass the question as its --path-label.

5. Review

Look at each still at full size, then zoomed on crowded areas. Fix before rendering the video:

  • objects that do not sit on their symbol (bbox estimates from pid-to-kg are approximate; small offsets are fine)
  • labels that overlap objects or each other, text that is unreadable at 1080x1350
  • pipes that cross through equipment, or links that go nowhere
  • anything that looks cheap: flat lighting, aliasing on thin lines, half-transparent leftovers

Layout problems are fixed with layout.py options or in the scene file, not by editing the Blender script.

7. Report

Give the paths of still_*.png, kg3d.mp4 (1080x1350) and kg3d_master.mp4 (2160x2700), and scene.blend. Say which path and loop the video lights up, and repeat that positions come from the drawing, not from the plant.

8. Web viewer (optional)

Offer it when the user wants other people to explore the scene (a link in a post, a page for a team). export_web.py writes a static folder (index.html, scene.glb, viewer.json, fonts) described in references/web_contract.md: people orbit the model with a finger or a mouse and tap one button per path or loop.

  • Give each path and loop a short button name with --name (e.g. --name path:1 "Blower air").
  • When the drawings come from a third party, pass their source with --credit and --credit-url.
  • Test it locally: python -m http.server in the web folder, then open it at phone size (390x844) and desktop size.
  • Hosting is the user's call: any static host works. For GitHub Pages, the folder goes in docs/ of a public repository and --site-url gives the page address, so link previews show the poster (--poster).
  • The poster is a 1200x628 JPEG: crop a striking frame of the video (<out dir>/frames/, e.g. bubbles rising in a basin) to that landscape ratio. Look at it before using it.

Related Skills