SHARE
TWEET

Untitled

a guest Jun 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import bpy
  2. import bmesh
  3. from mathutils import Vector
  4. from mathutils.bvhtree import BVHTree
  5.  
  6. remove_originals = True
  7. remove_doubles = True
  8.  
  9. context = bpy.context
  10. scene = context.scene
  11. # by selection
  12. cubes = context.selected_objects
  13. # by name
  14. #cubes = [o for o in scene.objects if o.name.startswith("Cube")]
  15.  
  16. bm = bmesh.new()
  17. for o in cubes:
  18.     bm.from_mesh(o.data)
  19.     bmesh.ops.transform(bm,
  20.             verts=bm.verts[-8:],
  21.             matrix=o.matrix_world
  22.             )
  23. if remove_originals:
  24.     bpy.ops.object.delete()
  25.  
  26. bvhtree = BVHTree().FromBMesh(bm, epsilon=1e-7)
  27. faces = bm.faces[:]
  28.  
  29. remove = list()
  30. while faces:        
  31.     f = faces.pop()        
  32.     pair = bvhtree.find_nearest_range(f.calc_center_median(), 1e-4)
  33.     if len(pair) > 2:
  34.         # mark face for removal
  35.         remove.extend(p[2] for p in pair)
  36.  
  37. bm.faces.ensure_lookup_table()
  38. bmesh.ops.delete(bm,
  39.         geom=[bm.faces[i] for i in set(remove)],
  40.         context='FACES_KEEP_BOUNDARY',
  41.         )
  42. if remove_doubles:
  43.     bmesh.ops.remove_doubles(bm,
  44.             verts=bm.verts,
  45.             dist=1e-7)
  46.  
  47. me = bpy.data.meshes.new("CubeBoundaryFaces")
  48. bm.to_mesh(me)
  49. ob = bpy.data.objects.new("CubeBoundaryFaces", me)
  50.  
  51. scene.collection.objects.link(ob)
  52. context.view_layer.objects.active = ob
  53. ob.select_set(True)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top