Skip to content

add backface culling to Open3DScene and expose the interface to Python - #7527

Open
daizhirui wants to merge 2 commits into
isl-org:mainfrom
daizhirui:dev-backface-culling
Open

add backface culling to Open3DScene and expose the interface to Python#7527
daizhirui wants to merge 2 commits into
isl-org:mainfrom
daizhirui:dev-backface-culling

Conversation

@daizhirui

Copy link
Copy Markdown
Contributor

open3d.visualization.Visualizer can enable backface culling via the RenderOption. This feature is missing for Open3DScene. This pull request is to add the backface culling feature to Open3DScene and provide the corresponding Python binding. Then, with Python, we can write

import sys
import numpy as np
import open3d as o3d
import open3d.visualization.gui as gui
import open3d.visualization.rendering as rendering

DEFAULT_PLY = "<TEST_MESH_PLY_HERE>"
ply = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_PLY

# Start with back-face culling enabled so the ceiling is removed on open.
CULL_ON_START = True

mesh = o3d.io.read_triangle_mesh(ply)
if not mesh.has_vertex_normals():
    mesh.compute_vertex_normals()

gui.Application.instance.initialize()
win = gui.Application.instance.create_window("Back-face Culling Demo", 1280, 900)

widget = gui.SceneWidget()
widget.scene = rendering.Open3DScene(win.renderer)
win.add_child(widget)

mat = rendering.MaterialRecord()
mat.shader = "defaultLit"
mat.backface_culling = CULL_ON_START
widget.scene.add_geometry("mesh", mesh, mat)

bounds = widget.scene.bounding_box
widget.setup_camera(60.0, bounds, bounds.get_center())
# Elevated, looking-down viewpoint so that back-face culling visibly removes the
# ceiling and reveals the room interior.
c = bounds.get_center()
e = bounds.get_extent()
eye = c + np.array([e[0] * 0.2, -e[1] * 0.6, e[2] * 2.5])
widget.look_at(c, eye, np.array([0.0, 0.0, 1.0]))
widget.scene.show_axes(True)

# --- Controls panel ---
em = win.theme.font_size
panel = gui.Vert(0, gui.Margins(em, em, em, em))
cb = gui.Checkbox("Back-face culling")
cb.checked = CULL_ON_START


def on_cull(is_checked):
    # NOTE: the binding to enable backface culling
    widget.scene.set_geometry_backface_culling("mesh", is_checked)


cb.set_on_checked(on_cull)
panel.add_child(cb)
win.add_child(panel)


def on_layout(ctx):
    r = win.content_rect
    widget.frame = r
    pref = panel.calc_preferred_size(ctx, gui.Widget.Constraints())
    panel.frame = gui.Rect(r.get_right() - pref.width, r.y, pref.width, pref.height)


win.set_on_layout(on_layout)
gui.Application.instance.run()

Type

  • Bug fix (non-breaking change which fixes an issue): Fixes #
  • New feature (non-breaking change which adds functionality). Resolves #
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) Resolves #

Motivation and Context

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

  1. add a member backface_culling to open3d::visualization::rendering::MaterialRecord.
  2. add a method SetGeometryBackfaceCulling to open3d::visualization::rendering::Scene, open3d::visualization::rendering::Open3DScene and open3d::visualization::rendering::FilamentScene
  3. add the corresponding Python binding: backface_culling to mat for MaterialRecord and set_geometry_backface_culling to o3dscene for Open3DScene.

With backface_culling=True:
image

With backface_culling=False:
image

@update-docs

update-docs Bot commented Jul 31, 2026

Copy link
Copy Markdown

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