Skip to content

feat: PhysicsNode + physics-demo sample (roadmap 3.2.0)#673

Merged
ThomasGorisse merged 1 commit intomainfrom
feat/physics-node
Mar 20, 2026
Merged

feat: PhysicsNode + physics-demo sample (roadmap 3.2.0)#673
ThomasGorisse merged 1 commit intomainfrom
feat/physics-node

Conversation

@ThomasGorisse
Copy link
Contributor

Summary

Introduces PhysicsNode — a pure-Kotlin rigid-body composable — plus a samples/physics-demo app that lets you tap to throw bouncing balls.

PhysicsNode.kt (sceneview/src/main/java/io/github/sceneview/node/)

Two public types:

PhysicsBody — simulation state for one rigid body:

  • Euler integration via Node.onFrame each frame
  • Gravity: −9.8 m/s² on Y, dt clamped to 50 ms (absorbs GC spikes)
  • Floor collision: position clamp + velocity reflection × restitution
  • Sleep: stops integrating when speed falls below 0.05 m/s

PhysicsNode composable — DSL entry point:

PhysicsNode(
    node = sphereNode,
    mass = 1f,
    restitution = 0.6f,
    linearVelocity = Vector3(0f, 5f, 0f),
    floorY = 0f,
    radius = 0.1f
)

samples/physics-demo

  • Floor plane (flat CubeNode)
  • Tap anywhere → spawns a SphereNode that falls and bounces
  • Up to 10 simultaneous balls; oldest removed when cap is hit
  • Uses Scene {} (non-AR)

Design decisions

  • PhysicsBody is decoupled from Compose — can be stepped from ViewModel or imperative code
  • floorY: Float for floor detection — avoids full AABB implementation for this prototype
  • mass declared for API completeness / future impulse/force extensions

Test plan

  • ./gradlew :samples:physics-demo:assembleDebug
  • Tap screen → balls fall and bounce on the floor
  • Multiple balls coexist (up to 10)
  • Balls come to rest after bouncing settles

🤖 Generated with Claude Code

Adds a pure-Kotlin rigid-body physics prototype with no external library:

- `sceneview/…/node/PhysicsNode.kt`: `PhysicsBody` class (Euler integration,
  9.8 m/s² gravity, floor collision, restitution, sleep detection) and
  `PhysicsNode` composable that hooks into `Node.onFrame` to drive position
  each frame.
- `samples/physics-demo`: standalone sample — tap to spawn bouncing spheres
  that fall and bounce off a floor slab; up to 10 simultaneous balls.
- `settings.gradle`: register `:samples:physics-demo` module.

Build verified: `:samples:physics-demo:assembleDebug` passes clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ThomasGorisse ThomasGorisse merged commit 562aec3 into main Mar 20, 2026
2 checks passed
@ThomasGorisse ThomasGorisse deleted the feat/physics-node branch March 20, 2026 19:27
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