repeated_texture/
repeated_texture.rs1use bevy::{
5 image::{ImageAddressMode, ImageLoaderSettings, ImageSampler, ImageSamplerDescriptor},
6 math::Affine2,
7 prelude::*,
8};
9
10fn main() {
11 App::new()
12 .add_plugins(DefaultPlugins)
13 .add_systems(Startup, setup)
14 .run();
15}
16
17fn setup(
18 mut commands: Commands,
19 asset_server: Res<AssetServer>,
20 mut meshes: ResMut<Assets<Mesh>>,
21 mut materials: ResMut<Assets<StandardMaterial>>,
22) {
23 let image_with_default_sampler =
24 asset_server.load("textures/fantasy_ui_borders/panel-border-010.png");
25
26 commands.spawn((
28 Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
29 MeshMaterial3d(materials.add(StandardMaterial {
30 base_color_texture: Some(image_with_default_sampler.clone()),
31 ..default()
32 })),
33 Transform::from_translation(Vec3::ZERO),
34 ));
35
36 commands.spawn((
38 Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
39 MeshMaterial3d(materials.add(StandardMaterial {
40 base_color_texture: Some(asset_server.load_with_settings(
41 "textures/fantasy_ui_borders/panel-border-010-repeated.png",
42 |s: &mut _| {
43 *s = ImageLoaderSettings {
44 sampler: ImageSampler::Descriptor(ImageSamplerDescriptor {
45 address_mode_u: ImageAddressMode::Repeat,
47 address_mode_v: ImageAddressMode::Repeat,
48 ..default()
49 }),
50 ..default()
51 }
52 },
53 )),
54
55 uv_transform: Affine2::from_scale(Vec2::new(2., 3.)),
58 ..default()
59 })),
60 Transform::from_xyz(-1.5, 0.0, 0.0),
61 ));
62
63 commands.spawn((
65 Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
66 MeshMaterial3d(materials.add(StandardMaterial {
67 base_color_texture: Some(image_with_default_sampler),
71
72 uv_transform: Affine2::from_scale(Vec2::new(2., 3.)),
75 ..default()
76 })),
77 Transform::from_xyz(1.5, 0.0, 0.0),
78 ));
79
80 commands.spawn((
82 PointLight {
83 shadows_enabled: true,
84 ..default()
85 },
86 Transform::from_xyz(4.0, 8.0, 4.0),
87 ));
88 commands.spawn((
90 Camera3d::default(),
91 Transform::from_xyz(0.0, 1.5, 4.0).looking_at(Vec3::ZERO, Vec3::Y),
92 ));
93}