Skip to content

Conversation

@sean85914
Copy link

Type

  • New feature (non-breaking change which adds functionality).

Motivation and Context

Currently, TriangleMesh instances in Python compare by identity due to the lack of a C++ operator==.
This leads to unintuitive behavior:

m1 = o3d.geometry.TriangleMesh.create_sphere(0.1)
m1.compute_vertex_normals()
m2 = o3d.geometry.TriangleMesh(m1)

m1 == m2   # False

Although m2 is a copy of m1, equality returns False.
This PR adds a value-based equality operator for TriangleMesh to fix this.

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

  • Added bool TriangleMesh::operator==(const TriangleMesh &mesh) const
  • Equality is defined as vertices and triangles being identical.
  • vertices_ comparison uses isApprox for floating-point precision.
  • triangles_ comparison uses exact equality for integer indices.
  • Bound Python equality using py::self == py::self for TriangleMesh.
  • Updated Python behavior:
m1 = o3d.geometry.TriangleMesh.create_sphere(0.1)
m2 = o3d.geometry.TriangleMesh(m1)
assert m1 == m2   # True
  • Copy constructor remains consistent with value-based equality semantics.
  • Normals, colors, and other auxiliary attributes are not considered in equality, as they can be recomputed.

@update-docs
Copy link

update-docs bot commented Dec 9, 2025

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant