def test04_normal_weighting_scheme(variant_scalar_rgb): from mitsuba.core import Vector3f from mitsuba.render import Mesh import numpy as np """Tests the weighting scheme that is used to compute surface normals.""" m = Mesh("MyMesh", 5, 2, has_vertex_normals=True) vertices = m.vertex_positions_buffer() normals = m.vertex_normals_buffer() a, b = 1.0, 0.5 vertices[:] = [0, 0, 0, -a, 1, 0, a, 1, 0, -b, 0, 1, b, 0, 1] n0 = Vector3f(0.0, 0.0, -1.0) n1 = Vector3f(0.0, 1.0, 0.0) angle_0 = ek.pi / 2.0 angle_1 = ek.acos(3.0 / 5.0) n2 = n0 * angle_0 + n1 * angle_1 n2 /= ek.norm(n2) n = np.vstack([n2, n0, n0, n1, n1]).transpose() m.faces_buffer()[:] = [0, 1, 2, 0, 3, 4] m.recompute_vertex_normals() for i in range(5): assert ek.allclose(normals[i * 3:(i + 1) * 3], n[:, i], 5e-4)
def test04_normal_weighting_scheme(variant_scalar_rgb): from mitsuba.core import Struct, float_dtype, Vector3f from mitsuba.render import Mesh import numpy as np """Tests the weighting scheme that is used to compute surface normals.""" vertex_struct = Struct() \ .append("x", Struct.Type.Float32) \ .append("y", Struct.Type.Float32) \ .append("z", Struct.Type.Float32) \ .append("nx", Struct.Type.Float32) \ .append("ny", Struct.Type.Float32) \ .append("nz", Struct.Type.Float32) index_struct = Struct() \ .append("i0", Struct.Type.UInt32) \ .append("i1", Struct.Type.UInt32) \ .append("i2", Struct.Type.UInt32) m = Mesh("MyMesh", vertex_struct, 5, index_struct, 2) v = m.vertices() a, b = 1.0, 0.5 v['x'] = Float([0, -a, a, -b, b]) v['y'] = Float([0, 1, 1, 0, 0]) v['z'] = Float([0, 0, 0, 1, 1]) n0 = Vector3f(0.0, 0.0, -1.0) n1 = Vector3f(0.0, 1.0, 0.0) angle_0 = ek.pi / 2.0 angle_1 = ek.acos(3.0 / 5.0) n2 = n0 * angle_0 + n1 * angle_1 n2 /= ek.norm(n2) n = np.vstack([n2, n0, n0, n1, n1]) f = m.faces() f[0] = (0, 1, 2) f[1] = (0, 3, 4) m.recompute_vertex_normals() assert ek.allclose(v['nx'], n[:, 0], 5e-4) assert ek.allclose(v['ny'], n[:, 1], 5e-4) assert ek.allclose(v['nz'], n[:, 2], 5e-4)