Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import bpy
  2. import bmesh
  3.  
  4. def main(context):
  5.  
  6. context = bpy.context
  7. ob = context.edit_object
  8. me = ob.data
  9. bm = bmesh.from_edit_mesh(me)
  10.  
  11. bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='EDGE')
  12.  
  13. originalEdges = set(e for e in bm.edges if e.select)
  14.  
  15. bpy.ops.mesh.poke()
  16.  
  17. allEdges = set(e for e in bm.edges if e.select)
  18.  
  19. bpy.ops.mesh.region_to_loop()
  20.  
  21. borderEdges = set(e for e in bm.edges if e.select)
  22.  
  23. diamondEdges = allEdges - originalEdges - borderEdges
  24.  
  25. originalWithoutBorder = originalEdges - borderEdges
  26.  
  27. bpy.ops.mesh.select_all(action='DESELECT')
  28.  
  29. for e in originalWithoutBorder:
  30. e.select = True
  31.  
  32. bpy.ops.mesh.dissolve_mode(use_verts=True)
  33.  
  34. for e in diamondEdges:
  35. e.select = True
  36.  
  37. bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='VERT')
  38. bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
  39.  
  40. newFaces = set(f for f in bm.faces if f.select)
  41. bpy.ops.mesh.select_face_by_sides(number=3, type='EQUAL', extend=False)
  42. triangleFaces = set(f for f in bm.faces if f.select)
  43.  
  44. newFaces = newFaces - triangleFaces
  45. bpy.ops.mesh.select_all(action='DESELECT')
  46. for f in newFaces:
  47. f.select = True
  48.  
  49. bmesh.update_edit_mesh(me)
  50.  
  51. class VitalyPoke(bpy.types.Operator):
  52.  
  53. """
  54.  
  55. [Vitaly Poke]
  56.  
  57. Description:
  58. Uses the Poke operator and some caveman code to convert a selection of quads into diamond-looking faces
  59.  
  60. """
  61.  
  62. bl_idname = "arc.vitaly_poke"
  63. bl_label = "Vitaly Poke (ARC)"
  64.  
  65. @classmethod
  66. def poll(cls, context):
  67. return context.active_object is not None
  68.  
  69. def execute(self, context):
  70. main(context)
  71. return {'FINISHED'}
  72.  
  73. def register():
  74. bpy.utils.register_class(VitalyPoke)
  75.  
  76. def unregister():
  77. bpy.utils.unregister_class(VitalyPoke)
  78.  
  79. if __name__ == "__main__":
  80. register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement