The 3D-Car project is an application that displays and controls a 3D car model in a browser using Unity WebGL build. Users can interact with the car through a web interface embedded in Playground, which provides APIs to control the car's functions.
- Blender: Editing and optimizing the 3D car model.
- Unity WebGL: Exporting the car model as WebGL to run in a browser.
- HTML, JavaScript: Web interface for displaying and controlling the car.
- Edit the car model in Blender and export it to Unity.
- In Unity, set up components and program the car's functions.
- Build the Unity project as WebGL and embed it into Playground.
- Playground provides APIs to communicate with the WebGL build.
- The HTML interface receives data from the Playground API and controls the car model.
3D-Car/
¦-- Playground Unity/ # Folder containing all Unity assets
¦-- Build/ # Unity WebGL build
¦-- Web/
¦ +-- MainIndex.html # Folder containing HTML files and web resources
¦ +-- FromUnity.js # Handles interaction with MainIndex.html from Unity
¦-- README.md # Project documentation
- Run WebGL Build:
- Open the Build/ folder and run the WebGL build.
- Embed MainIndex.html into Playground to connect with the API.
- Playground sends control data to WebGL via API.
- Actions such as changing the car color, adjusting speed, etc., are executed using Unity functions.
For any suggestions or improvements, please open an issue or submit a pull request!
The project is under development, please update the documentation as changes occur.
Vehicle.AverageSpeed
Vehicle.Body.Windshield.Front.Wiping.Mode
Vehicle.Body.Windshield.Rear.Wiping.Mode
Vehicle.Body.Trunk.Front.IsLocked
Vehicle.Body.Trunk.Front.IsOpen
Vehicle.Body.Trunk.Front.Position
Vehicle.Body.Trunk.Front.IsLightOn
Vehicle.Body.Trunk.Rear.IsLocked
Vehicle.Body.Trunk.Rear.IsOpen
Vehicle.Body.Trunk.Rear.Position
Vehicle.Body.Trunk.Rear.IsLightOn
Vehicle.Cabin.Door.Row1.DriverSide.IsLocked
Vehicle.Cabin.Door.Row1.DriverSide.IsOpen
Vehicle.Cabin.Door.Row1.DriverSide.Position
Vehicle.Cabin.Door.Row1.DriverSide.Window.IsOpen
Vehicle.Cabin.Door.Row1.DriverSide.Window.Position
Vehicle.Cabin.Seat.Row1.DriverSide.Position
Vehicle.Cabin.Seat.Row1.DriverSide.Height
Vehicle.Cabin.Door.Row1.PassengerSide.IsLocked
Vehicle.Cabin.Door.Row1.PassengerSide.IsOpen
Vehicle.Cabin.Door.Row1.PassengerSide.Position
Vehicle.Cabin.Door.Row1.PassengerSide.Window.IsOpen
Vehicle.Cabin.Door.Row1.PassengerSide.Window.Position
Vehicle.Cabin.Seat.Row1.PassengerSide.Position
Vehicle.Cabin.Seat.Row1.PassengerSide.Height
Vehicle.Cabin.Door.Row2.DriverSide.IsLocked
Vehicle.Cabin.Door.Row2.DriverSide.IsOpen
Vehicle.Cabin.Door.Row2.DriverSide.Position
Vehicle.Cabin.Door.Row2.DriverSide.Window.IsOpen
Vehicle.Cabin.Door.Row2.DriverSide.Window.Position
Vehicle.Cabin.Seat.Row2.DriverSide.Position
Vehicle.Cabin.Seat.Row2.DriverSide.Height
Vehicle.Cabin.Door.Row2.PassengerSide.IsLocked
Vehicle.Cabin.Door.Row2.PassengerSide.IsOpen
Vehicle.Cabin.Door.Row2.PassengerSide.Position
Vehicle.Cabin.Door.Row2.PassengerSide.Window.IsOpen
Vehicle.Cabin.Door.Row2.PassengerSide.Window.Position
Vehicle.Cabin.Seat.Row2.PassengerSide.Position
Vehicle.Cabin.Seat.Row2.PassengerSide.Height
Vehicle.Body.Lights.Beam.High.IsOn
Vehicle.Body.Lights.Beam.Low.IsOn
Vehicle.Body.Lights.Brake.IsActive
Vehicle.Body.Lights.Hazard.IsSignaling
Vehicle.Body.Lights.LicensePlate.IsOn
Vehicle.Cabin.Light.AmbientLight.Row1.DriverSide.Color
Vehicle.Cabin.Light.AmbientLight.Row1.DriverSide.IsLightOn
Vehicle.Cabin.Light.AmbientLight.Row1.PassengerSide.Color
Vehicle.Cabin.Light.AmbientLight.Row1.PassengerSide.IsLightOn
Vehicle.Body.Mirrors.DriverSide.IsFolded
Vehicle.Body.Mirrors.DriverSide.IsLocked
Vehicle.Body.Mirrors.PassengerSide.IsFolded
Vehicle.Body.Mirrors.PassengerSide.IsLocked
For example:
let OBJECT_MAPPING = [
{
// The name of the Unity object to be controlled
entity: 'row1_door1',
// Placeholder for additional behavior (e.g., "islocked" status check)
behaviour: "",
// The key or field name in the browser used to control this feature
optionsName: 'row1_door1_open',
// The default API path used to retrieve this object's state
api: 'Vehicle.Cabin.Door.Row1.Driver.IsOpen',
// The data type expected from the API or browser (in this case, true/false)
dataType: "boolean",
// Last known value to prevent unnecessary updates
lastValue: false,
// Maps the boolean value from browser or API to corresponding action in Unity
actionMaps: {
"true": "true", // "true" from browser/API triggers Unity action "true"
"false": "false" // "false" from browser/API triggers Unity action "false"
}
},
// ...
];- Unity Hub (latest version)
- Unity Editor version 2022.3.7f1
- WebGL Build Support Module
- Download Unity Hub from the official site: https://unity.com/download
- Install and open Unity Hub.
- Open Unity Hub and go to the Installs tab.
- Click "Install Editor", then go to the "Archive" section.
- Find and download the version Unity 2022.3.7f1.
- Download the .unityhub install file and open it to install via Unity Hub.
✅ Make sure to select “WebGL Build Support” during installation.
If you've already installed Unity without WebGL:
- Go to Installs tab → click ⋮ next to version 2022.3.7f1 → select "Add Modules" → install WebGL Build Support.
- Go to the Projects tab → click "New Project".
- Choose the 3D template.
- Select version 2022.3.7f1.
- Name your project and click Create.
- Open your project.
- Go to File → Build Settings.
- Select WebGL in the platform list → click Switch Platform.
- Go to Player Settings:
- Resolution and Presentation:
- Set Canvas Width/Height as needed.
- Enable Run In Background if required.
- Publishing Settings:
- Set Compression Format to Brotli or Gzip.
- Enable Decompression Fallback for better compatibility.
- Resolution and Presentation:
- Add your main scene in Build Settings → click Add Open Scenes.
- Click Build, then choose a folder (e.g.,
Build/) to export the WebGL files.
The output will include files like:
To test the WebGL build locally, use a local server:
- Install the Live Server extension.
- Right-click
MainIndex.html→ Open with Live Server.
This project is a WebGL-based Unity application that controls a 3D car model. The car has various interactive features such as opening/closing doors, turning lights on/off, and adjusting seat positions. All functionalities are encapsulated and managed by a centralized controller.
- Individual car parts (door, seat, lights...) are modular scripts.
CarControlleracts as the integration hub that references all parts.- External HTML communicates with Unity WebGL through JavaScript API calls.
- Unity receives commands (as JSON or strings) and forwards them to the appropriate component.
- Each component implements a shared interface for consistent communication (
IActions,ILockable, etc).
- Modular component design for easy expansion.
- Centralized command processing via
CarController. - HTML integration for remote or UI-based control.
- Interface-driven architecture for flexibility.