OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / scenes / test / proc_nodes_sim_test.gd

62 lines · gd ref:
@tool
extends ProcGeometryNode

## SimulationZone test: MeshCube with accumulated position offset
## Each frame: prev_state + offset(0, -0.1, 0) = cube falls slowly
## Expected: red cube drifting downward continuously (resets on scene reload)
## Note: offset is per-frame, not time-scaled — at 60fps = 6 units/sec downward

func _ready():
	_build_graph()
	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.7, 0.2, 0.3)
		mat.roughness = 0.5
		mesh_child.material_override = mat

func _build_graph():
	var g = ProcNodeGraph.new()

	# 0: Cube (initial state — at origin)
	var cube = MeshCubeNode.new()
	g.add_node(cube)

	# 1: SimulationZoneInput
	var sim_in = SimulationZoneInputNode.new()
	sim_in.zone_id = 1
	g.add_node(sim_in)

	# 2: SetPosition (body — apply downward offset each frame)
	var set_pos = SetPositionNode.new()
	g.add_node(set_pos)

	# 3: Small downward offset per frame
	var gravity = VectorNode.new()
	gravity.value = Vector3(0, -0.1, 0)
	g.add_node(gravity)

	# 4: SimulationZoneOutput
	var sim_out = SimulationZoneOutputNode.new()
	sim_out.zone_id = 1
	g.add_node(sim_out)

	# --- Connections ---
	# cube → sim_in.Geometry (initial state)
	g.connect_sockets(0, 0, 1, 0)

	# sim_in.Geometry (output 1, prev frame) → set_pos.Geometry (input 0)
	g.connect_sockets(1, 1, 2, 0)

	# gravity → set_pos.Offset (input 1)
	g.connect_sockets(3, 0, 2, 1)

	# set_pos → sim_out.Geometry (input 0)
	g.connect_sockets(2, 0, 4, 0)

	self.graph = g
	print("SimulationZone test: cube falling with accumulated offset (continuous evaluation)")