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

keep camera position on reload #45

Merged
merged 1 commit into from
Jun 1, 2024
Merged
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
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