Beispiel #1
0
        def render_mesh(sample_mesh, res=256, scale=1):

            if sample_mesh.shape[-1] != 3:
                sample_colours = sample_mesh[..., 3:]
            else:
                sample_colours = np.ones_like(sample_mesh) * [0, 0, 1]
            sample_mesh = sample_mesh[..., :3]

            sample_mesh = Homogeneous(
                dm.utils.rotation_matrix(np.deg2rad(90),
                                         [0, 0, -1])).apply(sample_mesh)
            sample_mesh = ColouredTriMesh(sample_mesh * scale * res / 2 +
                                          res / 2,
                                          trilist=trilist,
                                          colours=sample_colours)
            sample_mesh = lambertian_shading(sample_mesh, ambient_colour=0)
            store_path = Path(LOGDIR) / str(epoch)
            if not store_path.exists():
                store_path.mkdir()

            m3io.export_mesh(sample_mesh,
                             store_path / '{}.obj'.format(time.time()))

            mesh_img = rasterize_mesh(sample_mesh, [res, res])
            mesh_img = mesh_img.rotate_ccw_about_centre(180)

            return mesh_img.pixels_with_channels_at_back()
Beispiel #2
0
def render_mesh(sample_mesh,
                trilist=None,
                scale=128,
                offset=128,
                shape=[256, 256],
                store_path=None,
                return_image=True,
                **kwargs):

    if isinstance(sample_mesh, ColouredTriMesh):
        sample_mesh = sample_mesh
    elif isinstance(sample_mesh, TriMesh):
        sample_mesh = ColouredTriMesh(sample_mesh.points,
                                      trilist=sample_mesh.trilist)
        sample_mesh = lambertian_shading(sample_mesh, **kwargs)
    else:
        if sample_mesh.shape[-1] != 3:
            sample_colours = sample_mesh[..., 3:]
        else:
            sample_colours = np.ones_like(sample_mesh) * [0, 0, 1]

        sample_mesh = sample_mesh[..., :3]

        sample_mesh = ColouredTriMesh(sample_mesh * scale + offset,
                                      trilist=trilist,
                                      colours=sample_colours)

        sample_mesh = lambertian_shading(sample_mesh, **kwargs)

    mesh_img = rasterize_mesh(sample_mesh, shape)
    # mesh_img = mesh_img.rotate_ccw_about_centre(180)

    if store_path:
        if not store_path.exists():
            store_path.mkdir()

        m3io.export_mesh(sample_mesh,
                         store_path / '{}.obj'.format(time.time()))

    if return_image:
        return mesh_img

    return mesh_img.pixels_with_channels_at_back()
Beispiel #3
0
def test_export_mesh_ply_binary():
    with _temporary_path(".ply") as f:
        mio.export_mesh(test_obj, f, binary=True)
        assert os.path.exists(f)
Beispiel #4
0
def test_export_mesh_ply_ascii():
    with _temporary_path(".ply") as f:
        mio.export_mesh(test_obj, f)
        assert os.path.exists(f)
Beispiel #5
0
def test_export_mesh_obj(mock_open, exists):
    exists.return_value = False
    fake_path = "/fake/fake.obj"
    with open(fake_path) as f:
        type(f).name = PropertyMock(return_value=fake_path)
        mio.export_mesh(test_obj, f, extension="obj")
Beispiel #6
0
def export_shape_nicp(r, id_, mesh, extension='.ply'):
    export_pickle(mesh.as_vector(), path_shape_nicp(r, id_), overwrite=True)
    m3io.export_mesh(mesh,
                     path_shape_nicp_mesh(r, id_, extension=extension),
                     extension=extension,
                     overwrite=True)
Beispiel #7
0
def test_export_mesh_obj(mock_open, exists):
    exists.return_value = False
    fake_path = '/fake/fake.obj'
    with open(fake_path) as f:
        type(f).name = PropertyMock(return_value=fake_path)
        mio.export_mesh(test_obj, f, extension='obj')
Beispiel #8
0
def test_export_mesh_ply_binary():
    with _temporary_path('.ply') as f:
        mio.export_mesh(test_obj, f, binary=True)
        assert os.path.exists(f)
Beispiel #9
0
def test_export_mesh_ply_ascii():
    with _temporary_path('.ply') as f:
        mio.export_mesh(test_obj, f)
        assert os.path.exists(f)