From e01be21a6cc4db1bab10b77712ee7ad6827421d5 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Sun, 2 Jun 2024 01:14:05 +0200 Subject: [PATCH] keep camera position on reload --- ogre_mesh_viewer.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/ogre_mesh_viewer.py b/ogre_mesh_viewer.py index 42cac05..248d591 100755 --- a/ogre_mesh_viewer.py +++ b/ogre_mesh_viewer.py @@ -285,7 +285,7 @@ def preRenderTargetUpdate(self, evt): if ImGui.MenuItem("Open File", "F1"): self.load_file() if ImGui.MenuItem("Reload File", "F5"): - app.reload() + app.reload(keep_cam=True) if ImGui.MenuItem("Save Screenshot", "P"): self.app._save_screenshot() ImGui.Separator() @@ -529,6 +529,7 @@ def __init__(self, infile, rescfg): self.active_controllers = {} self.next_rendersystem = "" + self.next_campose = None # in case we want to show the file dialog root = tk.Tk() @@ -554,7 +555,7 @@ def keyPressed(self, evt): elif evt.keysym.sym == OgreBites.SDLK_F1: self.gui.load_file() elif evt.keysym.sym == OgreBites.SDLK_F5: - self.reload() + self.reload(keep_cam=True) return True @@ -648,7 +649,11 @@ def update_fixed_camera_yaw(self): if self.grid_visible: self.grid_floor.show_plane(self.fixed_yaw_axis) - if self.fixed_yaw_axis == 0: + if self.next_campose: + camnode.setPosition(self.next_campose[0]) + camnode.setOrientation(self.next_campose[1]) + self.next_campose = None + elif self.fixed_yaw_axis == 0: self.camman.setYawPitchDist(0, 0, diam) camnode.roll(-Ogre.Degree(90)) elif self.fixed_yaw_axis == 2: @@ -656,10 +661,17 @@ def update_fixed_camera_yaw(self): else: self.camman.setYawPitchDist(0, self.default_tilt, diam) - def reload(self): - if app.infile: - app.restart = True - app.getRoot().queueEndRendering() + def reload(self, keep_cam=False): + if not app.infile: + return + + if keep_cam: + camnode = self.camman.getCamera() + # multiply to store a copy instead of a reference + self.next_campose = (camnode.getPosition()*1, camnode.getOrientation()*1) + + app.restart = True + app.getRoot().queueEndRendering() def locateResources(self): self.filename = os.path.basename(self.infile)