4
$\begingroup$

For modifying meshes (in the hereunder example removing vertices), I use the script as follows:

        # Création du Bmesh
        maillage = bpy.data.meshes[nom_objet]
        bm = bmesh.new()
        bm.from_mesh(maillage)
        # Mise à jour des ID des listes verts et faces
        bm.verts.ensure_lookup_table()
        # Suppression de tous les points du maillage sur Ox
        points_a_supprimer = [v for v in bm.verts if v.co.yz.length < 1e-07]
        bmesh.ops.delete(bm, geom = points_a_supprimer, context = 'VERTS')
        # Modification du maillage de l'objet et suppression du Bmesh
        bm.to_mesh(maillage)
        bm.free()
        del bm

But I do not really understand if the use of ".ensure_lookup_table()" is relevant. What is the purpose of this code ? Thanks in advance for explanations.

$\endgroup$
6
  • 1
    $\begingroup$ Totally unnecessary here. Relevant when indexing eg v = bm.verts[0]. Recommend testing against a tollerance rather than exact values. eg v.co.xy.length < 1e-7 $\endgroup$
    – batFINGER
    Commented Aug 8, 2020 at 12:20
  • $\begingroup$ Ensure lookup table only needed after you change the BMVertSeq in your script $\endgroup$
    – HikariTW
    Commented Aug 8, 2020 at 23:46
  • $\begingroup$ Thanks !Removing vertices does not change the BMVertSeq ? $\endgroup$
    – Hector
    Commented Aug 9, 2020 at 7:24
  • 1
    $\begingroup$ @HikariTW see above. Always needed if you intend to index that element. eg in console try bm = bmesh.new() and follow with bm.verts[0] ..... error need to run ensure lookup table. .. remember this is an empty new bmesh so no sequence has been altered. $\endgroup$
    – batFINGER
    Commented Aug 9, 2020 at 9:08
  • 1
    $\begingroup$ @batFINGER , when I remove the code line "bm.verts.ensure_lookup_table()" from the script, it continuous working right. And after that, if I add the code line "v=bm.verts[0]" I get the error message "IndexError: BMElemSeq[index]: outdated internal index table, run ensure_lookup_table() first". So, things are now clear for me. Again thanks for help. $\endgroup$
    – Hector
    Commented Aug 9, 2020 at 14:22

0

You must log in to answer this question.

Browse other questions tagged .