Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix forever repaint of big scenes #5071

Merged
merged 2 commits into from
Feb 6, 2024
Merged
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
20 changes: 13 additions & 7 deletions crates/re_space_view_spatial/src/eye.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,19 @@ impl OrbitEye {
}

pub fn lerp(&self, other: &Self, t: f32) -> Self {
Self {
orbit_center: self.orbit_center.lerp(other.orbit_center, t),
orbit_radius: lerp(self.orbit_radius..=other.orbit_radius, t),
world_from_view_rot: self.world_from_view_rot.slerp(other.world_from_view_rot, t),
fov_y: egui::lerp(self.fov_y..=other.fov_y, t),
up: self.up.lerp(other.up, t).normalize_or_zero(),
velocity: self.velocity.lerp(other.velocity, t),
if t == 0.0 {
*self // avoid rounding errors
} else if t == 1.0 {
*other // avoid rounding errors
} else {
Self {
orbit_center: self.orbit_center.lerp(other.orbit_center, t),
orbit_radius: lerp(self.orbit_radius..=other.orbit_radius, t),
world_from_view_rot: self.world_from_view_rot.slerp(other.world_from_view_rot, t),
fov_y: egui::lerp(self.fov_y..=other.fov_y, t),
up: self.up.lerp(other.up, t).normalize_or_zero(),
velocity: self.velocity.lerp(other.velocity, t),
}
}
}

Expand Down
19 changes: 10 additions & 9 deletions crates/re_space_view_spatial/src/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ impl View3DState {
let t = t.clamp(0.0, 1.0);
let t = ease_out(t);

if t < 1.0 {
response.ctx.request_repaint();
}

if let Some(target_orbit) = &cam_interpolation.target_orbit {
*orbit_eye = cam_interpolation.start.lerp(target_orbit, t);
} else if let Some(target_eye) = &cam_interpolation.target_eye {
Expand All @@ -160,12 +156,12 @@ impl View3DState {
self.eye_interpolation = None;
}

if 1.0 <= t {
// We have arrived at our target
self.eye_interpolation = None;
} else {
if t < 1.0 {
// There's more frames to render to finish interpolation.
response.ctx.request_repaint();
} else {
// We have arrived at our target
self.eye_interpolation = None;
}
}

Expand Down Expand Up @@ -256,6 +252,10 @@ impl View3DState {
// the user wants to move the camera somewhere, so stop spinning
self.spin = false;

if self.orbit_eye == Some(target) {
return; // We're already there.
}

// Don't restart interpolation if we're already on it.
if let Some(eye_interpolation) = &self.eye_interpolation {
if eye_interpolation.target_orbit == Some(target) {
Expand Down Expand Up @@ -329,7 +329,8 @@ impl EyeInterpolation {
.angle_between(stop.world_from_rub_view.rotation());

// Threshold to avoid doing pointless interpolations that trigger frame requests.
if angle_difference < 0.01 && start.pos_in_world().distance(stop.pos_in_world()) < 0.0001 {
let distance = start.pos_in_world().distance(stop.pos_in_world());
if angle_difference < 0.01 && distance < 0.0001 {
None
} else {
Some(egui::remap_clamp(
Expand Down
Loading