File size: 2,609 Bytes
8554568
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
98
99
100
101
102
103
104
105
import numpy as np
import pytest

from pyrender import (DirectionalLight, SpotLight, PointLight, Texture,
                      PerspectiveCamera, OrthographicCamera)
from pyrender.constants import SHADOW_TEX_SZ


def test_directional_light():

    d = DirectionalLight()
    assert d.name is None
    assert np.all(d.color == 1.0)
    assert d.intensity == 1.0

    d.name = 'direc'
    with pytest.raises(ValueError):
        d.color = None
    with pytest.raises(TypeError):
        d.intensity = None

    d = DirectionalLight(color=[0.0, 0.0, 0.0])
    assert np.all(d.color == 0.0)

    d._generate_shadow_texture()
    st = d.shadow_texture
    assert isinstance(st, Texture)
    assert st.width == st.height == SHADOW_TEX_SZ

    sc = d._get_shadow_camera(scene_scale=5.0)
    assert isinstance(sc, OrthographicCamera)
    assert sc.xmag == sc.ymag == 5.0
    assert sc.znear == 0.01 * 5.0
    assert sc.zfar == 10 * 5.0


def test_spot_light():

    s = SpotLight()
    assert s.name is None
    assert np.all(s.color == 1.0)
    assert s.intensity == 1.0
    assert s.innerConeAngle == 0.0
    assert s.outerConeAngle == np.pi / 4.0
    assert s.range is None

    with pytest.raises(ValueError):
        s.range = -1.0

    with pytest.raises(ValueError):
        s.range = 0.0

    with pytest.raises(ValueError):
        s.innerConeAngle = -1.0

    with pytest.raises(ValueError):
        s.innerConeAngle = np.pi / 3.0

    with pytest.raises(ValueError):
        s.outerConeAngle = -1.0

    with pytest.raises(ValueError):
        s.outerConeAngle = np.pi

    s.range = 5.0
    s.outerConeAngle = np.pi / 2 - 0.05
    s.innerConeAngle = np.pi / 3
    s.innerConeAngle = 0.0
    s.outerConeAngle = np.pi / 4.0

    s._generate_shadow_texture()
    st = s.shadow_texture
    assert isinstance(st, Texture)
    assert st.width == st.height == SHADOW_TEX_SZ

    sc = s._get_shadow_camera(scene_scale=5.0)
    assert isinstance(sc, PerspectiveCamera)
    assert sc.znear == 0.01 * 5.0
    assert sc.zfar == 10 * 5.0
    assert sc.aspectRatio == 1.0
    assert np.allclose(sc.yfov, np.pi / 16.0 * 9.0)  # Plus pi / 16


def test_point_light():

    s = PointLight()
    assert s.name is None
    assert np.all(s.color == 1.0)
    assert s.intensity == 1.0
    assert s.range is None

    with pytest.raises(ValueError):
        s.range = -1.0

    with pytest.raises(ValueError):
        s.range = 0.0

    s.range = 5.0

    with pytest.raises(NotImplementedError):
        s._generate_shadow_texture()

    with pytest.raises(NotImplementedError):
        s._get_shadow_camera(scene_scale=5.0)