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,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