62 lines
1.7 KiB
Rust
62 lines
1.7 KiB
Rust
use bevy::{color::palettes::css::RED, prelude::*, render::storage::ShaderStorageBuffer};
|
|
use bevy_egui::EguiPlugin;
|
|
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
|
use mandelbulb::{MandelbulbExtension, MandelbulbMaterial, MandelbulbStorage};
|
|
|
|
mod camera;
|
|
mod mandelbulb;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((
|
|
DefaultPlugins,
|
|
EguiPlugin {
|
|
enable_multipass_for_primary_context: false,
|
|
},
|
|
WorldInspectorPlugin::new(),
|
|
))
|
|
.add_plugins((camera::plugin, mandelbulb::plugin))
|
|
.add_systems(Startup, setup)
|
|
.add_systems(Update, (rotate_things,))
|
|
.run();
|
|
}
|
|
|
|
fn setup(
|
|
mut commands: Commands,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut materials: ResMut<Assets<MandelbulbMaterial>>,
|
|
mut buffers: ResMut<Assets<ShaderStorageBuffer>>,
|
|
) {
|
|
let transform = Transform::from_xyz(0.0, 0.0, 0.0);
|
|
|
|
let storage = buffers.add(ShaderStorageBuffer::from(MandelbulbStorage::default()));
|
|
|
|
commands.spawn((
|
|
Mesh3d(meshes.add(Cuboid::new(2.0, 2.0, 2.0))),
|
|
MeshMaterial3d(materials.add(MandelbulbExtension::create_material(
|
|
StandardMaterial {
|
|
base_color: RED.into(),
|
|
alpha_mode: AlphaMode::Blend,
|
|
..default()
|
|
},
|
|
storage,
|
|
))),
|
|
transform,
|
|
Rotate,
|
|
));
|
|
|
|
commands.spawn((
|
|
DirectionalLight::default(),
|
|
Transform::from_xyz(1.0, 1.0, 1.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
Rotate,
|
|
));
|
|
}
|
|
|
|
#[derive(Component)]
|
|
struct Rotate;
|
|
|
|
fn rotate_things(mut q: Query<&mut Transform, With<Rotate>>, time: Res<Time>) {
|
|
for mut t in &mut q {
|
|
t.rotate_y(time.delta_secs());
|
|
}
|
|
}
|