Skip to content

sathishTSR/r3f-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

npm version

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)

npm install -g r3f-template

Local Installation

npm install r3f-template
npx r3f-template

๐ŸŽฏ Usage

Interactive Mode

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

$ 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:

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

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Sathish - GitHub


Made with โค๏ธ for the React Three Fiber community