File: test_instanced_mesh.py

package info (click to toggle)
python-vispy 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,840 kB
  • sloc: python: 59,436; javascript: 6,800; makefile: 69; sh: 6
file content (50 lines) | stat: -rw-r--r-- 1,386 bytes parent folder | download | duplicates (2)
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
import numpy as np
from vispy import scene, use

from vispy.testing import (TestingCanvas, requires_application,
                           run_tests_if_main, requires_pyopengl)


def setup_module(module):
    use(gl='gl+')


def teardown_module(module):
    use(gl='gl2')


@requires_pyopengl()
@requires_application()
def test_mesh_with_vertex_values():
    size = (80, 60)
    with TestingCanvas(size=size) as c:
        use(gl='gl+')
        vert = np.array([[0, 0, 0], [0, 30, 0], [40, 0, 0]])
        faces = np.array([0, 1, 2])
        pos = np.array([[0, 0, 0], [80, 60, 0]])
        # identity and rotate 180
        trans = np.array([
            [
                [1, 0, 0],
                [0, 1, 0],
                [0, 0, 1],
            ],
            [
                [-1, 0, 0],
                [0, -1, 0],
                [0, 0, 1],
            ],
        ])
        colors = ['red', 'blue']
        mesh = scene.visuals.InstancedMesh(
            vertices=vert, faces=faces, instance_positions=pos, instance_transforms=trans, instance_colors=colors
        )
        v = c.central_widget.add_view(border_width=0)
        v.add(mesh)
        render = c.render()
        assert np.allclose(render[10, 10], (255, 0, 0, 255))
        assert np.allclose(render[-10, -10], (0, 0, 255, 255))
        assert np.allclose(render[30, 40], (0, 0, 0, 255))


run_tests_if_main()