Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Litttlefish authored Sep 13, 2024
2 parents 30fdb12 + e567669 commit 3d97559
Show file tree
Hide file tree
Showing 202 changed files with 5,599 additions and 3,936 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Check for typos
uses: crate-ci/[email protected].3
uses: crate-ci/[email protected].5
- name: Typos info
if: failure()
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
--exclude build-wasm-example
- name: Create PR
uses: peter-evans/create-pull-request@v6
uses: peter-evans/create-pull-request@v7
with:
delete-branch: true
base: "main"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
--exclude build-wasm-example
- name: Create PR
uses: peter-evans/create-pull-request@v6
uses: peter-evans/create-pull-request@v7
with:
delete-branch: true
base: "main"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/welcome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
jobs:
welcome:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v7
with:
Expand Down
25 changes: 24 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ setup = [
"curl",
"-o",
"assets/models/bunny.meshlet_mesh",
"https://raw.githubusercontent.com/JMS55/bevy_meshlet_asset/b6c712cfc87c65de419f856845401aba336a7bcd/bunny.meshlet_mesh",
"https://raw.githubusercontent.com/JMS55/bevy_meshlet_asset/e3da1533b4c69fb967f233c817e9b0921134d317/bunny.meshlet_mesh",
],
]

Expand Down Expand Up @@ -3251,6 +3251,29 @@ description = "A first-person camera that uses a world model and a view model wi
category = "Camera"
wasm = true

[[example]]
name = "projection_zoom"
path = "examples/camera/projection_zoom.rs"
doc-scrape-examples = true

[package.metadata.example.projection_zoom]
name = "Projection Zoom"
description = "Shows how to zoom orthographic and perspective projection cameras."
category = "Camera"
wasm = true

[[example]]
name = "camera_orbit"
path = "examples/camera/camera_orbit.rs"
doc-scrape-examples = true

[package.metadata.example.camera_orbit]
name = "Camera Orbit"
description = "Shows how to orbit a static scene using pitch, yaw, and roll."
category = "Camera"
wasm = true


[package.metadata.example.fps_overlay]
name = "FPS overlay"
description = "Demonstrates FPS overlay"
Expand Down
11 changes: 11 additions & 0 deletions assets/shaders/custom_ui_material.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@
@group(1) @binding(1) var<uniform> slider: f32;
@group(1) @binding(2) var material_color_texture: texture_2d<f32>;
@group(1) @binding(3) var material_color_sampler: sampler;
@group(1) @binding(4) var<uniform> border_color: vec4<f32>;


