OverviewFilesCommitsIssuesDocsReleasesPeers

proc-nodes / demo / import_json_probe.gd

44 lines · gd ref:
## Import a Blender-bridged graph and try to evaluate it.
extends SceneTree
func _init() -> void:
	var a := OS.get_cmdline_user_args()
	var js := FileAccess.get_file_as_string(a[0])
	var g: ProcNodeGraph = GraphImporter.import_from_json(js)
	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 missing := 0
	for i in range(g.get_node_count()):
		var n: ProcNode = g.get_node(i)
		if n == null:
			missing += 1
		else:
			print("  %2d %s" % [i, n.get_node_type()])
	print("null nodes: %d" % missing)
	var host := ProcGeometryNode.new()
	host.use_gpu = false
	# THE CAGE. A Blender geometry tree acts on the object's own mesh, which its
	# Group Input carries; proc-nodes now takes the same thing as input_mesh.
	# A box, subdivided, matching the cage the Blender side displaces.
	if a.size() > 1:
		var bm := BoxMesh.new()
		bm.size = Vector3(40.0, 4.0, 40.0)
		bm.subdivide_width = int(a[1])
		bm.subdivide_depth = int(a[1])
		bm.subdivide_height = 2
		host.set_input_mesh(bm)
		print("input mesh: BoxMesh %d subdivisions" % int(a[1]))
	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 := INF
		var hi := -INF
		for p in v:
			lo = minf(lo, p.y); hi = maxf(hi, p.y)
		print("BAKE: %d verts, y %.2f .. %.2f" % [v.size(), lo, hi])
	quit()