--- "src/_\345\210\266\344\275\234\343\203\231\343\203\274\343\202\271/hakobu_motion.py" 2026-10-30 15:17:17.000000000 +0900 +++ tools/hakobu_motion.py 2026-11-24 16:39:30.029274792 +0900 @@ -103,14 +103,24 @@ a[soft, :3] = np.minimum(a[soft, :3], 55) return Image.fromarray(a) bot.body = _clean_wheels(bot.body) -bg = np.array(Image.open(os.path.join(hk.ASSET_DIR, "g_05.png")).convert("RGB")) +def _cover(im, W_, H_): + """縦横比を保ったまま画面いっぱいに広げて、はみ出しを中央で切る(2026-11-24 全画面の感情型ショート)""" + k = max(W_ / im.width, H_ / im.height); im = im.resize((int(im.width * k + 0.5), int(im.height * k + 0.5)), Image.LANCZOS) + x0, y0 = (im.width - W_) // 2, (im.height - H_) // 2 + return im.crop((x0, y0, x0 + W_, y0 + H_)) +_CANVAS = os.environ.get("HK_CANVAS") # 例 "1080x1920"(全画面の寄りの絵)。なければ今までどおり 848x1056 +if _CANVAS: + _cw, _ch = (int(v) for v in _CANVAS.split("x")) + bg = np.array(_cover(Image.open(os.path.join(hk.ASSET_DIR, "g_05.png")).convert("RGB"), _cw, _ch)) +else: + bg = np.array(Image.open(os.path.join(hk.ASSET_DIR, "g_05.png")).convert("RGB")) Hh, Ww = bg.shape[:2] # 体を画面に置く: ディスプレイの幅を古い体(180px)にそろえ、足もとを y=905・中心を x=470 に(FVのロボットと同じ立ち位置) _ba = np.array(bot.body)[..., 3]; _bys, _bxs = np.nonzero(_ba > 10) _sys, _sxs = np.nonzero(bot.screen_mask) -BSC = 180.0 / (_sxs.max() - _sxs.min()) -BOX = 470 - BSC * (_bxs.min() + _bxs.max()) / 2 -BOY = 905 - BSC * _bys.max() +BSC = float(os.environ.get("HK_DISPW", 180)) / (_sxs.max() - _sxs.min()) # ディスプレイの幅(px)。寄りの絵は大きく +BOX = float(os.environ.get("HK_CX", 470)) - BSC * (_bxs.min() + _bxs.max()) / 2 +BOY = float(os.environ.get("HK_FOOT", 905)) - BSC * _bys.max() def to_canvas(arr): """体の座標で描いた RGBA を、画面(Ww×Hh)の立ち位置へ""" return cv2.warpAffine(arr, np.float32([[BSC, 0, BOX], [0, BSC, BOY]]), (Ww, Hh), flags=cv2.INTER_LINEAR, borderValue=(0, 0, 0, 0)) @@ -134,7 +144,7 @@ SHADOW_W = (_xs.max() - _xs.min()) * 0.62 _e = os.path.join(hk.ASSET_DIR, "bg_empty.png") # ロボットを消した病室(LaMa で埋めた) -plate_empty = np.array(Image.open(_e).convert("RGB")).astype(np.float32) if os.path.exists(_e) else plate_clean +plate_empty = np.array(_cover(Image.open(_e).convert("RGB"), Ww, Hh)).astype(np.float32) if os.path.exists(_e) else plate_clean def shadow(height, x=0.0, widen=1.0, y=0.0): """足もとの影(跳ぶほど小さく薄く)。返り値: 暗くする量 0〜1 の画像""" @@ -1570,7 +1580,7 @@ HAT[0] = getattr(pat, "hat", None) BG = None if getattr(pat, "bg", None): # 話ごとの背景(_ショート専用/背景/第NN話.png) - BG = np.array(Image.open(pat.bg).convert("RGB").resize((Ww, Hh), Image.LANCZOS)).astype(np.float32) + BG = np.array(_cover(Image.open(pat.bg).convert("RGB"), Ww, Hh)).astype(np.float32) p = subprocess.Popen(["ffmpeg", "-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "rgb24", "-s", f"{Ww}x{Hh}", "-r", str(FPS), "-i", "-", "-c:v", "libx264", "-pix_fmt", "yuv420p", "-crf", "18", out], stdin=subprocess.PIPE) @@ -1587,7 +1597,7 @@ acc /= k al = acc[..., 3:4] / 255 ys_, xs_ = np.nonzero(acc[..., 3] > 40) # 体がショートの映像の窓(y172〜937)からはみ出していないか - if len(ys_) and (ys_.min() < WIN[0] or ys_.max() > WIN[1] or xs_.min() <= 1 or xs_.max() >= Ww - 2): + if not _CANVAS and len(ys_) and (ys_.min() < WIN[0] or ys_.max() > WIN[1] or xs_.min() <= 1 or xs_.max() >= Ww - 2): CUT.append((round(t, 2), int(ys_.min()), int(ys_.max()))) mo = pat.motion(t) if BG is not None or getattr(pat, "empty", False):