I created a script (operator) that converts a selection of quads into a diamond pattern.
It works fine but when I try to Inset the newly created selection and change any of the options (like switching to individual face insets) the mesh seems to revert back to the original topology before my script was even run (see image below).
Video of what happens (I decided to select the faces manually but same result): https://www.youtube.com/watch?v=UHUNfZG1Qnw&feature=youtu.be
I noticed that if I change the selection somehow after running my operator I stop having the Inset issue, so I'm assuming my script is missing some command to fully apply the changes it makes to the mesh or something.
After running the script I call the operator from the F3 menu. Steps to reproduce:
1- Select grid of quad faces.
2- Use F3 to call the Operator after registering it.
3- Press I to inset and move the mouse to give the inset any amount.
4- Without leaving the tool, activate Individual on the inset options or viceversa (changing other options has the same effect).
5- Mesh reverts back.
Here's my operator:
import bpy
import bmesh
def main(context):
#context = bpy.context
ob = context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)
# Store the faces, the edges and the edge border of our current selection.
faces = set(f for f in bm.faces if f.select)
originalEdges = set(e for e in bm.edges if e.select)
borderEdges = set(e for e in originalEdges
if (e.is_boundary or not all(f.select for f in e.link_faces)))
# Poke the faces and select all of them minus the outer border of triangles.
ret = bmesh.ops.poke(bm, faces=list(faces))
for f in ret['faces']:
f.select = not bool(set(f.edges).intersection(borderEdges))
# Dissolve the original edges (minus the border) so we end up with a diamond pattern.
deleteEdges = originalEdges.difference(borderEdges)
diamondEdges = set(e for e in bm.edges if e.select).difference(deleteEdges)
bmesh.ops.dissolve_edges(bm, edges=list(deleteEdges))
bpy.ops.mesh.select_all(action='DESELECT')
# Select the Edges that form the Diamond Pattern
for e in diamondEdges:
e.select = True
# Easy way to convert our newly selected edges into faces
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
bmesh.update_edit_mesh(me)
class VitalyPoke(bpy.types.Operator):
"""
Description:
Uses the Poke operator and some caveman code to convert a selection of quads into diamond-looking faces
"""
bl_idname = "arc.vitaly_poke"
bl_label = "Vitaly Poke (ARC)"
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
main(context)
return {'FINISHED'}
def register():
bpy.utils.register_class(VitalyPoke)
def unregister():
bpy.utils.unregister_class(VitalyPoke)
if __name__ == "__main__":
register()
context = bpy.context
can be removed if used as above $\endgroup$