Skip to content

Commit

Permalink
keep camera position on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Jun 1, 2024
1 parent 81cc5fc commit e01be21
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions ogre_mesh_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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

Expand Down Expand Up @@ -648,18 +649,29 @@ 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:
self.camman.setYawPitchDist(0, self.default_tilt - Ogre.Degree(90), diam)
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)
Expand Down

0 comments on commit e01be21

Please sign in to comment.