Пример #1
0
 def stop(self):
     location = self._window.get_location() # returns a tuple? So convert to array
     
     Settings.set('DisplaySettings','location', [location[0], location[1]] )
     
     self._shutdown()
     pyglet.app.exit()
    def _save_configuration(self):
        print "Shutting down ConfigurationManager"
        # For each of the settings sections
        for section in Settings.get_sections():
            # if they don't yet have a section in the settings file, add one.
            if not section in self._config.sections():
                self._config.add_section(section)

            # Store their values
            for option in Settings.get_options(section):
                value = Settings.get(section, option)
                self._config.set(section, option, value )

                # print "Class value class: %s name: %s value: %s valuetype: %s" % ( section, option, value, value.__class__)

        # for class_def in self._settings_classes:
        #     class_name = class_def.__name__

        #     # if they don't yet have a section in the settings file, add one.
        #     if not class_name in self._config.sections():
        #         self._config.add_section(class_name)

        #     # Store their values
        #     for name, value in class_def.__dict__.iteritems():
        #         # Ignoring generated class properties
        #         if name[:2] != "__":
        #             self._config.set(class_name, name, value)
        #             print "Class value class: %s name: %s value: %s valuetype: %s" % ( class_name, name, value, value.__class__)

        with open(self._filepath, 'w') as configfile:
            self._config.write(configfile)
Пример #3
0
 def initialise_display(self, width, height, title="Pyglet Window"):
     self._width = width
     self._height = height
     self._title = title
 
     self._window = pyglet.window.Window(self._width, self._height, self._title, True, vsync=False)
     self._window.set_location(Settings.get('DisplaySettings','location')[0], Settings.get('DisplaySettings','location')[1])
     self._window.on_draw = self._draw
     
     # Configure the input object
     self._input = PygletInput(self._window)
     
     self._fps_display = pyglet.clock.ClockDisplay()
     
     Logger.Log("Initialised Pyglet window")
Пример #4
0
    def set_perspective(self):
        
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(self._fov, self._aspect, self._near_dist, self._far_dist)

        # If the transform for the camera has changed, then recalculate the frustrum
        if self.node_parent.transform.has_changed_this_frame:

            self._update_frustum = Settings.get('RenderSettings','update_frustum')

            if Input.get_key(Input.KEY_1):
                
                if not self._update_frustum:
                    self._update_frustum = True#not self._update_frustum
                    print "Frustum update enabled"
                    print "cam pos: %s" % self._transform.position

            if Input.get_key(Input.KEY_2):
                if self._update_frustum:
                    self._update_frustum = False
                    print "Frustum update disabled"
                    print "@ cam pos: %s" % self._transform.position

            if self._update_frustum:
                #self.calc_frustum()
                self.calc_frustum_lighthouse()

                self.update_projection_matrix()
            
            # show the frustum visualisation
            self._vis_frustum(not self._update_frustum)
Пример #5
0
    def __init__(self):
        self._current_framework = None
        
        selected_framework = Settings.get('FrameworkSettings','use_framework')

        if selected_framework == Frameworks.PYGAME:
            from epsilon.frameworks.pygameframework import PyGameFramework
            self._current_framework = PyGameFramework.get_instance()
            
        elif selected_framework == Frameworks.PYGLET:
            from epsilon.frameworks.pygletframework import PygletFramework
            self._current_framework = PygletFramework.get_instance()
Пример #6
0
    def draw_gizmos(self):
        
        if Settings.get('RenderSettings','grid'):
            self.draw_grid()

        # Gizmos are always on top
        glDisable(GL_DEPTH_TEST)

        gizmos = self._gizmo_manager.get_gizmo_root().transform.children
        for gizmo in gizmos:
            self._perform_draw_gizmos(gizmo.node)

        glEnable(GL_DEPTH_TEST)
