示例#1
0
def show_models():
    TRANSITION_TIME = 2
    viewer = MeshRenderer()

    while True:
        for sample_index in range(SAMPLE_COUNT):
            try:
                start = time.perf_counter()
                end = start + TRANSITION_TIME
                while time.perf_counter() < end:
                    progress = min(
                        (time.perf_counter() - start) / TRANSITION_TIME, 1.0)
                    if ROTATE_MODEL:
                        viewer.rotation = (
                            147 +
                            (sample_index + progress) / SAMPLE_COUNT * 360 * 6,
                            40)
                    code = torch.tensor(spline(float(sample_index) + progress),
                                        dtype=torch.float32,
                                        device=device)
                    viewer.set_mesh(
                        sdf_net.get_mesh(code,
                                         voxel_resolution=64,
                                         sphere_only=False,
                                         level=SURFACE_LEVEL))

            except KeyboardInterrupt:
                viewer.stop()
                return
示例#2
0
def create_image_sequence():
    ensure_directory('images')
    frame_index = 0
    viewer = MeshRenderer(size=1080, start_thread=False)
    progress_bar = tqdm(total=SAMPLE_COUNT * TRANSITION_FRAMES)

    for sample_index in range(SAMPLE_COUNT):
        for step in range(TRANSITION_FRAMES):
            code = torch.tensor(
                spline(float(sample_index) + step / TRANSITION_FRAMES),
                dtype=torch.float32,
                device=device)
            if ROTATE_MODEL:
                viewer.rotation = (
                    147 + frame_index /
                    (SAMPLE_COUNT * TRANSITION_FRAMES) * 360 * 6, 40)
            viewer.set_mesh(
                sdf_net.get_mesh(code,
                                 voxel_resolution=128,
                                 sphere_only=False,
                                 level=SURFACE_LEVEL))
            image = viewer.get_image(flip_red_blue=True)
            cv2.imwrite("images/frame-{:05d}.png".format(frame_index), image)
            frame_index += 1
            progress_bar.update()

    print("\n\nUse this command to create a video:\n")
    print(
        'ffmpeg -framerate 30 -i images/frame-%05d.png -c:v libx264 -profile:v high -crf 19 -pix_fmt yuv420p video.mp4'
    )