r3f-template
Version:
CLI to scaffold React Three Fiber templates with or without physics( Rapier )
234 lines (189 loc) ⢠6.69 kB
Markdown
[](https://www.npmjs.com/package/r3f-template)
# r3f-template
A CLI tool to scaffold React Three Fiber projects with or without physics (Rapier). Quickly bootstrap your 3D web applications with modern tooling and best practices.
## š Features
- **Interactive CLI**: Choose your project name, language, and features
- **Language Support**:
- **TypeScript**: Full type safety with TypeScript configuration
- **JavaScript**: Simple JavaScript setup for quick prototyping
- **Two Template Options**:
- **Basic Template**: React Three Fiber with essential 3D features
- **Physics Template**: Includes Rapier physics engine for realistic interactions
- **Modern Stack**: Built with Vite, ESLint, and modern tooling
- **Ready to Use**: Pre-configured with all necessary dependencies
## š¦ Installation
### Global Installation (Recommended)
```bash
npm install -g r3f-template
```
### Local Installation
```bash
npm install r3f-template
npx r3f-template
```
## šÆ Usage
### Interactive Mode
```bash
r3f-template
```
The CLI will prompt you for:
- **Project Name**: The name of your new project
- **Language**: Choose between TypeScript or JavaScript
- **Template**: Choose between Basic or Physics (Rapier) template
### Example Session
```bash
$ r3f-template
? Enter your project name: my-3d-game
? Choose your language: TypeScript
? Choose your template: Physics (Rapier)
ā
Project created in ./my-3d-game
š Run 'cd my-3d-game'
š Run 'npm install'
š Run 'npm run dev'
```
## š Template Structure
### Basic Template (TypeScript)
```
my-project/
āāā src/
ā āāā Components/
ā ā āāā Lights.tsx
ā ā āāā Suzanne.tsx
ā āāā App.tsx
ā āāā App.css
ā āāā index.css
ā āāā main.tsx
ā āāā vite-env.d.ts
āāā public/
ā āāā suzanne.glb
āāā package.json
āāā vite.config.ts
āāā tsconfig.json
āāā tsconfig.app.json
āāā tsconfig.node.json
āāā eslint.config.js
```
### Basic Template (JavaScript)
```
my-project/
āāā src/
ā āāā Components/
ā ā āāā Lights.jsx
ā ā āāā Suzanne.jsx
ā āāā App.jsx
ā āāā App.css
ā āāā index.css
ā āāā main.jsx
āāā public/
ā āāā suzanne.glb
āāā package.json
āāā vite.config.js
āāā eslint.config.js
```
### Physics Template (TypeScript)
```
my-project/
āāā src/
ā āāā Components/
ā ā āāā Lights.tsx
ā ā āāā Player.tsx
ā ā āāā Ground.tsx
ā ā āāā Suzanne.tsx
ā āāā App.tsx
ā āāā App.css
ā āāā index.css
ā āāā main.tsx
ā āāā vite-env.d.ts
āāā public/
ā āāā suzanne.gltf
āāā package.json
āāā vite.config.ts
āāā tsconfig.json
āāā tsconfig.app.json
āāā tsconfig.node.json
āāā eslint.config.js
```
### Physics Template (JavaScript)
```
my-project/
āāā src/
ā āāā Components/
ā ā āāā Lights.jsx
ā ā āāā Player.jsx
ā ā āāā Ground.jsx
ā ā āāā Suzanne.jsx
ā āāā App.jsx
ā āāā App.css
ā āāā index.css
ā āāā main.jsx
āāā public/
ā āāā suzanne.gltf
āāā package.json
āāā vite.config.js
āāā eslint.config.js
```
## š ļø Dependencies
### Basic Template
- `@react-three/drei` - Useful helpers for React Three Fiber
- `@react-three/fiber` - React renderer for Three.js
- `react` & `react-dom` - React core
- `three` - 3D library
- `vite` - Build tool
- `eslint` - Code linting
- `typescript` (TypeScript template only) - Type safety
### Physics Template (Additional)
- `@react-three/rapier` - Physics engine integration
## š® Getting Started
After creating your project:
```bash
cd my-project
npm install
npm run dev
```
Your 3D application will be available at `http://localhost:5173`
## šØ What's Included
### Basic Template Features
- **3D Scene Setup**: Pre-configured Canvas with proper lighting
- **Suzanne Model**: Classic 3D model for testing
- **TypeScript Support**: Full type safety (TypeScript template)
- **Hot Reload**: Fast development with Vite
- **ESLint**: Code quality and consistency
### Physics Template Features
- **Rapier Physics**: Realistic physics simulation
- **Player Controller**: First-person movement with keyboard controls (WASD/Arrow keys for movement, Space for jumping)
- **Mouse Look**: Pointer lock controls for camera rotation
- **Collision Detection**: Proper physics bodies and colliders
- **Interactive Environment**: Physics-enabled ground plane
- **Camera Follow**: Camera automatically follows the player position
## š® Controls (Physics Template)
The physics template includes a fully functional player controller with controls already implemented:
- **Movement**: Use WASD keys or Arrow keys to move
- **Jump**: Press Spacebar to jump
- **Mouse Look**: Click to lock mouse pointer and look around
- **Exit Mouse Lock**: Press Escape to unlock mouse
**Note**: All controls are pre-configured and ready to use - no additional setup required!
## šÆ Use Cases
- **3D Web Applications**: Interactive 3D experiences
- **Games**: Browser-based 3D games
- **Visualizations**: Data and scientific visualizations
- **Prototypes**: Quick 3D concept validation
- **Educational Projects**: Learning Three.js and React Three Fiber
## š§ Customization
Both templates are fully customizable:
- **Add Models**: Replace or add 3D models in the `public/` directory
- **Modify Components**: Edit components in `src/Components/`
- **Extend Physics**: Add more physics bodies and interactions
- **Styling**: Customize CSS in `src/App.css` and `src/index.css`
## š Resources
- [React Three Fiber Documentation](https://docs.pmnd.rs/react-three-fiber)
- [Three.js Documentation](https://threejs.org/docs/)
- [Rapier Physics](https://rapier.rs/)
- [Vite Documentation](https://vitejs.dev/)
## š¤ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## š License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## šØāš» Author
**Sathish** - [GitHub](https://github.com/sathishTSR)
---
Made with ā¤ļø for the React Three Fiber community