27
$\begingroup$

How does the program decide what indices to assign to vertices? If you create a primitive, are the indices generated randomly, or by some base primitive setting? If you extrude new vertices, will they be the next number in sequence?

What happens when you join two objects together that have the same indices used? Which points get reassigned, and by what logic? Can anything be done to control which get re-assigned?

Are there any ways to recalculate, re-assign, or copy vertex indices?

$\endgroup$

4 Answers 4

29
$\begingroup$

How does the program decide what indices to assign to vertices?

  • new vertexes are appended to the end of the vertex list
  • duplicating vertexes adds them also to the end and their order is maintained
  • .. list too long..

It would be very time consuming to analyze every mesh operation/modifier and how it handles vertex indices and make a list for you (it will be like the above though in most cases if not in all). Instead you can reverse engineer this yourself:

Type bpy.app.debug = True into the Python Console

This will enable super top secret mode with next option available in Properties panel:

enter image description here

Now you can see the indices and how they change for what you are interested in:

enter image description here

Can anything be done to control which get re-assigned?

Nope, blender handles it internally.

Are there any ways to recalculate, re-assign, or copy vertex indices?

Sure, with python you can do anything to meshes, you can reorder the vertices. Just by building a new mesh with different vertex order from old one and then switching them.

$\endgroup$
4
  • 1
    $\begingroup$ Is there a way to change the indices colors as well? The dark blue on a dark background is sometimes bad to read. $\endgroup$ Commented Mar 23, 2018 at 7:18
  • 1
    $\begingroup$ @BrunoBieri Yes, you can go to UserPrefs > Themes > 3D View and change the Face Angle Text Color which these numbers use. $\endgroup$ Commented Mar 23, 2018 at 8:58
  • 1
    $\begingroup$ It seems this has been moved to another place in Blender 2.8. Any ideas where I could find it? $\endgroup$
    – Bauxite
    Commented Apr 9, 2020 at 12:24
  • 2
    $\begingroup$ For Blender 2.8+ see blender.stackexchange.com/a/158495/1363 $\endgroup$
    – CodeManX
    Commented Jul 17, 2020 at 16:14
24
$\begingroup$

Jerryno did a great job of explaining mesh indexes in his answer, so I will focus on:

Are there any ways to recalculate, re-assign, or copy vertex indices?

Yes.

First let me clarify that there are more then just vertex indexes, faces and edges have indexes as well, but for the rest of this answer I will refer to just vertex indexes.

The simplest way to reorder the vertex indexes is with the Sort Mesh Elements tool, accessible from the 3D view header Mesh > Sort Elements. All the option in the dropdown menu run the same tool, and can be changed like any other operator by pressing F6 or in the Operator Properties section of the tool shelf.

menu item

If you want to do anything beyond reordering the indexes, that will require python.

$\endgroup$
2
  • $\begingroup$ ...so, you select the mesh that has the "wrong" order, and a similar mesh with the target order, and do Edit (vertices) -> Mesh -> Sort Elements -> Selected? $\endgroup$ Commented May 1, 2020 at 23:36
  • $\begingroup$ no it does not copy some other mesh's vertices' ids. To quote the manual "Selected Move all selected elements to the beginning (or end, if Reverse enabled), without affecting their relative orders. Warning: This option will also affect unselected elements’ indices!" AKA not what you want it to do. "Selected" simply renumbers the selected vertices so that they are at the beginning (or end with reverse enabled) of the indices. $\endgroup$
    – David
    Commented May 3, 2020 at 2:07
15
$\begingroup$

You can also sort mesh elements with Python, using the bmesh module:

import bpy
import bmesh
import random

ob = bpy.context.object
assert ob.type == "MESH"
me = ob.data

bm = bmesh.from_edit_mesh(me)
new_order = list(range(len(bm.verts)))
random.shuffle(new_order)

for i, v in zip(new_order, bm.verts):
    v.index = i

print("shuffled indices:")
for v in bm.verts:
    print(v.index)

print("update index()")    
bm.verts.index_update()

print("indices returned to original order:")
for v in bm.verts:
    print(v.index)

print("shuffling again, followed by a sort:")
for i, v in zip(new_order, bm.verts):
    v.index = i
bm.verts.sort()

for v in bm.verts:
    print(v.index)

bmesh.update_edit_mesh(me)

It's important to call sort() after assigning new indices to actually apply the new order. After that, indices will be ordered 0..n, but if you check the indices drawn in viewport, then you'll see that they changed.

$\endgroup$
8
  • $\begingroup$ Will this re-order to 0..1..2..3..4..5..n incrementally? Some game engine don't accept face indices and just programatically generate it incrementally on run-time. $\endgroup$
    – majidarif
    Commented May 17, 2017 at 17:51
  • $\begingroup$ Not sure what you mean by incrementally... If you export from Blender after sorting, the indices should be in that order. I don't think that holes (e.g. 0, 2, 3, ...) are allowed in Blender. $\endgroup$
    – CodeManX
    Commented May 18, 2017 at 15:47
  • $\begingroup$ I asked a question about that here. Can you check? :) blender.stackexchange.com/questions/79805/re-arranging-vertices $\endgroup$
    – majidarif
    Commented May 18, 2017 at 16:21
  • $\begingroup$ @CoDEmanX Its a nice script that shuffles the verices. What do i need to change to sort the list from smallest to biggest? i tried sorted(new_order) but did not worked $\endgroup$
    – DGRL
    Commented Dec 30, 2019 at 11:17
  • $\begingroup$ @DGRL Smallest to biggest what? $\endgroup$
    – CodeManX
    Commented Dec 31, 2019 at 12:40
7
$\begingroup$

For whoever will find this helpful, here is how to display vertex indices in 'Blender 2.80':

  1. In Preferences - Interface - Display, check 'Developer Extras'.

    enter image description here

  2. In the 3D View - Overlays, there should now be a 'Developer' section, check its "Indices" box - see screenshot below:

    enter image description here

$\endgroup$
5
  • $\begingroup$ thanks for the answer. I am able to do Step 1, but how do you do Step 2? I do not see an option for "3D View" to click. $\endgroup$ Commented Apr 22, 2020 at 23:26
  • $\begingroup$ I just added a screenshot, hope that helps. $\endgroup$
    – Animik
    Commented Apr 24, 2020 at 9:56
  • $\begingroup$ Also, don't forget to check "Text info" in the same panel, for some reason it is unchecked by default (on my end at least) $\endgroup$
    – Gorgious
    Commented Apr 24, 2020 at 10:04
  • $\begingroup$ Thanks! (I am using Blender 2.8+ but hopefully the interface is similar -- let me check!) $\endgroup$ Commented Apr 24, 2020 at 15:56
  • 1
    $\begingroup$ Is it possible to change the font, size and color of the index overlay? It's very difficult to read. $\endgroup$ Commented Sep 30, 2020 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .