1

I want to create an object based on the active one with inset faces and modified vertex coordinates. Inset works as expected if I don't modify verts coordinates but if I do it gives me unexpected results. Do I need to somehow "recalculate" bmesh after I modify verts positions?

Here's the result I'm getting:

enter image description here

Here's a code I run on a Plane object. As an example I make every point of the object 1 unit higher. I tried to include different variants of .ensure_lookup_table() without any luck.

import bpy
import bmesh
from mathutils import Vector

ob = bpy.context.object bm = bmesh.new() bm.from_mesh(ob.data)

for index, v in enumerate(bm.verts): v.co = v.co + Vector((0,0,index))

insetting bmesh

inset_faces = bmesh.ops.inset_region(bm, faces = bm.faces, thickness=0.5, use_boundary=True, use_even_offset=True)

creating mesh

mesh = bpy.data.meshes.new("mesh") obj = bpy.data.objects.new("new_obj", mesh) bpy.context.scene.collection.objects.link(obj)

bm.to_mesh(obj.data) obj.data.update() bm.free()

What am I missing?

Sergey Kritskiy
  • 895
  • 5
  • 15

1 Answers1

2

Update the normals.

After you "twist" face by index translation, the normals are not recalculated unless we explicitly call normal_update either on the bmesh instance, or on a per face basis.

Update Edge Info when using script in Edit Mode

Script with that edit, also optionally changed operator to inset individual.

import bpy
import bmesh
from mathutils import Vector

ob = bpy.context.object bm = bmesh.new() bm.from_mesh(ob.data)

for v in bm.verts: v.co.z += v.index

update the normals

bm.normal_update()

or on per face

''' for f in bm.faces: f.normal_update() '''

insetting bmesh

inset_faces = bmesh.ops.inset_individual( bm, faces=bm.faces, thickness=0.5, #use_interpolate=True, use_even_offset=True)

creating mesh

mesh = bpy.data.meshes.new("mesh") obj = bpy.data.objects.new("new_obj", mesh) bpy.context.scene.collection.objects.link(obj)

bm.to_mesh(obj.data) obj.data.update() bm.free()

enter image description here

batFINGER
  • 84,216
  • 10
  • 108
  • 233