Skip to content

CameraControls ^3.2.0

CameraControls is a camera controller similar to OrbitControls yet supports smooth transitions and more features.

However, it is thirty party library for ThreeJS. So to use it you would need to install and import using npm.

Here is where the fancy part begins. ✨ The cientos package provides a component called <CameraControls /> that is a wrapper of the CameraControls from the camera-controls module.

The nicest part? You don't need to extend the catalog or pass any arguments. It just works. 💯

Usage

vue
<script setup lang="ts">
import { reactive } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { CameraControls, Box } from '@tresjs/cientos'

const controlsState = reactive({
  minDistance: 0,
  maxDistance: 100,
})
</script>

<template>
  <TresCanvas clear-color="#82DBC5">
    <TresPerspectiveCamera :position="[5, 5, 5]" />
    <CameraControls
      v-bind="controlsState"
      make-default
    />
    <TresGridHelper :position="[0, -1, 0]" />
    <Box :scale="2">
      <TresMeshToonMaterial color="orange" />
    </Box>
    <TresAmbientLight />
    <TresDirectionalLight :position="[0, 2, 4]" />
  </TresCanvas>
</template>

WARNING

Is really important that the Perspective camera is set first in the canvas. Otherwise might break.

Props

Certainly! Here's the properties of the object in raw markdown table format:

PropDescriptionDefault
makeDefaultWhether to make this the default controls.false
cameraThe camera to control.undefined
domElementThe DOM element to listen to.undefined
minPolarAngleMinimum vertical angle in radians.0
maxPolarAngleMaximum vertical angle in radians.Math.PI
minAzimuthAngleMinimum horizontal angle in radians.-Infinity
maxAzimuthAngleMaximum horizontal angle in radians.Infinity
distanceCurrent distance.camera.position.z
minDistanceMinimum distance for dolly. PerspectiveCamera only.Number.EPSILON
maxDistanceMaximum distance for dolly. PerspectiveCamera only.Infinity
infinityDollytrue to enable Infinity Dolly for wheel and pinch.false
minZoomMinimum camera zoom.0.01
maxZoomMaximum camera zoom.Infinity
smoothTimeApproximate time in seconds to reach the target. A smaller value will reach the target faster.0.25
draggingSmoothTimeThe smoothTime while dragging.0.125
maxSpeedMax transition speed in units per second.Infinity
azimuthRotateSpeedSpeed of azimuth (horizontal) rotation.1.0
polarRotateSpeedSpeed of polar (vertical) rotation.1.0
dollySpeedSpeed of mouse-wheel dollying.1.0
dollyDragInvertedtrue to invert direction when dollying or zooming via drag.false
truckSpeedSpeed of drag for truck and pedestal.2.0
dollyToCursortrue to enable Dolly-in to the mouse cursor coords.false
dragToOffsetWhether to drag to offset.false
verticalDragToForwardThe same as .screenSpacePanning in three.js's OrbitControls.false
boundaryFrictionFriction ratio of the boundary.0.0
restThresholdControls how soon the rest event fires as the camera slows.0.01
colliderMeshesAn array of Meshes to collide with the camera. Be aware colliderMeshes may decrease performance. The collision test uses 4 raycasters from the camera since the near plane has 4 corners.[]

Events

vue
<CameraControls @change="onChange" @start="onStart" @end="onEnd" />
EventDescription
startDispatched when the control starts to change.
changeDispatched when the control changes.
endDispatched when the control ends to change.