A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date. Images, audio, models and binaries go through Git LFS (.gitattributes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
325 lines
13 KiB
Python
325 lines
13 KiB
Python
"""The story trailer: told the way the game opens. The Director's call from Earth in the real opening film, cut between the
|
|
phone in your hand and his face filling the frame; the planet; his assistant in your ear; then the game, with his calls
|
|
and her warnings over it, to the hundred percent and his joke about a second planet over the logo.
|
|
|
|
Every s_ take carries a sounds.txt from the game (frame, name, volume, pitch, metres off), so a shot brings its own voices
|
|
and effects with it, cut to exactly the stretch of the take it shows. The music bed is built here: silence under the call,
|
|
the game's music from the planet on, ducked under every line.
|
|
|
|
py -I cut.py story.py out.mp4 [from to]
|
|
"""
|
|
import os
|
|
import wave
|
|
|
|
import numpy as np
|
|
|
|
from cut import PROJECT, SR, Logo, Shot, Type, decode
|
|
from looks import AUDIO, GOLD, HOT, LOGO, NIGHT, PLAY, SPACE, clip # noqa: F401
|
|
|
|
ROLLS = os.path.join(PROJECT, r"Builds\Trailer\rolls3")
|
|
OUT = os.path.join(PROJECT, r"Builds\Trailer\story")
|
|
os.makedirs(OUT, exist_ok=True)
|
|
PUNCH, SHAKE, ABERRATE = 0.006, 1.2, 0.6
|
|
STUDIO = {"sat": 1.02, "contrast": 1.04, "gain": 1.0, "tint": (0, 0, 0)}
|
|
B = 60 / 79.5
|
|
|
|
|
|
# ───────────────────────── what the game heard ─────────────────────────
|
|
|
|
_logs = {}
|
|
|
|
|
|
def log(take):
|
|
base = take.split("@")[0]
|
|
if base not in _logs:
|
|
rows = []
|
|
path = os.path.join(ROLLS, base, "sounds.txt")
|
|
if os.path.exists(path):
|
|
for line in open(path, encoding="utf-8"):
|
|
p = line.rstrip("\n").split("\t")
|
|
if len(p) >= 5:
|
|
rows.append((int(p[0]) / 60.0, p[1], float(p[2].replace(",", ".")), float(p[4].replace(",", "."))))
|
|
_logs[base] = rows
|
|
return _logs[base]
|
|
|
|
|
|
def when(take, name, n=0):
|
|
hits = [t for t, nm, _, _ in log(take) if nm == name]
|
|
if len(hits) <= n:
|
|
raise SystemExit(f"{take}: no {name} #{n} in sounds.txt")
|
|
return hits[n]
|
|
|
|
|
|
_lengths = {}
|
|
|
|
|
|
def length(name):
|
|
if name not in _lengths:
|
|
with wave.open(clip(name)) as w:
|
|
_lengths[name] = w.getnframes() / w.getframerate()
|
|
return _lengths[name]
|
|
|
|
|
|
def voice(name):
|
|
return name.startswith("dir_") or name.startswith("asst_")
|
|
|
|
|
|
# ───────────────────────── laying shots ─────────────────────────
|
|
|
|
SHOTS = []
|
|
HEAR = [] # (at, take, from, seconds): that stretch of the take's sound, at that time
|
|
EXTRA = [] # sounds by hand: (at, clip path, gain[, seconds[, offset]])
|
|
now = 0.0
|
|
|
|
|
|
def put(take, start, secs, hear=True, sound=None, **kw):
|
|
"""The next shot: `secs` of `take` from `start` seconds in. Its own sound comes with it unless hear is False, or
|
|
sound=(take, from) brings another stretch instead."""
|
|
global now
|
|
SHOTS.append(Shot(take, now, now + secs, start=start, **kw))
|
|
if hear:
|
|
st, sf = sound if sound else (take, start)
|
|
HEAR.append((now, st, sf, secs))
|
|
now += secs
|
|
return now
|
|
|
|
|
|
def gap(secs):
|
|
global now
|
|
now += secs
|
|
|
|
|
|
# ───────────────────────── the cut ─────────────────────────
|
|
|
|
I, BOSS = "s_intro", "s_intro@s_boss"
|
|
RING = when(I, "phone_ring")
|
|
V = when(I, "dir_intro")
|
|
SPACE_AT = when(I, "space_rumble")
|
|
TAG = when(I, "dir_intro_tag")
|
|
|
|
# 1. the planks in the half dark, the phone ringing, coming up
|
|
put(I, RING - 1.6, V - (RING - 1.6), grade=PLAY)
|
|
# 2. the call: (from, to) in the line, and whose picture
|
|
CALL = [
|
|
(0.0, 2.32, I), # Listen up, you incompetent idiots!
|
|
(2.32, 6.2, BOSS), # EARTH IS OUT OF GRASS! NO GRASS!
|
|
(6.2, 9.2, I), # NOT A SINGLE DAMN BLADE!
|
|
(15.9, 20.2, BOSS), # And Earth needs EVERY. SINGLE. BLADE.
|
|
(20.2, 23.3, I), # I want it CUT! I want it PACKED!
|
|
(23.3, 25.95, BOSS), # And I want it SHIPPED BACK TO EARTH!
|
|
(25.95, 28.8, I), # I don't care if you have to use nail scissors!
|
|
(28.8, 33.0, BOSS), # NOW GET OUT THERE AND MOW THAT GODDAMN PLANET!
|
|
]
|
|
for a, b, who in CALL:
|
|
kw = {"grade": STUDIO if who == BOSS else PLAY}
|
|
if who == BOSS and a == 15.9:
|
|
kw["zoom"] = (1.0, 1.18)
|
|
put(who, V + a, b - a, **kw)
|
|
# 3. the phone goes, the head comes up, the cuts climb to the planet; his deadpan over it
|
|
put(I, V + 33.0, SPACE_AT - (V + 33.0), grade=PLAY)
|
|
MUSIC_AT = now
|
|
# the planet from orbit: the composited orbit take, with the film's own sound (the rumble, his "we take grass very seriously")
|
|
put("o_space_k", 1.0, TAG + length("dir_intro_tag") + 0.5 - SPACE_AT, sound=(I, SPACE_AT), grade=SPACE, zoom=(1.0, 1.05))
|
|
|
|
# 4. her hello: "Hi. I'm the Director's assistant. I'll be in your ear the whole time. He shouts. I explain."
|
|
# the film ends and she starts inside s_intro; s_after picks up 4 frames after s_intro's last
|
|
ASST = "s_after@s_asst"
|
|
A = when(I, "asst_hello")
|
|
AFTER = (3420 + 4) / 60.0
|
|
put(I, A - 0.3, 3.95, grade=PLAY) # her window in the corner of your view
|
|
put(BOSS, V + 3.0, 0.95, sound=(I, A + 4.62), grade=STUDIO) # He shouts. (over him shouting)
|
|
put(ASST, A + 6.05 - AFTER, 1.3, sound=(I, A + 6.05), grade=STUDIO) # I explain.
|
|
|
|
# 5. the game: the tools one after another, the crew
|
|
put("g_scissors", 0.3, B * 3, hear=False, grade=PLAY)
|
|
put("g_shears", 0.8, B * 2, hear=False, grade=PLAY)
|
|
put("g_sickle", 0.8, B * 2, hear=False, grade=PLAY)
|
|
put("g_scythe", 1.2, B * 3, hear=False, grade=PLAY)
|
|
put("g_wide", 1.5, B * 3, hear=False, grade=PLAY)
|
|
TOOLS_AT = SHOTS[-5].at
|
|
put("g_coop", 1.5, B * 4, hear=False, grade=PLAY)
|
|
put("v_sixteen", 0.9, B * 4, hear=False, grade=HOT)
|
|
COOP_AT = SHOTS[-2].at
|
|
|
|
# 6. belts: "Conveyor belts! Grass that moves BY ITSELF! ... This is what peak civilization looks like."
|
|
DB, DBB = "s_dir_belts", "s_dir_belts@s_boss"
|
|
VB = when(DB, "dir_belts")
|
|
put("k_belt", 0.6, 5.3, hear=False, sound=None, grade=HOT)
|
|
HEAR.append((SHOTS[-1].at, DB, VB - 0.1, 5.3))
|
|
put(DBB, VB + 6.3, 4.2, grade=STUDIO)
|
|
BELT_AT = SHOTS[-2].at
|
|
|
|
# 7. the combine: "A COMBINE HARVESTER?! (laughs) NOW we're talking! Earth's lawns will be green by Christmas!"
|
|
DC, DCB = "s_dir_combine", "s_dir_combine@s_boss"
|
|
VC = when(DC, "dir_combine")
|
|
put(DCB, VC - 0.1, 3.85, grade=STUDIO)
|
|
put("c_combine", 0.6, 2.4, hear=False, grade=HOT)
|
|
HEAR.append((SHOTS[-1].at, DC, VC + 3.75, 2.4))
|
|
put("c_combine_over", 1.0, 3.3, hear=False, grade=HOT)
|
|
HEAR.append((SHOTS[-1].at, DC, VC + 6.15, 3.3))
|
|
|
|
# 8. the weather: a twister over the meadow, the warning in your ear, and up you go
|
|
put("s_storm", 2.0, 3.6, hear=False, grade=HOT)
|
|
T0, TA = "s_thrown", "s_thrown@s_asst"
|
|
VT = when(T0, "asst_twister")
|
|
FLING = when(T0, "throw_whoosh")
|
|
VN = when(T0, "asst_thrown")
|
|
put(T0, VT - 0.2, 1.8, grade=PLAY) # Twister incoming!
|
|
put(T0, FLING - 1.6, VN - 0.1 - (FLING - 1.6), grade=PLAY) # it comes, and you go up
|
|
put(TA, VN - 0.1, length("asst_thrown") + 0.25, grade=STUDIO) # You got thrown by a twister. Noted.
|
|
STORM_AT = SHOTS[-4].at
|
|
|
|
# 9. the saucer, and him on the phone about it
|
|
U0, UB = "s_ufocall", "s_ufocall@s_boss"
|
|
VU = when(U0, "dir_ufo")
|
|
put("s_ufo", 4.0, 3.4, sound=(U0, VU - 1.65), grade=GOLD) # (the call connects) Was that a UFO?!
|
|
put(UB, VU + 2.6, 4.95, grade=STUDIO) # Listen to me. Do NOT let them take the grass.
|
|
put("s_ufo_top", 3.0, 3.1, hear=False, grade=GOLD)
|
|
HEAR.append((SHOTS[-1].at, U0, VU + 8.6, 3.1)) # THAT GRASS BELONGS TO EARTH!
|
|
UFO_AT = SHOTS[-3].at
|
|
|
|
# 10. everybody, everything, the whole ball
|
|
put("f_air", 0.6, B * 4, hear=False, grade=HOT)
|
|
put("n_line", 0.8, B * 3, hear=False, grade=NIGHT)
|
|
put("e_cut_k", 2.0, B * 5, hear=False, speed=1.6, zoom=(1.0, 1.05), grade=SPACE)
|
|
BIG_AT = SHOTS[-3].at
|
|
|
|
# 11. one hundred percent, and the joke over the logo
|
|
M, MB = "s_dir_m100", "s_dir_m100@s_boss"
|
|
VM = when(M, "dir_m100")
|
|
put(MB, VM - 0.1, 1.75, grade=STUDIO) # One hundred percent.
|
|
put(MB, VM + 4.1, 0.9, grade=STUDIO) # You did it.
|
|
put(MB, VM + 5.8, 3.4, grade=STUDIO, zoom=(1.0, 1.12)) # You magnificent idiots actually did it.
|
|
put("e_up", 0.2, 2.2, hear=False, speed=0.6, zoom=(1.02, 1.06), grade=dict(GOLD, sat=1.2))
|
|
HEAR.append((SHOTS[-1].at, M, VM + 10.4, 2.2)) # Earth has grass again!
|
|
LOGO_AT = now
|
|
put("e_up", 1.52, 9.0, hear=False, speed=0.45, zoom=(1.06, 1.12), grade=dict(GOLD, sat=1.2))
|
|
HEAR.append((LOGO_AT + 0.6, M, VM + 14.1, 3.05)) # Now. About the second planet.
|
|
HEAR.append((LOGO_AT + 4.4, M, VM + 19.0, 0.9)) # I'm kidding.
|
|
HEAR.append((LOGO_AT + 6.3, M, VM + 21.5, 2.2)) # Unless?
|
|
END = now
|
|
KEEP = [(0.0, END)]
|
|
|
|
|
|
# ───────────────────────── the sound ─────────────────────────
|
|
|
|
def gather():
|
|
pieces, sfx = [], []
|
|
for at, take, frm, secs in HEAR:
|
|
for ts, name, vol, dist in log(take):
|
|
if not os.path.exists(clip(name)):
|
|
continue
|
|
if voice(name):
|
|
L = length(name)
|
|
a, b = max(ts, frm), min(ts + L, frm + secs)
|
|
if b - a > 0.02:
|
|
pieces.append([at + a - frm, name, b - a, a - ts])
|
|
elif frm <= ts < frm + secs:
|
|
fall = 1.0 / (1.0 + dist / 10.0) if dist > 0 else 1.0
|
|
sfx.append((at + ts - frm, clip(name), min(1.0, vol) * fall * 0.85))
|
|
# a line laid in pieces that follow on in both picture and recording is one piece: no dip at the cut
|
|
pieces.sort(key=lambda p: (p[1], p[0]))
|
|
merged = []
|
|
for p in pieces:
|
|
q = merged[-1] if merged else None
|
|
if q and q[1] == p[1] and abs(q[0] + q[2] - p[0]) < 0.03 and abs(q[3] + q[2] - p[3]) < 0.03:
|
|
q[2] += p[2]
|
|
else:
|
|
merged.append(p)
|
|
voices = [(a, clip(n), 1.0, d, o) for a, n, d, o in merged]
|
|
return voices, sfx
|
|
|
|
|
|
VOICES, HEARD = gather()
|
|
|
|
# loops the takes don't log
|
|
EXTRA += [(STORM_AT, clip("twister_loop"), 0.5, 9.0), (STORM_AT, clip("wind_loop"), 0.35, 9.0), (STORM_AT + 0.4, clip("thunder"), 0.5)]
|
|
EXTRA += [(UFO_AT, clip("ufo_hum_loop"), 0.4, 12.0), (UFO_AT + 9.0, clip("ufo_beam_loop"), 0.35, 3.1)]
|
|
EXTRA += [(BELT_AT, clip("conveyor_loop"), 0.35, 5.3)] if os.path.exists(clip("conveyor_loop")) else []
|
|
EXTRA += [(TOOLS_AT + 0.3 + 0.6 * i, clip("snip"), 0.3) for i in range(4)]
|
|
EXTRA += [(TOOLS_AT + B * 5 + 0.3 + 0.75 * i, clip("scythe_swing_%d" % (i % 3 + 1)), 0.3) for i in range(8)]
|
|
EXTRA += [(TOOLS_AT, clip("grass_rustle_loop"), 0.3, B * 13)]
|
|
EXTRA += [(LOGO_AT, clip("milestone"), 0.6), (LOGO_AT + 0.1, clip("confetti"), 0.6)]
|
|
SFX = VOICES + HEARD + EXTRA
|
|
|
|
|
|
def bed():
|
|
"""Silence under the call; the music from the planet on, under every line ducked, out before the joke."""
|
|
n = int((END + 2) * SR)
|
|
out = np.zeros((n, 2), np.float32)
|
|
song = decode(clip("music_game_loop"))
|
|
i = int(MUSIC_AT * SR)
|
|
stop = int((LOGO_AT + 1.0) * SR)
|
|
k = 0
|
|
while i < stop:
|
|
m = min(len(song), stop - i)
|
|
out[i:i + m] += song[:m] * 0.8
|
|
i += m
|
|
k += 1
|
|
# rise in over the first second and a half, out over the last one
|
|
a = int(MUSIC_AT * SR)
|
|
ramp = int(1.5 * SR)
|
|
out[a:a + ramp] *= np.linspace(0.3, 1.0, ramp)[:, None]
|
|
tail = int(1.0 * SR)
|
|
out[stop - tail:stop] *= np.linspace(1.0, 0.0, tail)[:, None]
|
|
# under the voices
|
|
duck = np.ones(n, np.float32)
|
|
for at, _, _, d, _ in VOICES:
|
|
s, e = int((at - 0.15) * SR), int((at + d + 0.25) * SR)
|
|
duck[max(0, s):min(n, e)] = 0.32
|
|
kernel = int(0.2 * SR)
|
|
duck = np.convolve(duck, np.ones(kernel) / kernel, mode="same").astype(np.float32)
|
|
out *= duck[:, None]
|
|
path = os.path.join(OUT, "bed.wav")
|
|
raw = (np.clip(out, -1, 1) * 32767).astype(np.int16)
|
|
with wave.open(path, "wb") as f:
|
|
f.setnchannels(2)
|
|
f.setsampwidth(2)
|
|
f.setframerate(SR)
|
|
f.writeframes(raw.tobytes())
|
|
return path
|
|
|
|
|
|
TRACK = bed()
|
|
TRACK_GAIN = 1.0
|
|
|
|
|
|
def REACT(t):
|
|
return 0.0 if t < MUSIC_AT else 0.25
|
|
|
|
|
|
def BLACK(t):
|
|
if t < 0.6:
|
|
return 1 - t / 0.6
|
|
if t > END - 1.2:
|
|
return min(1.0, (t - (END - 1.2)) / 1.2)
|
|
return 0.0
|
|
|
|
|
|
FLASH = [(MUSIC_AT, 0.35), (LOGO_AT, 0.6)]
|
|
|
|
|
|
def caption(text, at, secs, size=72):
|
|
return Type(text, at + 0.1, at + secs - 0.1, size, y=0.86, how="rise")
|
|
|
|
|
|
TYPE = [
|
|
caption("START WITH NAIL SCISSORS", TOOLS_AT, B * 5),
|
|
caption("WORK YOUR WAY UP TO THE SCYTHE", TOOLS_AT + B * 7, B * 6),
|
|
caption("MOW WITH YOUR FRIENDS", COOP_AT, B * 4),
|
|
caption("UP TO 16 PLAYERS", COOP_AT + B * 4, B * 4),
|
|
caption("BUILD A GRASS FACTORY", BELT_AT, 5.3),
|
|
caption("WEATHER THAT FIGHTS BACK", STORM_AT, 3.6),
|
|
caption("A WHOLE PLANET TO CLEAR", BIG_AT + B * 7, B * 5),
|
|
Logo(LOGO, LOGO_AT, END, 1180, 0.4),
|
|
Type("WISHLIST NOW ON STEAM", LOGO_AT + 1.6, END, 76, y=0.76, how="rise"),
|
|
Type("CO-OP FOR 1 TO 16 PLAYERS", LOGO_AT + 2.4, END, 50, y=0.85, how="rise", colour=(226, 240, 200)),
|
|
]
|
|
|
|
if __name__ == "__main__":
|
|
for s in SHOTS:
|
|
print(f"{s.at:7.2f} {s.end - s.at:5.2f} {s.take:28s} from {s.start:6.2f}")
|
|
print("music at %.2f, logo at %.2f, end %.2f" % (MUSIC_AT, LOGO_AT, END))
|
|
for v in VOICES:
|
|
print("voice %7.2f %-14s %5.2f from %5.2f" % (v[0], os.path.basename(v[1]), v[3], v[4]))
|