Skip to content

Commit

Permalink
Rebuild Mesh's PMF on vertex position changes
Browse files Browse the repository at this point in the history
  • Loading branch information
njroussel committed Feb 9, 2024
1 parent fd80810 commit ced7b22
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/render/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ MI_VARIANT void Mesh<Float, Spectrum>::parameters_changed(const std::vector<std:
if (has_vertex_normals())
recompute_vertex_normals();

if (!m_area_pmf.empty() && (m_emitter || m_sensor))
ensure_pmf_built();
if (!m_area_pmf.empty() || m_emitter || m_sensor)
build_pmf();

if (m_parameterization)
m_parameterization = nullptr;
Expand Down
23 changes: 23 additions & 0 deletions src/render/tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,26 @@ def test32_shape_type(variant_scalar_rgb):
"filename" : "resources/data/tests/ply/rectangle_uv.ply",
})
assert mesh.shape_type() == mi.ShapeType.Mesh.value;


@fresolver_append_path
def test33_rebuild_area_pmf(variants_vec_rgb):
mesh = mi.load_dict({
"type" : "ply",
"filename" : "resources/data/tests/ply/triangle.ply",
"face_normals" : True
})

surface_area_before = mesh.surface_area()

params = mi.traverse(mesh)
key = 'vertex_positions'

vertices = dr.unravel(mi.Point3f, params[key])
new_vertices = mi.Transform4f().scale(2) @ vertices
params[key] = dr.ravel(new_vertices)
params.update()

surface_area_after = mesh.surface_area()

assert surface_area_after == 4 * surface_area_before

0 comments on commit ced7b22

Please sign in to comment.