Skip to content

Commit

Permalink
Set default yaw axis Vector3::UNIT_Y (tabletop mode) + Optional X, Z …
Browse files Browse the repository at this point in the history
…and free rotation
  • Loading branch information
sercero committed Apr 19, 2024
1 parent 0dfe840 commit c069059
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions ogre_mesh_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def __init__(self, app):
self.show_render_settings = False
self.side_panel_visible = True
self.is_filedialog_open = False
self.fixed_yaw_axes = {'X-up': (1, 0, 0), 'Y-up': (0, 1, 0), 'Z-up': (0, 0, 1)}
self.fixed_yaw_axis = 'Y-up'
self.fixed_yaw = True
self.default_tilt = Ogre.Degree(20)

self.app = app

Expand Down Expand Up @@ -201,6 +205,26 @@ def draw_loading(self):
ImGui.Text("Loading.. ")
ImGui.End()

def set_orientation(self):
camnode = self.app.camman.getCamera()
diam = camnode.getPosition().length()
camnode.setOrientation(Ogre.Quaternion.IDENTITY)
if self.fixed_yaw is True:
camnode.setFixedYawAxis(True, self.fixed_yaw_axes[self.fixed_yaw_axis])
if self.fixed_yaw_axis == 'X-up':
self.app.camman.setYawPitchDist(0, 0, diam)
camnode.roll(-Ogre.Degree(90))
print("X-up")
elif self.fixed_yaw_axis == 'Y-up':
self.app.camman.setYawPitchDist(0, self.default_tilt, diam)
print("Y-up")
elif self.fixed_yaw_axis == 'Z-up':
self.app.camman.setYawPitchDist(0, self.default_tilt + Ogre.Degree(90), diam)
print("Z-up")
else:
self.app.camman.setYawPitchDist(0, self.default_tilt, diam)
self.app.camman.setFixedYaw(self.fixed_yaw)

def load_file(self):
# Avoid recursive calling, which might block the window manager
if self.is_filedialog_open:
Expand Down Expand Up @@ -250,6 +274,25 @@ def preRenderTargetUpdate(self, evt):
if ImGui.MenuItem("Wireframe Mode", "W", app.cam.getPolygonMode() == Ogre.PM_WIREFRAME):
self.app._toggle_wireframe_mode()

if ImGui.BeginMenu("MeshViewer Orientation"):
if ImGui.MenuItem("Free rotation", "", not self.fixed_yaw):
self.fixed_yaw = False
self.set_orientation()
ImGui.Separator()
if ImGui.MenuItem("Fixed X-up", "", self.fixed_yaw and self.fixed_yaw_axis is 'X-up'):
self.fixed_yaw = True
self.fixed_yaw_axis = 'X-up'
self.set_orientation()
if ImGui.MenuItem("Fixed Y-up", "", self.fixed_yaw and self.fixed_yaw_axis is 'Y-up'):
self.fixed_yaw = True
self.fixed_yaw_axis = 'Y-up'
self.set_orientation()
if ImGui.MenuItem("Fixed Z-up", "", self.fixed_yaw and self.fixed_yaw_axis is 'Z-up'):
self.fixed_yaw = True
self.fixed_yaw_axis = 'Z-up'
self.set_orientation()
ImGui.EndMenu()

if entity.hasSkeleton() and ImGui.MenuItem("Show Skeleton", None, entity.getDisplaySkeleton()):
entity.setDisplaySkeleton(not entity.getDisplaySkeleton())
ImGui.EndMenu()
Expand Down Expand Up @@ -657,8 +700,7 @@ def setup(self):

self.camman = OgreBites.CameraMan(camnode)
self.camman.setStyle(OgreBites.CS_ORBIT)
self.camman.setYawPitchDist(0, 0.3, diam)
self.camman.setFixedYaw(False)
self.camman.setYawPitchDist(0, self.gui.default_tilt, diam)

self.input_dispatcher = OgreBites.InputListenerChain([self.getImGuiInputListener(), self.camman, self])
self.addInputListener(self.input_dispatcher)
Expand Down

0 comments on commit c069059

Please sign in to comment.