Esempio n. 1
0
    def get(self, path, create=False, **kwargs) -> Scene:
        """
        Get or create a scene object.
        This may return an empty object that will be filled during load
        based on the ``create`` parameter.

        :param path: Path to the scene file(s)
        :param create: (bool) Create an empty scene object if it doesn't exist
        :return: Scene object
        """
        # Figure out what scene loader class should be used
        for loader_name in settings.SCENE_LOADERS:
            loader_cls = import_string(loader_name)
            if loader_cls.supports_file(path):
                if path not in self.scenes:
                    loader_cls = import_string(loader_name)
                    self.scenes[path] = Scene(path,
                                              loader=loader_cls(path),
                                              **kwargs)
                break
        else:
            raise ImproperlyConfigured(
                "Scene {} has no loader class registered. Check settings.SCENE_LOADERS"
            )

        return self.scenes[path]
Esempio n. 2
0
def init(window=None, project=None, timeline=None):
    """
    Initialize, load and run

    :param manager: The effect manager to use
    """
    from demosys.effects.registry import Effect
    from demosys.scene import camera

    window.timeline = timeline

    # Inject attributes into the base Effect class
    setattr(Effect, '_window', window)
    setattr(Effect, '_ctx', window.ctx)
    setattr(Effect, '_project', project)

    # Set up the default system camera
    window.sys_camera = camera.SystemCamera(aspect=window.aspect_ratio,
                                            fov=60.0,
                                            near=1,
                                            far=1000)
    setattr(Effect, '_sys_camera', window.sys_camera)

    print("Loading started at", time.time())
    project.load()

    # Initialize timer
    timer_cls = import_string(settings.TIMER)
    window.timer = timer_cls()
    window.timer.start()
Esempio n. 3
0
def create_window():
    window_cls_name = settings.WINDOW.get('class',
                                          'demosys.context.glfw.GLFW_Window')
    print("window class", window_cls_name)
    window_cls = module_loading.import_string(window_cls_name)
    window = window_cls()
    window.print_context_info()
    return window
Esempio n. 4
0
def create_window():
    if window(raise_on_error=False):
        raise RuntimeError("Attempting to create window twice")

    window_cls_name = settings.WINDOW.get('class',
                                          'demosys.context.pyqt.Window')
    window_cls = import_string(window_cls_name)
    new_window = window_cls()
    new_window.print_context_info()
    return new_window
Esempio n. 5
0
def get_finder(import_path):
    """
    Get a finder class from an import path.
    Raises ``demosys.core.exceptions.ImproperlyConfigured`` if the finder is not found.
    This function uses an lru cache.

    :param import_path: string representing an import path
    :return: An instance of the finder
    """
    Finder = import_string(import_path)
    if not issubclass(Finder, finders.BaseFileSystemFinder):
        raise ImproperlyConfigured('Finder {} is not a subclass of core.finders.FileSystemFinder'.format(import_path))
    return Finder()
Esempio n. 6
0
    def handle(self, *args, **options):
        demosys.setup()
        manager_path = getattr(settings, 'EFFECT_MANAGER')
        if not manager_path:
            raise ImproperlyConfigured(
                "EFFECT_MANAGER not properly configured in settings")
        print(manager_path)
        try:
            manager_cls = import_string(manager_path)
        except ImportError as e:
            raise ImproperlyConfigured(
                "EFFECT_MANAGER '{}' failed to initialize: {}".format(
                    manager_path, e))

        manager = manager_cls()
        demosys.run(manager=manager)
