diff --git a/src/experimental/_impl/_tiles_wfc_impl.scad b/src/experimental/_impl/_tiles_wfc_impl.scad index e8ed4f10..85ea8419 100644 --- a/src/experimental/_impl/_tiles_wfc_impl.scad +++ b/src/experimental/_impl/_tiles_wfc_impl.scad @@ -59,12 +59,9 @@ function get_state_weight(weights, state) = weights[search([state], weights)[0]] function wf_collapse(wf, x, y, weights) = let( states = wf_eigenstates_at(wf, x, y), - wets = is_undef(weights) ? - let(all_weights = wf_weights(wf)) [for(state = states) get_state_weight(all_weights, state)] : - weights, - threshold = rand() * sum(wets) + threshold = rand() * sum(weights) ) - _wf_collapse(wf, x, y, states, wets, len(states), threshold); + _wf_collapse(wf, x, y, states, weights, len(states), threshold); function _wf_collapse(wf, x, y, states, weights, leng, threshold, i = 0) = threshold < 0 || i == leng ? wf : diff --git a/src/experimental/tile_wfc.scad b/src/experimental/tile_wfc.scad index f02f9e92..be906518 100644 --- a/src/experimental/tile_wfc.scad +++ b/src/experimental/tile_wfc.scad @@ -11,11 +11,15 @@ function tile_wfc(size, sample) = w = tilemap_width(tm), h = tilemap_height(tm), compatibilities = tilemap_compatibilities(tm), + wf = tilemap_wf(tm), + all_weights = wf_weights(wf), + states = wf_eigenstates_at(wf, x, y), + weights = [for(state = states) get_state_weight(all_weights, state)], first_collasped_propagated = propagate( w, h, compatibilities, - wf_collapse(tilemap_wf(tm), x, y), + wf_collapse(wf, x, y, weights), x, y ),