2022-11-12 23:35:01 +00:00
|
|
|
|
from geometry_script import *
|
|
|
|
|
|
2022-11-13 20:23:11 +00:00
|
|
|
|
@tree("Repeat Grid")
|
2025-07-04 21:03:02 +00:00
|
|
|
|
def repeat_grid(
|
|
|
|
|
geometry: Geometry,
|
|
|
|
|
columns: Int,
|
|
|
|
|
rows: Int,
|
|
|
|
|
spacing_x: Float = 0.0,
|
|
|
|
|
spacing_y: Float = 0.0
|
|
|
|
|
):
|
2025-07-04 20:32:21 +00:00
|
|
|
|
# measure your geometry’s bounds
|
|
|
|
|
bbox = geometry.bounding_box()
|
|
|
|
|
span_x = bbox.max.x - bbox.min.x
|
|
|
|
|
span_y = bbox.max.y - bbox.min.y
|
|
|
|
|
|
|
|
|
|
# total grid size = N * object size
|
2025-07-04 21:03:02 +00:00
|
|
|
|
total_x = columns * span_x + (columns - 1) * spacing_x
|
|
|
|
|
total_y = rows * span_y + (rows - 1) * spacing_y
|
2025-07-04 20:32:21 +00:00
|
|
|
|
|
|
|
|
|
# one extra vertex gives N cells
|
2022-11-13 20:23:11 +00:00
|
|
|
|
g = grid(
|
2025-07-04 20:32:21 +00:00
|
|
|
|
size_x=total_x, size_y=total_y,
|
2025-07-04 21:03:02 +00:00
|
|
|
|
vertices_x=columns + 1, vertices_y=rows + 1
|
2025-07-04 20:32:21 +00:00
|
|
|
|
).mesh.mesh_to_points()
|
|
|
|
|
|
2022-11-13 20:23:11 +00:00
|
|
|
|
return g.instance_on_points(instance=geometry)
|