Change deprecated shapes to new primitives in examples. Fix example lighting.

This commit is contained in:
Robin KAY 2024-02-16 21:51:21 +00:00
parent e8fe3d4b95
commit 9622c85367
7 changed files with 65 additions and 98 deletions

View File

@ -1,10 +1,6 @@
use std::f32::consts::PI; use std::f32::consts::PI;
use bevy::{ use bevy::{prelude::*, scene::SceneInstance, window::close_on_esc};
prelude::{shape::Plane, *},
scene::SceneInstance,
window::close_on_esc,
};
use bevy_mod_outline::{ use bevy_mod_outline::{
AutoGenerateOutlineNormalsPlugin, InheritOutlineBundle, OutlineBundle, OutlinePlugin, AutoGenerateOutlineNormalsPlugin, InheritOutlineBundle, OutlineBundle, OutlinePlugin,
OutlineVolume, OutlineVolume,
@ -20,10 +16,7 @@ fn main() {
OutlinePlugin, OutlinePlugin,
AutoGenerateOutlineNormalsPlugin, AutoGenerateOutlineNormalsPlugin,
)) ))
.insert_resource(AmbientLight { .insert_resource(AmbientLight::default())
color: Color::WHITE,
brightness: 1.0,
})
.add_systems(Startup, setup) .add_systems(Startup, setup)
.add_systems(Update, (setup_scene_once_loaded, close_on_esc)) .add_systems(Update, (setup_scene_once_loaded, close_on_esc))
.run(); .run();
@ -47,10 +40,12 @@ fn setup(
// Plane // Plane
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Plane { mesh: meshes.add(
size: 500000.0, Plane3d::new(Vec3::Y)
subdivisions: 0, .mesh()
})), .size(500000.0, 500000.0)
.build(),
),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))), material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
..default() ..default()
}); });

View File

@ -1,9 +1,6 @@
use std::{f32::consts::TAU, num::Wrapping, time::Duration}; use std::{f32::consts::TAU, num::Wrapping, time::Duration};
use bevy::{ use bevy::{prelude::*, window::close_on_esc};
prelude::{shape::Capsule, *},
window::close_on_esc,
};
use bevy_mod_outline::*; use bevy_mod_outline::*;
@ -36,14 +33,14 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
commands.insert_resource(MyAssets { commands.insert_resource(MyAssets {
mesh: meshes.add(Mesh::from(Capsule { mesh: meshes.add(
radius: 1.0, Capsule3d::new(1.0, 2.0)
rings: 10, .mesh()
depth: 2.0, .rings(10)
latitudes: 15, .latitudes(15)
longitudes: 15, .longitudes(15)
..default() .build(),
})), ),
material: materials.add(StandardMaterial::from(Color::BEIGE)), material: materials.add(StandardMaterial::from(Color::BEIGE)),
}); });

View File

@ -13,10 +13,7 @@ fn main() {
), ),
) )
.add_plugins(OutlinePlugin) .add_plugins(OutlinePlugin)
.insert_resource(AmbientLight { .insert_resource(AmbientLight::default())
color: Color::WHITE,
brightness: 1.0,
})
.add_systems(Startup, setup) .add_systems(Startup, setup)
.add_systems( .add_systems(
Update, Update,

View File

@ -27,10 +27,7 @@ fn main() {
OutlinePlugin, OutlinePlugin,
AutoGenerateOutlineNormalsPlugin, AutoGenerateOutlineNormalsPlugin,
)) ))
.insert_resource(AmbientLight { .insert_resource(AmbientLight::default())
brightness: 1.0,
..default()
})
.add_systems(Startup, setup) .add_systems(Startup, setup)
.add_systems(Update, (name_morphs, setup_outlines, setup_animations)) .add_systems(Update, (name_morphs, setup_outlines, setup_animations))
.run(); .run();

View File

