OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / tools / build_undersea_geiss_graph.gd

49 lines · gd ref:
extends SceneTree
## SEED blender/undersea_geiss.tscn — the bridged scene holding our Geiss-style undersea
## graph (demo sprint §4): Node3D "UnderseaGeiss" / MeshInstance3D "Undersea" (the
## object Blender sees) / ProcGeometryNode "ProcGeoNodes" carrying UnderseaGeissGraph's
## FULL graph at the KNOBS defaults (UnderseaGeissGraph.HOLDER).
##
## ⛔ SEED ONLY. Once the scene exists IT is the source of truth — structure and knob
## values, edited in Godot or in Blender through blender-bridge, whichever updated last
## leading — so this refuses to overwrite it. To start over, move the scene aside
## first (git keeps every version).
##
## UNDERSEA_SEED_OUT=<path> writes there instead, whether or not the scene exists (gates).
##
## Run: "$HYPER_TPS_GODOT" --headless --path . --script res://tools/build_undersea_geiss_graph.gd


func _init() -> void:
	var dest := OS.get_environment("UNDERSEA_SEED_OUT")
	if dest == "":
		dest = UnderseaGeissGraph.SCENE
		if FileAccess.file_exists(dest):
			print("[seed_undersea] %s exists — it is the source of truth; not overwritten" % dest)
			quit(1)
			return
	var root := Node3D.new()
	root.name = "UnderseaGeiss"
	var path := String(UnderseaGeissGraph.HOLDER).split("/")   # ["Undersea", "ProcGeoNodes"]
	var obj := MeshInstance3D.new()
	obj.name = path[0]
	root.add_child(obj)
	obj.owner = root
	var holder := ProcGeometryNode.new()
	holder.name = path[1]
	holder.set_graph(UnderseaGeissGraph.make())
	obj.add_child(holder)
	holder.owner = root
	var ps := PackedScene.new()
	var err := ps.pack(root)
	if err == OK:
		err = ResourceSaver.save(ps, dest)
	# A --script save writes no uid (memory: reference_godot-tscn-save-drops-uid);
	# give the scene one so the editor and the bridge can refer to it stably.
	if err == OK:
		err = ResourceSaver.set_uid(dest, ResourceUID.create_id())
	root.free()
	print("[seed_undersea] %s: %s (%d nodes)" % [dest, error_string(err),
			UnderseaGeissGraph.make().get_node_count()])
	quit(0 if err == OK else 1)