OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / scenes / test / proc_nodes_import_test.gd

66 lines · gd ref:
@tool
extends ProcGeometryNode

## GraphImporter test: import a proc-nodes graph from JSON
## Simulates what would come from Blender's geometry_serializer.py

func _ready():
	_test_import()
	call_deferred("_apply_material")

func _apply_material():
	var mesh_child = get_node_or_null("MeshOutput")
	if mesh_child and mesh_child is MeshInstance3D:
		var mat = StandardMaterial3D.new()
		mat.albedo_color = Color(0.5, 0.7, 0.3)
		mat.roughness = 0.7
		mesh_child.material_override = mat

func _test_import():
	# JSON matching what geometry_serializer.py would produce from Blender
	# Graph: MeshGrid(10x10, 50x50) → Displace(strength=1.5, scale=0.4)
	var json_str = JSON.stringify({
		"version": 1,
		"nodes": [
			{
				"id": 0,
				"bl_type": "GeometryNodeMeshGrid",
				"proc_type": "MeshGrid",
				"label": "Grid",
				"position": [0, 0],
				"properties": {},
				"defaults": {"0": 10.0, "1": 10.0, "2": 50, "3": 50}
			},
			{
				"id": 1,
				"bl_type": "GeometryNodeSetPosition",
				"proc_type": "Displace",
				"label": "Noise Displace",
				"position": [200, 0],
				"properties": {},
				"defaults": {"1": 1.5, "2": 0.4, "3": 5, "4": 0.5}
			}
		],
		"connections": [
			{"from_node": 0, "from_port": 0, "to_node": 1, "to_port": 0}
		]
	})

	print("=== GRAPH IMPORT TEST ===")
	print("JSON length: ", json_str.length())

	var graph = GraphImporter.import_from_json(json_str)
	if graph == null:
		print("FAIL: GraphImporter returned null")
		return

	print("Imported graph: ", graph.get_node_count(), " nodes, ", graph.get_connection_count(), " connections")

	if graph.get_node_count() >= 2:
		print("PASS: Graph imported successfully")
		self.graph = graph
	else:
		print("FAIL: Expected at least 2 nodes")

	print("=== END IMPORT TEST ===")