A simple, clean 3D model viewer built with React and Three.js for displaying GLTF models.
- Load and display GLTF/GLB models
- Orbit controls (rotate, zoom, pan)
- Auto-scaling and centering of models
- Professional lighting setup
- Responsive design
- Loading states and error handling
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm run buildmodel-viewer/
├── public/
│ └── models/ # Put your GLTF files here
│ ├── your-model.gltf
│ ├── textures/
│ └── *.bin
├── src/
│ ├── components/
│ │ ├── ModelViewer.jsx # Main 3D canvas component
│ │ └── Model.jsx # GLTF loader component
│ ├── App.jsx # Main app
│ ├── App.css
│ ├── main.jsx
│ └── index.css
├── package.json
└── vite.config.js
Create a public/models/ folder and place your GLTF files there:
public/
└── models/
├── robot.gltf
├── robot.bin
└── textures/
└── robot_texture.png
In src/App.jsx, change the model path:
const modelPath = '/models/robot.gltf'npm run devYour browser will open at http://localhost:3000
- Left Click + Drag: Rotate the model
- Right Click + Drag: Pan the camera
- Scroll Wheel: Zoom in/out
In ModelViewer.jsx:
<PerspectiveCamera makeDefault position={[0, 0, 5]} fov={50} />In ModelViewer.jsx:
<ambientLight intensity={0.5} />
<directionalLight position={[10, 10, 5]} intensity={1} />Use the Auto Rotate toggle button in the UI header.
In ModelViewer.jsx, modify the Environment preset:
<Environment preset="sunset" /> // Options: sunset, dawn, night, warehouse, forest, apartment, studio, city, park, lobby- React 18 - UI framework
- Three.js - 3D rendering engine
- @react-three/fiber - React renderer for Three.js
- @react-three/drei - Useful helpers for React Three Fiber
- Vite - Fast build tool and dev server
The auto-scaling should handle this, but you can manually adjust in Model.jsx:
const scale = 2 / maxDim // Change the 2 to make bigger/smaller- Reduce model complexity
- Optimize textures (use smaller sizes)
- Use GLB format instead of GLTF (single file, faster to load)
- Multiple model selection
- File upload functionality
- Screenshot/export features
- Annotation tools
- Material/texture editing
- Animation playback
- VR support