Skip to content

Commit 7f4733e

Browse files
committed
Added drive mode animations & API functionality
1 parent 7dbfc7f commit 7f4733e

5 files changed

Lines changed: 342 additions & 138 deletions

File tree

README.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
A small demo that shows a 3D car viewer using three.js and a GLTF model (Ferrari F40).
44

5+
## Screenshots
6+
7+
### Home (Showroom) Mode
8+
<img src="images/park-mode.png" alt="Showroom Mode" width="50%">
9+
10+
*The car is displayed in a dark showroom with dramatic spotlights, parking brake engaged*
11+
12+
### Drive Mode - Day
13+
<img src="images/drive-mode-day.png" alt="Drive Mode - Day" width="50%">
14+
15+
*Driving simulation with bright blue sky, animated road, and lane markings*
16+
17+
### Drive Mode - Night
18+
<img src="images/drive-mode-night.png" alt="Drive Mode - Night" width="50%">
19+
20+
*Night driving with dark sky and ambient lighting*
21+
522
View online
623

724
- The demo is automatically deployed to GitHub Pages:
@@ -34,18 +51,15 @@ Camera Info panel (press 'I')
3451
- Target: orbit target (x,y,z)
3552
- Distance: distance from camera to target
3653
- Azimuth & Polar angles in degrees
54+
- **Speed Simulation**: Interactive slider (0-75 mph) to control animation speed in Drive mode
3755
- Buttons:
3856
- Copy — copies camera state JSON to clipboard (position, target, distance, azimuthDeg, polarDeg)
39-
- Set Home — saves your current view as preset named "Home"
40-
- Go Home — moves the camera to the saved Home preset
41-
- Preset manager inside the panel:
42-
- Select a preset, then Go / Set (save current) / Delete
43-
- Import — paste a JSON payload like:
44-
{
45-
"position": [x, y, z],
46-
"target": [x, y, z]
47-
}
48-
- Presets are stored in localStorage under the key: `cameraPresets` (the old `cameraHome` is migrated automatically if present).
57+
- Day Mode / Night Mode — toggles between day (bright blue sky) and night (dark sky) lighting
58+
- Sim Brake Enable/Release — toggles between Home and Drive camera views
59+
- Default presets:
60+
- Home: `[-4.358857444267401, 1.5797084394163963, 3.222751650234066]`
61+
- Drive: `[0.12909591647276278, 2.215759854813773, -5.849405778042717]`
62+
- Presets are stored in localStorage under the key: `cameraPresets` (the old `cameraHome` is migrated automatically if present).
4963

5064
Park brake simulation & signals
5165

@@ -54,6 +68,19 @@ Park brake simulation & signals
5468
- Edge behavior:
5569
- 1 -> 0 (released) triggers transition to the Drive preset (if present).
5670
- 0 -> 1 (engaged) triggers transition to the Home preset (if present).
71+
- **Speed Control**:
72+
- In Drive mode, the animation speed is controlled by the current speed setting (0-75 mph).
73+
- Speed can be set via the slider in the Camera Info panel, or programmatically via the API.
74+
- Speeds above 75 mph are automatically clamped to 75 mph for animation purposes.
75+
- At 0 mph, the road/environment animation stops (but wheels still rotate slowly).
76+
- At 50 mph, the animation runs at base speed.
77+
- At 75 mph, the animation runs at 1.5x base speed.
78+
- Wheel rotation speed scales proportionally with the set speed.
79+
- Visual modes:
80+
- **Home (Showroom Mode)**: Dark background with spotlights, static environment, car displayed in showroom setting.
81+
- **Drive Mode**: Animated road moving toward the car, lane markings and trees moving to create illusion of travel. Animation speed controlled by speed setting.
82+
- **Day Mode**: Bright blue sky (#87ceeb), bright ambient lighting (0.6 intensity)
83+
- **Night Mode**: Dark night sky (#0a0a2e), dim ambient lighting (0.3 intensity)
5784

5885
Integration API (for parent application)
5986

@@ -64,16 +91,27 @@ Integration API (for parent application)
6491
- goToPreset(name, duration?) — Smoothly move to the preset (duration in ms).
6592
- animateTo(targetPosition, targetTarget, duration) — Animate to given THREE.Vector3 positions.
6693
- receiveVehicleSignal(signalName, value) — Forwards signals into the viewer.
94+
- setDayMode(isDay) — Set day/night mode. Pass `true` for day, `false` for night.
95+
- getDayMode() — Returns current day/night mode state (true = day, false = night).
96+
- toggleDayNight() — Toggles between day and night mode, returns new state.
97+
- **setSpeed(mph)** — Set the current speed in mph (0-75, clamped at 75). Controls animation speed in Drive mode.
98+
- **getSpeed()** — Returns the current speed setting in mph.
99+
- **getAnimationSpeed()** — Returns the current animation speed multiplier (calculated from speed).
67100

68101
- Convenience globals:
69102
- window.receiveVehicleSignal(signalName, value)
70103
- e.g. window.receiveVehicleSignal('park_brake', 0) — triggers the park_brake handling.
104+
- e.g. window.receiveVehicleSignal('speed', 65) — sets speed to 65 mph.
105+
- Signal names containing 'speed' or 'velocity' are treated as speed signals (in mph).
71106
- window.setParkingBrakeState(value)
72107
- e.g. window.setParkingBrakeState(1)
108+
- **window.setCarSpeed(mph)**
109+
- e.g. window.setCarSpeed(55) — sets speed to 55 mph (clamped at 75).
73110

74111
Implementation notes
75112

76113
- Built with three.js r128 and uses `OrbitControls` + `GLTFLoader` for the model.
114+
- **On page load/refresh, the camera ALWAYS starts in Home (showroom) mode** with the default preset position, ensuring a consistent starting view.
77115
- Presets are stored in localStorage as `{ <name>: { position: [...], target: [...] } }`.
78116
- The viewer auto-imports an example "Drive" preset (from demo data) on first run if no preset exists.
79117
- Camera is constrained so it cannot go underneath the ground plane and polar angle is limited to prevent under-floor views.

0 commit comments

Comments
 (0)