Beispiel #1
0
def render_shaded_batch(v, f, vc, width, height, camera_f, camera_c, light_direction=np.zeros((3,)), light_color=np.ones((3,)),
                        bgcolor=np.zeros(3, dtype=np.float32),
                        num_channels=3, camera_t=np.zeros(3, dtype=np.float32),
                        camera_rt=np.zeros(3, dtype=np.float32), name=None):
    """
    v: (B x V x 3)
    f: (F x 3)
    vt: (VT x 3)
    ft: (FT x 3)
    """
    org_f = f
    vc, _ = split_vertices_by_face(vc, org_f)
    v, f = split_vertices_by_face(v, org_f)
    vn = vertex_normals_pre_split(v, f, name=None, static=False)

    if light_direction.ndim < v.ndim:
        light_direction = tf.tile(tf.cast(light_direction, tf.float32)[
                                  np.newaxis, ...], (tf.shape(v)[0], 1))

    if light_color.ndim < v.ndim:
        light_color = tf.tile(tf.cast(light_color, tf.float32)[
                              np.newaxis, ...], (tf.shape(v)[0], 1))

    if vc.ndim < v.ndim:
        vc = tf.tile(tf.cast(vc, tf.float32)[
                     np.newaxis, ...], (tf.shape(v)[0], 1, 1))

    # shaded_vc = diffuse_directional(tf.cast(vn, tf.double), tf.cast(vc, tf.float64), tf.cast(light_direction, tf.double),
    #                                 tf.cast(light_color, tf.double), double_sided=True, name=None)
    shaded_vc = diffuse_point(v, vn, vc, light_direction, light_color)

    im = render_colored_batch(v, f, shaded_vc, width, height, camera_f, camera_c, bgcolor=bgcolor,
                              num_channels=num_channels, camera_t=camera_t,
                              camera_rt=camera_rt, name=name)
    return im
Beispiel #2
0
def render_textured_batch(v_, f_, vt_, ft_, texture_image, width, height, camera_f, camera_c,
                          bgcolor=np.zeros(3, dtype=np.float32), camera_t=np.zeros(3, dtype=np.float32),
                          camera_rt=np.zeros(3, dtype=np.float32)):
    """
    v: (B x V x 3)
    f: (F x 3)
    vt: (VT x 3)
    ft: (FT x 3)
    texture_image: (H x W x 3)
    """
    # f = tf.cast(f, tf.int32)
    # ft = tf.cast(ft, tf.int32)
    v, f = split_vertices_by_face(v_, f_)
    vt, ft = split_vertices_by_face(tf.expand_dims(vt_, 0), ft_)

    uv = tf.concat([vt[0], tf.ones_like(vt[0, :, -1:])], axis=1)

    uv_image = render_colored_batch(v, f, uv, width, height, camera_f, camera_c, bgcolor,
                                    camera_t=camera_t, camera_rt=camera_rt)
    mask_image = render_colored_batch(v, f, tf.ones_like(uv), width, height, camera_f, camera_c,
                                      bgcolor=np.zeros(3, dtype=np.float32),
                                      camera_t=camera_t, camera_rt=camera_rt)

    idx_u = tf.round(uv_image[:, :, :, 0] *
                     tf.cast(tf.shape(texture_image)[0] - 1, tf.float32))
    idx_v = tf.round((1 - uv_image[:, :, :, 1]) *
                     tf.cast(tf.shape(texture_image)[1] - 1, tf.float32))

    image = tf.gather_nd(texture_image, tf.cast(
        tf.stack((idx_v, idx_u), axis=3), tf.int32))

    return image * mask_image + (1 - mask_image) * tf.reshape(bgcolor, (1, 1, 3))
def render_normals_batch(v,
                         f,
                         width,
                         height,
                         camera_f,
                         camera_c,
                         bgcolor=np.zeros(3, dtype=np.float32),
                         num_channels=3,
                         camera_t=np.zeros(3, dtype=np.float32),
                         camera_rt=np.zeros(3, dtype=np.float32),
                         name=None):
    org_f = f
    v, f = split_vertices_by_face(v, org_f)
    vn = vertex_normals_pre_split(v, f, name=None, static=False)

    im = render_colored_batch(v,
                              f,
                              vn,
                              width,
                              height,
                              camera_f,
                              camera_c,
                              bgcolor=bgcolor,
                              num_channels=num_channels,
                              camera_t=camera_t,
                              camera_rt=camera_rt,
                              name=name)

    return im