OverviewFilesCommitsIssuesDocsReleasesPeers

proc-nodes / demo / mesh_dump_probe.gd

31 lines · gd ref:
## Bake a bridged graph and write its mesh (verts + triangles) as JSON.
##
## The instrument the geometry half of the socket audit needs: a Selection or a
## mode that is dropped changes WHICH elements an operation touched, which no
## value-level comparison can see.
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
	var host := ProcGeometryNode.new()
	host.use_gpu = false
	host.set_graph(g)
	get_root().add_child(host)
	var m: ArrayMesh = host.bake_mesh()
	var verts := []
	var tris := 0
	if m != null and m.get_surface_count() > 0:
		var arr := m.surface_get_arrays(0)
		var v: PackedVector3Array = arr[Mesh.ARRAY_VERTEX]
		for p in v:
			verts.append([p.x, p.y, p.z])
		var idx = arr[Mesh.ARRAY_INDEX]
		tris = (idx.size() / 3) if idx != null else (v.size() / 3)
	FileAccess.open(a[1], FileAccess.WRITE).store_string(
		JSON.stringify({"verts": verts, "tris": tris}))
	print("MESH: %d verts, %d tris" % [verts.size(), tris])
	quit()