- Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathtest_render.py
More file actions
Latest commit
97 lines (78 loc) · 3.49 KB
/
Copy pathtest_render.py
File metadata and controls
97 lines (78 loc) · 3.49 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
importos
importthreeppastp
def_camera():
cam=tp.PerspectiveCamera(60, 200/150, 0.1, 100)
cam.position.set(0, 1.5, 4)
cam.look_at(0, 0, 0)
returncam
deftest_read_pixels_shape_and_dtype(renderer, lit_scene):
lit_scene.add(tp.Mesh(tp.BoxGeometry(), tp.MeshStandardMaterial()))
renderer.render(lit_scene, _camera())
img=renderer.read_pixels()
assertimg.shape== (150, 200, 3)
assertstr(img.dtype) =="uint8"
deftest_render_draws_something(renderer, lit_scene):
mat=tp.MeshStandardMaterial()
mat.color=0x44aa88
lit_scene.add(tp.Mesh(tp.SphereGeometry(1.0), mat))
renderer.render(lit_scene, _camera())
img=renderer.read_pixels()
assertint(img.max()) >int(img.min()), "rendered image is uniformly flat"
deftest_clear_color_affects_background(renderer):
scene=tp.Scene()
renderer.set_clear_color(0x000000)
renderer.render(scene, _camera())
dark=int(renderer.read_pixels().max())
renderer.set_clear_color(0xffffff)
renderer.render(scene, _camera())
light=int(renderer.read_pixels().min())
renderer.set_clear_color(0x202830) # restore session default
assertlight>dark
deftest_save_frame(renderer, lit_scene, tmp_path):
lit_scene.add(tp.Mesh(tp.BoxGeometry(), tp.MeshStandardMaterial()))
renderer.render(lit_scene, _camera())
out=tmp_path/"frame.png"
renderer.save_frame(str(out))
assertout.exists() andout.stat().st_size>0
deftest_tone_mapping_and_ibl(renderer, hdr_env):
# ToneMapping operator + RGBELoader + scene.environment in one render pass.
prev=renderer.tone_mapping
try:
renderer.tone_mapping=tp.ToneMapping.ACESFilmic
scene=tp.Scene()
scene.environment=tp.RGBELoader().load(hdr_env) # image-based lighting
mat=tp.MeshStandardMaterial()
mat.metalness, mat.roughness=1.0, 0.1
scene.add(tp.Mesh(tp.SphereGeometry(1.0), mat))
renderer.render(scene, _camera())
img=renderer.read_pixels()
assertint(img.max()) >int(img.min()) # the metal sphere is lit by the env
finally:
renderer.tone_mapping=prev
deftest_read_pixels_flip_orientation(renderer, lit_scene):
# flip=True (default) and flip=False should differ for a non-symmetric scene
mesh=tp.Mesh(tp.BoxGeometry(), tp.MeshStandardMaterial())
mesh.position.y=1.0# push content up so top/bottom differ
lit_scene.add(mesh)
renderer.render(lit_scene, _camera())
top_down=renderer.read_pixels(flip=True)
bottom_up=renderer.read_pixels(flip=False)
asserttop_down.shape==bottom_up.shape
assertnot (top_down==bottom_up).all()
deftest_on_window_resize_registers():
# Registering a resize callback must not raise. (No event fires for a headless
# canvas, but this pins the binding the interactive demos rely on.)
canvas=tp.Canvas("resize-reg", width=64, height=64, headless=True)
canvas.on_window_resize(lambdaw, h: None)
deftest_resize_handler_operations(renderer):
# The work an on_window_resize handler does: resize the renderer + fix the
# camera aspect. Restores the session renderer's size afterwards.
try:
renderer.set_size(320, 240)
assertrenderer.size() == (320, 240)
cam=tp.PerspectiveCamera(60, 1.0, 0.1, 100)
cam.aspect=320/240
cam.update_projection_matrix()
assertabs(cam.aspect-320/240) <1e-5
finally:
renderer.set_size(200, 150) # restore the shared fixture's size