Three.js model cut off on mobile?

Keep the whole model in frame by refitting the perspective camera whenever its container changes size. Try the live comparison, then copy the resize helper into your project.

Landscape and portrait camera fit

Survey Wing · Same model in both views

Landscape

16:9
Survey Wing fits the landscape view at the starting distance.

Portrait

9:16
The portrait view cuts off the wings until the camera moves back.

Both cameras use the same distance. The portrait view cuts off the wings.

Why the sides get cut off in portrait

A Three.js PerspectiveCamera uses a vertical field of view. At the same camera distance, a narrower aspect ratio leaves less room from left to right. In Aspect only mode both cameras have the correct aspect ratio, but the portrait camera still crops the wings. Select Auto fit to move each camera to the distance its viewport needs.

The helper measures the model with Box3. It checks all eight corners against the horizontal and vertical limits of the camera frustum, moves the camera along its current viewing axis, and updates the near and far clipping planes.

Refit the camera on resize

  1. Copy the helper into camera-fit.js in a project that can import three.
  2. After your GLB loads, aim your perspective camera from the angle you want. Give the canvas container a CSS size and set its canvas to display: block; width: 100%; height: 100%.
  3. Pass the loaded gltf.scene and the container element to fitOnResize. If you already render every frame, you can omit onResize. If you use OrbitControls, pass controls to keep its target centered.
import { fitOnResize } from './camera-fit.js';

const stopFitting = fitOnResize({
  renderer,
  camera,
  model: gltf.scene,
  container: renderer.domElement.parentElement,
  onResize: () => renderer.render(scene, camera),
});

// Call stopFitting() when the viewer is removed.

camera-fit.js

ResizeObserver responds to the container's dimensions, including changes caused by window resizing and device rotation. The helper measures bounds once per call. Call stopFitting() and set it up again if the model's bounds change.

Try your own GLB

Drop a file into the Three.js Camera Fit tool to compare both viewports and copy the camera setup for either one. Your model stays in your browser.