|
1 | 1 | # 🚗 Three.js 3D Car Viewer |
2 | 2 |
|
3 | | -An interactive 3D car model viewer built with Three.js. This project demonstrates loading and manipulating 3D GLTF models in a web browser with keyboard controls, orbit camera, and fullscreen support. |
| 3 | +An interactive, high-end 3D car model viewer built with **Three.js** and **GSAP (GreenSock Animation Platform)**. It showcases a 3D model (GLB format) with automatic multi-angle cinematic camera paths, provides manual control capabilities, and opens with a premium loading screen transition. |
4 | 4 |
|
5 | | - |
6 | | - |
7 | | - |
| 5 | + |
| 6 | + |
| 7 | +--- |
8 | 8 |
|
9 | 9 | ## ✨ Features |
10 | 10 |
|
11 | | -- **3D Model Loading** - Load and display GLTF/GLB 3D models |
12 | | -- **Orbit Controls** - Rotate, pan, and zoom around the model with mouse |
13 | | -- **Keyboard Controls** - Move and rotate the 3D model using keyboard |
14 | | -- **Auto-Rotation** - Smooth automatic rotation of the camera view |
15 | | -- **Fullscreen Mode** - Double-click to toggle fullscreen |
16 | | -- **Responsive Design** - Automatically adapts to window resizing |
17 | | -- **Damping Effect** - Smooth camera movement with damping |
| 11 | +- **GSAP Loading Screen** - Minimalist brand layout featuring a thin horizontal loader line ("web line") that expands horizontally and a monospaced percentage counter counting up to 100% dynamically. |
| 12 | +- **Wipe-Down Reveal Transition** - Symmetrical slide-down curtain reveal that wipes the preloader away while fading/sliding loading elements up. |
| 13 | +- **Cinematic Entrance Sweep** - A majestic, smooth camera sweep that zooms in from a distance to establish the 3D scene in sync with the slide-down reveal. |
| 14 | +- **Multi-Angle Automated Paths** - Seamlessly loops through 4 cinematic camera tracks (Grand Reveal, Low Prowl, Rear Drama, Orbital Glide) with built-in camera drift simulating a handheld operator. |
| 15 | +- **Manual Orbit Controls** - Toggle to manual view with **Spacebar** to zoom, rotate, and pan around the model using OrbitControls. |
| 16 | +- **Seamless Re-Entry Blending** - When toggling back to Cinematic Mode, GSAP smoothly blends the camera position and focal target from the manual viewpoint back onto the cinematic track coordinates. |
| 17 | +- **Lighting Rig & Dynamic Underglow** - Warm key light casting shadow maps, cool fill, back-rim backlight, and an animated colored underglow spot under the model. |
| 18 | +- **Responsive Layout** - Automatically adapts camera aspect ratio and renderer frames to window resizing events. |
| 19 | +- **Automated CI/CD Deploy** - Configured with GitHub Actions to compile Vite production bundles and deploy to GitHub Pages on every push to the `main` branch. |
18 | 20 |
|
19 | | -## 🎮 Controls |
| 21 | +--- |
20 | 22 |
|
21 | | -### Mouse Controls |
| 23 | +## 🎮 Controls |
22 | 24 |
|
23 | | -| Action | Control | |
24 | | -| ----------- | ------------------ | |
25 | | -| Rotate view | Left-click + drag | |
26 | | -| Pan view | Right-click + drag | |
27 | | -| Zoom | Mouse wheel | |
| 25 | +### Mouse Controls (Free Camera Mode) |
| 26 | +- **Rotate view** - Left-click + drag |
| 27 | +- **Pan view** - Right-click + drag |
| 28 | +- **Zoom** - Mouse wheel |
28 | 29 |
|
29 | 30 | ### Keyboard Controls |
| 31 | +- **Spacebar** - Toggle between automated Cinematic Mode and manual Free Camera Mode. |
| 32 | +- **1, 2, 3, 4** - Seamlessly transition to a specific cinematic camera path target. |
| 33 | +- **Double-click (on Canvas)** - Toggle fullscreen mode. |
30 | 34 |
|
31 | | -| Key | Action | |
32 | | -| ------------ | ------------------------ | |
33 | | -| `W` | Move model forward (Z+) | |
34 | | -| `S` | Move model backward (Z-) | |
35 | | -| `A` | Move model left (X+) | |
36 | | -| `D` | Move model right (X-) | |
37 | | -| `Q` | Rotate model left | |
38 | | -| `E` | Rotate model right | |
39 | | -| `Z` | Move model down (Y-) | |
40 | | -| `X` | Move model up (Y+) | |
41 | | -| `Arrow Keys` | Pan camera | |
| 35 | +--- |
42 | 36 |
|
43 | | -### Other |
| 37 | +## 📁 Modular Project Structure |
44 | 38 |
|
45 | | -- **Double-click** - Toggle fullscreen mode |
| 39 | +The project has been refactored into a highly clean, decoupled, and modular structure under `src/`: |
| 40 | + |
| 41 | +``` |
| 42 | +threejs/ |
| 43 | +├── .github/ |
| 44 | +│ └── workflows/ |
| 45 | +│ ├── deploy.yml # CI/CD GitHub Pages deployment workflow |
| 46 | +│ └── static.yml # Static hosting check workflow |
| 47 | +├── media/ |
| 48 | +│ └── preview.webp # README live preview media asset |
| 49 | +├── public/ |
| 50 | +│ └── models/ |
| 51 | +│ └── car.glb # 3D car model GLB asset |
| 52 | +├── src/ |
| 53 | +│ ├── core/ |
| 54 | +│ │ ├── Scene.js # Scene creation, fog, and background colors |
| 55 | +│ │ ├── Camera.js # Perspective camera, path configs, GSAP transition manager |
| 56 | +│ │ ├── Renderer.js # WebGLRenderer setups, shadow configurations, resize hooks |
| 57 | +│ │ └── Controls.js # OrbitControls initialization and parameters |
| 58 | +│ ├── lights/ |
| 59 | +│ │ └── Lighting.js # Lights rig (ambient, directional, point light underglow) |
| 60 | +│ ├── objects/ |
| 61 | +│ │ ├── Ground.js # Circular metallic ground plane configuration |
| 62 | +│ │ └── CarModel.js # GLTF loading, bounds mapping, sub-mesh shadow casting |
| 63 | +│ ├── ui/ |
| 64 | +│ │ └── CinematicUI.js # Letterbox bars, labels, dots, and GSAP preloader fades |
| 65 | +│ └── index.css # Global stylesheet, resets, and preloader overlays styling |
| 66 | +├── index.html # HTML entry point (links index.css and main.js) |
| 67 | +├── main.js # Application orchestrator, event bindings, and animation loops |
| 68 | +├── package.json # Project dependencies and building scripts |
| 69 | +├── Dockerfile # Docker container settings |
| 70 | +└── README.md # This documentation file |
| 71 | +``` |
| 72 | + |
| 73 | +--- |
46 | 74 |
|
47 | 75 | ## 🚀 Getting Started |
48 | 76 |
|
49 | 77 | ### Prerequisites |
50 | | - |
51 | 78 | - Node.js (v18 or higher recommended) |
52 | 79 | - npm |
53 | 80 |
|
54 | | -### Installation |
| 81 | +### Installation & Run |
55 | 82 |
|
56 | 83 | 1. Clone the repository: |
57 | | - |
58 | 84 | ```bash |
59 | 85 | git clone <repository-url> |
60 | | - cd threejs |
| 86 | + cd threejs-3d-car-viewer |
61 | 87 | ``` |
62 | 88 |
|
63 | 89 | 2. Install dependencies: |
64 | | - |
65 | 90 | ```bash |
66 | 91 | npm install |
67 | 92 | ``` |
68 | 93 |
|
69 | | -3. Start the development server: |
70 | | - |
| 94 | +3. Run the local development server: |
71 | 95 | ```bash |
72 | 96 | npm run dev |
73 | 97 | ``` |
74 | 98 |
|
75 | | -4. Open your browser and navigate to the URL shown in the terminal (usually `http://localhost:5173`) |
76 | | - |
77 | | -## 📦 Build |
78 | | - |
79 | | -To build the project for production: |
| 99 | +4. Open your browser and navigate to the local URL (usually `http://localhost:5173/threejs-3d-car-viewer/`). |
80 | 100 |
|
| 101 | +### Production Build & Preview |
| 102 | +To compile the minified bundle: |
81 | 103 | ```bash |
82 | 104 | npm run build |
83 | 105 | ``` |
84 | | - |
85 | | -To preview the production build: |
86 | | - |
| 106 | +To run the production bundle locally: |
87 | 107 | ```bash |
88 | 108 | npm run preview |
89 | 109 | ``` |
90 | | - |
91 | | -## 🐳 Docker |
92 | | - |
93 | | -### Pull from Docker Hub |
94 | | - |
95 | | -The image is available on Docker Hub: |
96 | | - |
97 | | -```bash |
98 | | -docker pull omid2831/omid-threejs-app |
99 | | -docker run -p 3000:3000 omid2831/omid-threejs-app |
100 | | -``` |
101 | | - |
102 | | -🔗 **Docker Hub:** [omid2831/omid-threejs-app](https://hub.docker.com/r/omid2831/omid-threejs-app) |
103 | | - |
104 | | -### Build Locally |
105 | | - |
106 | | -Or build and run locally with Docker: |
107 | | - |
108 | | -```bash |
109 | | -# Build the image |
110 | | -docker build -t threejs-viewer . |
111 | | - |
112 | | -# Run the container |
113 | | -docker run -p 3000:3000 threejs-viewer |
114 | | -``` |
115 | | - |
116 | | -Then open `http://localhost:3000` in your browser. |
117 | | - |
118 | | -## 📁 Project Structure |
119 | | - |
120 | | -``` |
121 | | -threejs/ |
122 | | -├── public/ |
123 | | -│ └── models/ |
124 | | -│ └── car.glb # 3D car model |
125 | | -├── index.html # HTML entry point |
126 | | -├── main.js # Main Three.js application |
127 | | -├── package.json # Project dependencies |
128 | | -├── Dockerfile # Docker configuration |
129 | | -└── README.md # This file |
130 | | -``` |
131 | | - |
132 | | -## 🛠️ Technologies Used |
133 | | - |
134 | | -- **[Three.js](https://threejs.org/)** - 3D graphics library |
135 | | -- **[Vite](https://vitejs.dev/)** - Fast build tool and dev server |
136 | | -- **[GLTFLoader](https://threejs.org/docs/#examples/en/loaders/GLTFLoader)** - For loading 3D models |
137 | | -- **[OrbitControls](https://threejs.org/docs/#examples/en/controls/OrbitControls)** - Camera control system |
138 | | - |
139 | | -## 📄 License |
140 | | - |
141 | | -ISC |
142 | | - |
143 | | ---- |
144 | | - |
145 | | -Made with ❤️ and Three.js |
0 commit comments