예제 #1
0
    def frameStarted(self, evt):
        OgreBites.ApplicationContext.frameStarted(self, evt)

        if not self.cam.getViewport().getOverlaysEnabled():
            return True

        self.time = evt.timeSinceLastFrame
        self.Player.actualiza(self.time)

        OgreBites.ApplicationContext.frameStarted(self, evt)

        OgreOverlay.ImGuiOverlay.NewFrame(evt)

        if OgreOverlay.BeginMainMenuBar():

            if OgreOverlay.BeginMenu("Help"):
                if OgreOverlay.MenuItem("About"):
                    self.show_about = True
                OgreOverlay.EndMenu()

            OgreOverlay.EndMainMenuBar()

        if self.show_about:
            self.draw_about()

        return True
예제 #2
0
    def frameStarted(self, evt):
        OgreBites.ApplicationContext.frameStarted(self, evt)

        if not self.cam.getViewport().getOverlaysEnabled():
            return True

        OgreOverlay.ImGuiOverlay.NewFrame(evt)

        if OgreOverlay.BeginMainMenuBar():
            if OgreOverlay.BeginMenu("File"):
                if OgreOverlay.MenuItem("Select Renderer"):
                    self.getRoot().queueEndRendering()
                    self.restart = True
                if OgreOverlay.MenuItem("Save Screenshot", "P"):
                    self._save_screenshot()
                if OgreOverlay.MenuItem("Quit", "Esc"):
                    self.getRoot().queueEndRendering()
                OgreOverlay.EndMenu()
            if OgreOverlay.BeginMenu("View"):
                enode = self.entity.getParentSceneNode()
                if OgreOverlay.MenuItem("Show Axes", "A",
                                        self.axes.getVisible()):
                    self._toggle_axes()
                if OgreOverlay.MenuItem("Show Bounding Box", "B",
                                        enode.getShowBoundingBox()):
                    self._toggle_bbox()
                if self.entity.hasSkeleton() and OgreOverlay.MenuItem(
                        "Show Skeleton", None,
                        self.entity.getDisplaySkeleton()):
                    self.entity.setDisplaySkeleton(
                        not self.entity.getDisplaySkeleton())
                OgreOverlay.EndMenu()

            if OgreOverlay.BeginMenu("Help"):
                if OgreOverlay.MenuItem("Metrics", None, self.show_metrics):
                    self.show_metrics = not self.show_metrics
                if OgreOverlay.MenuItem("About"):
                    self.show_about = True
                OgreOverlay.EndMenu()

            OgreOverlay.EndMainMenuBar()

        if self.show_about:
            self.draw_about()

        if self.show_metrics:
            self.draw_metrics()

        # Mesh Info Sidebar
        mesh = Ogre.MeshManager.getSingleton().getByName(self.meshname)

        OgreOverlay.SetNextWindowPos(OgreOverlay.ImVec2(0, 30))
        flags = OgreOverlay.ImGuiWindowFlags_NoTitleBar \
              | OgreOverlay.ImGuiWindowFlags_NoMove
        OgreOverlay.Begin("MeshProps", None, flags)
        OgreOverlay.Text(self.meshname)

        highlight = -1

        if OgreOverlay.CollapsingHeader("Geometry"):
            if mesh.sharedVertexData:
                if OgreOverlay.TreeNode("Shared Vertices: {}".format(
                        mesh.sharedVertexData.vertexCount)):
                    show_vertex_decl(mesh.sharedVertexData.vertexDeclaration)
                    TreePop()
            else:
                OgreOverlay.Text("Shared Vertices: None")

            for i, sm in enumerate(mesh.getSubMeshes()):
                submesh_details = OgreOverlay.TreeNode("SubMesh #{}".format(i))
                if OgreOverlay.IsItemHovered():
                    highlight = i

                if submesh_details:
                    OgreOverlay.BulletText("Material: {}".format(
                        sm.getMaterialName()))
                    if sm.indexData:
                        bits = sm.indexData.indexBuffer.getIndexSize() * 8
                        OgreOverlay.BulletText("Indices: {} ({} bit)".format(
                            sm.indexData.indexCount, bits))
                    else:
                        OgreOverlay.BulletText("Indices: None")

                    if sm.vertexData:
                        if OgreOverlay.TreeNode("Vertices: {}".format(
                                sm.vertexData.vertexCount)):
                            show_vertex_decl(sm.vertexData.vertexDeclaration)
                            OgreOverlay.TreePop()
                    else:
                        OgreOverlay.BulletText("Vertices: shared")
                    OgreOverlay.TreePop()

        if self.highlighted > -1:
            self.entity.getSubEntities()[self.highlighted].setMaterialName(
                self.orig_mat)

        if highlight > -1:
            self.orig_mat = self.entity.getSubEntities(
            )[highlight].getMaterial().getName()
            self.entity.getSubEntities()[highlight].setMaterial(
                self.highlight_mat)
            self.highlighted = highlight

        animations = self.entity.getAllAnimationStates()
        if animations is not None and OgreOverlay.CollapsingHeader(
                "Animations"):
            controller_mgr = Ogre.ControllerManager.getSingleton()

            if self.entity.hasSkeleton():
                OgreOverlay.Text("Skeleton: {}".format(mesh.getSkeletonName()))
                # self.entity.setUpdateBoundingBoxFromSkeleton(True)
            if mesh.hasVertexAnimation():
                OgreOverlay.Text("Vertex Animations")

            for name, astate in animations.getAnimationStates().items():
                if OgreOverlay.TreeNode(name):
                    if astate.getEnabled():
                        if OgreOverlay.Button("Reset"):
                            astate.setEnabled(False)
                            astate.setTimePosition(0)
                            if name in self.active_controllers:
                                controller_mgr.destroyController(
                                    self.active_controllers[name])
                    elif OgreOverlay.Button("Play"):
                        astate.setEnabled(True)
                        self.active_controllers[
                            name] = controller_mgr.createFrameTimePassthroughController(
                                Ogre.AnimationStateControllerValue.create(
                                    astate, True))
                    changed = False
                    if astate.getLength() > 0:
                        OgreOverlay.SameLine()
                        changed, value = OgreOverlay.SliderFloat(
                            "", astate.getTimePosition(), 0,
                            astate.getLength(), "%.3fs")
                    if changed:
                        astate.setEnabled(True)
                        astate.setTimePosition(value)
                    OgreOverlay.TreePop()

        if OgreOverlay.CollapsingHeader("Bounds"):
            bounds = mesh.getBounds()
            s = bounds.getSize()
            OgreOverlay.BulletText("Size: {:.2f}, {:.2f}, {:.2f}".format(
                s[0], s[1], s[2]))
            c = bounds.getCenter()
            OgreOverlay.BulletText("Center: {:.2f}, {:.2f}, {:.2f}".format(
                c[0], c[1], c[2]))
            OgreOverlay.BulletText("Radius: {:.2f}".format(
                mesh.getBoundingSphereRadius()))

        OgreOverlay.End()

        # ShowDemoWindow()

        return True
