def __init__(self):
     ResourceHandlerBase.__init__(self)
     
     self._scene_manager = SceneManager.get_instance()
     self._resource_type = ResourceType.SCENE
     self._filetypes = ["xml"]
     self._log = SceneResourceHandlerLog()
 def draw(self):
     if self._camera is None:
         self._camera = SceneManager.get_instance().current_scene.active_camera
     
     if not self._camera is None:
         pos = self._camera.node_parent.transform.position
         self._camera_pos_label.text = "x: %3.2f y: %3.2f z: %3.2f" % (pos.x, pos.y, pos.z) 
     self._frame.draw()
    def reset_camera(self, button):
        if self._camera is None:
            self._camera = SceneManager.get_instance().current_scene.active_camera

        if not self._camera is None:
            self._camera.node_parent.transform.position = Vector3(0, 1, -300)
            if hasattr( self._camera, 'look_at_position'):
                self._camera.node_parent.transform.rotation = Quaternion()
                self._camera.look_at_position = Vector3(0,0,0)
Exemple #4
0
 def on_frame_start(self):
     # Configure the scene lights
     
     lights = SceneManager.get_instance().current_scene.lights
     
     light_data = []
     
     # At this point I don't know enough about Shaders to know
     # what the behaviour of the Shader is if the light structure
     # isn't full in video memory
     
     # If there aren't enough lights in the scene to satisfy the shader
     # calculate how many 'empty' lights need to be created
     inc_count = self.MAX_LIGHTS
     inc_rm_count = 0
     if len(lights) < self.MAX_LIGHTS:
         inc_count = len(lights)
         inc_rm_count = self.MAX_LIGHTS - len(lights)
     
     # Set the scene's light properties inside the Shader
     for i in range(0, inc_count):
         light = lights[i]
         with light.ambient as am:
             light_data.append([am.r, am.g, am.b, am.a])
         with light.diffuse as dif:
             light_data.append([dif.r, dif.g, dif.b, dif.a])
         with light.specular as spec:
             light_data.append([spec.r, spec.g, spec.b, spec.a])
         with light.world_position as pos:
             light_data.append([pos.x, pos.y, pos.z, 1.0])
         #light_data.append([light.attenuation, 0.2, 0.5, 1.0])
         light_data.append([0.05, 0.02, 0.01, 0.0])
     
     # (If necessary) fill the video memory structure with empty lights 
     for i in range(0, inc_rm_count):
         light_data.append([0.0, 0.0, 0.0, 0.0])
         light_data.append([0.0, 0.0, 0.0, 0.0])
         light_data.append([0.0, 0.0, 0.0, 0.0])
         light_data.append([0.0, 0.0, 0.0, 0.0])
         light_data.append([0.0, 0.0, 0.0, 0.0])
         
     # create a numpy array for the data
     light_data_np = numpy.array(light_data, 'f')
     
     # Send the light data through to the Shader Video Memory
     self.use()
     glUniform4fv(self._uniform_locations['lights'], (self.MAX_LIGHTS * self.LIGHT_SIZE), light_data_np)
     
     # Set the Global ambient value
     u_loc = self._uniform_locations['Global_ambient']
     if self._global_ambient not in [None, -1]:
         with self._global_ambient as ga:
             glUniform4f(u_loc,ga.r,ga.g,ga.b,ga.a)
     self.disable()
    def update_sphere(self):
        
#        start = datetime.now()
        
        if (datetime.now() - self._last_time).total_seconds() > 0.1:
        
            if self._ui.track_camera:
            
                if self._camera is None:
                    self._camera = SceneManager.get_instance().current_scene.active_camera

                # Store the camera pos for access by the quad children
                self._camera_pos = self._camera.node_parent.transform.position - self.transform.position

                self._camera_pos_sc = CubeSphereMap.get_cube_coord(self._camera_pos.x, self._camera_pos.y, self._camera_pos.z) 
                
                self._line.line_to(self._camera_pos)


                if self._ui.planet_camera:
                    # Check if the camera has intersected the planet.
                    if self._camera_pos.magnitude() < (self._radius + self._max_height):
                        u = self._camera_pos_sc.x
                        v = self._camera_pos_sc.y
                        face = self._camera_pos_sc.face
                        self._camera.node_parent.transform.position = CubeSphereMap.get_sphere_position(u, v, face, (self._radius + self._max_height))

                
                # Reset the number of splits
                self._num_splits = 0
                #print "Resetting splits"
                
                # If the camera has moved a sufficient distance to warrant an update
    #            if self._last_camera_pos is None:
    #                self._last_camera_pos = self._camera_pos
    #            dist = self._last_camera_pos - self._camera_pos 
    #            if dist.magnitude() > 1.0:
                    
                # Calc the horizon
                altitude = self._camera_pos.magnitude()
                horizon_altitude = max([altitude-self.radius, self.max_height])
                self._horizon = math.sqrt(horizon_altitude * horizon_altitude + 2.0 * horizon_altitude * self._radius)
                
                if True:
                    # Update all of the sides of the cube/sphere
                    for child in self.transform.children:
                        if isinstance(child.node, SphereQuad):
                            child.node.update_surface()
                        
                self._last_camera_pos = self._camera_pos
                        
                self._last_time = datetime.now()
                
                # Update the UI with the camera pos
    #            self._ui.rel_camera_pos = self._camera_pos
    #            self._ui.camera_pos = self._camera_pos_sc

                if not self._camera_pos_sc is None:
                    pos = CubeSphereMap.get_sphere_vector(self._camera_pos_sc.x, self._camera_pos_sc.y, self._camera_pos_sc.face)
                    pos.normalize()
                    pos *= (self._radius / 1.9)
                    self._camera_gizmo.transform.position = pos
    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())