@fragment
fn fragment(in: UiVertexOutput) -> @location(0) vec4<f32> {
let r = in.uv - 0.5;
let b = vec2(
select(in.border_widths.x, in.border_widths.y, r.x < 0.),
select(in.border_widths.z, in.border_widths.w, r.y < 0.)
);

if any(0.5 - b < abs(r)) {
return border_color;
}

if in.uv.x < slider {
let output_color = textureSample(material_color_texture, material_color_sampler, in.uv) * color;
return output_color;
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ use serde::{Deserialize, Serialize};
use thread_local::ThreadLocal;
use uuid::Uuid;

#[allow(missing_docs)]
/// The animation prelude.
///
/// This includes the most common types in this crate, re-exported for your convenience.
pub mod prelude {
#[doc(hidden)]
pub use crate::{
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ pub use sub_app::*;
#[cfg(not(target_arch = "wasm32"))]
pub use terminal_ctrl_c_handler::*;

#[allow(missing_docs)]
/// The app prelude.
///
/// This includes the most common types in this crate, re-exported for your convenience.
pub mod prelude {
#[doc(hidden)]
pub use crate::{
Expand Down
9 changes: 9 additions & 0 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub mod processor;
pub mod saver;
pub mod transformer;

/// The asset prelude.
///
/// This includes the most common types in this crate, re-exported for your convenience.
pub mod prelude {
#[doc(hidden)]
pub use crate::{
Expand Down Expand Up @@ -97,6 +100,12 @@ pub struct AssetPlugin {
pub meta_check: AssetMetaCheck,
}

/// Controls whether or not assets are pre-processed before being loaded.
///
/// This setting is controlled by setting [`AssetPlugin::mode`].
///
/// When building on web, asset preprocessing can cause problems due to the lack of filesystem access.
/// See [bevy#10157](https://github.com/bevyengine/bevy/issues/10157) for context.
#[derive(Debug)]
pub enum AssetMode {
/// Loads assets from their [`AssetSource`]'s default [`AssetReader`] without any "preprocessing".
Expand Down
74 changes: 24 additions & 50 deletions crates/bevy_asset/src/processor/process.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::io::SliceReader;
use crate::transformer::IdentityAssetTransformer;
use crate::{
io::{
AssetReaderError, AssetWriterError, MissingAssetWriterError,
Expand Down Expand Up @@ -47,6 +48,11 @@ pub trait Process: Send + Sync + Sized + 'static {
/// an [`AssetSaver`] that allows you save any `S` asset. However you can
/// also implement [`Process`] directly if [`LoadTransformAndSave`] feels limiting or unnecessary.
///
/// If your [`Process`] does not need to transform the [`Asset`], you can use [`IdentityAssetTransformer`] as `T`.
/// This will directly return the input [`Asset`], allowing your [`Process`] to directly load and then save an [`Asset`].
/// However, this pattern should only be used for cases such as file format conversion.
/// Otherwise, consider refactoring your [`AssetLoader`] and [`AssetSaver`] to isolate the transformation step into an explicit [`AssetTransformer`].
///
/// This uses [`LoadTransformAndSaveSettings`] to configure the processor.
///
/// [`Asset`]: crate::Asset
Expand All @@ -60,6 +66,18 @@ pub struct LoadTransformAndSave<
marker: PhantomData<fn() -> L>,
}

impl<L: AssetLoader, S: AssetSaver<Asset = L::Asset>> From<S>
for LoadTransformAndSave<L, IdentityAssetTransformer<L::Asset>, S>
{
fn from(value: S) -> Self {
LoadTransformAndSave {
transformer: IdentityAssetTransformer::new(),
saver: value,
marker: PhantomData,
}
}
}

/// Settings for the [`LoadTransformAndSave`] [`Process::Settings`] implementation.
///
/// `LoaderSettings` corresponds to [`AssetLoader::Settings`], `TransformerSettings` corresponds to [`AssetTransformer::Settings`],
Expand Down Expand Up @@ -98,30 +116,16 @@ impl<
/// This uses [`LoadAndSaveSettings`] to configure the processor.
///
/// [`Asset`]: crate::Asset
pub struct LoadAndSave<L: AssetLoader, S: AssetSaver<Asset = L::Asset>> {
saver: S,
marker: PhantomData<fn() -> L>,
}

impl<L: AssetLoader, S: AssetSaver<Asset = L::Asset>> From<S> for LoadAndSave<L, S> {
fn from(value: S) -> Self {
LoadAndSave {
saver: value,
marker: PhantomData,
}
}
}
#[deprecated = "Use `LoadTransformAndSave<L, IdentityAssetTransformer<<L as AssetLoader>::Asset>, S>` instead"]
pub type LoadAndSave<L, S> =
LoadTransformAndSave<L, IdentityAssetTransformer<<L as AssetLoader>::Asset>, S>;

/// Settings for the [`LoadAndSave`] [`Process::Settings`] implementation.
///
/// `LoaderSettings` corresponds to [`AssetLoader::Settings`] and `SaverSettings` corresponds to [`AssetSaver::Settings`].
#[derive(Serialize, Deserialize, Default)]
pub struct LoadAndSaveSettings<LoaderSettings, SaverSettings> {
/// The [`AssetLoader::Settings`] for [`LoadAndSave`].
pub loader_settings: LoaderSettings,
/// The [`AssetSaver::Settings`] for [`LoadAndSave`].
pub saver_settings: SaverSettings,
}
#[deprecated = "Use `LoadTransformAndSaveSettings<LoaderSettings, (), SaverSettings>` instead"]
pub type LoadAndSaveSettings<LoaderSettings, SaverSettings> =
LoadTransformAndSaveSettings<LoaderSettings, (), SaverSettings>;

/// An error that is encountered during [`Process::process`].
#[derive(Error, Debug)]
Expand Down Expand Up @@ -213,36 +217,6 @@ where
}
}

impl<Loader: AssetLoader, Saver: AssetSaver<Asset = Loader::Asset>> Process
for LoadAndSave<Loader, Saver>
{
type Settings = LoadAndSaveSettings<Loader::Settings, Saver::Settings>;
type OutputLoader = Saver::OutputLoader;

async fn process<'a>(
&'a self,
context: &'a mut ProcessContext<'_>,
meta: AssetMeta<(), Self>,
writer: &'a mut Writer,
) -> Result<<Self::OutputLoader as AssetLoader>::Settings, ProcessError> {
let AssetAction::Process { settings, .. } = meta.asset else {
return Err(ProcessError::WrongMetaType);
};
let loader_meta = AssetMeta::<Loader, ()>::new(AssetAction::Load {
loader: std::any::type_name::<Loader>().to_string(),
settings: settings.loader_settings,
});
let loaded_asset = context.load_source_asset(loader_meta).await?;
let saved_asset = SavedAsset::<Loader::Asset>::from_loaded(&loaded_asset).unwrap();
let output_settings = self
.saver
.save(writer, saved_asset, &settings.saver_settings)
.await
.map_err(|error| ProcessError::AssetSaveError(error.into()))?;
Ok(output_settings)
}
}

/// A type-erased variant of [`Process`] that enables interacting with processor implementations without knowing
/// their type.
pub trait ErasedProcessor: Send + Sync {
Expand Down
36 changes: 36 additions & 0 deletions crates/bevy_asset/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use bevy_utils::{ConditionalSendFuture, HashMap};
use serde::{Deserialize, Serialize};
use std::{
borrow::Borrow,
convert::Infallible,
hash::Hash,
marker::PhantomData,
ops::{Deref, DerefMut},
};

Expand Down Expand Up @@ -241,3 +243,37 @@ impl<'a, A: Asset> TransformedSubAsset<'a, A> {
self.labeled_assets.keys().map(|s| &**s)
}
}

/// An identity [`AssetTransformer`] which infallibly returns the input [`Asset`] on transformation.]
pub struct IdentityAssetTransformer<A: Asset> {
_phantom: PhantomData<fn(A) -> A>,
}

impl<A: Asset> IdentityAssetTransformer<A> {
pub const fn new() -> Self {
Self {
_phantom: PhantomData,
}
}
}

impl<A: Asset> Default for IdentityAssetTransformer<A> {
fn default() -> Self {
Self::new()
}
}

impl<A: Asset> AssetTransformer for IdentityAssetTransformer<A> {
type AssetInput = A;
type AssetOutput = A;
type Settings = ();
type Error = Infallible;

async fn transform<'a>(
&'a self,
asset: TransformedAsset<Self::AssetInput>,
_settings: &'a Self::Settings,
) -> Result<TransformedAsset<Self::AssetOutput>, Self::Error> {
Ok(asset)
}
}
4 changes: 3 additions & 1 deletion crates/bevy_audio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ mod audio_source;
mod pitch;
mod sinks;

#[allow(missing_docs)]
/// The audio prelude.
///
/// This includes the most common types in this crate, re-exported for your convenience.
pub mod prelude {
#[doc(hidden)]
pub use crate::{
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_color/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ mod test_colors;
mod testing;
mod xyza;

/// Commonly used color types and traits.
/// The color prelude.
///
/// This includes the most common types in this crate, re-exported for your convenience.
pub mod prelude {
pub use crate::color::*;
pub use crate::color_ops::*;
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ use bevy_ecs::system::Resource;
pub use name::*;
pub use task_pool_options::*;

/// The core prelude.
///
/// This includes the most common types in this crate, re-exported for your convenience.
pub mod prelude {
//! The Bevy Core Prelude.
#[doc(hidden)]
pub use crate::{
FrameCountPlugin, Name, NameOrEntity, TaskPoolOptions, TaskPoolPlugin,
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_core_pipeline/src/auto_exposure/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use bevy_render::{
};
use bevy_utils::{Entry, HashMap};

use super::pipeline::AutoExposureSettingsUniform;
use super::AutoExposureSettings;
use super::pipeline::AutoExposureUniform;
use super::AutoExposure;

#[derive(Resource, Default)]
pub(super) struct AutoExposureBuffers {
Expand All @@ -16,19 +16,19 @@ pub(super) struct AutoExposureBuffers {

pub(super) struct AutoExposureBuffer {
pub(super) state: StorageBuffer<f32>,
pub(super) settings: UniformBuffer<AutoExposureSettingsUniform>,
pub(super) settings: UniformBuffer<AutoExposureUniform>,
}

#[derive(Resource)]
pub(super) struct ExtractedStateBuffers {
changed: Vec<(Entity, AutoExposureSettings)>,
changed: Vec<(Entity, AutoExposure)>,
removed: Vec<Entity>,
}

pub(super) fn extract_buffers(
mut commands: Commands,
changed: Extract<Query<(Entity, &AutoExposureSettings), Changed<AutoExposureSettings>>>,
mut removed: Extract<RemovedComponents<AutoExposureSettings>>,
changed: Extract<Query<(Entity, &AutoExposure), Changed<AutoExposure>>>,
mut removed: Extract<RemovedComponents<AutoExposure>>,
) {
commands.insert_resource(ExtractedStateBuffers {
changed: changed
Expand All @@ -50,7 +50,7 @@ pub(super) fn prepare_buffers(
let (low_percent, high_percent) = settings.filter.into_inner();
let initial_state = 0.0f32.clamp(min_log_lum, max_log_lum);

let settings = AutoExposureSettingsUniform {
let settings = AutoExposureUniform {
min_log_lum,
inv_log_lum_range: 1.0 / (max_log_lum - min_log_lum),
log_lum_range: max_log_lum - min_log_lum,
Expand Down
Loading

0 comments on commit 3d97559

Please sign in to comment.