예제 #1
0
 def _configure_viewer(self):
     self._viewer.configure(
         platform=ngl.PLATFORM_AUTO,
         backend=misc.get_backend(self._backend),
         window=self._window,
         width=self._width,
         height=self._height,
         viewport=misc.get_viewport(self._width, self._height, self._aspect_ratio),
         swap_interval=1,
         samples=self._samples,
         clear_color=self._clear_color,
     )
예제 #2
0
 def set_scene(self, cfg):
     with QtCore.QMutexLocker(self._mutex):
         need_reconfigure = False
         self._scene = cfg['scene']
         self._framerate = cfg['framerate']
         self._duration = cfg['duration']
         self._aspect_ratio = cfg['aspect_ratio']
         if self._clear_color != cfg['clear_color']:
             self._clear_color = cfg['clear_color']
             need_reconfigure = True
         if self._samples != cfg['samples']:
             self._samples = cfg['samples']
             need_reconfigure = True
         if self._backend != cfg['backend']:
             self._backend = cfg['backend']
             need_reconfigure = True
         if need_reconfigure:
             self._viewer.set_scene(None)
             self._configure_viewer()
         else:
             viewport = misc.get_viewport(self._width, self._height, self._aspect_ratio)
             self._viewer.resize(self._width, self._height, viewport)
     self._push_event(lambda: self._set_scene())
    def _export(self, filename, width, height, extra_enc_args=None):
        fd_r, fd_w = os.pipe()

        cfg = self._get_scene_func()
        if not cfg:
            self.failed.emit("You didn't select any scene to export.")
            return False

        fps = cfg["framerate"]
        duration = cfg["duration"]
        samples = cfg["samples"]

        cmd = [
            # fmt: off
            "ffmpeg", "-r", "%d/%d" % fps,
            "-nostats", "-nostdin",
            "-f", "rawvideo",
            "-video_size", "%dx%d" % (width, height),
            "-pixel_format", "rgba",
            "-i", "pipe:%d" % fd_r
            # fmt: on
        ]
        if extra_enc_args:
            cmd += extra_enc_args
        cmd += ["-y", filename]

        reader = subprocess.Popen(cmd, pass_fds=(fd_r,))
        os.close(fd_r)

        capture_buffer = bytearray(width * height * 4)

        # node.gl context
        ctx = ngl.Context()
        ctx.configure(
            platform=ngl.PLATFORM_AUTO,
            backend=get_backend(cfg["backend"]),
            offscreen=1,
            width=width,
            height=height,
            viewport=get_viewport(width, height, cfg["aspect_ratio"]),
            samples=samples,
            clear_color=cfg["clear_color"],
            capture_buffer=capture_buffer,
        )
        ctx.set_scene_from_string(cfg["scene"])

        if self._time is not None:
            ctx.draw(self._time)
            os.write(fd_w, capture_buffer)
            self.progressed.emit(100)
        else:
            # Draw every frame
            nb_frame = int(duration * fps[0] / fps[1])
            for i in range(nb_frame):
                if self._cancelled:
                    break
                time = i * fps[1] / float(fps[0])
                ctx.draw(time)
                os.write(fd_w, capture_buffer)
                self.progressed.emit(i * 100 / nb_frame)
            self.progressed.emit(100)

        os.close(fd_w)
        reader.wait()
        return True
예제 #4
0
 def resize(self, width, height):
     with QtCore.QMutexLocker(self._mutex):
         self._width = width
         self._height = height
         viewport = misc.get_viewport(width, height, self._aspect_ratio)
         self._viewer.resize(width, height, viewport)