Debug Visualization and Text Rendering

Use app.debug as the entry point for debug visualization and text:

  • app.debug.overlay draws lines and points without creating scene Prims or mesh objects. Axes and arrows are built from line segments.

  • app.debug.geometry creates triangle-mesh debug objects in the SceneGraph and draws them through the scene renderer, using instancing for batches.

  • app.debug.world_text draws screen-aligned text at a 3D world position.

  • app.debug.screen_text draws text in viewport pixel coordinates.

Overlay uses line widths and point sizes in pixels; geometry uses mesh dimensions such as radii in world units.

app.debug groups the existing helpers; it is not a SceneGraph node or a separate data store. Only geometry creates scene objects, owned by the current scene. Overlay and text entries do not appear in the scene graph panel.

Helper

Create or update

Show or hide

Remove

app.debug.overlay

Call lines(), points(), axes(), or arrows() again at the same path

set_visible(path, visible)

remove(path), remove_all()

app.debug.geometry

Create with add_*(), then call update_*() on the returned view

view.set_visible(visible)

view.remove()

app.debug.world_text / app.debug.screen_text

set() replaces an entry; set_text() and set_position() update individual fields

set_visible(path, visible)

remove(path), remove_all()

Geometry is managed through its returned scene-object view. Overlay and text are managed by path. Use app.debug.* for new code; overlay clear*() methods remain available to empty data while retaining path entries.

The previous entry points (app.debug_overlay, app.scene.debug_geometry, app.world_text, and app.screen_text) still refer to the same helper objects. Updates or removals through either entry point affect the same data.

Debug geometry, overlay, and text

Debug overlay

Use debug.overlay for lightweight lines, points, axes, and arrows that do not create SceneGraph Prims:

self.debug.overlay.axes(
    path="/overlay/axes",
    origin=np.array([0.0, 0.0, 0.0]),
    rotation=np.eye(3),
    length=1.0,
)

Calling the same function with the same path creates or replaces its data and options. This is also the update operation; there is no separate update_*() method for overlay batches:

self.debug.overlay.points(path="/overlay/contacts", points=contact_positions)
self.debug.overlay.points(path="/overlay/contacts", points=new_contact_positions)

self.debug.overlay.set_visible(path="/overlay/contacts", visible=False)
self.debug.overlay.set_visible(path="/overlay/contacts", visible=True)
self.debug.overlay.remove(path="/overlay/contacts")
self.debug.overlay.remove_all()

An overlay path is an exact string identifier, not a SceneGraph hierarchy. Slashes only organize names for readability: remove("/overlay") does not remove "/overlay/axes". Use the complete identifier to manage an entry.

Lines, axes, and arrows share one set of identifiers, so drawing any of them at the same path replaces the previous line, axis, or arrow data. Points use a separate set and can coexist at that path. set_visible(path, visible) and remove(path) affect both at that exact path. An unknown path is a no-op.

set_visible() retains data so it can be shown again without resending it. The next draw call replaces the batch’s options too, including hidden. remove() deletes an entry and releases its buffers; remove_all() does this for every overlay entry. These calls do not remove scene objects or text.

For frequently reused paths, clear_lines(path), clear_points(path), and clear(path) remain available to empty data while retaining path entries. clear(path) empties both line and point data. These methods do not remove entries or match path prefixes.

Lines, points, axes, and arrows normally test scene depth (overlay=False). Pass overlay=True to any of these helpers to keep them visible through meshes without changing their world positions.

For force arrows, convert forces to displayed world-space lengths with a shared scale. starts and ends have shape (N, 3); optional RGBA colors have shape (N, 4), or (1, 4) / (4,) for one shared color:

self.debug.overlay.arrows(
    path="/overlay/forces",
    starts=contact_positions,
    ends=contact_positions + forces * force_scale,
    width=3.0,
    overlay=True,
)

Each arrow uses a shaft and four head segments. The head length is 20% of the arrow length, with an 8% half-width. Arrows of length at most 1e-8 are omitted; an empty batch clears the previous arrows while retaining the path entry.

Scene debug geometry

debug.geometry creates instanced meshes registered in the scene. Their world-space poses use ExternalBuffer; update them through the returned view, not Prim transforms or the gizmo:

self.debug_spheres = self.debug.geometry.add_spheres(
    path="/debug_geometry/spheres",
    centers=centers,
    radii=radii,
    colors=colors,
)

self.debug_spheres.update_spheres(
    centers=new_centers,
    radii=radii,
    colors=colors,
)
self.debug_spheres.remove()

Lines and arrows provide matching update_lines() and update_arrows() methods.

World-space text

Create the entry once, then update only the values that change:

self.debug.world_text.set(
    path="/labels/box",
    text="Box",
    position=ke.Vec3(0.0, 1.2, 0.0),
    pixel_size=28.0,
)

