I have several faces on the same plane, there is always a largest face and several smaller faces "inside" the larger one.
I've currently got all the faces stored in a list and sorted so the largest is always the the first index of the list faces[0]
to make it easier to know which face to cut from and the rest to use as cutters. This also needs to be as fast as possible as there could be hundreds of faces in an interactive modal being updated on-the-fly with 'MOUSEMOVE'
The code below creates the mesh on the left, I'd like to remove sections from the largest face using the smaller faces as cutters while keeping everything in bmesh so it ends up something like the mesh on the right:
I have looked at all the bmesh.ops
but have no idea which one would do the job, if any at all. I'm generally "okay" with bmesh, but I've never encountered a problem like this before.
Even some pointers on what direction to take would be appreciated.
A side question, anyone know what happened to batFINGER? That dude knew precisely everything :)
import bpy
import bmesh
verts = [(5.88470458984375, 1.1705703735351562, 0.000396728515625), (3.3334121704101562, 4.9888458251953125, 0.000396728515625), (-4.242645263671875, -4.24261474609375, 0.000396728515625), (5.884712219238281, -1.1705093383789062, 0.000396728515625), (-4.242645263671875, 4.242668151855469, 0.000396728515625), (12.054519653320312, 15.040176391601562, 0.000396728515625), (12.767379760742188, 7.8024444580078125, 0.000396728515625), (8.153594970703125, 13.424354553222656, 0.000396728515625), (11.313179016113281, 15.113189697265625, 0.000396728515625), (13.424346923828125, 8.153602600097656, 0.000396728515625), (7.802436828613281, 12.767387390136719, 0.000396728515625), (14.00018310546875, 8.626182556152344, 0.000396728515625), (7.5861968994140625, 12.054534912109375, 0.000396728515625), (14.472763061523438, 9.2020263671875, 0.000396728515625), (7.51318359375, 11.313186645507812, 0.000396728515625), (14.823921203613281, 9.858993530273438, 0.000396728515625), (7.5861968994140625, 10.571846008300781, 0.000396728515625), (15.0401611328125, 10.571846008300781, 0.000396728515625), (7.802436828613281, 9.858993530273438, 0.000396728515625), (15.113174438476562, 11.313194274902344, 0.000396728515625), (8.153594970703125, 9.2020263671875, 0.000396728515625), (15.0401611328125, 12.054534912109375, 0.000396728515625), (8.626174926757812, 8.626182556152344, 0.000396728515625), (14.823921203613281, 12.767387390136719, 0.000396728515625), (9.202011108398438, 8.153602600097656, 0.000396728515625), (14.472763061523438, 13.424362182617188, 0.000396728515625), (9.858978271484375, 7.8024444580078125, 0.000396728515625), (10.57183837890625, 15.040176391601562, 0.000396728515625), (14.00018310546875, 14.000198364257812, 0.000396728515625), (10.57183837890625, 7.586204528808594, 0.000396728515625), (9.858978271484375, 14.823928833007812, 0.000396728515625), (13.424346923828125, 14.4727783203125, 0.000396728515625), (11.313179016113281, 7.513191223144531, 0.000396728515625), (9.202011108398438, 14.472770690917969, 0.000396728515625), (-5.884712219238281, 1.1705703735351562, 0.000396728515625), (-3.814697265625e-06, 6.000022888183594, 0.000396728515625), (-5.543281555175781, 2.2961273193359375, 0.000396728515625), (-10.57180404663086, 15.040168762207031, 0.000396728515625), (1.1705398559570312, -5.8846893310546875, 0.000396728515625), (-9.858940124511719, 7.8024444580078125, 0.000396728515625), (-14.472724914550781, 13.424354553222656, 0.000396728515625), (-11.313140869140625, 15.113182067871094, 0.000396728515625), (-9.201972961425781, 8.153602600097656, 0.000396728515625), (-14.823883056640625, 12.767379760742188, 0.000396728515625), (-8.62613296508789, 8.626182556152344, 0.000396728515625), (-15.04012680053711, 12.054527282714844, 0.000396728515625), (-8.153556823730469, 9.202018737792969, 0.000396728515625), (-15.113143920898438, 11.313186645507812, 0.000396728515625), (-7.802398681640625, 9.858993530273438, 0.000396728515625), (-15.04012680053711, 10.57183837890625, 0.000396728515625), (-7.586158752441406, 10.571846008300781, 0.000396728515625), (-14.823883056640625, 9.858985900878906, 0.000396728515625), (-7.513141632080078, 11.313186645507812, 0.000396728515625), (-14.472724914550781, 9.202018737792969, 0.000396728515625), (-7.586158752441406, 12.054534912109375, 0.000396728515625), (-14.000144958496094, 8.626174926757812, 0.000396728515625), (-7.802398681640625, 12.767387390136719, 0.000396728515625), (-13.424308776855469, 8.153602600097656, 0.000396728515625), (-8.153556823730469, 13.424354553222656, 0.000396728515625), (-12.767337799072266, 7.8024444580078125, 0.000396728515625), (-12.054485321044922, 15.040168762207031, 0.000396728515625), (-8.626136779785156, 14.000190734863281, 0.000396728515625), (-12.054481506347656, 7.586204528808594, 0.000396728515625), (-12.767337799072266, 14.823928833007812, 0.000396728515625), (-9.201980590820312, 14.472770690917969, 0.000396728515625), (-11.313140869140625, 7.51318359375, 0.000396728515625), (-13.424308776855469, 14.472770690917969, 0.000396728515625), (0.0, -5.999977111816406, 0.000396728515625), (6.0, 3.0517578125e-05, 0.000396728515625), (-10.571807861328125, -7.586158752441406, 0.000396728515625), (-9.85894775390625, -14.823883056640625, 0.000396728515625), (-14.472732543945312, -9.201972961425781, 0.000396728515625), (-11.31314468383789, -7.513145446777344, 0.000396728515625), (-9.201976776123047, -14.472724914550781, 0.000396728515625), (-14.82388687133789, -9.85894775390625, 0.000396728515625), (-8.626136779785156, -14.000144958496094, 0.000396728515625), (-15.040130615234375, -10.571800231933594, 0.000396728515625), (-8.153556823730469, -13.424308776855469, 0.000396728515625), (-15.113143920898438, -11.313140869140625, 0.000396728515625), (-7.802402496337891, -12.767333984375, 0.000396728515625), (-15.040130615234375, -12.054489135742188, 0.000396728515625), (-7.586158752441406, -12.054481506347656, 0.000396728515625), (-14.82388687133789, -12.767341613769531, 0.000396728515625), (-7.513145446777344, -11.313140869140625, 0.000396728515625), (-14.472732543945312, -13.424308776855469, 0.000396728515625), (-7.586162567138672, -10.571792602539062, 0.000396728515625), (-14.000152587890625, -14.000152587890625, 0.000396728515625), (-7.802406311035156, -9.858940124511719, 0.000396728515625), (-13.424312591552734, -14.472724914550781, 0.000396728515625), (-8.153564453125, -9.201972961425781, 0.000396728515625), (-12.767341613769531, -14.823883056640625, 0.000396728515625), (-12.054489135742188, -7.586158752441406, 0.000396728515625), (-8.626144409179688, -8.626136779785156, 0.000396728515625), (-12.054489135742188, -15.040130615234375, 0.000396728515625), (-12.767341613769531, -7.802398681640625, 0.000396728515625), (-9.201980590820312, -8.153556823730469, 0.000396728515625), (-11.31314468383789, -15.113143920898438, 0.000396728515625), (-13.424312591552734, -8.153556823730469, 0.000396728515625), (4.2426300048828125, 4.242668151855469, 0.000396728515625), (-3.333423614501953, -4.988792419433594, 0.000396728515625), (2.2960968017578125, -5.543251037597656, 0.000396728515625), (-3.333423614501953, 4.9888458251953125, 0.000396728515625), (12.054519653320312, -7.586158752441406, 0.000396728515625), (12.767379760742188, -14.823883056640625, 0.000396728515625), (8.153594970703125, -9.201972961425781, 0.000396728515625), (11.313179016113281, -7.513145446777344, 0.000396728515625), (13.424346923828125, -14.472724914550781, 0.000396728515625), (7.802436828613281, -9.85894775390625, 0.000396728515625), (14.00018310546875, -14.000144958496094, 0.000396728515625), (7.5861968994140625, -10.571800231933594, 0.000396728515625), (14.472763061523438, -13.424308776855469, 0.000396728515625), (7.51318359375, -11.313140869140625, 0.000396728515625), (14.823921203613281, -12.767333984375, 0.000396728515625), (7.5861968994140625, -12.054489135742188, 0.000396728515625), (15.0401611328125, -12.054481506347656, 0.000396728515625), (7.802436828613281, -12.767341613769531, 0.000396728515625), (15.113174438476562, -11.313140869140625, 0.000396728515625), (8.153594970703125, -13.424308776855469, 0.000396728515625), (15.0401611328125, -10.571792602539062, 0.000396728515625), (8.626174926757812, -14.000152587890625, 0.000396728515625), (14.823921203613281, -9.858940124511719, 0.000396728515625), (9.202011108398438, -14.472724914550781, 0.000396728515625), (14.472763061523438, -9.201972961425781, 0.000396728515625), (9.858978271484375, -14.823883056640625, 0.000396728515625), (10.57183837890625, -7.586158752441406, 0.000396728515625), (14.00018310546875, -8.626136779785156, 0.000396728515625), (10.57183837890625, -15.040130615234375, 0.000396728515625), (9.858978271484375, -7.802398681640625, 0.000396728515625), (13.424339294433594, -8.153556823730469, 0.000396728515625), (11.313179016113281, -15.113143920898438, 0.000396728515625), (9.202011108398438, -8.153556823730469, 0.000396728515625), (12.767372131347656, 14.823936462402344, 0.000396728515625), (12.054519653320312, 7.586204528808594, 0.000396728515625), (8.626174926757812, 14.000198364257812, 0.000396728515625), (-1.1705436706542969, -5.8846893310546875, 0.000396728515625), (4.242645263671875, -4.24261474609375, 0.000396728515625), (-9.85894775390625, 14.823928833007812, 0.000396728515625), (-10.571796417236328, 7.586204528808594, 0.000396728515625), (-14.000144958496094, 14.000190734863281, 0.000396728515625), (-6.000003814697266, 2.288818359375e-05, 0.000396728515625), (-4.988822937011719, -3.3333969116210938, 0.000396728515625), (-4.988822937011719, 3.3334503173828125, 0.000396728515625), (4.9888153076171875, -3.3333892822265625, 0.000396728515625), (-9.858955383300781, -7.802398681640625, 0.000396728515625), (-2.2961044311523438, -5.543251037597656, 0.000396728515625), (-10.571800231933594, -15.040130615234375, 0.000396728515625), (-14.000152587890625, -8.626136779785156, 0.000396728515625), (4.9888153076171875, 3.3334503173828125, 0.000396728515625), (-1.1705474853515625, 5.884735107421875, 0.000396728515625), (1.1705322265625, 5.884735107421875, 0.000396728515625), (3.3334197998046875, -4.988792419433594, 0.000396728515625), (-5.543281555175781, -2.2960739135742188, 0.000396728515625), (5.54327392578125, 2.2961349487304688, 0.000396728515625), (-2.2961044311523438, 5.543304443359375, 0.000396728515625), (12.767372131347656, -7.802398681640625, 0.000396728515625), (12.054519653320312, -15.040130615234375, 0.000396728515625), (8.626174926757812, -8.626136779785156, 0.000396728515625), (5.54327392578125, -2.2960739135742188, 0.000396728515625), (2.2960891723632812, 5.543304443359375, 0.000396728515625), (-5.884712219238281, -1.1705169677734375, 0.000396728515625), (13.488861083984375, 16.000022888183594, 0.000396728515625), (16.000015258789062, 13.488868713378906, 0.000396728515625), (13.488861083984375, -15.999977111816406, 0.000396728515625), (16.000015258789062, -13.488815307617188, 0.000396728515625), (-13.48883056640625, -15.999977111816406, 0.000396728515625), (-15.999984741210938, -13.488815307617188, 0.000396728515625), (-13.48883056640625, 16.000022888183594, 0.000396728515625), (-15.999984741210938, 13.488868713378906, 0.000396728515625)]
faces = [[97, 94, 91, 72, 69, 143, 95, 92, 89, 87, 85, 83, 81, 79, 77, 75, 73, 70, 145, 96, 93, 90, 88, 86, 84, 82, 80, 78, 76, 74, 71, 146], [33, 30, 27, 8, 5, 131, 31, 28, 25, 23, 21, 19, 17, 15, 13, 11, 9, 6, 132, 32, 29, 26, 24, 22, 20, 18, 16, 14, 12, 10, 7, 133], [166, 167, 165, 164, 162, 163, 161, 160], [159, 139, 34, 36, 141, 4, 101, 153, 148, 35, 149, 158, 1, 98, 147, 152, 0, 68, 3, 157, 142, 135, 150, 100, 38, 67, 134, 144, 99, 2, 140, 151], [66, 63, 60, 41, 37, 136, 64, 61, 58, 56, 54, 52, 50, 48, 46, 44, 42, 39, 137, 65, 62, 59, 57, 55, 53, 51, 49, 47, 45, 43, 40, 138], [130, 127, 124, 105, 102, 154, 128, 125, 122, 120, 118, 116, 114, 112, 110, 108, 106, 103, 155, 129, 126, 123, 121, 119, 117, 115, 113, 111, 109, 107, 104, 156]]
edges = []
mesh = bpy.data.meshes.new('test_mesh')
mesh.from_pydata(verts, edges, faces)
obj = bpy.data.objects.new('test_obj', mesh)
bpy.data.collections['Defaults'].objects.link(obj)
bpy.context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT')
me = obj.data
bm = bmesh.from_edit_mesh(me)
def get_area(elem):
return elem.calc_area()
faces = []
for face in bm.faces:
faces.append(face)
faces.sort(key=get_area, reverse=True)
# ?? what bmesh operators to use here to cut small faces out of large face ??
bmesh.update_edit_mesh