All checks were successful
Build / build (push) Successful in 1m21s
Major changes: - Change asteroid config to use single scale number instead of Vector3 - Move planetTextures to public/assets/materials/planetTextures - Add GLB path configuration for start base - Fix inspector toggle to work bidirectionally - Add progression system support Asteroid Scaling Changes: - Update AsteroidConfig interface to use 'scale: number' instead of 'scaling: Vector3Array' - Modify RockFactory.createRock() to accept single scale parameter - Update level serializer/deserializer to use uniform scale - Simplify level generation code in levelEditor and levelGenerator - Update validation to check for positive number instead of 3-element array Asset Organization: - Move public/planetTextures → public/assets/materials/planetTextures - Update all texture path references in planetTextures.ts (210 paths) - Update default texture paths in createSun.ts and levelSerializer.ts - Update CLAUDE.md documentation with new asset structure Start Base Improvements: - Add baseGlbPath and landingGlbPath to StartBaseConfig - Update StarBase.buildStarBase() to accept GLB path parameter - Add position parameter support to StarBase - Store GLB path in mesh metadata for serialization - Add UI field in level editor for base GLB path Inspector Toggle: - Fix 'i' key to toggle inspector on/off instead of only on - Use scene.debugLayer.isVisible() for state checking - Consistent with ReplayManager implementation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
147 lines
5.0 KiB
Markdown
147 lines
5.0 KiB
Markdown
# CLAUDE.md
|
|
|
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
|
|
## Project Overview
|
|
|
|
This is a WebXR-based space shooter game built with BabylonJS, designed for VR headsets (primarily Meta Quest 2). Players pilot a spaceship through asteroid fields with multiple difficulty levels, using VR controllers for movement and shooting.
|
|
|
|
## Development Commands
|
|
|
|
```bash
|
|
# Build the project (TypeScript compilation + Vite build)
|
|
npm run build
|
|
|
|
# Preview production build locally
|
|
npm run preview
|
|
|
|
# Copy Havok physics WASM file (needed after clean installs)
|
|
npm run havok
|
|
|
|
# Generate speech audio files (requires OpenAI API)
|
|
npm run speech
|
|
```
|
|
|
|
**Note**: Do not run `npm run dev` per global user instructions.
|
|
|
|
## Core Architecture
|
|
|
|
### Scene Management Pattern
|
|
The project uses a singleton pattern for scene access via `DefaultScene`:
|
|
- `DefaultScene.MainScene` - Primary game scene
|
|
- `DefaultScene.DemoScene` - Demo/attract mode scene
|
|
- `DefaultScene.XR` - WebXR experience instance
|
|
|
|
All game objects reference these static properties rather than passing scene instances.
|
|
|
|
### Level System
|
|
Levels implement the `Level` interface with:
|
|
- `initialize()` - Setup level geometry and physics
|
|
- `play()` - Start level gameplay
|
|
- `dispose()` - Cleanup
|
|
- `getReadyObservable()` - Async loading notification
|
|
|
|
Current implementation: `Level1` with 5 difficulty modes (recruit, pilot, captain, commander, test)
|
|
|
|
### Ship and Controller System
|
|
The `Ship` class manages:
|
|
- Player spaceship rendering and physics
|
|
- VR controller input handling (Meta Quest 2 controllers)
|
|
- Weapon firing system
|
|
- Audio for thrust and weapons
|
|
- Camera parent transform for VR positioning
|
|
|
|
Controllers are added dynamically via WebXR observables when detected.
|
|
|
|
### Physics and Collision
|
|
- Uses Havok Physics engine (WASM-based)
|
|
- Fixed timestep: 1/45 second with 5 sub-steps
|
|
- Zero gravity environment
|
|
- Collision detection for projectiles vs asteroids
|
|
- Physics bodies use `PhysicsAggregate` pattern
|
|
|
|
### Asteroid Factory Pattern
|
|
`RockFactory` uses:
|
|
- Pre-loaded mesh instances for performance
|
|
- Particle system pooling for explosions (pool size: 10)
|
|
- Observable pattern for score events via collision callbacks
|
|
- Dynamic spawning based on difficulty configuration
|
|
|
|
### Rendering Optimization
|
|
The codebase uses rendering groups to control draw order:
|
|
- Group 1: Particle effects (explosions)
|
|
- Group 3: Ship cockpit and UI (always rendered on top)
|
|
|
|
This prevents z-fighting and ensures HUD elements are always visible in VR.
|
|
|
|
### Audio Architecture
|
|
Uses BabylonJS AudioEngineV2:
|
|
- Requires unlock via user interaction before VR entry
|
|
- Spatial audio for thrust sounds
|
|
- StaticSound for weapon fire
|
|
- Audio engine passed to Level and Ship constructors
|
|
|
|
### Difficulty System
|
|
Each difficulty level configures:
|
|
- `rockCount` - Number of asteroids to destroy
|
|
- `forceMultiplier` - Asteroid movement speed
|
|
- `rockSizeMin/Max` - Size range of asteroids
|
|
- `distanceMin/Max` - Spawn distance from player
|
|
|
|
Located in `level1.ts:getDifficultyConfig()`
|
|
|
|
## Key Technical Constraints
|
|
|
|
### WebXR Requirements
|
|
- Must have `navigator.xr` support
|
|
- Controllers are added asynchronously via observables
|
|
- Camera must be parented to ship transform before entering VR
|
|
- XR features enabled: LAYERS with multiview for performance
|
|
|
|
### Asset Loading
|
|
- 3D models: GLB format (cockpit, asteroids)
|
|
- Particle systems: JSON format in `public/systems/`
|
|
- Planet textures: Organized by biome in `public/assets/materials/planetTextures/`
|
|
- Audio: MP3 format in public root
|
|
|
|
### Performance Considerations
|
|
- Hardware scaling set to match device pixel ratio
|
|
- Particle system pooling prevents allocation during gameplay
|
|
- Instance meshes used where possible
|
|
- Physics sub-stepping for stability without high timestep cost
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
src/
|
|
main.ts - Entry point, game initialization, WebXR setup
|
|
defaultScene.ts - Singleton scene accessor
|
|
level.ts - Level interface
|
|
level1.ts - Main game level implementation
|
|
ship.ts - Player ship, controls, weapons
|
|
rockFactory.ts - Rock factory and collision handling
|
|
scoreboard.ts - In-cockpit HUD display
|
|
createSun.ts - Sun mesh generation
|
|
createPlanets.ts - Procedural planet generation
|
|
planetTextures.ts - Planet texture library
|
|
demo.ts - Attract mode implementation
|
|
|
|
public/
|
|
systems/ - Particle system definitions
|
|
assets/
|
|
materials/
|
|
planetTextures/ - Biome-based planet textures
|
|
themes/ - Themed assets
|
|
cockpit*.glb - Ship interior models
|
|
asteroid*.glb - Asteroid mesh variants
|
|
*.mp3 - Audio assets
|
|
```
|
|
|
|
## Important Implementation Notes
|
|
|
|
- Never modify git config or use force push operations
|
|
- Deploy target hostname: `space.digital-experiment.com` (from package.json)
|
|
- TypeScript target is ES6 with ESNext modules
|
|
- Vite handles bundling and dev server (though dev mode is disabled per user preference)
|
|
- Inspector can be toggled with 'i' key for debugging (only in development)
|