-
-
Save stevenctl/3492292c6461c8235e22f858c22ce6b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# do some auto-tiling stuff based on simple rules | |
# there is probably an "n-bit autotiling" name for what I'm doing here. | |
def base_tile_for(cell_coord, cube_id): | |
cube_arr = int_to_cube(cube_id) | |
prefix = ["Bottom", "Top"][int(cell_coord[2])] | |
def comp_adj(coco): | |
# west, east, south, north, bottom, top | |
adjacency = [] | |
for axis in [0, 1, 2]: | |
# check directly adjacent (this axis changes) | |
for delta in [-1, 1]: | |
delta_vec = np.array([0, 0, 0]) | |
delta_vec[axis] = delta | |
cc = coco + delta_vec | |
adjacency.append(cube_cell_filled(cube_arr, cc)) | |
xx, yy, zz = any(adjacency[:2]), any(adjacency[2:4]), any(adjacency[4:]) | |
adj_count = sum(1 for v in [xx, yy, zz] if v) | |
# check how many in this axis's plane (only this axis stays the same): | |
n_in_axes = [ | |
cube_arr[coco[0], :, :].sum(), | |
cube_arr[:, coco[1], :].sum(), | |
cube_arr[:, :, coco[2]].sum(), | |
] | |
return adj_count, xx, yy, zz, [n == 4 for n in n_in_axes] | |
adj_axes, _, _, z_adj, walls = comp_adj(cell_coord) | |
if any(walls): | |
hw, vw = walls[0] or walls[1], walls[2] | |
if hw and vw: | |
suffix = "Lip" | |
# if adj_axes == 3: | |
# suffix += ".C" | |
elif walls[0] and walls[1]: | |
suffix = "Lip.V" | |
else: | |
if adj_axes == 2: | |
suffix = "Flat" if vw else "Wall" | |
else: | |
suffix = "Lip.Bend" if vw else "Lip.Bend.V" | |
elif adj_axes == 3: | |
suffix = "Bend.HV" | |
elif adj_axes == 0: | |
suffix = "Corner" | |
elif adj_axes == 1: | |
suffix = "Edge" | |
suffix += ".V" if z_adj else ".H" | |
elif adj_axes == 2: | |
suffix = "Bend" | |
suffix += ".V" if z_adj else ".H" | |
else: | |
raise Exception("Somehow adjacency count isn't covered..??") | |
return prefix + "." + suffix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment