-
Notifications
You must be signed in to change notification settings - Fork 0
/
animated_example.rs
109 lines (106 loc) · 3.56 KB
/
animated_example.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use bevy::prelude::*;
use bevy_flycam::*;
use bevy_inspector_egui::WorldInspectorPlugin;
use bevy_tickles::prelude::shapes::Sphere;
use bevy_tickles::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(ParticlesPlugin)
.add_plugin(WorldInspectorPlugin::default())
.add_plugin(NoCameraPlayerPlugin)
.add_startup_system(spawn_particle_system)
.add_startup_system(spawn_cubes)
.run();
}
fn spawn_particle_system(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut atlases: ResMut<Assets<TextureAtlas>>,
) {
commands
.spawn_bundle(PerspectiveCameraBundle {
transform: Transform::from_xyz(0.0, 5.0, 20.0).looking_at(Vec3::ZERO, Vec3::Y),
..PerspectiveCameraBundle::new_3d()
})
.insert(FlyCam);
commands.spawn_bundle(DirectionalLightBundle::default());
let smoke_texture = asset_server.load("fireworks.png");
let texture_atlas = atlases.add(TextureAtlas::from_grid(
smoke_texture,
Vec2::new(256.0, 256.0),
6,
5,
));
commands
.spawn_bundle(ParticleSystemBundle {
transform: Transform::from_xyz(0., 0., 0.),
material: ParticleTextureSheet {
texture_atlas,
mode: TextureSheetMode::AnimateOverLifetime(TextureSheetAnimation {
start_index: 0,
looping_mode: TextureSheetLoopingMode::None,
..Default::default()
}),
}
.into(),
particle_params: ParticleParams {
start_size: RangeOrFixed::Range { min: 1.0, max: 4.0 },
start_speed: 0.0.into(),
start_lifetime: 1.0.into(),
start_color: ColorGradient::rainbow().into(),
..Default::default()
},
particle_emitter: ParticleEmitter {
rate: 300.0,
shape: EmitterShape {
shape: Shape::Sphere(Sphere {
radius: 10.0,
hemisphere: false,
}),
thickness: 0.0,
..Default::default()
},
..Default::default()
},
..Default::default()
})
.insert(Name::new("Particle System"));
}
fn spawn_cubes(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let mesh = meshes.add(shape::Cube::new(1.).into());
commands.spawn_bundle(PbrBundle {
mesh: mesh.clone(),
material: materials.add(Color::WHITE.into()),
transform: Transform::from_xyz(0., 0., 0.),
..Default::default()
});
commands.spawn_bundle(PbrBundle {
mesh: mesh.clone(),
material: materials.add(Color::RED.into()),
transform: Transform::from_xyz(-5., 0., 0.),
..Default::default()
});
commands.spawn_bundle(PbrBundle {
mesh: mesh.clone(),
material: materials.add(Color::BLUE.into()),
transform: Transform::from_xyz(5., 0., 0.),
..Default::default()
});
commands.spawn_bundle(PbrBundle {
mesh: mesh.clone(),
material: materials.add(Color::GREEN.into()),
transform: Transform::from_xyz(0., 0., 5.),
..Default::default()
});
commands.spawn_bundle(PbrBundle {
mesh,
material: materials.add(Color::YELLOW.into()),
transform: Transform::from_xyz(0., 0., -5.),
..Default::default()
});
}