@ -1,12 +1,6 @@
use std::f32::consts::TAU; use std::f32::consts::TAU;
use bevy::{ use bevy::{prelude::*, window::close_on_esc};
prelude::{
shape::{Capsule, Plane, Torus, UVSphere},
*,
},
window::close_on_esc,
};
use bevy_mod_outline::*; use bevy_mod_outline::*;
@ -32,11 +26,7 @@ fn setup(
// Add sphere with child meshes sticking out of it // Add sphere with child meshes sticking out of it
commands commands
.spawn(PbrBundle { .spawn(PbrBundle {
mesh: meshes.add(Mesh::from(UVSphere { mesh: meshes.add(Sphere::new(0.75).mesh().uv(30, 30)),
radius: 0.75,
sectors: 30,
stacks: 30,
})),
material: materials.add(StandardMaterial::from(Color::rgb(0.9, 0.1, 0.1))), material: materials.add(StandardMaterial::from(Color::rgb(0.9, 0.1, 0.1))),
transform: Transform::from_translation(Vec3::new(0.0, 1.0, 0.0)), transform: Transform::from_translation(Vec3::new(0.0, 1.0, 0.0)),
..default() ..default()
@ -57,14 +47,14 @@ fn setup(
.with_children(|parent| { .with_children(|parent| {
parent parent
.spawn(PbrBundle { .spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Capsule { mesh: meshes.add(
radius: 0.2, Capsule3d::new(0.2, 1.0)
rings: 15, .mesh()
depth: 1.0, .rings(15)
latitudes: 15, .latitudes(15)
longitudes: 15, .longitudes(15)
..Default::default() .build(),
})), ),
material: materials.add(StandardMaterial::from(Color::rgb(0.1, 0.1, 0.9))), material: materials.add(StandardMaterial::from(Color::rgb(0.1, 0.1, 0.9))),
transform: Transform::from_rotation(Quat::from_axis_angle(Vec3::X, TAU / 4.0)) transform: Transform::from_rotation(Quat::from_axis_angle(Vec3::X, TAU / 4.0))
.with_translation(Vec3::new(0.0, 0.0, 0.75)), .with_translation(Vec3::new(0.0, 0.0, 0.75)),
@ -73,12 +63,16 @@ fn setup(
.insert(InheritOutlineBundle::default()); .insert(InheritOutlineBundle::default());
parent parent
.spawn(PbrBundle { .spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Torus { mesh: meshes.add(
radius: 0.5, Torus {
ring_radius: 0.1, minor_radius: 0.1,
subdivisions_segments: 30, major_radius: 0.5,
subdivisions_sides: 15, }
})), .mesh()
.minor_resolution(15)
.major_resolution(30)
.build(),
),
material: materials.add(StandardMaterial::from(Color::rgb(0.1, 0.1, 0.9))), material: materials.add(StandardMaterial::from(Color::rgb(0.1, 0.1, 0.9))),
transform: Transform::from_rotation(Quat::from_axis_angle(Vec3::Z, TAU / 4.0)) transform: Transform::from_rotation(Quat::from_axis_angle(Vec3::Z, TAU / 4.0))
.with_translation(Vec3::new(0.0, 0.0, -0.75)), .with_translation(Vec3::new(0.0, 0.0, -0.75)),
@ -89,16 +83,12 @@ fn setup(
// Add plane, light source, and camera // Add plane, light source, and camera
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Plane { mesh: meshes.add(Plane3d::new(Vec3::Y).mesh().size(5.0, 5.0).build()),
size: 5.0,
subdivisions: 0,
})),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))), material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
..default() ..default()
}); });
commands.spawn(PointLightBundle { commands.spawn(PointLightBundle {
point_light: PointLight { point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true, shadows_enabled: true,
..default() ..default()
}, },

View File

@ -1,10 +1,7 @@
use std::f32::consts::PI; use std::f32::consts::PI;
use bevy::{ use bevy::{
prelude::{ prelude::*,
shape::{Plane, Torus},
*,
},
render::{camera::Viewport, view::RenderLayers}, render::{camera::Viewport, view::RenderLayers},
window::{close_on_esc, PrimaryWindow}, window::{close_on_esc, PrimaryWindow},
}; };
@ -38,12 +35,16 @@ fn setup(
// Add torus using the regular surface normals for outlining // Add torus using the regular surface normals for outlining
commands commands
.spawn(PbrBundle { .spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Torus { mesh: meshes.add(
radius: 0.6, Torus {
ring_radius: 0.2, minor_radius: 0.2,
subdivisions_segments: 40, major_radius: 0.6,
subdivisions_sides: 20, }
})), .mesh()
.minor_resolution(20)
.major_resolution(40)
.build(),
),
material: materials.add(StandardMaterial::from(Color::rgb(0.1, 0.1, 0.9))), material: materials.add(StandardMaterial::from(Color::rgb(0.1, 0.1, 0.9))),
transform: Transform::from_rotation(Quat::from_rotation_x(0.5 * PI)) transform: Transform::from_rotation(Quat::from_rotation_x(0.5 * PI))
.with_translation(0.8 * Vec3::Y), .with_translation(0.8 * Vec3::Y),
@ -62,16 +63,12 @@ fn setup(
// Add plane and light source // Add plane and light source
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Plane { mesh: meshes.add(Plane3d::new(Vec3::Y).mesh().size(5.0, 5.0).build()),
size: 5.0,
subdivisions: 0,
})),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))), material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
..default() ..default()
}); });
commands.spawn(PointLightBundle { commands.spawn(PointLightBundle {
point_light: PointLight { point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true, shadows_enabled: true,
..default() ..default()
}, },

View File

@ -1,12 +1,6 @@
use std::f32::consts::{PI, TAU}; use std::f32::consts::{PI, TAU};
use bevy::{ use bevy::{prelude::*, window::close_on_esc};
prelude::{
shape::{Cube, Plane, Torus},
*,
},
window::close_on_esc,
};
use bevy_mod_outline::*; use bevy_mod_outline::*;
@ -33,7 +27,7 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// Add cube with generated outline normals // Add cube with generated outline normals
let mut cube_mesh = Mesh::from(Cube { size: 1.0 }); let mut cube_mesh = Cuboid::new(1.0, 1.0, 1.0).mesh();
cube_mesh.generate_outline_normals().unwrap(); cube_mesh.generate_outline_normals().unwrap();
commands commands
.spawn(PbrBundle { .spawn(PbrBundle {
@ -55,12 +49,16 @@ fn setup(
// Add torus using the regular surface normals for outlining // Add torus using the regular surface normals for outlining
commands commands
.spawn(PbrBundle { .spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Torus { mesh: meshes.add(
radius: 0.3, Torus {
ring_radius: 0.1, minor_radius: 0.1,
subdivisions_segments: 20, major_radius: 0.3,
subdivisions_sides: 10, }
})), .mesh()
.minor_resolution(10)
.major_resolution(20)
.build(),
),
material: materials.add(StandardMaterial::from(Color::rgb(0.9, 0.1, 0.1))), material: materials.add(StandardMaterial::from(Color::rgb(0.9, 0.1, 0.1))),
transform: Transform::from_xyz(0.0, 1.2, 2.0) transform: Transform::from_xyz(0.0, 1.2, 2.0)
.with_rotation(Quat::from_rotation_x(0.5 * PI)), .with_rotation(Quat::from_rotation_x(0.5 * PI)),
@ -78,16 +76,12 @@ fn setup(
// Add plane, light source, and camera // Add plane, light source, and camera
commands.spawn(PbrBundle { commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Plane { mesh: meshes.add(Plane3d::new(Vec3::Y).mesh().size(5.0, 5.0).build()),
size: 5.0,
subdivisions: 0,
})),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))), material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
..default() ..default()
}); });
commands.spawn(PointLightBundle { commands.spawn(PointLightBundle {
point_light: PointLight { point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true, shadows_enabled: true,
..default() ..default()
}, },