A Vite + React starter focused on Three.js model viewing with physically based lighting, HDR environments, Draco-ready glTF loading, and a Zustand-driven scene control layer.
- React 18 + Vite 3
- Three.js +
postprocessing - Zustand (app and scene state)
- Styled Components + PrimeReact UI primitives
- React Router + React Query (core app scaffolding)
- A full-screen
ThreeViewermounted inMainpage ThreeEngineclass for scene/camera/renderer/composer lifecycle- HDR environment presets in
src/dataset/environments.js - Lighting controls wired through global state in
src/state/store.js - Draco decoder files preconfigured in
public/draco - Basic app shell (theme provider, router setup, page transition, navbar components)
- Node.js
>=20.0.0 - Yarn classic (
1.x) or npm (Yarn is used in scripts/examples below)
npm install --global yarn
yarn install
yarn startDev server defaults to port 4000 (see vite.config.js) and binds with --host so it is reachable on your network.
yarn start- start Vite dev serveryarn build- create production buildyarn lint- run ESLint with auto-fixyarn format- run Prettier on JS/JSX/JSON/MD files
src/
App.jsx # Providers + routes + toast + query devtools
index.js # React root bootstrap
api/ # API layer placeholder (currently empty)
assets/
textures/ # HDR/JPG environment assets
components/
ThreeViewer/
ThreeViewer.jsx # React bridge to ThreeEngine
libs/
ThreeEngine.js # Scene lifecycle + loading + render orchestration
Composer.js # Post-processing stack
Lights.js # Light rig
Helpers.js # ShadowPlane + camera fit helper
dataset/
environments.js # Env preset metadata and asset refs
routes.js # Route definitions
pages/Main/Main.jsx # Viewer page
state/store.js # Zustand scene/app state
theme/ # Global styling + responsive container
public/
draco/ # Draco decoders used by GLTFLoader
ThreeViewer is the React-facing component. It:
- Instantiates
ThreeEngineonce on mount. - Subscribes to Zustand slices (lights/env/model/loader).
- Pushes state changes into engine methods (
updateEnvmap,updateSunLight, etc.). - Disposes engine resources on unmount.
ThreeEngine owns:
- Scene primitives (axes helper, shadow plane)
- Camera +
OrbitControls - WebGL renderer setup (ACES tone mapping, shadows, sRGB output)
- Asset loaders (
GLTFLoader,DRACOLoader,RGBELoader, OBJ/MTL/FBX prepared) - Effect composer pipeline (SMAA, SSAO, bloom, vignette, brightness/contrast)
- Loading manager that updates UI loader visibility through store callbacks
The default store points to:
currentPhysics: 'models/house.glb'Place your model under public/models (or any public path), then update currentPhysics in src/state/store.js or set it dynamically from UI/state actions.
Edit src/dataset/environments.js:
- Add new
hdr/jpgimports fromsrc/assets/textures - Append a preset object with
name,azimuth,zenith, andexposure
These values drive:
- Environment map/background texture
- Sun orientation (
azimuth+zenith) - Tone mapping exposure
Update initial values in src/state/store.js:
sunInfofirstEmbientInfosecondEmbientInfo
Then, at runtime, ThreeViewer forwards updates to ThreeEngine light methods.
Open src/components/ThreeViewer/libs/Composer.js and tweak:
BloomEffect(intensity, threshold, smoothing)SSAOEffect(radius,intensity, thresholds)VignetteEffect/BrightnessContrastEffect
src/api/index.jsexists as a placeholder and is currently empty.- Router scaffolding supports multiple pages, but only
/(Main) is registered by default. - Several loaders are initialized (OBJ/MTL/FBX), while
loadModelcurrently loads GLTF/GLB. - If
yarn buildfails with "viteis not recognized", dependencies are not installed yet. Runyarn installfirst.