blender-geometry-script/examples/Repeat Grid.py

26 wiersze
710 B
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from geometry_script import *
@tree("Repeat Grid")
def repeat_grid(
geometry: Geometry,
columns: Int,
rows: Int,
spacing_x: Float = 0.0,
spacing_y: Float = 0.0
):
# measure your geometrys 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
total_x = columns * span_x + (columns - 1) * spacing_x
total_y = rows * span_y + (rows - 1) * spacing_y
# one extra vertex gives N cells
g = grid(
size_x=total_x, size_y=total_y,
vertices_x=columns + 1, vertices_y=rows + 1
).mesh.mesh_to_points()
return g.instance_on_points(instance=geometry)