Skip to content
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
67 changes: 59 additions & 8 deletions ogre_mesh_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ def show_vertex_decl(decl):
ImGui.Text(str(e.getSource()))
ImGui.EndTable()

def config_option_combo(rs, option):
if ImGui.BeginCombo(option.name, option.currentValue):
for val in option.possibleValues:
is_selected = (option.currentValue == val)
if ImGui.Selectable(val, is_selected):
rs.setConfigOption(option.name, val)

ImGui.EndCombo()

def printable(str):
return str.encode("utf-8", "replace").decode()

Expand Down Expand Up @@ -103,23 +112,58 @@ def __init__(self, app):
Ogre.RenderTargetListener.__init__(self)
self.show_about = False
self.show_metrics = False
self.show_render_settings = False

self.app = app

self.highlighted = -1
self.orig_mat = None
self.logwin = app.logwin

self.selected_renderer = app.getRoot().getRenderSystem().getName()

def draw_about(self):
flags = ImGui.WindowFlags_AlwaysAutoResize
self.show_about = ImGui.Begin("About OgreMeshViewer", self.show_about, flags)[1]
ImGui.Text("By Pavel Rojtberg")
ImGui.Text("OgreMeshViewer is licensed under the MIT License, see LICENSE for more information.")
ImGui.Text("OgreMeshViewer is licensed under the MIT License.")
ImGui.Text("See LICENSE for more information.")
ImGui.Separator()
ImGui.BulletText("Ogre: %s" % Ogre.__version__)
ImGui.BulletText("ImGui: %s" % ImGui.GetVersion())
ImGui.End()

def draw_render_settings(self):
flags = ImGui.WindowFlags_AlwaysAutoResize
self.show_render_settings = ImGui.Begin("Renderer Settings", self.show_render_settings, flags)[1]

#https://ogrecave.github.io/ogre/api/latest/class_ogre_1_1_root.html
if ImGui.BeginCombo("Renderer", self.selected_renderer):
for renderer in app.getRoot().getAvailableRenderers():
rname = renderer.getName()
is_selected = (self.selected_renderer == rname)
if ImGui.Selectable(rname, is_selected):
self.selected_renderer = rname
ImGui.EndCombo()

ImGui.Separator()

rs = app.getRoot().getRenderSystemByName(self.selected_renderer)
config_options = rs.getConfigOptions()
#https://ogrecave.github.io/ogre/api/latest/struct_ogre_1_1_config_option.html
for config_option in config_options.values():
config_option_combo(rs, config_option)

ImGui.Separator()

if ImGui.Button("Apply & Restart"):
app.next_rendersystem = self.selected_renderer
app.restart = True
app.getRoot().queueEndRendering()


ImGui.End()

def draw_metrics(self):
win = self.app.getRenderWindow()
stats = win.getStatistics()
Expand Down Expand Up @@ -161,15 +205,16 @@ def preRenderTargetUpdate(self, evt):
return

if ImGui.BeginMainMenuBar():

if ImGui.BeginMenu("File"):
if ImGui.MenuItem("Select Renderer"):
self.app.getRoot().queueEndRendering()
self.app.restart = True
if ImGui.MenuItem("Renderer Settings"):
self.show_render_settings = True
if ImGui.MenuItem("Save Screenshot", "P"):
self.app._save_screenshot()
if ImGui.MenuItem("Quit", "Esc"):
self.app.getRoot().queueEndRendering()
ImGui.EndMenu()

if entity is not None and ImGui.BeginMenu("View"):
enode = entity.getParentSceneNode()
if ImGui.MenuItem("Show Axes", "A", self.app.axes_visible):
Expand Down Expand Up @@ -197,6 +242,9 @@ def preRenderTargetUpdate(self, evt):
if self.show_metrics:
self.draw_metrics()

if self.show_render_settings:
self.draw_render_settings()

self.logwin.draw()

if self.app.attach_node is not None:
Expand Down Expand Up @@ -331,6 +379,8 @@ def __init__(self, infile, rescfg):

self.active_controllers = {}

self.next_rendersystem = None

def keyPressed(self, evt):
if evt.keysym.sym == OgreBites.SDLK_ESCAPE:
self.getRoot().queueEndRendering()
Expand Down Expand Up @@ -375,6 +425,8 @@ def _save_screenshot(self):
name = os.path.splitext(self.filename)[0]
outpath = os.path.join(self.filedir, "screenshot_{}_".format(name))

Ogre.LogManager.getSingleton().logMessage("Screenshot saved to folder: %s" % self.filedir)

self.cam.getViewport().setOverlaysEnabled(False)
self.getRoot().renderOneFrame()
self.getRenderWindow().writeContentsToTimestampedFile(outpath, ".png")
Expand Down Expand Up @@ -418,6 +470,9 @@ def loadResources(self):
rgm.initialiseResourceGroup(Ogre.RGN_DEFAULT)

def setup(self):
if self.next_rendersystem:
self.getRoot().setRenderSystem(self.getRoot().getRenderSystemByName(self.next_rendersystem))

OgreBites.ApplicationContext.setup(self)
self.addInputListener(self)

Expand Down Expand Up @@ -520,10 +575,6 @@ def shutdown(self):

self.entity = None
self.axes = None
if self.restart:
# make sure empty rendersystem is written
self.getRoot().shutdown()
self.getRoot().setRenderSystem(None)


if __name__ == "__main__":
Expand Down