Team Ai
Apppublic

OpenMotionLab/MotionGPT

sourceHugging Facemitupdated 1y agoView on Hugging Face
118likes
test_lights.py105 linesDownload Raw Back to unit
1import numpy as np2import pytest3 4from pyrender import (DirectionalLight, SpotLight, PointLight, Texture,5                      PerspectiveCamera, OrthographicCamera)6from pyrender.constants import SHADOW_TEX_SZ7 8 9def test_directional_light():10 11    d = DirectionalLight()12    assert d.name is None13    assert np.all(d.color == 1.0)14    assert d.intensity == 1.015 16    d.name = 'direc'17    with pytest.raises(ValueError):18        d.color = None19    with pytest.raises(TypeError):20        d.intensity = None21 22    d = DirectionalLight(color=[0.0, 0.0, 0.0])23    assert np.all(d.color == 0.0)24 25    d._generate_shadow_texture()26    st = d.shadow_texture27    assert isinstance(st, Texture)28    assert st.width == st.height == SHADOW_TEX_SZ29 30    sc = d._get_shadow_camera(scene_scale=5.0)31    assert isinstance(sc, OrthographicCamera)32    assert sc.xmag == sc.ymag == 5.033    assert sc.znear == 0.01 * 5.034    assert sc.zfar == 10 * 5.035 36 37def test_spot_light():38 39    s = SpotLight()40    assert s.name is None41    assert np.all(s.color == 1.0)42    assert s.intensity == 1.043    assert s.innerConeAngle == 0.044    assert s.outerConeAngle == np.pi / 4.045    assert s.range is None46 47    with pytest.raises(ValueError):48        s.range = -1.049 50    with pytest.raises(ValueError):51        s.range = 0.052 53    with pytest.raises(ValueError):54        s.innerConeAngle = -1.055 56    with pytest.raises(ValueError):57        s.innerConeAngle = np.pi / 3.058 59    with pytest.raises(ValueError):60        s.outerConeAngle = -1.061 62    with pytest.raises(ValueError):63        s.outerConeAngle = np.pi64 65    s.range = 5.066    s.outerConeAngle = np.pi / 2 - 0.0567    s.innerConeAngle = np.pi / 368    s.innerConeAngle = 0.069    s.outerConeAngle = np.pi / 4.070 71    s._generate_shadow_texture()72    st = s.shadow_texture73    assert isinstance(st, Texture)74    assert st.width == st.height == SHADOW_TEX_SZ75 76    sc = s._get_shadow_camera(scene_scale=5.0)77    assert isinstance(sc, PerspectiveCamera)78    assert sc.znear == 0.01 * 5.079    assert sc.zfar == 10 * 5.080    assert sc.aspectRatio == 1.081    assert np.allclose(sc.yfov, np.pi / 16.0 * 9.0)  # Plus pi / 1682 83 84def test_point_light():85 86    s = PointLight()87    assert s.name is None88    assert np.all(s.color == 1.0)89    assert s.intensity == 1.090    assert s.range is None91 92    with pytest.raises(ValueError):93        s.range = -1.094 95    with pytest.raises(ValueError):96        s.range = 0.097 98    s.range = 5.099 100    with pytest.raises(NotImplementedError):101        s._generate_shadow_texture()102 103    with pytest.raises(NotImplementedError):104        s._get_shadow_camera(scene_scale=5.0)105