diff --git a/src/bin/measure.rs b/src/bin/measure.rs index 4365b57..365dbdf 100644 --- a/src/bin/measure.rs +++ b/src/bin/measure.rs @@ -73,6 +73,8 @@ async fn render_views( walltime: Duration::from_secs(100), scene_center: None, scene_extend: None, + background_color: wgpu::Color::BLACK, + resolution: resolution, }, &mut None, ); @@ -121,6 +123,8 @@ async fn render_views( walltime: Duration::from_secs(100), scene_center: None, scene_extend: None, + background_color: wgpu::Color::BLACK, + resolution: resolution, }, &mut None, ); diff --git a/src/bin/render.rs b/src/bin/render.rs index 21dc83a..fccd836 100644 --- a/src/bin/render.rs +++ b/src/bin/render.rs @@ -27,6 +27,12 @@ struct Opt { /// maximum allowed Spherical Harmonics (SH) degree #[arg(long, default_value_t = 3)] max_sh_deg: u32, + + #[arg(long, default_value_t = 0)] + output_width: u32, + + #[arg(long, default_value_t = 0)] + output_height: u32, } #[allow(unused)] @@ -38,6 +44,8 @@ async fn render_views( cameras: Vec, img_out: &PathBuf, split: &str, + output_width: u32, + output_height: u32, ) { let img_out = img_out.join(&split); println!("saving images to '{}'", img_out.to_string_lossy()); @@ -55,10 +63,22 @@ async fn render_views( for (i, s) in cameras.iter().enumerate().progress_with(pb) { let mut resolution: Vector2 = Vector2::new(s.width, s.height); - if resolution.x > 1600 { - let s = resolution.x as f32 / 1600.; - resolution.x = 1600; - resolution.y = (resolution.y as f32 / s) as u32; + if output_width != 0 && output_height != 0 { + resolution.x = output_width; + resolution.y = output_height; + } + else + { + if resolution.x > 1600 { + let s = resolution.x as f32 / 1600.; + resolution.x = 1600; + resolution.y = (resolution.y as f32 / s) as u32; + } + if resolution.y > 1600 { + let s = resolution.y as f32 / 1600.; + resolution.x = (resolution.x as f32 / s) as u32; + resolution.y = 1600; + } } let target = device.create_texture(&wgpu::TextureDescriptor { @@ -101,6 +121,8 @@ async fn render_views( walltime: Duration::from_secs(100), scene_center: None, scene_extend: None, + background_color: wgpu::Color::BLACK, + resolution: resolution, }, &mut None, ); @@ -164,6 +186,8 @@ async fn main() { scene.cameras(Some(Split::Test)), &opt.img_out, "test", + opt.output_width, + opt.output_height, ) .await; render_views( @@ -174,6 +198,8 @@ async fn main() { scene.cameras(Some(Split::Train)), &opt.img_out, "train", + opt.output_width, + opt.output_height, ) .await; diff --git a/src/bin/video.rs b/src/bin/video.rs index d64bc70..7d6d482 100644 --- a/src/bin/video.rs +++ b/src/bin/video.rs @@ -37,6 +37,15 @@ struct Opt { #[arg(long, default_value_t = 30)] fps: u32, + + #[arg(long, default_value_t = 2880)] + output_width: u32, + + #[arg(long, default_value_t = 4320)] + output_height: u32, + + #[arg(long, default_value_t = 0)] + beginning_scale_up_seconds: u64, } async fn render_tracking_shot( @@ -48,10 +57,13 @@ async fn render_tracking_shot( video_out: &PathBuf, duration: Option, fps: u32, + output_width: u32, + output_height: u32, + beginning_scale_up_seconds: u64, ) { println!("saving video to '{}'", video_out.to_string_lossy()); - let resolution: Vector2 = Vector2::new(1024, 1024) * 2; + let resolution: Vector2 = Vector2::new(output_width, output_height); let target = device.create_texture(&wgpu::TextureDescriptor { label: Some("render texture"), @@ -126,9 +138,11 @@ async fn render_tracking_shot( mip_splatting: None, kernel_size: None, clipping_box: None, - walltime: state_time, + walltime: state_time + Duration::from_secs(beginning_scale_up_seconds), scene_center: None, scene_extend: None, + background_color: wgpu::Color::BLACK, + resolution: resolution, }, &mut None, ); @@ -198,6 +212,9 @@ async fn main() { &opt.video_out, opt.duration.map(Duration::from_secs_f32), opt.fps, + opt.output_width, + opt.output_height, + opt.beginning_scale_up_seconds, ) .await; diff --git a/src/controller.rs b/src/controller.rs index 72a0c35..707ea8b 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -25,6 +25,13 @@ pub struct CameraController { pub right_mouse_pressed: bool, pub alt_pressed: bool, pub user_inptut: bool, + + pub touched_count: i32, + pub last_touch: Vector3,//x,y,id + pub last_touch_2: Vector3,//x,y,id + pub touch_rotate_sensitivity_threshold: f32, + pub touch_rotate_sensitivity: f32, + pub touch_zoom_sensitivity: f32, } impl CameraController { @@ -42,6 +49,12 @@ impl CameraController { right_mouse_pressed: false, alt_pressed: false, user_inptut: false, + touched_count: 0, + last_touch: Vector3::zero(), + last_touch_2: Vector3::zero(), + touch_rotate_sensitivity_threshold: 3.0, + touch_rotate_sensitivity: 2.0, + touch_zoom_sensitivity: 0.01, } } @@ -104,6 +117,58 @@ impl CameraController { self.user_inptut = true; } + pub fn process_touch(&mut self, touch_id: f32, touch_x: f32, touch_y: f32) { + //println!("touched_count {}", self.touched_count); + if self.touched_count == 1 {//rotate + let mut touch_dx = 0.0; + if touch_x - self.last_touch.x < -self.touch_rotate_sensitivity_threshold { + touch_dx = -1.0; + } + else if touch_x - self.last_touch.x > self.touch_rotate_sensitivity_threshold { + touch_dx = 1.0; + } + let mut touch_dy = 0.0; + if touch_y - self.last_touch.y < -self.touch_rotate_sensitivity_threshold { + touch_dy = -1.0; + } + else if touch_y - self.last_touch.y > self.touch_rotate_sensitivity_threshold { + touch_dy = 1.0; + } + self.rotation.x += touch_dx * self.touch_rotate_sensitivity; + self.rotation.y += touch_dy * self.touch_rotate_sensitivity; + self.user_inptut = true; + //save last + self.last_touch.x = touch_x; + self.last_touch.y = touch_y; + self.last_touch.z = touch_id; + } + else if self.touched_count == 2 {//zoom + let last_distance = ((self.last_touch.x - self.last_touch_2.x) * (self.last_touch.x - self.last_touch_2.x) + (self.last_touch.y - self.last_touch_2.y) * (self.last_touch.y - self.last_touch_2.y)).sqrt(); + let mut cur_distance = 0.0; + if self.last_touch.z == touch_id {//1st point + cur_distance = ((self.last_touch_2.x - touch_x) * (self.last_touch_2.x - touch_x) + (self.last_touch_2.y - touch_y) * (self.last_touch_2.y - touch_y)).sqrt(); + //save last + self.last_touch.x = touch_x; + self.last_touch.y = touch_y; + } + else if self.last_touch_2.z == touch_id{//2nd point + cur_distance = ((self.last_touch.x - touch_x) * (self.last_touch.x - touch_x) + (self.last_touch.y - touch_y) * (self.last_touch.y - touch_y)).sqrt(); + //save last + self.last_touch_2.x = touch_x; + self.last_touch_2.y = touch_y; + } + let delta_distance = cur_distance - last_distance; + if delta_distance > 0.0 { + self.scroll -= self.touch_zoom_sensitivity; + self.user_inptut = true; + } + else if delta_distance < 0.0 { + self.scroll += self.touch_zoom_sensitivity; + self.user_inptut = true; + } + } + } + /// moves the controller center to the closest point on a line defined by the camera position and rotation /// ajusts the controller up vector by projecting the current up vector onto the plane defined by the camera right vector pub fn reset_to_camera(&mut self, camera: PerspectiveCamera) { diff --git a/src/lib.rs b/src/lib.rs index 9191212..2bd6a87 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -839,6 +839,32 @@ pub async fn open_window( _=>{} } } + WindowEvent::Touch(touch) => { + //println!("Touch {}/{}/{}", touch.id, touch.location.x, touch.location.y); + match touch.phase + { + winit::event::TouchPhase::Started => { + //println!("start"); + state.controller.touched_count += 1; + if state.controller.touched_count == 1 { + state.controller.last_touch.x = touch.location.x as f32; + state.controller.last_touch.y = touch.location.y as f32; + state.controller.last_touch.z = touch.id as f32; + } + else if state.controller.touched_count == 2 { + state.controller.last_touch_2.x = touch.location.x as f32; + state.controller.last_touch_2.y = touch.location.y as f32; + state.controller.last_touch_2.z = touch.id as f32; + } + }, + winit::event::TouchPhase::Ended => { + //println!("end"); + state.controller.touched_count -= 1; + }, + winit::event::TouchPhase::Moved => state.controller.process_touch(touch.id as f32, touch.location.x as f32, touch.location.y as f32), + winit::event::TouchPhase::Cancelled => state.controller.touched_count = 0, + } + } WindowEvent::RedrawRequested => { if !config.no_vsync{ // make sure the next redraw is called with a small delay