rename GlobalTransform::compute_matrix to to_matrix (#19643)
# Objective - compute_matrix doesn't compute anything, it just puts an Affine3A into a Mat4. the name is inaccurate ## Solution - rename it to conform with to_isometry (which, ironically, does compute a decomposition which is rather expensive) ## Testing - Its a rename. If it compiles, its good to go --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
parent
20781371e8
commit
2915a3b903
@ -560,7 +560,7 @@ pub(super) fn prepare_atmosphere_transforms(
|
||||
};
|
||||
|
||||
for (entity, view) in &views {
|
||||
let world_from_view = view.world_from_view.compute_matrix();
|
||||
let world_from_view = view.world_from_view.to_matrix();
|
||||
let camera_z = world_from_view.z_axis.truncate();
|
||||
let camera_y = world_from_view.y_axis.truncate();
|
||||
let atmo_z = camera_z
|
||||
|
@ -353,7 +353,7 @@ pub(crate) fn assign_objects_to_clusters(
|
||||
|
||||
let mut requested_cluster_dimensions = config.dimensions_for_screen_size(screen_size);
|
||||
|
||||
let world_from_view = camera_transform.compute_matrix();
|
||||
let world_from_view = camera_transform.to_matrix();
|
||||
let view_from_world_scale = camera_transform.compute_transform().scale.recip();
|
||||
let view_from_world_scale_max = view_from_world_scale.abs().max_element();
|
||||
let view_from_world = world_from_view.inverse();
|
||||
|
@ -341,7 +341,7 @@ pub fn build_directional_light_cascades(
|
||||
.iter()
|
||||
.filter_map(|(entity, transform, projection, camera)| {
|
||||
if camera.is_active {
|
||||
Some((entity, projection, transform.compute_matrix()))
|
||||
Some((entity, projection, transform.to_matrix()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -357,7 +357,7 @@ pub fn build_directional_light_cascades(
|
||||
// light_to_world has orthogonal upper-left 3x3 and zero translation.
|
||||
// Even though only the direction (i.e. rotation) of the light matters, we don't constrain
|
||||
// users to not change any other aspects of the transform - there's no guarantee
|
||||
// `transform.compute_matrix()` will give us a matrix with our desired properties.
|
||||
// `transform.to_matrix()` will give us a matrix with our desired properties.
|
||||
// Instead, we directly create a good matrix from just the rotation.
|
||||
let world_from_light = Mat4::from_quat(transform.compute_transform().rotation);
|
||||
let light_to_world_inverse = world_from_light.inverse();
|
||||
|
@ -595,7 +595,7 @@ where
|
||||
) -> Option<LightProbeInfo<C>> {
|
||||
environment_map.id(image_assets).map(|id| LightProbeInfo {
|
||||
world_from_light: light_probe_transform.affine(),
|
||||
light_from_world: light_probe_transform.compute_matrix().inverse(),
|
||||
light_from_world: light_probe_transform.to_matrix().inverse(),
|
||||
asset_id: id,
|
||||
intensity: environment_map.intensity(),
|
||||
affects_lightmapped_mesh_diffuse: environment_map.affects_lightmapped_mesh_diffuse(),
|
||||
|
@ -216,7 +216,7 @@ pub fn update_previous_view_data(
|
||||
query: Query<(Entity, &Camera, &GlobalTransform), Or<(With<Camera3d>, With<ShadowView>)>>,
|
||||
) {
|
||||
for (entity, camera, camera_transform) in &query {
|
||||
let world_from_view = camera_transform.compute_matrix();
|
||||
let world_from_view = camera_transform.to_matrix();
|
||||
let view_from_world = world_from_view.inverse();
|
||||
let view_from_clip = camera.clip_from_view().inverse();
|
||||
|
||||
@ -703,7 +703,7 @@ pub fn prepare_previous_view_uniforms(
|
||||
let prev_view_data = match maybe_previous_view_uniforms {
|
||||
Some(previous_view) => previous_view.clone(),
|
||||
None => {
|
||||
let world_from_view = camera.world_from_view.compute_matrix();
|
||||
let world_from_view = camera.world_from_view.to_matrix();
|
||||
let view_from_world = world_from_view.inverse();
|
||||
let view_from_clip = camera.clip_from_view.inverse();
|
||||
|
||||
|
@ -700,7 +700,7 @@ pub fn prepare_volumetric_fog_uniforms(
|
||||
// Do this up front to avoid O(n^2) matrix inversion.
|
||||
local_from_world_matrices.clear();
|
||||
for (_, _, fog_transform) in fog_volumes.iter() {
|
||||
local_from_world_matrices.push(fog_transform.compute_matrix().inverse());
|
||||
local_from_world_matrices.push(fog_transform.to_matrix().inverse());
|
||||
}
|
||||
|
||||
let uniform_count = view_targets.iter().len() * local_from_world_matrices.len();
|
||||
@ -712,7 +712,7 @@ pub fn prepare_volumetric_fog_uniforms(
|
||||
};
|
||||
|
||||
for (view_entity, extracted_view, volumetric_fog) in view_targets.iter() {
|
||||
let world_from_view = extracted_view.world_from_view.compute_matrix();
|
||||
let world_from_view = extracted_view.world_from_view.to_matrix();
|
||||
|
||||
let mut view_fog_volumes = vec![];
|
||||
|
||||
|
@ -317,7 +317,7 @@ mod tests {
|
||||
#[test]
|
||||
fn ray_mesh_intersection_simple() {
|
||||
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
|
||||
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
|
||||
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
|
||||
let positions = &[V0, V1, V2];
|
||||
let vertex_normals = None;
|
||||
let indices: Option<&[u16]> = None;
|
||||
@ -338,7 +338,7 @@ mod tests {
|
||||
#[test]
|
||||
fn ray_mesh_intersection_indices() {
|
||||
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
|
||||
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
|
||||
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
|
||||
let positions = &[V0, V1, V2];
|
||||
let vertex_normals = None;
|
||||
let indices: Option<&[u16]> = Some(&[0, 1, 2]);
|
||||
@ -359,7 +359,7 @@ mod tests {
|
||||
#[test]
|
||||
fn ray_mesh_intersection_indices_vertex_normals() {
|
||||
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
|
||||
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
|
||||
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
|
||||
let positions = &[V0, V1, V2];
|
||||
let vertex_normals: Option<&[[f32; 3]]> =
|
||||
Some(&[[-1., 0., 0.], [-1., 0., 0.], [-1., 0., 0.]]);
|
||||
@ -381,7 +381,7 @@ mod tests {
|
||||
#[test]
|
||||
fn ray_mesh_intersection_vertex_normals() {
|
||||
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
|
||||
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
|
||||
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
|
||||
let positions = &[V0, V1, V2];
|
||||
let vertex_normals: Option<&[[f32; 3]]> =
|
||||
Some(&[[-1., 0., 0.], [-1., 0., 0.], [-1., 0., 0.]]);
|
||||
@ -403,7 +403,7 @@ mod tests {
|
||||
#[test]
|
||||
fn ray_mesh_intersection_missing_vertex_normals() {
|
||||
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
|
||||
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
|
||||
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
|
||||
let positions = &[V0, V1, V2];
|
||||
let vertex_normals: Option<&[[f32; 3]]> = Some(&[]);
|
||||
let indices: Option<&[u16]> = None;
|
||||
@ -424,7 +424,7 @@ mod tests {
|
||||
#[test]
|
||||
fn ray_mesh_intersection_indices_missing_vertex_normals() {
|
||||
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
|
||||
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
|
||||
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
|
||||
let positions = &[V0, V1, V2];
|
||||
let vertex_normals: Option<&[[f32; 3]]> = Some(&[]);
|
||||
let indices: Option<&[u16]> = Some(&[0, 1, 2]);
|
||||
@ -445,7 +445,7 @@ mod tests {
|
||||
#[test]
|
||||
fn ray_mesh_intersection_not_enough_indices() {
|
||||
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
|
||||
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
|
||||
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
|
||||
let positions = &[V0, V1, V2];
|
||||
let vertex_normals = None;
|
||||
let indices: Option<&[u16]> = Some(&[0]);
|
||||
@ -466,7 +466,7 @@ mod tests {
|
||||
#[test]
|
||||
fn ray_mesh_intersection_bad_indices() {
|
||||
let ray = Ray3d::new(Vec3::ZERO, Dir3::X);
|
||||
let mesh_transform = GlobalTransform::IDENTITY.compute_matrix();
|
||||
let mesh_transform = GlobalTransform::IDENTITY.to_matrix();
|
||||
let positions = &[V0, V1, V2];
|
||||
let vertex_normals = None;
|
||||
let indices: Option<&[u16]> = Some(&[0, 1, 3]);
|
||||
|
@ -233,7 +233,7 @@ impl<'w, 's> MeshRayCast<'w, 's> {
|
||||
if let Some(distance) = ray_aabb_intersection_3d(
|
||||
ray,
|
||||
&Aabb3d::new(aabb.center, aabb.half_extents),
|
||||
&transform.compute_matrix(),
|
||||
&transform.to_matrix(),
|
||||
) {
|
||||
aabb_hits_tx.send((FloatOrd(distance), entity)).ok();
|
||||
}
|
||||
@ -287,7 +287,7 @@ impl<'w, 's> MeshRayCast<'w, 's> {
|
||||
|
||||
// Perform the actual ray cast.
|
||||
let _ray_cast_guard = ray_cast_guard.enter();
|
||||
let transform = transform.compute_matrix();
|
||||
let transform = transform.to_matrix();
|
||||
let intersection = ray_intersection_over_mesh(mesh, &transform, ray, backfaces);
|
||||
|
||||
if let Some(intersection) = intersection {
|
||||
|
@ -601,8 +601,7 @@ impl Camera {
|
||||
rect_relative.y = 1.0 - rect_relative.y;
|
||||
|
||||
let ndc = rect_relative * 2. - Vec2::ONE;
|
||||
let ndc_to_world =
|
||||
camera_transform.compute_matrix() * self.computed.clip_from_view.inverse();
|
||||
let ndc_to_world = camera_transform.to_matrix() * self.computed.clip_from_view.inverse();
|
||||
let world_near_plane = ndc_to_world.project_point3(ndc.extend(1.));
|
||||
// Using EPSILON because an ndc with Z = 0 returns NaNs.
|
||||
let world_far_plane = ndc_to_world.project_point3(ndc.extend(f32::EPSILON));
|
||||
@ -668,7 +667,7 @@ impl Camera {
|
||||
) -> Option<Vec3> {
|
||||
// Build a transformation matrix to convert from world space to NDC using camera data
|
||||
let clip_from_world: Mat4 =
|
||||
self.computed.clip_from_view * camera_transform.compute_matrix().inverse();
|
||||
self.computed.clip_from_view * camera_transform.to_matrix().inverse();
|
||||
let ndc_space_coords: Vec3 = clip_from_world.project_point3(world_position);
|
||||
|
||||
(!ndc_space_coords.is_nan()).then_some(ndc_space_coords)
|
||||
@ -689,8 +688,7 @@ impl Camera {
|
||||
/// Will panic if the projection matrix is invalid (has a determinant of 0) and `glam_assert` is enabled.
|
||||
pub fn ndc_to_world(&self, camera_transform: &GlobalTransform, ndc: Vec3) -> Option<Vec3> {
|
||||
// Build a transformation matrix to convert from NDC to world space using camera data
|
||||
let ndc_to_world =
|
||||
camera_transform.compute_matrix() * self.computed.clip_from_view.inverse();
|
||||
let ndc_to_world = camera_transform.to_matrix() * self.computed.clip_from_view.inverse();
|
||||
|
||||
let world_space_coords = ndc_to_world.project_point3(ndc);
|
||||
|
||||
|
@ -93,8 +93,7 @@ pub trait CameraProjection {
|
||||
/// This code is called by [`update_frusta`](crate::view::visibility::update_frusta) system
|
||||
/// for each camera to update its frustum.
|
||||
fn compute_frustum(&self, camera_transform: &GlobalTransform) -> Frustum {
|
||||
let clip_from_world =
|
||||
self.get_clip_from_view() * camera_transform.compute_matrix().inverse();
|
||||
let clip_from_world = self.get_clip_from_view() * camera_transform.to_matrix().inverse();
|
||||
Frustum::from_clip_from_world_custom_far(
|
||||
&clip_from_world,
|
||||
&camera_transform.translation(),
|
||||
|
@ -316,7 +316,7 @@ pub struct ExtractedView {
|
||||
impl ExtractedView {
|
||||
/// Creates a 3D rangefinder for a view
|
||||
pub fn rangefinder3d(&self) -> ViewRangefinder3d {
|
||||
ViewRangefinder3d::from_world_from_view(&self.world_from_view.compute_matrix())
|
||||
ViewRangefinder3d::from_world_from_view(&self.world_from_view.to_matrix())
|
||||
}
|
||||
}
|
||||
|
||||
@ -934,7 +934,7 @@ pub fn prepare_view_uniforms(
|
||||
}
|
||||
|
||||
let view_from_clip = clip_from_view.inverse();
|
||||
let world_from_view = extracted_view.world_from_view.compute_matrix();
|
||||
let world_from_view = extracted_view.world_from_view.to_matrix();
|
||||
let view_from_world = world_from_view.inverse();
|
||||
|
||||
let clip_from_world = if temporal_jitter.is_some() {
|
||||
|
@ -143,7 +143,7 @@ pub fn prepare_raytracing_scene_bindings(
|
||||
continue;
|
||||
};
|
||||
|
||||
let transform = transform.compute_matrix();
|
||||
let transform = transform.to_matrix();
|
||||
*tlas.get_mut_single(instance_id).unwrap() = Some(TlasInstance::new(
|
||||
blas,
|
||||
tlas_transform(&transform),
|
||||
|
@ -115,7 +115,7 @@ impl GlobalTransform {
|
||||
|
||||
/// Returns the 3d affine transformation matrix as a [`Mat4`].
|
||||
#[inline]
|
||||
pub fn compute_matrix(&self) -> Mat4 {
|
||||
pub fn to_matrix(&self) -> Mat4 {
|
||||
Mat4::from(self.0)
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
title: GlobalTransform::compute_matrix rename
|
||||
pull_requests: [19643]
|
||||
---
|
||||
|
||||
`GlobalTransform::compute_matrix` has been renamed to `GlobalTransform::to_matrix` because it does not compute anything, it simply moves data into a different type.
|
Loading…
Reference in New Issue
Block a user