How to update UVs after a geometry modification in bmesh

I did the most simple code I could. you need to select 2 verts in edit mode on the default cube. which has already UVs. So my question is how to update UVs to the new geometry?

import bpy,bmesh
me =
bm = bmesh.from_edit_mesh(me) 
hist = bm.select_history
v2=hist[1]  =,1)
bmesh.ops.remove_doubles(bm, verts=list(hist), dist=0.0001)

#there? if I want to update UVs
uv_layer =
for face in bm.faces:
    for loop in face.loops:
        loop[uv_layer].uv = ?


uvs are modified by accessing their layer data, which is stored in loops. here’s a similar question over on stack exchange that has some example code in the solution that should help get you going:

ok I give up this idea correct uv option in some operator gives really strange things

I thought it was possible to do same operation on UV that on vertices like a merge but apparently like several loops are linked to the two vertices this is a mess…

right- that’s kinda what i was talking about, UVs are stored per LOOP, not per vert. there is no such thing as “merging uvs”. If two uvs share an edge and are cospatial then they are ‘merged’.

and it’s not really a mess, that’s just how UVs work. In other tech (unity and UE4 for example) uvs are stored per triangle, and it’s the same thing- there is no ‘merging’ of uvs.

1 Like

I just remembered a lengthy post I made a year or so ago over on devtalk that goes into much greater detail about all of this in case you’re interested in learning more about it:

1 Like

I understood what you explained and I saw it before but I really don’t see how to transform my code to have the wanted result. before I was using the remove double operator, it has an option correct UVs. so if you are merging several vertices on 2 edges you get a hole in UVs without correct UVs (the missing face). but now I’m using a lerp fonction to reduce distance between vertices and at value=1 it’s merging (bmesh remove double which has not uv option). what is happening at line 147 in the script