Rename option

This commit is contained in:
Jan Hohenheim 2025-07-14 13:24:39 +02:00
parent 777e28ef3a
commit 105a0d1d0f
No known key found for this signature in database
2 changed files with 35 additions and 47 deletions

View File

@ -159,20 +159,17 @@ pub struct GltfPlugin {
/// Can be modified with the [`DefaultGltfImageSampler`] resource. /// Can be modified with the [`DefaultGltfImageSampler`] resource.
pub default_sampler: ImageSamplerDescriptor, pub default_sampler: ImageSamplerDescriptor,
/// Whether to convert glTF coordinates to Bevy's coordinate system by default. /// How to convert glTF coordinates on import. Assuming glTF cameras, glTF lights, and glTF meshes had global unit transforms,
/// If set to `true`, the loader will convert the coordinate system of loaded glTF assets to Bevy's coordinate system /// their Bevy [`Transform::forward`](bevy_transform::components::Transform::forward) will be pointing in the following global directions:
/// such that objects looking forward in glTF will also look forward in Bevy. /// - When set to `false`
/// - glTF cameras and glTF lights: global -Z,
/// - glTF models: global +Z.
/// - When set to `true`
/// - glTF cameras and glTF lights: global +Z,
/// - glTF models: global -Z.
/// ///
/// The exact coordinate system conversion is as follows: /// The default is `false`.
/// - glTF: pub favor_model_coordinates: bool,
/// - forward: Z
/// - up: Y
/// - right: -X
/// - Bevy:
/// - forward: -Z
/// - up: Y
/// - right: X
pub convert_coordinates: bool,
/// Registry for custom vertex attributes. /// Registry for custom vertex attributes.
/// ///
@ -185,7 +182,7 @@ impl Default for GltfPlugin {
GltfPlugin { GltfPlugin {
default_sampler: ImageSamplerDescriptor::linear(), default_sampler: ImageSamplerDescriptor::linear(),
custom_vertex_attributes: HashMap::default(), custom_vertex_attributes: HashMap::default(),
convert_coordinates: false, favor_model_coordinates: false,
} }
} }
} }
@ -241,7 +238,7 @@ impl Plugin for GltfPlugin {
supported_compressed_formats, supported_compressed_formats,
custom_vertex_attributes: self.custom_vertex_attributes.clone(), custom_vertex_attributes: self.custom_vertex_attributes.clone(),
default_sampler, default_sampler,
default_convert_coordinates: self.convert_coordinates, default_favor_model_coordinates: self.favor_model_coordinates,
}); });
} }
} }

View File

@ -151,20 +151,17 @@ pub struct GltfLoader {
pub custom_vertex_attributes: HashMap<Box<str>, MeshVertexAttribute>, pub custom_vertex_attributes: HashMap<Box<str>, MeshVertexAttribute>,
/// Arc to default [`ImageSamplerDescriptor`]. /// Arc to default [`ImageSamplerDescriptor`].
pub default_sampler: Arc<Mutex<ImageSamplerDescriptor>>, pub default_sampler: Arc<Mutex<ImageSamplerDescriptor>>,
/// Whether to convert glTF coordinates to Bevy's coordinate system by default. /// How to convert glTF coordinates on import. Assuming glTF cameras, glTF lights, and glTF meshes had global unit transforms,
/// If set to `true`, the loader will convert the coordinate system of loaded glTF assets to Bevy's coordinate system /// their Bevy [`Transform::forward`](bevy_transform::components::Transform::forward) will be pointing in the following global directions:
/// such that objects looking forward in glTF will also look forward in Bevy. /// - When set to `false`
/// - glTF cameras and glTF lights: global -Z,
/// - glTF models: global +Z.
/// - When set to `true`
/// - glTF cameras and glTF lights: global +Z,
/// - glTF models: global -Z.
/// ///
/// The exact coordinate system conversion is as follows: /// The default is `false`.
/// - glTF: pub default_favor_model_coordinates: bool,
/// - forward: Z
/// - up: Y
/// - right: -X
/// - Bevy:
/// - forward: -Z
/// - up: Y
/// - right: X
pub default_convert_coordinates: bool,
} }
/// Specifies optional settings for processing gltfs at load time. By default, all recognized contents of /// Specifies optional settings for processing gltfs at load time. By default, all recognized contents of
@ -206,23 +203,17 @@ pub struct GltfLoaderSettings {
pub default_sampler: Option<ImageSamplerDescriptor>, pub default_sampler: Option<ImageSamplerDescriptor>,
/// If true, the loader will ignore sampler data from gltf and use the default sampler. /// If true, the loader will ignore sampler data from gltf and use the default sampler.
pub override_sampler: bool, pub override_sampler: bool,
/// Overrides the default glTF coordinate conversion setting. /// How to convert glTF coordinates on import. Assuming glTF cameras, glTF lights, and glTF meshes had global unit transforms,
/// their Bevy [`Transform::forward`](bevy_transform::components::Transform::forward) will be pointing in the following global directions:
/// - When set to `false`
/// - glTF cameras and glTF lights: global -Z,
/// - glTF models: global +Z.
/// - When set to `true`
/// - glTF cameras and glTF lights: global +Z,
/// - glTF models: global -Z.
/// ///
/// If set to `Some(true)`, the loader will convert the coordinate system of loaded glTF assets to Bevy's coordinate system /// If `None`, uses the global default set by [`GltfPlugin::favor_model_coordinates`](crate::GltfPlugin::favor_model_coordinates).
/// such that objects looking forward in glTF will also look forward in Bevy. pub favor_model_coordinates: Option<bool>,
///
/// The exact coordinate system conversion is as follows:
/// - glTF:
/// - forward: Z
/// - up: Y
/// - right: -X
/// - Bevy:
/// - forward: -Z
/// - up: Y
/// - right: X
///
/// If `None`, uses the global default set by [`GltfPlugin::convert_coordinates`](crate::GltfPlugin::convert_coordinates).
pub convert_coordinates: Option<bool>,
} }
impl Default for GltfLoaderSettings { impl Default for GltfLoaderSettings {
@ -235,7 +226,7 @@ impl Default for GltfLoaderSettings {
include_source: false, include_source: false,
default_sampler: None, default_sampler: None,
override_sampler: false, override_sampler: false,
convert_coordinates: None, favor_model_coordinates: None,
} }
} }
} }
@ -295,9 +286,9 @@ async fn load_gltf<'a, 'b, 'c>(
paths paths
}; };
let convert_coordinates = match settings.convert_coordinates { let convert_coordinates = match settings.favor_model_coordinates {
Some(convert_coordinates) => convert_coordinates, Some(convert_coordinates) => convert_coordinates,
None => loader.default_convert_coordinates, None => loader.default_favor_model_coordinates,
}; };
#[cfg(feature = "bevy_animation")] #[cfg(feature = "bevy_animation")]