예제 #3
0
    def preRenderTargetUpdate(self, evt):
        if not self.app.cam.getViewport().getOverlaysEnabled():
            return

        Ogre.Overlay.ImGuiOverlay.NewFrame()

        entity = self.app.entity

        if entity is None:
            self.draw_loading()
            return

        if ImGui.BeginMainMenuBar():
            if ImGui.BeginMenu("File"):
                if ImGui.MenuItem("Select Renderer"):
                    self.app.getRoot().queueEndRendering()
                    self.app.restart = True
                if ImGui.MenuItem("Save Screenshot", "P"):
                    self.app._save_screenshot()
                if ImGui.MenuItem("Quit", "Esc"):
                    self.app.getRoot().queueEndRendering()
                ImGui.EndMenu()
            if ImGui.BeginMenu("View"):
                enode = entity.getParentSceneNode()
                if ImGui.MenuItem("Show Axes", "A", self.app.axes_visible):
                    self.app._toggle_axes()
                if ImGui.MenuItem("Show Bounding Box", "B",
                                  enode.getShowBoundingBox()):
                    self.app._toggle_bbox()
                if entity.hasSkeleton() and ImGui.MenuItem(
                        "Show Skeleton", None, entity.getDisplaySkeleton()):
                    entity.setDisplaySkeleton(not entity.getDisplaySkeleton())
                ImGui.EndMenu()

            if ImGui.BeginMenu("Help"):
                if ImGui.MenuItem("Metrics", None, self.show_metrics):
                    self.show_metrics = not self.show_metrics
                if ImGui.MenuItem("Log"):
                    self.logwin.show = True
                if ImGui.MenuItem("About"):
                    self.show_about = True
                ImGui.EndMenu()

            ImGui.EndMainMenuBar()

        if self.show_about:
            self.draw_about()

        if self.show_metrics:
            self.draw_metrics()

        # Mesh Info Sidebar
        mesh = entity.getMesh()

        ImGui.SetNextWindowSize(ImGui.ImVec2(300, 500),
                                ImGui.ImGuiCond_FirstUseEver)
        ImGui.SetNextWindowPos(ImGui.ImVec2(0, 30))
        flags = ImGui.ImGuiWindowFlags_NoTitleBar | ImGui.ImGuiWindowFlags_NoMove
        ImGui.Begin("MeshProps", None, flags)
        ImGui.Text(mesh.getName())

        highlight = -1

        if ImGui.CollapsingHeader("Geometry"):
            if mesh.sharedVertexData:
                if ImGui.TreeNode("Shared Vertices: {}".format(
                        mesh.sharedVertexData.vertexCount)):
                    show_vertex_decl(mesh.sharedVertexData.vertexDeclaration)
                    ImGui.TreePop()
            else:
                ImGui.Text("Shared Vertices: None")

            for i, sm in enumerate(mesh.getSubMeshes()):
                submesh_details = ImGui.TreeNode("SubMesh #{}".format(i))
                if ImGui.IsItemHovered():
                    highlight = i

                if submesh_details:
                    ImGui.BulletText("Material: {}".format(
                        sm.getMaterialName()))
                    op = ROP2STR[
                        sm.
                        operationType] if sm.operationType <= 6 else "Control Points"
                    ImGui.BulletText("Operation: {}".format(op))

                    if sm.indexData.indexCount:
                        bits = sm.indexData.indexBuffer.getIndexSize() * 8
                        ImGui.BulletText("Indices: {} ({} bit)".format(
                            sm.indexData.indexCount, bits))
                    else:
                        ImGui.BulletText("Indices: None")

                    if sm.vertexData:
                        if ImGui.TreeNode("Vertices: {}".format(
                                sm.vertexData.vertexCount)):
                            show_vertex_decl(sm.vertexData.vertexDeclaration)
                            ImGui.TreePop()
                    else:
                        ImGui.BulletText("Vertices: shared")
                    ImGui.TreePop()

        if self.highlighted > -1:
            entity.getSubEntities()[self.highlighted].setMaterialName(
                self.orig_mat)

        if highlight > -1:
            self.orig_mat = entity.getSubEntities()[highlight].getMaterial(
            ).getName()
            entity.getSubEntities()[highlight].setMaterial(
                self.app.highlight_mat)
            self.highlighted = highlight

        animations = entity.getAllAnimationStates()
        if animations is not None and ImGui.CollapsingHeader("Animations"):
            controller_mgr = Ogre.ControllerManager.getSingleton()

            if entity.hasSkeleton():
                ImGui.Text("Skeleton: {}".format(mesh.getSkeletonName()))
                # self.entity.setUpdateBoundingBoxFromSkeleton(True)
            if mesh.hasVertexAnimation():
                ImGui.Text("Vertex Animations")

            for name, astate in animations.getAnimationStates().items():
                if ImGui.TreeNode(name):
                    if astate.getEnabled():
                        if ImGui.Button("Reset"):
                            astate.setEnabled(False)
                            astate.setTimePosition(0)
                            if name in self.app.active_controllers:
                                controller_mgr.destroyController(
                                    self.app.active_controllers[name])
                    elif ImGui.Button("Play"):
                        astate.setEnabled(True)
                        self.app.active_controllers[
                            name] = controller_mgr.createFrameTimePassthroughController(
                                Ogre.AnimationStateControllerValue.create(
                                    astate, True))
                    changed = False
                    if astate.getLength() > 0:
                        ImGui.SameLine()
                        changed, value = ImGui.SliderFloat(
                            "", astate.getTimePosition(), 0,
                            astate.getLength(), "%.3fs")
                    if changed:
                        astate.setEnabled(True)
                        astate.setTimePosition(value)
                    ImGui.TreePop()

        lod_count = mesh.getNumLodLevels()
        if lod_count > 1 and ImGui.CollapsingHeader("LOD levels"):
            entity.setMeshLodBias(1)  # reset LOD override
            strategy = mesh.getLodStrategy().getName()
            curr_idx = entity.getCurrentLodIndex()
            ImGui.Text("Strategy: {}".format(strategy))
            for i in range(lod_count):
                txt = "Base Mesh" if i == 0 else "Level {}: {:.2f}".format(
                    i,
                    mesh.getLodLevel(i).userValue)
                ImGui.Bullet()
                ImGui.Selectable(txt, i == curr_idx)
                if ImGui.IsItemHovered():
                    # force this LOD level
                    entity.setMeshLodBias(1, i, i)

        if ImGui.CollapsingHeader("Bounds"):
            bounds = mesh.getBounds()
            s = bounds.getSize()
            ImGui.BulletText("Size: {:.2f}, {:.2f}, {:.2f}".format(
                s[0], s[1], s[2]))
            c = bounds.getCenter()
            ImGui.BulletText("Center: {:.2f}, {:.2f}, {:.2f}".format(
                c[0], c[1], c[2]))
            ImGui.BulletText("Radius: {:.2f}".format(
                mesh.getBoundingSphereRadius()))

        ImGui.End()

        self.logwin.draw()