2023-04-17 18:16:56 +02:00
|
|
|
//! Demonstrates how to work with Cubic curves.
|
|
|
|
|
|
|
|
use bevy::{
|
|
|
|
math::{cubic_splines::CubicCurve, vec3},
|
|
|
|
prelude::*,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Component)]
|
2024-02-03 22:40:55 +01:00
|
|
|
struct Curve(CubicCurve<Vec3>);
|
2023-04-17 18:16:56 +02:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::new()
|
|
|
|
.add_plugins(DefaultPlugins)
|
|
|
|
.add_systems(Startup, setup)
|
|
|
|
.add_systems(Update, animate_cube)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn setup(
|
|
|
|
mut commands: Commands,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
) {
|
|
|
|
// Define your control points
|
|
|
|
// These points will define the curve
|
|
|
|
// You can learn more about bezier curves here
|
|
|
|
// https://en.wikipedia.org/wiki/B%C3%A9zier_curve
|
|
|
|
let points = [[
|
|
|
|
vec3(-6., 2., 0.),
|
|
|
|
vec3(12., 8., 0.),
|
|
|
|
vec3(-12., 8., 0.),
|
|
|
|
vec3(6., 2., 0.),
|
|
|
|
]];
|
|
|
|
|
|
|
|
// Make a CubicCurve
|
Rename `Bezier` to `CubicBezier` for clarity (#9554)
# Objective
A Bezier curve is a curve defined by two or more control points. In the
simplest form, it's just a line. The (arguably) most common type of
Bezier curve is a cubic Bezier, defined by four control points. These
are often used in animation, etc. Bevy has a Bezier curve struct called
`Bezier`. However, this is technically a misnomer as it only represents
cubic Bezier curves.
## Solution
This PR changes the struct name to `CubicBezier` to more accurately
reflect the struct's usage. Since it's exposed in Bevy's prelude, it can
potentially collide with other `Bezier` implementations. While that
might instead be an argument for removing it from the prelude, there's
also something to be said for adding a more general `Bezier` into Bevy,
in which case we'd likely want to use the name `Bezier`. As a final
motivator, not only is the struct located in `cubic_spines.rs`, there
are also several other spline-related structs which follow the
`CubicXxx` naming convention where applicable. For example,
`CubicSegment` represents a cubic Bezier curve (with coefficients
pre-baked).
---
## Migration Guide
- Change all `Bezier` references to `CubicBezier`
2023-08-28 11:37:42 -06:00
|
|
|
let bezier = CubicBezier::new(points).to_curve();
|
2023-04-17 18:16:56 +02:00
|
|
|
|
|
|
|
// Spawning a cube to experiment on
|
|
|
|
commands.spawn((
|
|
|
|
PbrBundle {
|
2024-02-08 20:01:34 +02:00
|
|
|
mesh: meshes.add(Cuboid::default()),
|
2024-02-24 16:35:32 -05:00
|
|
|
material: materials.add(LegacyColor::ORANGE),
|
2023-04-17 18:16:56 +02:00
|
|
|
transform: Transform::from_translation(points[0][0]),
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
Curve(bezier),
|
|
|
|
));
|
|
|
|
|
|
|
|
// Some light to see something
|
New Exposure and Lighting Defaults (and calibrate examples) (#11868)
# Objective
After adding configurable exposure, we set the default ev100 value to
`7` (indoor). This brought us out of sync with Blender's configuration
and defaults. This PR changes the default to `9.7` (bright indoor or
very overcast outdoors), as I calibrated in #11577. This feels like a
very reasonable default.
The other changes generally center around tweaking Bevy's lighting
defaults and examples to play nicely with this number, alongside a few
other tweaks and improvements.
Note that for artistic reasons I have reverted some examples, which
changed to directional lights in #11581, back to point lights.
Fixes #11577
---
## Changelog
- Changed `Exposure::ev100` from `7` to `9.7` to better match Blender
- Renamed `ExposureSettings` to `Exposure`
- `Camera3dBundle` now includes `Exposure` for discoverability
- Bumped `FULL_DAYLIGHT ` and `DIRECT_SUNLIGHT` to represent the
middle-to-top of those ranges instead of near the bottom
- Added new `AMBIENT_DAYLIGHT` constant and set that as the new
`DirectionalLight` default illuminance.
- `PointLight` and `SpotLight` now have a default `intensity` of
1,000,000 lumens. This makes them actually useful in the context of the
new "semi-outdoor" exposure and puts them in the "cinema lighting"
category instead of the "common household light" category. They are also
reasonably close to the Blender default.
- `AmbientLight` default has been bumped from `20` to `80`.
## Migration Guide
- The increased `Exposure::ev100` means that all existing 3D lighting
will need to be adjusted to match (DirectionalLights, PointLights,
SpotLights, EnvironmentMapLights, etc). Or alternatively, you can adjust
the `Exposure::ev100` on your cameras to work nicely with your current
lighting values. If you are currently relying on default intensity
values, you might need to change the intensity to achieve the same
effect. Note that in Bevy 0.12, point/spot lights had a different hard
coded ev100 value than directional lights. In Bevy 0.13, they use the
same ev100, so if you have both in your scene, the _scale_ between these
light types has changed and you will likely need to adjust one or both
of them.
2024-02-15 12:42:48 -08:00
|
|
|
commands.spawn(PointLightBundle {
|
|
|
|
point_light: PointLight {
|
2023-04-17 18:16:56 +02:00
|
|
|
shadows_enabled: true,
|
New Exposure and Lighting Defaults (and calibrate examples) (#11868)
# Objective
After adding configurable exposure, we set the default ev100 value to
`7` (indoor). This brought us out of sync with Blender's configuration
and defaults. This PR changes the default to `9.7` (bright indoor or
very overcast outdoors), as I calibrated in #11577. This feels like a
very reasonable default.
The other changes generally center around tweaking Bevy's lighting
defaults and examples to play nicely with this number, alongside a few
other tweaks and improvements.
Note that for artistic reasons I have reverted some examples, which
changed to directional lights in #11581, back to point lights.
Fixes #11577
---
## Changelog
- Changed `Exposure::ev100` from `7` to `9.7` to better match Blender
- Renamed `ExposureSettings` to `Exposure`
- `Camera3dBundle` now includes `Exposure` for discoverability
- Bumped `FULL_DAYLIGHT ` and `DIRECT_SUNLIGHT` to represent the
middle-to-top of those ranges instead of near the bottom
- Added new `AMBIENT_DAYLIGHT` constant and set that as the new
`DirectionalLight` default illuminance.
- `PointLight` and `SpotLight` now have a default `intensity` of
1,000,000 lumens. This makes them actually useful in the context of the
new "semi-outdoor" exposure and puts them in the "cinema lighting"
category instead of the "common household light" category. They are also
reasonably close to the Blender default.
- `AmbientLight` default has been bumped from `20` to `80`.
## Migration Guide
- The increased `Exposure::ev100` means that all existing 3D lighting
will need to be adjusted to match (DirectionalLights, PointLights,
SpotLights, EnvironmentMapLights, etc). Or alternatively, you can adjust
the `Exposure::ev100` on your cameras to work nicely with your current
lighting values. If you are currently relying on default intensity
values, you might need to change the intensity to achieve the same
effect. Note that in Bevy 0.12, point/spot lights had a different hard
coded ev100 value than directional lights. In Bevy 0.13, they use the
same ev100, so if you have both in your scene, the _scale_ between these
light types has changed and you will likely need to adjust one or both
of them.
2024-02-15 12:42:48 -08:00
|
|
|
intensity: 10_000_000.,
|
|
|
|
range: 100.0,
|
2023-04-17 18:16:56 +02:00
|
|
|
..default()
|
|
|
|
},
|
New Exposure and Lighting Defaults (and calibrate examples) (#11868)
# Objective
After adding configurable exposure, we set the default ev100 value to
`7` (indoor). This brought us out of sync with Blender's configuration
and defaults. This PR changes the default to `9.7` (bright indoor or
very overcast outdoors), as I calibrated in #11577. This feels like a
very reasonable default.
The other changes generally center around tweaking Bevy's lighting
defaults and examples to play nicely with this number, alongside a few
other tweaks and improvements.
Note that for artistic reasons I have reverted some examples, which
changed to directional lights in #11581, back to point lights.
Fixes #11577
---
## Changelog
- Changed `Exposure::ev100` from `7` to `9.7` to better match Blender
- Renamed `ExposureSettings` to `Exposure`
- `Camera3dBundle` now includes `Exposure` for discoverability
- Bumped `FULL_DAYLIGHT ` and `DIRECT_SUNLIGHT` to represent the
middle-to-top of those ranges instead of near the bottom
- Added new `AMBIENT_DAYLIGHT` constant and set that as the new
`DirectionalLight` default illuminance.
- `PointLight` and `SpotLight` now have a default `intensity` of
1,000,000 lumens. This makes them actually useful in the context of the
new "semi-outdoor" exposure and puts them in the "cinema lighting"
category instead of the "common household light" category. They are also
reasonably close to the Blender default.
- `AmbientLight` default has been bumped from `20` to `80`.
## Migration Guide
- The increased `Exposure::ev100` means that all existing 3D lighting
will need to be adjusted to match (DirectionalLights, PointLights,
SpotLights, EnvironmentMapLights, etc). Or alternatively, you can adjust
the `Exposure::ev100` on your cameras to work nicely with your current
lighting values. If you are currently relying on default intensity
values, you might need to change the intensity to achieve the same
effect. Note that in Bevy 0.12, point/spot lights had a different hard
coded ev100 value than directional lights. In Bevy 0.13, they use the
same ev100, so if you have both in your scene, the _scale_ between these
light types has changed and you will likely need to adjust one or both
of them.
2024-02-15 12:42:48 -08:00
|
|
|
transform: Transform::from_xyz(8., 16., 8.),
|
2023-04-17 18:16:56 +02:00
|
|
|
..default()
|
|
|
|
});
|
|
|
|
|
|
|
|
// ground plane
|
|
|
|
commands.spawn(PbrBundle {
|
2024-02-08 20:01:34 +02:00
|
|
|
mesh: meshes.add(Plane3d::default().mesh().size(50., 50.)),
|
2024-02-24 16:35:32 -05:00
|
|
|
material: materials.add(LegacyColor::SILVER),
|
2023-04-17 18:16:56 +02:00
|
|
|
..default()
|
|
|
|
});
|
|
|
|
|
|
|
|
// The camera
|
|
|
|
commands.spawn(Camera3dBundle {
|
|
|
|
transform: Transform::from_xyz(0., 6., 12.).looking_at(Vec3::new(0., 3., 0.), Vec3::Y),
|
|
|
|
..default()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-02-03 22:40:55 +01:00
|
|
|
fn animate_cube(time: Res<Time>, mut query: Query<(&mut Transform, &Curve)>, mut gizmos: Gizmos) {
|
2023-04-17 18:16:56 +02:00
|
|
|
let t = (time.elapsed_seconds().sin() + 1.) / 2.;
|
|
|
|
|
|
|
|
for (mut transform, cubic_curve) in &mut query {
|
|
|
|
// Draw the curve
|
2024-02-24 16:35:32 -05:00
|
|
|
gizmos.linestrip(cubic_curve.0.iter_positions(50), LegacyColor::WHITE);
|
2023-04-17 18:16:56 +02:00
|
|
|
// position takes a point from the curve where 0 is the initial point
|
|
|
|
// and 1 is the last point
|
|
|
|
transform.translation = cubic_curve.0.position(t);
|
|
|
|
}
|
|
|
|
}
|