A modular Three.js VR experience featuring a floating island with teleportation controls.
The project follows Three.js best practices with a modular folder structure:
src/
├── components/ # Main application components
│ └── VRApp.ts # Main VR application orchestrator
├── controls/ # Input handling and controls
│ ├── DesktopControls.ts # WASD + pointer lock controls
│ └── VRControls.ts # VR controller handling
├── loaders/ # Asset loading utilities
│ └── GLTFAssetLoader.ts # GLTF model loader
├── scenes/ # Scene setup and management
│ └── IslandScene.ts # Island scene configuration
├── types/ # TypeScript type definitions
│ └── index.ts # Shared interfaces and types
├── utils/ # Utility functions
│ └── RendererUtils.ts # Renderer setup utilities
├── index.ts # Barrel exports
└── main.ts # Application entry point
- Desktop Controls: WASD movement with pointer lock
- VR Support: Full WebXR compatibility with controller tracking
- Teleportation: Point-and-click teleportation in VR
- Smooth Rotation: Thumbstick rotation in VR
- Asset Loading: GLTF model loading with proper positioning
- TypeScript: Full type safety with proper interfaces
- W/A/S/D or Arrow Keys: Movement
- Mouse: Look around (click to enable pointer lock)
- Controller Triggers: Teleportation (point and trigger)
- Right Thumbstick: Smooth rotation
- Natural Movement: Room-scale tracking
The main application class that orchestrates all components and manages the render loop.
Handles keyboard input and pointer lock controls for desktop experience.
Manages VR controllers, teleportation system, and smooth rotation.
Configures the 3D scene with lighting, background, and helper objects.
Handles loading and positioning of 3D models with proper scaling and centering.
Utility functions for renderer setup and window resize handling.
- Node.js
- pnpm (or npm/yarn)
pnpm install
pnpm devpnpm build- three: Core Three.js library
- @types/three: TypeScript definitions for Three.js
- Modularity: Each component has a single responsibility
- Reusability: Components can be easily reused or extended
- Maintainability: Clean separation of concerns
- Type Safety: Full TypeScript support with proper interfaces
- Scalability: Easy to add new features or modify existing ones
To add new features:
- New Scenes: Add classes to
src/scenes/ - New Controls: Add classes to
src/controls/ - New Assets: Add loaders to
src/loaders/ - New Components: Add to
src/components/ - New Types: Add interfaces to
src/types/
Each new module should follow the established patterns for consistency and maintainability.