-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrender_utils.py
44 lines (30 loc) · 1.1 KB
/
render_utils.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
import pyrender as pyr
import trimesh
import numpy as np
import data.camera as camera
def load_camera(json_path):
cam = camera.Camera(json_path)
pycam = pyr.camera.IntrinsicsCamera(*cam.get_params())
return cam, pycam
def load_model(model_file):
fuze_trimesh = trimesh.load(model_file)
return pyr.Mesh.from_trimesh(fuze_trimesh)
def load_lights(config):
lights = []
for l in config["lighting"]:
l_type = l["type"]
intensity = l["intensity"] if "intensity" in l else 1e0
color = l["color"] if "color" in l else [255, 255, 255]
cone_angle = l["cone_angle"] if "cone_angle" in l else np.pi / 4
light = None
if l_type == 'directional':
light = pyr.DirectionalLight(color=color, intensity=intensity)
elif l_type == 'spot':
light = pyr.SpotLight(color=color, outerConeAngle=cone_angle, intensity=intensity)
if light:
lights.append(light)
return lights
def get_cam_pose(config):
pose = np.eye(4, dtype=np.float32)
pose[:3,3] = config["object"]["offset"]
return pose