OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / scenes / test / proc_nodes_points_test.gd

71 lines · gd ref:
@tool
extends ProcGeometryNode

## Point distribution test: MeshGrid → DistributePointsOnFaces → PointsToVertices
## Expected: 500 random points scattered across a flat grid surface
## (Points rendered as vertices — may need to zoom in or use a particle shader to see)

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(1.0, 0.3, 0.1)
		mat.roughness = 0.5
		mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
		mat.point_size = 4.0
		mat.use_point_size = true
		mesh_child.material_override = mat

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

	# 0: Grid as scatter surface
	var grid = MeshGridNode.new()
	g.add_node(grid)
	# 1-4: Grid params (10x10, 20x20 verts)
	var sx = ValueNode.new()
	sx.value = 10.0
	g.add_node(sx)
	var sy = ValueNode.new()
	sy.value = 10.0
	g.add_node(sy)
	var vx = ValueNode.new()
	vx.value = 20.0
	g.add_node(vx)
	var vy = ValueNode.new()
	vy.value = 20.0
	g.add_node(vy)

	# 5: DistributePointsOnFaces
	var scatter = DistributePointsOnFacesNode.new()
	g.add_node(scatter)
	# 6: Count
	var count = ValueNode.new()
	count.value = 500.0
	g.add_node(count)
	# 7: Seed
	var seed_val = ValueNode.new()
	seed_val.value = 42.0
	g.add_node(seed_val)

	# 8: PointsToVertices (convert pointcloud to mesh for display)
	var to_verts = PointsToVerticesNode.new()
	g.add_node(to_verts)

	# --- Connections ---
	g.connect_sockets(1, 0, 0, 0)   # sx → grid.SizeX
	g.connect_sockets(2, 0, 0, 1)   # sy → grid.SizeY
	g.connect_sockets(3, 0, 0, 2)   # vx → grid.VertsX
	g.connect_sockets(4, 0, 0, 3)   # vy → grid.VertsY
	g.connect_sockets(0, 0, 5, 0)   # grid → scatter.Geometry
	g.connect_sockets(6, 0, 5, 1)   # count → scatter.Count
	g.connect_sockets(7, 0, 5, 2)   # seed → scatter.Seed
	g.connect_sockets(5, 0, 8, 0)   # scatter → to_verts.Points

	self.graph = g
	print("Points test: 500 random points scattered on 10x10 grid")