@@ -31,4 +31,43 @@ def test_meshdata():
31
31
assert_array_equal (square_edges , mesh .get_edges ())
32
32
33
33
34
+ def test_vertex_normals_indexed_none ():
35
+ dtype_float = np .float32
36
+ dtype_int = np .int64
37
+ vertices = np .array ([[0 , 0 , 0 ], [1 , 0 , 0 ], [0 , 1 , 0 ], [0 , 0 , 1 ]],
38
+ dtype = dtype_float )
39
+ faces = np .array ([[0 , 2 , 1 ], [0 , 3 , 2 ], [0 , 1 , 3 ]], dtype = dtype_int )
40
+ mesh = MeshData (vertices = vertices , faces = faces )
41
+ vertex_normals_unnormalized = np .array (
42
+ [[- 1 , - 1 , - 1 ], [0 , - 1 , - 1 ], [- 1 , 0 , - 1 ], [- 1 , - 1 , 0 ]],
43
+ dtype = dtype_float )
44
+ norms = np .sqrt ((vertex_normals_unnormalized ** 2 ).sum (axis = 1 ,
45
+ keepdims = True ))
46
+ expected_vertex_normals = vertex_normals_unnormalized / norms
47
+
48
+ computed_vertex_normals = mesh .get_vertex_normals (indexed = None )
49
+
50
+ assert_array_equal (expected_vertex_normals , computed_vertex_normals )
51
+
52
+
53
+ def test_vertex_normals_indexed_faces ():
54
+ dtype_float = np .float32
55
+ dtype_int = np .int64
56
+ vertices = np .array ([[0 , 0 , 0 ], [1 , 0 , 0 ], [0 , 1 , 0 ], [0 , 0 , 1 ]],
57
+ dtype = dtype_float )
58
+ faces = np .array ([[0 , 2 , 1 ], [0 , 3 , 2 ], [0 , 1 , 3 ]], dtype = dtype_int )
59
+ mesh = MeshData (vertices = vertices , faces = faces )
60
+ vertex_normals_unnormalized = np .array (
61
+ [[- 1 , - 1 , - 1 ], [0 , - 1 , - 1 ], [- 1 , 0 , - 1 ], [- 1 , - 1 , 0 ]],
62
+ dtype = dtype_float )
63
+ norms = np .sqrt ((vertex_normals_unnormalized ** 2 ).sum (axis = 1 ,
64
+ keepdims = True ))
65
+ vertex_normals = vertex_normals_unnormalized / norms
66
+ expected_vertex_normals = vertex_normals [faces ]
67
+
68
+ computed_vertex_normals = mesh .get_vertex_normals (indexed = "faces" )
69
+
70
+ assert_array_equal (expected_vertex_normals , computed_vertex_normals )
71
+
72
+
34
73
run_tests_if_main ()
0 commit comments