1.9 KiB
1.9 KiB
OpenSpec Change: enterprise-gaming-r3f-physics-core
- Change ID: enterprise-gaming-r3f-physics-core
- Package:
@suaveplan/r3f-physics-core - Category: gaming/physics
- Target path:
gaming/physics/r3f-physics-core - Status: PROPOSED
- Date: 2026-04-24
Summary
Deliver @suaveplan/r3f-physics-core on the genesis branch from scratch at enterprise quality. The package provides a physics engine abstraction layer for React Three Fiber: a PhysicsProvider React context wraps any physics backend (Rapier, Cannon, custom); useRigidBody(), useCollider(), and usePhysicsWorld() hooks provide access to physics primitives in a backend-agnostic way. The PhysicsBackend interface matches @suaveplan/character-physics's PhysicsBackend + @suaveplan/vehicle-physics's VehiclePhysicsBackend. Genesis adds structured errors, OTel step-time histogram, and 100% coverage.
Available workspace deps
@suaveplan/error, @suaveplan/types, @suaveplan/events, react, @react-three/fiber, three.
Public API surface
function PhysicsProvider(props: PhysicsProviderProps): JSX.Element
// backend, gravity, fixedStep, debug
function usePhysicsWorld(): PhysicsWorld
function useRigidBody(options: RigidBodyOptions): RigidBodyHandle
function useCollider(body: RigidBodyHandle, desc: ColliderDesc): ColliderHandle
interface PhysicsWorld {
step(dt: number): void
raycast(origin: Vec3, dir: Vec3, maxDist: number): RaycastHit | null
readonly bodies: ReadonlyMap<string, RigidBodyHandle>
}
File layout
gaming/physics/r3f-physics-core/
package.json / tsconfig.json / vitest.config.ts
src/
index.ts / error-codes.ts
types/common.ts + md
context/physics-provider.tsx + md + test
hooks/
use-physics-world.ts + md + test
use-rigid-body.ts + md + test
use-collider.ts + md + test
tests/integration.test.ts