File size: 1,481 Bytes
870b85a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import bpy, bmesh, json, sys
args = sys.argv[sys.argv.index("--") + 1:]; scenes = json.load(open(args[0])); out = {}
def label_of(o):
    cur = o
    while cur is not None:
        ks = cur.keys()
        if "structural_object_id" in ks: return "structure:" + str(cur["structural_object_id"])
        if "portal_id" in ks: return "portal:" + str(cur["portal_id"])
        cur = cur.parent
    return None
for s in scenes:
    blend = [b for b in s["blends"] if "/generated/" in b][-1]
    bpy.ops.wm.open_mainfile(filepath=blend, load_ui=False)
    dg = bpy.context.evaluated_depsgraph_get(); segs = []; nw = 0
    for o in bpy.context.scene.objects:
        if o.type != "MESH": continue
        lab = label_of(o)
        if not lab or not lab.startswith("structure:wall"): continue
        nw += 1; oe = o.evaluated_get(dg); me = oe.to_mesh()
        bm = bmesh.new(); bm.from_mesh(me); bm.transform(o.matrix_world)
        res = bmesh.ops.bisect_plane(bm, geom=bm.verts[:] + bm.edges[:] + bm.faces[:], plane_co=(0, 0, 0.5), plane_no=(0, 0, 1))
        for e in res["geom_cut"]:
            if isinstance(e, bmesh.types.BMEdge):
                a, b = e.verts[0].co, e.verts[1].co; segs.append([[round(a.x, 4), round(a.y, 4)], [round(b.x, 4), round(b.y, 4)]])
        bm.free(); oe.to_mesh_clear()
    out[s["seed"]] = {"blend": blend, "wall_objects": nw, "segments": segs}
    print("scene", s["seed"], "walls", nw, "cut segments", len(segs))
json.dump(out, open(args[1], "w"))