Skip to content

Commit ae5d3aa

Browse files
committed
Rename TangentCalculationStrategy to TangentAlgorithm
The variants have also been renamed to match their algorithm names.
1 parent 79169dd commit ae5d3aa

File tree

11 files changed

+49
-58
lines changed

11 files changed

+49
-58
lines changed

crates/bevy_gltf/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ use bevy_platform_support::collections::HashMap;
102102
use bevy_app::prelude::*;
103103
use bevy_asset::AssetApp;
104104
use bevy_image::CompressedImageFormats;
105-
use bevy_mesh::{MeshVertexAttribute, TangentCalculationStrategy};
105+
use bevy_mesh::{MeshVertexAttribute, TangentAlgorithm};
106106
use bevy_render::renderer::RenderDevice;
107107

108108
/// The glTF prelude.
@@ -119,8 +119,8 @@ pub use {assets::*, label::GltfAssetLabel, loader::*};
119119
#[derive(Default)]
120120
pub struct GltfPlugin {
121121
custom_vertex_attributes: HashMap<Box<str>, MeshVertexAttribute>,
122-
/// The strategy to use when computing tangents for meshes without them.
123-
pub tangent_calculation_strategy: TangentCalculationStrategy,
122+
/// The algorithm to use when computing tangents for meshes without them.
123+
pub tangent_calculation_algorithm: TangentAlgorithm,
124124
}
125125

126126
impl GltfPlugin {
@@ -138,12 +138,12 @@ impl GltfPlugin {
138138
self
139139
}
140140

141-
/// The strategy to use when computing mesh tangents.
142-
pub fn with_tangent_calculation_strategy(
141+
/// The algorithm to use when computing mesh tangents.
142+
pub fn with_tangent_calculation_algorithm(
143143
mut self,
144-
tangent_strategy: TangentCalculationStrategy,
144+
tangent_algorithm: TangentAlgorithm,
145145
) -> Self {
146-
self.tangent_calculation_strategy = tangent_strategy;
146+
self.tangent_calculation_algorithm = tangent_algorithm;
147147
self
148148
}
149149
}
@@ -171,7 +171,7 @@ impl Plugin for GltfPlugin {
171171
app.register_asset_loader(GltfLoader {
172172
supported_compressed_formats,
173173
custom_vertex_attributes: self.custom_vertex_attributes.clone(),
174-
tangent_calculation_strategy: self.tangent_calculation_strategy,
174+
tangent_calculation_algorithm: self.tangent_calculation_algorithm,
175175
});
176176
}
177177
}

crates/bevy_gltf/src/loader/mod.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ use bevy_math::{Mat4, Vec3};
2828
use bevy_mesh::{
2929
morph::{MeshMorphWeights, MorphAttributes, MorphTargetImage, MorphWeights},
3030
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
31-
Indices, Mesh, MeshVertexAttribute, PrimitiveTopology, TangentCalculationStrategy,
32-
VertexAttributeValues,
31+
Indices, Mesh, MeshVertexAttribute, PrimitiveTopology, TangentAlgorithm, VertexAttributeValues,
3332
};
3433
#[cfg(feature = "pbr_transmission_textures")]
3534
use bevy_pbr::UvChannel;
@@ -147,8 +146,8 @@ pub struct GltfLoader {
147146
/// See [this section of the glTF specification](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes-overview)
148147
/// for additional details on custom attributes.
149148
pub custom_vertex_attributes: HashMap<Box<str>, MeshVertexAttribute>,
150-
/// The strategy to use when computing mesh tangents.
151-
pub tangent_calculation_strategy: TangentCalculationStrategy,
149+
/// The algorithm to use when computing mesh tangents.
150+
pub tangent_calculation_algorithm: TangentAlgorithm,
152151
}
153152

