Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bin/measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
);
Expand Down
34 changes: 30 additions & 4 deletions src/bin/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -38,6 +44,8 @@ async fn render_views(
cameras: Vec<SceneCamera>,
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());
Expand All @@ -55,10 +63,22 @@ async fn render_views(
for (i, s) in cameras.iter().enumerate().progress_with(pb) {
let mut resolution: Vector2<u32> = 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 {
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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(
Expand All @@ -174,6 +198,8 @@ async fn main() {
scene.cameras(Some(Split::Train)),
&opt.img_out,
"train",
opt.output_width,
opt.output_height,
)
.await;

Expand Down
21 changes: 19 additions & 2 deletions src/bin/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -48,10 +57,13 @@ async fn render_tracking_shot(
video_out: &PathBuf,
duration: Option<Duration>,
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<u32> = Vector2::new(1024, 1024) * 2;
let resolution: Vector2<u32> = Vector2::new(output_width, output_height);

let target = device.create_texture(&wgpu::TextureDescriptor {
label: Some("render texture"),
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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;

Expand Down
65 changes: 65 additions & 0 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f32>,//x,y,id
pub last_touch_2: Vector3<f32>,//x,y,id
pub touch_rotate_sensitivity_threshold: f32,
pub touch_rotate_sensitivity: f32,
pub touch_zoom_sensitivity: f32,
}

impl CameraController {
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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) {
Expand Down
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,32 @@ pub async fn open_window<R: Read + Seek + Send + Sync + 'static>(
_=>{}
}
}
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
Expand Down