forked from ycjungSubhuman/DeepDeformable3DCaricatures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.py
More file actions
executable file
·73 lines (60 loc) · 2.25 KB
/
Copy pathrender.py
File metadata and controls
executable file
·73 lines (60 loc) · 2.25 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Obtain video that demainstrates the training result
"""
import igl
import tqdm
import trimesh
import os
os.environ['PYOPENGL_PLATFORM'] = 'egl'
import pyrender
import numpy as np
import time
import matplotlib.pyplot as plt
from PIL import Image
from scipy.spatial.transform import Rotation
def get_colors(input, vmin, vmax, colormap="viridis"):
colormap = plt.cm.get_cmap(colormap)
norm = plt.Normalize(vmin, vmax, clip=True)
return colormap(norm(input))[:, :3]
class MeshRenderer:
def __init__(self):
self.renderer = pyrender.OffscreenRenderer(512, 512)
def render_mesh(self, V, F):
material = pyrender.MetallicRoughnessMaterial(
baseColorFactor=np.array([1.0, 1.0, 1.0, 1.0]),
metallicFactor=0.0, roughnessFactor=0.4)
tm = trimesh.Trimesh(V, F)
mesh = pyrender.Mesh.from_trimesh(tm)
scene = pyrender.Scene(ambient_light=0.00*np.ones(3))
cam = pyrender.OrthographicCamera(1.00, 1.00)
pose = np.array([
[1.5, 0.0, 0.0, 0.0],
[0.0, 1.5, 0.0, 0.0],
[0.0, 0.0, 1.5, 2.0],
[0.0, 0.0, 0.0, 1.0]])
scene.add(mesh)
scene.add(cam, pose=pose)
light = pyrender.DirectionalLight(color=np.ones(3), intensity=3.0)
scene.add(light, pose=pose)
color, _ = self.renderer.render(scene)
return color
def render_mesh_tex(self, V, F, VT, texture):
material = pyrender.MetallicRoughnessMaterial(
metallicFactor=0.0, roughnessFactor=0.4,
emissiveTexture=texture)
tm = trimesh.Trimesh(V, F, process=False)
tm.visual = trimesh.visual.TextureVisuals(uv=VT, image=texture)
mesh = pyrender.Mesh.from_trimesh(tm, smooth=True)
scene = pyrender.Scene(ambient_light=0.00*np.ones(3))
cam = pyrender.OrthographicCamera(1.00, 1.00)
pose = np.array([
[1.5, 0.0, 0.0, 0.0],
[0.0, 1.5, 0.0, 0.0],
[0.0, 0.0, 1.5, 2.0],
[0.0, 0.0, 0.0, 1.0]])
scene.add(mesh)
scene.add(cam, pose=pose)
light = pyrender.DirectionalLight(color=np.ones(3), intensity=30.0)
scene.add(light, pose=pose)
color, _ = self.renderer.render(scene)
return color