"""Labels on the cut along the centre line (looking to starboard: bow to the left). blender -b --factory-startup models/M_Ship_v2_interior_season2.blend --python build/bl_section.py -- \n previews/Vessel_60_fore_decks_cut_along_the_centre_line_raw.png 7 47 -11.6 8.4 2400 python build/annotate_section.py """ import os from PIL import Image, ImageDraw, ImageFont S = os.path.dirname(os.path.abspath(__file__)) OUT = r"D:\HADAL - The Descent\models\vessel-interior\previews\Vessel_60_fore_decks_cut_along_the_centre_line.png" X_LEFT, Z_TOP, PPM = 47.0, 8.4, 60.0 def font(size, bold=True): for name in (("arialbd.ttf",) if bold else ()) + ("arial.ttf", "DejaVuSans.ttf"): try: return ImageFont.truetype(name, size) except OSError: pass return ImageFont.load_default() def P(x, z): return ((X_LEFT - x) * PPM, (Z_TOP - z) * PPM) im = Image.open(OUT[:-4] + "_raw.png").convert("RGB") d = ImageDraw.Draw(im) F, Fs = font(30), font(24) def label(x, z, text, anchor="mm", f=None, fill=(255, 235, 150)): f = f or F px, py = P(x, z) box = d.multiline_textbbox((px, py), text, font=f, anchor=anchor, align="center", spacing=4) d.rectangle([box[0] - 8, box[1] - 5, box[2] + 8, box[3] + 5], fill=(12, 12, 14)) d.multiline_text((px, py), text, font=f, fill=fill, anchor=anchor, align="center", spacing=4) def level(z, x0, x1, text, at, anchor, colour=(255, 90, 60)): (a, y), (b, _) = P(x0, z), P(x1, z) d.line([a, y, b, y], fill=colour, width=3) label(at[0], at[1], text, anchor=anchor, f=Fs) level(3.14, 46.5, 7.4, "command deck z 3.14", (46.6, 3.62), "lm") level(-1.96, 46.5, 15.3, "fore deck, raised z -1.96", (46.6, -1.48), "lm") level(-3.36, 15.2, 7.4, "sub bay deck z -3.36", (11.0, -3.86), "mm") label(38.2, 0.2, "SENSOR ROOM\n(the door to the lift room)") label(25.0, 0.2, "FORE PASSAGE, five bays\n(doors to habitation and quarters B)") label(23.0, 5.1, "control room corridor") label(12.2, -0.6, "SUB BAY", f=Fs) label(13.9, -2.72, "landing\nand steps", f=Fs) level(-7.95, 46.5, 37.6, "lower deck z -7.95", (46.6, -7.47), "lm") label(26.6, -5.9, "LOWER DECK, the room underneath\n10.8 x 20.8 m, 3.9 m high") label(35.4, -8.7, "its last bay lies under the lift room", f=Fs) # the rise (ax, ay), (_, by) = P(16.6, -3.36), P(16.6, -1.96) d.line([ax, ay, ax, by], fill=(255, 90, 60), width=4) d.polygon([(ax - 9, by + 16), (ax + 9, by + 16), (ax, by)], fill=(255, 90, 60)) label(17.0, -2.66, "+1.40 m", anchor="rm", f=Fs) d.rectangle([0, im.height - 40, im.width, im.height], fill=(12, 12, 14)) d.text((14, im.height - 34), "Cut along the centre line, looking to starboard: bow to the left, sub bay (moon pool) to the right. Even light, lamps off.", font=font(22, False), fill=(230, 230, 230)) im.save(OUT) print("ok", OUT, im.size)