File size: 2,066 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
import json, os, sys, yaml
from shapely.geometry import box, Point, MultiLineString, LineString, mapping
from shapely.ops import unary_union
from shapely import affinity
S = sys.argv[1]; seeds = sys.argv[2:]
g1 = yaml.safe_load(open(S + "/engine/source/configs/robots/task_constraints_v1.yaml"))["robots"]["g1"]
r = max(g1["body_width_m"], g1["body_depth_m"]) / 2 + g1["depth_model"]["body_edge_clearance_m"]
W = json.load(open("walls_all.json")); out = {}
def fp(e):
    w, d = e["dimensions_m"][:2]; cx, cy = e.get("actual_center_xy_m") or e["center_xy_m"]
    return affinity.rotate(box(cx - w / 2, cy - d / 2, cx + w / 2, cy + d / 2), e.get("yaw_deg", 0.0), origin=(cx, cy))
for seed in seeds:
    info = W[seed]; sm = json.load(open(os.path.dirname(info["blend"]) + "/SceneManifest.v16.json"))
    walls = MultiLineString(info["segments"]).buffer(0.02)
    portals = [LineString(p["opening_segment_xy_m"]).buffer(0.45, cap_style=2) for p in sm["portals"] if p.get("opening_segment_xy_m")]
    house = unary_union([box(*x["bounds_m"]) for x in sm["rooms"]] + portals).difference(walls)
    fe = [e for e in sm["entities"] if not (e.get("supported_by_entity_id") or e.get("support_entity_id")) and e.get("role") not in ("rug", "floor_cover")]
    free = house.buffer(-r).difference(unary_union([fp(e) for e in fe]).buffer(r)); comps = list(getattr(free, "geoms", [free]))
    entry = next(p for p in sm["portals"] if "entry" in p["portal_id"]); (x0, y0), (x1, y1) = entry["opening_segment_xy_m"]; mid = Point((x0 + x1) / 2, (y0 + y1) / 2)
    ei = min(range(len(comps)), key=lambda i: comps[i].distance(mid))
    out[seed] = {"rooms": [(x["room_id"], x["bounds_m"]) for x in sm["rooms"]], "walls": mapping(walls), "furniture": [(e["entity_id"], mapping(fp(e))) for e in fe],
                 "comps": [mapping(c) for c in comps], "entry_comp": ei, "entry": entry["opening_segment_xy_m"],
                 "doors": [p["opening_segment_xy_m"] for p in sm["portals"] if p.get("opening_segment_xy_m")]}
json.dump(out, open("plan2d.json", "w"))
print("ok", list(out))