Nuclear Powered Macros

    @cognite/3d-camera-controls

    1.6.0 • Public • Published

    camera-controls

    A camera control for three.js, similar to THREE.OrbitControls yet supports smooth transitions, es6 import and FPV.

    Test

    To test the controller then do:

    • git clone
    • cd camera-controls
    • yarn
    • yarn run dev
    • Open camera-controls/examples/basic.html on browser

    Usage

    import * as THREE from 'three';
    import { CameraControls } from 'camera-controls';
    
    CameraControls.install(THREE);
    
    // snip ( init three scene... )
    const clock = new THREE.Clock();
    const camera = new THREE.PerspectiveCamera(60, width / height, 0.01, 100);
    const cameraControls = new CameraControls(camera, renderer.domElement);
    
    ( function anim () {
    	// snip
    	const delta = clock.getDelta();
    	const isControlsUpdated = cameraControls.update(delta);
    
    	requestAnimationFrame(anim);
    
    	if (isControlsUpdated) {
    		renderer.render(scene, camera);
    	}
    } )();

    Constructor

    CameraControls(camera, domElement)

    • camera is a three.js perspective camera to be controlled.
    • domElement is a HTML element for draggable area.

    Properties

    • .enabled: Default is true. Whether or not the controls are enabled.
    • .minDistance: Default is 0. Minimum distance for dolly.
    • .maxDistance: Default is Infinity. Maximum distance for dolly.
    • .minPolarAngle: Default is 0, in radians.
    • .maxPolarAngle: Default is Math.PI, in radians.
    • .minAzimuthAngle: Default is -Infinity, in radians.
    • .maxAzimuthAngle: Default is Infinity, in radians.
    • .dampingFactor: Default is 0.5.
    • .draggingDampingFactor: Default is 0.1.
    • .minZoomDistance: Default is 0.3. Min zoom distance per zoom event.
    • .maxZoomDistance: Default is 1.0. Max zoom distance per zoom event.
    • .panSpeed: Default is 1.0. Speed of drag panning (only for touch).
    • .minPanDistance: Default is 1.0. Min distance to mvoe when panning.
    • .rotationSpeed: Default is 0.005. Speed to rotate in first-person mode.
    • .enableKeyboardNavigation: Default is true. If keyboard navigation is enabled.
    • .minDistToTarget: Default is 2.0. Minimum distance to a target you can be (will push the target if closer).

    Methods

    rotate(rotX, rotY, enableTransition)

    Rotate azimuthal angle(theta) and polar angle(phi). rotX and rotY are in radian. enableTransition is in a boolean

    rotateTo(rotX, rotY, enableTransition)

    Rotate azimuthal angle(theta) and polar angle(phi) to a given point.

    dolly(distance, enableTransition, x = 0, y = 0)

    Dolly in/out camera position. distance is in a number. enableTransition is in a boolean. x and y is the dolly direction in GL coordinates (-1, +1).

    dollyTo(distance, enableTransition, x = 0, y = 0)

    Dolly in/out camera position to given distance. x and y is the dolly direction in GL coordinates (-1, +1).

    pan(x, y, enableTransition)

    Pan camera using current azimuthal angle.

    moveTo(x, y, z, enableTransition)

    Move target position to given point.

    getState()

    Get the current internal state.

    setCameraPosition(position, target, enableTransition = false)

    Set camera position to position and target to target.

    reset(enableTransition)

    Reset all rotation, zoom, position to default.

    update(delta)

    Update camera position and directions. This should be called in your tick loop and returns true if re-rendering is needed. delta is delta time between previous update call.

    dispose()

    Dispose cameraControls instancem, remove all eventListeners.

    Keywords

    none

    Install

    npm i @cognite/3d-camera-controls

    DownloadsWeekly Downloads

    14

    Version

    1.6.0

    License

    UNLICENSED

    Unpacked Size

    26.5 kB

    Total Files

    3

    Last publish

    Collaborators

    • cognite.harbs
    • queenie-cognite
    • sig1991
    • mlkrsrc
    • ahmedcognite
    • kondanta
    • bkuzma
    • shubhski
    • stefanmaretic
    • maksym.kowalski
    • bdemirel
    • toonday
    • sennen-cognite
    • eiriklv
    • dmakked
    • caner-cognite
    • 23andreas
    • ikechukwu
    • astridkg
    • marcelo_costa
    • fran.hrzenjak
    • torgrim
    • wchatx
    • julia.scott
    • marvin.reza
    • einar.omang
    • bhavith
    • oleksandr.kolomiiets
    • dafn
    • erlendvollset
    • eirik.djuve
    • luka-mikec-cognite
    • sou1est
    • sagarthalwar
    • martin-wahlberg
    • nabati
    • kinga.cognite
    • borlov
    • cyriaquebrousse
    • tugceozgur
    • erikangelsen-cognite
    • ankku
    • silvavelosa
    • henrist
    • robinhoodie
    • peet.cremer
    • ponnapz
    • shekhardesigner
    • kornelione
    • vhnguyen
    • greenbech-cognite
    • lpereiracgn
    • manoj-cognite
    • oiuytrdsxcvbnjkhgfcvbnm
    • wjoel
    • tapped
    • sumitpandey
    • francisco.rull
    • frxstrem
    • cognitecicd
    • parami.abeysekara
    • cemreyavuz
    • neringaalt
    • rhuan.barreto
    • funsim
    • lokaltog
    • pavelzubarev
    • msusag
    • nfremming
    • steinhdan
    • dmivankov
    • polomani
    • simen.eriksen
    • nils-cognite
    • dlcognite
    • haak
    • carlospereira
    • larsmoa
    • nishafern
    • trygve.utstumo
    • kathrine-cognite
    • rekarnar
    • maximcognite
    • rumeshwick
    • vegardokland
    • hhenriques
    • tfheen-cognite
    • oksana_korniienko
    • j-bjorne
    • scottmelhop
    • mathialo
    • agadacz-cognite
    • paulo-menezes-cognite
    • miladcognite
    • me-ydv-5
    • cogniteterraform
    • anderscognite
    • fredrik955
    • halvard
    • dan.levings.cognite
    • sindresh92
    • christjt
    • maksim.nesterenko
    • hakontro
    • arnekv
    • ana-gheorghe
    • digaomilleniun.cognite
    • cognite-ornellas
    • harish0489
    • pedro.lindeza
    • abdullah-cognite
    • davidhwu
    • anjalirai2626
    • d0ttir
    • filipjohnsen
    • omarakabbal
    • savokr
    • pramodcog
    • tharindudg
    • brgverst
    • thorkild
    • sigridschaanning
    • smartalas
    • arnels
    • sondre.solbakken
    • pbettler
    • dsaks999
    • qtiptip
    • sceniclife
    • johan-cognite
    • theresatalor-cognite
    • mspang
    • eliasbjorne
    • oysteinolsen
    • anders-cog
    • skairunner
    • jtcog
    • petmotzf
    • deep-cognite
    • mattmurph9
    • lprovensi
    • haakonflatval-cognite
    • begozcan
    • khalzmax
    • chingyu-cognite
    • mikaelcognite
    • sighol
    • heiding
    • ronald-cognite
    • daniel.priori
    • ravinda-cognite
    • timurgen
    • trodden-dev
    • podeig-cognite
    • emel.varol
    • bdimitrijoski
    • madskjeldsberg
    • yevhenii.maltsev
    • farrukk24
    • aurlien
    • bianca-mv
    • samarv
    • soleh23
    • malindakpt
    • mihilr
    • gayandeegala
    • tfarvac
    • borajimin
    • samir-ajdarpasic
    • torbjornopheim
    • chanaka25
    • geircognite
    • soumesh.banerjee
    • mohsin.cognite
    • vebjorngilberg
    • roligheten
    • marcushorn
    • sara.aalbu
    • atussa
    • aizumi
    • therockvalley
    • dmitrijs.rutko.cognite
    • perarnet
    • bisera
    • shehan.cognite
    • udara-cognite
    • raabyeeggs
    • asankad
    • jarlah
    • keepfloyding
    • cgustad
    • cognitehumlen
    • tommy_thorsen
    • andersfylling
    • meisammalekzadeh
    • ericbrattli
    • mcarun
    • saagar-cognite
    • waqasjaved1