Nodes/ComfyUI libigl/Scramble Int Field
ComfyUI Node

Scramble Int Field

Make segmentation colors actually readable

By PozzettiAndrea·Created 10 months ago·Updated 4 days ago· 218
Scramble Int Field
  • mesh
  • mesh
field_nameseg
seed0

ScrambleIntField solves a stupidly common annoyance: you run a segmentation or connected-components pass on a mesh, color-map the label field in a viewer, and every adjacent segment is almost the same color because their integer labels happen to be numerically close. Human brains read that as mush. This node fixes it by reassigning the label values so that neighboring segments get maximally distinct numbers - which, once you color-map them, means maximally distinct colors. It's a tiny utility, but if you've ever stared at a 40-color segmentation trying to find the boundary between label 7 and label 8, it feels like a gift.

How it works

The mechanism is more clever than the name suggests. It reads an integer face field (by default face_seg), builds the adjacency graph of segments - which segments share edges, using trimesh's built-in face adjacency - then runs greedy graph coloring on that graph so no two adjacent segments end up with the same value. It finishes by spreading the assigned colors across the original value range using golden-ratio spacing, which makes the colors land evenly rather than clumping. The whole thing is seeded, so the same seed gives you the same scramble every time - important when you want to compare runs or reproduce a result for someone else.

Two details worth knowing. The field it reads is face_<field_name>, looked up in the mesh's face attributes first, then in legacy metadata for compatibility - so if you're working with older workflows that stored labels in metadata, it still finds them. And it's non-destructive: if the field you asked for doesn't exist, it logs a warning and returns your mesh unchanged rather than erroring or corrupting anything.

Inputs and outputs

  • mesh - the TRIMESH input, straight from any node that produces one, ideally one carrying a face-label field.
  • field_name (default seg) - which integer face field to scramble. Match it to whatever your upstream node named its labels.
  • seed (optional, default 0) - controls the color-assignment order, per the tooltip. Change it to get a different scramble.

The single output is mesh - the same mesh with the scrambled values written back into both face attributes and metadata. Wire it into a color-mapped preview (the pack's VTK/fields viewers handle this nicely) and the boundaries will finally pop.

Installing it

It's part of ComfyUI-GeometryPack, so install the pack once and every node comes with it:

cd ComfyUI/custom_nodes
git clone https://github.com/PozzettiAndrea/ComfyUI-GeometryPack.git
cd ComfyUI-GeometryPack
pip install -r requirements.txt --upgrade
python install.py

or search GeometryPack in ComfyUI Manager and restart. The pack's install is the experimental comfy-env one - it pulls pixi and heavy native deps (Blender, CGAL, libigl, VTK) on first launch, so budget a few minutes of build time and don't assume it hung.

Where people get burned

Almost all ScrambleIntField problems are field-name problems. The default is seg, and if your upstream node names its labels anything else - label, part, component - this node will quietly return your mesh unchanged while logging "Field 'x' not found" to the console. Check that message before assuming the node is broken. Also keep expectations honest about what "scramble" means: it maximizes contrast between neighbors, it doesn't sort your segments by size or meaning. And since this pack is explicitly work-in-progress (the author's own release notes say "occasional breakage"), if a brand-new version of the pack changes how fields are stored, your old metadata-based workflows may need a nudge. For the daily job - making a segmented mesh legible at a glance - it's hard to beat a node that does one thing, does it well, and refuses to touch your mesh when it can't.

Categorygeometrypack/analysis

Inputs (3)

NameTypeDefaultDescription
meshTRIMESH
field_nameSTRINGsegName of the integer face field to scramble.
seedoptINT00–4294967295Random seed for color assignment order.

Outputs (1)

NameTypeDescription
meshTRIMESH