154153
/// Specifies optional settings for processing gltfs at load time. By default, all recognized contents of
@@ -688,17 +687,17 @@ async fn load_gltf<'a, 'b, 'c>(
688687
&& needs_tangents(&primitive.material())
689688
{
690689
tracing::debug!(
691-
"Missing vertex tangents for {}, computing them using the {:?} strategy. Consider using a tool such as Blender to pre-compute the tangents.",
692-
file_name, loader.tangent_calculation_strategy
690+
"Missing vertex tangents for {}, computing them using the {:?} algorithm. Consider using a tool such as Blender to pre-compute the tangents.",
691+
file_name, loader.tangent_calculation_algorithm
693692
);
694693

695694
let generate_tangents_span = info_span!("compute_tangents", name = file_name);
696695

697696
generate_tangents_span.in_scope(|| {
698-
if let Err(err) = mesh.compute_tangents(loader.tangent_calculation_strategy) {
697+
if let Err(err) = mesh.compute_tangents(loader.tangent_calculation_algorithm) {
699698
warn!(
700699
"Failed to generate vertex tangents using {:?}: {}",
701-
loader.tangent_calculation_strategy, err
700+
loader.tangent_calculation_algorithm, err
702701
);
703702
}
704703
});

crates/bevy_mesh/src/gramschmidt.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ pub(crate) fn generate_tangents_for_mesh(
136136
mod tests {
137137
use bevy_math::{primitives::*, Vec2, Vec3, Vec3A};
138138

139-
use crate::{Mesh, TangentCalculationStrategy};
139+
use crate::{Mesh, TangentAlgorithm};
140140

141141
// The tangents should be very close for simple shapes
142142
fn compare_tangents(mut mesh: Mesh) {
143143
let hq_tangents: Vec<[f32; 4]> = {
144144
mesh.remove_attribute(Mesh::ATTRIBUTE_TANGENT);
145-
mesh.compute_tangents(TangentCalculationStrategy::HighQuality)
146-
.expect("compute_tangents(HighQuality)");
145+
mesh.compute_tangents(TangentAlgorithm::Mikktspace)
146+
.expect("compute_tangents(Mikktspace)");
147147
mesh.attribute(Mesh::ATTRIBUTE_TANGENT)
148148
.expect("hq_tangents.attribute(tangent)")
149149
.as_float4()
@@ -153,8 +153,8 @@ mod tests {
153153

154154
let fa_tangents: Vec<[f32; 4]> = {
155155
mesh.remove_attribute(Mesh::ATTRIBUTE_TANGENT);
156-
mesh.compute_tangents(TangentCalculationStrategy::FastApproximation)
157-
.expect("compute_tangents(FastApproximation)");
156+
mesh.compute_tangents(TangentAlgorithm::GramSchmidt)
157+
.expect("compute_tangents(GramSchmidt)");
158158
mesh.attribute(Mesh::ATTRIBUTE_TANGENT)
159159
.expect("fa_tangents.attribute(tangent)")
160160
.as_float4()

crates/bevy_mesh/src/mesh.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -777,26 +777,22 @@ impl Mesh {
777777
/// Requires a [`PrimitiveTopology::TriangleList`] topology and the [`Mesh::ATTRIBUTE_POSITION`], [`Mesh::ATTRIBUTE_NORMAL`] and [`Mesh::ATTRIBUTE_UV_0`] attributes set.
778778
#[deprecated(since = "0.16.0", note = "use compute_tangents")]
779779
pub fn generate_tangents(&mut self) -> Result<(), GenerateTangentsError> {
780-
self.compute_tangents(TangentCalculationStrategy::HighQuality)?;
780+
self.compute_tangents(TangentAlgorithm::Mikktspace)?;
781781
Ok(())
782782
}
783783

784784
/// Generate tangents for the mesh using the given algorithm.
785785
///
786786
/// Sets the [`Mesh::ATTRIBUTE_TANGENT`] attribute if successful.
787787
///
788-
/// See [`TangentCalculationStrategy`] for mesh topology and attribute requirements.
788+
/// See [`TangentAlgorithm`] for mesh topology and attribute requirements.
789789
pub fn compute_tangents(
790790
&mut self,
791-
strategy: TangentCalculationStrategy,
791+
algorithm: TangentAlgorithm,
792792
) -> Result<(), GenerateTangentsError> {
793-
let tangents = match strategy {
794-
TangentCalculationStrategy::HighQuality => {
795-
mikktspace::generate_tangents_for_mesh(self)?
796-
}
797-
TangentCalculationStrategy::FastApproximation => {
798-
gramschmidt::generate_tangents_for_mesh(self)?
799-
}
793+
let tangents = match algorithm {
794+
TangentAlgorithm::Mikktspace => mikktspace::generate_tangents_for_mesh(self)?,
795+
TangentAlgorithm::GramSchmidt => gramschmidt::generate_tangents_for_mesh(self)?,
800796
};
801797
self.insert_attribute(Mesh::ATTRIBUTE_TANGENT, tangents);
802798
Ok(())
@@ -822,12 +818,12 @@ impl Mesh {
822818
///
823819
/// (Alternatively, you can use [`Mesh::compute_tangents`] to mutate an existing mesh in-place)
824820
///
825-
/// See [`TangentCalculationStrategy`] for mesh topology and attribute requirements.
821+
/// See [`TangentAlgorithm`] for mesh topology and attribute requirements.
826822
pub fn with_computed_tangents(
827823
mut self,
828-
strategy: TangentCalculationStrategy,
824+
algorithm: TangentAlgorithm,
829825
) -> Result<Mesh, GenerateTangentsError> {
830-
self.compute_tangents(strategy)?;
826+
self.compute_tangents(algorithm)?;
831827
Ok(self)
832828
}
833829

@@ -1275,18 +1271,18 @@ impl core::ops::Mul<Mesh> for Transform {
12751271
}
12761272
}
12771273

1278-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
1279-
/// The strategy to use when computing mesh tangents. Defaults to `HighQuality`.
1280-
pub enum TangentCalculationStrategy {
1274+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default, Hash)]
1275+
/// The algorithm to use when computing mesh tangents. Defaults to `Mikktspace`.
1276+
pub enum TangentAlgorithm {
12811277
/// Uses the Morten S. Mikkelsen "mikktspace" algorithm. Produces potentially higher quality tangents, but much slower.
12821278
///
12831279
/// Requires a [`PrimitiveTopology::TriangleList`] topology and the [`Mesh::ATTRIBUTE_POSITION`], [`Mesh::ATTRIBUTE_NORMAL`] and [`Mesh::ATTRIBUTE_UV_0`] attributes set.
12841280
#[default]
1285-
HighQuality,
1281+
Mikktspace,
12861282
/// Uses the Gram-Schmidt fast approximation algorithm. Produces potentially lower quality tangents, but very fast.
12871283
///
12881284
/// Requires a [`PrimitiveTopology::TriangleList`] topology and the [`Mesh::ATTRIBUTE_POSITION`], [`Mesh::ATTRIBUTE_NORMAL`] and [`Mesh::ATTRIBUTE_UV_0`] attributes set.
1289-
FastApproximation,
1285+
GramSchmidt,
12901286
}
12911287

12921288
#[derive(Error, Debug)]

crates/bevy_pbr/src/decal/forward.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use bevy_math::{prelude::Rectangle, Quat, Vec2, Vec3};
99
use bevy_reflect::{Reflect, TypePath};
1010
use bevy_render::{
1111
alpha::AlphaMode,
12-
mesh::{
13-
Mesh, Mesh3d, MeshBuilder, MeshVertexBufferLayoutRef, Meshable, TangentCalculationStrategy,
14-
},
12+
mesh::{Mesh, Mesh3d, MeshBuilder, MeshVertexBufferLayoutRef, Meshable, TangentAlgorithm},
1513
render_resource::{
1614
AsBindGroup, CompareFunction, RenderPipelineDescriptor, Shader,
1715
SpecializedMeshPipelineError,
@@ -44,7 +42,7 @@ impl Plugin for ForwardDecalPlugin {
4442
.mesh()
4543
.build()
4644
.rotated_by(Quat::from_rotation_arc(Vec3::Z, Vec3::Y))
47-
.with_computed_tangents(TangentCalculationStrategy::HighQuality)
45+
.with_computed_tangents(TangentAlgorithm::Mikktspace)
4846
.unwrap(),
4947
);
5048

examples/3d/anisotropy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bevy::{
77
core_pipeline::Skybox,
88
math::vec3,
99
prelude::*,
10-
render::mesh::TangentCalculationStrategy,
10+
render::mesh::TangentAlgorithm,
1111
time::Stopwatch,
1212
};
1313

@@ -116,7 +116,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, app_status: Res
116116
Mesh3d(
117117
asset_server.add(
118118
Mesh::from(Sphere::new(0.1))
119-
.with_computed_tangents(TangentCalculationStrategy::HighQuality)
119+
.with_computed_tangents(TangentAlgorithm::Mikktspace)
120120
.unwrap(),
121121
),
122122
),

examples/3d/clearcoat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use bevy::{
2525
image::ImageLoaderSettings,
2626
math::vec3,
2727
prelude::*,
28-
render::mesh::TangentCalculationStrategy,
28+
render::mesh::TangentAlgorithm,
2929
};
3030

3131
/// The size of each sphere.
@@ -84,7 +84,7 @@ fn create_sphere_mesh(meshes: &mut Assets<Mesh>) -> Handle<Mesh> {
8484

8585
let mut sphere_mesh = Sphere::new(1.0).mesh().build();
8686
sphere_mesh
87-
.compute_tangents(TangentCalculationStrategy::HighQuality)
87+
.compute_tangents(TangentAlgorithm::Mikktspace)
8888
.expect("Failed to generate tangents");
8989
meshes.add(sphere_mesh)
9090
}

examples/3d/deferred_rendering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bevy::{
1212
NotShadowCaster, NotShadowReceiver, OpaqueRendererMethod,
1313
},
1414
prelude::*,
15-
render::mesh::TangentCalculationStrategy,
15+
render::mesh::TangentAlgorithm,
1616
};
1717

1818
fn main() {
@@ -234,7 +234,7 @@ fn setup_parallax(
234234

235235
// NOTE: for normal maps and depth maps to work, the mesh
236236
// needs tangents generated.
237-
cube.compute_tangents(TangentCalculationStrategy::FastApproximation)
237+
cube.compute_tangents(TangentAlgorithm::GramSchmidt)
238238
.unwrap();
239239

240240
let parallax_material = materials.add(StandardMaterial {

examples/3d/parallax_mapping.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
44
use std::fmt;
55

6-
use bevy::{
7-
image::ImageLoaderSettings, math::ops, prelude::*, render::mesh::TangentCalculationStrategy,
8-
};
6+
use bevy::{image::ImageLoaderSettings, math::ops, prelude::*, render::mesh::TangentAlgorithm};
97

108
fn main() {
119
App::new()
@@ -269,7 +267,7 @@ fn setup(
269267
// NOTE: for normal maps and depth maps to work, the mesh
270268
// needs tangents generated.
271269
Mesh::from(Cuboid::default())
272-
.with_computed_tangents(TangentCalculationStrategy::HighQuality)
270+
.with_computed_tangents(TangentAlgorithm::Mikktspace)
273271
.unwrap(),
274272
),
275273
),
@@ -279,7 +277,7 @@ fn setup(
279277

280278
let background_cube = meshes.add(
281279
Mesh::from(Cuboid::new(40.0, 40.0, 40.0))
282-
.with_computed_tangents(TangentCalculationStrategy::HighQuality)
280+
.with_computed_tangents(TangentAlgorithm::Mikktspace)
283281
.unwrap(),
284282
);
285283

examples/3d/rotate_environment_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bevy::{
77
core_pipeline::{tonemapping::Tonemapping::AcesFitted, Skybox},
88
image::ImageLoaderSettings,
99
prelude::*,
10-
render::mesh::TangentCalculationStrategy,
10+
render::mesh::TangentAlgorithm,
1111
};
1212

1313
/// Entry point.
@@ -52,7 +52,7 @@ fn create_sphere_mesh(meshes: &mut Assets<Mesh>) -> Handle<Mesh> {
5252

5353
let mut sphere_mesh = Sphere::new(1.0).mesh().build();
5454
sphere_mesh
55-
.compute_tangents(TangentCalculationStrategy::HighQuality)
55+
.compute_tangents(TangentAlgorithm::Mikktspace)
5656
.expect("Failed to generate tangents");
5757
meshes.add(sphere_mesh)
5858
}

examples/ecs/error_handling.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use bevy::ecs::{
1111
use bevy::math::sampling::UniformMeshSampler;
1212
use bevy::prelude::*;
1313

14-
use bevy::render::mesh::TangentCalculationStrategy;
14+
use bevy::render::mesh::TangentAlgorithm;
1515
use rand::distributions::Distribution;
1616
use rand::SeedableRng;
1717
use rand_chacha::ChaCha8Rng;
@@ -96,7 +96,7 @@ fn setup(
9696

9797
// Create a new sphere mesh:
9898
let mut sphere_mesh = Sphere::new(1.0).mesh().ico(7)?;
99-
sphere_mesh.compute_tangents(TangentCalculationStrategy::HighQuality)?;
99+
sphere_mesh.compute_tangents(TangentAlgorithm::Mikktspace)?;
100100

101101
// Spawn the mesh into the scene:
102102
let mut sphere = commands.spawn((

0 commit comments

Comments
 (0)