Three Vue3Three Vue3
Guide
Demo
AI Agents
  • English
  • 简体中文
GitHub
Guide
Demo
AI Agents
  • English
  • 简体中文
GitHub
    • Getting Started
    • Scene
    • Parameter Bus
    • SkyBox
    • Model Loader

      • Component Loader
      • Function Loader
    • Popup
    • Callout
    • Movable Element
    • Animation
    • Model Rotator
    • Picker
    • Fit Camera
      • Default Usage
      • Functions
      • Options
      • Methods
    • Mesh

      • Wave Circle Mesh
      • Flow Line Mesh
    • Effect

      • Nature

        • Rain
        • Snow
        • Water
        • Water Pool
        • Sandy Beach
      • Sky & Atmosphere

        • Sky Dome
        • HeightFog
        • Nebula Galaxy
      • Light

        • Bloom
        • Sweep Light
        • Light Gradient
        • Light Pillar
        • Radar Sweep
        • Signal Wave
        • Force Shield
      • Particles & Sprites

        • Fireworks
        • Text Fireworks
        • Glow Sprite
    • GIS

      • Geographic Reference
      • GeoObject
      • GeoJsonLayer
      • Tile Layer

type

Class / Function

FitCamera is a THREE.PerspectiveCamera with framing helpers, and the same helpers are also exported as plain functions. They compute the camera distance from the content bounding box, so you never hard-code a viewpoint or a far plane for a specific model scale.

Default Usage

Click me to view the codes
<template>
  <tv-scene class="scene" :camera="camera" @created="created"></tv-scene>
</template>

<script lang="ts" setup>
import * as THREE from 'three'
import { FitCamera } from 'three-vue3'

const camera = new FitCamera(45, 1, 0.1, 2000)

const created = (scene, { controls }) => {
  const group = new THREE.Group()
  const geometry = new THREE.SphereGeometry(0.4, 16, 16)
  const material = new THREE.MeshLambertMaterial({ color: 0xff7a45 })

  for (let i = 0; i < 12; i++) {
    const sphere = new THREE.Mesh(geometry, material)
    sphere.position.set(Math.cos(i) * 6, (i % 3) - 1, Math.sin(i) * 6)
    group.add(sphere)
  }

  scene.add(group)

  // Frame the whole group in a single call.
  if (controls) camera.bind(controls).fitToObject(group)
}
</script>

<style>
.scene {
  margin-top: 10px;
  width: 100%;
  height: 300px;
}
</style>

Functions

The class methods delegate to these functions, which accept any THREE.PerspectiveCamera.

import { fitCameraToBox, fitCameraToObject, fitCameraToPoints } from 'three-vue3'

fitCameraToObject(camera, model, { elevation: Math.PI / 6, padding: 1.6 })

Options

NameTypeDefaultDescription
elevationnumberPI / 4optional Viewing elevation above the horizontal plane, in radians.
azimuthnumberPI / 4optional Horizontal bearing around the target, clockwise from -Z.
paddingnumber1.4optional Distance multiplier, > 1 zooms out for margin.
distancenumberoptional Overrides the computed distance, in world units.
adjustClipbooleantrueoptional Derives near / far from the content scale.
controlsOrbitControls | nullnulloptional When supplied, its target is synced to the box centre.

Methods

NameParametersDescription
bind(controls?: OrbitControls | null) => thisBinds the controls used by later fits.
fitToPoints(points: LocalPoint[], options?: CameraFitOptions) => thisFrames a set of local-space points.
fitToObject(object: Object3D | Object3D[], options?: CameraFitOptions) => thisFrames the world-space bounding box.
fitToBox(box: THREE.Box3, options?: CameraFitOptions) => thisFrames an explicit world-space box.
Edit this page on GitHub
Last Updated:
Contributors: Shing Rui
Prev
Picker