Skip to content

3D Collision debug view in-editor & in-game#8598

Open
Bouh wants to merge 9 commits into
masterfrom
collision-debug-view
Open

3D Collision debug view in-editor & in-game#8598
Bouh wants to merge 9 commits into
masterfrom
collision-debug-view

Conversation

@Bouh

@Bouh Bouh commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Second part of #8597

The debug view displays Jolt's actual colliders and isn't meant to resize with the object. If we want collision shapes to follow the object on non-uniform rescaling across the three axes, we'd need to change the Jolt implementation itself so the body is rebuilt/scaled accordingly, not only the debug renderer.

Editor + in-game preview

592075839-68ae613b-c5e1-4633-baa3-e1ee7f091992.mp4

This also add an action to enable the debug from the events, and a toggle for it.

Credits goes to Eldarduil for his help and work on the debug threejs functions.
https://eldarduil.itch.io/show-3d-collision-shapes-for-gdevelop

Bouh added 7 commits May 13, 2026 21:43
`onBehaviorUpdated` in CompactObjectPropertiesEditor was a no-op, so
editing behavior properties from the compact panel never propagated
to the in-app editor preview. Wire it to `onObjectsModified([object])`
like the other property edits in the same file. Debounced at 250ms
via `useDebounce` to avoid one hot reload per keystroke on fields.
Extract the field initialization from the constructor into a private
`_applyBehaviorData` helper, and reuse it for both the constructor
(full data) and the hot-reload hook `applyBehaviorOverriding` (diff
containing only changed fields). When any shape-related property is
present in the diff, the body is rebuilt via `recreateBody()`.

Previously the default `applyBehaviorOverriding` returned false, so
hot reload of Physics3D properties was silently dropped, forcing a
full restart of the app or closing and reopening the tab to see any
tweak made in the editor.
Add `_debugDraw3DEnabled`, `_debugDraw3DColorHex` and
`_debugDraw3DDepthTest` to RuntimeInstanceContainer, plus a new
`enableDebugDraw3D(enabled, colorHex, depthTest)` method that mirrors
the existing 2D `enableDebugDraw`. When the settings change while a
draw is active, the existing wireframes are cleared so the renderer
rebuilds them with the new configuration.

`RuntimeScene.renderAndStep` calls `renderDebugDraw3D` each frame when
the flag is on — same hook point as the 2D debug draw.

The actual rendering is implemented in a follow-up commit.
Implement `renderDebugDraw3D` and `clearDebugDraw3D` on
DebuggerPixiRenderer. Wireframes are rendered as THREE.js meshes
attached to each object's 3D renderer object.

Supports the four Physics3D primitive shapes (Box, Sphere, Capsule,
Cylinder) including orientation (X/Y/Z), shape offsets, parent-scale
compensation, and the PhysicsCharacter3D bottom-origin adjustment.

Also supports the Mesh shape: each child mesh of the object's 3D
renderer is wrapped with a `THREE.WireframeGeometry` + LineSegments.
Async-loaded Model3D meshes are picked up automatically each frame,
and detached source meshes are pruned.

State is tracked in a `Map<RuntimeObject, DebugDraw3DState>` on the
renderer, with a per-frame `seen` set that disposes wireframes whose
owning object disappeared. CustomRuntimeObject children are visited
recursively so nested Physics3D objects are covered.

Wireframes opt out of raycasting (`mesh.raycast = () => {}`) so that
the community Raycaster3D extension doesn't crash on intersections
without normals.
Expose the new 3D debug-draw via two GDevelop actions in the Debugger
Tools extension:

- `EnableDebugDraw3D` — enable/disable with explicit color (R;G;B)
  and depth-test parameters. Mirrors the existing `EnableDebugDraw`
  action used for 2D.
- `ToggleDebugDraw3D` — flips the current state, reusing the last
  color and depth-test values stored on the instance container.

Both delegate to `RuntimeInstanceContainer.enableDebugDraw3D`.
…editor

Add a Debug-icon button next to the Lightbulb in the root row of the
Layers tree view (only when in embedded-game / in-app editor mode).
Clicking it toggles the local state `areCollisionsShownInEditor` in
SceneEditor and broadcasts a `set3DCollisionsShownInEditor` message
to the embedded preview frames via `previewDebuggerServer`.

The runtime debugger client receives the command and calls
`enableDebugDraw3D` on the edited instance container, reusing the
default color and depth-test settings.

Props are threaded through the `EditorsDisplay` interface, both
mosaic and swipeable-drawer displays, plus the LayersList story mock.
@Bouh Bouh marked this pull request as ready for review May 27, 2026 10:54
@Bouh Bouh requested a review from 4ian as a code owner May 27, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant