Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

threejs-modern-app

> 编程语言
Open source

Boilerplate and utils for a fullscreen Three.js app

385 stars0 likes3 views
WebsiteGitHub

About

Boilerplate and utils for a fullscreen Three.js app

threejs-modern-app

Boilerplate and utils for a fullscreen three.js app It is inspired from mattdesl's threejs-app, but it was rewritten and simplified using ES6 syntax rather than node, making it easier to read and well commented, so it can be easily customized to fit your needs.

DEMO

Features

  • All the three.js boilerplate code is tucked away in a file, the exported WebGLApp is easily configurable from the outside, for example you can enable postprocessing, orbit controls, a gui, FPS stats, Detect GPU, and use the save screenshot or record mp4 functionality. It also has built-in support for cannon-es. [Read more]

  • A scalable three.js component structure where each component is a class which extends THREE.Group, so you can add any object to it. The class also has update, resize, and pointer hooks. [Read more]

  • An asset manager which handles the preloading of .gltf models, images, audios, videos and can be easily extended to support other files. It also automatically uploads a texture to the GPU, loads cube env maps or parses equirectangular projection images. [Read more]

  • global window.DEBUG flag which is true when the url contains ?debug as a query parameter. So you can enable debug mode both locally and in production. [Read more]

  • glslify to import shaders from node_modules. [Read more]

  • GPU tiering info using detect-gpu [Read more]

  • Modern and customizable development tools such as ⚡️esbuild⚡️, eslint, and prettier.

  • Beautiful console output:

Usage

Once you installed the dependencies running yarn, these are the available commands:

  • yarn start starts a server locally
  • yarn start --https starts an HTTPS server locally
  • yarn build builds the project for production, ready to be deployed from the build/ folder

All the build tools logic is in the package.json and esbuild.js.

WebGLApp

javascript
import WebGLApp from './utils/WebGLApp'

const webgl = new WebGLApp({ ...options })

The WebGLApp class contains all the code needed for three.js to run a scene, it is always the same so it makes sense to hide it in a standalone file and don't think about it.

You can see an example configuration here:

https://github.com/marcofugaro/threejs-modern-app/blob/3f9d43d2ad790a20b0c9a0b62db7095bac6cef82/src/index.js#L14-L30

You can pass the class the options you would pass to the THREE.WebGLRenderer, and also some more options:

Option Default Description
background '#111' The background of the scene.
backgroundAlpha 1 The transparency of the background.
maxPixelRatio 2 You can clamp the pixelRatio. Often the pixelRatio is clamped for performance reasons.
width window.innerWidth The canvas width.
height window.innerHeight The canvas height.
orthographic false Use an OrthographicCamera instead of the default PerspectiveCamera.
cameraPosition new Vector3(0, 0, 4) Set the initial camera position. The camera will always look at [0, 0, 0].
fov 45 The field of view of the PerspectiveCamera. It is ignored if the option orthographic is true.
frustumSize 3 Defines the size of the OrthographicCamera frustum. It is ignored if the option orthographic is false.
near 0.01 The camera near plane.
far 100 The camera far plane.
postprocessing false Enable the postprocessing library. The composer gets exposed as webgl.composer.
xr false Enable three.js WebXR mode. The update function now will have a xrframe object passed as a third parameter.
showFps false Show the stats.js fps counter.
orbitControls undefined Set this to true to enable OrbitControls. You can also pass an object of OrbitControls properties to set.
gui undefined Wether or not to initialize the gui using lil-gui. Exposed ad webgl.gui.
guiClosed false Set this to true to initialize the gui panel closed.
world undefined Accepts an instance of the cannon-es world (new CANNON.World()). Exposed as webgl.world.
showWorldWireframes false Set this to true to show the wireframes of every body in the world. Uses cannon-es-debugger.

The webgl instance will contain all the three.js elements such as webgl.scene, webgl.renderer, webgl.camera or webgl.canvas. It also exposes some useful properties and methods:

webgl.isDragging

Wether or not the user is currently dragging. It is true between the onPointerDown and onPointerUp events.

webgl.cursor

Set this property to change the cursor style of the canvas. For example you can use it to display the pointer cursor on some objects:

javascript
onPointerMove(event, { x, y }) {
  // raycast and get the intersecting mesh
  const intersectingMesh = getIntersectingMesh([x, y], this, this.webgl)

  if (intersectingMesh) {
    this.webgl.cursor = 'pointer'
  } else {
    this.webgl.cursor = null
  }
}

webgl.saveScreenshot({ ...options })

Save a screenshot of the application as a png.

Option Default Description
width window.innerWidth The width of the screenshot.
height window.innerHeight The height of the screenshot.
fileName 'Screenshot' The name the .png file will have.

webgl.startRecording({ ...options })

Start the recording of a video using mp4-wasm.

Option Default Description
width window.innerWidth The width of the video.
height window.innerHeight The height of the video.
fileName 'Recording' The name the .mp4 file will have.
...others Other options that you can pass to the createWebCodecsEncoder() method of mp4-wasm.

webgl.stopRecording()

Stop the recording and download the video. It returns a promise that is resolved once the processing is done.

webgl.onUpdate((dt, time) => {})

Subscribe to the update requestAnimationFrame without having to create a component. If needed you can later unsubscribe the function with webgl.offUpdate(function).

Parameter Description
dt The seconds elapsed from the latest frame, in a 60fps application it's 0.016s (aka 16ms)
time The time in seconds elapsed from when the animation loop starts

webgl.onPointerDown((event, { x, y }) => {})

Subscribe a function to the pointerdown event on the canvas without having to create a component. If needed you can later unsubscribe the function with webgl.offPointerDown(function).

Parameter Description
event The native event.
position An object containing the x and the y position from the top left of the canvas.

webgl.onPointerMove((event, { x, y }) => {})

Subs

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptboilerplatestarter-kitthreejswebgl

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言