16
$\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$
22
$\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$
  • $\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$ – Bruno Bieri Mar 23 '18 at 7:18
  • $\begingroup$ @BrunoBieri Yes, you can go to UserPrefs > Themes > 3D View and change the Face Angle Text Color which these numbers use. $\endgroup$ – Jaroslav Jerryno Novotny Mar 23 '18 at 8:58
13
$\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$
8
$\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$
  • $\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 May 17 '17 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 May 18 '17 at 15:47
  • $\begingroup$ I asked a question about that here. Can you check? :) blender.stackexchange.com/questions/79805/re-arranging-vertices $\endgroup$ – majidarif May 18 '17 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.