[−][src]Struct wfc_tiled::TilePattern
Extracts a pattern from a tilemap and lets you run Wave Function Collapse on it.
This struct can be initialized from a .csv file, a vector, or a Grid.
It will automatically extract overapping patterns of the given size (in tiles), and respecting the orientation setting.
For example, if you don't want to allow your tiles to be rotated, use Orientation::Original
Afterwards call run_collapse() in order to generate a new tilemap based on the input.
WFC is not guaranteed to succeed, even with the correct input. For this reason there is a retry_times
parameter indicating the number of attemps that
will be done. If it still fails, the function will return an error.
Examples
let input_path = "example\\input.csv"; let tilesheet_path = "example\\tset.png"; let attempts = 1000; let pattern_size = 2; let output_size = Size::new(32, 32); // Extract patterns from input let pattern = TilePattern::from_csv(input_path, std::num::NonZeroU32::new(pattern_size).unwrap(), &[Orientation::Original]) .expect("Error while creating pattern"); // Run Wave Function Collapse let grid = pattern.run_collapse(output_size, attempts, WrapXY, ForbidNothing, &mut rand::thread_rng()) .expect("Error in WFC"); // Save as CSV grid_to_csv(&grid, "out.csv")?; // Save as Tiled .tmx file let tset = TileSet { image_path: tilesheet_path, image_size: Size::new(256, 1450), columns: 8, tile_count: 360, tile_size: Size::new(32, 32) }; grid_to_tiled(&grid, "out.tmx", tset)?;
Fields
grid: Grid<u32>
overlapping_patterns: OverlappingPatterns<u32>
Methods
impl TilePattern
[src]
pub fn new(
grid: Grid<u32>,
pattern_size: NonZeroU32,
orientation: &[Orientation]
) -> TilePattern
[src]
grid: Grid<u32>,
pattern_size: NonZeroU32,
orientation: &[Orientation]
) -> TilePattern
pub fn from_vec(
map: Vec<u32>,
size: Size,
pattern_size: NonZeroU32,
orientation: &[Orientation]
) -> TilePattern
[src]
map: Vec<u32>,
size: Size,
pattern_size: NonZeroU32,
orientation: &[Orientation]
) -> TilePattern
pub fn from_csv<P: AsRef<Path>>(
path: P,
pattern_size: NonZeroU32,
orientation: &[Orientation]
) -> Result<TilePattern, Box<dyn Error>>
[src]
path: P,
pattern_size: NonZeroU32,
orientation: &[Orientation]
) -> Result<TilePattern, Box<dyn Error>>
pub fn run_collapse<W: Wrap, F: ForbidPattern, R: Rng>(
&self,
output_size: Size,
retry_times: usize,
wrap: W,
forbid: F,
rng: &mut R
) -> Result<Grid<u32>, PropagateError>
[src]
&self,
output_size: Size,
retry_times: usize,
wrap: W,
forbid: F,
rng: &mut R
) -> Result<Grid<u32>, PropagateError>
Auto Trait Implementations
impl Send for TilePattern
impl Sync for TilePattern
impl Unpin for TilePattern
impl UnwindSafe for TilePattern
impl RefUnwindSafe for TilePattern
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,