self.debug.world_text.set_position("/labels/box", new_position)
self.debug.world_text.set_text("/labels/box", "Moving box")
self.debug.world_text.set_visible(path="/labels/box", visible=False)
self.debug.world_text.set_visible(path="/labels/box", visible=True)
self.debug.world_text.remove(path="/labels/box")
self.debug.world_text.remove_all()

Set depth_test=False when the label should remain visible through scene geometry.

Repeating set() replaces the complete entry, including its options. set_text() and set_position() update only the specified field and preserve visibility. set_visible(), remove(), and remove_all() follow the same management convention as debug.overlay, but affect only world text.

Screen-space text

position is measured in pixels from the selected anchor. Without an explicit anchor, it uses TopLeft, so (24, 24) places the text 24 pixels right and down from the top-left corner:

self.debug.screen_text.set(
    path="/status",
    text="Ready",
    position=ke.Vec2(24.0, 24.0),
    anchor=ke.render.ScreenAnchor.TOP_LEFT,
)

self.debug.screen_text.set_text("/status", "Running")
self.debug.screen_text.set_visible(path="/status", visible=False)
self.debug.screen_text.remove(path="/status")
self.debug.screen_text.remove_all()

When alignment is omitted, it follows the anchor column automatically: left, center, or right. Pass an explicit alignment to override it.

Screen text has the same update and management methods as world text; its remove_all() affects only screen text. For existing callers, text helpers retain set_hidden(path, hidden) and clear() as compatibility spellings of set_visible(path, not hidden) and remove_all().

Run the complete example:

python ./python/examples/debug_visualization.py

The yellow arrow follows the moving box and starts at its center. It uses debug.overlay.arrows(..., overlay=True) so the shaft remains visible through the box, and reuses the same path each frame to update its position.

