Generalized from the render lanes' proven tools: map segmentation, 2.5D massing by wealth zone, a CPU ray marcher with analytic landmarks and true-scale proxy people, prompt composition from blocks, a self-calibrating batch submitter with a renderer adapter point, the plate-vs-frame gates (drift, ECC, landmark region, skyline and invented structures, figure brackets, corner sweep), matrix job builders, a cost line, and an end-to-end smoke test on a synthetic town.
101 lines
5.8 KiB
Python
101 lines
5.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Build the matrix jobs for an accepted set of keepers: time-of-day x weather, and population x time-of-day.
|
|
|
|
Weather/time matrix (exteriors): every cell is an EDIT of the accepted Day Dry keeper of the same camera (or, for
|
|
Sunset/Night cells, a relight of the Day cell of the same weather), never a fresh re-surface, so geometry carries.
|
|
Cells and sizes come from the tier (references/effort-tiers.md):
|
|
tier 1: Day|Sunset|Night x Dry|Rain|Snow (light) = 9 per camera, plus any storm/deep-snow cells you enable
|
|
tier 2: Day + Night Dry + one Snow (light)
|
|
tier 3: Day Dry only (no matrix)
|
|
Population x time matrix (venues with people): the plate carries proxies at the chosen density; each cell states the
|
|
hour and the density relationally. Sizes by tier: T1 4x3 (Morning/Afternoon/Evening/Late Night x Quiet/Moderate/
|
|
Packed; 4x4 with Empty for storyline hubs), T2 2x3 (Day/Sunset x Quiet/Moderate/Packed), T3 1x2 (peak hour x
|
|
Quiet/Packed), T4 none.
|
|
|
|
usage: matrix_jobs.py weather --config citykit.json --prompts prompts.json --tier 1 V=DayDryKeeper.png ... --out jobs_matrix.json
|
|
matrix_jobs.py population --config citykit.json --prompts prompts.json --tier 1 V=EmptyMaster.png ... --out jobs_pop.json
|
|
prompts.json needs "weather" {Rain, Snow (light), Snow (medium), Snow (heavy), Blizzard, ...}, "relights" {Sunset,
|
|
Night, ...}, "hours" {Morning, ...} and "densities" {Quiet, ...} blocks. Weather names follow the naming convention
|
|
in references/naming.md so files sort and display consistently.
|
|
"""
|
|
import argparse
|
|
import json
|
|
import os
|
|
|
|
from citykit import load_config
|
|
|
|
WEATHER_BY_TIER = {1: ["Dry", "Rain", "Snow (light)"], 2: ["Dry", "Snow (light)"], 3: ["Dry"], 4: []}
|
|
TIMES_BY_TIER = {1: ["Day", "Sunset", "Night"], 2: ["Day", "Night"], 3: ["Day"], 4: []}
|
|
POP_BY_TIER = {1: (["Morning", "Afternoon", "Evening", "Late Night"], ["Quiet", "Moderate", "Packed"]),
|
|
2: (["Day", "Sunset"], ["Quiet", "Moderate", "Packed"]),
|
|
3: (["Peak"], ["Quiet", "Packed"]), 4: ([], [])}
|
|
|
|
|
|
def weather_jobs(cfg, P, keepers, tier, takes, extra_weather):
|
|
size = cfg["renderer"].get("size", "2048x1152")
|
|
jobs = []
|
|
weathers = WEATHER_BY_TIER[tier] + extra_weather
|
|
for v, keeper in keepers.items():
|
|
for wx in weathers:
|
|
# day cell of this weather: an edit of the Day Dry keeper (Dry = the keeper itself, no job)
|
|
if wx != "Dry":
|
|
prompt = P["weather"][wx] + " " + P.get("weather_lock", "") + " " + P["nomodern"]
|
|
for t in range(1, takes + 1):
|
|
jobs.append(dict(id="%s_Day-%s_t%d" % (v, wx.replace(" ", ""), t), size=size, refs=[os.path.abspath(keeper)],
|
|
prompt=prompt + " [%s, Day %s, take %d]" % (v, wx, t),
|
|
derived_from=keeper, cell="Day %s" % wx, view=v))
|
|
# Sunset/Night of this weather: relights of the Day cell of the same weather (chained; run after picking)
|
|
for tm in TIMES_BY_TIER[tier]:
|
|
if tm == "Day":
|
|
continue
|
|
src = keeper if wx == "Dry" else "<pick of %s Day %s>" % (v, wx)
|
|
prompt = P["relights"][tm if tm in P["relights"] else tm.lower()] + " " + P["nomodern"]
|
|
for t in range(1, takes + 1):
|
|
jobs.append(dict(id="%s_%s-%s_t%d" % (v, tm, wx.replace(" ", ""), t), size=size, refs=[src],
|
|
prompt=prompt + " [%s, %s %s, take %d]" % (v, tm, wx, t),
|
|
derived_from=src, cell="%s %s" % (tm, wx), view=v, chained=(wx != "Dry")))
|
|
return jobs
|
|
|
|
|
|
def population_jobs(cfg, P, masters, tier, takes, with_empty):
|
|
size = cfg["renderer"].get("size", "2048x1152")
|
|
hours, dens = POP_BY_TIER[tier]
|
|
if with_empty and tier == 1:
|
|
dens = ["Empty"] + dens
|
|
jobs = []
|
|
for v, master in masters.items():
|
|
for hr in hours:
|
|
for dn in dens:
|
|
prompt = " ".join([P.get("population_intro", ""), P["hours"][hr], P["densities"][dn],
|
|
P.get("population_locks", ""), P["nomodern"]])
|
|
for t in range(1, takes + 1):
|
|
jobs.append(dict(id="%s_%s-%s_t%d" % (v, hr.replace(" ", ""), dn, t), size=size,
|
|
refs=[os.path.abspath(master)], prompt=prompt + " [%s, %s %s, take %d]" % (v, hr, dn, t),
|
|
cell="%s %s" % (hr, dn), view=v))
|
|
return jobs
|
|
|
|
|
|
if __name__ == "__main__":
|
|
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
ap.add_argument("mode", choices=["weather", "population"])
|
|
ap.add_argument("rest", nargs="*", help="V=keeper.png pairs")
|
|
ap.add_argument("--config", required=True)
|
|
ap.add_argument("--prompts", required=True)
|
|
ap.add_argument("--tier", type=int, default=1)
|
|
ap.add_argument("--takes", type=int, default=2)
|
|
ap.add_argument("--extra-weather", default="", help="comma list, e.g. 'Blizzard,Snow (heavy)'")
|
|
ap.add_argument("--with-empty", action="store_true", help="tier 1 population: add the Empty column (4x4)")
|
|
ap.add_argument("--out", required=True)
|
|
a = ap.parse_intermixed_args()
|
|
cfg = load_config(a.config)
|
|
P = json.load(open(a.prompts))
|
|
keep = dict(x.split("=", 1) for x in a.rest if "=" in x)
|
|
if a.mode == "weather":
|
|
jobs = weather_jobs(cfg, P, keep, a.tier, a.takes, [w for w in a.extra_weather.split(",") if w])
|
|
else:
|
|
jobs = population_jobs(cfg, P, keep, a.tier, a.takes, a.with_empty)
|
|
R = cfg["renderer"]
|
|
chained = [j for j in jobs if j.get("chained")]
|
|
json.dump(dict(model=R["model"], quality=R.get("quality", "high"), refs_common=[], jobs=jobs), open(a.out, "w"), indent=1)
|
|
print(len(jobs), "jobs ->", a.out, "(%d chained: fill in their refs after picking the Day cell)" % len(chained))
|