File size: 64,053 Bytes
d72771b
 
 
 
 
85e0fe1
 
 
 
 
d72771b
 
 
 
 
 
 
 
 
85e0fe1
d72771b
 
 
 
 
 
 
 
 
 
 
 
ef0afec
 
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85e0fe1
d72771b
 
85e0fe1
 
 
c36e12e
85e0fe1
 
c36e12e
 
85e0fe1
 
 
 
 
 
 
 
 
 
c36e12e
85e0fe1
 
 
 
 
d72771b
 
 
 
 
 
 
 
 
 
85e0fe1
d72771b
 
 
85e0fe1
 
 
 
d72771b
 
 
 
85e0fe1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85e0fe1
d72771b
 
 
 
 
 
 
 
 
 
60f575d
85e0fe1
 
d9a54f4
 
 
 
 
 
 
85e0fe1
d72771b
 
 
d9a54f4
 
 
 
 
d72771b
d9a54f4
d72771b
 
 
85e0fe1
d72771b
d9a54f4
 
d72771b
d9a54f4
 
 
 
 
 
 
 
d72771b
d9a54f4
 
 
 
d72771b
d9a54f4
d72771b
d9a54f4
 
 
 
 
 
d72771b
 
 
 
675b16f
 
 
 
d72771b
 
 
675b16f
 
 
 
 
d72771b
 
 
 
 
 
675b16f
d72771b
 
 
 
d9a54f4
 
d72771b
85e0fe1
 
 
 
d72771b
85e0fe1
 
d9a54f4
60f575d
 
 
85e0fe1
60f575d
85e0fe1
d72771b
d9a54f4
 
d72771b
d9a54f4
d72771b
d9a54f4
 
d72771b
d9a54f4
 
d72771b
60f575d
 
 
 
d72771b
d9a54f4
d72771b
60f575d
 
 
 
 
d72771b
d9a54f4
d72771b
60f575d
d72771b
d9a54f4
60f575d
d72771b
60f575d
d9a54f4
 
 
 
 
ef0afec
 
 
 
 
 
 
 
 
 
d9a54f4
60f575d
 
 
d72771b
85e0fe1
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85e0fe1
 
 
 
d72771b
 
 
 
 
 
 
85e0fe1
 
 
 
 
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85e0fe1
 
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60f575d
 
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85e0fe1
 
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85e0fe1
 
 
60f575d
85e0fe1
 
 
 
ef0afec
675b16f
 
ef0afec
85e0fe1
 
 
 
d9a54f4
85e0fe1
 
ef0afec
85e0fe1
 
 
 
d9a54f4
85e0fe1
d9a54f4
ef0afec
85e0fe1
 
 
d9a54f4
85e0fe1
 
 
ef0afec
 
 
 
 
85e0fe1
ef0afec
85e0fe1
 
 
d9a54f4
675b16f
 
 
 
ef0afec
85e0fe1
ef0afec
 
85e0fe1
ef0afec
85e0fe1
 
ef0afec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60f575d
85e0fe1
d72771b
 
 
 
 
 
 
 
 
 
 
 
60f575d
 
d72771b
 
 
 
85e0fe1
 
 
 
 
 
 
 
 
 
60f575d
 
 
 
 
 
 
85e0fe1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60f575d
85e0fe1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c36e12e
 
 
 
85e0fe1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85e0fe1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
85e0fe1
d72771b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef0afec
d72771b
ef0afec
 
 
 
d72771b
 
 
e0daa77
d72771b
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
"""Write the kitchen environment, assets/environments/kitchen/scene.xml, from MuJoCo primitives.

usage: python tools/make_kitchen.py

A kitchen and dining room in the spirit of RoboCasa, without its assets: a counter run with drawers,
cabinet doors, an oven, a cooktop and a sink; a fridge whose door and an island whose drawers open by
bar pulls an arm grasps from above (src/robots/fixtures.js); an island at the tabletop scene's table
height (0.82 m, so the pick policy trained there works here) with a prep sink; a trash can; a sideboard
with a radio and a microwave; a dining table and a sofa corner; what makes it lived in (details()); and
small objects to pick.

Sites (invisible) mark the regions household tasks talk about (src/tasks/): `surface_*` the tops things
stand on, `container_*` the volumes things go in, `zone_*` the parts of surfaces the arms reach, where a
task's objects are put at the start.
The header (defaults, floor friction) matches MuJoCo-GS-Web's environments, so XLeRobot handles the same.
The robot is spawned by its own XML at the origin facing -x; the island is in front of it.
Material names are what the page's lit renderer gives textures to (src/render/materials.js).
"""

import math
from pathlib import Path

import objects as objects_  # tools/objects.py

OUT = Path(__file__).resolve().parents[1] / "assets" / "environments" / "kitchen" / "scene.xml"

COUNTER_TOP = 0.90  # counter run
ISLAND_TOP = 0.82  # same as MuJoCo-GS-Web's tabletop tables
WALL_H = 2.6

lines: list[str] = []
excludes: list[tuple[str, str]] = []  # body pairs that do not collide
pairs: list[str] = []  # explicit contact pairs (<pair .../>): the doors' magnets
equalities: list[str] = []  # equality constraints: the microwave's door release


def f(*v: float) -> str:
    return " ".join(f"{x:.4g}" for x in v)


def box(name: str | None, pos, size, material: str, collide: bool = True, extra: str = "") -> str:
    n = f' name="{name}"' if name else ""
    # The robot's XML, included first, sets contype/conaffinity 0 in the main default class, so every
    # environment geom says explicitly whether it collides (as MuJoCo-GS-Web's environments do).
    c = ' contype="1" conaffinity="1"' if collide else ' contype="0" conaffinity="0"'
    return f'<geom{n} type="box" pos="{f(*pos)}" size="{f(*size)}" material="{material}"{c}{extra}/>'


def site(name: str, pos, size) -> str:
    """A box site marking a region for the tasks: not drawn, no collisions."""
    return f'<site name="{name}" type="box" pos="{f(*pos)}" size="{f(*size)}" group="5" rgba="0 0 0 0"/>'


