CenaForge: primeira versão pública
Gerador de vídeos narrativos (Godot + FFmpeg), painel Next.js, serviço de voz, Clipador de lives e Publicador para YouTube, TikTok e Instagram. Inclui a leitura das visualizações dos posts para o Dashboard e o botão "Publicar no <rede>" nos cartões das publicações. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,500 @@
|
||||
extends Node2D
|
||||
## Desenho das cenas 2D do documentário. `apply(t)` guarda o tempo e redesenha;
|
||||
## tudo depende só de (configuração, t), então o render é determinístico.
|
||||
## Medidas proporcionais ao tamanho da tela: a mesma composição em 540x960 e 1080x1920.
|
||||
##
|
||||
## Modelos:
|
||||
## title { title, subtitle?, kicker? }
|
||||
## counter { value, decimals?, prefix?, suffix?, label?, note?, grid?: { cols, rows, highlight } }
|
||||
## map { preset?: "litoral-sp", title?, markers: [{ label, lat?, lon?, kind?: "city"|"island" }],
|
||||
## route?: { from, to, label? } } (from/to = rótulo ou índice do marcador)
|
||||
|
||||
const BG := Color("#0d0d10")
|
||||
const BG_2 := Color("#1a120c")
|
||||
const ACCENT := Color("#ff7a1a")
|
||||
const GLOW := Color("#ffb547")
|
||||
const TEXT := Color("#f5f2ee")
|
||||
const MUTED := Color("#b8b0a8")
|
||||
const SEA := Color("#0b1e2b")
|
||||
const SEA_2 := Color("#0f2a3a")
|
||||
const LAND := Color("#1f3326")
|
||||
const LAND_EDGE := Color("#4f7a5a")
|
||||
|
||||
## Litoral sul e centro de São Paulo (ilustrativo, sem escala exata): pontos da costa de
|
||||
## sudoeste para nordeste e um pequeno dicionário de lugares (lat, lon).
|
||||
const PRESETS := {
|
||||
"litoral-sp": {
|
||||
"bounds": {"north": -23.35, "south": -24.95, "west": -47.65, "east": -45.75},
|
||||
"coast": [
|
||||
[-24.95, -47.65], [-24.80, -47.62], [-24.70, -47.52], [-24.55, -47.28], [-24.42, -47.10],
|
||||
[-24.32, -47.00], [-24.25, -46.90], [-24.18, -46.79], [-24.12, -46.68], [-24.09, -46.62],
|
||||
[-24.03, -46.48], [-24.01, -46.41], [-23.98, -46.37], [-23.99, -46.30], [-24.00, -46.25],
|
||||
[-23.93, -46.18], [-23.85, -46.14], [-23.80, -45.98], [-23.77, -45.85], [-23.80, -45.75],
|
||||
],
|
||||
"places": {
|
||||
"São Paulo": [-23.55, -46.63], "Santos": [-23.96, -46.33], "Guarujá": [-23.99, -46.26],
|
||||
"São Vicente": [-23.96, -46.39], "Praia Grande": [-24.00, -46.42], "Mongaguá": [-24.09, -46.62],
|
||||
"Itanhaém": [-24.18, -46.79], "Peruíbe": [-24.32, -47.00], "Bertioga": [-23.85, -46.14],
|
||||
"Ilha da Queimada Grande": [-24.487, -46.674], "Queimada Grande": [-24.487, -46.674],
|
||||
"Ilha da Queimada Pequena": [-24.375, -46.795], "Queimada Pequena": [-24.375, -46.795],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var _cfg: Dictionary
|
||||
var _p: Dictionary
|
||||
var _size := Vector2.ZERO
|
||||
var _t := 0.0
|
||||
var _dur := 1.0
|
||||
var _font: SystemFont
|
||||
var _font_regular: SystemFont
|
||||
var _map_cache := {}
|
||||
var _glow_tex: GradientTexture2D
|
||||
|
||||
|
||||
func setup(cfg: Dictionary, viewport_size: Vector2) -> void:
|
||||
_cfg = cfg
|
||||
_p = cfg.params
|
||||
_size = viewport_size
|
||||
_dur = maxf(float(cfg.video.duration), 0.1)
|
||||
_font = _make_font(800)
|
||||
_font_regular = _make_font(500)
|
||||
RenderingServer.set_default_clear_color(BG)
|
||||
var g := Gradient.new()
|
||||
g.set_color(0, Color(1, 1, 1, 1))
|
||||
g.set_color(1, Color(1, 1, 1, 0))
|
||||
g.add_point(0.45, Color(1, 1, 1, 0.32))
|
||||
_glow_tex = GradientTexture2D.new()
|
||||
_glow_tex.gradient = g
|
||||
_glow_tex.fill = GradientTexture2D.FILL_RADIAL
|
||||
_glow_tex.fill_from = Vector2(0.5, 0.5)
|
||||
_glow_tex.fill_to = Vector2(1.0, 0.5)
|
||||
_glow_tex.width = 512
|
||||
_glow_tex.height = 512
|
||||
if cfg.template == "map":
|
||||
_map_cache = _prepare_map()
|
||||
|
||||
|
||||
func apply(t: float) -> void:
|
||||
_t = t
|
||||
queue_redraw()
|
||||
|
||||
|
||||
## Resumo do estado no instante atual (para o manifesto ser comparável entre execuções).
|
||||
func state_signature() -> String:
|
||||
return "%s|%.3f" % [_cfg.template, _ease_out(_progress(0.0, 1.0))]
|
||||
|
||||
|
||||
func _make_font(weight: int) -> SystemFont:
|
||||
var f := SystemFont.new()
|
||||
f.font_names = PackedStringArray(["Segoe UI", "Segoe UI Variable Display", "Arial", "DejaVu Sans", "Liberation Sans"])
|
||||
f.font_weight = weight
|
||||
f.antialiasing = TextServer.FONT_ANTIALIASING_GRAY
|
||||
return f
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
if _cfg.is_empty():
|
||||
return
|
||||
match str(_cfg.template):
|
||||
"title":
|
||||
_draw_title()
|
||||
"counter":
|
||||
_draw_counter()
|
||||
"map":
|
||||
_draw_map()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- utilidades
|
||||
|
||||
func _progress(start: float, length: float) -> float:
|
||||
return clampf((_t - start) / maxf(length, 0.001), 0.0, 1.0)
|
||||
|
||||
|
||||
static func _ease_in_out(p: float) -> float:
|
||||
return p * p * (3.0 - 2.0 * p)
|
||||
|
||||
|
||||
static func _ease_out(p: float) -> float:
|
||||
return 1.0 - pow(1.0 - p, 3.0)
|
||||
|
||||
|
||||
func _px(fraction: float) -> int:
|
||||
return int(round(_size.y * fraction))
|
||||
|
||||
|
||||
func _background(top: Color, bottom: Color) -> void:
|
||||
var r := Rect2(Vector2.ZERO, _size)
|
||||
draw_polygon(PackedVector2Array([r.position, Vector2(r.end.x, 0), r.end, Vector2(0, r.end.y)]),
|
||||
PackedColorArray([top, top, bottom, bottom]))
|
||||
|
||||
|
||||
func _glow(center: Vector2, radius: float, color: Color) -> void:
|
||||
# Brilho suave: textura de degradê radial (sem anéis em degrau).
|
||||
draw_texture_rect(_glow_tex, Rect2(center - Vector2(radius, radius), Vector2(radius, radius) * 2.0), false, Color(color.r, color.g, color.b, color.a * 0.45))
|
||||
|
||||
|
||||
## Texto (quebra por palavra) com o topo em `top_y`, centralizado ou alinhado à esquerda
|
||||
## (margem de (1 - width_fraction) / 2). Devolve a altura usada.
|
||||
func _text_block(text: String, top_y: float, size_px: int, color: Color, font: Font, width_fraction := 0.84, max_lines := 4, align := HORIZONTAL_ALIGNMENT_CENTER) -> float:
|
||||
if text.is_empty():
|
||||
return 0.0
|
||||
var width := _size.x * width_fraction
|
||||
var left := (_size.x - width) / 2.0
|
||||
var block := font.get_multiline_string_size(text, align, width, size_px, max_lines)
|
||||
var ascent := font.get_ascent(size_px)
|
||||
draw_multiline_string(font, Vector2(left, top_y + ascent), text, align, width, size_px, max_lines, color)
|
||||
return block.y
|
||||
|
||||
|
||||
func _with_alpha(c: Color, a: float) -> Color:
|
||||
return Color(c.r, c.g, c.b, c.a * clampf(a, 0.0, 1.0))
|
||||
|
||||
|
||||
## Número no formato brasileiro: 1.500 / 0,0055.
|
||||
static func _format_number(value: float, decimals: int) -> String:
|
||||
var negative := value < 0.0
|
||||
var v := absf(value)
|
||||
var int_part := int(floor(v))
|
||||
var frac := ""
|
||||
if decimals > 0:
|
||||
var scaled := int(round((v - float(int_part)) * pow(10.0, decimals)))
|
||||
if scaled >= int(pow(10.0, decimals)):
|
||||
int_part += 1
|
||||
scaled = 0
|
||||
frac = "," + str(scaled).pad_zeros(decimals)
|
||||
var digits := str(int_part)
|
||||
var grouped := ""
|
||||
var count := 0
|
||||
for i in range(digits.length() - 1, -1, -1):
|
||||
grouped = digits[i] + grouped
|
||||
count += 1
|
||||
if count % 3 == 0 and i > 0:
|
||||
grouped = "." + grouped
|
||||
return ("-" if negative else "") + grouped + frac
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- título
|
||||
|
||||
## Cores de destaque por variação ("gerar de novo"): brasa, ciano, violeta.
|
||||
const VARIANT_ACCENTS := [Color("#ff7a1a"), Color("#3fc1c9"), Color("#a78bfa")]
|
||||
|
||||
|
||||
func _variant() -> int:
|
||||
return int(_p.get("variant", 0))
|
||||
|
||||
|
||||
func _accent() -> Color:
|
||||
return VARIANT_ACCENTS[_variant() % VARIANT_ACCENTS.size()]
|
||||
|
||||
|
||||
func _draw_title() -> void:
|
||||
match _variant() % 3:
|
||||
1:
|
||||
_draw_title_editorial()
|
||||
2:
|
||||
_draw_title_lower()
|
||||
_:
|
||||
_draw_title_center()
|
||||
|
||||
|
||||
## Variação 1: editorial, alinhado à esquerda, barra vertical de destaque.
|
||||
func _draw_title_editorial() -> void:
|
||||
var accent := _accent()
|
||||
_background(BG, BG_2)
|
||||
_glow(Vector2(_size.x * 0.15, _size.y * 0.35), _size.x * 0.8, Color(accent.r, accent.g, accent.b, 0.5))
|
||||
var appear := _ease_out(_progress(0.15, 0.7))
|
||||
var bar := _ease_out(_progress(0.0, 0.7))
|
||||
var x0 := _size.x * 0.08
|
||||
var top := _size.y * 0.3
|
||||
var y := top + (1.0 - appear) * _px(0.02)
|
||||
var kicker := str(_p.get("kicker", ""))
|
||||
if not kicker.is_empty():
|
||||
y += _text_block(kicker.to_upper(), y, _px(0.022), _with_alpha(accent, appear), _font, 0.78, 1, HORIZONTAL_ALIGNMENT_LEFT) + _px(0.02)
|
||||
var h := _text_block(str(_p.get("title", "")), y, _px(0.066), _with_alpha(TEXT, appear), _font, 0.78, 5, HORIZONTAL_ALIGNMENT_LEFT)
|
||||
draw_rect(Rect2(Vector2(x0, top), Vector2(_px(0.007), (y - top + h) * bar)), accent)
|
||||
var sub_appear := _ease_out(_progress(0.55, 0.7))
|
||||
_text_block(str(_p.get("subtitle", "")), y + h + _px(0.03), _px(0.03), _with_alpha(MUTED, sub_appear), _font_regular, 0.78, 3, HORIZONTAL_ALIGNMENT_LEFT)
|
||||
|
||||
|
||||
## Variação 2: texto grande na parte de baixo-centro, sublinhado que corre, brilho embaixo.
|
||||
func _draw_title_lower() -> void:
|
||||
var accent := _accent()
|
||||
_background(BG_2, BG)
|
||||
_glow(Vector2(_size.x * 0.5, _size.y * 0.62), _size.x * 0.9 * (1.0 + 0.05 * sin(_t * 1.1)), Color(accent.r, accent.g, accent.b, 0.55))
|
||||
var appear := _ease_out(_progress(0.1, 0.8))
|
||||
var y := _size.y * 0.44 + (1.0 - appear) * _px(0.04)
|
||||
var kicker := str(_p.get("kicker", ""))
|
||||
if not kicker.is_empty():
|
||||
y += _text_block(kicker.to_upper(), y, _px(0.022), _with_alpha(accent, appear), _font, 0.8, 1) + _px(0.02)
|
||||
y += _text_block(str(_p.get("title", "")), y, _px(0.07), _with_alpha(TEXT, appear), _font, 0.88, 4) + _px(0.02)
|
||||
var line := _ease_out(_progress(0.5, 0.8))
|
||||
draw_rect(Rect2(Vector2(_size.x * 0.5 - _size.x * 0.25 * line, y), Vector2(_size.x * 0.5 * line, _px(0.005))), accent)
|
||||
var sub_appear := _ease_out(_progress(0.7, 0.7))
|
||||
_text_block(str(_p.get("subtitle", "")), y + _px(0.03), _px(0.03), _with_alpha(MUTED, sub_appear), _font_regular, 0.8, 3)
|
||||
|
||||
|
||||
## Variação 0: centralizado, barra que cresce do centro.
|
||||
func _draw_title_center() -> void:
|
||||
_background(BG, BG_2)
|
||||
var breathe := 1.0 + 0.04 * sin(_t * 1.3)
|
||||
_glow(Vector2(_size.x * 0.5, _size.y * 0.42), _size.x * 0.75 * breathe, Color(ACCENT.r, ACCENT.g, ACCENT.b, 0.55))
|
||||
var appear := _ease_out(_progress(0.15, 0.7))
|
||||
var slide := (1.0 - appear) * _size.y * 0.03
|
||||
var y := _size.y * 0.36 + slide
|
||||
var kicker := str(_p.get("kicker", ""))
|
||||
if not kicker.is_empty():
|
||||
y += _text_block(kicker.to_upper(), y, _px(0.022), _with_alpha(GLOW, appear), _font, 0.8, 1) + _px(0.02)
|
||||
# Barra de destaque que cresce do centro.
|
||||
var bar := _ease_out(_progress(0.0, 0.6))
|
||||
var bar_w := _size.x * 0.36 * bar
|
||||
draw_rect(Rect2(Vector2((_size.x - bar_w) / 2.0, y), Vector2(bar_w, _px(0.006))), ACCENT)
|
||||
y += _px(0.035)
|
||||
y += _text_block(str(_p.get("title", "")), y, _px(0.058), _with_alpha(TEXT, appear), _font, 0.84, 4) + _px(0.025)
|
||||
var sub_appear := _ease_out(_progress(0.55, 0.7))
|
||||
_text_block(str(_p.get("subtitle", "")), y + (1.0 - sub_appear) * _px(0.015), _px(0.03), _with_alpha(MUTED, sub_appear), _font_regular, 0.8, 3)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- contador / infográfico
|
||||
|
||||
func _draw_counter() -> void:
|
||||
var accent := _accent()
|
||||
_background(BG, BG_2)
|
||||
_glow(Vector2(_size.x * 0.5, _size.y * 0.33), _size.x * 0.6, Color(accent.r, accent.g, accent.b, 0.5))
|
||||
var value := float(_p.get("value", 0))
|
||||
var decimals := int(_p.get("decimals", 0))
|
||||
var count_len := clampf(_dur * 0.45, 0.8, 2.4)
|
||||
var shown := value * _ease_out(_progress(0.2, count_len))
|
||||
var number := str(_p.get("prefix", "")) + _format_number(shown, decimals) + str(_p.get("suffix", ""))
|
||||
var pop := _ease_out(_progress(0.0, 0.5))
|
||||
var grid_mode := typeof(_p.get("grid")) == TYPE_DICTIONARY
|
||||
# Anel que fecha enquanto o número conta (sem grade: o anel é o elemento visual do infográfico).
|
||||
var ring_center := Vector2(_size.x * 0.5, _size.y * (0.27 if grid_mode else 0.36))
|
||||
var ring_r := _size.x * (0.27 if grid_mode else 0.33)
|
||||
var fill := _ease_out(_progress(0.2, count_len))
|
||||
draw_arc(ring_center, ring_r, 0.0, TAU, 128, Color(1, 1, 1, 0.07 * pop), _px(0.012), true)
|
||||
draw_arc(ring_center, ring_r, -PI / 2.0, -PI / 2.0 + TAU * fill, 128, _with_alpha(accent, pop), _px(0.012), true)
|
||||
if fill > 0.0:
|
||||
var tip := ring_center + Vector2(cos(-PI / 2.0 + TAU * fill), sin(-PI / 2.0 + TAU * fill)) * ring_r
|
||||
draw_circle(tip, _px(0.011), _with_alpha(accent.lightened(0.35), pop))
|
||||
var size_px := int(_px(0.12 if number.length() <= 4 else 0.095) * (0.85 + 0.15 * pop))
|
||||
var number_h := _font.get_multiline_string_size(number, HORIZONTAL_ALIGNMENT_CENTER, _size.x * 0.6, size_px, 1).y
|
||||
var kicker := str(_p.get("kicker", ""))
|
||||
if not kicker.is_empty():
|
||||
_text_block(kicker, ring_center.y - number_h * 0.5 - _px(0.04), _px(0.028), _with_alpha(MUTED, pop), _font_regular, 0.5, 1)
|
||||
_text_block(number, ring_center.y - number_h * 0.5, size_px, _with_alpha(accent.lightened(0.3), pop), _font, 0.6, 1)
|
||||
var label_appear := _ease_out(_progress(0.35, 0.6))
|
||||
var y := ring_center.y + ring_r + _px(0.035)
|
||||
y += _text_block(str(_p.get("label", "")), y, _px(0.036), _with_alpha(TEXT, label_appear), _font, 0.84, 2) + _px(0.03)
|
||||
|
||||
var grid = _p.get("grid")
|
||||
if typeof(grid) == TYPE_DICTIONARY:
|
||||
_draw_grid(grid, y)
|
||||
else:
|
||||
var note_appear := _ease_out(_progress(0.9, 0.7))
|
||||
_text_block(str(_p.get("note", "")), y + _px(0.02), _px(0.028), _with_alpha(MUTED, note_appear), _font_regular, 0.8, 4)
|
||||
|
||||
|
||||
func _draw_grid(grid: Dictionary, top: float) -> void:
|
||||
var cols := clampi(int(grid.get("cols", 10)), 1, 30)
|
||||
var rows := clampi(int(grid.get("rows", 10)), 1, 30)
|
||||
var highlight := clampi(int(grid.get("highlight", 1)), 0, cols * rows)
|
||||
var area_w := _size.x * 0.72
|
||||
var area_h := _size.y * 0.86 - top
|
||||
var cell := minf(area_w / cols, area_h / rows)
|
||||
var origin := Vector2((_size.x - cell * cols) / 2.0, top)
|
||||
var total := cols * rows
|
||||
var fill_len := clampf(_dur * 0.3, 0.6, 1.8)
|
||||
for i in total:
|
||||
var col := i % cols
|
||||
var row := i / cols
|
||||
# Células aparecem em onda (diagonal); as destacadas acendem depois.
|
||||
var appear := _ease_out(_progress(0.6 + float(col + row) / float(cols + rows) * fill_len, 0.3))
|
||||
if appear <= 0.0:
|
||||
continue
|
||||
var r := Rect2(origin + Vector2(col * cell, row * cell), Vector2(cell, cell)).grow(-cell * 0.12)
|
||||
var is_hl := i < highlight
|
||||
var lit := _ease_out(_progress(0.6 + fill_len + 0.2 + float(i) * 0.04, 0.35)) if is_hl else 0.0
|
||||
var base := Color(1, 1, 1, 0.10 * appear)
|
||||
draw_rect(r, base.lerp(Color(ACCENT.r, ACCENT.g, ACCENT.b, appear), lit))
|
||||
var note_appear := _ease_out(_progress(0.6 + fill_len + 0.6, 0.6))
|
||||
_text_block(str(_p.get("note", "")), origin.y + cell * rows + _px(0.02), _px(0.026), _with_alpha(MUTED, note_appear), _font_regular, 0.84, 3)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- mapa
|
||||
|
||||
func _prepare_map() -> Dictionary:
|
||||
var preset: Dictionary = PRESETS.get(str(_p.get("preset", "litoral-sp")), PRESETS["litoral-sp"])
|
||||
var places: Dictionary = preset.places
|
||||
# 1) Lugares citados (lat/lon dados ou do dicionário do preset).
|
||||
var resolved := []
|
||||
for m in _p.get("markers", []):
|
||||
if typeof(m) != TYPE_DICTIONARY:
|
||||
continue
|
||||
var label := str(m.get("label", ""))
|
||||
var lat = m.get("lat")
|
||||
var lon = m.get("lon")
|
||||
if (lat == null or lon == null) and places.has(label):
|
||||
lat = places[label][0]
|
||||
lon = places[label][1]
|
||||
if lat == null or lon == null:
|
||||
continue
|
||||
var lower := label.to_lower()
|
||||
var kind := str(m.get("kind", "island" if lower.contains("ilha") or lower.contains("queimada") else "city"))
|
||||
resolved.append({"label": label, "lat": float(lat), "lon": float(lon), "kind": kind})
|
||||
# 2) Enquadramento: em volta dos lugares citados (com folga), ou o preset inteiro.
|
||||
var b: Dictionary = preset.bounds.duplicate()
|
||||
if not resolved.is_empty():
|
||||
var n := -90.0
|
||||
var s_ := 90.0
|
||||
var w := 180.0
|
||||
var e := -180.0
|
||||
for m in resolved:
|
||||
n = maxf(n, m.lat)
|
||||
s_ = minf(s_, m.lat)
|
||||
w = minf(w, m.lon)
|
||||
e = maxf(e, m.lon)
|
||||
var pad_lat := maxf((n - s_) * 0.7, 0.22)
|
||||
var pad_lon := maxf((e - w) * 0.7, 0.22)
|
||||
b = {"north": n + pad_lat, "south": s_ - pad_lat, "west": w - pad_lon, "east": e + pad_lon}
|
||||
var area := Rect2(Vector2(_size.x * 0.06, _size.y * 0.2), Vector2(_size.x * 0.88, _size.y * 0.62))
|
||||
var mid_lat := deg_to_rad((float(b.north) + float(b.south)) / 2.0)
|
||||
var span_x := (float(b.east) - float(b.west)) * cos(mid_lat)
|
||||
var span_y := float(b.north) - float(b.south)
|
||||
var scale := minf(area.size.x / span_x, area.size.y / span_y)
|
||||
var offset := area.position + (area.size - Vector2(span_x, span_y) * scale) / 2.0
|
||||
var project := func(lat: float, lon: float) -> Vector2:
|
||||
return offset + Vector2((lon - float(b.west)) * cos(mid_lat), float(b.north) - lat) * scale
|
||||
var coast := PackedVector2Array()
|
||||
for pt in preset.coast:
|
||||
coast.append(project.call(float(pt[0]), float(pt[1])))
|
||||
# Terra = costa + cantos do norte (a costa paulista corre de sudoeste para nordeste).
|
||||
var pb: Dictionary = preset.bounds
|
||||
var land := coast.duplicate()
|
||||
# Cantos bem além da tela: no começo do voo o mapa aparece aberto (zoom 0,45).
|
||||
land.append(project.call(float(pb.south) - 1.0, float(pb.east) + 8.0))
|
||||
land.append(project.call(float(pb.north) + 8.0, float(pb.east) + 8.0))
|
||||
land.append(project.call(float(pb.north) + 8.0, float(pb.west) - 8.0))
|
||||
land.append(project.call(float(pb.south) - 8.0, float(pb.west) - 8.0))
|
||||
var markers := []
|
||||
for m in resolved:
|
||||
markers.append({"label": m.label, "pos": project.call(m.lat, m.lon), "lat": m.lat, "lon": m.lon, "kind": m.kind})
|
||||
var route := {}
|
||||
var r = _p.get("route")
|
||||
if typeof(r) == TYPE_DICTIONARY and markers.size() >= 2:
|
||||
var a := _find_marker(markers, r.get("from", 0))
|
||||
var z := _find_marker(markers, r.get("to", 1))
|
||||
if a >= 0 and z >= 0 and a != z:
|
||||
var label := str(r.get("label", ""))
|
||||
if label.is_empty():
|
||||
label = "%d km" % int(round(_haversine_km(markers[a].lat, markers[a].lon, markers[z].lat, markers[z].lon)))
|
||||
route = {"a": markers[a].pos, "b": markers[z].pos, "label": label}
|
||||
var focus: Vector2 = area.get_center()
|
||||
if not route.is_empty():
|
||||
focus = (route.a + route.b) / 2.0
|
||||
return {"coast": coast, "land": land, "markers": markers, "route": route, "focus": focus}
|
||||
|
||||
|
||||
static func _find_marker(markers: Array, key) -> int:
|
||||
if typeof(key) in [TYPE_INT, TYPE_FLOAT]:
|
||||
var i := int(key)
|
||||
return i if i >= 0 and i < markers.size() else -1
|
||||
for i in markers.size():
|
||||
if markers[i].label == str(key):
|
||||
return i
|
||||
return -1
|
||||
|
||||
|
||||
static func _haversine_km(lat1: float, lon1: float, lat2: float, lon2: float) -> float:
|
||||
var d_lat := deg_to_rad(lat2 - lat1)
|
||||
var d_lon := deg_to_rad(lon2 - lon1)
|
||||
var a := sin(d_lat / 2.0) ** 2 + cos(deg_to_rad(lat1)) * cos(deg_to_rad(lat2)) * sin(d_lon / 2.0) ** 2
|
||||
return 6371.0 * 2.0 * atan2(sqrt(a), sqrt(1.0 - a))
|
||||
|
||||
|
||||
func _draw_map() -> void:
|
||||
_background(SEA_2, SEA)
|
||||
var m := _map_cache
|
||||
# Voo: começa aberto (litoral inteiro) e desce até a rota; depois aproxima devagar.
|
||||
var focus: Vector2 = m.focus
|
||||
var center := _size / 2.0
|
||||
var intro := _ease_in_out(_progress(0.0, minf(1.6, _dur * 0.35)))
|
||||
var start_zoom := 0.45 if _variant() % 2 == 0 else 0.62
|
||||
var zoom := lerpf(start_zoom, 1.0, intro) + 0.1 * _ease_out(_progress(1.6, maxf(_dur - 1.6, 0.1)))
|
||||
var pivot := center.lerp(focus, intro)
|
||||
var shift := (center - focus) * 0.3 * intro
|
||||
draw_set_transform(pivot - pivot * zoom + shift, 0.0, Vector2(zoom, zoom))
|
||||
# Ondas do mar: linhas horizontais suaves que deslizam.
|
||||
for i in 18:
|
||||
var y := _size.y * (0.05 + float(i) * 0.055) + fmod(_t * 6.0, _size.y * 0.055)
|
||||
draw_line(Vector2(0, y), Vector2(_size.x, y), Color(1, 1, 1, 0.025), 2.0)
|
||||
var land_alpha := _ease_out(_progress(0.0, 0.6))
|
||||
draw_colored_polygon(m.land, _with_alpha(LAND, land_alpha))
|
||||
draw_polyline(m.coast, _with_alpha(LAND_EDGE, land_alpha), maxf(2.0, _size.y * 0.002), true)
|
||||
|
||||
var route: Dictionary = m.route
|
||||
if not route.is_empty():
|
||||
# A linha só começa quando o voo termina (1,5 s).
|
||||
var route_len := clampf(_dur * 0.3, 0.8, 2.0)
|
||||
var p := _ease_out(_progress(1.5, route_len))
|
||||
var a: Vector2 = route.a
|
||||
var b: Vector2 = route.b
|
||||
var end := a.lerp(b, p)
|
||||
# Linha tracejada que se desenha de A até B.
|
||||
var dash := _size.y * 0.012
|
||||
var length := a.distance_to(end)
|
||||
var dir := (b - a).normalized()
|
||||
var s := 0.0
|
||||
while s < length:
|
||||
draw_line(a + dir * s, a + dir * minf(s + dash, length), GLOW, maxf(3.0, _size.y * 0.003), true)
|
||||
s += dash * 1.8
|
||||
if p >= 1.0:
|
||||
var lp := _ease_out(_progress(1.5 + route_len, 0.5))
|
||||
# Pulso no destino: anéis que crescem e somem, a cada 1,2 s.
|
||||
for k in 2:
|
||||
var phase := fmod(maxf(_t - 1.5 - route_len, 0.0) + float(k) * 0.6, 1.2) / 1.2
|
||||
draw_arc(b, _size.y * (0.012 + 0.04 * phase), 0.0, TAU, 48, Color(GLOW.r, GLOW.g, GLOW.b, 0.8 * (1.0 - phase) * lp), maxf(2.0, _size.y * 0.002), true)
|
||||
var label := str(route.label)
|
||||
var fs := _px(0.03)
|
||||
var tw := _font.get_string_size(label, HORIZONTAL_ALIGNMENT_LEFT, -1, fs).x
|
||||
# Ao lado da linha (perpendicular, para a direita), longe dos pontos.
|
||||
var normal := Vector2(-dir.y, dir.x)
|
||||
if normal.x < 0.0:
|
||||
normal = -normal
|
||||
var mid := (a + b) / 2.0 + normal * fs * 2.2
|
||||
var box := Rect2(mid - Vector2(0, fs * 0.7), Vector2(tw + fs, fs * 1.4))
|
||||
draw_rect(box, _with_alpha(Color(0, 0, 0, 0.7), lp))
|
||||
draw_string(_font, box.position + Vector2(fs * 0.5, fs * 1.0), label, HORIZONTAL_ALIGNMENT_LEFT, -1, fs, _with_alpha(GLOW, lp))
|
||||
|
||||
var markers: Array = m.markers
|
||||
for i in markers.size():
|
||||
var mk: Dictionary = markers[i]
|
||||
var pop := _ease_out(_progress(0.4 + float(i) * 0.25, 0.4))
|
||||
if pop <= 0.0:
|
||||
continue
|
||||
var pos: Vector2 = mk.pos
|
||||
var fs := _px(0.026)
|
||||
if mk.kind == "island":
|
||||
var r := _size.y * 0.012 * pop
|
||||
draw_colored_polygon(PackedVector2Array([pos + Vector2(-r * 1.4, 0), pos + Vector2(-r * 0.6, -r), pos + Vector2(r * 0.8, -r * 0.8),
|
||||
pos + Vector2(r * 1.5, r * 0.1), pos + Vector2(r * 0.5, r * 0.9), pos + Vector2(-r * 0.9, r * 0.7)]), Color(LAND_EDGE, pop))
|
||||
draw_circle(pos, r * 2.6, Color(GLOW.r, GLOW.g, GLOW.b, 0.18 * pop))
|
||||
else:
|
||||
draw_circle(pos, _size.y * 0.007 * pop, Color(TEXT, pop))
|
||||
draw_circle(pos, _size.y * 0.004 * pop, Color(ACCENT, pop))
|
||||
var tw := _font.get_string_size(mk.label, HORIZONTAL_ALIGNMENT_LEFT, -1, fs).x
|
||||
var right_side := pos.x + tw + fs < _size.x * 0.95
|
||||
var text_pos := pos + (Vector2(fs * 0.8, fs * 0.35) if right_side else Vector2(-tw - fs * 0.8, fs * 0.35))
|
||||
if mk.kind == "island":
|
||||
# Ilha: nome centralizado embaixo (no mar), sem cruzar a costa.
|
||||
text_pos = pos + Vector2(-tw / 2.0, _size.y * 0.035 + fs * 0.6)
|
||||
text_pos.x = clampf(text_pos.x, _size.x * 0.03, _size.x * 0.97 - tw)
|
||||
draw_string(_font, text_pos + Vector2(2, 2), mk.label, HORIZONTAL_ALIGNMENT_LEFT, -1, fs, Color(0, 0, 0, 0.6 * pop))
|
||||
draw_string(_font, text_pos, mk.label, HORIZONTAL_ALIGNMENT_LEFT, -1, fs, Color(TEXT, pop))
|
||||
|
||||
draw_set_transform(Vector2.ZERO, 0.0, Vector2.ONE)
|
||||
# Título no alto e aviso de mapa ilustrativo (fora do zoom).
|
||||
var title := str(_p.get("title", ""))
|
||||
if not title.is_empty():
|
||||
_text_block(title, _size.y * 0.07, _px(0.04), Color(TEXT, _ease_out(_progress(0.1, 0.6))), _font, 0.86, 2)
|
||||
draw_string(_font_regular, Vector2(_size.x * 0.05, _size.y * 0.965), "Mapa ilustrativo", HORIZONTAL_ALIGNMENT_LEFT, -1, _px(0.016), Color(1, 1, 1, 0.45))
|
||||
@@ -0,0 +1,84 @@
|
||||
extends RefCounted
|
||||
## Contrato das cenas do documentário:
|
||||
## { "id": "...", "kind": "doc2d" | "doc3d",
|
||||
## "video": { "width": 1080, "height": 1920, "fps": 30, "durationSeconds": 6.2 },
|
||||
## "template": <modelo do tipo>, "params": { ... } }
|
||||
## doc2d (motion graphics, doc2d_canvas.gd): "title" | "counter" | "map"
|
||||
## doc3d (cena 3D da biblioteca): o nome de uma pasta em godot/library/ ("island", ...)
|
||||
## A duração vem do áudio do trecho: a cena dura exatamente o que a narração dura.
|
||||
## params.variant (inteiro, opcional): variação de layout/câmera para "gerar de novo".
|
||||
|
||||
const TEMPLATES_2D := ["title", "counter", "map"]
|
||||
const LIBRARY_DIR := "res://library"
|
||||
|
||||
|
||||
## Script da cena 3D da biblioteca: res://library/<id>/template.gd.
|
||||
static func library_script(id: String) -> String:
|
||||
return "%s/%s/template.gd" % [LIBRARY_DIR, id]
|
||||
|
||||
|
||||
## Cenas 3D disponíveis (pastas da biblioteca com template.gd).
|
||||
static func library_templates() -> Array:
|
||||
var out := []
|
||||
var dir := DirAccess.open(LIBRARY_DIR)
|
||||
if dir == null:
|
||||
return out
|
||||
for name in dir.get_directories():
|
||||
if ResourceLoader.exists(library_script(name)):
|
||||
out.append(name)
|
||||
return out
|
||||
|
||||
|
||||
static func load_file(path: String) -> Dictionary:
|
||||
if not FileAccess.file_exists(path):
|
||||
return {"ok": false, "errors": ["arquivo não encontrado: %s" % path]}
|
||||
var parsed = JSON.parse_string(FileAccess.get_file_as_string(path))
|
||||
if typeof(parsed) != TYPE_DICTIONARY:
|
||||
return {"ok": false, "errors": ["JSON inválido ou não é objeto"]}
|
||||
return validate(parsed)
|
||||
|
||||
|
||||
static func validate(raw: Dictionary) -> Dictionary:
|
||||
var errors := []
|
||||
if typeof(raw.get("id")) != TYPE_STRING or str(raw.id).is_empty():
|
||||
errors.append("id: texto obrigatório")
|
||||
var kind := str(raw.get("kind", ""))
|
||||
if not (kind in ["doc2d", "doc3d"]):
|
||||
errors.append("kind: \"doc2d\" ou \"doc3d\"")
|
||||
var video = raw.get("video")
|
||||
if typeof(video) != TYPE_DICTIONARY:
|
||||
errors.append("video: objeto obrigatório")
|
||||
return {"ok": false, "errors": errors}
|
||||
for key in ["width", "height", "fps", "durationSeconds"]:
|
||||
if not (typeof(video.get(key)) in [TYPE_INT, TYPE_FLOAT]) or float(video.get(key)) <= 0.0:
|
||||
errors.append("video.%s: número positivo obrigatório" % key)
|
||||
if errors.is_empty():
|
||||
if float(video.durationSeconds) > 120.0:
|
||||
errors.append("video.durationSeconds: máximo 120 s por cena")
|
||||
if int(video.fps) < 1 or int(video.fps) > 60:
|
||||
errors.append("video.fps: entre 1 e 60")
|
||||
var template = raw.get("template")
|
||||
if kind == "doc2d" and not (template in TEMPLATES_2D):
|
||||
errors.append("template: um de %s para doc2d" % [TEMPLATES_2D])
|
||||
if kind == "doc3d" and not (typeof(template) == TYPE_STRING and ResourceLoader.exists(library_script(template))):
|
||||
errors.append("template: cena 3D \"%s\" não existe na biblioteca (godot/library/). Disponíveis: %s" % [template, library_templates()])
|
||||
var params = raw.get("params", {})
|
||||
if typeof(params) != TYPE_DICTIONARY:
|
||||
errors.append("params: objeto")
|
||||
elif template == "counter" and not (typeof(params.get("value")) in [TYPE_INT, TYPE_FLOAT]):
|
||||
errors.append("params.value: número obrigatório no modelo counter")
|
||||
elif template == "title" and str(params.get("title", "")).strip_edges().is_empty():
|
||||
errors.append("params.title: texto obrigatório no modelo title")
|
||||
elif template == "map" and typeof(params.get("markers", [])) != TYPE_ARRAY:
|
||||
errors.append("params.markers: lista")
|
||||
if not errors.is_empty():
|
||||
return {"ok": false, "errors": errors}
|
||||
var cfg := raw.duplicate(true)
|
||||
cfg.video.fps = int(video.fps)
|
||||
cfg.video.width = int(video.width)
|
||||
cfg.video.height = int(video.height)
|
||||
cfg.video.duration = float(video.durationSeconds)
|
||||
cfg.video.total_frames = int(round(float(video.durationSeconds) * float(video.fps)))
|
||||
if not cfg.has("params"):
|
||||
cfg.params = {}
|
||||
return {"ok": true, "config": cfg}
|
||||
@@ -0,0 +1,196 @@
|
||||
extends Node
|
||||
## Cenas do documentário: 2D (motion graphics: mapa, contador, título; doc2d_canvas.gd) e
|
||||
## 3D (cenas da BIBLIOTECA: res://library/<template>/template.gd), escolhidas pelo "kind" do JSON.
|
||||
## Cena 3D nova = pasta nova em godot/library/ (veja doc/godot/cenas.md); nada aqui muda.
|
||||
## Mesmo protocolo do main.gd (rua 3D), para o lançador tratar as duas igual:
|
||||
## --config <json> | --validate-only | --manifest <json> | --warmup-frames <n>
|
||||
## Render (Movie Maker): t = quadro / fps, quadros de aquecimento em t=0 e um
|
||||
## manifesto com quadros produzidos e um resumo determinístico do estado.
|
||||
|
||||
const DocConfig := preload("res://scripts/doc/doc_config.gd")
|
||||
const Doc2DCanvas := preload("res://scripts/doc/doc2d_canvas.gd")
|
||||
|
||||
const EXIT_INVALID_CONFIG := 2
|
||||
const EXIT_ENVIRONMENT := 3
|
||||
const EXIT_MANIFEST := 4
|
||||
const DEFAULT_WARMUP_FRAMES := 3
|
||||
const MAX_WARMUP_FRAMES := 30
|
||||
|
||||
var _cfg: Dictionary
|
||||
## Doc2DCanvas (Node2D) ou a cena 3D da biblioteca (Node3D): setup(cfg, tamanho), apply(t) e state_signature().
|
||||
var _canvas: Node
|
||||
var _render_mode := false
|
||||
var _frame := 0
|
||||
var _warmup_frames := DEFAULT_WARMUP_FRAMES
|
||||
var _warmup_done := 0
|
||||
var _total_frames := 0
|
||||
var _fps := 30
|
||||
var _preview_time := 0.0
|
||||
var _manifest_path := ""
|
||||
var _config_path := ""
|
||||
var _state_lines := PackedStringArray()
|
||||
var _started_msec := 0
|
||||
var _halted := false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_started_msec = Time.get_ticks_msec()
|
||||
var args := _parse_user_args(OS.get_cmdline_user_args())
|
||||
if not args.has("config"):
|
||||
printerr("ARGS_INVALID --config é obrigatório na cena do documentário")
|
||||
_halt(EXIT_INVALID_CONFIG)
|
||||
return
|
||||
_config_path = _resolve_path(str(args.config))
|
||||
_render_mode = Engine.get_write_movie_path() != ""
|
||||
_manifest_path = _resolve_path(str(args.manifest)) if args.has("manifest") else ""
|
||||
if args.has("warmup-frames"):
|
||||
var value := str(args["warmup-frames"])
|
||||
if not value.is_valid_int() or int(value) < 0 or int(value) > MAX_WARMUP_FRAMES:
|
||||
printerr("ARGS_INVALID --warmup-frames precisa ser inteiro entre 0 e %d" % MAX_WARMUP_FRAMES)
|
||||
_halt(EXIT_INVALID_CONFIG)
|
||||
return
|
||||
_warmup_frames = int(value)
|
||||
|
||||
var result := DocConfig.load_file(_config_path)
|
||||
if not result.ok:
|
||||
printerr("CONFIG_INVALID %s" % _config_path)
|
||||
for e in result.errors:
|
||||
printerr(" - " + str(e))
|
||||
_halt(EXIT_INVALID_CONFIG)
|
||||
return
|
||||
_cfg = result.config
|
||||
# Cena 3D da biblioteca: o script precisa compilar. Erro aqui reprova JÁ (na validação),
|
||||
# em vez de virar um laço infinito de quadros com "apply em Nil".
|
||||
var scene_script: GDScript = null
|
||||
if _cfg.kind == "doc3d":
|
||||
scene_script = load(DocConfig.library_script(_cfg.template)) as GDScript
|
||||
if scene_script == null or not scene_script.can_instantiate():
|
||||
printerr("SCENE_SCRIPT_INVALID %s: o template.gd não compila (veja os erros de GDScript acima)" % DocConfig.library_script(_cfg.template))
|
||||
_halt(EXIT_INVALID_CONFIG)
|
||||
return
|
||||
if args.has("validate-only"):
|
||||
print("CONFIG_OK %s (%s, %d quadros, modelo %s)" % [_cfg.id, _config_path, _cfg.video.total_frames, _cfg.template])
|
||||
_halt(0)
|
||||
return
|
||||
|
||||
_fps = _cfg.video.fps
|
||||
_total_frames = _cfg.video.total_frames
|
||||
var viewport_size := get_viewport().get_visible_rect().size
|
||||
if _render_mode:
|
||||
var movie_dir := Engine.get_write_movie_path().get_base_dir()
|
||||
if movie_dir.is_relative_path():
|
||||
movie_dir = ProjectSettings.globalize_path("res://").path_join(movie_dir)
|
||||
if not DirAccess.dir_exists_absolute(movie_dir):
|
||||
printerr("RENDER_ENVIRONMENT pasta de saída do Movie Maker não existe: %s" % movie_dir)
|
||||
_halt(EXIT_ENVIRONMENT)
|
||||
return
|
||||
var expected := Vector2(_cfg.video.width, _cfg.video.height)
|
||||
if viewport_size != expected:
|
||||
printerr("RENDER_ENVIRONMENT viewport %s difere da configuração %s (use o lançador, que gera override.cfg)" % [viewport_size, expected])
|
||||
_halt(EXIT_ENVIRONMENT)
|
||||
return
|
||||
|
||||
if _cfg.kind == "doc3d":
|
||||
_canvas = scene_script.new()
|
||||
else:
|
||||
_canvas = Doc2DCanvas.new()
|
||||
if _canvas == null or not _canvas.has_method("apply") or not _canvas.has_method("setup"):
|
||||
printerr("SCENE_SCRIPT_INVALID a cena não tem setup(cfg, tamanho) e apply(t)")
|
||||
_halt(EXIT_INVALID_CONFIG)
|
||||
return
|
||||
_canvas.name = "Canvas"
|
||||
add_child(_canvas)
|
||||
_canvas.setup(_cfg, viewport_size)
|
||||
_canvas.apply(0.0)
|
||||
print("SCENE_READY id=%s mode=%s frames=%d fps=%d viewport=%dx%d template=%s" % [
|
||||
_cfg.id, "render" if _render_mode else "preview", _total_frames, _fps,
|
||||
int(viewport_size.x), int(viewport_size.y), _cfg.template])
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if _cfg.is_empty() or _halted:
|
||||
return
|
||||
if not _render_mode:
|
||||
_preview_time = fmod(_preview_time + delta, maxf(_cfg.video.duration, 0.001))
|
||||
_canvas.apply(_preview_time)
|
||||
return
|
||||
if _warmup_done < _warmup_frames:
|
||||
_canvas.apply(0.0)
|
||||
_warmup_done += 1
|
||||
return
|
||||
var t := float(_frame) / float(_fps)
|
||||
_canvas.apply(t)
|
||||
_state_lines.append("%.4f|%s" % [t, _canvas.state_signature()])
|
||||
_frame += 1
|
||||
if _frame >= _total_frames:
|
||||
_finish_render()
|
||||
|
||||
|
||||
func _finish_render() -> void:
|
||||
var size := get_viewport().get_visible_rect().size
|
||||
var manifest := {
|
||||
"configId": _cfg.id,
|
||||
"configPath": _config_path,
|
||||
"kind": _cfg.kind,
|
||||
"template": _cfg.template,
|
||||
"fps": _fps,
|
||||
"durationSeconds": _cfg.video.duration,
|
||||
"framesRendered": _frame,
|
||||
"expectedFrames": _total_frames,
|
||||
"warmupFrames": _warmup_frames,
|
||||
"firstSceneFrameIndex": _warmup_frames,
|
||||
"pngFramesWritten": _warmup_frames + _frame,
|
||||
"viewport": [int(size.x), int(size.y)],
|
||||
"renderer": {
|
||||
"method": RenderingServer.get_current_rendering_method(),
|
||||
"driver": RenderingServer.get_current_rendering_driver_name(),
|
||||
"adapter": RenderingServer.get_video_adapter_name(),
|
||||
"vendor": RenderingServer.get_video_adapter_vendor(),
|
||||
},
|
||||
"godotVersion": Engine.get_version_info().string,
|
||||
"scene": {"template": _cfg.template},
|
||||
"stateDigest": "\n".join(_state_lines).md5_text(),
|
||||
"wallClockSeconds": (Time.get_ticks_msec() - _started_msec) / 1000.0,
|
||||
}
|
||||
if _manifest_path != "":
|
||||
DirAccess.make_dir_recursive_absolute(_manifest_path.get_base_dir())
|
||||
var file := FileAccess.open(_manifest_path, FileAccess.WRITE)
|
||||
if file == null:
|
||||
printerr("MANIFEST_WRITE_FAILED %s (erro %d)" % [_manifest_path, FileAccess.get_open_error()])
|
||||
get_tree().quit(EXIT_MANIFEST)
|
||||
return
|
||||
file.store_string(JSON.stringify(manifest, " "))
|
||||
file.close()
|
||||
print("RENDER_DONE frames=%d warmup=%d fps=%d digest=%s" % [_frame, _warmup_frames, _fps, manifest.stateDigest])
|
||||
get_tree().quit(0)
|
||||
|
||||
|
||||
func _halt(code: int) -> void:
|
||||
_halted = true
|
||||
get_tree().quit(code)
|
||||
|
||||
|
||||
func _parse_user_args(raw: PackedStringArray) -> Dictionary:
|
||||
var out := {}
|
||||
var i := 0
|
||||
while i < raw.size():
|
||||
var arg := raw[i]
|
||||
if arg.begins_with("--"):
|
||||
var key := arg.substr(2)
|
||||
if key.contains("="):
|
||||
out[key.get_slice("=", 0)] = key.substr(key.find("=") + 1)
|
||||
elif i + 1 < raw.size() and not raw[i + 1].begins_with("--"):
|
||||
out[key] = raw[i + 1]
|
||||
i += 1
|
||||
else:
|
||||
out[key] = true
|
||||
i += 1
|
||||
return out
|
||||
|
||||
|
||||
static func _resolve_path(path: String) -> String:
|
||||
var p := path.replace("\\", "/")
|
||||
if p.is_absolute_path():
|
||||
return p.simplify_path()
|
||||
var root := ProjectSettings.globalize_path("res://").trim_suffix("/").get_base_dir()
|
||||
return root.path_join(p).simplify_path()
|
||||
Reference in New Issue
Block a user