Пример #7
0
 def setup_3d(self):
     
     setup_ok = False
     
     # Configure OpenGL Settings for drawing 3D
     glEnable(GL_DEPTH_TEST)
     glEnable(GL_POLYGON_SMOOTH)
     glEnable(GL_BLEND)
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
     glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
     
     glShadeModel(GL_SMOOTH)
     
     glCullFace(GL_BACK)
     glEnable(GL_CULL_FACE)
             
     glClearColor(*self._back_colour.get_gl_colour())
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
     
     if Settings.get('RenderSettings','wireframe'):
         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
     else:
         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
     
     # If the SceneManager instance hasn't been set
     if self._camera is None and self._scene_root is None:
         if not SceneManager.get_current_scene() is None:
             # If there isn't a camera set, get the active camera from the SceneManager
             if self._camera is None:
                 self._camera = SceneManager.get_current_scene().active_camera
             
             # Get the Scene Root
             if self._scene_root is None:    
                 self._scene_root = SceneManager.get_current_scene().root
     
     setup_ok = False
     if self._camera is None:
         Logger.Log("RENDER ERROR: Camera not found.")
     elif self._scene_root is None:
         Logger.Log("RENDER ERROR: Scene Root not found.")
     else:
         setup_ok = True
         
         # Activate the camera for rendering
         # set_projection, etc
         self._camera.activate()
     
     return setup_ok            
Пример #8
0
 def __init__(self):
     # Get the Pyglet window
     pyglet_framework = PygletFramework.get_instance() 
     self._window = pyglet_framework.window
     
     # Configure the Settings for the GUI
     theme_path = 'simplui/themes/pywidget'
     theme_path = os.path.join(os.path.dirname(__file__), theme_path)
     self._themes = [Theme(theme_path)]
     
     res = Settings.get("DisplaySettings","resolution")
     
     self._frame = Frame(self._themes[0], w=res[0], h=res[1])
     self._window.push_handlers(self._frame)
     
     # Add this UI Window to the UIManager
     UIManager.get_instance().add_ui(self)
Пример #9
0
    def draw(self):
        
        if self._visible and not self._culled:
        
            # Draw bounds
            if Settings.get('RenderSettings','draw_bounds'):
                if self._material:
                    self.node_parent.transform.bounds.colour = self._material.diffuse
                self.node_parent.transform.bounds.debug_draw()

            
            # Set Material
            # Every node _must_ have a material from now on.
            # The renderer is moving to entirely Shader based rendering and
            # as such all meshes cannot be rendered without a material 
            # definition
            if self._mesh and self._material:
                self._material.draw(self._mesh.glmesh, self.node_parent.transform)
Пример #10
0
    def __init__(self, width=None, 
                       height=None):
        NodeComponent.__init__(self)
        
        if width is None:
            width = Settings.get('DisplaySettings','resolution')[0]

        if height is None:
            height = Settings.get('DisplaySettings','resolution')[1]

        self._width = width
        self._height = height
        
        self._near_dist = 1.0
        self._near_width = 0.0
        self._near_height = 0.0
        self._far_dist = 1000.0
        self._far_width = 0.0
        self._far_height = 0.0
        
        self._aspect = self._width / float(self._height)
        #self._fov = 75.0
        self._fov = 60.0
        
        self._frustum_planes = []
        
        # Build Near/Far Planes
        self._calc_near_far()
        
        # Internal Stats
        self._num_inside = 0
        self._num_outside = 0
        self._num_intersect = 0
        
        # Debug
        self._update_frustum = True
        if Settings.has_option('RenderSettings','update_frustum'):
            self._update_frustum = Settings.get('RenderSettings','update_frustum')
        else:
            Settings.set('RenderSettings','update_frustum', self._update_frustum)
        
        self._top = None
        self._bottom = None
        self._left = None
        self._right = None

        self._verts = []

        self._gizmos = None

        self._projection_matrix = None
Пример #11
0
    def __init__(self):
        WindowRenderer.__init__(self)
        self._meshes = []
        
        self._has_initialised = False
        self._camera = None
        self._scene_root = None
        self._print_font = None
        self._shader_manager = None
        self._ui_manager = None
        
        # Render Settings
        self._rendersettings = RenderSettings.get_instance()

        if not Settings.has_option('RenderSettings','wireframe'):
            Settings.set('RenderSettings','wireframe', False)

        if not Settings.has_option('RenderSettings','grid'):
            Settings.set('RenderSettings','grid', False)

        if not Settings.has_option('RenderSettings','draw_bounds'):
            Settings.set('RenderSettings','draw_bounds', False)
        
        # Render Listener to allow access to settings
        self._listener = RenderListener(self)
        
        # For FPS Calc
        self._last_time = 0.0
        
        self._fatal_error_displayed = False
        
        # Back Colour
        self._back_colour = Preset.lightgrey

        # Nodes queued for rendering.
        self._render_queue = []
