forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_geom.py
More file actions
84 lines (62 loc) · 2.42 KB
/
test_geom.py
File metadata and controls
84 lines (62 loc) · 2.42 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
from panda3d import core
empty_format = core.GeomVertexFormat.get_empty()
def test_geom_decompose_in_place():
vertex_data = core.GeomVertexData("", empty_format, core.GeomEnums.UH_static)
prim = core.GeomTristrips(core.GeomEnums.UH_static)
prim.add_vertex(0)
prim.add_vertex(1)
prim.add_vertex(2)
prim.add_vertex(3)
prim.close_primitive()
geom = core.Geom(vertex_data)
geom.add_primitive(prim)
geom.decompose_in_place()
prim = geom.get_primitive(0)
assert tuple(prim.get_vertex_list()) == (0, 1, 2, 2, 1, 3)
def test_geom_decompose():
vertex_data = core.GeomVertexData("", empty_format, core.GeomEnums.UH_static)
prim = core.GeomTristrips(core.GeomEnums.UH_static)
prim.add_vertex(0)
prim.add_vertex(1)
prim.add_vertex(2)
prim.add_vertex(3)
prim.close_primitive()
geom = core.Geom(vertex_data)
geom.add_primitive(prim)
new_geom = geom.decompose()
new_prim = new_geom.get_primitive(0)
assert tuple(new_prim.get_vertex_list()) == (0, 1, 2, 2, 1, 3)
# Old primitive should still be unchanged
assert prim == geom.get_primitive(0)
def test_geom_calc_sphere_bounds():
# Ensure that it ignores NaN
data = core.GeomVertexData("", core.GeomVertexFormat.get_v3(), core.Geom.UH_static)
vertex = core.GeomVertexWriter(data, "vertex")
vertex.add_data3((float("NaN"), 0, 0))
vertex.add_data3((1, 1, 1))
vertex.add_data3((1, 1, 2))
prim = core.GeomPoints(core.Geom.UH_static)
prim.add_next_vertices(3)
geom = core.Geom(data)
geom.add_primitive(prim)
geom.set_bounds_type(core.BoundingVolume.BT_sphere)
bounds = geom.get_bounds()
assert isinstance(bounds, core.BoundingSphere)
assert bounds.get_center() == (1, 1, 1.5)
assert bounds.get_radius() == 0.5
def test_geom_calc_box_bounds():
# Ensure that it ignores NaN
data = core.GeomVertexData("", core.GeomVertexFormat.get_v3(), core.Geom.UH_static)
vertex = core.GeomVertexWriter(data, "vertex")
vertex.add_data3((float("NaN"), 0, 0))
vertex.add_data3((1, 1, 1))
vertex.add_data3((1, 1, 2))
prim = core.GeomPoints(core.Geom.UH_static)
prim.add_next_vertices(3)
geom = core.Geom(data)
geom.add_primitive(prim)
geom.set_bounds_type(core.BoundingVolume.BT_box)
bounds = geom.get_bounds()
assert isinstance(bounds, core.BoundingBox)
assert bounds.get_min() == (1, 1, 1)
assert bounds.get_max() == (1, 1, 2)