Skip to content

Commit

Permalink
fix: 2dgs z rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mosure committed Oct 18, 2024
1 parent 9f79e26 commit aae545e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_gaussian_splatting"
description = "bevy gaussian splatting render pipeline plugin"
version = "2.6.0"
version = "2.6.1"
edition = "2021"
authors = ["mosure <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/render/surfel.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn compute_cov2d_surfel(
let S = get_scale_matrix(scale);
let R = get_rotation_matrix(rotation);

let L = T_r * S * R;
let L = T_r * transpose(R) * S;

let world_from_local = mat3x4<f32>(
vec4<f32>(L.x, 0.0),
Expand Down
39 changes: 31 additions & 8 deletions tools/surfel_plane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use bevy_gaussian_splatting::{
GaussianCloudSettings,
GaussianSplattingBundle,
GaussianSplattingPlugin,
gaussian::f32::Rotation,
utils::{
setup_hooks,
GaussianSplattingViewer,
Expand All @@ -35,7 +36,7 @@ pub fn setup_surfel_compare(
) {
let grid_size_x = 10;
let grid_size_y = 10;
let spacing = 5.0;
let spacing = 12.0;
let visualize_bounding_box = false;

let mut blue_gaussians = Vec::new();
Expand All @@ -47,11 +48,22 @@ pub fn setup_surfel_compare(
let x = i as f32 * spacing - (grid_size_x as f32 * spacing) / 2.0;
let y = j as f32 * spacing - (grid_size_y as f32 * spacing) / 2.0;
let position = [x, y, 0.0, 1.0];
let scale = [1.0, 1.0, 0.01, 0.5];
let scale = [2.0, 1.0, 0.01, 0.5];

let angle = std::f32::consts::PI / 2.0 * i as f32 / grid_size_x as f32;
let rotation = Quat::from_rotation_z(angle).to_array();
let rotation = [3usize, 0usize, 1usize, 2usize]
.iter()
.map(|i| rotation[*i])
.collect::<Vec<_>>()
.try_into()
.unwrap();

let gaussian = Gaussian {
position_visibility: position.into(),
rotation: [0.0, 0.0, 0.0, 1.0].into(),
rotation: Rotation {
rotation,
},
scale_opacity: scale.into(),
spherical_harmonic: blue_sh,
};
Expand Down Expand Up @@ -80,14 +92,22 @@ pub fn setup_surfel_compare(
let x = i as f32 * spacing - (grid_size_x as f32 * spacing) / 2.0;
let y = j as f32 * spacing - (grid_size_y as f32 * spacing) / 2.0;
let position = [x, y, 0.0, 1.0];
let scale = [1.0, 1.0, 99.0, 0.3];
let scale = [2.0, 1.0, 0.01, 0.5];

// let angle = std::f32::consts::PI / 2.0;
// let rotation = Quat::from_rotation_y(angle).to_array().into();
let angle = std::f32::consts::PI / 2.0 * (i + 1) as f32 / grid_size_x as f32;
let rotation = Quat::from_rotation_z(angle).to_array();
let rotation = [3usize, 0usize, 1usize, 2usize]
.iter()
.map(|i| rotation[*i])
.collect::<Vec<_>>()
.try_into()
.unwrap();

let gaussian = Gaussian {
position_visibility: position.into(),
rotation: [0.0, 0.0, 0.0, 1.0].into(),
rotation: Rotation {
rotation,
},
scale_opacity: scale.into(),
spherical_harmonic: red_sh,
};
Expand All @@ -110,9 +130,12 @@ pub fn setup_surfel_compare(
Name::new("gaussian_cloud_2dgs"),
));

let camera_transform = Transform::from_translation(Vec3::new(0.0, 1.5, 20.0));
info!("camera_transform: {:?}", camera_transform.compute_matrix().to_cols_array_2d());

commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 1.5, 20.0)),
transform: camera_transform,
tonemapping: Tonemapping::None,
..default()
},
Expand Down

0 comments on commit aae545e

Please sign in to comment.