fabiencasenave
commited on
Commit
•
ede25fc
1
Parent(s):
4d140b4
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# # Top of main python script
|
2 |
+
# import os
|
3 |
+
# os.environ['PYOPENGL_PLATFORM'] = 'egl'
|
4 |
+
|
5 |
+
# import pyrender
|
6 |
+
# import numpy as np
|
7 |
+
|
8 |
+
# r = pyrender.OffscreenRenderer(viewport_width=640,
|
9 |
+
# viewport_height=480,
|
10 |
+
# point_size=1.0)
|
11 |
+
|
12 |
+
# cam = pyrender.PerspectiveCamera(yfov=np.pi / 3.0, aspectRatio=1.414)
|
13 |
+
|
14 |
+
# scene = pyrender.Scene(ambient_light=[0.02, 0.02, 0.02],
|
15 |
+
# bg_color=[1.0, 1.0, 1.0])
|
16 |
+
|
17 |
+
# scene.add(cam, pose=np.eye(4))
|
18 |
+
# color, depth = r.render(scene)
|
19 |
+
|
20 |
+
# print(color)
|
21 |
+
# print(depth)
|
22 |
+
|
23 |
+
|
24 |
+
import os
|
25 |
+
# switch to "osmesa" or "egl" before loading pyrender
|
26 |
+
os.environ["PYOPENGL_PLATFORM"] = "egl"
|
27 |
+
|
28 |
+
import numpy as np
|
29 |
+
import pyrender
|
30 |
+
import trimesh
|
31 |
+
import matplotlib.pyplot as plt
|
32 |
+
|
33 |
+
# generate mesh
|
34 |
+
sphere = trimesh.creation.icosphere(subdivisions=4, radius=0.8)
|
35 |
+
sphere.vertices+=1e-2*np.random.randn(*sphere.vertices.shape)
|
36 |
+
mesh = pyrender.Mesh.from_trimesh(sphere, smooth=False)
|
37 |
+
|
38 |
+
# compose scene
|
39 |
+
scene = pyrender.Scene(ambient_light=[.1, .1, .3], bg_color=[0, 0, 0])
|
40 |
+
camera = pyrender.PerspectiveCamera( yfov=np.pi / 3.0)
|
41 |
+
light = pyrender.DirectionalLight(color=[1,1,1], intensity=2e3)
|
42 |
+
|
43 |
+
scene.add(mesh, pose= np.eye(4))
|
44 |
+
scene.add(light, pose= np.eye(4))
|
45 |
+
|
46 |
+
c = 2**-0.5
|
47 |
+
scene.add(camera, pose=[[ 1, 0, 0, 0],
|
48 |
+
[ 0, c, -c, -2],
|
49 |
+
[ 0, c, c, 2],
|
50 |
+
[ 0, 0, 0, 1]])
|
51 |
+
|
52 |
+
# render scene
|
53 |
+
r = pyrender.OffscreenRenderer(512, 512)
|
54 |
+
color, _ = r.render(scene)
|
55 |
+
|
56 |
+
plt.figure(figsize=(8,8))
|
57 |
+
plt.imshow(color)
|
58 |
+
|
59 |
+
plt.savefig("test.png")
|