Grass Cutters Together: the project as of moon-sweepers f3666f0
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>
This commit is contained in:
393
Tools/Trailer/polden.py
Normal file
393
Tools/Trailer/polden.py
Normal file
@ -0,0 +1,393 @@
|
||||
"""The scripted trailer, Docs/TRAILER_SCRIPT.md (the Polden workshop way): the Director's call opens it, one pair of nail
|
||||
scissors against the planet, then a co-op evening told by four players on voice chat (foreman, gremlin, engineer,
|
||||
tourist), the loop from hands to machines to factory, the planet fighting back, the bald planet, and the Director again.
|
||||
|
||||
Every line is an Eleven v4 take: the crew's put through a headset filter (ArtSource/Trailer/crew), the Director's and the
|
||||
assistant's clean (ArtSource/Trailer/boss). The music is ElevenLabs too
|
||||
(ArtSource/Trailer/polden_music.mp3); under the storm it goes dull and the storm loop comes up.
|
||||
|
||||
py -I cut.py polden.py out.mp4 [from to]
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import wave
|
||||
|
||||
import numpy as np
|
||||
|
||||
from cut import PROJECT, SR, Logo, Shot, Type, decode
|
||||
from looks import GOLD, HOT, LOGO, NIGHT, PLAY, SPACE, clip
|
||||
|
||||
TR = os.path.join(PROJECT, "Builds", "Trailer")
|
||||
ROLLS = TR
|
||||
OUT = os.path.join(TR, "polden")
|
||||
os.makedirs(OUT, exist_ok=True)
|
||||
CREW = os.path.join(PROJECT, "ArtSource", "Trailer", "crew")
|
||||
MUSIC = os.path.join(PROJECT, "ArtSource", "Trailer", "polden_music.mp3")
|
||||
PUNCH, SHAKE, ABERRATE = 0.008, 1.5, 0.8
|
||||
STUDIO = {"sat": 1.02, "contrast": 1.04, "gain": 1.0, "tint": (0, 0, 0)}
|
||||
B = 60 / 129.2 # the music's beat
|
||||
|
||||
|
||||
def roll(take):
|
||||
base = take.split("@")[0]
|
||||
for d in ("rolls_z", "rolls3", "rolls_1105"):
|
||||
if os.path.isdir(os.path.join(TR, d, base)):
|
||||
return os.path.join(TR, d, take)
|
||||
raise SystemExit("no take " + take)
|
||||
|
||||
|
||||
# ───────────────────────── what the game heard ─────────────────────────
|
||||
|
||||
_logs = {}
|
||||
|
||||
|
||||
def log(take):
|
||||
base = take.split("@")[0]
|
||||
if base not in _logs:
|
||||
rows = []
|
||||
path = os.path.join(os.path.dirname(roll(take)), 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]
|
||||
|
||||
|
||||
def seconds(path):
|
||||
with wave.open(path) as w:
|
||||
return w.getnframes() / w.getframerate()
|
||||
|
||||
|
||||
# ───────────────────────── laying shots ─────────────────────────
|
||||
|
||||
SHOTS, HEAR, EXTRA, LINES, SUBS = [], [], [], [], []
|
||||
now = 0.0
|
||||
|
||||
|
||||
def put(take, start, secs, hear=False, sound=None, **kw):
|
||||
global now
|
||||
SHOTS.append(Shot(roll(take), now, now + secs, start=start, **kw))
|
||||
if hear or sound:
|
||||
st, sf = sound if sound else (take, start)
|
||||
HEAR.append((now, st, sf, secs))
|
||||
now += secs
|
||||
return now
|
||||
|
||||
|
||||
WHO = {"fo": (255, 214, 90), "gr": (255, 140, 90), "en": (140, 220, 255), "to": (190, 255, 150)}
|
||||
|
||||
|
||||
def say(name, at, text, gain=1.0):
|
||||
"""A crew line on voice chat, with its subtitle (Steam plays trailers muted until you click)."""
|
||||
path = os.path.join(CREW, name + ".wav")
|
||||
d = seconds(path)
|
||||
LINES.append((at, path, 1.15 * gain))
|
||||
SUBS.append((at, at + max(d, 1.0) + 0.25, text, WHO[name[:2]]))
|
||||
return at + d
|
||||
|
||||
|
||||
def sub(at, secs, text, colour=(255, 255, 255)):
|
||||
SUBS.append((at, at + secs, text, colour))
|
||||
|
||||
|
||||
LIP = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lipsync.json")))
|
||||
TALK = [] # the Director's and the assistant's lines: (at, clip, gain, seconds, from)
|
||||
|
||||
|
||||
def speak(line, text, zooms=((1.0, 1.04), (1.12, 1.16)), colour=(255, 255, 255)):
|
||||
"""A line of theirs, the trailer's own take of it (ArtSource/Trailer/boss). Shown as ElevenLabs' talking avatar of
|
||||
the figure (rolls_z/el_<line>, made from that same take) when there is one; otherwise in their own filmed loops, cut
|
||||
where the mouth moves with it (lipsync.py chose the stretches). The shot ends with the voice: no air after it."""
|
||||
L = LIP[line]
|
||||
path = os.path.join(PROJECT, L["clip"])
|
||||
secs = L["to"] - L["from"]
|
||||
at = now
|
||||
if os.path.isdir(os.path.join(TR, "rolls_z", "el_" + line)):
|
||||
put("el_" + line, 0.0, secs, grade=STUDIO, zoom=zooms[0])
|
||||
else:
|
||||
for k, p in enumerate(L["parts"]):
|
||||
put(p["take"], 0.0, min(p["secs"], at + secs - now), grade=STUDIO, zoom=zooms[k % len(zooms)])
|
||||
TALK.append((at, path, 1.0, secs, L["from"]))
|
||||
sub(at + 0.05, now - at - 0.1, text, colour)
|
||||
return at
|
||||
|
||||
|
||||
# ───────────────────────── 1 · We have a situation ─────────────────────────
|
||||
|
||||
speak("earth", "EARTH IS OUT OF GRASS! NO GRASS!")
|
||||
TITLE1 = 0.6
|
||||
speak("scissors", "I don't care if you have to use nail scissors!", zooms=((1.1, 1.18),))
|
||||
BLADE_AT = now
|
||||
put("z_blade", 0.5, 4.0, grade=HOT)
|
||||
say("to_nails", BLADE_AT + 0.4, "...these are nail scissors.")
|
||||
EXTRA += [(BLADE_AT + 0.15 + 0.42 * i, clip("snip"), 0.35) for i in range(4)]
|
||||
EXTRA += [(BLADE_AT, clip("grass_rustle_loop"), 0.35, 4.0), (BLADE_AT, clip("ambience_loop"), 0.5, 4.0)]
|
||||
MUSIC_AT = now # the music starts on the cut to the crew; its big hit then lands on the bald planet
|
||||
|
||||
# ───────────────────────── 2 · Meet the crew ─────────────────────────
|
||||
|
||||
CREW_AT = now
|
||||
put("v_touch", 0.3, 3.0, grade=GOLD)
|
||||
say("fo_rows", CREW_AT + 0.15, "Okay team. Rows. Straight rows.")
|
||||
t = put("p_4", 1.0, 1.1, grade=GOLD)
|
||||
say("gr_big", t - 1.0, "Wait... how big is this planet?")
|
||||
WHOLE_AT = now
|
||||
put("o_dive", 0.6, 2.4, grade=SPACE)
|
||||
t = now
|
||||
put("o_giant", 0.4, 3.0, grade=GOLD)
|
||||
say("to_sky", t + 0.2, "Guys... look at the sky.")
|
||||
|
||||
# ───────────────────────── 3 · By hand ─────────────────────────
|
||||
|
||||
HAND_AT = now
|
||||
put("g_scissors", 0.6, B * 3, grade=PLAY)
|
||||
put("c_swing", 0.4, B * 3, grade=HOT)
|
||||
t = now
|
||||
put("g_deposit", 1.0, B * 4, grade=PLAY)
|
||||
say("fo_hand", t + 0.2, "Hand it in, hand it in!")
|
||||
CATCH_AT = now
|
||||
put("z_catch", 0.55, 2.5, hear=True, grade=HOT)
|
||||
say("gr_catch", CATCH_AT + 0.25, "Catch!")
|
||||
THROW, HIT = 0.32 * 3.2 - 0.55, 0.32 * 3.2 + 0.42 - 0.55
|
||||
EXTRA += [(CATCH_AT + THROW, clip("throw_whoosh"), 0.7), (CATCH_AT + HIT, clip("cardboard_thud_1"), 1.0), (CATCH_AT + HIT + 0.02, clip("land"), 0.6)]
|
||||
SIXTEEN_AT = now
|
||||
put("v_sixteen", 0.8, B * 6, grade=HOT)
|
||||
|
||||
# ───────────────────────── 4 · Bigger blades ─────────────────────────
|
||||
|
||||
BLADES_AT = now
|
||||
put("g_shears", 0.8, B * 2, grade=PLAY)
|
||||
put("g_sickle", 0.8, B * 2, grade=PLAY)
|
||||
put("g_scythe", 1.2, B * 2, grade=PLAY)
|
||||
put("g_wide", 1.5, B * 2, grade=PLAY)
|
||||
put("c_tractor", 1.6, B * 3, grade=HOT)
|
||||
t = now
|
||||
put("g_combine", 1.0, B * 3, grade=PLAY)
|
||||
say("fo_back", t + 0.1, "We are SO back.")
|
||||
put("c_combine", 0.6, B * 4, grade=HOT)
|
||||
t = now
|
||||
put("c_combine_top", 0.5, B * 4, grade=HOT)
|
||||
say("en_pickup", t + 0.1, "Who took the pickup?")
|
||||
t = now
|
||||
put("w_wheels", 0.3, B * 5, grade=HOT)
|
||||
say("gr_nobody", t + 0.15, "Nobody!")
|
||||
EXTRA += [(BLADES_AT + B * 2 * i + 0.1, clip("scythe_swing_%d" % (i % 3 + 1)), 0.35) for i in range(4)]
|
||||
EXTRA += [(BLADES_AT + B * 8, clip("combine_engine_loop"), 0.3, B * 14)]
|
||||
|
||||
# ───────────────────────── 5 · Let the factory do it ─────────────────────────
|
||||
|
||||
FACTORY_AT = now
|
||||
put("k_grow", 0.4, B * 6, grade=HOT)
|
||||
put("k_hammer", 1.0, B * 2, grade=HOT)
|
||||
put("y_drones", 0.4, B * 4, grade=GOLD)
|
||||
put("k_robots", 0.5, B * 3, grade=HOT)
|
||||
t = now
|
||||
put("k_belt", 0.6, B * 6, grade=HOT)
|
||||
say("en_works", t + 0.2, "It works. It actually works.")
|
||||
EXTRA += [(t, clip("conveyor_loop"), 0.35, B * 6)]
|
||||
SPILL_AT = now
|
||||
put("z_spill", 1.2, 3.0, hear=True, grade=HOT)
|
||||
say("en_mostly", SPILL_AT + 1.0, "...it mostly works.")
|
||||
|
||||
# ───────────────────────── 6 · The planet fights back ─────────────────────────
|
||||
|
||||
STORM_AT = now
|
||||
put("y_acid", 0.4, 2.9, grade=HOT)
|
||||
say("to_rain", STORM_AT + 0.2, "Is the rain... eating the grass?")
|
||||
t = now
|
||||
put("s_storm", 2.0, 2.2, grade=HOT)
|
||||
say("fo_save", t + 0.1, "The bundles! Save the bundles!")
|
||||
T0 = "s_thrown"
|
||||
FLING = when(T0, "throw_whoosh")
|
||||
t = now
|
||||
put(T0, FLING - 1.1, 2.3, grade=PLAY)
|
||||
say("gr_goin", t, "I'm going in!")
|
||||
EXTRA += [(t + 1.1, clip("throw_whoosh"), 0.8)]
|
||||
speak("noted", "You got thrown by a twister. Noted.", zooms=((1.0, 1.05), (1.14, 1.18)), colour=(255, 200, 220))
|
||||
UFO_AT = now
|
||||
put("y_ufo", 0.4, 2.6, grade=GOLD)
|
||||
STORM_END = now
|
||||
EXTRA += [(STORM_AT, clip("rain_loop"), 0.45, 5.1), (STORM_AT + 2.9, clip("twister_loop"), 0.5, 5.9), (STORM_AT + 2.9, clip("wind_loop"), 0.35, 5.9),
|
||||
(STORM_AT + 3.0, clip("thunder"), 0.55), (UFO_AT, clip("ufo_hum_loop"), 0.45, 2.6), (UFO_AT + 0.8, clip("ufo_beam_loop"), 0.35, 1.8)]
|
||||
|
||||
# ───────────────────────── 7 · Not a single blade ─────────────────────────
|
||||
|
||||
BIG_AT = now
|
||||
for take, start, grade in (("f_air", 0.6, HOT), ("y_house", 0.8, GOLD), ("f_top", 0.5, HOT), ("y_house_night", 0.6, NIGHT),
|
||||
("f_in", 0.6, HOT), ("f_side", 0.8, HOT)):
|
||||
put(take, start, B * 2, grade=grade)
|
||||
CUT_AT = now
|
||||
put("e_cut_k", 2.0, B * 6, speed=1.6, zoom=(1.0, 1.05), grade=SPACE)
|
||||
t = now
|
||||
put("e_crew", 0.6, B * 5, grade=GOLD)
|
||||
say("to_did", t + 0.1, "We did that?")
|
||||
say("fo_did", t + 1.2, "We did that.")
|
||||
|
||||
# ───────────────────────── 8 · CTA ─────────────────────────
|
||||
|
||||
CTA_AT = now
|
||||
speak("did", "You magnificent idiots actually did it.")
|
||||
LOGO_AT = now
|
||||
put("e_up", 1.52, 6.0, speed=0.45, zoom=(1.06, 1.12), grade=dict(GOLD, sat=1.2))
|
||||
say("gr_keep", LOGO_AT + 0.5, "Can we keep the combine?")
|
||||
EXTRA += [(LOGO_AT, clip("milestone"), 0.6), (LOGO_AT + 0.1, clip("confetti"), 0.6)]
|
||||
HIT = 66.5 # the song's last hit, in its own seconds
|
||||
# where the song's zero falls: the hit mid bald planet, and a whole number of beats skipped so the cuts stay on the beat
|
||||
SONG_AT = MUSIC_AT - max(0, round((MUSIC_AT - (CUT_AT + 1.54 - HIT)) / B)) * B
|
||||
EXTRA += [(SONG_AT + HIT, clip("ambience_loop"), 0.5, LOGO_AT + 2.0 - (SONG_AT + HIT))]
|
||||
END = now
|
||||
KEEP = [(0.0, END)]
|
||||
|
||||
|
||||
# ───────────────────────── the sound ─────────────────────────
|
||||
|
||||
def voice(name):
|
||||
return name.startswith("dir_") or name.startswith("asst_")
|
||||
|
||||
|
||||
def gather():
|
||||
"""What the takes heard: the Director's lines, cut to the stretch each shot shows; the game's effects within it."""
|
||||
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 = seconds(clip(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 and not name.startswith("phone"):
|
||||
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.8))
|
||||
voices = [(a, clip(n), 1.0, d, o) for a, n, d, o in pieces]
|
||||
# a pile of bundles logs a clunk a frame: one per name every 0.15 s is plenty
|
||||
sfx.sort(key=lambda x: x[0])
|
||||
last, thin = {}, []
|
||||
for at, path, g in sfx:
|
||||
if at - last.get(path, -9) >= 0.15:
|
||||
last[path] = at
|
||||
thin.append((at, path, g * 0.6))
|
||||
return voices, thin
|
||||
|
||||
|
||||
DIRECTOR, HEARD = gather()
|
||||
VOICES = DIRECTOR + TALK + [(a, p, g, seconds(p)) for a, p, g in LINES]
|
||||
SFX = DIRECTOR + TALK + LINES + HEARD + [e for e in EXTRA if os.path.exists(e[1])]
|
||||
MISSING = sorted({os.path.basename(e[1]) for e in EXTRA if not os.path.exists(e[1])})
|
||||
|
||||
|
||||
def bed():
|
||||
"""Nothing under the call; the music from the pull-back on, dull and low under the storm, ducked under every line."""
|
||||
n = int((END + 2) * SR)
|
||||
out = np.zeros((n, 2), np.float32)
|
||||
song = decode(MUSIC)
|
||||
# the song in two: through its last hit, which buttons the bald planet, and on as it rings out under "we did that"
|
||||
# and the Director (no dead air); then from two beats before that hit again, so it lands on the logo
|
||||
lead = int((HIT - 0.9) * SR)
|
||||
i = int(MUSIC_AT * SR)
|
||||
j = int((LOGO_AT - 0.9) * SR)
|
||||
a = song[int((MUSIC_AT - SONG_AT) * SR):].copy()
|
||||
up = int(0.2 * SR)
|
||||
a[:up] *= np.linspace(0.0, 1.0, up)[:, None]
|
||||
a = a[:max(0, j - i) + int(0.3 * SR)]
|
||||
fade = int(0.3 * SR)
|
||||
a[-fade:] *= np.linspace(1.0, 0.0, fade)[:, None] ** 2
|
||||
out[i:i + len(a)] += a[:n - i] * 0.9
|
||||
b = song[lead:lead + n - j].copy()
|
||||
b[:int(0.05 * SR)] *= np.linspace(0.0, 1.0, int(0.05 * SR))[:, None]
|
||||
out[j:j + len(b)] += b * 0.9
|
||||
# the storm: the band through a wall, the storm loop over it
|
||||
s, e = int(STORM_AT * SR), int(STORM_END * SR)
|
||||
import subprocess
|
||||
seg = out[s:e].copy()
|
||||
p = subprocess.run(["ffmpeg", "-v", "error", "-f", "f32le", "-ac", "2", "-ar", str(SR), "-i", "-", "-af", "lowpass=f=420,lowpass=f=420",
|
||||
"-f", "f32le", "-ac", "2", "-ar", str(SR), "-"], input=seg.tobytes(), capture_output=True, check=True)
|
||||
dull = np.frombuffer(p.stdout, np.float32).reshape(-1, 2)[:len(seg)] * 0.8
|
||||
x = int(0.35 * SR)
|
||||
w = np.ones(len(seg), np.float32)
|
||||
w[:x] = np.linspace(0, 1, x)
|
||||
w[-x:] = np.linspace(1, 0, x)
|
||||
out[s:e] = seg * (1 - w[:, None]) + dull * w[:, None]
|
||||
storm = decode(clip("music_storm_loop"))
|
||||
k = min(len(storm), e - s)
|
||||
out[s:s + k] += storm[:k] * 0.55 * w[:k, None]
|
||||
# under the voices
|
||||
duck = np.ones(n, np.float32)
|
||||
for v in VOICES:
|
||||
at, d = v[0], v[3]
|
||||
a, b = int((at - 0.12) * SR), int((at + d + 0.2) * SR)
|
||||
duck[max(0, a):min(n, b)] = 0.38
|
||||
kernel = int(0.18 * 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 + 1.0 or CTA_AT <= t < LOGO_AT else 0.3
|
||||
|
||||
|
||||
def BLACK(t):
|
||||
if t < 0.25:
|
||||
return 1 - t / 0.25
|
||||
if t > END - 1.0:
|
||||
return min(1.0, (t - (END - 1.0)) / 1.0)
|
||||
return 0.0
|
||||
|
||||
|
||||
FLASH = [(CREW_AT, 0.4), (BIG_AT, 0.45), (LOGO_AT, 0.6)]
|
||||
|
||||
|
||||
def card(text, at, secs, size=110):
|
||||
return Type(text, at, at + secs, size, y=0.2, how="slam")
|
||||
|
||||
|
||||
TYPE = [
|
||||
card("EARTH RAN OUT OF GRASS", TITLE1, 3.0),
|
||||
card("MOW A WHOLE PLANET", WHOLE_AT + 0.1, 2.3),
|
||||
card("UP TO 16 PLAYERS ONLINE", SIXTEEN_AT + 0.1, B * 6 - 0.2),
|
||||
card("FROM NAIL SCISSORS TO A COMBINE", BLADES_AT + 0.05, B * 8 - 0.1, 96),
|
||||
card("LET THE FACTORY DO IT", FACTORY_AT + 0.05, B * 8 - 0.1),
|
||||
card("AN ALIEN WORLD", UFO_AT + 0.1, 2.4),
|
||||
card("NOT A SINGLE BLADE LEFT", CUT_AT + 0.1, B * 6 - 0.2),
|
||||
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("ONLINE CO-OP FOR 1 TO 16 PLAYERS", LOGO_AT + 2.4, END, 50, y=0.85, how="rise", colour=(226, 240, 200)),
|
||||
]
|
||||
# subtitles, low and small, in each speaker's colour
|
||||
for a, b, text, colour in SUBS:
|
||||
if a < LOGO_AT:
|
||||
TYPE.append(Type(text, a, b, 52, y=0.9, how="fade", colour=colour, edge=(18, 22, 16)))
|
||||
else:
|
||||
TYPE.append(Type(text, a, b, 48, y=0.94, how="fade", colour=colour, edge=(18, 22, 16)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
for s in SHOTS:
|
||||
print(f"{s.at:7.2f} {s.end - s.at:5.2f} {os.path.basename(s.take):24s} from {s.start:6.2f}")
|
||||
print("song %.2f " % SONG_AT, end="")
|
||||
print("music %.2f crew %.2f hand %.2f blades %.2f factory %.2f storm %.2f big %.2f cta %.2f logo %.2f end %.2f" % (
|
||||
MUSIC_AT, CREW_AT, HAND_AT, BLADES_AT, FACTORY_AT, STORM_AT, BIG_AT, CTA_AT, LOGO_AT, END))
|
||||
for v in VOICES:
|
||||
print("voice %7.2f %-16s %5.2f" % (v[0], os.path.basename(v[1]), v[3]))
|
||||
print("missing sounds:", MISSING)
|
||||
Reference in New Issue
Block a user