-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_example.rs
102 lines (99 loc) · 3.55 KB
/
basic_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
use bevy::prelude::*;
use bevy_inspector_egui::WorldInspectorPlugin;
use bevy_tickles::prelude::modifiers::*;
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_startup_system(spawn_particle_system)
.add_startup_system(spawn_cubes)
.run();
}
fn spawn_particle_system(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn_bundle(PerspectiveCameraBundle {
transform: Transform::from_xyz(10.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..PerspectiveCameraBundle::new_3d()
});
commands.spawn_bundle(DirectionalLightBundle::default());
commands
.spawn_bundle(ParticleSystemBundle {
transform: Transform::from_xyz(0., 5., 0.),
material: ParticleMaterial::Image(asset_server.load("wrench.png")),
particle_params: ParticleParams {
rotation: RotationMode::FreeRotation {
start_rotation: RangeOrFixed::Range {
min: -6.0,
max: 6.0,
},
start_angular_velocity: Default::default(),
},
start_size: 0.0.into(),
start_speed: 2.0.into(),
..Default::default()
},
particle_emitter: ParticleEmitter {
rate: 20.0,
shape: EmitterShape {
shape: Shape::Sphere(Sphere {
radius: 0.2,
..Default::default()
}),
..Default::default()
},
..Default::default()
},
..Default::default()
})
.insert(ColorOverLifeTime(
ColorGradient::empty()
.add_point(0.0, Color::WHITE)
.add_point(0.3, Color::ORANGE)
.add_point(0.5, Color::GREEN)
.add_point(1.0, Color::rgba(0.5, 0.5, 1.0, 0.0)),
))
.insert(SizeOverTime(0.5))
.insert(ParticleGravity(Vec3::new(0., -1.5, 0.)))
.insert(AngularVelocityOverTime(1.0))
.insert(OrbitalVelocityOverLifeTime::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()
});
}