Complete source: debug_visualization.py
  1"""Debug geometry, overlay, and text in one scene."""
  2
  3import math
  4
  5import numpy as np
  6
  7import kangengine as ke
  8from kangengine.utils._example_args import render_example_parser
  9
 10
 11class DebugVisualizationApp(ke.App):
 12    def setup(self):
 13        self.count = 0
 14        self.orbit_angle = 0.0
 15        materials = self.create_standard_materials()
 16        self.scene.add_ground("/ground", scale=20.0)
 17
 18        self.box = self.scene.add_mesh(
 19            "/box",
 20            ke.geometry.create_cube_data(1.0),
 21            materials.common,
 22            color=ke.Vec4(0.8, 0.3, 0.05, 1.0),
 23        )
 24        self.box.set_local_translation(ke.Vec3(0.0, 0.5, 0.0))
 25
 26        # Lightweight overlay: no SceneGraph prims are created.
 27        self.debug.overlay.lines(
 28            "/overlay/lines",
 29            np.array([[-3.0, 0.05, -1.0], [-3.0, 0.05, 0.0]]),
 30            np.array([[-1.5, 1.0, -1.0], [-1.5, 1.0, 0.0]]),
 31            np.array(
 32                [
 33                    [1.0, 0.25, 0.2, 1.0],
 34                    [0.2, 0.9, 0.35, 1.0],
 35                ]
 36            ),
 37            width=3.0,
 38        )
 39        self.debug.overlay.points(
 40            "/overlay/points",
 41            np.array([[-3.0, 0.1, 1.0], [-2.5, 0.5, 1.0], [-2.0, 0.9, 1.0]]),
 42            np.array(
 43                [
 44                    [1.0, 0.3, 0.3, 1.0],
 45                    [0.3, 1.0, 0.3, 1.0],
 46                    [0.3, 0.5, 1.0, 1.0],
 47                ]
 48            ),
 49            size=10.0,
 50        )
 51        self.debug.overlay.axes(
 52            "/overlay/axes",
 53            origin=np.array([-2.0, 0.05, 2.0]),
 54            rotation=np.eye(3),
 55            length=1.0,
 56            width=3.0,
 57        )
 58        # Mesh-based debug geometry: visible as ordinary SceneGraph objects.
 59        self.debug.geometry.add_lines(
 60            "/debug_geometry/lines",
 61            np.array([[1.5, 0.05, -1.0], [1.5, 0.05, 0.0]]),
 62            np.array([[3.0, 1.0, -1.0], [3.0, 1.0, 0.0]]),
 63            np.array(
 64                [
 65                    [1.0, 0.6, 0.15, 1.0],
 66                    [0.2, 0.75, 1.0, 1.0],
 67                ]
 68            ),
 69            material=materials.debug,
 70            radius=0.025,
 71        )
 72        self.debug.geometry.add_arrows(
 73            "/debug_geometry/arrows",
 74            np.array([[1.5, 0.05, 1.0], [1.5, 0.05, 2.0]]),
 75            np.array([[3.0, 1.0, 1.0], [3.0, 1.0, 2.0]]),
 76            np.array(
 77                [
 78                    [0.95, 0.35, 0.75, 1.0],
 79                    [0.45, 0.95, 0.35, 1.0],
 80                ]
 81            ),
 82            material=materials.debug,
 83            radius=0.04,
 84        )
 85        self.debug.geometry.add_axes(
 86            "/debug_geometry/axes",
 87            origin=np.array([2.0, 0.05, 3.0]),
 88            rotation=np.eye(3),
 89            material=materials.debug,
 90            length=1.0,
 91            radius=0.02,
 92        )
 93        self.debug_sphere_centers = np.array(
 94            [
 95                [0.5, 0.4, 4.5],
 96                [1.5, 0.6, 4.5],
 97                [2.9, 0.8, 4.5],
 98            ],
 99            dtype=np.float32,
100        )
101        self.debug_sphere_radii = np.array([0.35, 0.55, 0.75])
102        self.debug_sphere_colors = np.array(
103            [
104                [1.0, 0.35, 0.25, 1.0],
105                [0.3, 0.8, 1.0, 1.0],
106                [0.5, 1.0, 0.35, 1.0],
107            ]
108        )
109        self.debug_spheres = self.debug.geometry.add_spheres(
110            "/debug_geometry/spheres",
111            centers=self.debug_sphere_centers,
112            radii=self.debug_sphere_radii,
113            colors=self.debug_sphere_colors,
114            material=materials.debug,
115        )
116
117        self.debug.world_text.set(
118            "/labels/overlay",
119            "Debug overlay",
120            ke.Vec3(-2.3, 1.5, 0.0),
121            pixel_size=24.0,
122            depth_test=False,
123        )
124        self.debug.world_text.set(
125            "/labels/geometry",
126            "Scene debug geometry",
127            ke.Vec3(2.3, 1.5, 0.0),
128            pixel_size=24.0,
129        )
130        self.debug.world_text.set(
131            "/labels/box",
132            "Moving box",
133            ke.Vec3(0.0, 1.7, 0.0),
134            pixel_size=24.0,
135        )
136        self.debug.screen_text.set(
137            "/screen/title",
138            "Debug Visualization {}".format(self.count),
139            ke.Vec2(30.0, 30.0),
140            pixel_size=28.0,
141        )
142        self.debug.screen_text.set(
143            "/screen/anchor",
144            "TopCenter",
145            ke.Vec2(30.0, 30.0),
146            alignment=ke.render.TextAlignment.CENTER,
147            anchor=ke.render.ScreenAnchor.TOP_CENTER,
148            color=ke.Vec4(0.3, 0.9, 1.0, 1.0),
149            pixel_size=25.0,
150        )
151        self.debug.screen_text.set(
152            "/screen/anchor2",
153            "CenterLeft",
154            ke.Vec2(0.0, 0.0),
155            anchor=ke.render.ScreenAnchor.CENTER_LEFT,
156            color=ke.Vec4(0.3, 0.9, 1.0, 1.0),
157            pixel_size=25.0,
158        )
159
160        # self.set_camera_view([7.0, -9.0, 6.0], [0.0, 0.0, 0.8])
161
162    def pre_render(self):
163        self.orbit_angle = (
164            self.orbit_angle + math.radians(120.0) * self.get_delta_time()
165        ) % (2.0 * math.pi)
166        self.box.set_local_translation(
167            ke.Vec3(
168                math.cos(self.orbit_angle),
169                0.5,
170                math.sin(self.orbit_angle),
171            )
172        )
173
174        box_pos = self.box.get_world_translation()
175        box_quat = self.box.get_world_quat()
176        # Reusing this path updates the arrow; overlay keeps its buried shaft visible.
177        yellow = ke.ColorLibrary.get(ke.ColorType.YELLOW)
178        self.debug.overlay.arrows(
179            path="/overlay/box_direction",
180            starts=np.array([[box_pos.x, box_pos.y, box_pos.z]]),
181            ends=np.array([[box_pos.x, box_pos.y + 0.9, box_pos.z]]),
182            colors=np.array([[yellow.r, yellow.g, yellow.b, yellow.a]]),
183            width=3.0,
184            overlay=True,
185        )
186
187        self.debug.world_text.set_position(
188            "/labels/box",
189            box_pos + box_quat * ke.Vec3(0.0, 1.2, 0.0),
190        )
191
192        sphere_centers = self.debug_sphere_centers.copy()
193        sphere_centers[:, 1] += 0.1 * np.sin(
194            self.orbit_angle + np.arange(len(sphere_centers))
195        )
196        self.debug_spheres.update_spheres(
197            sphere_centers,
198            self.debug_sphere_radii,
199            self.debug_sphere_colors,
200        )
201
202        self.debug.screen_text.set_text(
203            "/screen/title",
204            "Debug Visualization {}".format(self.count),
205        )
206        self.count += 1
207
208
209if __name__ == "__main__":
210    args = render_example_parser(description=__doc__).parse_args()
211    app = DebugVisualizationApp()
212    app.initialize(1920, 1080, False, ke.UpAxis.Y, renderer=args.renderer)
213    app.start()