Esempio n. 7
0
def run(manager=None):
    """
    Initialize, load and run

    :param manager: The effect manager to use
    """
    window = create_window()
    window.manager = manager

    print("Loader started at", time.time())

    # Inject attributes into the base Effect class
    setattr(Effect, '_window_width', window.buffer_width)
    setattr(Effect, '_window_height', window.buffer_height)
    setattr(Effect, '_window_aspect', window.aspect_ratio)
    setattr(Effect, '_ctx', window.ctx)

    # Set up the default system camera
    window.sys_camera = camera.SystemCamera(aspect=window.aspect_ratio,
                                            fov=60.0,
                                            near=1,
                                            far=1000)
    setattr(Effect, '_sys_camera', window.sys_camera)

    # Initialize Effects
    if not manager.pre_load():
        return

    # Load resources
    num_resources = resources.count()
    print("Loading {} resources".format(num_resources))
    window.resources = resources
    resources.load()

    # Post-Load actions for effects
    if not manager.post_load():
        return

    # Initialize timer
    timer_cls = module_loading.import_string(settings.TIMER)
    window.timer = timer_cls()
    window.timer.start()

    # Main loop
    frame_time = 60.0 / 1000.0
    time_start = time.time()
    prev_time = window.timer.get_time()

    while not window.should_close():
        current_time = window.timer.get_time()

        window.use()
        window.clear()
        window.draw(current_time, frame_time)
        window.swap_buffers()

        frame_time = current_time - prev_time
        prev_time = current_time

    duration_timer = window.timer.stop()
    duration = time.time() - time_start

    window.terminate()

    if duration > 0:
        fps = round(window.frames / duration, 2)
        print("Duration: {}s rendering {} frames at {} fps".format(
            duration, window.frames, fps))
        print("Timeline duration:", duration_timer)
Esempio n. 8
0
 def __init__(self):
     super().__init__()
     self._loaders = [
         import_string(loader) for loader in settings.PROGRAM_LOADERS
     ]
Esempio n. 9
0
def run(manager=None):
    """
    Initialize, load and run

    :param manager: The effect manager to use
    """
    global MANAGER
    MANAGER = manager

    global WINDOW
    WINDOW = Window()

    fbo.WINDOW_FBO = fbo.WindowFBO(WINDOW)

    print("Loader started at", glfw.get_time())

    # Inject attributes into the base Effect class
    Effect.window_width = WINDOW.buffer_width
    Effect.window_height = WINDOW.buffer_height
    Effect.window_aspect = WINDOW.aspect_ratio

    # Set up the default system camera
    global CAMERA
    CAMERA = camera.SystemCamera(aspect=WINDOW.aspect_ratio,
                                 fov=60.0,
                                 near=1,
                                 far=1000)
    Effect.sys_camera = CAMERA

    # Initialize Effects
    if not manager.pre_load():
        return

    # Load resources
    num_resources = resources.count()
    print("Loading {} resources".format(num_resources))
    resources.load()

    # Post-Load actions for effects
    if not manager.post_load():
        return

    glfw.set_key_callback(WINDOW.window, key_event_callback)
    glfw.set_cursor_pos_callback(WINDOW.window, mouse_event_callback)
    glfw.set_window_size_callback(WINDOW.window, window_resize_callback)

    # Initialize timer
    global TIMER
    timer_cls = module_loading.import_string(settings.TIMER)
    TIMER = timer_cls()
    TIMER.start()

    # Main loop
    frames, ft = 0, 0
    prev_time = TIMER.get_time()
    time_start = glfw.get_time()
    while not WINDOW.should_close():
        # Immediately get control of the current time
        t = TIMER.get_time()

        # Set the viewport as FBOs will change the values
        GL.glViewport(0, 0, WINDOW.buffer_width, WINDOW.buffer_height)

        # Clear the buffer
        GL.glClearColor(0.0, 0.0, 0.0, 0.0)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT
                   | GL.GL_STENCIL_BUFFER_BIT)

        # Tell the manager to draw stuff
        manager.draw(t, ft, fbo.WINDOW_FBO)

        # Swap buffers and deal with events and statistics
        WINDOW.swap_buffers()
        WINDOW.poll_events()
        frames += 1
        ft = t - prev_time
        prev_time = t

    duration_timer = TIMER.stop()
    duration = glfw.get_time() - time_start
    if duration > 0:
        fps = round(frames / duration, 2)
        print("Duration: {}s rendering {} frames at {} fps".format(
            duration, frames, fps))
        print("Timeline duration:", duration_timer)
Esempio n. 10
0
 def create_timeline(self, project):
     timeline.instance = import_string(settings.TIMELINE)(project)
     return timeline.instance
Esempio n. 11
0
 def create_project(self, *args, **kwargs):
     project.instance = import_string(settings.PROJECT)(*args, **kwargs)
     return project.instance