Пример #12
0
 def show_bounds_action(self, checkbox):
     #RenderSettings.set_setting("draw_bounds",checkbox.value)
     Settings.set('RenderSettings','draw_bounds', checkbox.value)
Пример #13
0
 def show_wireframe_action(self, checkbox):
     #RenderSettings.set_setting("wireframe",checkbox.value)
     Settings.set('RenderSettings','wireframe', checkbox.value)
Пример #14
0
 def update_frustum_action(self, checkbox):
     #RenderSettings.set_setting("update_frustum",checkbox.value)
     Settings.set('RenderSettings','update_frustum', checkbox.value)
Пример #15
0
    def _build_ui(self):
        
        stats_layout = FoldingBox('stats', content=
                        # each box needs a content layout
                        VLayout(children =
                        [
                            Label('0000.0 fps', name='fps_label'),
                            HLayout(children=
                            [
                                Label('MoUI:', hexpand=False),
                                Label('', name='mouse_over')
                            ]),
                            ])
                        )
        
        wf = False
        sg = True
        sb = False
        uf = True
        if Settings.has_option('RenderSettings','wireframe'):
            wf = Settings.get('RenderSettings','wireframe')

        if Settings.has_option('RenderSettings','grid'):
            sg = Settings.get('RenderSettings','grid')

        if Settings.has_option('RenderSettings','draw_bounds'):
            sb = Settings.get('RenderSettings','draw_bounds')

        if Settings.has_option('RenderSettings','update_frustum'):
            uf = Settings.get('RenderSettings','update_frustum')
        
        settings_layout = FoldingBox('settings', content=
                                VLayout(children=
                                [
                                    # a checkbox, note the action function is provided directly
                                    Checkbox('Show wireframe', h=100, action=self.show_wireframe_action, value=wf),
                                    Checkbox('Show Grid', h=100, action=self.show_grid_action,value=sg),
                                    Checkbox('Show Bounds', h=100, action=self.show_bounds_action,value=sb),
                                    Checkbox('Update Frustum', h=100, action=self.update_frustum_action,value=uf),
                                    Button('Quit', action=self.quit_action),
                                ])
                            )
        
        self._dialog = Dialogue('Inspector',
                                x=20,
                                y=550, 
                                content=
                                VLayout(autosizex=True, 
                                        hpadding=0, 
                                        children=
                                        [
                                         stats_layout,
                                         settings_layout
                                        ])
                                )
        
        # self._console = Dialogue('Python console', 
        self._console = Console('Python Console',
                                 x=20, 
                                 y=50,
                                 # content=VLayout(autosizex=True,
                                 #                 hpadding=0,
                                 #                 children=
                                 #                 [
                                 #                    Label('text\nsome\nthing',w=390, h=300),
                                 #                    TextInput(text=">>>", w=390)
                                 #                 ])
                                )
        
        
        self._frame.add(self._dialog)

        # Setup the UI console logger
        self._ui_log_listener = LogListener()
        self._ui_log_listener.set_log_func(self._console.new_line)
        self._frame.add(self._console)
        
        self._mouse_over_label = self._frame.get_element_by_name('mouse_over')
        self._fps_label = self._frame.get_element_by_name('fps_label')
