diff --git a/src/experimental/_impl/_tiles_wfc_impl.scad b/src/experimental/_impl/_tiles_wfc_impl.scad index 157c79ac..95ef3626 100644 --- a/src/experimental/_impl/_tiles_wfc_impl.scad +++ b/src/experimental/_impl/_tiles_wfc_impl.scad @@ -73,10 +73,11 @@ function _replaceStatesAt(wf, x, y, states) = m_replace(wf_eigenstates(wf), x, y, states) ]; -function wf_not_collapsed_coords(wf) = - let(eigenstates = wf_eigenstates(wf), we = wf_width(wf) - 1, he = wf_height(wf) - 1, rx = [0:we]) +function wf_not_collapsed_coords(wf, notCollaspedCoords) = + let(eigenstates = wf_eigenstates(wf)) [ - for(y = [0:he], x = rx) + for(coord = notCollaspedCoords) + let(y = coord.y, x = coord.x) if(len(eigenstates[y][x]) != 1) [x, y] ]; @@ -172,7 +173,7 @@ function generate(nbr_dirs, compatibilities, wf, notCollaspedCoords, collapsing_ weights = coord_weights[2], nwf = propagate(nbr_dirs, compatibilities, wf_collapse(wf, coord_weights.x, coord_weights.y, weights), coord_weights) ) - generate(nbr_dirs, compatibilities, nwf, wf_not_collapsed_coords(nwf), collapsing_method); + generate(nbr_dirs, compatibilities, nwf, wf_not_collapsed_coords(nwf, notCollaspedCoords), collapsing_method); function neighbor_dirs(x, y, width, height) = [ if(x > 0) [-1, 0], // left diff --git a/src/experimental/tile_wfc.scad b/src/experimental/tile_wfc.scad index 0bd1147e..fcb8aea8 100644 --- a/src/experimental/tile_wfc.scad +++ b/src/experimental/tile_wfc.scad @@ -7,9 +7,11 @@ function tile_wfc(size, sample, method = "length") = let( w = size.x, h = size.y, + rangey = [0:h - 1], + rangex = [0:w - 1], nbr_dirs = [ - for(y = [0:h - 1]) - [for(x = [0:w - 1]) neighbor_dirs(x, y, w, h)] + for(y = rangey) + [for(x = rangex) neighbor_dirs(x, y, w, h)] ], // random start x = floor(rand(w * 0.25, w * 0.75)), @@ -17,15 +19,20 @@ function tile_wfc(size, sample, method = "length") = compatibilities = compatibilities_of_tiles(sample), wf = wave_function(w, h, weights_of_tiles(sample)), all_weights = wf_weights(wf), - states = wf_eigenstates_at(wf, x, y), - weights = [for(state = states) get_state_weight(all_weights, state)], + weights = [for(state = wf_eigenstates_at(wf, x, y)) get_state_weight(all_weights, state)], first_collasped_propagated = propagate( nbr_dirs, compatibilities, wf_collapse(wf, x, y, weights), [x, y] ), - notCollapsedCoords = wf_not_collapsed_coords(first_collasped_propagated) + fstp_states = wf_eigenstates(wf), + notCollapsedCoords = [ + for(y = rangey) + let(y_states = fstp_states[y]) + for(x = rangex) + if(len(y_states[x]) != 1) [x, y] + ] ) generate(nbr_dirs, compatibilities, first_collasped_propagated, notCollapsedCoords, collapsing(method));