def region(name: str, x0: float, x1: float, y0: float, y1: float, z0: float, z1: float) -> str:
    return site(name, ((x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2), ((x1 - x0) / 2, (y1 - y0) / 2, (z1 - z0) / 2))


def static(name: str, geoms: list[str], pos=(0, 0, 0)) -> None:
    lines.append(f'    <body name="{name}" pos="{f(*pos)}">')
    lines.extend(f"      {g}" for g in geoms)
    lines.append("    </body>")


def vis(kind: str, material: str, rgba: str | None = None, **attrs) -> str:
    """A geom that is only seen: no collisions, and no mass (on a door or a drawer it would add some)."""
    a = " ".join(f'{k}="{v}"' for k, v in attrs.items())
    c = f' rgba="{rgba}"' if rgba else ""
    return f'<geom type="{kind}" {a} material="{material}"{c} density="0" contype="0" conaffinity="0"/>'


def bar_handle(name: str, at, axis: str, normal: str, out: int, length: float, radius: float = 0.01, stand: float = 0.04, inset: float = 0.025) -> list[str]:
    """A bar pull for a drawer or a door: a steel bar `length` long along `axis` ("x", "y" or "z"), its
    middle in front of the point `at` on the face it is fixed to, which looks along `normal` (`out` +1 or
    -1: the side the bar is on). `stand` is the room between bar and face, for a finger behind it; the
    posts that hold it are `inset` in from its ends."""
    n, a = "xyz".index(normal), "xyz".index(axis)
    gap = stand + radius  # bar centre off the face
    c = list(at)
    c[n] += out * gap
    p, q = list(c), list(c)
    p[a] -= length / 2
    q[a] += length / 2
    geoms = [f'<geom name="{name}" type="capsule" fromto="{f(*p, *q)}" size="{radius}" material="steel" mass="0.1" contype="1" conaffinity="1"/>']
    for s in (-1, 1):
        post = list(at)
        post[a] += s * (length / 2 - inset)
        post[n] += out * gap / 2
        size = [0.006, 0.006, 0.006]
        size[n] = gap / 2
        geoms.append(f'<geom type="box" pos="{f(*post)}" size="{f(*size)}" material="steel" mass="0.02" contype="1" conaffinity="1"/>')
    return geoms


def door(name: str, front: float, ya: float, yb: float, z_lo: float, z_hi: float, hinge: str) -> None:
    """A cabinet door on the counter front from y = ya to yb, hinged on its left (ya) or right (yb) edge
    as seen from the room, opening outward; its handle is near the other edge, at the top."""
    w = (yb - ya) / 2 - 0.003
    dh = (z_hi - z_lo) / 2
    left = hinge == "left"
    s = 1 if left else -1  # the door extends this way in y from its hinge
    hy = s * (2 * w - 0.05)
    panel = box(None, (0, s * w, 0), (0.012, w, dh), "cabinet_door", extra=' mass="2"')
    lines[len(lines):] = [
        f'    <body name="{name}" pos="{f(front + 0.012, ya + 0.003 if left else yb - 0.003, (z_lo + z_hi) / 2)}">',
        f'      <joint name="{name}_hinge" type="hinge" axis="0 0 {-1 if left else 1}" range="0 1.9" damping="1.5" frictionloss="0.2" armature="0.05"/>',
        f"      {panel}",
        f'      <geom name="{name}_handle" type="capsule" fromto="{f(0.045, hy, dh - 0.25, 0.045, hy, dh - 0.07)}" size="0.01" material="steel" mass="0.1" contype="1" conaffinity="1"/>',
        f'      <geom type="box" pos="{f(0.028, hy, dh - 0.23)}" size="0.017 0.006 0.006" material="steel" mass="0.02" contype="1" conaffinity="1"/>',
        f'      <geom type="box" pos="{f(0.028, hy, dh - 0.09)}" size="0.017 0.006 0.006" material="steel" mass="0.02" contype="1" conaffinity="1"/>',
        "    </body>",
    ]


def drawer(name: str, fx: float, fy: float, z_lo: float, z_hi: float, yaw: float, width: float, depth: float, stand: float = 0.04) -> None:
    """A drawer with its front's outer face centred on (fx, fy), from z_lo to z_hi, sliding out up to 40 cm
    the way the front faces (world yaw `yaw`); `width` across its front, `depth` from front to back. A
    bar pull on the front's upper part (`stand` off it: under a worktop that overhangs the front, more, so a
    finger coming down behind the bar clears the worktop's edge), and a site `container_<name>` for its
    inside, which moves with it."""
    hx, hy, dh = depth / 2, width / 2, (z_hi - z_lo) / 2
    c, s = math.cos(yaw), math.sin(yaw)
    out = hx + 0.024  # the front's outer face, from the body's origin along the slide
    turn = f' quat="{f(math.cos(yaw / 2), 0, 0, math.sin(yaw / 2))}"' if yaw else ""
    geoms = [
        box(None, (hx + 0.012, 0, 0), (0.012, hy + 0.015, dh), "cabinet_door", extra=' mass="1"'),
        box(None, (0, 0, -dh + 0.008), (hx, hy, 0.006), "cabinet", extra=' mass="0.6"'),
        # sides and back nearly as high as the front, so what is let go into it stays in
        box(None, (0, hy - 0.006, -0.015), (hx, 0.006, dh - 0.03), "cabinet", extra=' mass="0.3"'),
        box(None, (0, -hy + 0.006, -0.015), (hx, 0.006, dh - 0.03), "cabinet", extra=' mass="0.3"'),
        box(None, (-hx + 0.006, 0, -0.015), (0.006, hy, dh - 0.03), "cabinet", extra=' mass="0.3"'),
        *bar_handle(f"{name}_handle", (out, 0, dh - 0.05), "y", "x", 1, min(0.26, width - 0.14), stand=stand),
        # its inside, up to 3 cm over the sides (the containers' regions reach over their rims)
        site(f"container_{name}", (0, 0, 0.0145), (hx - 0.012, hy - 0.012, dh - 0.0145)),
    ]
    lines.append(f'    <body name="{name}" pos="{f(fx - c * out, fy - s * out, (z_lo + z_hi) / 2)}"{turn}>')
    lines.append(f'      <joint name="{name}_slide" type="slide" axis="1 0 0" range="0 0.4" damping="3" frictionloss="0.4" armature="0.05"/>')
    lines.extend(f"      {g}" for g in geoms)
    lines.append("    </body>")


def counter_run() -> None:
    """Base cabinets along the back wall (x = -3), worktop at COUNTER_TOP, drawers and doors facing +x."""
    depth, x0 = 0.6, -2.95  # cabinets from x0 to x0 + depth
    front = x0 + depth
    y0, y1 = -1.9, 1.3
    cx = x0 + depth / 2
    h = COUNTER_TOP - 0.04
    geoms = [
        box("worktop_left", (cx + 0.015, (y0 + -0.1) / 2, COUNTER_TOP - 0.02), (depth / 2 + 0.015, (-0.1 - y0) / 2, 0.02), "countertop"),
        box("worktop_right", (cx + 0.015, (0.9 + y1) / 2, COUNTER_TOP - 0.02), (depth / 2 + 0.015, (y1 - 0.9) / 2, 0.02), "countertop"),
        # around the sink cut-out (y -0.1 .. 0.9 minus the basin)
        box(None, (cx + 0.015 - 0.24, 0.4, COUNTER_TOP - 0.02), (0.075, 0.5, 0.02), "countertop"),
        box(None, (cx + 0.015 + 0.24, 0.4, COUNTER_TOP - 0.02), (0.075, 0.5, 0.02), "countertop"),
        box(None, (cx + 0.015, -0.03, COUNTER_TOP - 0.02), (0.165, 0.07, 0.02), "countertop"),
        box(None, (cx + 0.015, 0.83, COUNTER_TOP - 0.02), (0.165, 0.07, 0.02), "countertop"),
        box("plinth", (front - 0.05, (y0 + y1) / 2, 0.05), (0.03, (y1 - y0) / 2, 0.05), "plinth"),
        box("cabinet_back", (x0 + 0.01, (y0 + y1) / 2, h / 2), (0.01, (y1 - y0) / 2, h / 2), "cabinet"),
        box("cabinet_bottom", (cx, (y0 + y1) / 2, 0.105), (depth / 2 - 0.02, (y1 - y0) / 2, 0.005), "cabinet"),
    ]
    # Side panels between the bays: drawers, oven, door, sink (two doors), two doors.
    bays = [y0, -1.3, -0.7, -0.1, 0.5, y1]
    for k, y in enumerate(bays):
        geoms.append(box(None, (cx, y, (0.1 + h) / 2), (depth / 2 - 0.01, 0.009, (h - 0.1) / 2), "cabinet"))
    # Oven in the bay under the cooktop: a closed box with a window, a handle and knobs.
    oy, ow = -1.0, 0.294
    geoms += [
        box("oven", (front - 0.26, oy, (0.12 + h) / 2), (0.25, ow, (h - 0.12) / 2), "oven"),
        box(None, (front + 0.006, oy, (0.12 + h) / 2), (0.018, ow, (h - 0.12) / 2), "oven"),
        vis("box", "oven_glass", pos=f(front + 0.025, oy, 0.43), size=f(0.002, 0.22, 0.17)),
        vis("capsule", "steel", fromto=f(front + 0.06, oy - 0.2, 0.7, front + 0.06, oy + 0.2, 0.7), size="0.011"),
        vis("box", "steel", pos=f(front + 0.043, oy - 0.17, 0.7), size="0.02 0.006 0.006"),
        vis("box", "steel", pos=f(front + 0.043, oy + 0.17, 0.7), size="0.02 0.006 0.006"),
        *[vis("cylinder", "oven_knob", fromto=f(front + 0.024, oy + dy, 0.81, front + 0.044, oy + dy, 0.81), size="0.017") for dy in (-0.2, -0.1, 0.1, 0.2)],
    ]
    # Sink basin under the cut-out, y -0.1 .. 0.9 inner 0.33 x 0.86.
    sink_x, sink_y = cx + 0.015, 0.4
    basin_d = 0.18
    zb = COUNTER_TOP - basin_d
    geoms += [
        box("sink_bottom", (sink_x, sink_y, zb), (0.165, 0.43, 0.005), "steel"),
        box(None, (sink_x - 0.16, sink_y, zb + basin_d / 2), (0.005, 0.43, basin_d / 2), "steel"),
        box(None, (sink_x + 0.16, sink_y, zb + basin_d / 2), (0.005, 0.43, basin_d / 2), "steel"),
        box(None, (sink_x, sink_y - 0.425, zb + basin_d / 2), (0.165, 0.005, basin_d / 2), "steel"),
        box(None, (sink_x, sink_y + 0.425, zb + basin_d / 2), (0.165, 0.005, basin_d / 2), "steel"),
        # tap
        f'<geom type="cylinder" pos="{f(x0 + 0.08, sink_y, COUNTER_TOP + 0.15)}" size="0.015 0.15" material="steel" contype="0" conaffinity="0"/>',
        f'<geom type="capsule" fromto="{f(x0 + 0.08, sink_y, COUNTER_TOP + 0.3, x0 + 0.24, sink_y, COUNTER_TOP + 0.3)}" size="0.013" material="steel" contype="0" conaffinity="0"/>',
        # backsplash
        box("backsplash", (x0 + 0.005, (y0 + y1) / 2, COUNTER_TOP + 0.3), (0.005, (y1 - y0) / 2, 0.3), "tile", collide=False),
        # cooktop over the oven, with four burners
        box("cooktop", (cx + 0.015, oy, COUNTER_TOP + 0.003), (0.26, 0.28, 0.004), "glass", collide=False),
        *[vis("cylinder", "burner", pos=f(cx + 0.015 + dx, oy + dy, COUNTER_TOP + 0.0075), size=f(r, 0.0005)) for dx, dy, r in [(-0.12, -0.13, 0.09), (-0.12, 0.13, 0.07), (0.12, -0.13, 0.07), (0.12, 0.13, 0.09)]],
    ]
    # Upper cabinets (out of reach), one door per bay at most 0.6 m wide; glass doors over the sink; a
    # range hood over the cooktop.
    uz0, uz1, ud = 1.49, 2.21, 0.36
    uzc, uh = (uz0 + uz1) / 2, (uz1 - uz0) / 2
    for ya, yb, n, glass in [(y0, -1.3, 1, False), (-0.7, -0.1, 1, False), (-0.1, 0.5, 2, True), (0.5, y1, 2, False)]:
        geoms.append(box(None, (x0 + ud / 2, (ya + yb) / 2, uzc), (ud / 2, (yb - ya) / 2 - 0.002, uh), "cabinet"))
        for k in range(n):
            da, db = ya + (yb - ya) * k / n + 0.003, ya + (yb - ya) * (k + 1) / n - 0.003
            dc, dw = (da + db) / 2, (db - da) / 2
            if glass:
                # a frame round a glass pane, with a shelf of plates behind it
                for py, pz, sy, sz in [(dc, uz0 + 0.03, dw, 0.03), (dc, uz1 - 0.03, dw, 0.03), (da + 0.03, uzc, 0.03, uh), (db - 0.03, uzc, 0.03, uh)]:
                    geoms.append(vis("box", "cabinet_door", pos=f(x0 + ud + 0.01, py, pz), size=f(0.01, sy, sz)))
                geoms.append(vis("box", "cabinet_glass", pos=f(x0 + ud + 0.006, dc, uzc), size=f(0.003, dw - 0.03, uh - 0.03)))
                geoms.append(vis("box", "cabinet", pos=f(x0 + ud / 2, dc, uzc - 0.02), size=f(ud / 2 - 0.02, dw, 0.008)))
                for j in range(5):  # a stack of plates on the shelf, and one of bowls below
                    geoms.append(vis("cylinder", "plate", pos=f(x0 + 0.18, dc, uzc - 0.006 + 0.012 * j), size="0.09 0.005"))
                for j in range(3):
                    geoms.append(vis("cylinder", "bowl", pos=f(x0 + 0.18, dc, uz0 + 0.04 + 0.03 * j), size=f(0.07 - 0.004 * j, 0.012)))
            else:
                geoms.append(vis("box", "cabinet_door", pos=f(x0 + ud + 0.01, dc, uzc), size=f(0.01, dw, uh - 0.004)))
            hand = db - 0.045 if (n == 1 or k == 0) else da + 0.045  # the edge that opens
            geoms.append(vis("capsule", "steel", fromto=f(x0 + ud + 0.035, hand, uz0 + 0.06, x0 + ud + 0.035, hand, uz0 + 0.2), size="0.008"))
    geoms += [
        region("surface_counter_left", x0, front + 0.015, y0, -0.1, COUNTER_TOP - 0.005, COUNTER_TOP + 0.005),
        region("surface_counter_right", x0, front + 0.015, 0.9, y1, COUNTER_TOP - 0.005, COUNTER_TOP + 0.005),
        region("container_counter_sink", sink_x - 0.155, sink_x + 0.155, sink_y - 0.42, sink_y + 0.42, zb + 0.005, COUNTER_TOP + 0.06),
        # Out of the way: where a task stores what it does not use (the back of the worktop, beyond reach).
        region("zone_storage_counter_a", x0 + 0.1, x0 + 0.33, -0.62, -0.18, COUNTER_TOP - 0.005, COUNTER_TOP + 0.005),
        region("zone_storage_counter_b", x0 + 0.1, x0 + 0.33, y0 + 0.06, -1.34, COUNTER_TOP - 0.005, COUNTER_TOP + 0.005),
        box("hood", (x0 + 0.25, oy, 1.66), (0.25, 0.3, 0.05), "hood"),
        vis("box", "hood", pos=f(x0 + 0.13, oy, 2.0), size="0.13 0.14 0.3"),
        vis("box", "oven_glass", pos=f(x0 + 0.42, oy, 1.606), size="0.06 0.22 0.004"),
    ]
    static("counter", geoms)

    # Drawers in the first bay (y0 .. y0+0.6), two high; doors in the next bays.
    for k, (z_lo, z_hi) in enumerate([(0.12, 0.47), (0.49, h - 0.02)]):
        drawer(f"drawer_{'bottom' if k == 0 else 'top'}", front + 0.002, y0 + 0.3, z_lo, z_hi, 0, 0.57, 0.52, stand=0.06)
    # Doors: one in the bay after the oven, two under the sink, two in the last bay (0.8 m is too wide for
    # one). Each is hinged on its outer edge.
    z_lo, z_hi = 0.13, h - 0.01
    door("cabinet_door_1", front, -0.7, -0.1, z_lo, z_hi, "left")
    door("sink_door_left", front, -0.1, 0.2, z_lo, z_hi, "left")
    door("sink_door_right", front, 0.2, 0.5, z_lo, z_hi, "right")
    door("cabinet_door_2", front, 0.5, 0.9, z_lo, z_hi, "left")
    door("cabinet_door_3", front, 0.9, y1, z_lo, z_hi, "right")


FRIDGE = {"x0": -2.95, "depth": 0.72, "ya": 1.38, "yb": 2.13, "height": 1.9, "wall": 0.03}
# The main shelf is at the pantry shelf's height, where an arm reaches in through the open door; the one
# below holds drinks over the crisper drawers, the two above are beyond the arms.
# A top-freezer fridge, as the model Lit draws in its place is (tools/make_appliances.py): the fridge door
# from 7 cm up to the mullion, the freezer door over it (shut for good: no task opens it), at the model's
# heights for this height.
FRIDGE_DOORS = (0.073, 1.229, 1.274)  # the fridge door's bottom and top (the mullion's underside), the freezer door's bottom
# The main shelf is at the pantry shelf's height, where an arm reaches in through the open door; the one
# below holds drinks over the crisper drawers. Over the main shelf the compartment is clear to the mullion.
FRIDGE_SHELVES = (0.46, 0.78)
FRIDGE_MAIN = 0.78


def fridge() -> None:
    """A top-freezer fridge with a lit, lined inside: glass shelves with food, two crisper drawers with
    vegetables, and bins on the door (milk, juice, sauces, eggs) that swing with it. The door is hinged on
    the wall's side, as a fridge at the end of a counter run is: it opens away from the counter, and what is
    inside is reached from there; its handle is a bar near the other edge. The shell's geoms are named
    fridge_shell_*, the freezer door's freezer_door: Lit draws the model's in their place."""
    x0, depth, ya, yb, hgt, wall = (FRIDGE[k] for k in ("x0", "depth", "ya", "yb", "height", "wall"))
    lo, hi, fz = FRIDGE_DOORS
    cx, cy = x0 + depth / 2, (ya + yb) / 2
    front = x0 + depth  # the opening, where the closed door's inside is
    inner = (yb - ya) / 2 - wall  # half width inside
    shelf_front = front - 0.015  # (the door's bins, only seen, reach over the shelves' fronts when it is shut)
    sx, shx = (x0 + wall + shelf_front) / 2, (shelf_front - x0 - wall) / 2
    t = 0.025  # the doors' half thickness
    mid, half = (0.12 + hi) / 2, (hi - 0.12) / 2  # the fridge's compartment, floor to mullion
    g = [
        box("fridge_shell_back", (x0 + wall / 2, cy, hgt / 2), (wall / 2, (yb - ya) / 2, hgt / 2), "fridge"),
        box("fridge_shell_left", (cx, ya + wall / 2, hgt / 2), (depth / 2, wall / 2, hgt / 2), "fridge"),
        box("fridge_shell_right", (cx, yb - wall / 2, hgt / 2), (depth / 2, wall / 2, hgt / 2), "fridge"),
        box("fridge_shell_top", (cx, cy, hgt - wall / 2), (depth / 2, (yb - ya) / 2, wall / 2), "fridge"),
        box("fridge_shell_bottom", (cx, cy, 0.06), (depth / 2, (yb - ya) / 2, 0.06), "fridge"),
        box("fridge_shell_mullion", (cx, cy, (hi + fz) / 2), (depth / 2, (yb - ya) / 2, (fz - hi) / 2), "fridge"),
        # the freezer door, a little short of the top, as the model's is
        box("freezer_door", (front + t, cy, (fz + hgt - 0.006) / 2), (t, (yb - ya) / 2, (hgt - 0.006 - fz) / 2), "fridge"),
        # liner and light
        vis("box", "fridge_inside", pos=f(x0 + wall + 0.003, cy, mid), size=f(0.003, inner, half)),
        vis("box", "fridge_inside", pos=f(cx + wall / 2, ya + wall + 0.003, mid), size=f(depth / 2 - wall / 2, 0.003, half)),
        vis("box", "fridge_inside", pos=f(cx + wall / 2, yb - wall - 0.003, mid), size=f(depth / 2 - wall / 2, 0.003, half)),
        vis("box", "fridge_inside", pos=f(cx + wall / 2, cy, hi - 0.003), size=f(depth / 2 - wall / 2, inner, 0.003)),
        vis("box", "fridge_inside", pos=f(cx + wall / 2, cy, 0.123), size=f(depth / 2 - wall / 2, inner, 0.003)),
        vis("box", "fridge_light", pos=f(front - 0.09, cy, hi - 0.008), size="0.04 0.1 0.005"),
    ]
    # The freezer door's bar, as the fridge door's (only seen: out of the arms' reach), and notes held by
    # magnets on it.
    g += bar_handle("freezer_handle", (front + 2 * t, ya + 0.17, (fz + hgt - 0.006) / 2), "z", "x", 1, 0.39, radius=0.012, stand=0.05, inset=0.07)
    for k, (ny, nz, mat) in enumerate([(-0.3, 1.52, "note_0"), (-0.42, 1.59, "note_1"), (-0.36, 1.35, "note_2")]):
        g.append(vis("box", mat, pos=f(front + 2 * t + 0.001, yb + ny, nz), size="0.001 0.05 0.06"))
        g.append(vis("cylinder", f"magnet_{k}", fromto=f(front + 2 * t + 0.001, yb + ny, nz + 0.05, front + 2 * t + 0.008, yb + ny, nz + 0.05), size="0.01"))
    # Glass shelves (solid) with white front trims.
    for k, z in enumerate(FRIDGE_SHELVES):
        g.append(box(f"fridge_shelf_{k + 1}", (sx, cy, z), (shx, inner, 0.006), "fridge_glass"))
        g.append(vis("box", "fridge_trim", pos=f(shelf_front - 0.008, cy, z), size=f(0.008, inner, 0.012)))
    # Two crisper drawers under the lowest shelf, frosted, with vegetables: set back from the opening, where
    # the door's lowest bin and its bottles are when it is shut (they reach 0.1 m in; the shelves are above them).
    crisp_front = front - 0.11
    kx, khx = (x0 + wall + 0.01 + crisp_front) / 2, (crisp_front - x0 - wall - 0.01) / 2
    for ca, cb in [(ya + wall + 0.01, cy - 0.006), (cy + 0.006, yb - wall - 0.01)]:
        cc, cw, top = (ca + cb) / 2, (cb - ca) / 2, FRIDGE_SHELVES[0] - 0.03
        g += [
            vis("box", "fridge_bin", pos=f(kx, cc, 0.135), size=f(khx, cw, 0.004)),
            vis("box", "fridge_bin", pos=f(crisp_front - 0.004, cc, (0.14 + top) / 2), size=f(0.004, cw, (top - 0.14) / 2)),
            vis("box", "fridge_bin", pos=f(kx, ca + 0.004, (0.14 + top) / 2), size=f(khx, 0.004, (top - 0.14) / 2)),
            vis("box", "fridge_bin", pos=f(kx, cb - 0.004, (0.14 + top) / 2), size=f(khx, 0.004, (top - 0.14) / 2)),
            vis("box", "fridge_trim", pos=f(crisp_front - 0.004, cc, top - 0.04), size=f(0.012, cw * 0.4, 0.01)),
        ]
    veg = [("tomato", "sphere", (0.04,), (-0.2, -0.12, 0.18)), ("tomato", "sphere", (0.035,), (-0.12, -0.05, 0.18)),
           ("lettuce", "ellipsoid", (0.09, 0.08, 0.07), (-0.25, 0.1, 0.21)), ("pepper", "ellipsoid", (0.04, 0.04, 0.05), (-0.1, 0.12, 0.19)),
           ("carrot", "capsule", (0.015, 0.07), (-0.25, 0.27, 0.16)), ("carrot", "capsule", (0.015, 0.07), (-0.2, 0.3, 0.16)),
           ("lemon", "ellipsoid", (0.035, 0.03, 0.03), (-0.12, 0.3, 0.17))]
    for mat, kind, size, (dx, dy, z) in veg:
        dx -= 0.11  # in the drawers, set back as they are
        if kind == "capsule":
            g.append(vis("capsule", mat, fromto=f(front + dx - size[1], cy + dy, z, front + dx + size[1], cy + dy, z), size=f(size[0])))
        else:
            g.append(vis(kind, mat, pos=f(front + dx, cy + dy, z), size=f(*size)))
    # Drinks on the low shelf, to look at (the main one is for the tasks).
    s0 = FRIDGE_SHELVES[0] + 0.006
    g += [
        vis("cylinder", "juice", pos=f(sx - 0.12, cy - 0.22, s0 + 0.11), size="0.045 0.11"),
        vis("cylinder", "lid", pos=f(sx - 0.12, cy - 0.22, s0 + 0.228), size="0.02 0.008"),
        vis("cylinder", "water", pos=f(sx - 0.05, cy - 0.1, s0 + 0.12), size="0.04 0.12"),
        *[vis("cylinder", "can_2" if k % 2 else "can", pos=f(sx + 0.02 + 0.07 * (k // 3), cy + 0.08 + 0.07 * (k % 3), s0 + 0.06), size="0.032 0.06") for k in range(6)],
    ]
    main = FRIDGE_MAIN + 0.006
    g += [
        region("container_fridge", x0 + wall, front, ya + wall, yb - wall, 0.12, hi),
        # the main shelf, and the front of it that an arm reaches through the open door (4 to 8 cm in): 11 cm
        # or more from the counter's side wall (the hand holding something is wider than it, and stays clear
        # of the wall), and short of the middle (beyond, the base would stand behind the open door's edge)
        region("surface_fridge_shelf", x0 + wall, shelf_front, ya + wall, yb - wall, main - 0.005, main + 0.005),
        region("zone_fridge_shelf", front - 0.08, front - 0.04, ya + wall + 0.11, cy - 0.095, main - 0.005, main + 0.005),
    ]
    static("fridge", g)
    # The fridge door, with its bins on the inside (shown only, so nothing falls as it swings), hinged at
    # yb. Its body's origin is on the hinge, at the door's middle height; the inside face is at x = -t.
    w = (yb - ya) / 2
    dz, zc = (hi - lo) / 2, (hi + lo) / 2
    d = [
        f'<geom name="fridge_door_panel" type="box" pos="{f(0, -w, 0)}" size="{f(t, w, dz)}" material="fridge" mass="9" contype="1" conaffinity="1"/>',
        vis("box", "fridge_inside", pos=f(-t - 0.003, -w, 0), size=f(0.003, w - 0.04, dz - 0.06)),
    ]
    bins = [z - zc for z in (0.2, 0.58, 0.96)]  # the bins' floors, from 20 cm up
    for zb in bins:
        d += [
            vis("box", "fridge_trim", pos=f(-t - 0.05, -w, zb), size=f(0.045, w - 0.06, 0.005)),
            vis("box", "fridge_bin", pos=f(-t - 0.095, -w, zb + 0.04), size=f(0.004, w - 0.06, 0.04)),
            vis("box", "fridge_trim", pos=f(-t - 0.05, -0.065, zb + 0.04), size=f(0.045, 0.004, 0.04)),
            vis("box", "fridge_trim", pos=f(-t - 0.05, -2 * w + 0.065, zb + 0.04), size=f(0.045, 0.004, 0.04)),
        ]
    zb = bins[0] + 0.005  # tall things in the bottom bin
    d += [
        vis("box", "milk", pos=f(-t - 0.05, -0.16, zb + 0.1), size="0.035 0.035 0.1"),
        vis("box", "milk_top", pos=f(-t - 0.05, -0.16, zb + 0.215), size="0.035 0.02 0.015"),
        vis("cylinder", "juice", pos=f(-t - 0.05, -0.29, zb + 0.11), size="0.035 0.11"),
        vis("cylinder", "lid", pos=f(-t - 0.05, -0.29, zb + 0.23), size="0.015 0.012"),
        vis("cylinder", "water", pos=f(-t - 0.05, -0.62, zb + 0.12), size="0.035 0.12"),
    ]
    zb = bins[1] + 0.005  # sauces in the middle bin
    for k, (mat, r, hh) in enumerate([("jar_red", 0.025, 0.07), ("sauce", 0.022, 0.08), ("jar_green", 0.025, 0.06), ("sauce", 0.02, 0.075)]):
        y = -0.15 - 0.15 * k
        d += [vis("cylinder", mat, pos=f(-t - 0.05, y, zb + hh), size=f(r, hh)), vis("cylinder", "lid", pos=f(-t - 0.05, y, zb + 2 * hh + 0.006), size=f(r * 0.6, 0.008))]
    zb = bins[2] + 0.005  # eggs in the top bin
    d.append(vis("box", "fridge_trim", pos=f(-t - 0.05, -w, zb + 0.008), size=f(0.04, 0.16, 0.008)))
    for k in range(6):
        d.append(vis("ellipsoid", "egg", pos=f(-t - 0.05 + (0.02 if k % 2 else -0.02), -w - 0.12 + 0.048 * (k // 2) * 2.5, zb + 0.035), size="0.017 0.017 0.023"))
    # An upright bar pull near the free edge, as a fridge's is, on the door's middle, from 0.28 m up to
    # 0.92 m: no higher, so what the robot carries (0.93 m up at least, over the worktops) passes over it.
    # An arm grasps it with the hand level, the jaws round it, and pushes it shut just below that
    # (src/robots/fixtures.js). Its posts sit 5 cm in from its ends.
    d += bar_handle("fridge_handle", (t, -2 * w + 0.17, 0.6 - zc), "z", "x", 1, 0.64, radius=0.012, stand=0.05, inset=0.05)
    # The door's magnetic gasket: a strip along the free edge inside the door, half a millimetre off the
    # cabinet's side wall when it is shut (it only meets that wall: no other collisions, not drawn). MuJoCo's
    # contact adhesion pulls the two together within 2 cm, so the door swings shut over the last centimetres
    # and opens with a tug (two contacts, at the strip's ends, of 3 N each).
    sx, sy = -t + 0.004 + 0.0005, -2 * w + 0.015
    d.append(f'<geom name="fridge_door_seal" type="capsule" fromto="{f(sx, sy, lo - zc + 0.06, sx, sy, hi - zc - 0.06)}" size="0.004" density="0" contype="0" conaffinity="0" group="3"/>')
    pairs.append('<pair geom1="fridge_door_seal" geom2="fridge_shell_left" condim="1" gap="0.02" adhesion="3"/>')
    # The hinge's stop holds the door where it shuts: it need not collide with the cabinet as well (pulled
    # against it by the magnet, the door would touch it at a dozen points, each a contact to solve).
    excludes.append(("fridge", "fridge_door"))
    lines.append(f'    <body name="fridge_door" pos="{f(front + t, yb, zc)}">')
    # axis +z: opening turns the free edge (-y, the counter's side) out toward the room (+x); the hinge's
    # friction holds it where it is left (a brush does not swing it wide)
    lines.append('      <joint name="fridge_door_hinge" type="hinge" axis="0 0 1" range="0 1.9" damping="2" frictionloss="2" armature="0.1"/>')
    lines.extend(f"      {x}" for x in d)
    lines.append("    </body>")


ISLAND = {"cx": -1.2, "cy": 0.0, "hx": 0.35, "hy": 0.65}
# A prep sink at the island's end toward the oven: an arm reaches into it from that end, where a sink at
# the back of the counter is beyond it.
PREP_SINK = {"x0": -1.36, "x1": -1.04, "y0": -0.63, "y1": -0.37, "depth": 0.16}


def island() -> None:
    cx, cy, hx, hy = (ISLAND[k] for k in ("cx", "cy", "hx", "hy"))
    x0, x1, y0, y1 = cx - hx, cx + hx, cy - hy, cy + hy
    sk = PREP_SINK
    t = ISLAND_TOP
    zb = t - sk["depth"]

    def top(name, xa, xb, ya, yb):
        return box(name, ((xa + xb) / 2, (ya + yb) / 2, t - 0.02), ((xb - xa) / 2, (yb - ya) / 2, 0.02), "countertop")

    def body(xa, xb, ya, yb, z1):
        return box(None, ((xa + xb) / 2, (ya + yb) / 2, (0.1 + z1) / 2), ((xb - xa) / 2, (yb - ya) / 2, (z1 - 0.1) / 2), "cabinet")

    bx, by = (sk["x0"] + sk["x1"]) / 2, (sk["y0"] + sk["y1"]) / 2
    hxs, hys = (sk["x1"] - sk["x0"]) / 2, (sk["y1"] - sk["y0"]) / 2
    wall_z, wall_h = (zb + t) / 2, (t - zb) / 2
    # Two drawers at the end toward the fridge (+y), under the flush top: an arm comes down behind a bar
    # pull there (under the counter's overhanging worktop it cannot), and the base backs out into the room.
    cav = y1 - 0.5  # the drawers' space, from here to the end
    cz = (0.1 + t - 0.04) / 2
    static("island", [
        # Flush on all sides, like the tabletop scene's tables: the robot's bumper meets the island
        # before its shoulders reach the worktop's edge. The top goes round the sink's cut-out.
        top("island_top", x0, x1, sk["y1"], y1),
        top(None, x0, x1, y0, sk["y0"]),
        top(None, x0, sk["x0"], sk["y0"], sk["y1"]),
        top(None, sk["x1"], x1, sk["y0"], sk["y1"]),
        body(x0 + 0.005, x1 - 0.005, sk["y1"], cav, t - 0.04),
        box(None, (x0 + 0.015, (cav + y1) / 2, cz), (0.01, (y1 - cav) / 2, cz - 0.1), "cabinet"),
        box(None, (x1 - 0.015, (cav + y1) / 2, cz), (0.01, (y1 - cav) / 2, cz - 0.1), "cabinet"),
        box(None, (cx, (cav + y1) / 2, 0.105), (hx - 0.025, (y1 - cav) / 2, 0.005), "cabinet"),
        box(None, (cx, y1 - 0.01, 0.565), (hx - 0.025, 0.01, 0.01), "cabinet"),
        body(x0 + 0.005, x1 - 0.005, y0 + 0.005, sk["y0"], t - 0.04),
        body(x0 + 0.005, sk["x0"], sk["y0"], sk["y1"], t - 0.04),
        body(sk["x1"], x1 - 0.005, sk["y0"], sk["y1"], t - 0.04),
        body(sk["x0"], sk["x1"], sk["y0"], sk["y1"], zb - 0.01),
        box("island_plinth", (cx, cy, 0.05), (hx - 0.03, hy - 0.03, 0.05), "plinth"),
        # the basin, flush with the top
        box("prep_sink_bottom", (bx, by, zb), (hxs, hys, 0.005), "steel"),
        box(None, (sk["x0"] + 0.005, by, wall_z), (0.005, hys, wall_h), "steel"),
        box(None, (sk["x1"] - 0.005, by, wall_z), (0.005, hys, wall_h), "steel"),
        box(None, (bx, sk["y0"] + 0.005, wall_z), (hxs, 0.005, wall_h), "steel"),
        box(None, (bx, sk["y1"] - 0.005, wall_z), (hxs, 0.005, wall_h), "steel"),
        vis("box", "sink_drain", pos=f(bx, by, zb + 0.0055), size="0.025 0.025 0.0005"),
        # a tap at the far edge (seen only: an arm reaching in goes under its spout)
        vis("cylinder", "steel", pos=f(bx, sk["y1"] + 0.035, t + 0.12), size="0.012 0.12"),
        vis("capsule", "steel", fromto=f(bx, sk["y1"] + 0.035, t + 0.24, bx, sk["y1"] - 0.06, t + 0.24), size="0.011"),
        vis("box", "steel", pos=f(bx + 0.04, sk["y1"] + 0.035, t + 0.05), size="0.02 0.006 0.006"),
        region("surface_island", x0, x1, y0, y1, t - 0.005, t + 0.005),
        region("container_prep_sink", sk["x0"] + 0.01, sk["x1"] - 0.01, sk["y0"] + 0.01, sk["y1"] - 0.01, zb + 0.005, t + 0.06),
        # Where a task puts things, at the start and to put them down: along the edge facing the room, 4 to
        # 10 cm in (an arm reaches about 11 cm past an edge the base stands at).
        region("zone_island_front", x1 - 0.10, x1 - 0.04, y0 + 0.08, y1 - 0.08, t - 0.005, t + 0.005),
    ])
    drawer("island_drawer_top", cx, y1 + 0.024, 0.578, t - 0.045, math.pi / 2, 0.62, 0.46)
    drawer("island_drawer_bottom", cx, y1 + 0.024, 0.12, 0.552, math.pi / 2, 0.62, 0.46)


TRASH = {"x": -1.5, "y": -2.36, "half": 0.16, "height": 0.62}


def trash_can() -> None:
    """An open bin against the wall by the oven, low enough for an arm to drop things in."""
    x, y, h, hgt = (TRASH[k] for k in ("x", "y", "half", "height"))
    w = 0.008  # half wall thickness
    static("trash_can", [
        box("trash_can_bottom", (x, y, 0.015), (h, h, 0.015), "trash"),
        box(None, (x - h + w, y, hgt / 2), (w, h, hgt / 2), "trash"),
        box(None, (x + h - w, y, hgt / 2), (w, h, hgt / 2), "trash"),
        box(None, (x, y - h + w, hgt / 2), (h - 2 * w, w, hgt / 2), "trash"),
        box(None, (x, y + h - w, hgt / 2), (h - 2 * w, w, hgt / 2), "trash"),
        # a rim and a bag showing over it
        vis("box", "trash_rim", pos=f(x, y + h - w, hgt + 0.006), size=f(h + 0.004, w + 0.004, 0.006)),
        vis("box", "trash_rim", pos=f(x, y - h + w, hgt + 0.006), size=f(h + 0.004, w + 0.004, 0.006)),
        vis("box", "trash_rim", pos=f(x - h + w, y, hgt + 0.006), size=f(w + 0.004, h, 0.006)),
        vis("box", "trash_rim", pos=f(x + h - w, y, hgt + 0.006), size=f(w + 0.004, h, 0.006)),
        vis("box", "trash_bag", pos=f(x, y, 0.033), size=f(h - 2 * w - 0.002, h - 2 * w - 0.002, 0.003)),
        region("container_trash_can", x - h + 2 * w, x + h - 2 * w, y - h + 2 * w, y + h - 2 * w, 0.03, hgt + 0.05),
    ])


SIDEBOARD = {"x0": -0.95, "x1": 0.45, "y0": 2.22, "y1": 2.6, "top": 0.78}
RADIO = {"x": -0.73, "y": 2.285, "hx": 0.12, "hy": 0.055, "hz": 0.04}


def sideboard() -> None:
    """A low sideboard along the wall by the fridge, its front flush (no handles): a pantry shelf for the
    tasks, with a radio on it."""
    x0, x1, y0, y1, top = (SIDEBOARD[k] for k in ("x0", "x1", "y0", "y1", "top"))
    cx, cy = (x0 + x1) / 2, (y0 + y1) / 2
    g = [
        box("sideboard_top", (cx, cy, top - 0.015), ((x1 - x0) / 2, (y1 - y0) / 2, 0.015), "wood"),
        box("sideboard_body", (cx, cy + 0.01, (0.08 + top - 0.03) / 2), ((x1 - x0) / 2 - 0.01, (y1 - y0) / 2 - 0.01, (top - 0.03 - 0.08) / 2), "sideboard"),
        box(None, (cx, cy + 0.02, 0.04), ((x1 - x0) / 2 - 0.03, (y1 - y0) / 2 - 0.03, 0.04), "plinth"),
    ]
    # three fronts with knobs set in (seen only), as on a low cabinet
    for k in range(3):
        fx = x0 + (x1 - x0) * (k + 0.5) / 3
        g.append(vis("box", "sideboard_front", pos=f(fx, y0 + 0.003, (0.1 + top - 0.04) / 2), size=f((x1 - x0) / 6 - 0.01, 0.004, (top - 0.04 - 0.1) / 2 - 0.01)))
        g.append(vis("sphere", "brass", pos=f(fx, y0 - 0.002, top - 0.12), size="0.008"))
    # a plant and two jars at the far end (seen only)
    g += [
        region("surface_sideboard", x0, x1, y0, y1, top - 0.005, top + 0.005),
        # the front 4 to 10 cm, between the radio and the microwave
        region("zone_sideboard_front", RADIO["x"] + RADIO["hx"] + 0.08, MICROWAVE["x0"] - 0.06, y0 + 0.04, y0 + 0.10, top - 0.005, top + 0.005),
    ]
    # The radio: its body, a speaker grille, a dial and an antenna; the power button is its own body.
    rx, ry, rz = RADIO["x"], RADIO["y"], top
    hx, hy, hz = RADIO["hx"], RADIO["hy"], RADIO["hz"]
    g += [
        box("radio_body", (rx, ry, rz + hz), (hx, hy, hz), "radio"),
        vis("cylinder", "speaker", fromto=f(rx - 0.05, ry - hy - 0.003, rz + hz, rx - 0.05, ry - hy + 0.001, rz + hz), size="0.03"),
        vis("cylinder", "radio_dial", fromto=f(rx + 0.06, ry - hy - 0.008, rz + hz - 0.005, rx + 0.06, ry - hy + 0.001, rz + hz - 0.005), size="0.016"),
        vis("box", "radio_panel", pos=f(rx + 0.06, ry - hy - 0.001, rz + hz + 0.024), size="0.035 0.002 0.008"),
        vis("capsule", "steel", fromto=f(rx + hx - 0.02, ry + 0.03, rz + 2 * hz, rx + hx + 0.05, ry + 0.06, rz + 2 * hz + 0.22), size="0.003"),
    ]
    static("sideboard", g)
    # Power button on top, near the front: 12 mm of travel against a spring; the radio switches on or off
    # each time it is pressed down (src/tasks/devices.js). The light shows whether it is on.
    bx, by, bz = rx + 0.02, ry - 0.015, rz + 2 * hz + 0.008
    lines[len(lines):] = [
        f'    <body name="radio_button" pos="{f(bx, by, bz)}">',
        '      <joint name="radio_button_slide" type="slide" axis="0 0 1" range="-0.012 0" stiffness="150" springref="0" damping="1.5" armature="0.005"/>',
        f'      <geom name="radio_button_cap" type="box" size="0.022 0.018 0.008" material="radio_button" mass="0.01" contype="1" conaffinity="1"/>',
        '      <geom name="radio_led" type="sphere" pos="0.032 0 0" size="0.005" material="radio_led" contype="0" conaffinity="0"/>',
        "    </body>",
    ]
    # it goes down into the radio, as into a recess round it
    excludes.append(("sideboard", "radio_button"))
    microwave(top)


MICROWAVE = {"x0": -0.06, "x1": 0.42, "y0": 2.25, "y1": 2.57, "h": 0.28}


def microwave(top: float) -> None:
    """A microwave on the sideboard's end, as RoboCasa's kitchens have: a door hinged on its left that swings
    out into the room, held shut by a magnet against a spring; pressing the release button at the foot of
    the control panel pops it open about 20 degrees (a pin pushes it past the magnet's reach), and a push on
    the door's face swings it back until the magnet catches it: no pull. A glass turntable and a light
    inside, and a control panel on the right."""
    x0, x1, y0, y1, h = (MICROWAVE[k] for k in ("x0", "x1", "y0", "y1", "h"))
    z0, z1 = top, top + h
    panel = x1 - 0.14  # the control panel's left edge
    wall = 0.01
    base = 0.036  # the cavity's floor, at the model's (tools/make_appliances.py): what goes in rests on it
    g = [
        box(None, ((x0 + x1) / 2, (y0 + y1) / 2, z1 - wall / 2), ((x1 - x0) / 2, (y1 - y0) / 2, wall / 2), "microwave"),
        box("microwave_floor", ((x0 + x1) / 2, (y0 + y1) / 2, z0 + base / 2), ((x1 - x0) / 2, (y1 - y0) / 2, base / 2), "microwave"),
        box(None, (x0 + wall / 2, (y0 + y1) / 2, (z0 + z1) / 2), (wall / 2, (y1 - y0) / 2, h / 2), "microwave"),
        box(None, ((panel + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2), ((x1 - panel) / 2, (y1 - y0) / 2, h / 2), "microwave"),
        box(None, ((x0 + x1) / 2, y1 - wall / 2, (z0 + z1) / 2), ((x1 - x0) / 2, wall / 2, h / 2), "microwave"),
        # inside: a light, a lined cavity, a glass plate
        vis("box", "microwave_inside", pos=f((x0 + panel) / 2, y1 - wall - 0.002, (z0 + base + z1 - wall) / 2), size=f((panel - x0) / 2 - wall, 0.002, (h - base - wall) / 2)),
        vis("box", "fridge_light", pos=f((x0 + panel) / 2, (y0 + y1) / 2 + 0.06, z1 - wall - 0.004), size="0.04 0.03 0.003"),
        vis("cylinder", "fridge_glass", pos=f((x0 + panel) / 2, (y0 + y1) / 2 + 0.01, z0 + base + 0.003), size="0.11 0.003"),
        # the control panel: a display and two rows of buttons (the door's release button is its own body)
        vis("box", "microwave_panel", pos=f((panel + x1) / 2, y0 - 0.001, (z0 + z1) / 2), size=f((x1 - panel) / 2 - 0.01, 0.002, h / 2 - 0.015)),
        vis("box", "microwave_display", pos=f((panel + x1) / 2, y0 - 0.004, z1 - 0.05), size="0.045 0.002 0.014"),
        *[vis("box", "radio_dial", pos=f(panel + 0.035 + 0.035 * (k % 3), y0 - 0.004, z1 - 0.1 - 0.03 * (k // 3)), size="0.012 0.002 0.008") for k in range(9)],
        region("container_microwave", x0 + wall, panel, y0, y1 - wall, z0 + base, z1 - wall),
    ]
    static("microwave", g)
    # The door, hinged on the left edge of the opening; it opens (positive) by turning its free edge (+x)
    # out toward the room (-y). Its inside face is on the cabinet's front (y = 0 in its frame) when shut.
    # A spring turns it open (0.72 N m shut, to rest about 20 degrees open against the hinge's friction);
    # a magnet holds it shut: a strip along its foot near the free edge, half a millimetre off the
    # cabinet's floor slab, which MuJoCo's contact adhesion pulls to the slab within 6 mm (2 N at each of
    # its two contacts: 1.1 N m). It only meets that slab: no other collisions, not drawn.
    dw = panel - x0 - 0.004  # its width
    t = 0.012  # half thickness
    dz = h / 2 - 0.006
    d = [
        f'<geom name="microwave_door_panel" type="box" pos="{f(dw / 2, -t, h / 2)}" size="{f(dw / 2, t, dz)}" material="microwave" mass="1.2" contype="1" conaffinity="1"/>',
        f'<geom name="microwave_door_window" type="box" pos="{f(dw / 2 - 0.02, -2 * t - 0.001, h / 2 + 0.02)}" size="{f(dw / 2 - 0.05, 0.002, dz - 0.05)}" material="microwave_window" density="0" contype="0" conaffinity="0"/>',
        # Where a closed gripper pushes the door shut (src/robots/fixtures.js): a mark low on its face near the free
        # edge, at 0.81 m (an arm comes down to it from straight above, in front of the sideboard's edge). It does
        # not collide and is not drawn; its mass is the pull's that the door used to have.
        f'<geom name="microwave_door_push" type="capsule" fromto="{f(dw - 0.19, -2 * t - 0.012, 0.03, dw - 0.03, -2 * t - 0.012, 0.03)}" size="0.01" mass="0.14" contype="0" conaffinity="0" group="3"/>',
        f'<geom name="microwave_door_seal" type="capsule" fromto="{f(dw - 0.075, -0.0035, 0.02, dw - 0.025, -0.0035, 0.02)}" size="0.003" density="0" contype="0" conaffinity="0" group="3"/>',
    ]
    pairs.append('<pair geom1="microwave_door_seal" geom2="microwave_floor" condim="1" gap="0.006" adhesion="2"/>')
    excludes.append(("microwave", "microwave_door"))  # the hinge's stop holds it shut, as the fridge's
    lines.append(f'    <body name="microwave_door" pos="{f(x0 + 0.002, y0, z0)}">')
    lines.append('      <joint name="microwave_door_hinge" type="hinge" axis="0 0 -1" range="0 1.9" stiffness="1.2" springref="0.6" damping="0.4" frictionloss="0.3" armature="0.02"/>')
    lines.extend(f"      {x}" for x in d)
    lines.append("    </body>")
    # The release: a button at the foot of the control panel (where the model's lowest one is), pressed in
    # (+y) 6 mm at most against a spring, and a pin in the floor slab at the door's free edge that follows
    # it 2.2 times as far out and pushes the door 13 mm open, past the magnet's reach. The linkage (an
    # equality) is stiff, and the parts heavy enough to carry the push: a light pin lags behind the button
    # against the magnet. They slide in the cabinet without touching it; the pin is not drawn.
    lines[len(lines):] = [
        f'    <body name="microwave_button" pos="{f(panel + 0.066, y0 - 0.0045, z0 + 0.058)}">',
        '      <joint name="microwave_button_slide" type="slide" axis="0 1 0" range="0 0.006" stiffness="150" springref="0" damping="1.5" armature="0.02"/>',
        '      <geom name="microwave_button_cap" type="box" size="0.0165 0.004 0.012" material="microwave_start" mass="0.01" contype="1" conaffinity="1"/>',
        "    </body>",
        f'    <body name="microwave_pin" pos="{f(x0 + 0.002 + dw - 0.014, y0 + 0.005, z0 + 0.018)}">',
        '      <joint name="microwave_pin_slide" type="slide" axis="0 -1 0" range="0 0.014" damping="0.5" armature="0.02"/>',
        '      <geom name="microwave_pin" type="box" size="0.005 0.004 0.005" mass="0.01" contype="1" conaffinity="1" group="3"/>',
        "    </body>",
    ]
    excludes.extend([("microwave", "microwave_button"), ("microwave", "microwave_pin")])
    equalities.append('<joint joint1="microwave_pin_slide" joint2="microwave_button_slide" polycoef="0 2.2 0 0 0" solref="0.004 1"/>')


def dining() -> None:
    """A dining table with chairs along the wall side and at the far end: the side facing the island and
    the near end are free, where the robot reaches across the table's edge."""
    cx, cy = 1.25, 1.45
    top = 0.75
    legs = [box(None, (cx + sx * 0.7, cy + sy * 0.38, top / 2), (0.03, 0.03, top / 2), "wood") for sx in (-1, 1) for sy in (-1, 1)]
    static("dining_table", [
        box("dining_top", (cx, cy, top - 0.02), (0.8, 0.45, 0.02), "wood"), *legs,
        region("surface_dining_table", cx - 0.8, cx + 0.8, cy - 0.45, cy + 0.45, top - 0.005, top + 0.005),
        # the free end and the free side, 4 to 10 cm in from the edge
        region("zone_dining_end", cx - 0.76, cx - 0.70, cy - 0.33, cy + 0.33, top - 0.005, top + 0.005),
        region("zone_dining_side", cx - 0.62, cx + 0.62, cy - 0.41, cy - 0.35, top - 0.005, top + 0.005),
    ])

    def chair(k, x, y, facing):
        """A chair at (x, y) whose seat faces `facing` (a unit axis: its back is on the other side)."""
        fx, fy = facing
        static(f"chair_{k}", [
            box(None, (x, y, 0.45), (0.21, 0.21, 0.02), "wood"),
            box(None, (x - fx * 0.2, y - fy * 0.2, 0.7), (0.02 if fx else 0.21, 0.21 if fx else 0.02, 0.25), "wood"),
            *[box(None, (x + ax * 0.18, y + ay * 0.18, 0.22), (0.018, 0.018, 0.22), "wood") for ax in (-1, 1) for ay in (-1, 1)],
        ])

    for k, x in enumerate([cx - 0.5, cx, cx + 0.5]):
        chair(k + 1, x, cy + 0.65, (0, -1))
    chair(4, cx + 1.02, cy, (-1, 0))


def living() -> None:
    sx, sy = 1.3, -1.75
    static("sofa", [
        box("sofa_seat", (sx, sy - 0.05, 0.22), (0.95, 0.4, 0.2), "fabric"),
        box("sofa_back", (sx, sy - 0.38, 0.55), (0.95, 0.12, 0.35), "fabric"),
        box(None, (sx - 0.9, sy - 0.05, 0.35), (0.1, 0.42, 0.3), "fabric"),
        box(None, (sx + 0.9, sy - 0.05, 0.35), (0.1, 0.42, 0.3), "fabric"),
    ])
    static("coffee_table", [
        box("coffee_top", (sx, sy + 0.85, 0.42), (0.5, 0.28, 0.02), "wood"),
        region("surface_coffee_table", sx - 0.5, sx + 0.5, sy + 0.57, sy + 1.13, 0.435, 0.445),
        region("zone_storage_coffee", sx - 0.42, sx + 0.42, sy + 0.65, sy + 1.05, 0.435, 0.445),
        *[box(None, (sx + ax * 0.45, sy + 0.85 + ay * 0.23, 0.2), (0.025, 0.025, 0.2), "wood") for ax in (-1, 1) for ay in (-1, 1)],
    ])
    static("rug", [box(None, (sx, sy + 0.6, 0.002), (1.2, 0.9, 0.002), "rug", collide=False)])


def room() -> None:
    t = 0.05
    static("walls", [
        box("wall_back", (-3.0 - t, 0, WALL_H / 2), (t, 2.6, WALL_H / 2), "wall"),
        box("wall_front", (2.6 + t, 0, WALL_H / 2), (t, 2.6, WALL_H / 2), "wall"),
        box("wall_left", (-0.2, -2.6 - t, WALL_H / 2), (2.8 + 2 * t, t, WALL_H / 2), "wall"),
        box("wall_right", (-0.2, 2.6 + t, WALL_H / 2), (2.8 + 2 * t, t, WALL_H / 2), "wall"),
    ])


def objects() -> None:
    """Small objects to pick (tools/objects.py), on the island, the dining table, the counter and in the fridge."""
    z = ISLAND_TOP
    fx = FRIDGE["x0"] + FRIDGE["depth"] - 0.3  # at the back, out of the way of what tasks put in at the front
    shelf = FRIDGE_MAIN + 0.006
    for part in [
        objects_.apple(-0.91, -0.42, z), objects_.orange(-0.91, -0.02, z), objects_.cube(-0.9, 0.42, z),
        # The can and the mug near the island's back edge, where an arm reaches from the corridor behind it.
        objects_.can(-1.43, -0.3, z), objects_.mug(-1.42, 0.35, z),
        # A bowl and a plate to put things in or on. The bowl by the island's edge facing the room: placing
        # reaches it (12 cm in, it was at the arm's limit).
        objects_.bowl(-0.94, 0.2, z), objects_.plate(-0.99, -0.22, z),
        # On the dining table, at the end without chairs where an arm reaches from the floor, and at the
        # front of the counter (its door handles keep the base 6 cm off).
        objects_.banana(0.52, 1.3, 0.75, yaw=1.3), objects_.cup(0.52, 1.62, 0.75), objects_.bottle(-2.41, -0.45, COUNTER_TOP),
        objects_.can(0.53, 1.46, 0.75, name="can_2", material="can_2"), objects_.lemon(0.55, 1.13, 0.75),
        objects_.book(1.15, -0.9, 0.44),
        # In the fridge, at the back of the main shelf.
        objects_.yogurt(fx, 1.86, shelf), objects_.juice_box(fx, 1.98, shelf),
    ]:
        lines.extend(part)


def details() -> None:
    """(Not named decor_*: the page's renderer takes those for a 3DGS scene's stand-in and hides the floor.)
    What makes it lived in, as RoboCasa's and BEHAVIOR's kitchens are: cookware on the cooktop, a coffee
    machine, a kettle, a knife block and a crock of spoons, spices, a towel roll, soap and a sponge; light
    strips under the wall cabinets and lamps over the table; windows with curtains, a clock, pictures and
    notes on the fridge; plants, a reading lamp and cushions; a tiled floor in the kitchen. Seen only
    (no collisions) but for the plants' pots and the lamp, and kept off what the tasks use: the zones, the
    island, the floor the robot drives on."""
    x0, front = -2.95, -2.35
    top = COUNTER_TOP
    # a tall pantry cabinet between the fridge and the wall, flush with the fridge's front
    px0, px1, py0, py1 = -2.95, -2.235, FRIDGE["yb"] + 0.01, 2.6
    static("pantry_cabinet", [
        box(None, ((px0 + px1) / 2, (py0 + py1) / 2, 1.05), ((px1 - px0) / 2, (py1 - py0) / 2, 1.05), "cabinet"),
        vis("box", "cabinet_door", pos=f(px1 + 0.008, (py0 + py1) / 2, 1.05), size=f(0.008, (py1 - py0) / 2 - 0.006, 1.02)),
        vis("capsule", "steel", fromto=f(px1 + 0.035, py0 + 0.05, 0.85, px1 + 0.035, py0 + 0.05, 1.25), size="0.009"),
    ])
    # a tiled floor in the kitchen part of the room, and skirting boards round the walls
    static("details_floor", [
        vis("box", "floor_tile", pos=f(-1.78, 0, 0.0015), size=f(1.22, 2.6, 0.0015)),
        vis("box", "skirting", pos=f(-2.996, 0, 0.04), size=f(0.004, 2.6, 0.04)),
        vis("box", "skirting", pos=f(2.596, 0, 0.04), size=f(0.004, 2.6, 0.04)),
        vis("box", "skirting", pos=f(-0.2, -2.596, 0.04), size=f(2.8, 0.004, 0.04)),
        vis("box", "skirting", pos=f(-0.2, 2.596, 0.04), size=f(2.8, 0.004, 0.04)),
    ])
    g = []
    # the cooktop: a pot with a lid on the back burner, a pan on a front one
    bx, by = -2.755, -1.13
    g += [
        vis("cylinder", "steel", pos=f(bx, by, top + 0.07), size="0.085 0.065"),
        vis("cylinder", "pan", pos=f(bx, by, top + 0.137), size="0.087 0.004"),
        vis("sphere", "pan", pos=f(bx, by, top + 0.15), size="0.012"),
        vis("capsule", "pan", fromto=f(bx, by - 0.085, top + 0.11, bx, by - 0.115, top + 0.11), size="0.008"),
        vis("capsule", "pan", fromto=f(bx, by + 0.085, top + 0.11, bx, by + 0.115, top + 0.11), size="0.008"),
        vis("cylinder", "pan", pos=f(-2.515, -0.87, top + 0.02), size="0.11 0.012"),
        vis("capsule", "pan", fromto=f(-2.515, -0.76, top + 0.035, -2.515, -0.6, top + 0.06), size="0.01"),
    ]
    # a towel over the oven's handle
    g += [vis("box", "towel", pos=f(front + 0.065, -1.0, 0.64), size="0.004 0.09 0.07"), vis("box", "towel", pos=f(front + 0.055, -1.0, 0.712), size="0.012 0.09 0.006")]
    # a crock of wooden spoons beside the cooktop, and spices on a little shelf on the splashback
    g += [
        vis("cylinder", "ceramic", pos=f(x0 + 0.07, -0.67, top + 0.07), size="0.045 0.07"),
        *[vis("capsule", "wood", fromto=f(x0 + 0.07 + dx, -0.67 + dy, top + 0.08, x0 + 0.07 + 2 * dx, -0.67 + 2 * dy, top + 0.27), size="0.007") for dx, dy in [(0.01, 0.01), (-0.012, 0.006), (0.004, -0.013)]],
        vis("box", "wood", pos=f(x0 + 0.045, -1.62, top + 0.33), size="0.04 0.22 0.008"),
        *[vis("cylinder", f"spice_{k % 4}", pos=f(x0 + 0.045, -1.8 + 0.072 * k, top + 0.37), size="0.018 0.035") for k in range(6)],
        *[vis("cylinder", "lid", pos=f(x0 + 0.045, -1.8 + 0.072 * k, top + 0.41), size="0.019 0.006") for k in range(6)],
    ]
    # by the sink: soap and a sponge; a roll of paper towel on the splashback
    g += [
        vis("cylinder", "soap", pos=f(x0 + 0.06, 0.86, top + 0.08), size="0.028 0.08"),
        vis("cylinder", "steel", pos=f(x0 + 0.06, 0.86, top + 0.175), size="0.01 0.015"),
        vis("box", "sponge", pos=f(x0 + 0.06, -0.05, top + 0.015), size="0.045 0.03 0.015"),
        vis("capsule", "steel", fromto=f(x0 + 0.06, 1.0, top + 0.42, x0 + 0.06, 1.26, top + 0.42), size="0.006"),
        vis("cylinder", "paper", fromto=f(x0 + 0.075, 1.02, top + 0.38, x0 + 0.075, 1.24, top + 0.38), size="0.055"),
    ]
    # by the fridge: a coffee machine with a cup under its spout, a kettle, a knife block
    cx_, cy_ = x0 + 0.1, 1.04
    g += [
        vis("box", "appliance_dark", pos=f(cx_, cy_, top + 0.17), size="0.09 0.09 0.17"),
        vis("box", "appliance_dark", pos=f(cx_ + 0.11, cy_, top + 0.31), size="0.03 0.08 0.03"),
        vis("box", "glass", pos=f(cx_ + 0.07, cy_, top + 0.012), size="0.07 0.08 0.012"),
        vis("cylinder", "ceramic", pos=f(cx_ + 0.11, cy_, top + 0.06), size="0.03 0.035"),
        vis("box", "water_tank", pos=f(cx_ - 0.03, cy_ + 0.075, top + 0.2), size="0.05 0.02 0.14"),
        vis("cylinder", "steel", pos=f(x0 + 0.33, 1.22, top + 0.09), size="0.07 0.09"),
        vis("capsule", "appliance_dark", fromto=f(x0 + 0.33, 1.16, top + 0.2, x0 + 0.33, 1.28, top + 0.2), size="0.012"),
        vis("capsule", "steel", fromto=f(x0 + 0.39, 1.22, top + 0.1, x0 + 0.46, 1.22, top + 0.15), size="0.012"),
        vis("box", "wood", pos=f(x0 + 0.12, 1.24, top + 0.09), size="0.05 0.04 0.09"),
        *[vis("capsule", "appliance_dark", fromto=f(x0 + 0.12 + dx, 1.24, top + 0.18, x0 + 0.12 + dx, 1.24, top + 0.24), size="0.009") for dx in (-0.025, 0, 0.025)],
    ]
    # light strips under the wall cabinets (none over the cooktop: the hood has its light)
    for ya, yb in [(-1.9, -1.3), (-0.7, -0.1), (-0.1, 0.5), (0.5, 1.3)]:
        g.append(vis("box", "led", pos=f(x0 + 0.32, (ya + yb) / 2, 1.484), size=f(0.012, (yb - ya) / 2 - 0.03, 0.003)))
    static("details_counter", g)
    # notes and magnets on the fridge door (they swing with it: geoms on its body are added in fridge())
    # windows with curtains: over the sideboard and over the dining table (the wall behind it all)
    g = []
    for wx0, wx1 in [(-0.65, 0.15), (0.75, 1.85)]:
        wc, ww = (wx0 + wx1) / 2, (wx1 - wx0) / 2
        g += [
            vis("box", "window_glass", pos=f(wc, 2.598, 1.65), size=f(ww, 0.002, 0.5)),
            vis("box", "window_frame", pos=f(wc, 2.592, 2.16), size=f(ww + 0.04, 0.008, 0.02)),
            vis("box", "window_frame", pos=f(wc, 2.592, 1.14), size=f(ww + 0.04, 0.008, 0.02)),
            vis("box", "window_frame", pos=f(wx0 - 0.02, 2.592, 1.65), size="0.02 0.008 0.5"),
            vis("box", "window_frame", pos=f(wx1 + 0.02, 2.592, 1.65), size="0.02 0.008 0.5"),
            vis("box", "window_frame", pos=f(wc, 2.592, 1.65), size="0.012 0.008 0.5"),
            vis("box", "window_frame", pos=f(wc, 2.575, 1.115), size=f(ww + 0.06, 0.025, 0.012)),
            vis("capsule", "steel", fromto=f(wx0 - 0.3, 2.56, 2.25, wx1 + 0.3, 2.56, 2.25), size="0.008"),
            vis("box", "curtain", pos=f(wx0 - 0.2, 2.55, 1.66), size="0.13 0.012 0.59"),
            vis("box", "curtain", pos=f(wx1 + 0.2, 2.55, 1.66), size="0.13 0.012 0.59"),
        ]
    # a clock over the doorway-side wall, by the fridge
    g += [
        vis("cylinder", "clock_frame", fromto=f(-1.72, 2.6, 1.95, -1.72, 2.585, 1.95), size="0.16"),
        vis("cylinder", "clock_face", fromto=f(-1.72, 2.585, 1.95, -1.72, 2.58, 1.95), size="0.145"),
        vis("box", "clock_frame", pos=f(-1.72, 2.578, 1.99), size="0.006 0.002 0.05"),
        vis("box", "clock_frame", pos=f(-1.69, 2.578, 1.95), size="0.04 0.002 0.005"),
    ]
    # pictures: on the back wall between the corner and the wall cabinet (y -2.6 to -1.9: room for one), on
    # the side wall by the trash corner, and over the sofa's end
    g += [vis("box", "picture_frame", pos=f(-2.996, -2.32, 1.62), size=f(0.006, 0.2, 0.16)), vis("box", "canvas_0", pos=f(-2.992, -2.32, 1.62), size=f(0.004, 0.18, 0.14))]
    g += [vis("box", "picture_frame", pos=f(-1.5, -2.596, 1.6), size=f(0.18, 0.006, 0.24)), vis("box", "canvas_1", pos=f(-1.5, -2.592, 1.6), size=f(0.16, 0.004, 0.22))]
    g += [vis("box", "picture_frame", pos=f(2.596, -1.75, 1.55), size=f(0.006, 0.45, 0.3)), vis("box", "canvas_2", pos=f(2.592, -1.75, 1.55), size=f(0.004, 0.42, 0.27))]
    static("details_walls", g)
    # lamps over the dining table
    g = []
    for lx in (0.95, 1.55):
        g += [
            vis("capsule", "clock_frame", fromto=f(lx, 1.45, 2.6, lx, 1.45, 1.98), size="0.004"),
            vis("cylinder", "lamp_shade", pos=f(lx, 1.45, 1.92), size="0.13 0.06"),
            vis("sphere", "bulb", pos=f(lx, 1.45, 1.86), size="0.035"),
        ]
    # on the table: a vase of flowers and place mats (away from where things are put)
    g += [
        vis("cylinder", "vase", pos=f(1.65, 1.62, 0.84), size="0.045 0.09"),
        *[vis("capsule", "leaf", fromto=f(1.65, 1.62, 0.88, 1.65 + dx, 1.62 + dy, 1.04), size="0.004") for dx, dy in [(0.03, 0.02), (-0.03, 0.01), (0.0, -0.03), (0.02, -0.02)]],
        *[vis("sphere", f"flower_{k % 2}", pos=f(1.65 + dx, 1.62 + dy, 1.05), size="0.025") for k, (dx, dy) in enumerate([(0.03, 0.02), (-0.03, 0.01), (0.0, -0.03), (0.02, -0.02)])],
        *[vis("box", "placemat", pos=f(px, 1.72, 0.751), size="0.18 0.12 0.001") for px in (0.75, 1.25)],
    ]
    # plants in the corners (their pots solid), a reading lamp by the sofa, cushions and a throw on it
    g += [
        box(None, (2.35, 2.35, 0.17), (0.14, 0.14, 0.17), "pot"),
        *[vis("ellipsoid", "leaf", pos=f(2.35 + dx, 2.35 + dy, z), size=f(rx, rx, rz)) for dx, dy, z, rx, rz in [(0, 0, 0.6, 0.2, 0.3), (0.08, -0.06, 0.9, 0.15, 0.22), (-0.07, 0.05, 1.05, 0.13, 0.2)]],
        box(None, (-2.72, -2.35, 0.15), (0.12, 0.12, 0.15), "pot"),
        *[vis("ellipsoid", "leaf", pos=f(-2.72 + dx, -2.35 + dy, z), size=f(rx, rx, rz)) for dx, dy, z, rx, rz in [(0, 0, 0.5, 0.17, 0.25), (0.05, 0.05, 0.75, 0.13, 0.18)]],
        box(None, (0.12, -2.35, 0.015), (0.14, 0.14, 0.015), "lamp_base"),
        f'<geom type="capsule" fromto="{f(0.12, -2.35, 0.03, 0.12, -2.35, 1.5)}" size="0.015" material="lamp_base" contype="1" conaffinity="1"/>',
        vis("cylinder", "lamp_shade_light", pos=f(0.12, -2.35, 1.55), size="0.16 0.12"),
        vis("box", "cushion", pos=f(0.85, -1.93, 0.58), size="0.2 0.07 0.16", euler="-0.25 0 0"),
        vis("box", "cushion_2", pos=f(1.75, -1.93, 0.58), size="0.2 0.07 0.16", euler="-0.25 0 0"),
        vis("box", "throw", pos=f(1.45, -1.72, 0.428), size="0.3 0.3 0.01"),
    ]
    static("details_room", g)


MATERIALS = {
    **objects_.MATERIALS,
    "floor": "0.62 0.47 0.33 1", "wall": "0.93 0.91 0.87 1", "tile": "0.9 0.92 0.93 1",
    "cabinet": "0.55 0.63 0.57 1", "cabinet_door": "0.58 0.66 0.6 1", "countertop": "0.9 0.89 0.86 1",
    "plinth": "0.25 0.25 0.25 1", "steel": "0.75 0.76 0.78 1", "glass": "0.1 0.1 0.12 1",
    "fridge": "0.92 0.92 0.93 1", "fridge_inside": "0.95 0.97 1 1", "wood": "0.55 0.38 0.24 1",
    "fabric": "0.33 0.38 0.47 1", "rug": "0.72 0.66 0.58 1",
    # oven, cooktop, hood, glass doors
    "oven": "0.2 0.2 0.22 1", "oven_glass": "0.06 0.06 0.08 1", "oven_knob": "0.75 0.76 0.78 1", "burner": "0.3 0.3 0.32 1",
    "hood": "0.78 0.79 0.81 1", "cabinet_glass": "0.75 0.86 0.9 0.3",
    # inside the fridge
    "fridge_glass": "0.85 0.93 0.97 0.35", "fridge_trim": "0.97 0.97 0.98 1", "fridge_bin": "0.88 0.94 0.97 0.45",
    "fridge_light": 'rgba="1 0.98 0.92 1" emission="1"',
    "tomato": "0.85 0.15 0.1 1", "lettuce": "0.45 0.75 0.3 1", "pepper": "0.95 0.75 0.1 1", "carrot": "0.95 0.5 0.12 1",
    "lemon": "0.98 0.9 0.3 1", "cake": "0.98 0.92 0.82 1", "cake_top": "0.85 0.2 0.3 1", "cheese": "0.98 0.82 0.35 1",
    "jar_red": "0.75 0.15 0.12 1", "jar_green": "0.35 0.55 0.2 1", "lid": "0.85 0.85 0.86 1", "leftovers": "0.9 0.6 0.35 1",
    "water": "0.75 0.88 0.95 0.6", "milk": "0.97 0.97 0.97 1", "milk_top": "0.2 0.45 0.85 1", "juice": "0.98 0.6 0.1 1",
    "sauce": "0.55 0.25 0.1 1", "egg": "0.96 0.9 0.8 1",
    # prep sink, trash can, sideboard and radio
    "sink_drain": "0.35 0.35 0.37 1", "trash": "0.32 0.34 0.36 1", "trash_rim": "0.22 0.23 0.25 1", "trash_bag": "0.12 0.12 0.13 1",
    "sideboard": "0.5 0.35 0.23 1", "sideboard_front": "0.56 0.4 0.27 1", "brass": "0.8 0.65 0.3 1",
    "pot": "0.7 0.4 0.3 1", "leaf": "0.3 0.55 0.25 1", "jar_glass": "0.8 0.88 0.85 0.5",
    "radio": "0.72 0.2 0.16 1", "speaker": "0.25 0.22 0.2 1", "radio_dial": "0.9 0.88 0.82 1", "radio_panel": "0.95 0.85 0.55 1",
    "radio_button": "0.93 0.91 0.86 1", "radio_led": "0.2 0.22 0.2 1",
    # the microwave
    "microwave": "0.86 0.86 0.87 1", "microwave_inside": "0.75 0.76 0.78 1", "microwave_panel": "0.12 0.12 0.13 1",
    "microwave_window": "0.08 0.09 0.1 0.85", "microwave_display": 'rgba="0.45 0.95 0.55 1" emission="1"', "microwave_start": "0.2 0.65 0.3 1",
    # the details: floor and walls, things on the counters, lights, windows, pictures, plants
    "floor_tile": "0.82 0.8 0.76 1", "skirting": "0.95 0.94 0.92 1", "pan": "0.16 0.16 0.17 1", "towel": "0.85 0.35 0.3 1",
    "ceramic": "0.93 0.92 0.88 1", "spice_0": "0.75 0.3 0.15 1", "spice_1": "0.85 0.65 0.2 1", "spice_2": "0.35 0.5 0.25 1",
    "spice_3": "0.55 0.2 0.15 1", "soap": "0.3 0.7 0.4 0.85", "sponge": "0.95 0.8 0.25 1", "paper": "0.97 0.97 0.96 1",
    "appliance_dark": "0.13 0.13 0.14 1", "water_tank": "0.75 0.85 0.95 0.5", "led": 'rgba="1 0.95 0.85 1" emission="1"',
    "window_glass": 'rgba="0.75 0.86 0.95 1" emission="0.6"', "window_frame": "0.95 0.95 0.94 1", "curtain": "0.78 0.72 0.6 1",
    "clock_frame": "0.15 0.15 0.16 1", "clock_face": "0.97 0.97 0.95 1", "picture_frame": "0.35 0.25 0.18 1",
    "canvas_0": "0.35 0.55 0.7 1", "canvas_1": "0.85 0.6 0.35 1", "canvas_2": "0.5 0.65 0.45 1", "note_0": "0.98 0.92 0.45 1",
    "note_1": "0.6 0.85 0.95 1", "note_2": "0.95 0.65 0.75 1", "magnet_0": "0.85 0.2 0.2 1", "magnet_1": "0.2 0.45 0.85 1",
    "magnet_2": "0.25 0.65 0.3 1", "lamp_shade": "0.2 0.22 0.24 1", "bulb": 'rgba="1 0.92 0.75 1" emission="1"',
    "lamp_base": "0.25 0.24 0.22 1", "lamp_shade_light": 'rgba="0.95 0.9 0.8 1" emission="0.4"', "vase": "0.7 0.85 0.9 0.6",
    "flower_0": "0.95 0.45 0.55 1", "flower_1": "0.98 0.85 0.3 1", "placemat": "0.65 0.55 0.45 1", "cushion": "0.85 0.7 0.35 1",
    "cushion_2": "0.55 0.65 0.75 1", "throw": "0.75 0.5 0.45 1",
}


def main() -> None:
    counter_run()
    fridge()
    island()
    trash_can()
    sideboard()
    dining()
    living()
    room()
    objects()
    details()
    mats = "\n".join(f'    <material name="{k}" {v if "=" in v else f"rgba=\"{v}\""}/>' for k, v in MATERIALS.items())
    xml = f"""<mujoco model="kitchen environment">
  <!-- Written by tools/make_kitchen.py. The header matches MuJoCo-GS-Web's environments. -->

  <statistic center="-1 0 1.0" extent="3.0"/>

  <visual>
    <headlight diffuse="0.4 0.4 0.4" ambient="0.3 0.3 0.3" specular="0 0 0"/>
    <global azimuth="150" elevation="-20" offwidth="1280" offheight="960"/>
  </visual>

  <asset>
    <texture type="skybox" builtin="gradient" rgb1="0.85 0.87 0.9" rgb2="0.6 0.62 0.65" width="512" height="3072"/>
    <texture name="planks" type="2d" builtin="checker" width="512" height="512" rgb1="0.62 0.47 0.33" rgb2="0.58 0.43 0.3"/>
{mats.replace('<material name="floor" rgba="0.62 0.47 0.33 1"/>', '<material name="floor" texture="planks" texrepeat="6 30" texuniform="true"/>')}
  </asset>

  <default>
    <geom condim="4" friction="1.0 0.05 0.01"
          solref="0.002 1.0" solimp="0.95 0.99 0.001"/>
  </default>

  <worldbody>
    <light pos="-1 0 2.5" dir="0 0 -1" directional="true" diffuse="0.5 0.5 0.5" specular="0.1 0.1 0.1"/>
    <light pos="1 1.5 2.4" dir="0 0 -1" diffuse="0.4 0.4 0.4"/>

    <geom name="floor" size="0 0 0.05" type="plane" material="floor" contype="1" conaffinity="1" friction="0.5 0.02 0.01"/>
{chr(10).join(lines)}
  </worldbody>

  <contact>
{chr(10).join(f'    <exclude body1="{a}" body2="{b}"/>' for a, b in excludes)}
{chr(10).join(f'    {p}' for p in pairs)}
  </contact>

  <equality>
{chr(10).join(f'    {e}' for e in equalities)}
  </equality>
</mujoco>
"""
    OUT.parent.mkdir(parents=True, exist_ok=True)
    OUT.write_text(xml, encoding="utf-8", newline="\n")
    print(f"wrote {OUT} ({len(xml) / 1000:.1f} kB)")


if __name__ == "__main__":
    main()