Пример #16
0
    def __init__(self):
        # Load Configuration settings
        ConfigurationManager.load_configuration()

        #Start Logger
        method = Settings.get('LoggerSettings','method')
        filename = Settings.get('LoggerSettings','filename')
        to_console = Settings.get('LoggerSettings','log_to_console')
        Logger.Configure(method, filename, to_console)
        Logger.Log('Initialising Core Systems')
        
        # The order of initialisation in this function is extremely important
        # as it determines the order in which classes will receive events.
        # For instance it is important that input is processed
        
        # Start Event System so it can receive new listeners when the
        # classes below are initialised 
        self._event_manager = EventManager.get_instance()
        
        #Register Core Event Listener for detecting quit
        self._core_listener = CoreListener(False)
        
        # Initialise Time
        self._time = Time.get_instance()
        
        # Create a Scene
        self._scene = SceneManager.get_instance()
        self._scene.init()
        
        #Start Render System
        self._render_manager = RenderManager.get_instance()

        self._render_manager.init( Settings.get('DisplaySettings','resolution')[0],
                                   Settings.get('DisplaySettings','resolution')[1],
                                   Settings.get('DisplaySettings','window_title')
                                 )
        
        # Setup the framework callbacks
        self._framework = FrameworkManager.framework()
        self._framework.setup = self.setup
        self._framework.run_loop = self.update
        self._framework.on_draw = self._render_manager.draw
        self._framework.on_shutdown = self.shutdown
                
        # Setup Frame Start/End Events
        self._frame_start = FrameStarted()
        self._frame_end = FrameEnded()
        
        #Get the Texture Manager
        self._texture_manager = TextureManager.get_instance()
        
        # Start the ShaderManager
        self._shader_manager = ShaderManager.get_instance()
        
        # Start Scripting System
        self._script_manager = ScriptManager.get_instance()
        
        # Start the UI Manager and setup the MainUI
        self._ui_manager = UIManager.get_instance()
        self._main_ui = MainUI()
        
        # Start the GizmoManager system
        self._gizmo_manager = GizmoManager.get_instance()
        
        # Configure the ResourceManager
        self._resource_manager = ResourceManager.get_instance()
        # enable Image Loading
        self._resource_manager.add_handler(ImageResourceHandler())
        # enable Scene Loading
        self._resource_manager.add_handler(SceneResourceHandler())
        # enable Wavefront Obj Loading
        self._resource_manager.add_handler(WavefrontResourceHandler())
Пример #17
0
    def _load_configuration(self):
        if self._config_exists:
            # If read ok
            read_result = self._config.read(self._filepath)

            if len(read_result) > 0 and os.path.basename(read_result[0]) == self._filename:

                # Populate the classes with the appropriate values
                for section in self._config.sections():
                    #print "Reading Config Section: " + section
                    
                    for option in self._config.options(section):
                        
                        value_type = "str"

                        # If the section has been defined in the default settings
                        if Settings.has_section(section):
                            value_type = Settings.get(section, option).__class__.__name__
                        
                        # Else use a manual technique to figure this out.
                        else:
                            value = self._config.get(section, option)
                            value_type = self._check_type( value )
                            
                        if value_type == "str":
                            Settings.set(section, option, self._config.get(section, option) )

                        elif value_type == "int":
                            Settings.set(section, option, self._config.getint(section, option) )

                        elif value_type == "float":
                            Settings.set(section, option, self._config.getfloat(section, option) )

                        elif value_type == "bool":
                            Settings.set(section, option, self._config.getboolean(section, option) )

                        elif value_type == "list":
                            # If the item is a list get it as a string and process it as appropriate
                            # only lists containing homogeneous values are supported

                            list_value = self._config.get(section, option)

                            # If the section has already been defined in the default settings
                            if Settings.has_section(section):
                                #assuming that the list has more than one value...
                                list_type = Settings.get(section, option)[0].__class__.__name__

                            # Otherwise extract the type
                            else:
                                #Extract the first list element

                                # Default to a single element list
                                list_element = list_value[1:-1]

                                #Check for more and adjust as necessary
                                if list_value.find(',') > 0:
                                    list_element = list_value[1:list_value.find(',')]

                                # Get the element_type
                                list_type = self._check_type( list_element )

                            # In place of python's lack of a switch statement, defaulting to str if None
                            cast_func = { 'int' : int, 'float' : float, 'bool' : bool, 'str' : str, 'NoneType' : str }[list_type]

                            # Generate a list from the string
                            Settings.set(section, option, [cast_func(value) for value in list_value[1:-1].split(',')] )



                        value = self._config.get(section, option)
                        # print "Reading property class: %s name: %s value: %s" % ( section, option, str(value) )
                        # print "Class value class: %s name: %s value: %s valuetype: %s" % ( section, option, str(Settings.get(section, option)), Settings.get(section, option).__class__ )
        else:
            print "Can't find configuration file: %s " % self._filename
Пример #18
0
 def show_grid_action(self, checkbox):
     #RenderSettings.set_setting("grid",checkbox.value)
     Settings.set('RenderSettings','grid', checkbox.value)