OverviewFilesCommitsIssuesDocsReleasesPeers

proc-nodes / demo / group_input_probe.gd

52 lines · gd ref:
## Import a bridged graph, report what its Group Input actually carries, and bake.
##
## A Blender geometry tree's parameters are links from Group Input, and their
## VALUES live on the modifier. This prints the value each of those sockets
## delivers inside proc-nodes, which is the thing that was silently nothing.
##
## Args: <graph.json> <box subdivisions>
extends SceneTree

func _init() -> void:
	var a := OS.get_cmdline_user_args()
	var g: ProcNodeGraph = GraphImporter.import_from_json(FileAccess.get_file_as_string(a[0]))
	if g == null:
		push_error("import returned null"); quit(1); return
	print("imported: %d nodes, %d connections" % [g.get_node_count(), g.get_connection_count()])

	var gi := -1
	for i in range(g.get_node_count()):
		var n: ProcNode = g.get_node(i)
		if n != null and n.get_node_type() == "GroupInput":
			gi = i
			break
	if gi < 0:
		print("NO GROUP INPUT")
	else:
		print("group_input node %d, %d outputs" % [gi, g.get_node(gi).get_output_count()])
		for s in range(g.get_node(gi).get_output_count()):
			print("  socket %d = %s" % [s, str(g.evaluate_socket(gi, s))])

	var host := ProcGeometryNode.new()
	host.use_gpu = false
	var bm := BoxMesh.new()
	bm.size = Vector3(4.0, 4.0, 4.0)
	bm.subdivide_width = int(a[1])
	bm.subdivide_depth = int(a[1])
	bm.subdivide_height = int(a[1])
	host.set_input_mesh(bm)
	host.set_graph(g)
	get_root().add_child(host)
	var m: ArrayMesh = host.bake_mesh()
	if m == null or m.get_surface_count() == 0:
		print("BAKE: no mesh")
	else:
		var v: PackedVector3Array = m.surface_get_arrays(0)[Mesh.ARRAY_VERTEX]
		var lo := Vector3(INF, INF, INF)
		var hi := Vector3(-INF, -INF, -INF)
		for p in v:
			lo = lo.min(p); hi = hi.max(p)
		print("BAKE: %d verts  x %.4f..%.4f  y %.4f..%.4f  z %.4f..%.4f"
			% [v.size(), lo.x, hi.x, lo.y, hi.y, lo.z, hi.z])
	quit()