Nodes/Comfyui-imagetoSTL/ImageToSTLNode
ComfyUI Node

ImageToSTLNode

Turn a depth map into an actual STL file

By xiaogui8dangjia·Created about a year ago·Updated about a year ago· 3
ImageToSTLNode
  • image
  • stl_file_path
save_pathC:\Users\Administrator\Desktop/模型.stl
height_scale20.0
x_scale1.0
y_scale1.0

You already know the workflow: run a depth estimator, get a grayscale map where white is near and black is far. The missing piece is what you do with that map when you want something physical. ImageToSTLNode is that missing piece - it reads the brightness of each pixel, treats it as a height, and writes a real .stl file to disk. No models to download, no API to call, no GPU required. It's pure CPU numpy math from image to file.

Set expectations before you get excited, though. This is a bas-relief tool, not an image-to-3D engine. It produces the kind of thing you'd mill onto a plaque or a coin - a height field, like the Marigold 3D-printing demo everyone got excited about - not a sculpture with volume and backfaces. If you want full 3D models, that's TripoSR or Hunyuan3D territory. This node is for the narrow, genuinely useful case of "I have a depth/height map and I want to print it as a relief."

How it actually works

The source is one file and it's refreshingly simple. The node:

  1. Converts the ComfyUI image tensor to a PIL image (taking the red channel if you feed it color - so feed it grayscale).
  2. Shrinks the longest side to 500px with bicubic resampling, so a 1024×1024 depth map becomes a 500×500 heightfield.
  3. Builds a grid of vertices where z = pixel_brightness / 255 * height_scale - brighter pixels poke up higher.
  4. Writes two triangles per grid cell, centers the model at the origin, rotates it 180°, and exports via trimesh to your save_path.

Roughly half a million triangles for a maxed-out 500×500 image. That's chunky but fine for a relief.

The inputs and output that matter

Only four inputs, and only one you'll actually fiddle with most of the time:

  • image - your depth map or grayscale height image. Bright = tall, so a white background with a dark subject prints as a depression, not a bump. Invert if you want it the other way.
  • height_scale (default 20, range 10–40) - how tall the relief gets in Z units. This is the one you tune. Low for a subtle plaque, high for an aggressive relief.
  • x_scale / y_scale (default 1, 0.1–10) - stretch or squash the model in the X/Y plane. Left at 1 unless you're compensating for a print's aspect ratio.
  • save_path - where the STL lands.

The single output, stl_file_path, is a STRING: the absolute path of the file it wrote. It also auto-dedups - run it twice and you get model_1.stl instead of an overwrite.

Installing it

One caveat up front: this pack has no requirements.txt, and it imports trimesh at the top of the module. If trimesh isn't in ComfyUI's Python environment, the node fails to register at startup. Install it into your ComfyUI venv:

cd ComfyUI/custom_nodes
git clone https://github.com/xiaogui8dangjia/Comfyui-imagetoSTL
# then install the one real dependency into ComfyUI's Python:
/path/to/comfyui/venv/bin/pip install trimesh

Restart ComfyUI and it shows up as ImageToSTLNode. You can also search "Comfyui-imagetoSTL" in ComfyUI Manager, but it'll still need the trimesh install. No model files, nothing else.

Where people get burned

The default save path is a hardcoded Windows path - C:\Users\Administrator\Desktop\模型.stl, literally the author's own desktop from their dev box. On Linux or macOS that's a nonsense path, and the node even tries to mkdir it on load (you'll get a directory literally named C:\Users\Administrator\Desktop sitting in your ComfyUI folder - harmless but weird). Set save_path to something real every time.

The mesh is an open shell, not watertight. There's no base plate and no side walls - just the top surface of triangles. A slicer will complain about open edges and non-manifold geometry. For a quick look or a CNC/carving pass it's fine; for FDM printing you'll want to add a base and solidify the shell in something like PrusaSlicer, Blender, or MeshLab first.

Resolution is capped at 500px. Bigger depth maps get downscaled, so fine detail in the original image is gone before it ever becomes geometry. If detail matters, generate your depth map at a sensible resolution - you don't need 4K, and you'll gain nothing from it here.

The upside: it's fast, free, and dead simple. Feed it a good depth map, set height_scale to taste, and you have a print-ready relief in seconds - the cheap end of a niche that usually involves a GPU, a model download, and a lot more ceremony.

CategoryCustom Nodes

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
save_pathSTRINGC:\Users\Administrator\Desktop/模型.stl
height_scaleFLOAT20.010–40
x_scaleFLOAT1.00.1–10
y_scaleFLOAT1.00.1–10

Outputs (1)

NameTypeDescription
stl_file_pathSTRING