Nodes/Avatar Graph/Mesh Sort Elements
ComfyUI Node

Mesh Sort Elements

Reorder the mesh's internal index numbering

By avatechai·Created 3 years ago·Updated 2 years ago· 264
Mesh Sort Elements
  • BPY_OBJ
  • elements
  • BPY_OBJ
type
reversefalse
seed0

This is a plumbing node, not a visual one - expect nothing to look different in a preview after running it, because nothing about the geometry or the current selection actually changes. It wraps Blender's real bpy.ops.mesh.sort_elements operator, part of Avatar Graph, the pack that runs actual Blender inside ComfyUI's process (via the bpy Python package) to build interactive 2D-to-3D avatars, auto-generating a node for every mesh operator Blender has.

What it actually does

Every vertex, edge, and face on a mesh has an internal index number, and that numbering is normally invisible - until something downstream depends on it. Export formats can rely on consistent vertex order for morph-target/shape-key correspondence; scripts that walk a mesh element-by-element read it in index order; keeping numbering stable across regenerated versions of a mesh matters for anything comparing them. This node reorders that internal numbering according to a rule you pick, without touching where any vertex actually sits in space.

Inputs and output

  • BPY_OBJ - the mesh coming in.
  • type - the sort rule: VIEW_ZAXIS or VIEW_XAXIS (order by position along that axis), CURSOR_DISTANCE (order by distance from the 3D cursor), MATERIAL (group by material slot), SELECTED (selected elements first), RANDOMIZE (shuffle), or REVERSE (flip the current order).
  • elements - a B_ENUM_SET, meaning a checkbox-style multi-select rather than a single choice: tick VERT, EDGE, and/or FACE to control which element types the reorder actually applies to.
  • reverse (default false) - flips the resulting order after the chosen sort rule is applied.
  • seed - only meaningful when type is RANDOMIZE; controls the shuffle.

Output is a single BPY_OBJ, geometry unchanged, internal ordering updated.

Installing it

ComfyUI Manager: search "avatar-graph-comfyui", install, restart. Manually: cd ComfyUI/custom_nodes && git clone https://github.com/avatechai/avatar-graph-comfyui, then cd avatar-graph-comfyui && python -m pip install -r requirements.txt, then restart.

Python 3.10.x is the requirement to nail down first - the bpy package this pack is built on needs that exact minor version, and the README recommends a dedicated conda environment on macOS/Linux (conda create --name comfyui python=3.10) rather than trusting an existing Python install. Windows users get a prebuilt ComfyUI + Python 3.10 zip linked in the README to unzip over their install before adding the pack via Manager. Restart with --enable-cors-header (macOS also wants --force-fp16) for the live 3D preview - without it, the graph still runs fine, you just save the model manually from the pack's Avatar Main Output node instead.

Common issues

Rule out the Python version first if this pack's nodes aren't loading. On this node specifically, "nothing happened" after running it is the expected result almost every time - this reorders index numbering, not geometry or visible selection state, so there's genuinely nothing to see in a viewport or preview. It only matters once something further downstream (an export step, a script reading elements by index) actually cares about that order. And check elements if a sort seems to have no effect on the element type you expected: choosing FACE as the sort type while only VERT is enabled in elements reorders the wrong thing for what you intended.

Categoryblender

Inputs (5)

NameTypeDefaultDescription
BPY_OBJoptBPY_OBJ
typeoptCOMBO7 options: VIEW_ZAXIS, VIEW_XAXIS, CURSOR_DISTANCE, MATERIAL, SELECTED, RANDOMIZE, +1
elementsoptB_ENUM_SET
reverseoptBOOLEANfalse
seedoptINT00–2147483647

Outputs (1)

NameTypeDescription
BPY_OBJBPY_OBJ