-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.py
49 lines (40 loc) · 1.91 KB
/
render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import matplotlib
from render_utils import *
from render_utils import create_uniform_camera_poses
def create_uniform_camera_poses_circular(N, r=2):
mesh = geometry.TriangleMesh()
def rotation_matrix_y(degrees):
rad = degrees / 180 * np.pi
return np.array(
[[np.cos(rad), 0, -np.sin(rad)], [0, 1, 0], [np.sin(rad), 0, np.cos(rad)]]
)
camera_poses = []
for i in range(N):
frontvectors = np.array([0, 0, 1]) * r
frontvectors = rotation_matrix_y(360 / N * i) @ frontvectors
camera_pose = np.array(
pyrr.Matrix44.look_at(
eye=frontvectors, target=np.zeros(3), up=np.array([0.0, 1.0, 0])
).T
)
camera_pose = np.linalg.inv(np.array(camera_pose))
camera_poses.append(camera_pose)
return np.stack(camera_poses, 0)
def render_mesh(mesh, camera_poses=None, resolution=1024, radius=2.0, if_correct_normals=True, only_render_images=False, clean=False):
from render_utils import create_uniform_camera_poses
if not isinstance(camera_poses, np.ndarray):
camera_poses = create_uniform_camera_poses(radius)
render = Render(size=resolution, camera_poses=camera_poses)
triangle_ids, rendered_images, normal_maps, depth_images, p_images = render.render(
path=None, clean=clean, mesh=mesh, only_render_images=only_render_images,
if_correct_normals=if_correct_normals
)
return [triangle_ids, rendered_images, normal_maps, depth_images, p_images], camera_poses
def render_mesh_circular(mesh, N=10, resolution=1024, only_render_images=False):
camera_poses = create_uniform_camera_poses_circular(N)
render = Render(size=resolution, camera_poses=camera_poses)
triangle_ids, rendered_images, normal_maps, depth_images, p_images = render.render(
path=None, clean=False, mesh=mesh, only_render_images=only_render_images
)
return rendered_images