Skip to content

Commit

Permalink
Fix texture index mapper in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
splashdust committed Nov 17, 2024
1 parent ae78f0b commit 3f8b72b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
12 changes: 11 additions & 1 deletion examples/bombs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*, utils::HashMap};
use bevy_voxel_world::prelude::*;
use noise::{HybridMulti, NoiseFn, Perlin};
use std::time::Duration;
use std::{sync::Arc, time::Duration};
#[derive(Resource, Clone, Default)]
struct MainWorld;

Expand All @@ -14,6 +14,16 @@ impl VoxelWorldConfig for MainWorld {
fn voxel_lookup_delegate(&self) -> VoxelLookupDelegate<Self::MaterialIndex> {
Box::new(move |_chunk_pos| get_voxel_fn())
}

fn texture_index_mapper(&self) -> Arc<dyn Fn(Self::MaterialIndex) -> [u32; 3] + Send + Sync> {
Arc::new(|mat| match mat {
0 => [0, 0, 0],
1 => [1, 1, 1],
2 => [2, 2, 2],
3 => [3, 3, 3],
_ => [0, 0, 0],
})
}
}

fn main() {
Expand Down
10 changes: 10 additions & 0 deletions examples/multiple_worlds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ impl VoxelWorldConfig for MainWorld {
fn voxel_lookup_delegate(&self) -> VoxelLookupDelegate<Self::MaterialIndex> {
Box::new(move |_chunk_pos| get_voxel_fn())
}

fn texture_index_mapper(&self) -> Arc<dyn Fn(Self::MaterialIndex) -> [u32; 3] + Send + Sync> {
Arc::new(|mat| match mat {
0 => [0, 0, 0],
1 => [1, 1, 1],
2 => [2, 2, 2],
3 => [3, 3, 3],
_ => [0, 0, 0],
})
}
}

// This is the second world configuration. In this example, the second world is using a custom material.
Expand Down
12 changes: 12 additions & 0 deletions examples/noise_terrain.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*, utils::HashMap};
use bevy_voxel_world::prelude::*;
use noise::{HybridMulti, NoiseFn, Perlin};
Expand All @@ -15,6 +17,16 @@ impl VoxelWorldConfig for MainWorld {
fn voxel_lookup_delegate(&self) -> VoxelLookupDelegate<Self::MaterialIndex> {
Box::new(move |_chunk_pos| get_voxel_fn())
}

fn texture_index_mapper(&self) -> Arc<dyn Fn(Self::MaterialIndex) -> [u32; 3] + Send + Sync> {
Arc::new(|mat| match mat {
0 => [0, 0, 0],
1 => [1, 1, 1],
2 => [2, 2, 2],
3 => [3, 3, 3],
_ => [0, 0, 0],
})
}
}

fn main() {
Expand Down

0 comments on commit 3f8b72b

Please sign in to comment.