@luxonis/visualizer-protobuf 2.22.0 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{WorkerImageDecoder.worker-tkX9-IYo.js → WorkerImageDecoder.worker-C3ZBQ2Wk.js} +1 -1
- package/dist/{decodeImage-C8kB6T3V.js → decodeImage-CxUhz2gE.js} +14278 -2893
- package/dist/{index-P-f_cKZS.js → index-B9Zf3rrb.js} +2 -2
- package/dist/{index-BQ24Upp_.js → index-BJOK4X3d.js} +2 -2
- package/dist/{index-DMvr0-pP.js → index-BTO4og7t.js} +2 -2
- package/dist/{index-DTCT-lVn.js → index-BqTw2FSJ.js} +4 -4
- package/dist/{index-CH1TUS48.js → index-Bw0fCcF0.js} +2 -2
- package/dist/{index-DDVf76z9.js → index-CCWfhL1j.js} +2 -2
- package/dist/{index-BHXfMPMv.js → index-CFz07x1R.js} +2 -2
- package/dist/{index-Bvet1xE9.js → index-CM0J0Tip.js} +2 -2
- package/dist/{index-DtzTeqB7.js → index-D3by772J.js} +2 -2
- package/dist/{index-DzyYicoH.js → index-DMmaMUCD.js} +2813 -1608
- package/dist/{index-C-cGIa0r.js → index-DQ_hdLpb.js} +2 -2
- package/dist/{index-yfiGMPtK.js → index-DRmoIUFd.js} +2 -2
- package/dist/{index-Dcus_L6F.js → index-DWgnF3_o.js} +156 -57
- package/dist/{index-DYpNYj7G.js → index-Db42Qzy_.js} +2 -2
- package/dist/{index-C_ioBAtk.js → index-DgisSKDf.js} +2 -2
- package/dist/{index-CV57d9Tz.js → index-DjOkSXUO.js} +2 -2
- package/dist/{index-D5F-PpU5.js → index-DqqFhpKC.js} +2 -2
- package/dist/{index-RKZ-F77P.js → index-Wr3SUBO9.js} +2 -2
- package/dist/{index-DHgo3Ne_.js → index-oTzD1_p-.js} +2 -2
- package/dist/index.js +2 -2
- package/dist/lib/src/connection/foxglove-connection.d.ts +3 -1
- package/dist/lib/src/connection/foxglove-connection.d.ts.map +1 -1
- package/dist/lib/src/connection/foxglove-connection.js +16 -32
- package/dist/lib/src/connection/foxglove-connection.js.map +1 -1
- package/dist/lib/src/messaging/deserialization/pointcloud/pointcloudFromDepth.worker.js +373 -247
- package/dist/lib/src/messaging/deserialization/pointcloud/pointcloudFromDepth.worker.js.map +1 -1
- package/dist/lib/src/messaging/deserialization/pointcloud/poitcloudPoolManager.d.ts +30 -0
- package/dist/lib/src/messaging/deserialization/pointcloud/poitcloudPoolManager.d.ts.map +1 -0
- package/dist/lib/src/messaging/deserialization/pointcloud/poitcloudPoolManager.js +106 -0
- package/dist/lib/src/messaging/deserialization/pointcloud/poitcloudPoolManager.js.map +1 -0
- package/dist/lib/src/messaging/deserialization/pointcloud/utils.d.ts +0 -9
- package/dist/lib/src/messaging/deserialization/pointcloud/utils.d.ts.map +1 -1
- package/dist/lib/src/messaging/deserialization/pointcloud/utils.js +0 -16
- package/dist/lib/src/messaging/deserialization/pointcloud/utils.js.map +1 -1
- package/dist/lib/src/panels/PointCloudPanel.js +3 -3
- package/dist/lib/src/panels/PointCloudPanel.js.map +1 -1
- package/dist/lib/src/utils/poitcloud-sync.js +1 -1
- package/dist/lib/src/utils/poitcloud-sync.js.map +1 -1
- package/dist/packages/studio-base/src/panels/ThreeDeeRender/renderables/CameraStateSettings.d.ts +1 -0
- package/dist/packages/studio-base/src/panels/ThreeDeeRender/renderables/CameraStateSettings.d.ts.map +1 -1
- package/dist/packages/studio-base/src/panels/ThreeDeeRender/renderables/CameraStateSettings.js +243 -154
- package/dist/packages/studio-base/src/panels/ThreeDeeRender/renderables/CameraStateSettings.js.map +1 -1
- package/dist/pointcloudFromDepth.worker-qotYPy_e.js +450 -0
- package/dist/{utils-Cmsz3FxA.js → utils-Hzt3wxhG.js} +2 -20
- package/package.json +2 -1
- package/dist/pointcloudFromDepth.worker-CNKyMUU-.js +0 -326
|
@@ -3,7 +3,7 @@ import React__default, { useReducer, useRef, useCallback, useLayoutEffect, Compo
|
|
|
3
3
|
import ReactDOM__default from 'react-dom';
|
|
4
4
|
import { S as isSymbol, U as toString, V as keys, W as getSymbols$1, X as stubArray, Y as arrayPush, Z as baseGetAllKeys, g as getTag, $ as getAllKeys, k as baseGet, c as baseIteratee, j as castPath, t as toKey, a0 as arrayMap$1, a1 as baseUniq, b as baseFlatten, a2 as useMustNotChange, a3 as useCurrentLayoutActions, a4 as useCurrentLayoutSelector, r as reportError, A as AppError, L as Logger, u as useGuaranteedContext, a5 as usePanelMosaicId, a6 as useSelectedPanels, a7 as PANEL_TITLE_CONFIG_KEY, a8 as noop$4, o as getPanelTypeFromId, M as useShallowMemo, T as TAB_PANEL_TYPE, J as filterMap, d as dist$3, a9 as useAppConfiguration, aa as useValueChangedDebugLog, ab as useJsonTreeTheme } from './tslib.es6-C73eoP_E.js';
|
|
5
5
|
import { createStore, useStore } from 'zustand';
|
|
6
|
-
import { g as generateUtilityClass, c as createAggregator, f as flatRest, b as baseSet, A as AnalyticsContext, P as PropTypes, E as ErrorDisplay, S as Stack$1, m as makeStyles$1, _ as _extends$1, W as WorkspaceContext, u as useAnalytics, a as AppEvent, L as LeftSidebarItemKeys, R as RightSidebarItemKeys, d as useTranslation, e as usePanelCatalog, h as EmptyState, i as isEmpty, j as PanelContext, k as PanelCatalogContext, l as usePanelStateStore, n as useDefaultPanelTitle, o as useWorkspaceStore, p as WorkspaceStoreSelectors, q as difference, r as usePanelContext, s as useMessagePipeline, v as v4, t as useHoverValue, w as useSetHoverValue, x as useClearHoverValue, y as useMessagePipelineGetter, z as usePanelSettingsTreeUpdate, B as PlayerCapabilities, C as assertNever, D as PlayerPresence, F as isEqual, G as isDesktopApp, H as createTheme, I as propTypesExports } from './index-
|
|
6
|
+
import { g as generateUtilityClass, c as createAggregator, f as flatRest, b as baseSet, A as AnalyticsContext, P as PropTypes, E as ErrorDisplay, S as Stack$1, m as makeStyles$1, _ as _extends$1, W as WorkspaceContext, u as useAnalytics, a as AppEvent, L as LeftSidebarItemKeys, R as RightSidebarItemKeys, d as useTranslation, e as usePanelCatalog, h as EmptyState, i as isEmpty, j as PanelContext, k as PanelCatalogContext, l as usePanelStateStore, n as useDefaultPanelTitle, o as useWorkspaceStore, p as WorkspaceStoreSelectors, q as difference, r as usePanelContext, s as useMessagePipeline, v as v4, t as useHoverValue, w as useSetHoverValue, x as useClearHoverValue, y as useMessagePipelineGetter, z as usePanelSettingsTreeUpdate, B as PlayerCapabilities, C as assertNever, D as PlayerPresence, F as isEqual, G as isDesktopApp, H as createTheme, I as propTypesExports } from './index-DWgnF3_o.js';
|
|
7
7
|
import { MosaicDragType, MosaicContext, MosaicWindowContext, getOtherBranch, getNodeAtPath } from 'react-mosaic-component';
|
|
8
8
|
import { t as typescript } from './useMessageReducer-jNx5e6JW.js';
|
|
9
9
|
import { g as getDefaultExportFromCjs, c as commonjsGlobal, a as getAugmentedNamespace } from './_commonjsHelpers-E-ZsRS8r.js';
|
|
@@ -17,15 +17,15 @@ import MoreVertIcon from '@mui/icons-material/MoreVert';
|
|
|
17
17
|
import CancelIcon from '@mui/icons-material/Cancel';
|
|
18
18
|
import SearchIcon from '@mui/icons-material/Search';
|
|
19
19
|
import { useDrag, useDrop } from 'react-dnd';
|
|
20
|
-
import { B as Box3, V as Vector3, I as InstancedBufferGeometry, F as Float32BufferAttribute, a as InstancedInterleavedBuffer, b as InterleavedBufferAttribute, W as WireframeGeometry, S as Sphere, U as UniformsLib, c as Vector2, e as ShaderLib, f as UniformsUtils, g as ShaderMaterial, h as Vector4, M as Matrix4, L as Line3, i as Mesh, j as MathUtils, O as Object3D, C as Color, r as rgbToThreeColor, s as stringToRgba, m as makeRgba, k as MeshStandardMaterial, R as ReplaceStencilOp, N as NotEqualStencilFunc, D as DoubleSide, P as PointsMaterial, l as rgbaToCssString, n as colorModeSettingsFields, o as autoSelectColorSettings, p as PlaneGeometry, q as DataTexture, t as UVMapping, u as ClampToEdgeWrapping, v as NearestFilter, w as LinearFilter, x as FS_SRGB_TO_LINEAR, y as SRGBColorSpace, z as LinearSRGBColorSpace, A as rgbaToLinear, E as RedFormat, G as RGBAFormat, H as getColorConverter, J as FloatType, K as UnsignedByteType, Q as NEEDS_MIN_MAX$1, T as InstancedMesh, X as CylinderGeometry, Y as ConeGeometry, Z as DataTextureLoader, _ as LinearMipmapLinearFilter, $ as Loader, a0 as LoaderUtils, a1 as FileLoader, a2 as MeshBasicMaterial, a3 as Scene, a4 as TextureLoader, a5 as AnimationClip, a6 as VectorKeyframeTrack, a7 as QuaternionKeyframeTrack, a8 as MeshLambertMaterial, a9 as MeshPhongMaterial, aa as FrontSide, ab as PerspectiveCamera, ac as OrthographicCamera, ad as AmbientLight, ae as SpotLight, af as PointLight, ag as DirectionalLight, ah as BufferGeometry, ai as Group, aj as Quaternion, ak as Bone, al as LineBasicMaterial, am as SkinnedMesh, an as Line, ao as LineSegments, ap as RepeatWrapping, aq as Skeleton, ar as BufferAttribute, as as TrianglesDrawMode, at as TriangleFanDrawMode, au as TriangleStripDrawMode, av as MeshPhysicalMaterial, aw as ImageBitmapLoader, ax as InterleavedBuffer, ay as Material, az as PropertyBinding, aA as LineLoop, aB as Points, aC as InterpolateLinear, aD as ColorManagement, aE as NearestMipmapNearestFilter, aF as LinearMipmapNearestFilter, aG as NearestMipmapLinearFilter, aH as MirroredRepeatWrapping, aI as InterpolateDiscrete, aJ as Texture, aK as NumberKeyframeTrack, aL as Interpolant, aM as EdgesGeometry, aN as LoadingManager, aO as stringToRgb, aP as getLuminance, aQ as Euler, aR as vec3TupleApproxEquals, aS as decodeCompressedImageToBitmap, aT as CanvasTexture, aU as Shape, aV as SRGBToLinear, aW as ShapeGeometry, aX as DynamicDrawUsage, aY as ShaderChunk, aZ as IMAGE_DEFAULT_COLOR_MODE_SETTINGS, a_ as colorHasTransparency, a$ as StaticDrawUsage, b0 as RawShaderMaterial, b1 as GLSL3, b2 as colorFieldComputedPrefix, b3 as getRotationTo, b4 as SphereGeometry, b5 as rgbaGradient, b6 as InstancedBufferAttribute, b7 as BoxGeometry, b8 as DARK_OUTLINE, b9 as LIGHT_OUTLINE, ba as CircleGeometry, bb as LineDashedMaterial, bc as GreaterDepth, bd as EventDispatcher, be as Plane, bf as Raycaster, bg as WebGLRenderTarget, bh as
|
|
20
|
+
import { B as Box3, V as Vector3, I as InstancedBufferGeometry, F as Float32BufferAttribute, a as InstancedInterleavedBuffer, b as InterleavedBufferAttribute, W as WireframeGeometry, S as Sphere, U as UniformsLib, c as Vector2, e as ShaderLib, f as UniformsUtils, g as ShaderMaterial, h as Vector4, M as Matrix4, L as Line3, i as Mesh, j as MathUtils, O as Object3D, C as Color, r as rgbToThreeColor, s as stringToRgba, m as makeRgba, k as MeshStandardMaterial, R as ReplaceStencilOp, N as NotEqualStencilFunc, D as DoubleSide, P as PointsMaterial, l as rgbaToCssString, n as colorModeSettingsFields, o as autoSelectColorSettings, p as PlaneGeometry, q as DataTexture, t as UVMapping, u as ClampToEdgeWrapping, v as NearestFilter, w as LinearFilter, x as FS_SRGB_TO_LINEAR, y as SRGBColorSpace, z as LinearSRGBColorSpace, A as rgbaToLinear, E as RedFormat, G as RGBAFormat, H as getColorConverter, J as FloatType, K as UnsignedByteType, Q as NEEDS_MIN_MAX$1, T as InstancedMesh, X as CylinderGeometry, Y as ConeGeometry, Z as DataTextureLoader, _ as LinearMipmapLinearFilter, $ as Loader, a0 as LoaderUtils, a1 as FileLoader, a2 as MeshBasicMaterial, a3 as Scene, a4 as TextureLoader, a5 as AnimationClip, a6 as VectorKeyframeTrack, a7 as QuaternionKeyframeTrack, a8 as MeshLambertMaterial, a9 as MeshPhongMaterial, aa as FrontSide, ab as PerspectiveCamera, ac as OrthographicCamera, ad as AmbientLight, ae as SpotLight, af as PointLight, ag as DirectionalLight, ah as BufferGeometry, ai as Group, aj as Quaternion, ak as Bone, al as LineBasicMaterial, am as SkinnedMesh, an as Line, ao as LineSegments, ap as RepeatWrapping, aq as Skeleton, ar as BufferAttribute, as as TrianglesDrawMode, at as TriangleFanDrawMode, au as TriangleStripDrawMode, av as MeshPhysicalMaterial, aw as ImageBitmapLoader, ax as InterleavedBuffer, ay as Material, az as PropertyBinding, aA as LineLoop, aB as Points, aC as InterpolateLinear, aD as ColorManagement, aE as NearestMipmapNearestFilter, aF as LinearMipmapNearestFilter, aG as NearestMipmapLinearFilter, aH as MirroredRepeatWrapping, aI as InterpolateDiscrete, aJ as Texture, aK as NumberKeyframeTrack, aL as Interpolant, aM as EdgesGeometry, aN as LoadingManager, aO as stringToRgb, aP as getLuminance, aQ as Euler, aR as vec3TupleApproxEquals, aS as decodeCompressedImageToBitmap, aT as CanvasTexture, aU as Shape, aV as SRGBToLinear, aW as ShapeGeometry, aX as DynamicDrawUsage, aY as ShaderChunk, aZ as IMAGE_DEFAULT_COLOR_MODE_SETTINGS, a_ as colorHasTransparency, a$ as StaticDrawUsage, b0 as RawShaderMaterial, b1 as GLSL3, b2 as colorFieldComputedPrefix, b3 as getRotationTo, b4 as SphereGeometry, b5 as rgbaGradient, b6 as InstancedBufferAttribute, b7 as BoxGeometry, b8 as DARK_OUTLINE, b9 as LIGHT_OUTLINE, ba as CircleGeometry, bb as LineDashedMaterial, bc as GreaterDepth, bd as EventDispatcher$1, be as Plane, bf as Raycaster, bg as WebGLRenderTarget, bh as THREE$1, bi as Spherical, bj as WebGLRenderer, bk as NoToneMapping, bl as VSMShadowMap, bm as HemisphereLight } from './decodeImage-CxUhz2gE.js';
|
|
21
21
|
import { CacheProvider } from '@emotion/react';
|
|
22
22
|
import '@mui/material/styles/createTypography';
|
|
23
23
|
import { E as EventEmitter } from './FoxgloveServer-C39Uooyk.js';
|
|
24
24
|
import require$$1$3 from 'color';
|
|
25
25
|
import require$$2$1 from 'lodash.curry';
|
|
26
26
|
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
|
27
|
-
import './utils-Cmsz3FxA.js';
|
|
28
27
|
import './comlink-DHMAu6X7.js';
|
|
28
|
+
import './utils-Hzt3wxhG.js';
|
|
29
29
|
import './foxglove-protocol-CYoMweAY.js';
|
|
30
30
|
import 'react-dnd-html5-backend';
|
|
31
31
|
import 'object-assign';
|
|
@@ -12404,10 +12404,10 @@ const _line = new Line3();
|
|
|
12404
12404
|
const _closestPoint = new Vector3();
|
|
12405
12405
|
|
|
12406
12406
|
const _box = new Box3();
|
|
12407
|
-
const _sphere = new Sphere();
|
|
12407
|
+
const _sphere$1 = new Sphere();
|
|
12408
12408
|
const _clipToWorldVector = new Vector4();
|
|
12409
12409
|
|
|
12410
|
-
let _ray
|
|
12410
|
+
let _ray, _lineWidth;
|
|
12411
12411
|
|
|
12412
12412
|
// Returns the margin required to expand by in world space given the distance from the camera,
|
|
12413
12413
|
// line width, resolution, and camera projection
|
|
@@ -12445,7 +12445,7 @@ function raycastWorldUnits( lineSegments, intersects ) {
|
|
|
12445
12445
|
const pointOnLine = new Vector3();
|
|
12446
12446
|
const point = new Vector3();
|
|
12447
12447
|
|
|
12448
|
-
_ray
|
|
12448
|
+
_ray.distanceSqToSegment( _line.start, _line.end, point, pointOnLine );
|
|
12449
12449
|
const isInside = point.distanceTo( pointOnLine ) < _lineWidth * 0.5;
|
|
12450
12450
|
|
|
12451
12451
|
if ( isInside ) {
|
|
@@ -12453,7 +12453,7 @@ function raycastWorldUnits( lineSegments, intersects ) {
|
|
|
12453
12453
|
intersects.push( {
|
|
12454
12454
|
point,
|
|
12455
12455
|
pointOnLine,
|
|
12456
|
-
distance: _ray
|
|
12456
|
+
distance: _ray.origin.distanceTo( point ),
|
|
12457
12457
|
object: lineSegments,
|
|
12458
12458
|
face: null,
|
|
12459
12459
|
faceIndex: i,
|
|
@@ -12486,7 +12486,7 @@ function raycastScreenSpace( lineSegments, camera, intersects ) {
|
|
|
12486
12486
|
// pick a point 1 unit out along the ray to avoid the ray origin
|
|
12487
12487
|
// sitting at the camera origin which will cause "w" to be 0 when
|
|
12488
12488
|
// applying the projection matrix.
|
|
12489
|
-
_ray
|
|
12489
|
+
_ray.at( 1, _ssOrigin );
|
|
12490
12490
|
|
|
12491
12491
|
// ndc space [ - 1.0, 1.0 ]
|
|
12492
12492
|
_ssOrigin.w = 1;
|
|
@@ -12581,12 +12581,12 @@ function raycastScreenSpace( lineSegments, camera, intersects ) {
|
|
|
12581
12581
|
const pointOnLine = new Vector3();
|
|
12582
12582
|
const point = new Vector3();
|
|
12583
12583
|
|
|
12584
|
-
_ray
|
|
12584
|
+
_ray.distanceSqToSegment( _line.start, _line.end, point, pointOnLine );
|
|
12585
12585
|
|
|
12586
12586
|
intersects.push( {
|
|
12587
12587
|
point: point,
|
|
12588
12588
|
pointOnLine: pointOnLine,
|
|
12589
|
-
distance: _ray
|
|
12589
|
+
distance: _ray.origin.distanceTo( point ),
|
|
12590
12590
|
object: lineSegments,
|
|
12591
12591
|
face: null,
|
|
12592
12592
|
faceIndex: i,
|
|
@@ -12654,7 +12654,7 @@ class LineSegments2 extends Mesh {
|
|
|
12654
12654
|
|
|
12655
12655
|
const threshold = ( raycaster.params.Line2 !== undefined ) ? raycaster.params.Line2.threshold || 0 : 0;
|
|
12656
12656
|
|
|
12657
|
-
_ray
|
|
12657
|
+
_ray = raycaster.ray;
|
|
12658
12658
|
|
|
12659
12659
|
const matrixWorld = this.matrixWorld;
|
|
12660
12660
|
const geometry = this.geometry;
|
|
@@ -12669,7 +12669,7 @@ class LineSegments2 extends Mesh {
|
|
|
12669
12669
|
|
|
12670
12670
|
}
|
|
12671
12671
|
|
|
12672
|
-
_sphere.copy( geometry.boundingSphere ).applyMatrix4( matrixWorld );
|
|
12672
|
+
_sphere$1.copy( geometry.boundingSphere ).applyMatrix4( matrixWorld );
|
|
12673
12673
|
|
|
12674
12674
|
// increase the sphere bounds by the worst case line screen space width
|
|
12675
12675
|
let sphereMargin;
|
|
@@ -12679,14 +12679,14 @@ class LineSegments2 extends Mesh {
|
|
|
12679
12679
|
|
|
12680
12680
|
} else {
|
|
12681
12681
|
|
|
12682
|
-
const distanceToSphere = Math.max( camera.near, _sphere.distanceToPoint( _ray
|
|
12682
|
+
const distanceToSphere = Math.max( camera.near, _sphere$1.distanceToPoint( _ray.origin ) );
|
|
12683
12683
|
sphereMargin = getWorldSpaceHalfWidth( camera, distanceToSphere, material.resolution );
|
|
12684
12684
|
|
|
12685
12685
|
}
|
|
12686
12686
|
|
|
12687
|
-
_sphere.radius += sphereMargin;
|
|
12687
|
+
_sphere$1.radius += sphereMargin;
|
|
12688
12688
|
|
|
12689
|
-
if ( _ray
|
|
12689
|
+
if ( _ray.intersectsSphere( _sphere$1 ) === false ) {
|
|
12690
12690
|
|
|
12691
12691
|
return;
|
|
12692
12692
|
|
|
@@ -12709,14 +12709,14 @@ class LineSegments2 extends Mesh {
|
|
|
12709
12709
|
|
|
12710
12710
|
} else {
|
|
12711
12711
|
|
|
12712
|
-
const distanceToBox = Math.max( camera.near, _box.distanceToPoint( _ray
|
|
12712
|
+
const distanceToBox = Math.max( camera.near, _box.distanceToPoint( _ray.origin ) );
|
|
12713
12713
|
boxMargin = getWorldSpaceHalfWidth( camera, distanceToBox, material.resolution );
|
|
12714
12714
|
|
|
12715
12715
|
}
|
|
12716
12716
|
|
|
12717
12717
|
_box.expandByScalar( boxMargin );
|
|
12718
12718
|
|
|
12719
|
-
if ( _ray
|
|
12719
|
+
if ( _ray.intersectsBox( _box ) === false ) {
|
|
12720
12720
|
|
|
12721
12721
|
return;
|
|
12722
12722
|
|
|
@@ -14143,7 +14143,7 @@ function multiplyScalar(vec, scalar) {
|
|
|
14143
14143
|
* @module glMatrix
|
|
14144
14144
|
*/
|
|
14145
14145
|
// Configuration Constants
|
|
14146
|
-
var EPSILON = 0.000001;
|
|
14146
|
+
var EPSILON$1 = 0.000001;
|
|
14147
14147
|
var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
|
|
14148
14148
|
if (!Math.hypot) Math.hypot = function () {
|
|
14149
14149
|
var y = 0,
|
|
@@ -14883,7 +14883,7 @@ function slerp(out, a, b, t) {
|
|
|
14883
14883
|
} // calculate coefficients
|
|
14884
14884
|
|
|
14885
14885
|
|
|
14886
|
-
if (1.0 - cosom > EPSILON) {
|
|
14886
|
+
if (1.0 - cosom > EPSILON$1) {
|
|
14887
14887
|
// standard case (slerp)
|
|
14888
14888
|
omega = Math.acos(cosom);
|
|
14889
14889
|
sinom = Math.sin(omega);
|
|
@@ -15352,7 +15352,7 @@ function interpolate(start, end, fraction) {
|
|
|
15352
15352
|
const MAX_DURATION = 4_294_967_295n * BigInt(1e9);
|
|
15353
15353
|
// Number of transforms evicted is this * max capacity
|
|
15354
15354
|
const MAX_CAPACITY_EVICT_PORTION = 0.25;
|
|
15355
|
-
const DEG2RAD$
|
|
15355
|
+
const DEG2RAD$2 = Math.PI / 180;
|
|
15356
15356
|
const tempLower$1 = [0n, Transform.Identity()];
|
|
15357
15357
|
const tempUpper$1 = [0n, Transform.Identity()];
|
|
15358
15358
|
const tempVec4 = [0, 0, 0, 0];
|
|
@@ -15812,9 +15812,9 @@ function copyPose(out, pose) {
|
|
|
15812
15812
|
// Compute a quaternion from XYZ Euler angles in degrees. This method is adapted
|
|
15813
15813
|
// from THREE.js Quaternionr#setFromEuler()
|
|
15814
15814
|
function quaternionFromEuler(out, euler) {
|
|
15815
|
-
const x = euler[0] * DEG2RAD$
|
|
15816
|
-
const y = euler[1] * DEG2RAD$
|
|
15817
|
-
const z = euler[2] * DEG2RAD$
|
|
15815
|
+
const x = euler[0] * DEG2RAD$2;
|
|
15816
|
+
const y = euler[1] * DEG2RAD$2;
|
|
15817
|
+
const z = euler[2] * DEG2RAD$2;
|
|
15818
15818
|
const c1 = Math.cos(x / 2);
|
|
15819
15819
|
const c2 = Math.cos(y / 2);
|
|
15820
15820
|
const c3 = Math.cos(z / 2);
|
|
@@ -30194,7 +30194,7 @@ const tempVecB = new Vector3();
|
|
|
30194
30194
|
const tempLower = [0n, Transform.Identity()];
|
|
30195
30195
|
const tempUpper = [0n, Transform.Identity()];
|
|
30196
30196
|
const tempQuaternion$1 = new Quaternion();
|
|
30197
|
-
const tempEuler$
|
|
30197
|
+
const tempEuler$2 = new Euler();
|
|
30198
30198
|
const tempTfPath = ["transforms", ""];
|
|
30199
30199
|
class FrameAxes extends SceneExtension {
|
|
30200
30200
|
static extensionId = "foxglove.FrameAxes";
|
|
@@ -30605,8 +30605,8 @@ function buildSettingsFields(frame, currentTime, config) {
|
|
|
30605
30605
|
const q = transform.rotation();
|
|
30606
30606
|
xyzValue = [round$1(p[0], 3), round$1(p[1], 3), round$1(p[2], 3)];
|
|
30607
30607
|
tempQuaternion$1.set(q[0], q[1], q[2], q[3]);
|
|
30608
|
-
tempEuler$
|
|
30609
|
-
rpyValue = [round$1(MathUtils.radToDeg(tempEuler$
|
|
30608
|
+
tempEuler$2.setFromQuaternion(tempQuaternion$1, "XYZ");
|
|
30609
|
+
rpyValue = [round$1(MathUtils.radToDeg(tempEuler$2.x), 3), round$1(MathUtils.radToDeg(tempEuler$2.y), 3), round$1(MathUtils.radToDeg(tempEuler$2.z), 3)];
|
|
30610
30610
|
}
|
|
30611
30611
|
}
|
|
30612
30612
|
const fields = {
|
|
@@ -31477,7 +31477,7 @@ class WorkerImageDecoder {
|
|
|
31477
31477
|
//#reusableBuffer: SharedArrayBuffer | null = null;
|
|
31478
31478
|
|
|
31479
31479
|
constructor() {
|
|
31480
|
-
this.#worker = new Worker(new URL("WorkerImageDecoder.worker-
|
|
31480
|
+
this.#worker = new Worker(new URL("WorkerImageDecoder.worker-C3ZBQ2Wk.js", import.meta.url), {
|
|
31481
31481
|
type: "module"
|
|
31482
31482
|
});
|
|
31483
31483
|
}
|
|
@@ -39157,7 +39157,7 @@ function normalizePolygonStamped(polygon) {
|
|
|
39157
39157
|
};
|
|
39158
39158
|
}
|
|
39159
39159
|
|
|
39160
|
-
function clamp$
|
|
39160
|
+
function clamp$2( value, min, max ) {
|
|
39161
39161
|
|
|
39162
39162
|
return Math.max( min, Math.min( max, value ) );
|
|
39163
39163
|
|
|
@@ -39172,7 +39172,7 @@ const SHAFT_DIAMETER = 1.0;
|
|
|
39172
39172
|
const HEAD_LENGTH = 0.23;
|
|
39173
39173
|
const HEAD_DIAMETER = 2.0;
|
|
39174
39174
|
const HEAD_LENGTH_PROPORTION = 0.23;
|
|
39175
|
-
const UNIT_X$
|
|
39175
|
+
const UNIT_X$1 = new Vector3(1, 0, 0);
|
|
39176
39176
|
const tempStart = new Vector3();
|
|
39177
39177
|
const tempEnd = new Vector3();
|
|
39178
39178
|
const tempDirection = new Vector3();
|
|
@@ -39244,7 +39244,7 @@ class RenderableArrow extends RenderableMarker {
|
|
|
39244
39244
|
let headLength = HEAD_LENGTH_PROPORTION * distance;
|
|
39245
39245
|
if (marker.scale.z !== 0) {
|
|
39246
39246
|
const length = marker.scale.z;
|
|
39247
|
-
headLength = clamp$
|
|
39247
|
+
headLength = clamp$2(length, 0, distance);
|
|
39248
39248
|
}
|
|
39249
39249
|
const shaftLength = distance - headLength;
|
|
39250
39250
|
const shaftDiameter = marker.scale.x;
|
|
@@ -39256,7 +39256,7 @@ class RenderableArrow extends RenderableMarker {
|
|
|
39256
39256
|
this.shaftMesh.position.addScaledVector(tempDirection, 0.5 * (shaftLength / distance));
|
|
39257
39257
|
this.headMesh.position.set(pointB.x, pointB.y, pointB.z);
|
|
39258
39258
|
this.headMesh.position.addScaledVector(tempDirection, -0.5 * (headLength / distance));
|
|
39259
|
-
const rotation = getRotationTo(UNIT_X$
|
|
39259
|
+
const rotation = getRotationTo(UNIT_X$1, tempDirection);
|
|
39260
39260
|
this.shaftMesh.setRotationFromQuaternion(rotation);
|
|
39261
39261
|
this.headMesh.rotation.copy(this.shaftMesh.rotation);
|
|
39262
39262
|
} else {
|
|
@@ -45874,7 +45874,7 @@ const PARAM_DISPLAY_NAME = "/robot_description (parameter)";
|
|
|
45874
45874
|
const VALID_SRC_ERR = "ValidSrc";
|
|
45875
45875
|
const FETCH_URDF_ERR = "FetchUrdf";
|
|
45876
45876
|
const PARSE_URDF_ERR = "ParseUrdf";
|
|
45877
|
-
const DEG2RAD = Math.PI / 180;
|
|
45877
|
+
const DEG2RAD$1 = Math.PI / 180;
|
|
45878
45878
|
const RAD2DEG = 180 / Math.PI;
|
|
45879
45879
|
const DEFAULT_COLOR_STR = "#ffffff";
|
|
45880
45880
|
const DEFAULT_COLOR = stringToRgba(makeRgba(), DEFAULT_COLOR_STR);
|
|
@@ -45913,7 +45913,7 @@ const tempVec3a = new Vector3();
|
|
|
45913
45913
|
const tempVec3b = new Vector3();
|
|
45914
45914
|
const tempQuaternion1 = new Quaternion();
|
|
45915
45915
|
const tempQuaternion2 = new Quaternion();
|
|
45916
|
-
const tempEuler$
|
|
45916
|
+
const tempEuler$1 = new Euler();
|
|
45917
45917
|
var EmbeddedMaterialUsage = /*#__PURE__*/function (EmbeddedMaterialUsage) {
|
|
45918
45918
|
EmbeddedMaterialUsage[EmbeddedMaterialUsage["Use"] = 0] = "Use";
|
|
45919
45919
|
EmbeddedMaterialUsage[EmbeddedMaterialUsage["Ignore"] = 1] = "Ignore";
|
|
@@ -46297,8 +46297,8 @@ class Urdfs extends SceneExtension {
|
|
|
46297
46297
|
const axis = tempVec3a.set(joint.axis.x, joint.axis.y, joint.axis.z);
|
|
46298
46298
|
if (isAngular) {
|
|
46299
46299
|
const degrees = action.payload.value;
|
|
46300
|
-
const quaternion = tempQuaternion1.setFromAxisAngle(axis, degrees * DEG2RAD);
|
|
46301
|
-
const euler = tempEuler$
|
|
46300
|
+
const quaternion = tempQuaternion1.setFromAxisAngle(axis, degrees * DEG2RAD$1);
|
|
46301
|
+
const euler = tempEuler$1.setFromQuaternion(quaternion);
|
|
46302
46302
|
frame.offsetEulerDegrees = [euler.x * RAD2DEG, euler.y * RAD2DEG, euler.z * RAD2DEG];
|
|
46303
46303
|
this.saveSetting(["transforms", frameKey, "rpyCoefficient"], frame.offsetEulerDegrees);
|
|
46304
46304
|
} else {
|
|
@@ -47169,8 +47169,8 @@ function urdfChildren(transforms, transformTree, jointStates) {
|
|
|
47169
47169
|
return children;
|
|
47170
47170
|
}
|
|
47171
47171
|
function eulerDegreesToQuaternion(eulerDegrees) {
|
|
47172
|
-
tempEuler$
|
|
47173
|
-
return tempQuaternion1.setFromEuler(tempEuler$
|
|
47172
|
+
tempEuler$1.set(eulerDegrees[0] * DEG2RAD$1, eulerDegrees[1] * DEG2RAD$1, eulerDegrees[2] * DEG2RAD$1);
|
|
47173
|
+
return tempQuaternion1.setFromEuler(tempEuler$1);
|
|
47174
47174
|
}
|
|
47175
47175
|
function signedDistanceAlongAxis(position, axis) {
|
|
47176
47176
|
const p = tempVec3a.set(position[0], position[1], position[2]);
|
|
@@ -53136,7 +53136,7 @@ function distanceInRange(distance, min, max) {
|
|
|
53136
53136
|
return distance >= min && distance <= max;
|
|
53137
53137
|
}
|
|
53138
53138
|
// Clamp a value in the range of [min..max]
|
|
53139
|
-
function clamp(value, min, max) {
|
|
53139
|
+
function clamp$1(value, min, max) {
|
|
53140
53140
|
return value <= min ? min : value >= max ? max : value;
|
|
53141
53141
|
}
|
|
53142
53142
|
// Return the default [min, max] range of valid distances for a given hardware model
|
|
@@ -53241,7 +53241,7 @@ function computeIntensity(rawIntensity, rawDistance, corrections) {
|
|
|
53241
53241
|
const maxIntensity = corrections.maxIntensity;
|
|
53242
53242
|
const focalOffset = 256 * (1 - corrections.focalDistance / 13100) * (1 - corrections.focalDistance / 13100);
|
|
53243
53243
|
const focalSlope = corrections.focalSlope;
|
|
53244
|
-
return clamp(rawIntensity + focalSlope * Math.abs(focalOffset - 256 * sqr(1 - rawDistance / 65535)), minIntensity, maxIntensity);
|
|
53244
|
+
return clamp$1(rawIntensity + focalSlope * Math.abs(focalOffset - 256 * sqr(1 - rawDistance / 65535)), minIntensity, maxIntensity);
|
|
53245
53245
|
}
|
|
53246
53246
|
|
|
53247
53247
|
(function (exports) {
|
|
@@ -53762,7 +53762,7 @@ class MeasurementTool extends SceneExtension {
|
|
|
53762
53762
|
// License, v2.0. If a copy of the MPL was not distributed with this
|
|
53763
53763
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/
|
|
53764
53764
|
|
|
53765
|
-
const UNIT_X
|
|
53765
|
+
const UNIT_X = new Vector3(1, 0, 0);
|
|
53766
53766
|
const tempVec3$2 = new Vector3();
|
|
53767
53767
|
function makeArrowMarker(type) {
|
|
53768
53768
|
return {
|
|
@@ -53942,7 +53942,7 @@ class PublishClickTool extends SceneExtension {
|
|
|
53942
53942
|
this.#point2 = worldSpaceCursorCoords.clone();
|
|
53943
53943
|
if (this.#point1 && this.publishClickType !== "point") {
|
|
53944
53944
|
const p = this.#point1.clone();
|
|
53945
|
-
const q = new Quaternion().setFromUnitVectors(UNIT_X
|
|
53945
|
+
const q = new Quaternion().setFromUnitVectors(UNIT_X, tempVec3$2.subVectors(this.#point2, this.#point1).normalize());
|
|
53946
53946
|
this.dispatchEvent({
|
|
53947
53947
|
type: "foxglove.publish-submit",
|
|
53948
53948
|
publishClickType: this.publishClickType,
|
|
@@ -53981,7 +53981,7 @@ class PublishClickTool extends SceneExtension {
|
|
|
53981
53981
|
this.#arrow.visible = true;
|
|
53982
53982
|
this.#arrow.position.copy(this.#point1);
|
|
53983
53983
|
if (this.#point2) {
|
|
53984
|
-
this.#arrow.quaternion.setFromUnitVectors(UNIT_X
|
|
53984
|
+
this.#arrow.quaternion.setFromUnitVectors(UNIT_X, tempVec3$2.subVectors(this.#point2, this.#point1).normalize());
|
|
53985
53985
|
} else {
|
|
53986
53986
|
this.#arrow.quaternion.set(0, 0, 0, 1);
|
|
53987
53987
|
}
|
|
@@ -55980,7 +55980,7 @@ const REPLACEMENT_CHARACTER = "\uFFFD";
|
|
|
55980
55980
|
* Manages the creation of a Signed Distance Field (SDF) font atlas, and performs text layout to
|
|
55981
55981
|
* generate attributes for rendering text using the atlas.
|
|
55982
55982
|
*/
|
|
55983
|
-
class FontManager extends EventDispatcher {
|
|
55983
|
+
class FontManager extends EventDispatcher$1 {
|
|
55984
55984
|
options;
|
|
55985
55985
|
alphabet = "";
|
|
55986
55986
|
atlasData = {
|
|
@@ -56194,7 +56194,9 @@ out vec4 outColor;
|
|
|
56194
56194
|
|
|
56195
56195
|
${
|
|
56196
56196
|
// for LinearTosRGB()
|
|
56197
|
-
ShaderChunk.colorspace_pars_fragment
|
|
56197
|
+
ShaderChunk.colorspace_pars_fragment ??
|
|
56198
|
+
// for backward compatibility with three@<154
|
|
56199
|
+
ShaderChunk.encodings_pars_fragment}
|
|
56198
56200
|
|
|
56199
56201
|
// From https://github.com/Jam3/three-bmfont-text/blob/e17efbe4e9392a83d4c5ee35c67eca5a11a13395/shaders/sdf.js
|
|
56200
56202
|
float aastep(float threshold, float value) {
|
|
@@ -56421,7 +56423,7 @@ class Label extends Object3D {
|
|
|
56421
56423
|
this.pickingMaterial.uniforms.uScale.value = scale;
|
|
56422
56424
|
}
|
|
56423
56425
|
}
|
|
56424
|
-
class LabelPool extends EventDispatcher {
|
|
56426
|
+
class LabelPool extends EventDispatcher$1 {
|
|
56425
56427
|
atlasTexture;
|
|
56426
56428
|
availableLabels = [];
|
|
56427
56429
|
disposed = false;
|
|
@@ -57439,1447 +57441,2607 @@ class SharedGeometry {
|
|
|
57439
57441
|
}
|
|
57440
57442
|
}
|
|
57441
57443
|
|
|
57442
|
-
|
|
57443
|
-
|
|
57444
|
-
|
|
57445
|
-
|
|
57446
|
-
|
|
57447
|
-
|
|
57448
|
-
|
|
57449
|
-
const
|
|
57450
|
-
|
|
57451
|
-
|
|
57452
|
-
|
|
57453
|
-
|
|
57454
|
-
const
|
|
57455
|
-
|
|
57456
|
-
|
|
57457
|
-
|
|
57458
|
-
|
|
57459
|
-
|
|
57460
|
-
|
|
57461
|
-
|
|
57462
|
-
|
|
57463
|
-
|
|
57464
|
-
|
|
57465
|
-
|
|
57466
|
-
|
|
57467
|
-
|
|
57468
|
-
|
|
57469
|
-
|
|
57470
|
-
|
|
57471
|
-
|
|
57472
|
-
|
|
57473
|
-
|
|
57474
|
-
|
|
57475
|
-
|
|
57476
|
-
|
|
57477
|
-
|
|
57478
|
-
|
|
57479
|
-
|
|
57480
|
-
|
|
57481
|
-
|
|
57482
|
-
|
|
57483
|
-
|
|
57484
|
-
|
|
57485
|
-
|
|
57486
|
-
|
|
57487
|
-
|
|
57488
|
-
this.maxAzimuthAngle = Infinity; // radians
|
|
57489
|
-
|
|
57490
|
-
// Set to true to enable damping (inertia)
|
|
57491
|
-
// If damping is enabled, you must call controls.update() in your animation loop
|
|
57492
|
-
this.enableDamping = false;
|
|
57493
|
-
this.dampingFactor = 0.05;
|
|
57494
|
-
|
|
57495
|
-
// This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
|
|
57496
|
-
// Set to false to disable zooming
|
|
57497
|
-
this.enableZoom = true;
|
|
57498
|
-
this.zoomSpeed = 1.0;
|
|
57499
|
-
|
|
57500
|
-
// Set to false to disable rotating
|
|
57501
|
-
this.enableRotate = true;
|
|
57502
|
-
this.rotateSpeed = 1.0;
|
|
57503
|
-
|
|
57504
|
-
// Set to false to disable panning
|
|
57505
|
-
this.enablePan = true;
|
|
57506
|
-
this.panSpeed = 1.0;
|
|
57507
|
-
this.screenSpacePanning = true; // if false, pan orthogonal to world-space direction camera.up
|
|
57508
|
-
this.keyPanSpeed = 7.0; // pixels moved per arrow key push
|
|
57509
|
-
this.zoomToCursor = false;
|
|
57510
|
-
|
|
57511
|
-
// Set to true to automatically rotate around the target
|
|
57512
|
-
// If auto-rotate is enabled, you must call controls.update() in your animation loop
|
|
57513
|
-
this.autoRotate = false;
|
|
57514
|
-
this.autoRotateSpeed = 2.0; // 30 seconds per orbit when fps is 60
|
|
57444
|
+
/*!
|
|
57445
|
+
* camera-controls
|
|
57446
|
+
* https://github.com/yomotsu/camera-controls
|
|
57447
|
+
* (c) 2017 @yomotsu
|
|
57448
|
+
* Released under the MIT License.
|
|
57449
|
+
*/
|
|
57450
|
+
// see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons#value
|
|
57451
|
+
const MOUSE_BUTTON = {
|
|
57452
|
+
LEFT: 1,
|
|
57453
|
+
RIGHT: 2,
|
|
57454
|
+
MIDDLE: 4,
|
|
57455
|
+
};
|
|
57456
|
+
const ACTION = Object.freeze({
|
|
57457
|
+
NONE: 0b0,
|
|
57458
|
+
ROTATE: 0b1,
|
|
57459
|
+
TRUCK: 0b10,
|
|
57460
|
+
SCREEN_PAN: 0b100,
|
|
57461
|
+
OFFSET: 0b1000,
|
|
57462
|
+
DOLLY: 0b10000,
|
|
57463
|
+
ZOOM: 0b100000,
|
|
57464
|
+
TOUCH_ROTATE: 0b1000000,
|
|
57465
|
+
TOUCH_TRUCK: 0b10000000,
|
|
57466
|
+
TOUCH_SCREEN_PAN: 0b100000000,
|
|
57467
|
+
TOUCH_OFFSET: 0b1000000000,
|
|
57468
|
+
TOUCH_DOLLY: 0b10000000000,
|
|
57469
|
+
TOUCH_ZOOM: 0b100000000000,
|
|
57470
|
+
TOUCH_DOLLY_TRUCK: 0b1000000000000,
|
|
57471
|
+
TOUCH_DOLLY_SCREEN_PAN: 0b10000000000000,
|
|
57472
|
+
TOUCH_DOLLY_OFFSET: 0b100000000000000,
|
|
57473
|
+
TOUCH_DOLLY_ROTATE: 0b1000000000000000,
|
|
57474
|
+
TOUCH_ZOOM_TRUCK: 0b10000000000000000,
|
|
57475
|
+
TOUCH_ZOOM_OFFSET: 0b100000000000000000,
|
|
57476
|
+
TOUCH_ZOOM_SCREEN_PAN: 0b1000000000000000000,
|
|
57477
|
+
TOUCH_ZOOM_ROTATE: 0b10000000000000000000,
|
|
57478
|
+
});
|
|
57479
|
+
const DOLLY_DIRECTION = {
|
|
57480
|
+
NONE: 0,
|
|
57481
|
+
IN: 1,
|
|
57482
|
+
OUT: -1,
|
|
57483
|
+
};
|
|
57484
|
+
function isPerspectiveCamera(camera) {
|
|
57485
|
+
return camera.isPerspectiveCamera;
|
|
57486
|
+
}
|
|
57487
|
+
function isOrthographicCamera(camera) {
|
|
57488
|
+
return camera.isOrthographicCamera;
|
|
57489
|
+
}
|
|
57515
57490
|
|
|
57516
|
-
|
|
57517
|
-
|
|
57491
|
+
const PI_2 = Math.PI * 2;
|
|
57492
|
+
const PI_HALF = Math.PI / 2;
|
|
57518
57493
|
|
|
57519
|
-
|
|
57520
|
-
|
|
57494
|
+
const EPSILON = 1e-5;
|
|
57495
|
+
const DEG2RAD = Math.PI / 180;
|
|
57496
|
+
function clamp(value, min, max) {
|
|
57497
|
+
return Math.max(min, Math.min(max, value));
|
|
57498
|
+
}
|
|
57499
|
+
function approxZero(number, error = EPSILON) {
|
|
57500
|
+
return Math.abs(number) < error;
|
|
57501
|
+
}
|
|
57502
|
+
function approxEquals(a, b, error = EPSILON) {
|
|
57503
|
+
return approxZero(a - b, error);
|
|
57504
|
+
}
|
|
57505
|
+
function roundToStep(value, step) {
|
|
57506
|
+
return Math.round(value / step) * step;
|
|
57507
|
+
}
|
|
57508
|
+
function infinityToMaxNumber(value) {
|
|
57509
|
+
if (isFinite(value))
|
|
57510
|
+
return value;
|
|
57511
|
+
if (value < 0)
|
|
57512
|
+
return -Number.MAX_VALUE;
|
|
57513
|
+
return Number.MAX_VALUE;
|
|
57514
|
+
}
|
|
57515
|
+
function maxNumberToInfinity(value) {
|
|
57516
|
+
if (Math.abs(value) < Number.MAX_VALUE)
|
|
57517
|
+
return value;
|
|
57518
|
+
return value * Infinity;
|
|
57519
|
+
}
|
|
57520
|
+
// https://docs.unity3d.com/ScriptReference/Mathf.SmoothDamp.html
|
|
57521
|
+
// https://github.com/Unity-Technologies/UnityCsReference/blob/a2bdfe9b3c4cd4476f44bf52f848063bfaf7b6b9/Runtime/Export/Math/Mathf.cs#L308
|
|
57522
|
+
function smoothDamp(current, target, currentVelocityRef, smoothTime, maxSpeed = Infinity, deltaTime) {
|
|
57523
|
+
// Based on Game Programming Gems 4 Chapter 1.10
|
|
57524
|
+
smoothTime = Math.max(0.0001, smoothTime);
|
|
57525
|
+
const omega = 2 / smoothTime;
|
|
57526
|
+
const x = omega * deltaTime;
|
|
57527
|
+
const exp = 1 / (1 + x + 0.48 * x * x + 0.235 * x * x * x);
|
|
57528
|
+
let change = current - target;
|
|
57529
|
+
const originalTo = target;
|
|
57530
|
+
// Clamp maximum speed
|
|
57531
|
+
const maxChange = maxSpeed * smoothTime;
|
|
57532
|
+
change = clamp(change, -maxChange, maxChange);
|
|
57533
|
+
target = current - change;
|
|
57534
|
+
const temp = (currentVelocityRef.value + omega * change) * deltaTime;
|
|
57535
|
+
currentVelocityRef.value = (currentVelocityRef.value - omega * temp) * exp;
|
|
57536
|
+
let output = target + (change + temp) * exp;
|
|
57537
|
+
// Prevent overshooting
|
|
57538
|
+
if (originalTo - current > 0.0 === output > originalTo) {
|
|
57539
|
+
output = originalTo;
|
|
57540
|
+
currentVelocityRef.value = (output - originalTo) / deltaTime;
|
|
57541
|
+
}
|
|
57542
|
+
return output;
|
|
57543
|
+
}
|
|
57544
|
+
// https://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html
|
|
57545
|
+
// https://github.com/Unity-Technologies/UnityCsReference/blob/a2bdfe9b3c4cd4476f44bf52f848063bfaf7b6b9/Runtime/Export/Math/Vector3.cs#L97
|
|
57546
|
+
function smoothDampVec3(current, target, currentVelocityRef, smoothTime, maxSpeed = Infinity, deltaTime, out) {
|
|
57547
|
+
// Based on Game Programming Gems 4 Chapter 1.10
|
|
57548
|
+
smoothTime = Math.max(0.0001, smoothTime);
|
|
57549
|
+
const omega = 2 / smoothTime;
|
|
57550
|
+
const x = omega * deltaTime;
|
|
57551
|
+
const exp = 1 / (1 + x + 0.48 * x * x + 0.235 * x * x * x);
|
|
57552
|
+
let targetX = target.x;
|
|
57553
|
+
let targetY = target.y;
|
|
57554
|
+
let targetZ = target.z;
|
|
57555
|
+
let changeX = current.x - targetX;
|
|
57556
|
+
let changeY = current.y - targetY;
|
|
57557
|
+
let changeZ = current.z - targetZ;
|
|
57558
|
+
const originalToX = targetX;
|
|
57559
|
+
const originalToY = targetY;
|
|
57560
|
+
const originalToZ = targetZ;
|
|
57561
|
+
// Clamp maximum speed
|
|
57562
|
+
const maxChange = maxSpeed * smoothTime;
|
|
57563
|
+
const maxChangeSq = maxChange * maxChange;
|
|
57564
|
+
const magnitudeSq = changeX * changeX + changeY * changeY + changeZ * changeZ;
|
|
57565
|
+
if (magnitudeSq > maxChangeSq) {
|
|
57566
|
+
const magnitude = Math.sqrt(magnitudeSq);
|
|
57567
|
+
changeX = changeX / magnitude * maxChange;
|
|
57568
|
+
changeY = changeY / magnitude * maxChange;
|
|
57569
|
+
changeZ = changeZ / magnitude * maxChange;
|
|
57570
|
+
}
|
|
57571
|
+
targetX = current.x - changeX;
|
|
57572
|
+
targetY = current.y - changeY;
|
|
57573
|
+
targetZ = current.z - changeZ;
|
|
57574
|
+
const tempX = (currentVelocityRef.x + omega * changeX) * deltaTime;
|
|
57575
|
+
const tempY = (currentVelocityRef.y + omega * changeY) * deltaTime;
|
|
57576
|
+
const tempZ = (currentVelocityRef.z + omega * changeZ) * deltaTime;
|
|
57577
|
+
currentVelocityRef.x = (currentVelocityRef.x - omega * tempX) * exp;
|
|
57578
|
+
currentVelocityRef.y = (currentVelocityRef.y - omega * tempY) * exp;
|
|
57579
|
+
currentVelocityRef.z = (currentVelocityRef.z - omega * tempZ) * exp;
|
|
57580
|
+
out.x = targetX + (changeX + tempX) * exp;
|
|
57581
|
+
out.y = targetY + (changeY + tempY) * exp;
|
|
57582
|
+
out.z = targetZ + (changeZ + tempZ) * exp;
|
|
57583
|
+
// Prevent overshooting
|
|
57584
|
+
const origMinusCurrentX = originalToX - current.x;
|
|
57585
|
+
const origMinusCurrentY = originalToY - current.y;
|
|
57586
|
+
const origMinusCurrentZ = originalToZ - current.z;
|
|
57587
|
+
const outMinusOrigX = out.x - originalToX;
|
|
57588
|
+
const outMinusOrigY = out.y - originalToY;
|
|
57589
|
+
const outMinusOrigZ = out.z - originalToZ;
|
|
57590
|
+
if (origMinusCurrentX * outMinusOrigX + origMinusCurrentY * outMinusOrigY + origMinusCurrentZ * outMinusOrigZ > 0) {
|
|
57591
|
+
out.x = originalToX;
|
|
57592
|
+
out.y = originalToY;
|
|
57593
|
+
out.z = originalToZ;
|
|
57594
|
+
currentVelocityRef.x = (out.x - originalToX) / deltaTime;
|
|
57595
|
+
currentVelocityRef.y = (out.y - originalToY) / deltaTime;
|
|
57596
|
+
currentVelocityRef.z = (out.z - originalToZ) / deltaTime;
|
|
57597
|
+
}
|
|
57598
|
+
return out;
|
|
57599
|
+
}
|
|
57521
57600
|
|
|
57522
|
-
|
|
57523
|
-
|
|
57601
|
+
function extractClientCoordFromEvent(pointers, out) {
|
|
57602
|
+
out.set(0, 0);
|
|
57603
|
+
pointers.forEach((pointer) => {
|
|
57604
|
+
out.x += pointer.clientX;
|
|
57605
|
+
out.y += pointer.clientY;
|
|
57606
|
+
});
|
|
57607
|
+
out.x /= pointers.length;
|
|
57608
|
+
out.y /= pointers.length;
|
|
57609
|
+
}
|
|
57524
57610
|
|
|
57525
|
-
|
|
57526
|
-
|
|
57527
|
-
|
|
57528
|
-
|
|
57611
|
+
function notSupportedInOrthographicCamera(camera, message) {
|
|
57612
|
+
if (isOrthographicCamera(camera)) {
|
|
57613
|
+
console.warn(`${message} is not supported in OrthographicCamera`);
|
|
57614
|
+
return true;
|
|
57615
|
+
}
|
|
57616
|
+
return false;
|
|
57617
|
+
}
|
|
57529
57618
|
|
|
57530
|
-
|
|
57531
|
-
|
|
57619
|
+
class EventDispatcher {
|
|
57620
|
+
constructor() {
|
|
57621
|
+
this._listeners = {};
|
|
57622
|
+
}
|
|
57623
|
+
/**
|
|
57624
|
+
* Adds the specified event listener.
|
|
57625
|
+
* @param type event name
|
|
57626
|
+
* @param listener handler function
|
|
57627
|
+
* @category Methods
|
|
57628
|
+
*/
|
|
57629
|
+
addEventListener(type, listener) {
|
|
57630
|
+
const listeners = this._listeners;
|
|
57631
|
+
if (listeners[type] === undefined)
|
|
57632
|
+
listeners[type] = [];
|
|
57633
|
+
if (listeners[type].indexOf(listener) === -1)
|
|
57634
|
+
listeners[type].push(listener);
|
|
57635
|
+
}
|
|
57636
|
+
/**
|
|
57637
|
+
* Presence of the specified event listener.
|
|
57638
|
+
* @param type event name
|
|
57639
|
+
* @param listener handler function
|
|
57640
|
+
* @category Methods
|
|
57641
|
+
*/
|
|
57642
|
+
hasEventListener(type, listener) {
|
|
57643
|
+
const listeners = this._listeners;
|
|
57644
|
+
return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
|
|
57645
|
+
}
|
|
57646
|
+
/**
|
|
57647
|
+
* Removes the specified event listener
|
|
57648
|
+
* @param type event name
|
|
57649
|
+
* @param listener handler function
|
|
57650
|
+
* @category Methods
|
|
57651
|
+
*/
|
|
57652
|
+
removeEventListener(type, listener) {
|
|
57653
|
+
const listeners = this._listeners;
|
|
57654
|
+
const listenerArray = listeners[type];
|
|
57655
|
+
if (listenerArray !== undefined) {
|
|
57656
|
+
const index = listenerArray.indexOf(listener);
|
|
57657
|
+
if (index !== -1)
|
|
57658
|
+
listenerArray.splice(index, 1);
|
|
57659
|
+
}
|
|
57660
|
+
}
|
|
57661
|
+
/**
|
|
57662
|
+
* Removes all event listeners
|
|
57663
|
+
* @param type event name
|
|
57664
|
+
* @category Methods
|
|
57665
|
+
*/
|
|
57666
|
+
removeAllEventListeners(type) {
|
|
57667
|
+
if (!type) {
|
|
57668
|
+
this._listeners = {};
|
|
57669
|
+
return;
|
|
57670
|
+
}
|
|
57671
|
+
if (Array.isArray(this._listeners[type]))
|
|
57672
|
+
this._listeners[type].length = 0;
|
|
57673
|
+
}
|
|
57674
|
+
/**
|
|
57675
|
+
* Fire an event type.
|
|
57676
|
+
* @param event DispatcherEvent
|
|
57677
|
+
* @category Methods
|
|
57678
|
+
*/
|
|
57679
|
+
dispatchEvent(event) {
|
|
57680
|
+
const listeners = this._listeners;
|
|
57681
|
+
const listenerArray = listeners[event.type];
|
|
57682
|
+
if (listenerArray !== undefined) {
|
|
57683
|
+
event.target = this;
|
|
57684
|
+
const array = listenerArray.slice(0);
|
|
57685
|
+
for (let i = 0, l = array.length; i < l; i++) {
|
|
57686
|
+
array[i].call(this, event);
|
|
57687
|
+
}
|
|
57688
|
+
}
|
|
57689
|
+
}
|
|
57690
|
+
}
|
|
57532
57691
|
|
|
57533
|
-
|
|
57534
|
-
|
|
57535
|
-
|
|
57692
|
+
var _a;
|
|
57693
|
+
const VERSION = '2.10.0'; // will be replaced with `version` in package.json during the build process.
|
|
57694
|
+
const TOUCH_DOLLY_FACTOR = 1 / 8;
|
|
57695
|
+
const isMac = /Mac/.test((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _a === void 0 ? void 0 : _a.platform);
|
|
57696
|
+
let THREE;
|
|
57697
|
+
let _ORIGIN;
|
|
57698
|
+
let _AXIS_Y;
|
|
57699
|
+
let _AXIS_Z;
|
|
57700
|
+
let _v2;
|
|
57701
|
+
let _v3A;
|
|
57702
|
+
let _v3B;
|
|
57703
|
+
let _v3C;
|
|
57704
|
+
let _cameraDirection;
|
|
57705
|
+
let _xColumn;
|
|
57706
|
+
let _yColumn;
|
|
57707
|
+
let _zColumn;
|
|
57708
|
+
let _deltaTarget;
|
|
57709
|
+
let _deltaOffset;
|
|
57710
|
+
let _sphericalA;
|
|
57711
|
+
let _sphericalB;
|
|
57712
|
+
let _box3A;
|
|
57713
|
+
let _box3B;
|
|
57714
|
+
let _sphere;
|
|
57715
|
+
let _quaternionA;
|
|
57716
|
+
let _quaternionB;
|
|
57717
|
+
let _rotationMatrix;
|
|
57718
|
+
let _raycaster;
|
|
57719
|
+
class CameraControls extends EventDispatcher {
|
|
57720
|
+
/**
|
|
57721
|
+
* Injects THREE as the dependency. You can then proceed to use CameraControls.
|
|
57722
|
+
*
|
|
57723
|
+
* e.g
|
|
57724
|
+
* ```javascript
|
|
57725
|
+
* CameraControls.install( { THREE: THREE } );
|
|
57726
|
+
* ```
|
|
57727
|
+
*
|
|
57728
|
+
* Note: If you do not wish to use enter three.js to reduce file size(tree-shaking for example), make a subset to install.
|
|
57729
|
+
*
|
|
57730
|
+
* ```js
|
|
57731
|
+
* import {
|
|
57732
|
+
* Vector2,
|
|
57733
|
+
* Vector3,
|
|
57734
|
+
* Vector4,
|
|
57735
|
+
* Quaternion,
|
|
57736
|
+
* Matrix4,
|
|
57737
|
+
* Spherical,
|
|
57738
|
+
* Box3,
|
|
57739
|
+
* Sphere,
|
|
57740
|
+
* Raycaster,
|
|
57741
|
+
* MathUtils,
|
|
57742
|
+
* } from 'three';
|
|
57743
|
+
*
|
|
57744
|
+
* const subsetOfTHREE = {
|
|
57745
|
+
* Vector2 : Vector2,
|
|
57746
|
+
* Vector3 : Vector3,
|
|
57747
|
+
* Vector4 : Vector4,
|
|
57748
|
+
* Quaternion: Quaternion,
|
|
57749
|
+
* Matrix4 : Matrix4,
|
|
57750
|
+
* Spherical : Spherical,
|
|
57751
|
+
* Box3 : Box3,
|
|
57752
|
+
* Sphere : Sphere,
|
|
57753
|
+
* Raycaster : Raycaster,
|
|
57754
|
+
* };
|
|
57755
|
+
|
|
57756
|
+
* CameraControls.install( { THREE: subsetOfTHREE } );
|
|
57757
|
+
* ```
|
|
57758
|
+
* @category Statics
|
|
57759
|
+
*/
|
|
57760
|
+
static install(libs) {
|
|
57761
|
+
THREE = libs.THREE;
|
|
57762
|
+
_ORIGIN = Object.freeze(new THREE.Vector3(0, 0, 0));
|
|
57763
|
+
_AXIS_Y = Object.freeze(new THREE.Vector3(0, 1, 0));
|
|
57764
|
+
_AXIS_Z = Object.freeze(new THREE.Vector3(0, 0, 1));
|
|
57765
|
+
_v2 = new THREE.Vector2();
|
|
57766
|
+
_v3A = new THREE.Vector3();
|
|
57767
|
+
_v3B = new THREE.Vector3();
|
|
57768
|
+
_v3C = new THREE.Vector3();
|
|
57769
|
+
_cameraDirection = new THREE.Vector3();
|
|
57770
|
+
_xColumn = new THREE.Vector3();
|
|
57771
|
+
_yColumn = new THREE.Vector3();
|
|
57772
|
+
_zColumn = new THREE.Vector3();
|
|
57773
|
+
_deltaTarget = new THREE.Vector3();
|
|
57774
|
+
_deltaOffset = new THREE.Vector3();
|
|
57775
|
+
_sphericalA = new THREE.Spherical();
|
|
57776
|
+
_sphericalB = new THREE.Spherical();
|
|
57777
|
+
_box3A = new THREE.Box3();
|
|
57778
|
+
_box3B = new THREE.Box3();
|
|
57779
|
+
_sphere = new THREE.Sphere();
|
|
57780
|
+
_quaternionA = new THREE.Quaternion();
|
|
57781
|
+
_quaternionB = new THREE.Quaternion();
|
|
57782
|
+
_rotationMatrix = new THREE.Matrix4();
|
|
57783
|
+
_raycaster = new THREE.Raycaster();
|
|
57784
|
+
}
|
|
57785
|
+
/**
|
|
57786
|
+
* list all ACTIONs
|
|
57787
|
+
* @category Statics
|
|
57788
|
+
*/
|
|
57789
|
+
static get ACTION() {
|
|
57790
|
+
return ACTION;
|
|
57791
|
+
}
|
|
57792
|
+
/**
|
|
57793
|
+
* Creates a `CameraControls` instance.
|
|
57794
|
+
*
|
|
57795
|
+
* Note:
|
|
57796
|
+
* You **must install** three.js before using camera-controls. see [#install](#install)
|
|
57797
|
+
* Not doing so will lead to runtime errors (`undefined` references to THREE).
|
|
57798
|
+
*
|
|
57799
|
+
* e.g.
|
|
57800
|
+
* ```
|
|
57801
|
+
* CameraControls.install( { THREE } );
|
|
57802
|
+
* const cameraControls = new CameraControls( camera, domElement );
|
|
57803
|
+
* ```
|
|
57804
|
+
*
|
|
57805
|
+
* @param camera A `THREE.PerspectiveCamera` or `THREE.OrthographicCamera` to be controlled.
|
|
57806
|
+
* @param domElement A `HTMLElement` for the draggable area, usually `renderer.domElement`.
|
|
57807
|
+
* @category Constructor
|
|
57808
|
+
*/
|
|
57809
|
+
constructor(camera, domElement) {
|
|
57810
|
+
super();
|
|
57811
|
+
/**
|
|
57812
|
+
* Minimum vertical angle in radians.
|
|
57813
|
+
* The angle has to be between `0` and `.maxPolarAngle` inclusive.
|
|
57814
|
+
* The default value is `0`.
|
|
57815
|
+
*
|
|
57816
|
+
* e.g.
|
|
57817
|
+
* ```
|
|
57818
|
+
* cameraControls.maxPolarAngle = 0;
|
|
57819
|
+
* ```
|
|
57820
|
+
* @category Properties
|
|
57821
|
+
*/
|
|
57822
|
+
this.minPolarAngle = 0; // radians
|
|
57823
|
+
/**
|
|
57824
|
+
* Maximum vertical angle in radians.
|
|
57825
|
+
* The angle has to be between `.maxPolarAngle` and `Math.PI` inclusive.
|
|
57826
|
+
* The default value is `Math.PI`.
|
|
57827
|
+
*
|
|
57828
|
+
* e.g.
|
|
57829
|
+
* ```
|
|
57830
|
+
* cameraControls.maxPolarAngle = Math.PI;
|
|
57831
|
+
* ```
|
|
57832
|
+
* @category Properties
|
|
57833
|
+
*/
|
|
57834
|
+
this.maxPolarAngle = Math.PI; // radians
|
|
57835
|
+
/**
|
|
57836
|
+
* Minimum horizontal angle in radians.
|
|
57837
|
+
* The angle has to be less than `.maxAzimuthAngle`.
|
|
57838
|
+
* The default value is `- Infinity`.
|
|
57839
|
+
*
|
|
57840
|
+
* e.g.
|
|
57841
|
+
* ```
|
|
57842
|
+
* cameraControls.minAzimuthAngle = - Infinity;
|
|
57843
|
+
* ```
|
|
57844
|
+
* @category Properties
|
|
57845
|
+
*/
|
|
57846
|
+
this.minAzimuthAngle = -Infinity; // radians
|
|
57847
|
+
/**
|
|
57848
|
+
* Maximum horizontal angle in radians.
|
|
57849
|
+
* The angle has to be greater than `.minAzimuthAngle`.
|
|
57850
|
+
* The default value is `Infinity`.
|
|
57851
|
+
*
|
|
57852
|
+
* e.g.
|
|
57853
|
+
* ```
|
|
57854
|
+
* cameraControls.maxAzimuthAngle = Infinity;
|
|
57855
|
+
* ```
|
|
57856
|
+
* @category Properties
|
|
57857
|
+
*/
|
|
57858
|
+
this.maxAzimuthAngle = Infinity; // radians
|
|
57859
|
+
// How far you can dolly in and out ( PerspectiveCamera only )
|
|
57860
|
+
/**
|
|
57861
|
+
* Minimum distance for dolly. The value must be higher than `0`. Default is `Number.EPSILON`.
|
|
57862
|
+
* PerspectiveCamera only.
|
|
57863
|
+
* @category Properties
|
|
57864
|
+
*/
|
|
57865
|
+
this.minDistance = Number.EPSILON;
|
|
57866
|
+
/**
|
|
57867
|
+
* Maximum distance for dolly. The value must be higher than `minDistance`. Default is `Infinity`.
|
|
57868
|
+
* PerspectiveCamera only.
|
|
57869
|
+
* @category Properties
|
|
57870
|
+
*/
|
|
57871
|
+
this.maxDistance = Infinity;
|
|
57872
|
+
/**
|
|
57873
|
+
* `true` to enable Infinity Dolly for wheel and pinch. Use this with `minDistance` and `maxDistance`
|
|
57874
|
+
* If the Dolly distance is less (or over) than the `minDistance` (or `maxDistance`), `infinityDolly` will keep the distance and pushes the target position instead.
|
|
57875
|
+
* @category Properties
|
|
57876
|
+
*/
|
|
57877
|
+
this.infinityDolly = false;
|
|
57878
|
+
/**
|
|
57879
|
+
* Minimum camera zoom.
|
|
57880
|
+
* @category Properties
|
|
57881
|
+
*/
|
|
57882
|
+
this.minZoom = 0.01;
|
|
57883
|
+
/**
|
|
57884
|
+
* Maximum camera zoom.
|
|
57885
|
+
* @category Properties
|
|
57886
|
+
*/
|
|
57887
|
+
this.maxZoom = Infinity;
|
|
57888
|
+
/**
|
|
57889
|
+
* Approximate time in seconds to reach the target. A smaller value will reach the target faster.
|
|
57890
|
+
* @category Properties
|
|
57891
|
+
*/
|
|
57892
|
+
this.smoothTime = 0.25;
|
|
57893
|
+
/**
|
|
57894
|
+
* the smoothTime while dragging
|
|
57895
|
+
* @category Properties
|
|
57896
|
+
*/
|
|
57897
|
+
this.draggingSmoothTime = 0.125;
|
|
57898
|
+
/**
|
|
57899
|
+
* Max transition speed in unit-per-seconds
|
|
57900
|
+
* @category Properties
|
|
57901
|
+
*/
|
|
57902
|
+
this.maxSpeed = Infinity;
|
|
57903
|
+
/**
|
|
57904
|
+
* Speed of azimuth (horizontal) rotation.
|
|
57905
|
+
* @category Properties
|
|
57906
|
+
*/
|
|
57907
|
+
this.azimuthRotateSpeed = 1.0;
|
|
57908
|
+
/**
|
|
57909
|
+
* Speed of polar (vertical) rotation.
|
|
57910
|
+
* @category Properties
|
|
57911
|
+
*/
|
|
57912
|
+
this.polarRotateSpeed = 1.0;
|
|
57913
|
+
/**
|
|
57914
|
+
* Speed of mouse-wheel dollying.
|
|
57915
|
+
* @category Properties
|
|
57916
|
+
*/
|
|
57917
|
+
this.dollySpeed = 1.0;
|
|
57918
|
+
/**
|
|
57919
|
+
* `true` to invert direction when dollying or zooming via drag
|
|
57920
|
+
* @category Properties
|
|
57921
|
+
*/
|
|
57922
|
+
this.dollyDragInverted = false;
|
|
57923
|
+
/**
|
|
57924
|
+
* Speed of drag for truck and pedestal.
|
|
57925
|
+
* @category Properties
|
|
57926
|
+
*/
|
|
57927
|
+
this.truckSpeed = 2.0;
|
|
57928
|
+
/**
|
|
57929
|
+
* `true` to enable Dolly-in to the mouse cursor coords.
|
|
57930
|
+
* @category Properties
|
|
57931
|
+
*/
|
|
57932
|
+
this.dollyToCursor = false;
|
|
57933
|
+
/**
|
|
57934
|
+
* @category Properties
|
|
57935
|
+
*/
|
|
57936
|
+
this.dragToOffset = false;
|
|
57937
|
+
/**
|
|
57938
|
+
* Friction ratio of the boundary.
|
|
57939
|
+
* @category Properties
|
|
57940
|
+
*/
|
|
57941
|
+
this.boundaryFriction = 0.0;
|
|
57942
|
+
/**
|
|
57943
|
+
* Controls how soon the `rest` event fires as the camera slows.
|
|
57944
|
+
* @category Properties
|
|
57945
|
+
*/
|
|
57946
|
+
this.restThreshold = 0.01;
|
|
57947
|
+
/**
|
|
57948
|
+
* An array of Meshes to collide with camera.
|
|
57949
|
+
* Be aware colliderMeshes may decrease performance. The collision test uses 4 raycasters from the camera since the near plane has 4 corners.
|
|
57950
|
+
* @category Properties
|
|
57951
|
+
*/
|
|
57952
|
+
this.colliderMeshes = [];
|
|
57953
|
+
/**
|
|
57954
|
+
* Force cancel user dragging.
|
|
57955
|
+
* @category Methods
|
|
57956
|
+
*/
|
|
57957
|
+
// cancel will be overwritten in the constructor.
|
|
57958
|
+
this.cancel = () => { };
|
|
57959
|
+
this._enabled = true;
|
|
57960
|
+
this._state = ACTION.NONE;
|
|
57961
|
+
this._viewport = null;
|
|
57962
|
+
this._changedDolly = 0;
|
|
57963
|
+
this._changedZoom = 0;
|
|
57964
|
+
this._hasRested = true;
|
|
57965
|
+
this._boundaryEnclosesCamera = false;
|
|
57966
|
+
this._needsUpdate = true;
|
|
57967
|
+
this._updatedLastTime = false;
|
|
57968
|
+
this._elementRect = new DOMRect();
|
|
57969
|
+
this._isDragging = false;
|
|
57970
|
+
this._dragNeedsUpdate = true;
|
|
57971
|
+
this._activePointers = [];
|
|
57972
|
+
this._lockedPointer = null;
|
|
57973
|
+
this._interactiveArea = new DOMRect(0, 0, 1, 1);
|
|
57974
|
+
// Use draggingSmoothTime over smoothTime while true.
|
|
57975
|
+
// set automatically true on user-dragging start.
|
|
57976
|
+
// set automatically false on programmable methods call.
|
|
57977
|
+
this._isUserControllingRotate = false;
|
|
57978
|
+
this._isUserControllingDolly = false;
|
|
57979
|
+
this._isUserControllingTruck = false;
|
|
57980
|
+
this._isUserControllingOffset = false;
|
|
57981
|
+
this._isUserControllingZoom = false;
|
|
57982
|
+
this._lastDollyDirection = DOLLY_DIRECTION.NONE;
|
|
57983
|
+
// velocities for smoothDamp
|
|
57984
|
+
this._thetaVelocity = { value: 0 };
|
|
57985
|
+
this._phiVelocity = { value: 0 };
|
|
57986
|
+
this._radiusVelocity = { value: 0 };
|
|
57987
|
+
this._targetVelocity = new THREE.Vector3();
|
|
57988
|
+
this._focalOffsetVelocity = new THREE.Vector3();
|
|
57989
|
+
this._zoomVelocity = { value: 0 };
|
|
57990
|
+
this._truckInternal = (deltaX, deltaY, dragToOffset, screenSpacePanning) => {
|
|
57991
|
+
let truckX;
|
|
57992
|
+
let pedestalY;
|
|
57993
|
+
if (isPerspectiveCamera(this._camera)) {
|
|
57994
|
+
const offset = _v3A.copy(this._camera.position).sub(this._target);
|
|
57995
|
+
// half of the fov is center to top of screen
|
|
57996
|
+
const fov = this._camera.getEffectiveFOV() * DEG2RAD;
|
|
57997
|
+
const targetDistance = offset.length() * Math.tan(fov * 0.5);
|
|
57998
|
+
truckX = (this.truckSpeed * deltaX * targetDistance / this._elementRect.height);
|
|
57999
|
+
pedestalY = (this.truckSpeed * deltaY * targetDistance / this._elementRect.height);
|
|
58000
|
+
}
|
|
58001
|
+
else if (isOrthographicCamera(this._camera)) {
|
|
58002
|
+
const camera = this._camera;
|
|
58003
|
+
truckX = this.truckSpeed * deltaX * (camera.right - camera.left) / camera.zoom / this._elementRect.width;
|
|
58004
|
+
pedestalY = this.truckSpeed * deltaY * (camera.top - camera.bottom) / camera.zoom / this._elementRect.height;
|
|
58005
|
+
}
|
|
58006
|
+
else {
|
|
58007
|
+
return;
|
|
58008
|
+
}
|
|
58009
|
+
if (screenSpacePanning) {
|
|
58010
|
+
dragToOffset ?
|
|
58011
|
+
this.setFocalOffset(this._focalOffsetEnd.x + truckX, this._focalOffsetEnd.y, this._focalOffsetEnd.z, true) :
|
|
58012
|
+
this.truck(truckX, 0, true);
|
|
58013
|
+
this.forward(-pedestalY, true);
|
|
58014
|
+
}
|
|
58015
|
+
else {
|
|
58016
|
+
dragToOffset ?
|
|
58017
|
+
this.setFocalOffset(this._focalOffsetEnd.x + truckX, this._focalOffsetEnd.y + pedestalY, this._focalOffsetEnd.z, true) :
|
|
58018
|
+
this.truck(truckX, pedestalY, true);
|
|
58019
|
+
}
|
|
58020
|
+
};
|
|
58021
|
+
this._rotateInternal = (deltaX, deltaY) => {
|
|
58022
|
+
const theta = PI_2 * this.azimuthRotateSpeed * deltaX / this._elementRect.height; // divide by *height* to refer the resolution
|
|
58023
|
+
const phi = PI_2 * this.polarRotateSpeed * deltaY / this._elementRect.height;
|
|
58024
|
+
this.rotate(theta, phi, true);
|
|
58025
|
+
};
|
|
58026
|
+
this._dollyInternal = (delta, x, y) => {
|
|
58027
|
+
const dollyScale = Math.pow(0.95, -delta * this.dollySpeed);
|
|
58028
|
+
const lastDistance = this._sphericalEnd.radius;
|
|
58029
|
+
const distance = this._sphericalEnd.radius * dollyScale;
|
|
58030
|
+
const clampedDistance = clamp(distance, this.minDistance, this.maxDistance);
|
|
58031
|
+
const overflowedDistance = clampedDistance - distance;
|
|
58032
|
+
if (this.infinityDolly && this.dollyToCursor) {
|
|
58033
|
+
this._dollyToNoClamp(distance, true);
|
|
58034
|
+
}
|
|
58035
|
+
else if (this.infinityDolly && !this.dollyToCursor) {
|
|
58036
|
+
this.dollyInFixed(overflowedDistance, true);
|
|
58037
|
+
this._dollyToNoClamp(clampedDistance, true);
|
|
58038
|
+
}
|
|
58039
|
+
else {
|
|
58040
|
+
this._dollyToNoClamp(clampedDistance, true);
|
|
58041
|
+
}
|
|
58042
|
+
if (this.dollyToCursor) {
|
|
58043
|
+
this._changedDolly += (this.infinityDolly ? distance : clampedDistance) - lastDistance;
|
|
58044
|
+
this._dollyControlCoord.set(x, y);
|
|
58045
|
+
}
|
|
58046
|
+
this._lastDollyDirection = Math.sign(-delta);
|
|
58047
|
+
};
|
|
58048
|
+
this._zoomInternal = (delta, x, y) => {
|
|
58049
|
+
const zoomScale = Math.pow(0.95, delta * this.dollySpeed);
|
|
58050
|
+
const lastZoom = this._zoom;
|
|
58051
|
+
const zoom = this._zoom * zoomScale;
|
|
58052
|
+
// for both PerspectiveCamera and OrthographicCamera
|
|
58053
|
+
this.zoomTo(zoom, true);
|
|
58054
|
+
if (this.dollyToCursor) {
|
|
58055
|
+
this._changedZoom += zoom - lastZoom;
|
|
58056
|
+
this._dollyControlCoord.set(x, y);
|
|
58057
|
+
}
|
|
58058
|
+
};
|
|
58059
|
+
// Check if the user has installed THREE
|
|
58060
|
+
if (typeof THREE === 'undefined') {
|
|
58061
|
+
console.error('camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information.');
|
|
58062
|
+
}
|
|
58063
|
+
this._camera = camera;
|
|
58064
|
+
this._yAxisUpSpace = new THREE.Quaternion().setFromUnitVectors(this._camera.up, _AXIS_Y);
|
|
58065
|
+
this._yAxisUpSpaceInverse = this._yAxisUpSpace.clone().invert();
|
|
58066
|
+
this._state = ACTION.NONE;
|
|
58067
|
+
// the location
|
|
58068
|
+
this._target = new THREE.Vector3();
|
|
58069
|
+
this._targetEnd = this._target.clone();
|
|
58070
|
+
this._focalOffset = new THREE.Vector3();
|
|
58071
|
+
this._focalOffsetEnd = this._focalOffset.clone();
|
|
58072
|
+
// rotation
|
|
58073
|
+
this._spherical = new THREE.Spherical().setFromVector3(_v3A.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace));
|
|
58074
|
+
this._sphericalEnd = this._spherical.clone();
|
|
58075
|
+
this._lastDistance = this._spherical.radius;
|
|
58076
|
+
this._zoom = this._camera.zoom;
|
|
58077
|
+
this._zoomEnd = this._zoom;
|
|
58078
|
+
this._lastZoom = this._zoom;
|
|
58079
|
+
// collisionTest uses nearPlane.s
|
|
58080
|
+
this._nearPlaneCorners = [
|
|
58081
|
+
new THREE.Vector3(),
|
|
58082
|
+
new THREE.Vector3(),
|
|
58083
|
+
new THREE.Vector3(),
|
|
58084
|
+
new THREE.Vector3(),
|
|
58085
|
+
];
|
|
58086
|
+
this._updateNearPlaneCorners();
|
|
58087
|
+
// Target cannot move outside of this box
|
|
58088
|
+
this._boundary = new THREE.Box3(new THREE.Vector3(-Infinity, -Infinity, -Infinity), new THREE.Vector3(Infinity, Infinity, Infinity));
|
|
58089
|
+
// reset
|
|
58090
|
+
this._cameraUp0 = this._camera.up.clone();
|
|
58091
|
+
this._target0 = this._target.clone();
|
|
58092
|
+
this._position0 = this._camera.position.clone();
|
|
58093
|
+
this._zoom0 = this._zoom;
|
|
58094
|
+
this._focalOffset0 = this._focalOffset.clone();
|
|
58095
|
+
this._dollyControlCoord = new THREE.Vector2();
|
|
58096
|
+
// configs
|
|
58097
|
+
this.mouseButtons = {
|
|
58098
|
+
left: ACTION.ROTATE,
|
|
58099
|
+
middle: ACTION.DOLLY,
|
|
58100
|
+
right: ACTION.TRUCK,
|
|
58101
|
+
wheel: isPerspectiveCamera(this._camera) ? ACTION.DOLLY :
|
|
58102
|
+
isOrthographicCamera(this._camera) ? ACTION.ZOOM :
|
|
58103
|
+
ACTION.NONE,
|
|
58104
|
+
};
|
|
58105
|
+
this.touches = {
|
|
58106
|
+
one: ACTION.TOUCH_ROTATE,
|
|
58107
|
+
two: isPerspectiveCamera(this._camera) ? ACTION.TOUCH_DOLLY_TRUCK :
|
|
58108
|
+
isOrthographicCamera(this._camera) ? ACTION.TOUCH_ZOOM_TRUCK :
|
|
58109
|
+
ACTION.NONE,
|
|
58110
|
+
three: ACTION.TOUCH_TRUCK,
|
|
58111
|
+
};
|
|
58112
|
+
const dragStartPosition = new THREE.Vector2();
|
|
58113
|
+
const lastDragPosition = new THREE.Vector2();
|
|
58114
|
+
const dollyStart = new THREE.Vector2();
|
|
58115
|
+
const onPointerDown = (event) => {
|
|
58116
|
+
if (!this._enabled || !this._domElement)
|
|
58117
|
+
return;
|
|
58118
|
+
if (this._interactiveArea.left !== 0 ||
|
|
58119
|
+
this._interactiveArea.top !== 0 ||
|
|
58120
|
+
this._interactiveArea.width !== 1 ||
|
|
58121
|
+
this._interactiveArea.height !== 1) {
|
|
58122
|
+
const elRect = this._domElement.getBoundingClientRect();
|
|
58123
|
+
const left = event.clientX / elRect.width;
|
|
58124
|
+
const top = event.clientY / elRect.height;
|
|
58125
|
+
// check if the interactiveArea contains the drag start position.
|
|
58126
|
+
if (left < this._interactiveArea.left ||
|
|
58127
|
+
left > this._interactiveArea.right ||
|
|
58128
|
+
top < this._interactiveArea.top ||
|
|
58129
|
+
top > this._interactiveArea.bottom)
|
|
58130
|
+
return;
|
|
58131
|
+
}
|
|
58132
|
+
// Don't call `event.preventDefault()` on the pointerdown event
|
|
58133
|
+
// to keep receiving pointermove evens outside dragging iframe
|
|
58134
|
+
// https://taye.me/blog/tips/2015/11/16/mouse-drag-outside-iframe/
|
|
58135
|
+
const mouseButton = event.pointerType !== 'mouse' ? null :
|
|
58136
|
+
(event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT ? MOUSE_BUTTON.LEFT :
|
|
58137
|
+
(event.buttons & MOUSE_BUTTON.MIDDLE) === MOUSE_BUTTON.MIDDLE ? MOUSE_BUTTON.MIDDLE :
|
|
58138
|
+
(event.buttons & MOUSE_BUTTON.RIGHT) === MOUSE_BUTTON.RIGHT ? MOUSE_BUTTON.RIGHT :
|
|
58139
|
+
null;
|
|
58140
|
+
if (mouseButton !== null) {
|
|
58141
|
+
const zombiePointer = this._findPointerByMouseButton(mouseButton);
|
|
58142
|
+
zombiePointer && this._disposePointer(zombiePointer);
|
|
58143
|
+
}
|
|
58144
|
+
if ((event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT && this._lockedPointer)
|
|
58145
|
+
return;
|
|
58146
|
+
const pointer = {
|
|
58147
|
+
pointerId: event.pointerId,
|
|
58148
|
+
clientX: event.clientX,
|
|
58149
|
+
clientY: event.clientY,
|
|
58150
|
+
deltaX: 0,
|
|
58151
|
+
deltaY: 0,
|
|
58152
|
+
mouseButton,
|
|
58153
|
+
};
|
|
58154
|
+
this._activePointers.push(pointer);
|
|
58155
|
+
// eslint-disable-next-line no-undef
|
|
58156
|
+
this._domElement.ownerDocument.removeEventListener('pointermove', onPointerMove, { passive: false });
|
|
58157
|
+
this._domElement.ownerDocument.removeEventListener('pointerup', onPointerUp);
|
|
58158
|
+
this._domElement.ownerDocument.addEventListener('pointermove', onPointerMove, { passive: false });
|
|
58159
|
+
this._domElement.ownerDocument.addEventListener('pointerup', onPointerUp);
|
|
58160
|
+
this._isDragging = true;
|
|
58161
|
+
startDragging(event);
|
|
58162
|
+
};
|
|
58163
|
+
const onPointerMove = (event) => {
|
|
58164
|
+
if (event.cancelable)
|
|
58165
|
+
event.preventDefault();
|
|
58166
|
+
const pointerId = event.pointerId;
|
|
58167
|
+
const pointer = this._lockedPointer || this._findPointerById(pointerId);
|
|
58168
|
+
if (!pointer)
|
|
58169
|
+
return;
|
|
58170
|
+
pointer.clientX = event.clientX;
|
|
58171
|
+
pointer.clientY = event.clientY;
|
|
58172
|
+
pointer.deltaX = event.movementX;
|
|
58173
|
+
pointer.deltaY = event.movementY;
|
|
58174
|
+
this._state = 0;
|
|
58175
|
+
if (event.pointerType === 'touch') {
|
|
58176
|
+
switch (this._activePointers.length) {
|
|
58177
|
+
case 1:
|
|
58178
|
+
this._state = this.touches.one;
|
|
58179
|
+
break;
|
|
58180
|
+
case 2:
|
|
58181
|
+
this._state = this.touches.two;
|
|
58182
|
+
break;
|
|
58183
|
+
case 3:
|
|
58184
|
+
this._state = this.touches.three;
|
|
58185
|
+
break;
|
|
58186
|
+
}
|
|
58187
|
+
}
|
|
58188
|
+
else {
|
|
58189
|
+
if ((!this._isDragging && this._lockedPointer) ||
|
|
58190
|
+
this._isDragging && (event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT) {
|
|
58191
|
+
this._state = this._state | this.mouseButtons.left;
|
|
58192
|
+
}
|
|
58193
|
+
if (this._isDragging && (event.buttons & MOUSE_BUTTON.MIDDLE) === MOUSE_BUTTON.MIDDLE) {
|
|
58194
|
+
this._state = this._state | this.mouseButtons.middle;
|
|
58195
|
+
}
|
|
58196
|
+
if (this._isDragging && (event.buttons & MOUSE_BUTTON.RIGHT) === MOUSE_BUTTON.RIGHT) {
|
|
58197
|
+
this._state = this._state | this.mouseButtons.right;
|
|
58198
|
+
}
|
|
58199
|
+
}
|
|
58200
|
+
dragging();
|
|
58201
|
+
};
|
|
58202
|
+
const onPointerUp = (event) => {
|
|
58203
|
+
const pointer = this._findPointerById(event.pointerId);
|
|
58204
|
+
if (pointer && pointer === this._lockedPointer)
|
|
58205
|
+
return;
|
|
58206
|
+
pointer && this._disposePointer(pointer);
|
|
58207
|
+
if (event.pointerType === 'touch') {
|
|
58208
|
+
switch (this._activePointers.length) {
|
|
58209
|
+
case 0:
|
|
58210
|
+
this._state = ACTION.NONE;
|
|
58211
|
+
break;
|
|
58212
|
+
case 1:
|
|
58213
|
+
this._state = this.touches.one;
|
|
58214
|
+
break;
|
|
58215
|
+
case 2:
|
|
58216
|
+
this._state = this.touches.two;
|
|
58217
|
+
break;
|
|
58218
|
+
case 3:
|
|
58219
|
+
this._state = this.touches.three;
|
|
58220
|
+
break;
|
|
58221
|
+
}
|
|
58222
|
+
}
|
|
58223
|
+
else {
|
|
58224
|
+
this._state = ACTION.NONE;
|
|
58225
|
+
}
|
|
58226
|
+
endDragging();
|
|
58227
|
+
};
|
|
58228
|
+
let lastScrollTimeStamp = -1;
|
|
58229
|
+
const onMouseWheel = (event) => {
|
|
58230
|
+
if (!this._domElement)
|
|
58231
|
+
return;
|
|
58232
|
+
if (!this._enabled || this.mouseButtons.wheel === ACTION.NONE)
|
|
58233
|
+
return;
|
|
58234
|
+
if (this._interactiveArea.left !== 0 ||
|
|
58235
|
+
this._interactiveArea.top !== 0 ||
|
|
58236
|
+
this._interactiveArea.width !== 1 ||
|
|
58237
|
+
this._interactiveArea.height !== 1) {
|
|
58238
|
+
const elRect = this._domElement.getBoundingClientRect();
|
|
58239
|
+
const left = event.clientX / elRect.width;
|
|
58240
|
+
const top = event.clientY / elRect.height;
|
|
58241
|
+
// check if the interactiveArea contains the drag start position.
|
|
58242
|
+
if (left < this._interactiveArea.left ||
|
|
58243
|
+
left > this._interactiveArea.right ||
|
|
58244
|
+
top < this._interactiveArea.top ||
|
|
58245
|
+
top > this._interactiveArea.bottom)
|
|
58246
|
+
return;
|
|
58247
|
+
}
|
|
58248
|
+
event.preventDefault();
|
|
58249
|
+
if (this.dollyToCursor ||
|
|
58250
|
+
this.mouseButtons.wheel === ACTION.ROTATE ||
|
|
58251
|
+
this.mouseButtons.wheel === ACTION.TRUCK) {
|
|
58252
|
+
const now = performance.now();
|
|
58253
|
+
// only need to fire this at scroll start.
|
|
58254
|
+
if (lastScrollTimeStamp - now < 1000)
|
|
58255
|
+
this._getClientRect(this._elementRect);
|
|
58256
|
+
lastScrollTimeStamp = now;
|
|
58257
|
+
}
|
|
58258
|
+
// Ref: https://github.com/cedricpinson/osgjs/blob/00e5a7e9d9206c06fdde0436e1d62ab7cb5ce853/sources/osgViewer/input/source/InputSourceMouse.js#L89-L103
|
|
58259
|
+
const deltaYFactor = isMac ? -1 : -3;
|
|
58260
|
+
const delta = (event.deltaMode === 1) ? event.deltaY / deltaYFactor : event.deltaY / (deltaYFactor * 10);
|
|
58261
|
+
const x = this.dollyToCursor ? (event.clientX - this._elementRect.x) / this._elementRect.width * 2 - 1 : 0;
|
|
58262
|
+
const y = this.dollyToCursor ? (event.clientY - this._elementRect.y) / this._elementRect.height * -2 + 1 : 0;
|
|
58263
|
+
switch (this.mouseButtons.wheel) {
|
|
58264
|
+
case ACTION.ROTATE: {
|
|
58265
|
+
this._rotateInternal(event.deltaX, event.deltaY);
|
|
58266
|
+
this._isUserControllingRotate = true;
|
|
58267
|
+
break;
|
|
58268
|
+
}
|
|
58269
|
+
case ACTION.TRUCK: {
|
|
58270
|
+
this._truckInternal(event.deltaX, event.deltaY, false, false);
|
|
58271
|
+
this._isUserControllingTruck = true;
|
|
58272
|
+
break;
|
|
58273
|
+
}
|
|
58274
|
+
case ACTION.SCREEN_PAN: {
|
|
58275
|
+
this._truckInternal(event.deltaX, event.deltaY, false, true);
|
|
58276
|
+
this._isUserControllingTruck = true;
|
|
58277
|
+
break;
|
|
58278
|
+
}
|
|
58279
|
+
case ACTION.OFFSET: {
|
|
58280
|
+
this._truckInternal(event.deltaX, event.deltaY, true, false);
|
|
58281
|
+
this._isUserControllingOffset = true;
|
|
58282
|
+
break;
|
|
58283
|
+
}
|
|
58284
|
+
case ACTION.DOLLY: {
|
|
58285
|
+
this._dollyInternal(-delta, x, y);
|
|
58286
|
+
this._isUserControllingDolly = true;
|
|
58287
|
+
break;
|
|
58288
|
+
}
|
|
58289
|
+
case ACTION.ZOOM: {
|
|
58290
|
+
this._zoomInternal(-delta, x, y);
|
|
58291
|
+
this._isUserControllingZoom = true;
|
|
58292
|
+
break;
|
|
58293
|
+
}
|
|
58294
|
+
}
|
|
58295
|
+
this.dispatchEvent({ type: 'control' });
|
|
58296
|
+
};
|
|
58297
|
+
const onContextMenu = (event) => {
|
|
58298
|
+
if (!this._domElement || !this._enabled)
|
|
58299
|
+
return;
|
|
58300
|
+
// contextmenu event is fired right after pointerdown
|
|
58301
|
+
// remove attached handlers and active pointer, if interrupted by contextmenu.
|
|
58302
|
+
if (this.mouseButtons.right === CameraControls.ACTION.NONE) {
|
|
58303
|
+
const pointerId = event instanceof PointerEvent ? event.pointerId : 0;
|
|
58304
|
+
const pointer = this._findPointerById(pointerId);
|
|
58305
|
+
pointer && this._disposePointer(pointer);
|
|
58306
|
+
// eslint-disable-next-line no-undef
|
|
58307
|
+
this._domElement.ownerDocument.removeEventListener('pointermove', onPointerMove, { passive: false });
|
|
58308
|
+
this._domElement.ownerDocument.removeEventListener('pointerup', onPointerUp);
|
|
58309
|
+
return;
|
|
58310
|
+
}
|
|
58311
|
+
event.preventDefault();
|
|
58312
|
+
};
|
|
58313
|
+
const startDragging = (event) => {
|
|
58314
|
+
if (!this._enabled)
|
|
58315
|
+
return;
|
|
58316
|
+
extractClientCoordFromEvent(this._activePointers, _v2);
|
|
58317
|
+
this._getClientRect(this._elementRect);
|
|
58318
|
+
dragStartPosition.copy(_v2);
|
|
58319
|
+
lastDragPosition.copy(_v2);
|
|
58320
|
+
const isMultiTouch = this._activePointers.length >= 2;
|
|
58321
|
+
if (isMultiTouch) {
|
|
58322
|
+
// 2 finger pinch
|
|
58323
|
+
const dx = _v2.x - this._activePointers[1].clientX;
|
|
58324
|
+
const dy = _v2.y - this._activePointers[1].clientY;
|
|
58325
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
58326
|
+
dollyStart.set(0, distance);
|
|
58327
|
+
// center coords of 2 finger truck
|
|
58328
|
+
const x = (this._activePointers[0].clientX + this._activePointers[1].clientX) * 0.5;
|
|
58329
|
+
const y = (this._activePointers[0].clientY + this._activePointers[1].clientY) * 0.5;
|
|
58330
|
+
lastDragPosition.set(x, y);
|
|
58331
|
+
}
|
|
58332
|
+
this._state = 0;
|
|
58333
|
+
if (!event) {
|
|
58334
|
+
if (this._lockedPointer)
|
|
58335
|
+
this._state = this._state | this.mouseButtons.left;
|
|
58336
|
+
}
|
|
58337
|
+
else if ('pointerType' in event && event.pointerType === 'touch') {
|
|
58338
|
+
switch (this._activePointers.length) {
|
|
58339
|
+
case 1:
|
|
58340
|
+
this._state = this.touches.one;
|
|
58341
|
+
break;
|
|
58342
|
+
case 2:
|
|
58343
|
+
this._state = this.touches.two;
|
|
58344
|
+
break;
|
|
58345
|
+
case 3:
|
|
58346
|
+
this._state = this.touches.three;
|
|
58347
|
+
break;
|
|
58348
|
+
}
|
|
58349
|
+
}
|
|
58350
|
+
else {
|
|
58351
|
+
if (!this._lockedPointer && (event.buttons & MOUSE_BUTTON.LEFT) === MOUSE_BUTTON.LEFT) {
|
|
58352
|
+
this._state = this._state | this.mouseButtons.left;
|
|
58353
|
+
}
|
|
58354
|
+
if ((event.buttons & MOUSE_BUTTON.MIDDLE) === MOUSE_BUTTON.MIDDLE) {
|
|
58355
|
+
this._state = this._state | this.mouseButtons.middle;
|
|
58356
|
+
}
|
|
58357
|
+
if ((event.buttons & MOUSE_BUTTON.RIGHT) === MOUSE_BUTTON.RIGHT) {
|
|
58358
|
+
this._state = this._state | this.mouseButtons.right;
|
|
58359
|
+
}
|
|
58360
|
+
}
|
|
58361
|
+
// stop current movement on drag start
|
|
58362
|
+
// - rotate
|
|
58363
|
+
if ((this._state & ACTION.ROTATE) === ACTION.ROTATE ||
|
|
58364
|
+
(this._state & ACTION.TOUCH_ROTATE) === ACTION.TOUCH_ROTATE ||
|
|
58365
|
+
(this._state & ACTION.TOUCH_DOLLY_ROTATE) === ACTION.TOUCH_DOLLY_ROTATE ||
|
|
58366
|
+
(this._state & ACTION.TOUCH_ZOOM_ROTATE) === ACTION.TOUCH_ZOOM_ROTATE) {
|
|
58367
|
+
this._sphericalEnd.theta = this._spherical.theta;
|
|
58368
|
+
this._sphericalEnd.phi = this._spherical.phi;
|
|
58369
|
+
this._thetaVelocity.value = 0;
|
|
58370
|
+
this._phiVelocity.value = 0;
|
|
58371
|
+
}
|
|
58372
|
+
// - truck and screen-pan
|
|
58373
|
+
if ((this._state & ACTION.TRUCK) === ACTION.TRUCK ||
|
|
58374
|
+
(this._state & ACTION.SCREEN_PAN) === ACTION.SCREEN_PAN ||
|
|
58375
|
+
(this._state & ACTION.TOUCH_TRUCK) === ACTION.TOUCH_TRUCK ||
|
|
58376
|
+
(this._state & ACTION.TOUCH_SCREEN_PAN) === ACTION.TOUCH_SCREEN_PAN ||
|
|
58377
|
+
(this._state & ACTION.TOUCH_DOLLY_TRUCK) === ACTION.TOUCH_DOLLY_TRUCK ||
|
|
58378
|
+
(this._state & ACTION.TOUCH_DOLLY_SCREEN_PAN) === ACTION.TOUCH_DOLLY_SCREEN_PAN ||
|
|
58379
|
+
(this._state & ACTION.TOUCH_ZOOM_TRUCK) === ACTION.TOUCH_ZOOM_TRUCK ||
|
|
58380
|
+
(this._state & ACTION.TOUCH_ZOOM_SCREEN_PAN) === ACTION.TOUCH_DOLLY_SCREEN_PAN) {
|
|
58381
|
+
this._targetEnd.copy(this._target);
|
|
58382
|
+
this._targetVelocity.set(0, 0, 0);
|
|
58383
|
+
}
|
|
58384
|
+
// - dolly
|
|
58385
|
+
if ((this._state & ACTION.DOLLY) === ACTION.DOLLY ||
|
|
58386
|
+
(this._state & ACTION.TOUCH_DOLLY) === ACTION.TOUCH_DOLLY ||
|
|
58387
|
+
(this._state & ACTION.TOUCH_DOLLY_TRUCK) === ACTION.TOUCH_DOLLY_TRUCK ||
|
|
58388
|
+
(this._state & ACTION.TOUCH_DOLLY_SCREEN_PAN) === ACTION.TOUCH_DOLLY_SCREEN_PAN ||
|
|
58389
|
+
(this._state & ACTION.TOUCH_DOLLY_OFFSET) === ACTION.TOUCH_DOLLY_OFFSET ||
|
|
58390
|
+
(this._state & ACTION.TOUCH_DOLLY_ROTATE) === ACTION.TOUCH_DOLLY_ROTATE) {
|
|
58391
|
+
this._sphericalEnd.radius = this._spherical.radius;
|
|
58392
|
+
this._radiusVelocity.value = 0;
|
|
58393
|
+
}
|
|
58394
|
+
// - zoom
|
|
58395
|
+
if ((this._state & ACTION.ZOOM) === ACTION.ZOOM ||
|
|
58396
|
+
(this._state & ACTION.TOUCH_ZOOM) === ACTION.TOUCH_ZOOM ||
|
|
58397
|
+
(this._state & ACTION.TOUCH_ZOOM_TRUCK) === ACTION.TOUCH_ZOOM_TRUCK ||
|
|
58398
|
+
(this._state & ACTION.TOUCH_ZOOM_SCREEN_PAN) === ACTION.TOUCH_ZOOM_SCREEN_PAN ||
|
|
58399
|
+
(this._state & ACTION.TOUCH_ZOOM_OFFSET) === ACTION.TOUCH_ZOOM_OFFSET ||
|
|
58400
|
+
(this._state & ACTION.TOUCH_ZOOM_ROTATE) === ACTION.TOUCH_ZOOM_ROTATE) {
|
|
58401
|
+
this._zoomEnd = this._zoom;
|
|
58402
|
+
this._zoomVelocity.value = 0;
|
|
58403
|
+
}
|
|
58404
|
+
// - offset
|
|
58405
|
+
if ((this._state & ACTION.OFFSET) === ACTION.OFFSET ||
|
|
58406
|
+
(this._state & ACTION.TOUCH_OFFSET) === ACTION.TOUCH_OFFSET ||
|
|
58407
|
+
(this._state & ACTION.TOUCH_DOLLY_OFFSET) === ACTION.TOUCH_DOLLY_OFFSET ||
|
|
58408
|
+
(this._state & ACTION.TOUCH_ZOOM_OFFSET) === ACTION.TOUCH_ZOOM_OFFSET) {
|
|
58409
|
+
this._focalOffsetEnd.copy(this._focalOffset);
|
|
58410
|
+
this._focalOffsetVelocity.set(0, 0, 0);
|
|
58411
|
+
}
|
|
58412
|
+
this.dispatchEvent({ type: 'controlstart' });
|
|
58413
|
+
};
|
|
58414
|
+
const dragging = () => {
|
|
58415
|
+
if (!this._enabled || !this._dragNeedsUpdate)
|
|
58416
|
+
return;
|
|
58417
|
+
this._dragNeedsUpdate = false;
|
|
58418
|
+
extractClientCoordFromEvent(this._activePointers, _v2);
|
|
58419
|
+
// When pointer lock is enabled clientX, clientY, screenX, and screenY remain 0.
|
|
58420
|
+
// If pointer lock is enabled, use the Delta directory, and assume active-pointer is not multiple.
|
|
58421
|
+
const isPointerLockActive = this._domElement && this._domElement.ownerDocument.pointerLockElement === this._domElement;
|
|
58422
|
+
const lockedPointer = isPointerLockActive ? this._lockedPointer || this._activePointers[0] : null;
|
|
58423
|
+
const deltaX = lockedPointer ? -lockedPointer.deltaX : lastDragPosition.x - _v2.x;
|
|
58424
|
+
const deltaY = lockedPointer ? -lockedPointer.deltaY : lastDragPosition.y - _v2.y;
|
|
58425
|
+
lastDragPosition.copy(_v2);
|
|
58426
|
+
// rotate
|
|
58427
|
+
if ((this._state & ACTION.ROTATE) === ACTION.ROTATE ||
|
|
58428
|
+
(this._state & ACTION.TOUCH_ROTATE) === ACTION.TOUCH_ROTATE ||
|
|
58429
|
+
(this._state & ACTION.TOUCH_DOLLY_ROTATE) === ACTION.TOUCH_DOLLY_ROTATE ||
|
|
58430
|
+
(this._state & ACTION.TOUCH_ZOOM_ROTATE) === ACTION.TOUCH_ZOOM_ROTATE) {
|
|
58431
|
+
this._rotateInternal(deltaX, deltaY);
|
|
58432
|
+
this._isUserControllingRotate = true;
|
|
58433
|
+
}
|
|
58434
|
+
// mouse dolly or zoom
|
|
58435
|
+
if ((this._state & ACTION.DOLLY) === ACTION.DOLLY ||
|
|
58436
|
+
(this._state & ACTION.ZOOM) === ACTION.ZOOM) {
|
|
58437
|
+
const dollyX = this.dollyToCursor ? (dragStartPosition.x - this._elementRect.x) / this._elementRect.width * 2 - 1 : 0;
|
|
58438
|
+
const dollyY = this.dollyToCursor ? (dragStartPosition.y - this._elementRect.y) / this._elementRect.height * -2 + 1 : 0;
|
|
58439
|
+
const dollyDirection = this.dollyDragInverted ? -1 : 1;
|
|
58440
|
+
if ((this._state & ACTION.DOLLY) === ACTION.DOLLY) {
|
|
58441
|
+
this._dollyInternal(dollyDirection * deltaY * TOUCH_DOLLY_FACTOR, dollyX, dollyY);
|
|
58442
|
+
this._isUserControllingDolly = true;
|
|
58443
|
+
}
|
|
58444
|
+
else {
|
|
58445
|
+
this._zoomInternal(dollyDirection * deltaY * TOUCH_DOLLY_FACTOR, dollyX, dollyY);
|
|
58446
|
+
this._isUserControllingZoom = true;
|
|
58447
|
+
}
|
|
58448
|
+
}
|
|
58449
|
+
// touch dolly or zoom
|
|
58450
|
+
if ((this._state & ACTION.TOUCH_DOLLY) === ACTION.TOUCH_DOLLY ||
|
|
58451
|
+
(this._state & ACTION.TOUCH_ZOOM) === ACTION.TOUCH_ZOOM ||
|
|
58452
|
+
(this._state & ACTION.TOUCH_DOLLY_TRUCK) === ACTION.TOUCH_DOLLY_TRUCK ||
|
|
58453
|
+
(this._state & ACTION.TOUCH_ZOOM_TRUCK) === ACTION.TOUCH_ZOOM_TRUCK ||
|
|
58454
|
+
(this._state & ACTION.TOUCH_DOLLY_SCREEN_PAN) === ACTION.TOUCH_DOLLY_SCREEN_PAN ||
|
|
58455
|
+
(this._state & ACTION.TOUCH_ZOOM_SCREEN_PAN) === ACTION.TOUCH_ZOOM_SCREEN_PAN ||
|
|
58456
|
+
(this._state & ACTION.TOUCH_DOLLY_OFFSET) === ACTION.TOUCH_DOLLY_OFFSET ||
|
|
58457
|
+
(this._state & ACTION.TOUCH_ZOOM_OFFSET) === ACTION.TOUCH_ZOOM_OFFSET ||
|
|
58458
|
+
(this._state & ACTION.TOUCH_DOLLY_ROTATE) === ACTION.TOUCH_DOLLY_ROTATE ||
|
|
58459
|
+
(this._state & ACTION.TOUCH_ZOOM_ROTATE) === ACTION.TOUCH_ZOOM_ROTATE) {
|
|
58460
|
+
const dx = _v2.x - this._activePointers[1].clientX;
|
|
58461
|
+
const dy = _v2.y - this._activePointers[1].clientY;
|
|
58462
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
58463
|
+
const dollyDelta = dollyStart.y - distance;
|
|
58464
|
+
dollyStart.set(0, distance);
|
|
58465
|
+
const dollyX = this.dollyToCursor ? (lastDragPosition.x - this._elementRect.x) / this._elementRect.width * 2 - 1 : 0;
|
|
58466
|
+
const dollyY = this.dollyToCursor ? (lastDragPosition.y - this._elementRect.y) / this._elementRect.height * -2 + 1 : 0;
|
|
58467
|
+
if ((this._state & ACTION.TOUCH_DOLLY) === ACTION.TOUCH_DOLLY ||
|
|
58468
|
+
(this._state & ACTION.TOUCH_DOLLY_ROTATE) === ACTION.TOUCH_DOLLY_ROTATE ||
|
|
58469
|
+
(this._state & ACTION.TOUCH_DOLLY_TRUCK) === ACTION.TOUCH_DOLLY_TRUCK ||
|
|
58470
|
+
(this._state & ACTION.TOUCH_DOLLY_SCREEN_PAN) === ACTION.TOUCH_DOLLY_SCREEN_PAN ||
|
|
58471
|
+
(this._state & ACTION.TOUCH_DOLLY_OFFSET) === ACTION.TOUCH_DOLLY_OFFSET) {
|
|
58472
|
+
this._dollyInternal(dollyDelta * TOUCH_DOLLY_FACTOR, dollyX, dollyY);
|
|
58473
|
+
this._isUserControllingDolly = true;
|
|
58474
|
+
}
|
|
58475
|
+
else {
|
|
58476
|
+
this._zoomInternal(dollyDelta * TOUCH_DOLLY_FACTOR, dollyX, dollyY);
|
|
58477
|
+
this._isUserControllingZoom = true;
|
|
58478
|
+
}
|
|
58479
|
+
}
|
|
58480
|
+
// truck
|
|
58481
|
+
if ((this._state & ACTION.TRUCK) === ACTION.TRUCK ||
|
|
58482
|
+
(this._state & ACTION.TOUCH_TRUCK) === ACTION.TOUCH_TRUCK ||
|
|
58483
|
+
(this._state & ACTION.TOUCH_DOLLY_TRUCK) === ACTION.TOUCH_DOLLY_TRUCK ||
|
|
58484
|
+
(this._state & ACTION.TOUCH_ZOOM_TRUCK) === ACTION.TOUCH_ZOOM_TRUCK) {
|
|
58485
|
+
this._truckInternal(deltaX, deltaY, false, false);
|
|
58486
|
+
this._isUserControllingTruck = true;
|
|
58487
|
+
}
|
|
58488
|
+
// screen-pan
|
|
58489
|
+
if ((this._state & ACTION.SCREEN_PAN) === ACTION.SCREEN_PAN ||
|
|
58490
|
+
(this._state & ACTION.TOUCH_SCREEN_PAN) === ACTION.TOUCH_SCREEN_PAN ||
|
|
58491
|
+
(this._state & ACTION.TOUCH_DOLLY_SCREEN_PAN) === ACTION.TOUCH_DOLLY_SCREEN_PAN ||
|
|
58492
|
+
(this._state & ACTION.TOUCH_ZOOM_SCREEN_PAN) === ACTION.TOUCH_ZOOM_SCREEN_PAN) {
|
|
58493
|
+
this._truckInternal(deltaX, deltaY, false, true);
|
|
58494
|
+
this._isUserControllingTruck = true;
|
|
58495
|
+
}
|
|
58496
|
+
// offset
|
|
58497
|
+
if ((this._state & ACTION.OFFSET) === ACTION.OFFSET ||
|
|
58498
|
+
(this._state & ACTION.TOUCH_OFFSET) === ACTION.TOUCH_OFFSET ||
|
|
58499
|
+
(this._state & ACTION.TOUCH_DOLLY_OFFSET) === ACTION.TOUCH_DOLLY_OFFSET ||
|
|
58500
|
+
(this._state & ACTION.TOUCH_ZOOM_OFFSET) === ACTION.TOUCH_ZOOM_OFFSET) {
|
|
58501
|
+
this._truckInternal(deltaX, deltaY, true, false);
|
|
58502
|
+
this._isUserControllingOffset = true;
|
|
58503
|
+
}
|
|
58504
|
+
this.dispatchEvent({ type: 'control' });
|
|
58505
|
+
};
|
|
58506
|
+
const endDragging = () => {
|
|
58507
|
+
extractClientCoordFromEvent(this._activePointers, _v2);
|
|
58508
|
+
lastDragPosition.copy(_v2);
|
|
58509
|
+
this._dragNeedsUpdate = false;
|
|
58510
|
+
if (this._activePointers.length === 0 ||
|
|
58511
|
+
(this._activePointers.length === 1 && this._activePointers[0] === this._lockedPointer)) {
|
|
58512
|
+
this._isDragging = false;
|
|
58513
|
+
}
|
|
58514
|
+
if (this._activePointers.length === 0 && this._domElement) {
|
|
58515
|
+
// eslint-disable-next-line no-undef
|
|
58516
|
+
this._domElement.ownerDocument.removeEventListener('pointermove', onPointerMove, { passive: false });
|
|
58517
|
+
this._domElement.ownerDocument.removeEventListener('pointerup', onPointerUp);
|
|
58518
|
+
this.dispatchEvent({ type: 'controlend' });
|
|
58519
|
+
}
|
|
58520
|
+
};
|
|
58521
|
+
this.lockPointer = () => {
|
|
58522
|
+
if (!this._enabled || !this._domElement)
|
|
58523
|
+
return;
|
|
58524
|
+
this.cancel();
|
|
58525
|
+
// Element.requestPointerLock is allowed to happen without any pointer active - create a faux one for compatibility with controls
|
|
58526
|
+
this._lockedPointer = {
|
|
58527
|
+
pointerId: -1,
|
|
58528
|
+
clientX: 0,
|
|
58529
|
+
clientY: 0,
|
|
58530
|
+
deltaX: 0,
|
|
58531
|
+
deltaY: 0,
|
|
58532
|
+
mouseButton: null,
|
|
58533
|
+
};
|
|
58534
|
+
this._activePointers.push(this._lockedPointer);
|
|
58535
|
+
// eslint-disable-next-line no-undef
|
|
58536
|
+
this._domElement.ownerDocument.removeEventListener('pointermove', onPointerMove, { passive: false });
|
|
58537
|
+
this._domElement.ownerDocument.removeEventListener('pointerup', onPointerUp);
|
|
58538
|
+
this._domElement.requestPointerLock();
|
|
58539
|
+
this._domElement.ownerDocument.addEventListener('pointerlockchange', onPointerLockChange);
|
|
58540
|
+
this._domElement.ownerDocument.addEventListener('pointerlockerror', onPointerLockError);
|
|
58541
|
+
this._domElement.ownerDocument.addEventListener('pointermove', onPointerMove, { passive: false });
|
|
58542
|
+
this._domElement.ownerDocument.addEventListener('pointerup', onPointerUp);
|
|
58543
|
+
startDragging();
|
|
58544
|
+
};
|
|
58545
|
+
this.unlockPointer = () => {
|
|
58546
|
+
var _a, _b, _c;
|
|
58547
|
+
if (this._lockedPointer !== null) {
|
|
58548
|
+
this._disposePointer(this._lockedPointer);
|
|
58549
|
+
this._lockedPointer = null;
|
|
58550
|
+
}
|
|
58551
|
+
(_a = this._domElement) === null || _a === void 0 ? void 0 : _a.ownerDocument.exitPointerLock();
|
|
58552
|
+
(_b = this._domElement) === null || _b === void 0 ? void 0 : _b.ownerDocument.removeEventListener('pointerlockchange', onPointerLockChange);
|
|
58553
|
+
(_c = this._domElement) === null || _c === void 0 ? void 0 : _c.ownerDocument.removeEventListener('pointerlockerror', onPointerLockError);
|
|
58554
|
+
this.cancel();
|
|
58555
|
+
};
|
|
58556
|
+
const onPointerLockChange = () => {
|
|
58557
|
+
const isPointerLockActive = this._domElement && this._domElement.ownerDocument.pointerLockElement === this._domElement;
|
|
58558
|
+
if (!isPointerLockActive)
|
|
58559
|
+
this.unlockPointer();
|
|
58560
|
+
};
|
|
58561
|
+
const onPointerLockError = () => {
|
|
58562
|
+
this.unlockPointer();
|
|
58563
|
+
};
|
|
58564
|
+
this._addAllEventListeners = (domElement) => {
|
|
58565
|
+
this._domElement = domElement;
|
|
58566
|
+
this._domElement.style.touchAction = 'none';
|
|
58567
|
+
this._domElement.style.userSelect = 'none';
|
|
58568
|
+
this._domElement.style.webkitUserSelect = 'none';
|
|
58569
|
+
this._domElement.addEventListener('pointerdown', onPointerDown);
|
|
58570
|
+
this._domElement.addEventListener('pointercancel', onPointerUp);
|
|
58571
|
+
this._domElement.addEventListener('wheel', onMouseWheel, { passive: false });
|
|
58572
|
+
this._domElement.addEventListener('contextmenu', onContextMenu);
|
|
58573
|
+
};
|
|
58574
|
+
this._removeAllEventListeners = () => {
|
|
58575
|
+
if (!this._domElement)
|
|
58576
|
+
return;
|
|
58577
|
+
this._domElement.style.touchAction = '';
|
|
58578
|
+
this._domElement.style.userSelect = '';
|
|
58579
|
+
this._domElement.style.webkitUserSelect = '';
|
|
58580
|
+
this._domElement.removeEventListener('pointerdown', onPointerDown);
|
|
58581
|
+
this._domElement.removeEventListener('pointercancel', onPointerUp);
|
|
58582
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener#matching_event_listeners_for_removal
|
|
58583
|
+
// > it's probably wise to use the same values used for the call to `addEventListener()` when calling `removeEventListener()`
|
|
58584
|
+
// see https://github.com/microsoft/TypeScript/issues/32912#issuecomment-522142969
|
|
58585
|
+
// eslint-disable-next-line no-undef
|
|
58586
|
+
this._domElement.removeEventListener('wheel', onMouseWheel, { passive: false });
|
|
58587
|
+
this._domElement.removeEventListener('contextmenu', onContextMenu);
|
|
58588
|
+
// eslint-disable-next-line no-undef
|
|
58589
|
+
this._domElement.ownerDocument.removeEventListener('pointermove', onPointerMove, { passive: false });
|
|
58590
|
+
this._domElement.ownerDocument.removeEventListener('pointerup', onPointerUp);
|
|
58591
|
+
this._domElement.ownerDocument.removeEventListener('pointerlockchange', onPointerLockChange);
|
|
58592
|
+
this._domElement.ownerDocument.removeEventListener('pointerlockerror', onPointerLockError);
|
|
58593
|
+
};
|
|
58594
|
+
this.cancel = () => {
|
|
58595
|
+
if (this._state === ACTION.NONE)
|
|
58596
|
+
return;
|
|
58597
|
+
this._state = ACTION.NONE;
|
|
58598
|
+
this._activePointers.length = 0;
|
|
58599
|
+
endDragging();
|
|
58600
|
+
};
|
|
58601
|
+
if (domElement)
|
|
58602
|
+
this.connect(domElement);
|
|
58603
|
+
this.update(0);
|
|
58604
|
+
}
|
|
58605
|
+
/**
|
|
58606
|
+
* The camera to be controlled
|
|
58607
|
+
* @category Properties
|
|
58608
|
+
*/
|
|
58609
|
+
get camera() {
|
|
58610
|
+
return this._camera;
|
|
58611
|
+
}
|
|
58612
|
+
set camera(camera) {
|
|
58613
|
+
this._camera = camera;
|
|
58614
|
+
this.updateCameraUp();
|
|
58615
|
+
this._camera.updateProjectionMatrix();
|
|
58616
|
+
this._updateNearPlaneCorners();
|
|
58617
|
+
this._needsUpdate = true;
|
|
58618
|
+
}
|
|
58619
|
+
/**
|
|
58620
|
+
* Whether or not the controls are enabled.
|
|
58621
|
+
* `false` to disable user dragging/touch-move, but all methods works.
|
|
58622
|
+
* @category Properties
|
|
58623
|
+
*/
|
|
58624
|
+
get enabled() {
|
|
58625
|
+
return this._enabled;
|
|
58626
|
+
}
|
|
58627
|
+
set enabled(enabled) {
|
|
58628
|
+
this._enabled = enabled;
|
|
58629
|
+
if (!this._domElement)
|
|
58630
|
+
return;
|
|
58631
|
+
if (enabled) {
|
|
58632
|
+
this._domElement.style.touchAction = 'none';
|
|
58633
|
+
this._domElement.style.userSelect = 'none';
|
|
58634
|
+
this._domElement.style.webkitUserSelect = 'none';
|
|
58635
|
+
}
|
|
58636
|
+
else {
|
|
58637
|
+
this.cancel();
|
|
58638
|
+
this._domElement.style.touchAction = '';
|
|
58639
|
+
this._domElement.style.userSelect = '';
|
|
58640
|
+
this._domElement.style.webkitUserSelect = '';
|
|
58641
|
+
}
|
|
58642
|
+
}
|
|
58643
|
+
/**
|
|
58644
|
+
* Returns `true` if the controls are active updating.
|
|
58645
|
+
* readonly value.
|
|
58646
|
+
* @category Properties
|
|
58647
|
+
*/
|
|
58648
|
+
get active() {
|
|
58649
|
+
return !this._hasRested;
|
|
58650
|
+
}
|
|
58651
|
+
/**
|
|
58652
|
+
* Getter for the current `ACTION`.
|
|
58653
|
+
* readonly value.
|
|
58654
|
+
* @category Properties
|
|
58655
|
+
*/
|
|
58656
|
+
get currentAction() {
|
|
58657
|
+
return this._state;
|
|
58658
|
+
}
|
|
58659
|
+
/**
|
|
58660
|
+
* get/set Current distance.
|
|
58661
|
+
* @category Properties
|
|
58662
|
+
*/
|
|
58663
|
+
get distance() {
|
|
58664
|
+
return this._spherical.radius;
|
|
58665
|
+
}
|
|
58666
|
+
set distance(distance) {
|
|
58667
|
+
if (this._spherical.radius === distance &&
|
|
58668
|
+
this._sphericalEnd.radius === distance)
|
|
58669
|
+
return;
|
|
58670
|
+
this._spherical.radius = distance;
|
|
58671
|
+
this._sphericalEnd.radius = distance;
|
|
58672
|
+
this._needsUpdate = true;
|
|
58673
|
+
}
|
|
58674
|
+
// horizontal angle
|
|
58675
|
+
/**
|
|
58676
|
+
* get/set the azimuth angle (horizontal) in radians.
|
|
58677
|
+
* Every 360 degrees turn is added to `.azimuthAngle` value, which is accumulative.
|
|
58678
|
+
* @category Properties
|
|
58679
|
+
*/
|
|
58680
|
+
get azimuthAngle() {
|
|
58681
|
+
return this._spherical.theta;
|
|
58682
|
+
}
|
|
58683
|
+
set azimuthAngle(azimuthAngle) {
|
|
58684
|
+
if (this._spherical.theta === azimuthAngle &&
|
|
58685
|
+
this._sphericalEnd.theta === azimuthAngle)
|
|
58686
|
+
return;
|
|
58687
|
+
this._spherical.theta = azimuthAngle;
|
|
58688
|
+
this._sphericalEnd.theta = azimuthAngle;
|
|
58689
|
+
this._needsUpdate = true;
|
|
58690
|
+
}
|
|
58691
|
+
// vertical angle
|
|
58692
|
+
/**
|
|
58693
|
+
* get/set the polar angle (vertical) in radians.
|
|
58694
|
+
* @category Properties
|
|
58695
|
+
*/
|
|
58696
|
+
get polarAngle() {
|
|
58697
|
+
return this._spherical.phi;
|
|
58698
|
+
}
|
|
58699
|
+
set polarAngle(polarAngle) {
|
|
58700
|
+
if (this._spherical.phi === polarAngle &&
|
|
58701
|
+
this._sphericalEnd.phi === polarAngle)
|
|
58702
|
+
return;
|
|
58703
|
+
this._spherical.phi = polarAngle;
|
|
58704
|
+
this._sphericalEnd.phi = polarAngle;
|
|
58705
|
+
this._needsUpdate = true;
|
|
58706
|
+
}
|
|
58707
|
+
/**
|
|
58708
|
+
* Whether camera position should be enclosed in the boundary or not.
|
|
58709
|
+
* @category Properties
|
|
58710
|
+
*/
|
|
58711
|
+
get boundaryEnclosesCamera() {
|
|
58712
|
+
return this._boundaryEnclosesCamera;
|
|
58713
|
+
}
|
|
58714
|
+
set boundaryEnclosesCamera(boundaryEnclosesCamera) {
|
|
58715
|
+
this._boundaryEnclosesCamera = boundaryEnclosesCamera;
|
|
58716
|
+
this._needsUpdate = true;
|
|
58717
|
+
}
|
|
58718
|
+
/**
|
|
58719
|
+
* Set drag-start, touches and wheel enable area in the domElement.
|
|
58720
|
+
* each values are between `0` and `1` inclusive, where `0` is left/top and `1` is right/bottom of the screen.
|
|
58721
|
+
* e.g. `{ x: 0, y: 0, width: 1, height: 1 }` for entire area.
|
|
58722
|
+
* @category Properties
|
|
58723
|
+
*/
|
|
58724
|
+
set interactiveArea(interactiveArea) {
|
|
58725
|
+
this._interactiveArea.width = clamp(interactiveArea.width, 0, 1);
|
|
58726
|
+
this._interactiveArea.height = clamp(interactiveArea.height, 0, 1);
|
|
58727
|
+
this._interactiveArea.x = clamp(interactiveArea.x, 0, 1 - this._interactiveArea.width);
|
|
58728
|
+
this._interactiveArea.y = clamp(interactiveArea.y, 0, 1 - this._interactiveArea.height);
|
|
58729
|
+
}
|
|
58730
|
+
/**
|
|
58731
|
+
* Adds the specified event listener.
|
|
58732
|
+
* Applicable event types (which is `K`) are:
|
|
58733
|
+
* | Event name | Timing |
|
|
58734
|
+
* | ------------------- | ------ |
|
|
58735
|
+
* | `'controlstart'` | When the user starts to control the camera via mouse / touches. ¹ |
|
|
58736
|
+
* | `'control'` | When the user controls the camera (dragging). |
|
|
58737
|
+
* | `'controlend'` | When the user ends to control the camera. ¹ |
|
|
58738
|
+
* | `'transitionstart'` | When any kind of transition starts, either user control or using a method with `enableTransition = true` |
|
|
58739
|
+
* | `'update'` | When the camera position is updated. |
|
|
58740
|
+
* | `'wake'` | When the camera starts moving. |
|
|
58741
|
+
* | `'rest'` | When the camera movement is below `.restThreshold` ². |
|
|
58742
|
+
* | `'sleep'` | When the camera end moving. |
|
|
58743
|
+
*
|
|
58744
|
+
* 1. `mouseButtons.wheel` (Mouse wheel control) does not emit `'controlstart'` and `'controlend'`. `mouseButtons.wheel` uses scroll-event internally, and scroll-event happens intermittently. That means "start" and "end" cannot be detected.
|
|
58745
|
+
* 2. Due to damping, `sleep` will usually fire a few seconds after the camera _appears_ to have stopped moving. If you want to do something (e.g. enable UI, perform another transition) at the point when the camera has stopped, you probably want the `rest` event. This can be fine tuned using the `.restThreshold` parameter. See the [Rest and Sleep Example](https://yomotsu.github.io/camera-controls/examples/rest-and-sleep.html).
|
|
58746
|
+
*
|
|
58747
|
+
* e.g.
|
|
58748
|
+
* ```
|
|
58749
|
+
* cameraControl.addEventListener( 'controlstart', myCallbackFunction );
|
|
58750
|
+
* ```
|
|
58751
|
+
* @param type event name
|
|
58752
|
+
* @param listener handler function
|
|
58753
|
+
* @category Methods
|
|
58754
|
+
*/
|
|
58755
|
+
addEventListener(type, listener) {
|
|
58756
|
+
super.addEventListener(type, listener);
|
|
58757
|
+
}
|
|
58758
|
+
/**
|
|
58759
|
+
* Removes the specified event listener
|
|
58760
|
+
* e.g.
|
|
58761
|
+
* ```
|
|
58762
|
+
* cameraControl.addEventListener( 'controlstart', myCallbackFunction );
|
|
58763
|
+
* ```
|
|
58764
|
+
* @param type event name
|
|
58765
|
+
* @param listener handler function
|
|
58766
|
+
* @category Methods
|
|
58767
|
+
*/
|
|
58768
|
+
removeEventListener(type, listener) {
|
|
58769
|
+
super.removeEventListener(type, listener);
|
|
58770
|
+
}
|
|
58771
|
+
/**
|
|
58772
|
+
* Rotate azimuthal angle(horizontal) and polar angle(vertical).
|
|
58773
|
+
* Every value is added to the current value.
|
|
58774
|
+
* @param azimuthAngle Azimuth rotate angle. In radian.
|
|
58775
|
+
* @param polarAngle Polar rotate angle. In radian.
|
|
58776
|
+
* @param enableTransition Whether to move smoothly or immediately
|
|
58777
|
+
* @category Methods
|
|
58778
|
+
*/
|
|
58779
|
+
rotate(azimuthAngle, polarAngle, enableTransition = false) {
|
|
58780
|
+
return this.rotateTo(this._sphericalEnd.theta + azimuthAngle, this._sphericalEnd.phi + polarAngle, enableTransition);
|
|
58781
|
+
}
|
|
58782
|
+
/**
|
|
58783
|
+
* Rotate azimuthal angle(horizontal) to the given angle and keep the same polar angle(vertical) target.
|
|
58784
|
+
*
|
|
58785
|
+
* e.g.
|
|
58786
|
+
* ```
|
|
58787
|
+
* cameraControls.rotateAzimuthTo( 30 * THREE.MathUtils.DEG2RAD, true );
|
|
58788
|
+
* ```
|
|
58789
|
+
* @param azimuthAngle Azimuth rotate angle. In radian.
|
|
58790
|
+
* @param enableTransition Whether to move smoothly or immediately
|
|
58791
|
+
* @category Methods
|
|
58792
|
+
*/
|
|
58793
|
+
rotateAzimuthTo(azimuthAngle, enableTransition = false) {
|
|
58794
|
+
return this.rotateTo(azimuthAngle, this._sphericalEnd.phi, enableTransition);
|
|
58795
|
+
}
|
|
58796
|
+
/**
|
|
58797
|
+
* Rotate polar angle(vertical) to the given angle and keep the same azimuthal angle(horizontal) target.
|
|
58798
|
+
*
|
|
58799
|
+
* e.g.
|
|
58800
|
+
* ```
|
|
58801
|
+
* cameraControls.rotatePolarTo( 30 * THREE.MathUtils.DEG2RAD, true );
|
|
58802
|
+
* ```
|
|
58803
|
+
* @param polarAngle Polar rotate angle. In radian.
|
|
58804
|
+
* @param enableTransition Whether to move smoothly or immediately
|
|
58805
|
+
* @category Methods
|
|
58806
|
+
*/
|
|
58807
|
+
rotatePolarTo(polarAngle, enableTransition = false) {
|
|
58808
|
+
return this.rotateTo(this._sphericalEnd.theta, polarAngle, enableTransition);
|
|
58809
|
+
}
|
|
58810
|
+
/**
|
|
58811
|
+
* Rotate azimuthal angle(horizontal) and polar angle(vertical) to the given angle.
|
|
58812
|
+
* Camera view will rotate over the orbit pivot absolutely:
|
|
58813
|
+
*
|
|
58814
|
+
* azimuthAngle
|
|
58815
|
+
* ```
|
|
58816
|
+
* 0º
|
|
58817
|
+
* \
|
|
58818
|
+
* 90º -----+----- -90º
|
|
58819
|
+
* \
|
|
58820
|
+
* 180º
|
|
58821
|
+
* ```
|
|
58822
|
+
* | direction | angle |
|
|
58823
|
+
* | --------- | ---------------------- |
|
|
58824
|
+
* | front | 0º |
|
|
58825
|
+
* | left | 90º (`Math.PI / 2`) |
|
|
58826
|
+
* | right | -90º (`- Math.PI / 2`) |
|
|
58827
|
+
* | back | 180º (`Math.PI`) |
|
|
58828
|
+
*
|
|
58829
|
+
* polarAngle
|
|
58830
|
+
* ```
|
|
58831
|
+
* 180º
|
|
58832
|
+
* |
|
|
58833
|
+
* 90º
|
|
58834
|
+
* |
|
|
58835
|
+
* 0º
|
|
58836
|
+
* ```
|
|
58837
|
+
* | direction | angle |
|
|
58838
|
+
* | -------------------- | ---------------------- |
|
|
58839
|
+
* | top/sky | 180º (`Math.PI`) |
|
|
58840
|
+
* | horizontal from view | 90º (`Math.PI / 2`) |
|
|
58841
|
+
* | bottom/floor | 0º |
|
|
58842
|
+
*
|
|
58843
|
+
* @param azimuthAngle Azimuth rotate angle to. In radian.
|
|
58844
|
+
* @param polarAngle Polar rotate angle to. In radian.
|
|
58845
|
+
* @param enableTransition Whether to move smoothly or immediately
|
|
58846
|
+
* @category Methods
|
|
58847
|
+
*/
|
|
58848
|
+
rotateTo(azimuthAngle, polarAngle, enableTransition = false) {
|
|
58849
|
+
this._isUserControllingRotate = false;
|
|
58850
|
+
const theta = clamp(azimuthAngle, this.minAzimuthAngle, this.maxAzimuthAngle);
|
|
58851
|
+
const phi = clamp(polarAngle, this.minPolarAngle, this.maxPolarAngle);
|
|
58852
|
+
this._sphericalEnd.theta = theta;
|
|
58853
|
+
this._sphericalEnd.phi = phi;
|
|
58854
|
+
this._sphericalEnd.makeSafe();
|
|
58855
|
+
this._needsUpdate = true;
|
|
58856
|
+
if (!enableTransition) {
|
|
58857
|
+
this._spherical.theta = this._sphericalEnd.theta;
|
|
58858
|
+
this._spherical.phi = this._sphericalEnd.phi;
|
|
58859
|
+
}
|
|
58860
|
+
const resolveImmediately = !enableTransition ||
|
|
58861
|
+
approxEquals(this._spherical.theta, this._sphericalEnd.theta, this.restThreshold) &&
|
|
58862
|
+
approxEquals(this._spherical.phi, this._sphericalEnd.phi, this.restThreshold);
|
|
58863
|
+
return this._createOnRestPromise(resolveImmediately);
|
|
58864
|
+
}
|
|
58865
|
+
/**
|
|
58866
|
+
* Dolly in/out camera position.
|
|
58867
|
+
* @param distance Distance of dollyIn. Negative number for dollyOut.
|
|
58868
|
+
* @param enableTransition Whether to move smoothly or immediately.
|
|
58869
|
+
* @category Methods
|
|
58870
|
+
*/
|
|
58871
|
+
dolly(distance, enableTransition = false) {
|
|
58872
|
+
return this.dollyTo(this._sphericalEnd.radius - distance, enableTransition);
|
|
58873
|
+
}
|
|
58874
|
+
/**
|
|
58875
|
+
* Dolly in/out camera position to given distance.
|
|
58876
|
+
* @param distance Distance of dolly.
|
|
58877
|
+
* @param enableTransition Whether to move smoothly or immediately.
|
|
58878
|
+
* @category Methods
|
|
58879
|
+
*/
|
|
58880
|
+
dollyTo(distance, enableTransition = false) {
|
|
58881
|
+
this._isUserControllingDolly = false;
|
|
58882
|
+
this._lastDollyDirection = DOLLY_DIRECTION.NONE;
|
|
58883
|
+
this._changedDolly = 0;
|
|
58884
|
+
return this._dollyToNoClamp(clamp(distance, this.minDistance, this.maxDistance), enableTransition);
|
|
58885
|
+
}
|
|
58886
|
+
_dollyToNoClamp(distance, enableTransition = false) {
|
|
58887
|
+
const lastRadius = this._sphericalEnd.radius;
|
|
58888
|
+
const hasCollider = this.colliderMeshes.length >= 1;
|
|
58889
|
+
if (hasCollider) {
|
|
58890
|
+
const maxDistanceByCollisionTest = this._collisionTest();
|
|
58891
|
+
const isCollided = approxEquals(maxDistanceByCollisionTest, this._spherical.radius);
|
|
58892
|
+
const isDollyIn = lastRadius > distance;
|
|
58893
|
+
if (!isDollyIn && isCollided)
|
|
58894
|
+
return Promise.resolve();
|
|
58895
|
+
this._sphericalEnd.radius = Math.min(distance, maxDistanceByCollisionTest);
|
|
58896
|
+
}
|
|
58897
|
+
else {
|
|
58898
|
+
this._sphericalEnd.radius = distance;
|
|
58899
|
+
}
|
|
58900
|
+
this._needsUpdate = true;
|
|
58901
|
+
if (!enableTransition) {
|
|
58902
|
+
this._spherical.radius = this._sphericalEnd.radius;
|
|
58903
|
+
}
|
|
58904
|
+
const resolveImmediately = !enableTransition || approxEquals(this._spherical.radius, this._sphericalEnd.radius, this.restThreshold);
|
|
58905
|
+
return this._createOnRestPromise(resolveImmediately);
|
|
58906
|
+
}
|
|
58907
|
+
/**
|
|
58908
|
+
* Dolly in, but does not change the distance between the target and the camera, and moves the target position instead.
|
|
58909
|
+
* Specify a negative value for dolly out.
|
|
58910
|
+
* @param distance Distance of dolly.
|
|
58911
|
+
* @param enableTransition Whether to move smoothly or immediately.
|
|
58912
|
+
* @category Methods
|
|
58913
|
+
*/
|
|
58914
|
+
dollyInFixed(distance, enableTransition = false) {
|
|
58915
|
+
this._targetEnd.add(this._getCameraDirection(_cameraDirection).multiplyScalar(distance));
|
|
58916
|
+
if (!enableTransition) {
|
|
58917
|
+
this._target.copy(this._targetEnd);
|
|
58918
|
+
}
|
|
58919
|
+
const resolveImmediately = !enableTransition ||
|
|
58920
|
+
approxEquals(this._target.x, this._targetEnd.x, this.restThreshold) &&
|
|
58921
|
+
approxEquals(this._target.y, this._targetEnd.y, this.restThreshold) &&
|
|
58922
|
+
approxEquals(this._target.z, this._targetEnd.z, this.restThreshold);
|
|
58923
|
+
return this._createOnRestPromise(resolveImmediately);
|
|
58924
|
+
}
|
|
58925
|
+
/**
|
|
58926
|
+
* Zoom in/out camera. The value is added to camera zoom.
|
|
58927
|
+
* Limits set with `.minZoom` and `.maxZoom`
|
|
58928
|
+
* @param zoomStep zoom scale
|
|
58929
|
+
* @param enableTransition Whether to move smoothly or immediately
|
|
58930
|
+
* @category Methods
|
|
58931
|
+
*/
|
|
58932
|
+
zoom(zoomStep, enableTransition = false) {
|
|
58933
|
+
return this.zoomTo(this._zoomEnd + zoomStep, enableTransition);
|
|
58934
|
+
}
|
|
58935
|
+
/**
|
|
58936
|
+
* Zoom in/out camera to given scale. The value overwrites camera zoom.
|
|
58937
|
+
* Limits set with .minZoom and .maxZoom
|
|
58938
|
+
* @param zoom
|
|
58939
|
+
* @param enableTransition
|
|
58940
|
+
* @category Methods
|
|
58941
|
+
*/
|
|
58942
|
+
zoomTo(zoom, enableTransition = false) {
|
|
58943
|
+
this._isUserControllingZoom = false;
|
|
58944
|
+
this._zoomEnd = clamp(zoom, this.minZoom, this.maxZoom);
|
|
58945
|
+
this._needsUpdate = true;
|
|
58946
|
+
if (!enableTransition) {
|
|
58947
|
+
this._zoom = this._zoomEnd;
|
|
58948
|
+
}
|
|
58949
|
+
const resolveImmediately = !enableTransition || approxEquals(this._zoom, this._zoomEnd, this.restThreshold);
|
|
58950
|
+
this._changedZoom = 0;
|
|
58951
|
+
return this._createOnRestPromise(resolveImmediately);
|
|
58952
|
+
}
|
|
58953
|
+
/**
|
|
58954
|
+
* @deprecated `pan()` has been renamed to `truck()`
|
|
58955
|
+
* @category Methods
|
|
58956
|
+
*/
|
|
58957
|
+
pan(x, y, enableTransition = false) {
|
|
58958
|
+
console.warn('`pan` has been renamed to `truck`');
|
|
58959
|
+
return this.truck(x, y, enableTransition);
|
|
58960
|
+
}
|
|
58961
|
+
/**
|
|
58962
|
+
* Truck and pedestal camera using current azimuthal angle
|
|
58963
|
+
* @param x Horizontal translate amount
|
|
58964
|
+
* @param y Vertical translate amount
|
|
58965
|
+
* @param enableTransition Whether to move smoothly or immediately
|
|
58966
|
+
* @category Methods
|
|
58967
|
+
*/
|
|
58968
|
+
truck(x, y, enableTransition = false) {
|
|
58969
|
+
this._camera.updateMatrix();
|
|
58970
|
+
_xColumn.setFromMatrixColumn(this._camera.matrix, 0);
|
|
58971
|
+
_yColumn.setFromMatrixColumn(this._camera.matrix, 1);
|
|
58972
|
+
_xColumn.multiplyScalar(x);
|
|
58973
|
+
_yColumn.multiplyScalar(-y);
|
|
58974
|
+
const offset = _v3A.copy(_xColumn).add(_yColumn);
|
|
58975
|
+
const to = _v3B.copy(this._targetEnd).add(offset);
|
|
58976
|
+
return this.moveTo(to.x, to.y, to.z, enableTransition);
|
|
58977
|
+
}
|
|
58978
|
+
/**
|
|
58979
|
+
* Move forward / backward.
|
|
58980
|
+
* @param distance Amount to move forward / backward. Negative value to move backward
|
|
58981
|
+
* @param enableTransition Whether to move smoothly or immediately
|
|
58982
|
+
* @category Methods
|
|
58983
|
+
*/
|
|
58984
|
+
forward(distance, enableTransition = false) {
|
|
58985
|
+
_v3A.setFromMatrixColumn(this._camera.matrix, 0);
|
|
58986
|
+
_v3A.crossVectors(this._camera.up, _v3A);
|
|
58987
|
+
_v3A.multiplyScalar(distance);
|
|
58988
|
+
const to = _v3B.copy(this._targetEnd).add(_v3A);
|
|
58989
|
+
return this.moveTo(to.x, to.y, to.z, enableTransition);
|
|
58990
|
+
}
|
|
58991
|
+
/**
|
|
58992
|
+
* Move up / down.
|
|
58993
|
+
* @param height Amount to move up / down. Negative value to move down
|
|
58994
|
+
* @param enableTransition Whether to move smoothly or immediately
|
|
58995
|
+
* @category Methods
|
|
58996
|
+
*/
|
|
58997
|
+
elevate(height, enableTransition = false) {
|
|
58998
|
+
_v3A.copy(this._camera.up).multiplyScalar(height);
|
|
58999
|
+
return this.moveTo(this._targetEnd.x + _v3A.x, this._targetEnd.y + _v3A.y, this._targetEnd.z + _v3A.z, enableTransition);
|
|
59000
|
+
}
|
|
59001
|
+
/**
|
|
59002
|
+
* Move target position to given point.
|
|
59003
|
+
* @param x x coord to move center position
|
|
59004
|
+
* @param y y coord to move center position
|
|
59005
|
+
* @param z z coord to move center position
|
|
59006
|
+
* @param enableTransition Whether to move smoothly or immediately
|
|
59007
|
+
* @category Methods
|
|
59008
|
+
*/
|
|
59009
|
+
moveTo(x, y, z, enableTransition = false) {
|
|
59010
|
+
this._isUserControllingTruck = false;
|
|
59011
|
+
const offset = _v3A.set(x, y, z).sub(this._targetEnd);
|
|
59012
|
+
this._encloseToBoundary(this._targetEnd, offset, this.boundaryFriction);
|
|
59013
|
+
this._needsUpdate = true;
|
|
59014
|
+
if (!enableTransition) {
|
|
59015
|
+
this._target.copy(this._targetEnd);
|
|
59016
|
+
}
|
|
59017
|
+
const resolveImmediately = !enableTransition ||
|
|
59018
|
+
approxEquals(this._target.x, this._targetEnd.x, this.restThreshold) &&
|
|
59019
|
+
approxEquals(this._target.y, this._targetEnd.y, this.restThreshold) &&
|
|
59020
|
+
approxEquals(this._target.z, this._targetEnd.z, this.restThreshold);
|
|
59021
|
+
return this._createOnRestPromise(resolveImmediately);
|
|
59022
|
+
}
|
|
59023
|
+
/**
|
|
59024
|
+
* Look in the given point direction.
|
|
59025
|
+
* @param x point x.
|
|
59026
|
+
* @param y point y.
|
|
59027
|
+
* @param z point z.
|
|
59028
|
+
* @param enableTransition Whether to move smoothly or immediately.
|
|
59029
|
+
* @returns Transition end promise
|
|
59030
|
+
* @category Methods
|
|
59031
|
+
*/
|
|
59032
|
+
lookInDirectionOf(x, y, z, enableTransition = false) {
|
|
59033
|
+
const point = _v3A.set(x, y, z);
|
|
59034
|
+
const direction = point.sub(this._targetEnd).normalize();
|
|
59035
|
+
const position = direction.multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);
|
|
59036
|
+
return this.setPosition(position.x, position.y, position.z, enableTransition);
|
|
59037
|
+
}
|
|
59038
|
+
/**
|
|
59039
|
+
* Fit the viewport to the box or the bounding box of the object, using the nearest axis. paddings are in unit.
|
|
59040
|
+
* set `cover: true` to fill enter screen.
|
|
59041
|
+
* e.g.
|
|
59042
|
+
* ```
|
|
59043
|
+
* cameraControls.fitToBox( myMesh );
|
|
59044
|
+
* ```
|
|
59045
|
+
* @param box3OrObject Axis aligned bounding box to fit the view.
|
|
59046
|
+
* @param enableTransition Whether to move smoothly or immediately.
|
|
59047
|
+
* @param options | `<object>` { cover: boolean, paddingTop: number, paddingLeft: number, paddingBottom: number, paddingRight: number }
|
|
59048
|
+
* @returns Transition end promise
|
|
59049
|
+
* @category Methods
|
|
59050
|
+
*/
|
|
59051
|
+
fitToBox(box3OrObject, enableTransition, { cover = false, paddingLeft = 0, paddingRight = 0, paddingBottom = 0, paddingTop = 0 } = {}) {
|
|
59052
|
+
const promises = [];
|
|
59053
|
+
const aabb = box3OrObject.isBox3
|
|
59054
|
+
? _box3A.copy(box3OrObject)
|
|
59055
|
+
: _box3A.setFromObject(box3OrObject);
|
|
59056
|
+
if (aabb.isEmpty()) {
|
|
59057
|
+
console.warn('camera-controls: fitTo() cannot be used with an empty box. Aborting');
|
|
59058
|
+
Promise.resolve();
|
|
59059
|
+
}
|
|
59060
|
+
// round to closest axis ( forward | backward | right | left | top | bottom )
|
|
59061
|
+
const theta = roundToStep(this._sphericalEnd.theta, PI_HALF);
|
|
59062
|
+
const phi = roundToStep(this._sphericalEnd.phi, PI_HALF);
|
|
59063
|
+
promises.push(this.rotateTo(theta, phi, enableTransition));
|
|
59064
|
+
const normal = _v3A.setFromSpherical(this._sphericalEnd).normalize();
|
|
59065
|
+
const rotation = _quaternionA.setFromUnitVectors(normal, _AXIS_Z);
|
|
59066
|
+
const viewFromPolar = approxEquals(Math.abs(normal.y), 1);
|
|
59067
|
+
if (viewFromPolar) {
|
|
59068
|
+
rotation.multiply(_quaternionB.setFromAxisAngle(_AXIS_Y, theta));
|
|
59069
|
+
}
|
|
59070
|
+
rotation.multiply(this._yAxisUpSpaceInverse);
|
|
59071
|
+
// make oriented bounding box
|
|
59072
|
+
const bb = _box3B.makeEmpty();
|
|
59073
|
+
// left bottom back corner
|
|
59074
|
+
_v3B.copy(aabb.min).applyQuaternion(rotation);
|
|
59075
|
+
bb.expandByPoint(_v3B);
|
|
59076
|
+
// right bottom back corner
|
|
59077
|
+
_v3B.copy(aabb.min).setX(aabb.max.x).applyQuaternion(rotation);
|
|
59078
|
+
bb.expandByPoint(_v3B);
|
|
59079
|
+
// left top back corner
|
|
59080
|
+
_v3B.copy(aabb.min).setY(aabb.max.y).applyQuaternion(rotation);
|
|
59081
|
+
bb.expandByPoint(_v3B);
|
|
59082
|
+
// right top back corner
|
|
59083
|
+
_v3B.copy(aabb.max).setZ(aabb.min.z).applyQuaternion(rotation);
|
|
59084
|
+
bb.expandByPoint(_v3B);
|
|
59085
|
+
// left bottom front corner
|
|
59086
|
+
_v3B.copy(aabb.min).setZ(aabb.max.z).applyQuaternion(rotation);
|
|
59087
|
+
bb.expandByPoint(_v3B);
|
|
59088
|
+
// right bottom front corner
|
|
59089
|
+
_v3B.copy(aabb.max).setY(aabb.min.y).applyQuaternion(rotation);
|
|
59090
|
+
bb.expandByPoint(_v3B);
|
|
59091
|
+
// left top front corner
|
|
59092
|
+
_v3B.copy(aabb.max).setX(aabb.min.x).applyQuaternion(rotation);
|
|
59093
|
+
bb.expandByPoint(_v3B);
|
|
59094
|
+
// right top front corner
|
|
59095
|
+
_v3B.copy(aabb.max).applyQuaternion(rotation);
|
|
59096
|
+
bb.expandByPoint(_v3B);
|
|
59097
|
+
// add padding
|
|
59098
|
+
bb.min.x -= paddingLeft;
|
|
59099
|
+
bb.min.y -= paddingBottom;
|
|
59100
|
+
bb.max.x += paddingRight;
|
|
59101
|
+
bb.max.y += paddingTop;
|
|
59102
|
+
rotation.setFromUnitVectors(_AXIS_Z, normal);
|
|
59103
|
+
if (viewFromPolar) {
|
|
59104
|
+
rotation.premultiply(_quaternionB.invert());
|
|
59105
|
+
}
|
|
59106
|
+
rotation.premultiply(this._yAxisUpSpace);
|
|
59107
|
+
const bbSize = bb.getSize(_v3A);
|
|
59108
|
+
const center = bb.getCenter(_v3B).applyQuaternion(rotation);
|
|
59109
|
+
if (isPerspectiveCamera(this._camera)) {
|
|
59110
|
+
const distance = this.getDistanceToFitBox(bbSize.x, bbSize.y, bbSize.z, cover);
|
|
59111
|
+
promises.push(this.moveTo(center.x, center.y, center.z, enableTransition));
|
|
59112
|
+
promises.push(this.dollyTo(distance, enableTransition));
|
|
59113
|
+
promises.push(this.setFocalOffset(0, 0, 0, enableTransition));
|
|
59114
|
+
}
|
|
59115
|
+
else if (isOrthographicCamera(this._camera)) {
|
|
59116
|
+
const camera = this._camera;
|
|
59117
|
+
const width = camera.right - camera.left;
|
|
59118
|
+
const height = camera.top - camera.bottom;
|
|
59119
|
+
const zoom = cover ? Math.max(width / bbSize.x, height / bbSize.y) : Math.min(width / bbSize.x, height / bbSize.y);
|
|
59120
|
+
promises.push(this.moveTo(center.x, center.y, center.z, enableTransition));
|
|
59121
|
+
promises.push(this.zoomTo(zoom, enableTransition));
|
|
59122
|
+
promises.push(this.setFocalOffset(0, 0, 0, enableTransition));
|
|
59123
|
+
}
|
|
59124
|
+
return Promise.all(promises);
|
|
59125
|
+
}
|
|
59126
|
+
/**
|
|
59127
|
+
* Fit the viewport to the sphere or the bounding sphere of the object.
|
|
59128
|
+
* @param sphereOrMesh
|
|
59129
|
+
* @param enableTransition
|
|
59130
|
+
* @category Methods
|
|
59131
|
+
*/
|
|
59132
|
+
fitToSphere(sphereOrMesh, enableTransition) {
|
|
59133
|
+
const promises = [];
|
|
59134
|
+
const isObject3D = 'isObject3D' in sphereOrMesh;
|
|
59135
|
+
const boundingSphere = isObject3D ?
|
|
59136
|
+
CameraControls.createBoundingSphere(sphereOrMesh, _sphere) :
|
|
59137
|
+
_sphere.copy(sphereOrMesh);
|
|
59138
|
+
promises.push(this.moveTo(boundingSphere.center.x, boundingSphere.center.y, boundingSphere.center.z, enableTransition));
|
|
59139
|
+
if (isPerspectiveCamera(this._camera)) {
|
|
59140
|
+
const distanceToFit = this.getDistanceToFitSphere(boundingSphere.radius);
|
|
59141
|
+
promises.push(this.dollyTo(distanceToFit, enableTransition));
|
|
59142
|
+
}
|
|
59143
|
+
else if (isOrthographicCamera(this._camera)) {
|
|
59144
|
+
const width = this._camera.right - this._camera.left;
|
|
59145
|
+
const height = this._camera.top - this._camera.bottom;
|
|
59146
|
+
const diameter = 2 * boundingSphere.radius;
|
|
59147
|
+
const zoom = Math.min(width / diameter, height / diameter);
|
|
59148
|
+
promises.push(this.zoomTo(zoom, enableTransition));
|
|
59149
|
+
}
|
|
59150
|
+
promises.push(this.setFocalOffset(0, 0, 0, enableTransition));
|
|
59151
|
+
return Promise.all(promises);
|
|
59152
|
+
}
|
|
59153
|
+
/**
|
|
59154
|
+
* Look at the `target` from the `position`.
|
|
59155
|
+
* @param positionX
|
|
59156
|
+
* @param positionY
|
|
59157
|
+
* @param positionZ
|
|
59158
|
+
* @param targetX
|
|
59159
|
+
* @param targetY
|
|
59160
|
+
* @param targetZ
|
|
59161
|
+
* @param enableTransition
|
|
59162
|
+
* @category Methods
|
|
59163
|
+
*/
|
|
59164
|
+
setLookAt(positionX, positionY, positionZ, targetX, targetY, targetZ, enableTransition = false) {
|
|
59165
|
+
this._isUserControllingRotate = false;
|
|
59166
|
+
this._isUserControllingDolly = false;
|
|
59167
|
+
this._isUserControllingTruck = false;
|
|
59168
|
+
this._lastDollyDirection = DOLLY_DIRECTION.NONE;
|
|
59169
|
+
this._changedDolly = 0;
|
|
59170
|
+
const target = _v3B.set(targetX, targetY, targetZ);
|
|
59171
|
+
const position = _v3A.set(positionX, positionY, positionZ);
|
|
59172
|
+
this._targetEnd.copy(target);
|
|
59173
|
+
this._sphericalEnd.setFromVector3(position.sub(target).applyQuaternion(this._yAxisUpSpace));
|
|
59174
|
+
this.normalizeRotations();
|
|
59175
|
+
this._needsUpdate = true;
|
|
59176
|
+
if (!enableTransition) {
|
|
59177
|
+
this._target.copy(this._targetEnd);
|
|
59178
|
+
this._spherical.copy(this._sphericalEnd);
|
|
59179
|
+
}
|
|
59180
|
+
const resolveImmediately = !enableTransition ||
|
|
59181
|
+
approxEquals(this._target.x, this._targetEnd.x, this.restThreshold) &&
|
|
59182
|
+
approxEquals(this._target.y, this._targetEnd.y, this.restThreshold) &&
|
|
59183
|
+
approxEquals(this._target.z, this._targetEnd.z, this.restThreshold) &&
|
|
59184
|
+
approxEquals(this._spherical.theta, this._sphericalEnd.theta, this.restThreshold) &&
|
|
59185
|
+
approxEquals(this._spherical.phi, this._sphericalEnd.phi, this.restThreshold) &&
|
|
59186
|
+
approxEquals(this._spherical.radius, this._sphericalEnd.radius, this.restThreshold);
|
|
59187
|
+
return this._createOnRestPromise(resolveImmediately);
|
|
59188
|
+
}
|
|
59189
|
+
/**
|
|
59190
|
+
* Similar to setLookAt, but it interpolates between two states.
|
|
59191
|
+
* @param positionAX
|
|
59192
|
+
* @param positionAY
|
|
59193
|
+
* @param positionAZ
|
|
59194
|
+
* @param targetAX
|
|
59195
|
+
* @param targetAY
|
|
59196
|
+
* @param targetAZ
|
|
59197
|
+
* @param positionBX
|
|
59198
|
+
* @param positionBY
|
|
59199
|
+
* @param positionBZ
|
|
59200
|
+
* @param targetBX
|
|
59201
|
+
* @param targetBY
|
|
59202
|
+
* @param targetBZ
|
|
59203
|
+
* @param t
|
|
59204
|
+
* @param enableTransition
|
|
59205
|
+
* @category Methods
|
|
59206
|
+
*/
|
|
59207
|
+
lerpLookAt(positionAX, positionAY, positionAZ, targetAX, targetAY, targetAZ, positionBX, positionBY, positionBZ, targetBX, targetBY, targetBZ, t, enableTransition = false) {
|
|
59208
|
+
this._isUserControllingRotate = false;
|
|
59209
|
+
this._isUserControllingDolly = false;
|
|
59210
|
+
this._isUserControllingTruck = false;
|
|
59211
|
+
this._lastDollyDirection = DOLLY_DIRECTION.NONE;
|
|
59212
|
+
this._changedDolly = 0;
|
|
59213
|
+
const targetA = _v3A.set(targetAX, targetAY, targetAZ);
|
|
59214
|
+
const positionA = _v3B.set(positionAX, positionAY, positionAZ);
|
|
59215
|
+
_sphericalA.setFromVector3(positionA.sub(targetA).applyQuaternion(this._yAxisUpSpace));
|
|
59216
|
+
const targetB = _v3C.set(targetBX, targetBY, targetBZ);
|
|
59217
|
+
const positionB = _v3B.set(positionBX, positionBY, positionBZ);
|
|
59218
|
+
_sphericalB.setFromVector3(positionB.sub(targetB).applyQuaternion(this._yAxisUpSpace));
|
|
59219
|
+
this._targetEnd.copy(targetA.lerp(targetB, t)); // tricky
|
|
59220
|
+
const deltaTheta = _sphericalB.theta - _sphericalA.theta;
|
|
59221
|
+
const deltaPhi = _sphericalB.phi - _sphericalA.phi;
|
|
59222
|
+
const deltaRadius = _sphericalB.radius - _sphericalA.radius;
|
|
59223
|
+
this._sphericalEnd.set(_sphericalA.radius + deltaRadius * t, _sphericalA.phi + deltaPhi * t, _sphericalA.theta + deltaTheta * t);
|
|
59224
|
+
this.normalizeRotations();
|
|
59225
|
+
this._needsUpdate = true;
|
|
59226
|
+
if (!enableTransition) {
|
|
59227
|
+
this._target.copy(this._targetEnd);
|
|
59228
|
+
this._spherical.copy(this._sphericalEnd);
|
|
59229
|
+
}
|
|
59230
|
+
const resolveImmediately = !enableTransition ||
|
|
59231
|
+
approxEquals(this._target.x, this._targetEnd.x, this.restThreshold) &&
|
|
59232
|
+
approxEquals(this._target.y, this._targetEnd.y, this.restThreshold) &&
|
|
59233
|
+
approxEquals(this._target.z, this._targetEnd.z, this.restThreshold) &&
|
|
59234
|
+
approxEquals(this._spherical.theta, this._sphericalEnd.theta, this.restThreshold) &&
|
|
59235
|
+
approxEquals(this._spherical.phi, this._sphericalEnd.phi, this.restThreshold) &&
|
|
59236
|
+
approxEquals(this._spherical.radius, this._sphericalEnd.radius, this.restThreshold);
|
|
59237
|
+
return this._createOnRestPromise(resolveImmediately);
|
|
59238
|
+
}
|
|
59239
|
+
/**
|
|
59240
|
+
* Set angle and distance by given position.
|
|
59241
|
+
* An alias of `setLookAt()`, without target change. Thus keep gazing at the current target
|
|
59242
|
+
* @param positionX
|
|
59243
|
+
* @param positionY
|
|
59244
|
+
* @param positionZ
|
|
59245
|
+
* @param enableTransition
|
|
59246
|
+
* @category Methods
|
|
59247
|
+
*/
|
|
59248
|
+
setPosition(positionX, positionY, positionZ, enableTransition = false) {
|
|
59249
|
+
return this.setLookAt(positionX, positionY, positionZ, this._targetEnd.x, this._targetEnd.y, this._targetEnd.z, enableTransition);
|
|
59250
|
+
}
|
|
59251
|
+
/**
|
|
59252
|
+
* Set the target position where gaze at.
|
|
59253
|
+
* An alias of `setLookAt()`, without position change. Thus keep the same position.
|
|
59254
|
+
* @param targetX
|
|
59255
|
+
* @param targetY
|
|
59256
|
+
* @param targetZ
|
|
59257
|
+
* @param enableTransition
|
|
59258
|
+
* @category Methods
|
|
59259
|
+
*/
|
|
59260
|
+
setTarget(targetX, targetY, targetZ, enableTransition = false) {
|
|
59261
|
+
const pos = this.getPosition(_v3A);
|
|
59262
|
+
const promise = this.setLookAt(pos.x, pos.y, pos.z, targetX, targetY, targetZ, enableTransition);
|
|
59263
|
+
// see https://github.com/yomotsu/camera-controls/issues/335
|
|
59264
|
+
this._sphericalEnd.phi = clamp(this._sphericalEnd.phi, this.minPolarAngle, this.maxPolarAngle);
|
|
59265
|
+
return promise;
|
|
59266
|
+
}
|
|
59267
|
+
/**
|
|
59268
|
+
* Set focal offset using the screen parallel coordinates. z doesn't affect in Orthographic as with Dolly.
|
|
59269
|
+
* @param x
|
|
59270
|
+
* @param y
|
|
59271
|
+
* @param z
|
|
59272
|
+
* @param enableTransition
|
|
59273
|
+
* @category Methods
|
|
59274
|
+
*/
|
|
59275
|
+
setFocalOffset(x, y, z, enableTransition = false) {
|
|
59276
|
+
this._isUserControllingOffset = false;
|
|
59277
|
+
this._focalOffsetEnd.set(x, y, z);
|
|
59278
|
+
this._needsUpdate = true;
|
|
59279
|
+
if (!enableTransition)
|
|
59280
|
+
this._focalOffset.copy(this._focalOffsetEnd);
|
|
59281
|
+
const resolveImmediately = !enableTransition ||
|
|
59282
|
+
approxEquals(this._focalOffset.x, this._focalOffsetEnd.x, this.restThreshold) &&
|
|
59283
|
+
approxEquals(this._focalOffset.y, this._focalOffsetEnd.y, this.restThreshold) &&
|
|
59284
|
+
approxEquals(this._focalOffset.z, this._focalOffsetEnd.z, this.restThreshold);
|
|
59285
|
+
return this._createOnRestPromise(resolveImmediately);
|
|
59286
|
+
}
|
|
59287
|
+
/**
|
|
59288
|
+
* Set orbit point without moving the camera.
|
|
59289
|
+
* SHOULD NOT RUN DURING ANIMATIONS. `setOrbitPoint()` will immediately fix the positions.
|
|
59290
|
+
* @param targetX
|
|
59291
|
+
* @param targetY
|
|
59292
|
+
* @param targetZ
|
|
59293
|
+
* @category Methods
|
|
59294
|
+
*/
|
|
59295
|
+
setOrbitPoint(targetX, targetY, targetZ) {
|
|
59296
|
+
this._camera.updateMatrixWorld();
|
|
59297
|
+
_xColumn.setFromMatrixColumn(this._camera.matrixWorldInverse, 0);
|
|
59298
|
+
_yColumn.setFromMatrixColumn(this._camera.matrixWorldInverse, 1);
|
|
59299
|
+
_zColumn.setFromMatrixColumn(this._camera.matrixWorldInverse, 2);
|
|
59300
|
+
const position = _v3A.set(targetX, targetY, targetZ);
|
|
59301
|
+
const distance = position.distanceTo(this._camera.position);
|
|
59302
|
+
const cameraToPoint = position.sub(this._camera.position);
|
|
59303
|
+
_xColumn.multiplyScalar(cameraToPoint.x);
|
|
59304
|
+
_yColumn.multiplyScalar(cameraToPoint.y);
|
|
59305
|
+
_zColumn.multiplyScalar(cameraToPoint.z);
|
|
59306
|
+
_v3A.copy(_xColumn).add(_yColumn).add(_zColumn);
|
|
59307
|
+
_v3A.z = _v3A.z + distance;
|
|
59308
|
+
this.dollyTo(distance, false);
|
|
59309
|
+
this.setFocalOffset(-_v3A.x, _v3A.y, -_v3A.z, false);
|
|
59310
|
+
this.moveTo(targetX, targetY, targetZ, false);
|
|
59311
|
+
}
|
|
59312
|
+
/**
|
|
59313
|
+
* Set the boundary box that encloses the target of the camera. box3 is in THREE.Box3
|
|
59314
|
+
* @param box3
|
|
59315
|
+
* @category Methods
|
|
59316
|
+
*/
|
|
59317
|
+
setBoundary(box3) {
|
|
59318
|
+
if (!box3) {
|
|
59319
|
+
this._boundary.min.set(-Infinity, -Infinity, -Infinity);
|
|
59320
|
+
this._boundary.max.set(Infinity, Infinity, Infinity);
|
|
59321
|
+
this._needsUpdate = true;
|
|
59322
|
+
return;
|
|
59323
|
+
}
|
|
59324
|
+
this._boundary.copy(box3);
|
|
59325
|
+
this._boundary.clampPoint(this._targetEnd, this._targetEnd);
|
|
59326
|
+
this._needsUpdate = true;
|
|
59327
|
+
}
|
|
59328
|
+
/**
|
|
59329
|
+
* Set (or unset) the current viewport.
|
|
59330
|
+
* Set this when you want to use renderer viewport and .dollyToCursor feature at the same time.
|
|
59331
|
+
* @param viewportOrX
|
|
59332
|
+
* @param y
|
|
59333
|
+
* @param width
|
|
59334
|
+
* @param height
|
|
59335
|
+
* @category Methods
|
|
59336
|
+
*/
|
|
59337
|
+
setViewport(viewportOrX, y, width, height) {
|
|
59338
|
+
if (viewportOrX === null) { // null
|
|
59339
|
+
this._viewport = null;
|
|
59340
|
+
return;
|
|
59341
|
+
}
|
|
59342
|
+
this._viewport = this._viewport || new THREE.Vector4();
|
|
59343
|
+
if (typeof viewportOrX === 'number') { // number
|
|
59344
|
+
this._viewport.set(viewportOrX, y, width, height);
|
|
59345
|
+
}
|
|
59346
|
+
else { // Vector4
|
|
59347
|
+
this._viewport.copy(viewportOrX);
|
|
59348
|
+
}
|
|
59349
|
+
}
|
|
59350
|
+
/**
|
|
59351
|
+
* Calculate the distance to fit the box.
|
|
59352
|
+
* @param width box width
|
|
59353
|
+
* @param height box height
|
|
59354
|
+
* @param depth box depth
|
|
59355
|
+
* @returns distance
|
|
59356
|
+
* @category Methods
|
|
59357
|
+
*/
|
|
59358
|
+
getDistanceToFitBox(width, height, depth, cover = false) {
|
|
59359
|
+
if (notSupportedInOrthographicCamera(this._camera, 'getDistanceToFitBox'))
|
|
59360
|
+
return this._spherical.radius;
|
|
59361
|
+
const boundingRectAspect = width / height;
|
|
59362
|
+
const fov = this._camera.getEffectiveFOV() * DEG2RAD;
|
|
59363
|
+
const aspect = this._camera.aspect;
|
|
59364
|
+
const heightToFit = (cover ? boundingRectAspect > aspect : boundingRectAspect < aspect) ? height : width / aspect;
|
|
59365
|
+
return heightToFit * 0.5 / Math.tan(fov * 0.5) + depth * 0.5;
|
|
59366
|
+
}
|
|
59367
|
+
/**
|
|
59368
|
+
* Calculate the distance to fit the sphere.
|
|
59369
|
+
* @param radius sphere radius
|
|
59370
|
+
* @returns distance
|
|
59371
|
+
* @category Methods
|
|
59372
|
+
*/
|
|
59373
|
+
getDistanceToFitSphere(radius) {
|
|
59374
|
+
if (notSupportedInOrthographicCamera(this._camera, 'getDistanceToFitSphere'))
|
|
59375
|
+
return this._spherical.radius;
|
|
59376
|
+
// https://stackoverflow.com/a/44849975
|
|
59377
|
+
const vFOV = this._camera.getEffectiveFOV() * DEG2RAD;
|
|
59378
|
+
const hFOV = Math.atan(Math.tan(vFOV * 0.5) * this._camera.aspect) * 2;
|
|
59379
|
+
const fov = 1 < this._camera.aspect ? vFOV : hFOV;
|
|
59380
|
+
return radius / (Math.sin(fov * 0.5));
|
|
59381
|
+
}
|
|
59382
|
+
/**
|
|
59383
|
+
* Returns the orbit center position, where the camera looking at.
|
|
59384
|
+
* @param out The receiving Vector3 instance to copy the result
|
|
59385
|
+
* @param receiveEndValue Whether receive the transition end coords or current. default is `true`
|
|
59386
|
+
* @category Methods
|
|
59387
|
+
*/
|
|
59388
|
+
getTarget(out, receiveEndValue = true) {
|
|
59389
|
+
const _out = !!out && out.isVector3 ? out : new THREE.Vector3();
|
|
59390
|
+
return _out.copy(receiveEndValue ? this._targetEnd : this._target);
|
|
59391
|
+
}
|
|
59392
|
+
/**
|
|
59393
|
+
* Returns the camera position.
|
|
59394
|
+
* @param out The receiving Vector3 instance to copy the result
|
|
59395
|
+
* @param receiveEndValue Whether receive the transition end coords or current. default is `true`
|
|
59396
|
+
* @category Methods
|
|
59397
|
+
*/
|
|
59398
|
+
getPosition(out, receiveEndValue = true) {
|
|
59399
|
+
const _out = !!out && out.isVector3 ? out : new THREE.Vector3();
|
|
59400
|
+
return _out.setFromSpherical(receiveEndValue ? this._sphericalEnd : this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(receiveEndValue ? this._targetEnd : this._target);
|
|
59401
|
+
}
|
|
59402
|
+
/**
|
|
59403
|
+
* Returns the spherical coordinates of the orbit.
|
|
59404
|
+
* @param out The receiving Spherical instance to copy the result
|
|
59405
|
+
* @param receiveEndValue Whether receive the transition end coords or current. default is `true`
|
|
59406
|
+
* @category Methods
|
|
59407
|
+
*/
|
|
59408
|
+
getSpherical(out, receiveEndValue = true) {
|
|
59409
|
+
const _out = out || new THREE.Spherical();
|
|
59410
|
+
return _out.copy(receiveEndValue ? this._sphericalEnd : this._spherical);
|
|
59411
|
+
}
|
|
59412
|
+
/**
|
|
59413
|
+
* Returns the focal offset, which is how much the camera appears to be translated in screen parallel coordinates.
|
|
59414
|
+
* @param out The receiving Vector3 instance to copy the result
|
|
59415
|
+
* @param receiveEndValue Whether receive the transition end coords or current. default is `true`
|
|
59416
|
+
* @category Methods
|
|
59417
|
+
*/
|
|
59418
|
+
getFocalOffset(out, receiveEndValue = true) {
|
|
59419
|
+
const _out = !!out && out.isVector3 ? out : new THREE.Vector3();
|
|
59420
|
+
return _out.copy(receiveEndValue ? this._focalOffsetEnd : this._focalOffset);
|
|
59421
|
+
}
|
|
59422
|
+
/**
|
|
59423
|
+
* Normalize camera azimuth angle rotation between 0 and 360 degrees.
|
|
59424
|
+
* @category Methods
|
|
59425
|
+
*/
|
|
59426
|
+
normalizeRotations() {
|
|
59427
|
+
this._sphericalEnd.theta = this._sphericalEnd.theta % PI_2;
|
|
59428
|
+
if (this._sphericalEnd.theta < 0)
|
|
59429
|
+
this._sphericalEnd.theta += PI_2;
|
|
59430
|
+
this._spherical.theta += PI_2 * Math.round((this._sphericalEnd.theta - this._spherical.theta) / PI_2);
|
|
59431
|
+
}
|
|
59432
|
+
/**
|
|
59433
|
+
* stop all transitions.
|
|
59434
|
+
*/
|
|
59435
|
+
stop() {
|
|
59436
|
+
this._focalOffset.copy(this._focalOffsetEnd);
|
|
59437
|
+
this._target.copy(this._targetEnd);
|
|
59438
|
+
this._spherical.copy(this._sphericalEnd);
|
|
59439
|
+
this._zoom = this._zoomEnd;
|
|
59440
|
+
}
|
|
59441
|
+
/**
|
|
59442
|
+
* Reset all rotation and position to defaults.
|
|
59443
|
+
* @param enableTransition
|
|
59444
|
+
* @category Methods
|
|
59445
|
+
*/
|
|
59446
|
+
reset(enableTransition = false) {
|
|
59447
|
+
if (!approxEquals(this._camera.up.x, this._cameraUp0.x) ||
|
|
59448
|
+
!approxEquals(this._camera.up.y, this._cameraUp0.y) ||
|
|
59449
|
+
!approxEquals(this._camera.up.z, this._cameraUp0.z)) {
|
|
59450
|
+
this._camera.up.copy(this._cameraUp0);
|
|
59451
|
+
const position = this.getPosition(_v3A);
|
|
59452
|
+
this.updateCameraUp();
|
|
59453
|
+
this.setPosition(position.x, position.y, position.z);
|
|
59454
|
+
}
|
|
59455
|
+
const promises = [
|
|
59456
|
+
this.setLookAt(this._position0.x, this._position0.y, this._position0.z, this._target0.x, this._target0.y, this._target0.z, enableTransition),
|
|
59457
|
+
this.setFocalOffset(this._focalOffset0.x, this._focalOffset0.y, this._focalOffset0.z, enableTransition),
|
|
59458
|
+
this.zoomTo(this._zoom0, enableTransition),
|
|
59459
|
+
];
|
|
59460
|
+
return Promise.all(promises);
|
|
59461
|
+
}
|
|
59462
|
+
/**
|
|
59463
|
+
* Set current camera position as the default position.
|
|
59464
|
+
* @category Methods
|
|
59465
|
+
*/
|
|
59466
|
+
saveState() {
|
|
59467
|
+
this._cameraUp0.copy(this._camera.up);
|
|
59468
|
+
this.getTarget(this._target0);
|
|
59469
|
+
this.getPosition(this._position0);
|
|
59470
|
+
this._zoom0 = this._zoom;
|
|
59471
|
+
this._focalOffset0.copy(this._focalOffset);
|
|
59472
|
+
}
|
|
59473
|
+
/**
|
|
59474
|
+
* Sync camera-up direction.
|
|
59475
|
+
* When camera-up vector is changed, `.updateCameraUp()` must be called.
|
|
59476
|
+
* @category Methods
|
|
59477
|
+
*/
|
|
59478
|
+
updateCameraUp() {
|
|
59479
|
+
this._yAxisUpSpace.setFromUnitVectors(this._camera.up, _AXIS_Y);
|
|
59480
|
+
this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert();
|
|
59481
|
+
}
|
|
59482
|
+
/**
|
|
59483
|
+
* Apply current camera-up direction to the camera.
|
|
59484
|
+
* The orbit system will be re-initialized with the current position.
|
|
59485
|
+
* @category Methods
|
|
59486
|
+
*/
|
|
59487
|
+
applyCameraUp() {
|
|
59488
|
+
const cameraDirection = _v3A.subVectors(this._target, this._camera.position).normalize();
|
|
59489
|
+
// So first find the vector off to the side, orthogonal to both this.object.up and
|
|
59490
|
+
// the "view" vector.
|
|
59491
|
+
const side = _v3B.crossVectors(cameraDirection, this._camera.up);
|
|
59492
|
+
// Then find the vector orthogonal to both this "side" vector and the "view" vector.
|
|
59493
|
+
// This vector will be the new "up" vector.
|
|
59494
|
+
this._camera.up.crossVectors(side, cameraDirection).normalize();
|
|
59495
|
+
this._camera.updateMatrixWorld();
|
|
59496
|
+
const position = this.getPosition(_v3A);
|
|
59497
|
+
this.updateCameraUp();
|
|
59498
|
+
this.setPosition(position.x, position.y, position.z);
|
|
59499
|
+
}
|
|
59500
|
+
/**
|
|
59501
|
+
* Update camera position and directions.
|
|
59502
|
+
* This should be called in your tick loop every time, and returns true if re-rendering is needed.
|
|
59503
|
+
* @param delta
|
|
59504
|
+
* @returns updated
|
|
59505
|
+
* @category Methods
|
|
59506
|
+
*/
|
|
59507
|
+
update(delta) {
|
|
59508
|
+
const deltaTheta = this._sphericalEnd.theta - this._spherical.theta;
|
|
59509
|
+
const deltaPhi = this._sphericalEnd.phi - this._spherical.phi;
|
|
59510
|
+
const deltaRadius = this._sphericalEnd.radius - this._spherical.radius;
|
|
59511
|
+
const deltaTarget = _deltaTarget.subVectors(this._targetEnd, this._target);
|
|
59512
|
+
const deltaOffset = _deltaOffset.subVectors(this._focalOffsetEnd, this._focalOffset);
|
|
59513
|
+
const deltaZoom = this._zoomEnd - this._zoom;
|
|
59514
|
+
// update theta
|
|
59515
|
+
if (approxZero(deltaTheta)) {
|
|
59516
|
+
this._thetaVelocity.value = 0;
|
|
59517
|
+
this._spherical.theta = this._sphericalEnd.theta;
|
|
59518
|
+
}
|
|
59519
|
+
else {
|
|
59520
|
+
const smoothTime = this._isUserControllingRotate ? this.draggingSmoothTime : this.smoothTime;
|
|
59521
|
+
this._spherical.theta = smoothDamp(this._spherical.theta, this._sphericalEnd.theta, this._thetaVelocity, smoothTime, Infinity, delta);
|
|
59522
|
+
this._needsUpdate = true;
|
|
59523
|
+
}
|
|
59524
|
+
// update phi
|
|
59525
|
+
if (approxZero(deltaPhi)) {
|
|
59526
|
+
this._phiVelocity.value = 0;
|
|
59527
|
+
this._spherical.phi = this._sphericalEnd.phi;
|
|
59528
|
+
}
|
|
59529
|
+
else {
|
|
59530
|
+
const smoothTime = this._isUserControllingRotate ? this.draggingSmoothTime : this.smoothTime;
|
|
59531
|
+
this._spherical.phi = smoothDamp(this._spherical.phi, this._sphericalEnd.phi, this._phiVelocity, smoothTime, Infinity, delta);
|
|
59532
|
+
this._needsUpdate = true;
|
|
59533
|
+
}
|
|
59534
|
+
// update distance
|
|
59535
|
+
if (approxZero(deltaRadius)) {
|
|
59536
|
+
this._radiusVelocity.value = 0;
|
|
59537
|
+
this._spherical.radius = this._sphericalEnd.radius;
|
|
59538
|
+
}
|
|
59539
|
+
else {
|
|
59540
|
+
const smoothTime = this._isUserControllingDolly ? this.draggingSmoothTime : this.smoothTime;
|
|
59541
|
+
this._spherical.radius = smoothDamp(this._spherical.radius, this._sphericalEnd.radius, this._radiusVelocity, smoothTime, this.maxSpeed, delta);
|
|
59542
|
+
this._needsUpdate = true;
|
|
59543
|
+
}
|
|
59544
|
+
// update target position
|
|
59545
|
+
if (approxZero(deltaTarget.x) && approxZero(deltaTarget.y) && approxZero(deltaTarget.z)) {
|
|
59546
|
+
this._targetVelocity.set(0, 0, 0);
|
|
59547
|
+
this._target.copy(this._targetEnd);
|
|
59548
|
+
}
|
|
59549
|
+
else {
|
|
59550
|
+
const smoothTime = this._isUserControllingTruck ? this.draggingSmoothTime : this.smoothTime;
|
|
59551
|
+
smoothDampVec3(this._target, this._targetEnd, this._targetVelocity, smoothTime, this.maxSpeed, delta, this._target);
|
|
59552
|
+
this._needsUpdate = true;
|
|
59553
|
+
}
|
|
59554
|
+
// update focalOffset
|
|
59555
|
+
if (approxZero(deltaOffset.x) && approxZero(deltaOffset.y) && approxZero(deltaOffset.z)) {
|
|
59556
|
+
this._focalOffsetVelocity.set(0, 0, 0);
|
|
59557
|
+
this._focalOffset.copy(this._focalOffsetEnd);
|
|
59558
|
+
}
|
|
59559
|
+
else {
|
|
59560
|
+
const smoothTime = this._isUserControllingOffset ? this.draggingSmoothTime : this.smoothTime;
|
|
59561
|
+
smoothDampVec3(this._focalOffset, this._focalOffsetEnd, this._focalOffsetVelocity, smoothTime, this.maxSpeed, delta, this._focalOffset);
|
|
59562
|
+
this._needsUpdate = true;
|
|
59563
|
+
}
|
|
59564
|
+
// update zoom
|
|
59565
|
+
if (approxZero(deltaZoom)) {
|
|
59566
|
+
this._zoomVelocity.value = 0;
|
|
59567
|
+
this._zoom = this._zoomEnd;
|
|
59568
|
+
}
|
|
59569
|
+
else {
|
|
59570
|
+
const smoothTime = this._isUserControllingZoom ? this.draggingSmoothTime : this.smoothTime;
|
|
59571
|
+
this._zoom = smoothDamp(this._zoom, this._zoomEnd, this._zoomVelocity, smoothTime, Infinity, delta);
|
|
59572
|
+
}
|
|
59573
|
+
if (this.dollyToCursor) {
|
|
59574
|
+
if (isPerspectiveCamera(this._camera) && this._changedDolly !== 0) {
|
|
59575
|
+
const dollyControlAmount = this._spherical.radius - this._lastDistance;
|
|
59576
|
+
const camera = this._camera;
|
|
59577
|
+
const cameraDirection = this._getCameraDirection(_cameraDirection);
|
|
59578
|
+
const planeX = _v3A.copy(cameraDirection).cross(camera.up).normalize();
|
|
59579
|
+
if (planeX.lengthSq() === 0)
|
|
59580
|
+
planeX.x = 1.0;
|
|
59581
|
+
const planeY = _v3B.crossVectors(planeX, cameraDirection);
|
|
59582
|
+
const worldToScreen = this._sphericalEnd.radius * Math.tan(camera.getEffectiveFOV() * DEG2RAD * 0.5);
|
|
59583
|
+
const prevRadius = this._sphericalEnd.radius - dollyControlAmount;
|
|
59584
|
+
const lerpRatio = (prevRadius - this._sphericalEnd.radius) / this._sphericalEnd.radius;
|
|
59585
|
+
const cursor = _v3C.copy(this._targetEnd)
|
|
59586
|
+
.add(planeX.multiplyScalar(this._dollyControlCoord.x * worldToScreen * camera.aspect))
|
|
59587
|
+
.add(planeY.multiplyScalar(this._dollyControlCoord.y * worldToScreen));
|
|
59588
|
+
const newTargetEnd = _v3A.copy(this._targetEnd).lerp(cursor, lerpRatio);
|
|
59589
|
+
const isMin = this._lastDollyDirection === DOLLY_DIRECTION.IN && this._spherical.radius <= this.minDistance;
|
|
59590
|
+
const isMax = this._lastDollyDirection === DOLLY_DIRECTION.OUT && this.maxDistance <= this._spherical.radius;
|
|
59591
|
+
if (this.infinityDolly && (isMin || isMax)) {
|
|
59592
|
+
this._sphericalEnd.radius -= dollyControlAmount;
|
|
59593
|
+
this._spherical.radius -= dollyControlAmount;
|
|
59594
|
+
const dollyAmount = _v3B.copy(cameraDirection).multiplyScalar(-dollyControlAmount);
|
|
59595
|
+
newTargetEnd.add(dollyAmount);
|
|
59596
|
+
}
|
|
59597
|
+
// target position may be moved beyond boundary.
|
|
59598
|
+
this._boundary.clampPoint(newTargetEnd, newTargetEnd);
|
|
59599
|
+
const targetEndDiff = _v3B.subVectors(newTargetEnd, this._targetEnd);
|
|
59600
|
+
this._targetEnd.copy(newTargetEnd);
|
|
59601
|
+
this._target.add(targetEndDiff);
|
|
59602
|
+
this._changedDolly -= dollyControlAmount;
|
|
59603
|
+
if (approxZero(this._changedDolly))
|
|
59604
|
+
this._changedDolly = 0;
|
|
59605
|
+
}
|
|
59606
|
+
else if (isOrthographicCamera(this._camera) && this._changedZoom !== 0) {
|
|
59607
|
+
const dollyControlAmount = this._zoom - this._lastZoom;
|
|
59608
|
+
const camera = this._camera;
|
|
59609
|
+
const worldCursorPosition = _v3A.set(this._dollyControlCoord.x, this._dollyControlCoord.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera);
|
|
59610
|
+
const quaternion = _v3B.set(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
59611
|
+
const cursor = _v3C.copy(worldCursorPosition).add(quaternion.multiplyScalar(-worldCursorPosition.dot(camera.up)));
|
|
59612
|
+
const prevZoom = this._zoom - dollyControlAmount;
|
|
59613
|
+
const lerpRatio = -(prevZoom - this._zoom) / this._zoom;
|
|
59614
|
+
// find the "distance" (aka plane constant in three.js) of Plane
|
|
59615
|
+
// from a given position (this._targetEnd) and normal vector (cameraDirection)
|
|
59616
|
+
// https://www.maplesoft.com/support/help/maple/view.aspx?path=MathApps%2FEquationOfAPlaneNormal#bkmrk0
|
|
59617
|
+
const cameraDirection = this._getCameraDirection(_cameraDirection);
|
|
59618
|
+
const prevPlaneConstant = this._targetEnd.dot(cameraDirection);
|
|
59619
|
+
const newTargetEnd = _v3A.copy(this._targetEnd).lerp(cursor, lerpRatio);
|
|
59620
|
+
const newPlaneConstant = newTargetEnd.dot(cameraDirection);
|
|
59621
|
+
// Pull back the camera depth that has moved, to be the camera stationary as zoom
|
|
59622
|
+
const pullBack = cameraDirection.multiplyScalar(newPlaneConstant - prevPlaneConstant);
|
|
59623
|
+
newTargetEnd.sub(pullBack);
|
|
59624
|
+
// target position may be moved beyond boundary.
|
|
59625
|
+
this._boundary.clampPoint(newTargetEnd, newTargetEnd);
|
|
59626
|
+
const targetEndDiff = _v3B.subVectors(newTargetEnd, this._targetEnd);
|
|
59627
|
+
this._targetEnd.copy(newTargetEnd);
|
|
59628
|
+
this._target.add(targetEndDiff);
|
|
59629
|
+
// this._target.copy( this._targetEnd );
|
|
59630
|
+
this._changedZoom -= dollyControlAmount;
|
|
59631
|
+
if (approxZero(this._changedZoom))
|
|
59632
|
+
this._changedZoom = 0;
|
|
59633
|
+
}
|
|
59634
|
+
}
|
|
59635
|
+
if (this._camera.zoom !== this._zoom) {
|
|
59636
|
+
this._camera.zoom = this._zoom;
|
|
59637
|
+
this._camera.updateProjectionMatrix();
|
|
59638
|
+
this._updateNearPlaneCorners();
|
|
59639
|
+
this._needsUpdate = true;
|
|
59640
|
+
}
|
|
59641
|
+
this._dragNeedsUpdate = true;
|
|
59642
|
+
// collision detection
|
|
59643
|
+
const maxDistance = this._collisionTest();
|
|
59644
|
+
this._spherical.radius = Math.min(this._spherical.radius, maxDistance);
|
|
59645
|
+
// decompose spherical to the camera position
|
|
59646
|
+
this._spherical.makeSafe();
|
|
59647
|
+
this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target);
|
|
59648
|
+
this._camera.lookAt(this._target);
|
|
59649
|
+
// set offset after the orbit movement
|
|
59650
|
+
const affectOffset = !approxZero(this._focalOffset.x) ||
|
|
59651
|
+
!approxZero(this._focalOffset.y) ||
|
|
59652
|
+
!approxZero(this._focalOffset.z);
|
|
59653
|
+
if (affectOffset) {
|
|
59654
|
+
_xColumn.setFromMatrixColumn(this._camera.matrix, 0);
|
|
59655
|
+
_yColumn.setFromMatrixColumn(this._camera.matrix, 1);
|
|
59656
|
+
_zColumn.setFromMatrixColumn(this._camera.matrix, 2);
|
|
59657
|
+
_xColumn.multiplyScalar(this._focalOffset.x);
|
|
59658
|
+
_yColumn.multiplyScalar(-this._focalOffset.y);
|
|
59659
|
+
_zColumn.multiplyScalar(this._focalOffset.z); // notice: z-offset will not affect in Orthographic.
|
|
59660
|
+
_v3A.copy(_xColumn).add(_yColumn).add(_zColumn);
|
|
59661
|
+
this._camera.position.add(_v3A);
|
|
59662
|
+
this._camera.updateMatrixWorld();
|
|
59663
|
+
}
|
|
59664
|
+
if (this._boundaryEnclosesCamera) {
|
|
59665
|
+
this._encloseToBoundary(this._camera.position.copy(this._target), _v3A.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse), 1.0);
|
|
59666
|
+
}
|
|
59667
|
+
const updated = this._needsUpdate;
|
|
59668
|
+
if (updated && !this._updatedLastTime) {
|
|
59669
|
+
this._hasRested = false;
|
|
59670
|
+
this.dispatchEvent({ type: 'wake' });
|
|
59671
|
+
this.dispatchEvent({ type: 'update' });
|
|
59672
|
+
}
|
|
59673
|
+
else if (updated) {
|
|
59674
|
+
this.dispatchEvent({ type: 'update' });
|
|
59675
|
+
if (approxZero(deltaTheta, this.restThreshold) &&
|
|
59676
|
+
approxZero(deltaPhi, this.restThreshold) &&
|
|
59677
|
+
approxZero(deltaRadius, this.restThreshold) &&
|
|
59678
|
+
approxZero(deltaTarget.x, this.restThreshold) &&
|
|
59679
|
+
approxZero(deltaTarget.y, this.restThreshold) &&
|
|
59680
|
+
approxZero(deltaTarget.z, this.restThreshold) &&
|
|
59681
|
+
approxZero(deltaOffset.x, this.restThreshold) &&
|
|
59682
|
+
approxZero(deltaOffset.y, this.restThreshold) &&
|
|
59683
|
+
approxZero(deltaOffset.z, this.restThreshold) &&
|
|
59684
|
+
approxZero(deltaZoom, this.restThreshold) &&
|
|
59685
|
+
!this._hasRested) {
|
|
59686
|
+
this._hasRested = true;
|
|
59687
|
+
this.dispatchEvent({ type: 'rest' });
|
|
59688
|
+
}
|
|
59689
|
+
}
|
|
59690
|
+
else if (!updated && this._updatedLastTime) {
|
|
59691
|
+
this.dispatchEvent({ type: 'sleep' });
|
|
59692
|
+
}
|
|
59693
|
+
this._lastDistance = this._spherical.radius;
|
|
59694
|
+
this._lastZoom = this._zoom;
|
|
59695
|
+
this._updatedLastTime = updated;
|
|
59696
|
+
this._needsUpdate = false;
|
|
59697
|
+
return updated;
|
|
59698
|
+
}
|
|
59699
|
+
/**
|
|
59700
|
+
* Get all state in JSON string
|
|
59701
|
+
* @category Methods
|
|
59702
|
+
*/
|
|
59703
|
+
toJSON() {
|
|
59704
|
+
return JSON.stringify({
|
|
59705
|
+
enabled: this._enabled,
|
|
59706
|
+
minDistance: this.minDistance,
|
|
59707
|
+
maxDistance: infinityToMaxNumber(this.maxDistance),
|
|
59708
|
+
minZoom: this.minZoom,
|
|
59709
|
+
maxZoom: infinityToMaxNumber(this.maxZoom),
|
|
59710
|
+
minPolarAngle: this.minPolarAngle,
|
|
59711
|
+
maxPolarAngle: infinityToMaxNumber(this.maxPolarAngle),
|
|
59712
|
+
minAzimuthAngle: infinityToMaxNumber(this.minAzimuthAngle),
|
|
59713
|
+
maxAzimuthAngle: infinityToMaxNumber(this.maxAzimuthAngle),
|
|
59714
|
+
smoothTime: this.smoothTime,
|
|
59715
|
+
draggingSmoothTime: this.draggingSmoothTime,
|
|
59716
|
+
dollySpeed: this.dollySpeed,
|
|
59717
|
+
truckSpeed: this.truckSpeed,
|
|
59718
|
+
dollyToCursor: this.dollyToCursor,
|
|
59719
|
+
target: this._targetEnd.toArray(),
|
|
59720
|
+
position: _v3A.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),
|
|
59721
|
+
zoom: this._zoomEnd,
|
|
59722
|
+
focalOffset: this._focalOffsetEnd.toArray(),
|
|
59723
|
+
target0: this._target0.toArray(),
|
|
59724
|
+
position0: this._position0.toArray(),
|
|
59725
|
+
zoom0: this._zoom0,
|
|
59726
|
+
focalOffset0: this._focalOffset0.toArray(),
|
|
59727
|
+
});
|
|
59728
|
+
}
|
|
59729
|
+
/**
|
|
59730
|
+
* Reproduce the control state with JSON. enableTransition is where anim or not in a boolean.
|
|
59731
|
+
* @param json
|
|
59732
|
+
* @param enableTransition
|
|
59733
|
+
* @category Methods
|
|
59734
|
+
*/
|
|
59735
|
+
fromJSON(json, enableTransition = false) {
|
|
59736
|
+
const obj = JSON.parse(json);
|
|
59737
|
+
this.enabled = obj.enabled;
|
|
59738
|
+
this.minDistance = obj.minDistance;
|
|
59739
|
+
this.maxDistance = maxNumberToInfinity(obj.maxDistance);
|
|
59740
|
+
this.minZoom = obj.minZoom;
|
|
59741
|
+
this.maxZoom = maxNumberToInfinity(obj.maxZoom);
|
|
59742
|
+
this.minPolarAngle = obj.minPolarAngle;
|
|
59743
|
+
this.maxPolarAngle = maxNumberToInfinity(obj.maxPolarAngle);
|
|
59744
|
+
this.minAzimuthAngle = maxNumberToInfinity(obj.minAzimuthAngle);
|
|
59745
|
+
this.maxAzimuthAngle = maxNumberToInfinity(obj.maxAzimuthAngle);
|
|
59746
|
+
this.smoothTime = obj.smoothTime;
|
|
59747
|
+
this.draggingSmoothTime = obj.draggingSmoothTime;
|
|
59748
|
+
this.dollySpeed = obj.dollySpeed;
|
|
59749
|
+
this.truckSpeed = obj.truckSpeed;
|
|
59750
|
+
this.dollyToCursor = obj.dollyToCursor;
|
|
59751
|
+
this._target0.fromArray(obj.target0);
|
|
59752
|
+
this._position0.fromArray(obj.position0);
|
|
59753
|
+
this._zoom0 = obj.zoom0;
|
|
59754
|
+
this._focalOffset0.fromArray(obj.focalOffset0);
|
|
59755
|
+
this.moveTo(obj.target[0], obj.target[1], obj.target[2], enableTransition);
|
|
59756
|
+
_sphericalA.setFromVector3(_v3A.fromArray(obj.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace));
|
|
59757
|
+
this.rotateTo(_sphericalA.theta, _sphericalA.phi, enableTransition);
|
|
59758
|
+
this.dollyTo(_sphericalA.radius, enableTransition);
|
|
59759
|
+
this.zoomTo(obj.zoom, enableTransition);
|
|
59760
|
+
this.setFocalOffset(obj.focalOffset[0], obj.focalOffset[1], obj.focalOffset[2], enableTransition);
|
|
59761
|
+
this._needsUpdate = true;
|
|
59762
|
+
}
|
|
59763
|
+
/**
|
|
59764
|
+
* Attach all internal event handlers to enable drag control.
|
|
59765
|
+
* @category Methods
|
|
59766
|
+
*/
|
|
59767
|
+
connect(domElement) {
|
|
59768
|
+
if (this._domElement) {
|
|
59769
|
+
console.warn('camera-controls is already connected.');
|
|
59770
|
+
return;
|
|
59771
|
+
}
|
|
59772
|
+
domElement.setAttribute('data-camera-controls-version', VERSION);
|
|
59773
|
+
this._addAllEventListeners(domElement);
|
|
59774
|
+
this._getClientRect(this._elementRect);
|
|
59775
|
+
}
|
|
59776
|
+
/**
|
|
59777
|
+
* Detach all internal event handlers to disable drag control.
|
|
59778
|
+
*/
|
|
59779
|
+
disconnect() {
|
|
59780
|
+
this.cancel();
|
|
59781
|
+
this._removeAllEventListeners();
|
|
59782
|
+
if (this._domElement) {
|
|
59783
|
+
this._domElement.removeAttribute('data-camera-controls-version');
|
|
59784
|
+
this._domElement = undefined;
|
|
59785
|
+
}
|
|
59786
|
+
}
|
|
59787
|
+
/**
|
|
59788
|
+
* Dispose the cameraControls instance itself, remove all eventListeners.
|
|
59789
|
+
* @category Methods
|
|
59790
|
+
*/
|
|
59791
|
+
dispose() {
|
|
59792
|
+
// remove all user event listeners
|
|
59793
|
+
this.removeAllEventListeners();
|
|
59794
|
+
// remove all internal event listeners
|
|
59795
|
+
this.disconnect();
|
|
59796
|
+
}
|
|
59797
|
+
// it's okay to expose public though
|
|
59798
|
+
_getTargetDirection(out) {
|
|
59799
|
+
// divide by distance to normalize, lighter than `Vector3.prototype.normalize()`
|
|
59800
|
+
return out.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse);
|
|
59801
|
+
}
|
|
59802
|
+
// it's okay to expose public though
|
|
59803
|
+
_getCameraDirection(out) {
|
|
59804
|
+
return this._getTargetDirection(out).negate();
|
|
59805
|
+
}
|
|
59806
|
+
_findPointerById(pointerId) {
|
|
59807
|
+
return this._activePointers.find((activePointer) => activePointer.pointerId === pointerId);
|
|
59808
|
+
}
|
|
59809
|
+
_findPointerByMouseButton(mouseButton) {
|
|
59810
|
+
return this._activePointers.find((activePointer) => activePointer.mouseButton === mouseButton);
|
|
59811
|
+
}
|
|
59812
|
+
_disposePointer(pointer) {
|
|
59813
|
+
this._activePointers.splice(this._activePointers.indexOf(pointer), 1);
|
|
59814
|
+
}
|
|
59815
|
+
_encloseToBoundary(position, offset, friction) {
|
|
59816
|
+
const offsetLength2 = offset.lengthSq();
|
|
59817
|
+
if (offsetLength2 === 0.0) { // sanity check
|
|
59818
|
+
return position;
|
|
59819
|
+
}
|
|
59820
|
+
// See: https://twitter.com/FMS_Cat/status/1106508958640988161
|
|
59821
|
+
const newTarget = _v3B.copy(offset).add(position); // target
|
|
59822
|
+
const clampedTarget = this._boundary.clampPoint(newTarget, _v3C); // clamped target
|
|
59823
|
+
const deltaClampedTarget = clampedTarget.sub(newTarget); // newTarget -> clampedTarget
|
|
59824
|
+
const deltaClampedTargetLength2 = deltaClampedTarget.lengthSq(); // squared length of deltaClampedTarget
|
|
59825
|
+
if (deltaClampedTargetLength2 === 0.0) { // when the position doesn't have to be clamped
|
|
59826
|
+
return position.add(offset);
|
|
59827
|
+
}
|
|
59828
|
+
else if (deltaClampedTargetLength2 === offsetLength2) { // when the position is completely stuck
|
|
59829
|
+
return position;
|
|
59830
|
+
}
|
|
59831
|
+
else if (friction === 0.0) {
|
|
59832
|
+
return position.add(offset).add(deltaClampedTarget);
|
|
59833
|
+
}
|
|
59834
|
+
else {
|
|
59835
|
+
const offsetFactor = 1.0 + friction * deltaClampedTargetLength2 / offset.dot(deltaClampedTarget);
|
|
59836
|
+
return position
|
|
59837
|
+
.add(_v3B.copy(offset).multiplyScalar(offsetFactor))
|
|
59838
|
+
.add(deltaClampedTarget.multiplyScalar(1.0 - friction));
|
|
59839
|
+
}
|
|
59840
|
+
}
|
|
59841
|
+
_updateNearPlaneCorners() {
|
|
59842
|
+
if (isPerspectiveCamera(this._camera)) {
|
|
59843
|
+
const camera = this._camera;
|
|
59844
|
+
const near = camera.near;
|
|
59845
|
+
const fov = camera.getEffectiveFOV() * DEG2RAD;
|
|
59846
|
+
const heightHalf = Math.tan(fov * 0.5) * near; // near plain half height
|
|
59847
|
+
const widthHalf = heightHalf * camera.aspect; // near plain half width
|
|
59848
|
+
this._nearPlaneCorners[0].set(-widthHalf, -heightHalf, 0);
|
|
59849
|
+
this._nearPlaneCorners[1].set(widthHalf, -heightHalf, 0);
|
|
59850
|
+
this._nearPlaneCorners[2].set(widthHalf, heightHalf, 0);
|
|
59851
|
+
this._nearPlaneCorners[3].set(-widthHalf, heightHalf, 0);
|
|
59852
|
+
}
|
|
59853
|
+
else if (isOrthographicCamera(this._camera)) {
|
|
59854
|
+
const camera = this._camera;
|
|
59855
|
+
const zoomInv = 1 / camera.zoom;
|
|
59856
|
+
const left = camera.left * zoomInv;
|
|
59857
|
+
const right = camera.right * zoomInv;
|
|
59858
|
+
const top = camera.top * zoomInv;
|
|
59859
|
+
const bottom = camera.bottom * zoomInv;
|
|
59860
|
+
this._nearPlaneCorners[0].set(left, top, 0);
|
|
59861
|
+
this._nearPlaneCorners[1].set(right, top, 0);
|
|
59862
|
+
this._nearPlaneCorners[2].set(right, bottom, 0);
|
|
59863
|
+
this._nearPlaneCorners[3].set(left, bottom, 0);
|
|
59864
|
+
}
|
|
59865
|
+
}
|
|
59866
|
+
// lateUpdate
|
|
59867
|
+
_collisionTest() {
|
|
59868
|
+
let distance = Infinity;
|
|
59869
|
+
const hasCollider = this.colliderMeshes.length >= 1;
|
|
59870
|
+
if (!hasCollider)
|
|
59871
|
+
return distance;
|
|
59872
|
+
if (notSupportedInOrthographicCamera(this._camera, '_collisionTest'))
|
|
59873
|
+
return distance;
|
|
59874
|
+
const rayDirection = this._getTargetDirection(_cameraDirection);
|
|
59875
|
+
_rotationMatrix.lookAt(_ORIGIN, rayDirection, this._camera.up);
|
|
59876
|
+
for (let i = 0; i < 4; i++) {
|
|
59877
|
+
const nearPlaneCorner = _v3B.copy(this._nearPlaneCorners[i]);
|
|
59878
|
+
nearPlaneCorner.applyMatrix4(_rotationMatrix);
|
|
59879
|
+
const origin = _v3C.addVectors(this._target, nearPlaneCorner);
|
|
59880
|
+
_raycaster.set(origin, rayDirection);
|
|
59881
|
+
_raycaster.far = this._spherical.radius + 1;
|
|
59882
|
+
const intersects = _raycaster.intersectObjects(this.colliderMeshes);
|
|
59883
|
+
if (intersects.length !== 0 && intersects[0].distance < distance) {
|
|
59884
|
+
distance = intersects[0].distance;
|
|
59885
|
+
}
|
|
59886
|
+
}
|
|
59887
|
+
return distance;
|
|
59888
|
+
}
|
|
59889
|
+
/**
|
|
59890
|
+
* Get its client rect and package into given `DOMRect` .
|
|
59891
|
+
*/
|
|
59892
|
+
_getClientRect(target) {
|
|
59893
|
+
if (!this._domElement)
|
|
59894
|
+
return;
|
|
59895
|
+
const rect = this._domElement.getBoundingClientRect();
|
|
59896
|
+
target.x = rect.left;
|
|
59897
|
+
target.y = rect.top;
|
|
59898
|
+
if (this._viewport) {
|
|
59899
|
+
target.x += this._viewport.x;
|
|
59900
|
+
target.y += rect.height - this._viewport.w - this._viewport.y;
|
|
59901
|
+
target.width = this._viewport.z;
|
|
59902
|
+
target.height = this._viewport.w;
|
|
59903
|
+
}
|
|
59904
|
+
else {
|
|
59905
|
+
target.width = rect.width;
|
|
59906
|
+
target.height = rect.height;
|
|
59907
|
+
}
|
|
59908
|
+
return target;
|
|
59909
|
+
}
|
|
59910
|
+
_createOnRestPromise(resolveImmediately) {
|
|
59911
|
+
if (resolveImmediately)
|
|
59912
|
+
return Promise.resolve();
|
|
59913
|
+
this._hasRested = false;
|
|
59914
|
+
this.dispatchEvent({ type: 'transitionstart' });
|
|
59915
|
+
return new Promise((resolve) => {
|
|
59916
|
+
const onResolve = () => {
|
|
59917
|
+
this.removeEventListener('rest', onResolve);
|
|
59918
|
+
resolve();
|
|
59919
|
+
};
|
|
59920
|
+
this.addEventListener('rest', onResolve);
|
|
59921
|
+
});
|
|
59922
|
+
}
|
|
59923
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
59924
|
+
_addAllEventListeners(_domElement) { }
|
|
59925
|
+
_removeAllEventListeners() { }
|
|
59926
|
+
/**
|
|
59927
|
+
* backward compatible
|
|
59928
|
+
* @deprecated use smoothTime (in seconds) instead
|
|
59929
|
+
* @category Properties
|
|
59930
|
+
*/
|
|
59931
|
+
get dampingFactor() {
|
|
59932
|
+
console.warn('.dampingFactor has been deprecated. use smoothTime (in seconds) instead.');
|
|
59933
|
+
return 0;
|
|
59934
|
+
}
|
|
59935
|
+
/**
|
|
59936
|
+
* backward compatible
|
|
59937
|
+
* @deprecated use smoothTime (in seconds) instead
|
|
59938
|
+
* @category Properties
|
|
59939
|
+
*/
|
|
59940
|
+
set dampingFactor(_) {
|
|
59941
|
+
console.warn('.dampingFactor has been deprecated. use smoothTime (in seconds) instead.');
|
|
59942
|
+
}
|
|
59943
|
+
/**
|
|
59944
|
+
* backward compatible
|
|
59945
|
+
* @deprecated use draggingSmoothTime (in seconds) instead
|
|
59946
|
+
* @category Properties
|
|
59947
|
+
*/
|
|
59948
|
+
get draggingDampingFactor() {
|
|
59949
|
+
console.warn('.draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.');
|
|
59950
|
+
return 0;
|
|
59951
|
+
}
|
|
59952
|
+
/**
|
|
59953
|
+
* backward compatible
|
|
59954
|
+
* @deprecated use draggingSmoothTime (in seconds) instead
|
|
59955
|
+
* @category Properties
|
|
59956
|
+
*/
|
|
59957
|
+
set draggingDampingFactor(_) {
|
|
59958
|
+
console.warn('.draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.');
|
|
59959
|
+
}
|
|
59960
|
+
static createBoundingSphere(object3d, out = new THREE.Sphere()) {
|
|
59961
|
+
const boundingSphere = out;
|
|
59962
|
+
const center = boundingSphere.center;
|
|
59963
|
+
_box3A.makeEmpty();
|
|
59964
|
+
// find the center
|
|
59965
|
+
object3d.traverseVisible((object) => {
|
|
59966
|
+
if (!object.isMesh)
|
|
59967
|
+
return;
|
|
59968
|
+
_box3A.expandByObject(object);
|
|
59969
|
+
});
|
|
59970
|
+
_box3A.getCenter(center);
|
|
59971
|
+
// find the radius
|
|
59972
|
+
let maxRadiusSq = 0;
|
|
59973
|
+
object3d.traverseVisible((object) => {
|
|
59974
|
+
if (!object.isMesh)
|
|
59975
|
+
return;
|
|
59976
|
+
const mesh = object;
|
|
59977
|
+
if (!mesh.geometry)
|
|
59978
|
+
return;
|
|
59979
|
+
const geometry = mesh.geometry.clone();
|
|
59980
|
+
geometry.applyMatrix4(mesh.matrixWorld);
|
|
59981
|
+
const bufferGeometry = geometry;
|
|
59982
|
+
const position = bufferGeometry.attributes.position;
|
|
59983
|
+
for (let i = 0, l = position.count; i < l; i++) {
|
|
59984
|
+
_v3A.fromBufferAttribute(position, i);
|
|
59985
|
+
maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_v3A));
|
|
59986
|
+
}
|
|
59987
|
+
});
|
|
59988
|
+
boundingSphere.radius = Math.sqrt(maxRadiusSq);
|
|
59989
|
+
return boundingSphere;
|
|
59990
|
+
}
|
|
59991
|
+
}
|
|
57536
59992
|
|
|
57537
|
-
|
|
59993
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
59994
|
+
// License, v2.0. If a copy of the MPL was not distributed with this
|
|
59995
|
+
// file, You can obtain one at http://mozilla.org/MPL/2.0/
|
|
57538
59996
|
|
|
57539
|
-
|
|
57540
|
-
|
|
57541
|
-
|
|
57542
|
-
|
|
57543
|
-
|
|
57544
|
-
|
|
57545
|
-
|
|
57546
|
-
|
|
57547
|
-
|
|
57548
|
-
|
|
57549
|
-
|
|
57550
|
-
|
|
57551
|
-
return this.object.position.distanceTo( this.target );
|
|
57552
|
-
|
|
57553
|
-
};
|
|
57554
|
-
|
|
57555
|
-
this.listenToKeyEvents = function ( domElement ) {
|
|
57556
|
-
|
|
57557
|
-
domElement.addEventListener( 'keydown', onKeyDown );
|
|
57558
|
-
this._domElementKeyEvents = domElement;
|
|
57559
|
-
|
|
57560
|
-
};
|
|
57561
|
-
|
|
57562
|
-
this.stopListenToKeyEvents = function () {
|
|
57563
|
-
|
|
57564
|
-
this._domElementKeyEvents.removeEventListener( 'keydown', onKeyDown );
|
|
57565
|
-
this._domElementKeyEvents = null;
|
|
57566
|
-
|
|
57567
|
-
};
|
|
57568
|
-
|
|
57569
|
-
this.saveState = function () {
|
|
57570
|
-
|
|
57571
|
-
scope.target0.copy( scope.target );
|
|
57572
|
-
scope.position0.copy( scope.object.position );
|
|
57573
|
-
scope.zoom0 = scope.object.zoom;
|
|
57574
|
-
|
|
57575
|
-
};
|
|
57576
|
-
|
|
57577
|
-
this.reset = function () {
|
|
57578
|
-
|
|
57579
|
-
scope.target.copy( scope.target0 );
|
|
57580
|
-
scope.object.position.copy( scope.position0 );
|
|
57581
|
-
scope.object.zoom = scope.zoom0;
|
|
57582
|
-
|
|
57583
|
-
scope.object.updateProjectionMatrix();
|
|
57584
|
-
scope.dispatchEvent( _changeEvent );
|
|
57585
|
-
|
|
57586
|
-
scope.update();
|
|
57587
|
-
|
|
57588
|
-
state = STATE.NONE;
|
|
57589
|
-
|
|
57590
|
-
};
|
|
57591
|
-
|
|
57592
|
-
// this method is exposed, but perhaps it would be better if we can make it private...
|
|
57593
|
-
this.update = function () {
|
|
57594
|
-
|
|
57595
|
-
const offset = new Vector3();
|
|
57596
|
-
|
|
57597
|
-
// so camera.up is the orbit axis
|
|
57598
|
-
const quat = new Quaternion().setFromUnitVectors( object.up, new Vector3( 0, 1, 0 ) );
|
|
57599
|
-
const quatInverse = quat.clone().invert();
|
|
57600
|
-
|
|
57601
|
-
const lastPosition = new Vector3();
|
|
57602
|
-
const lastQuaternion = new Quaternion();
|
|
57603
|
-
const lastTargetPosition = new Vector3();
|
|
57604
|
-
|
|
57605
|
-
const twoPI = 2 * Math.PI;
|
|
57606
|
-
|
|
57607
|
-
return function update( deltaTime = null ) {
|
|
57608
|
-
|
|
57609
|
-
const position = scope.object.position;
|
|
57610
|
-
|
|
57611
|
-
offset.copy( position ).sub( scope.target );
|
|
57612
|
-
|
|
57613
|
-
// rotate offset to "y-axis-is-up" space
|
|
57614
|
-
offset.applyQuaternion( quat );
|
|
57615
|
-
|
|
57616
|
-
// angle from z-axis around y-axis
|
|
57617
|
-
spherical.setFromVector3( offset );
|
|
57618
|
-
|
|
57619
|
-
if ( scope.autoRotate && state === STATE.NONE ) {
|
|
57620
|
-
|
|
57621
|
-
rotateLeft( getAutoRotationAngle( deltaTime ) );
|
|
57622
|
-
|
|
57623
|
-
}
|
|
57624
|
-
|
|
57625
|
-
if ( scope.enableDamping ) {
|
|
57626
|
-
|
|
57627
|
-
spherical.theta += sphericalDelta.theta * scope.dampingFactor;
|
|
57628
|
-
spherical.phi += sphericalDelta.phi * scope.dampingFactor;
|
|
57629
|
-
|
|
57630
|
-
} else {
|
|
57631
|
-
|
|
57632
|
-
spherical.theta += sphericalDelta.theta;
|
|
57633
|
-
spherical.phi += sphericalDelta.phi;
|
|
57634
|
-
|
|
57635
|
-
}
|
|
57636
|
-
|
|
57637
|
-
// restrict theta to be between desired limits
|
|
57638
|
-
|
|
57639
|
-
let min = scope.minAzimuthAngle;
|
|
57640
|
-
let max = scope.maxAzimuthAngle;
|
|
57641
|
-
|
|
57642
|
-
if ( isFinite( min ) && isFinite( max ) ) {
|
|
57643
|
-
|
|
57644
|
-
if ( min < - Math.PI ) min += twoPI; else if ( min > Math.PI ) min -= twoPI;
|
|
57645
|
-
|
|
57646
|
-
if ( max < - Math.PI ) max += twoPI; else if ( max > Math.PI ) max -= twoPI;
|
|
57647
|
-
|
|
57648
|
-
if ( min <= max ) {
|
|
57649
|
-
|
|
57650
|
-
spherical.theta = Math.max( min, Math.min( max, spherical.theta ) );
|
|
57651
|
-
|
|
57652
|
-
} else {
|
|
57653
|
-
|
|
57654
|
-
spherical.theta = ( spherical.theta > ( min + max ) / 2 ) ?
|
|
57655
|
-
Math.max( min, spherical.theta ) :
|
|
57656
|
-
Math.min( max, spherical.theta );
|
|
57657
|
-
|
|
57658
|
-
}
|
|
57659
|
-
|
|
57660
|
-
}
|
|
57661
|
-
|
|
57662
|
-
// restrict phi to be between desired limits
|
|
57663
|
-
spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
|
|
57664
|
-
|
|
57665
|
-
spherical.makeSafe();
|
|
57666
|
-
|
|
57667
|
-
|
|
57668
|
-
// move target to panned location
|
|
57669
|
-
|
|
57670
|
-
if ( scope.enableDamping === true ) {
|
|
57671
|
-
|
|
57672
|
-
scope.target.addScaledVector( panOffset, scope.dampingFactor );
|
|
57673
|
-
|
|
57674
|
-
} else {
|
|
57675
|
-
|
|
57676
|
-
scope.target.add( panOffset );
|
|
57677
|
-
|
|
57678
|
-
}
|
|
57679
|
-
|
|
57680
|
-
// adjust the camera position based on zoom only if we're not zooming to the cursor or if it's an ortho camera
|
|
57681
|
-
// we adjust zoom later in these cases
|
|
57682
|
-
if ( scope.zoomToCursor && performCursorZoom || scope.object.isOrthographicCamera ) {
|
|
57683
|
-
|
|
57684
|
-
spherical.radius = clampDistance( spherical.radius );
|
|
57685
|
-
|
|
57686
|
-
} else {
|
|
57687
|
-
|
|
57688
|
-
spherical.radius = clampDistance( spherical.radius * scale );
|
|
57689
|
-
|
|
57690
|
-
}
|
|
57691
|
-
|
|
57692
|
-
|
|
57693
|
-
offset.setFromSpherical( spherical );
|
|
57694
|
-
|
|
57695
|
-
// rotate offset back to "camera-up-vector-is-up" space
|
|
57696
|
-
offset.applyQuaternion( quatInverse );
|
|
57697
|
-
|
|
57698
|
-
position.copy( scope.target ).add( offset );
|
|
57699
|
-
|
|
57700
|
-
scope.object.lookAt( scope.target );
|
|
57701
|
-
|
|
57702
|
-
if ( scope.enableDamping === true ) {
|
|
57703
|
-
|
|
57704
|
-
sphericalDelta.theta *= ( 1 - scope.dampingFactor );
|
|
57705
|
-
sphericalDelta.phi *= ( 1 - scope.dampingFactor );
|
|
57706
|
-
|
|
57707
|
-
panOffset.multiplyScalar( 1 - scope.dampingFactor );
|
|
57708
|
-
|
|
57709
|
-
} else {
|
|
57710
|
-
|
|
57711
|
-
sphericalDelta.set( 0, 0, 0 );
|
|
57712
|
-
|
|
57713
|
-
panOffset.set( 0, 0, 0 );
|
|
57714
|
-
|
|
57715
|
-
}
|
|
57716
|
-
|
|
57717
|
-
// adjust camera position
|
|
57718
|
-
let zoomChanged = false;
|
|
57719
|
-
if ( scope.zoomToCursor && performCursorZoom ) {
|
|
57720
|
-
|
|
57721
|
-
let newRadius = null;
|
|
57722
|
-
if ( scope.object.isPerspectiveCamera ) {
|
|
57723
|
-
|
|
57724
|
-
// move the camera down the pointer ray
|
|
57725
|
-
// this method avoids floating point error
|
|
57726
|
-
const prevRadius = offset.length();
|
|
57727
|
-
newRadius = clampDistance( prevRadius * scale );
|
|
57728
|
-
|
|
57729
|
-
const radiusDelta = prevRadius - newRadius;
|
|
57730
|
-
scope.object.position.addScaledVector( dollyDirection, radiusDelta );
|
|
57731
|
-
scope.object.updateMatrixWorld();
|
|
57732
|
-
|
|
57733
|
-
} else if ( scope.object.isOrthographicCamera ) {
|
|
57734
|
-
|
|
57735
|
-
// adjust the ortho camera position based on zoom changes
|
|
57736
|
-
const mouseBefore = new Vector3( mouse.x, mouse.y, 0 );
|
|
57737
|
-
mouseBefore.unproject( scope.object );
|
|
57738
|
-
|
|
57739
|
-
scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / scale ) );
|
|
57740
|
-
scope.object.updateProjectionMatrix();
|
|
57741
|
-
zoomChanged = true;
|
|
57742
|
-
|
|
57743
|
-
const mouseAfter = new Vector3( mouse.x, mouse.y, 0 );
|
|
57744
|
-
mouseAfter.unproject( scope.object );
|
|
57745
|
-
|
|
57746
|
-
scope.object.position.sub( mouseAfter ).add( mouseBefore );
|
|
57747
|
-
scope.object.updateMatrixWorld();
|
|
57748
|
-
|
|
57749
|
-
newRadius = offset.length();
|
|
57750
|
-
|
|
57751
|
-
} else {
|
|
57752
|
-
|
|
57753
|
-
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.' );
|
|
57754
|
-
scope.zoomToCursor = false;
|
|
57755
|
-
|
|
57756
|
-
}
|
|
57757
|
-
|
|
57758
|
-
// handle the placement of the target
|
|
57759
|
-
if ( newRadius !== null ) {
|
|
57760
|
-
|
|
57761
|
-
if ( this.screenSpacePanning ) {
|
|
57762
|
-
|
|
57763
|
-
// position the orbit target in front of the new camera position
|
|
57764
|
-
scope.target.set( 0, 0, - 1 )
|
|
57765
|
-
.transformDirection( scope.object.matrix )
|
|
57766
|
-
.multiplyScalar( newRadius )
|
|
57767
|
-
.add( scope.object.position );
|
|
57768
|
-
|
|
57769
|
-
} else {
|
|
57770
|
-
|
|
57771
|
-
// get the ray and translation plane to compute target
|
|
57772
|
-
_ray.origin.copy( scope.object.position );
|
|
57773
|
-
_ray.direction.set( 0, 0, - 1 ).transformDirection( scope.object.matrix );
|
|
57774
|
-
|
|
57775
|
-
// if the camera is 20 degrees above the horizon then don't adjust the focus target to avoid
|
|
57776
|
-
// extremely large values
|
|
57777
|
-
if ( Math.abs( scope.object.up.dot( _ray.direction ) ) < TILT_LIMIT ) {
|
|
57778
|
-
|
|
57779
|
-
object.lookAt( scope.target );
|
|
57780
|
-
|
|
57781
|
-
} else {
|
|
57782
|
-
|
|
57783
|
-
_plane.setFromNormalAndCoplanarPoint( scope.object.up, scope.target );
|
|
57784
|
-
_ray.intersectPlane( _plane, scope.target );
|
|
57785
|
-
|
|
57786
|
-
}
|
|
57787
|
-
|
|
57788
|
-
}
|
|
57789
|
-
|
|
57790
|
-
}
|
|
57791
|
-
|
|
57792
|
-
} else if ( scope.object.isOrthographicCamera ) {
|
|
57793
|
-
|
|
57794
|
-
scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / scale ) );
|
|
57795
|
-
scope.object.updateProjectionMatrix();
|
|
57796
|
-
zoomChanged = true;
|
|
57797
|
-
|
|
57798
|
-
}
|
|
57799
|
-
|
|
57800
|
-
scale = 1;
|
|
57801
|
-
performCursorZoom = false;
|
|
57802
|
-
|
|
57803
|
-
// update condition is:
|
|
57804
|
-
// min(camera displacement, camera rotation in radians)^2 > EPS
|
|
57805
|
-
// using small-angle approximation cos(x/2) = 1 - x^2 / 8
|
|
57806
|
-
|
|
57807
|
-
if ( zoomChanged ||
|
|
57808
|
-
lastPosition.distanceToSquared( scope.object.position ) > EPS ||
|
|
57809
|
-
8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ||
|
|
57810
|
-
lastTargetPosition.distanceToSquared( scope.target ) > 0 ) {
|
|
57811
|
-
|
|
57812
|
-
scope.dispatchEvent( _changeEvent );
|
|
57813
|
-
|
|
57814
|
-
lastPosition.copy( scope.object.position );
|
|
57815
|
-
lastQuaternion.copy( scope.object.quaternion );
|
|
57816
|
-
lastTargetPosition.copy( scope.target );
|
|
57817
|
-
|
|
57818
|
-
zoomChanged = false;
|
|
57819
|
-
|
|
57820
|
-
return true;
|
|
57821
|
-
|
|
57822
|
-
}
|
|
57823
|
-
|
|
57824
|
-
return false;
|
|
57825
|
-
|
|
57826
|
-
};
|
|
57827
|
-
|
|
57828
|
-
}();
|
|
57829
|
-
|
|
57830
|
-
this.dispose = function () {
|
|
57831
|
-
|
|
57832
|
-
scope.domElement.removeEventListener( 'contextmenu', onContextMenu );
|
|
57833
|
-
|
|
57834
|
-
scope.domElement.removeEventListener( 'pointerdown', onPointerDown );
|
|
57835
|
-
scope.domElement.removeEventListener( 'pointercancel', onPointerUp );
|
|
57836
|
-
scope.domElement.removeEventListener( 'wheel', onMouseWheel );
|
|
57837
|
-
|
|
57838
|
-
scope.domElement.removeEventListener( 'pointermove', onPointerMove );
|
|
57839
|
-
scope.domElement.removeEventListener( 'pointerup', onPointerUp );
|
|
57840
|
-
|
|
57841
|
-
|
|
57842
|
-
if ( scope._domElementKeyEvents !== null ) {
|
|
57843
|
-
|
|
57844
|
-
scope._domElementKeyEvents.removeEventListener( 'keydown', onKeyDown );
|
|
57845
|
-
scope._domElementKeyEvents = null;
|
|
57846
|
-
|
|
57847
|
-
}
|
|
57848
|
-
|
|
57849
|
-
//scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
|
|
57850
|
-
|
|
57851
|
-
};
|
|
57852
|
-
|
|
57853
|
-
//
|
|
57854
|
-
// internals
|
|
57855
|
-
//
|
|
57856
|
-
|
|
57857
|
-
const scope = this;
|
|
57858
|
-
|
|
57859
|
-
const STATE = {
|
|
57860
|
-
NONE: - 1,
|
|
57861
|
-
ROTATE: 0,
|
|
57862
|
-
DOLLY: 1,
|
|
57863
|
-
PAN: 2,
|
|
57864
|
-
TOUCH_ROTATE: 3,
|
|
57865
|
-
TOUCH_PAN: 4,
|
|
57866
|
-
TOUCH_DOLLY_PAN: 5,
|
|
57867
|
-
TOUCH_DOLLY_ROTATE: 6
|
|
57868
|
-
};
|
|
57869
|
-
|
|
57870
|
-
let state = STATE.NONE;
|
|
57871
|
-
|
|
57872
|
-
const EPS = 0.000001;
|
|
57873
|
-
|
|
57874
|
-
// current position in spherical coordinates
|
|
57875
|
-
const spherical = new Spherical();
|
|
57876
|
-
const sphericalDelta = new Spherical();
|
|
57877
|
-
|
|
57878
|
-
let scale = 1;
|
|
57879
|
-
const panOffset = new Vector3();
|
|
57880
|
-
|
|
57881
|
-
const rotateStart = new Vector2();
|
|
57882
|
-
const rotateEnd = new Vector2();
|
|
57883
|
-
const rotateDelta = new Vector2();
|
|
57884
|
-
|
|
57885
|
-
const panStart = new Vector2();
|
|
57886
|
-
const panEnd = new Vector2();
|
|
57887
|
-
const panDelta = new Vector2();
|
|
57888
|
-
|
|
57889
|
-
const dollyStart = new Vector2();
|
|
57890
|
-
const dollyEnd = new Vector2();
|
|
57891
|
-
const dollyDelta = new Vector2();
|
|
57892
|
-
|
|
57893
|
-
const dollyDirection = new Vector3();
|
|
57894
|
-
const mouse = new Vector2();
|
|
57895
|
-
let performCursorZoom = false;
|
|
57896
|
-
|
|
57897
|
-
const pointers = [];
|
|
57898
|
-
const pointerPositions = {};
|
|
57899
|
-
|
|
57900
|
-
function getAutoRotationAngle( deltaTime ) {
|
|
57901
|
-
|
|
57902
|
-
if ( deltaTime !== null ) {
|
|
57903
|
-
|
|
57904
|
-
return ( 2 * Math.PI / 60 * scope.autoRotateSpeed ) * deltaTime;
|
|
57905
|
-
|
|
57906
|
-
} else {
|
|
57907
|
-
|
|
57908
|
-
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
|
57909
|
-
|
|
57910
|
-
}
|
|
57911
|
-
|
|
57912
|
-
}
|
|
57913
|
-
|
|
57914
|
-
function getZoomScale() {
|
|
57915
|
-
|
|
57916
|
-
return Math.pow( 0.95, scope.zoomSpeed );
|
|
57917
|
-
|
|
57918
|
-
}
|
|
57919
|
-
|
|
57920
|
-
function rotateLeft( angle ) {
|
|
57921
|
-
|
|
57922
|
-
sphericalDelta.theta -= angle;
|
|
57923
|
-
|
|
57924
|
-
}
|
|
57925
|
-
|
|
57926
|
-
function rotateUp( angle ) {
|
|
57927
|
-
|
|
57928
|
-
sphericalDelta.phi -= angle;
|
|
57929
|
-
|
|
57930
|
-
}
|
|
57931
|
-
|
|
57932
|
-
const panLeft = function () {
|
|
57933
|
-
|
|
57934
|
-
const v = new Vector3();
|
|
57935
|
-
|
|
57936
|
-
return function panLeft( distance, objectMatrix ) {
|
|
57937
|
-
|
|
57938
|
-
v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
|
|
57939
|
-
v.multiplyScalar( - distance );
|
|
57940
|
-
|
|
57941
|
-
panOffset.add( v );
|
|
57942
|
-
|
|
57943
|
-
};
|
|
57944
|
-
|
|
57945
|
-
}();
|
|
57946
|
-
|
|
57947
|
-
const panUp = function () {
|
|
57948
|
-
|
|
57949
|
-
const v = new Vector3();
|
|
57950
|
-
|
|
57951
|
-
return function panUp( distance, objectMatrix ) {
|
|
57952
|
-
|
|
57953
|
-
if ( scope.screenSpacePanning === true ) {
|
|
57954
|
-
|
|
57955
|
-
v.setFromMatrixColumn( objectMatrix, 1 );
|
|
57956
|
-
|
|
57957
|
-
} else {
|
|
57958
|
-
|
|
57959
|
-
v.setFromMatrixColumn( objectMatrix, 0 );
|
|
57960
|
-
v.crossVectors( scope.object.up, v );
|
|
57961
|
-
|
|
57962
|
-
}
|
|
57963
|
-
|
|
57964
|
-
v.multiplyScalar( distance );
|
|
57965
|
-
|
|
57966
|
-
panOffset.add( v );
|
|
57967
|
-
|
|
57968
|
-
};
|
|
57969
|
-
|
|
57970
|
-
}();
|
|
57971
|
-
|
|
57972
|
-
// deltaX and deltaY are in pixels; right and down are positive
|
|
57973
|
-
const pan = function () {
|
|
57974
|
-
|
|
57975
|
-
const offset = new Vector3();
|
|
57976
|
-
|
|
57977
|
-
return function pan( deltaX, deltaY ) {
|
|
57978
|
-
|
|
57979
|
-
const element = scope.domElement;
|
|
57980
|
-
|
|
57981
|
-
if ( scope.object.isPerspectiveCamera ) {
|
|
57982
|
-
|
|
57983
|
-
// perspective
|
|
57984
|
-
const position = scope.object.position;
|
|
57985
|
-
offset.copy( position ).sub( scope.target );
|
|
57986
|
-
let targetDistance = offset.length();
|
|
57987
|
-
|
|
57988
|
-
// half of the fov is center to top of screen
|
|
57989
|
-
targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
|
|
57990
|
-
|
|
57991
|
-
// we use only clientHeight here so aspect ratio does not distort speed
|
|
57992
|
-
panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix );
|
|
57993
|
-
panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix );
|
|
57994
|
-
|
|
57995
|
-
} else if ( scope.object.isOrthographicCamera ) {
|
|
57996
|
-
|
|
57997
|
-
// orthographic
|
|
57998
|
-
panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom / element.clientWidth, scope.object.matrix );
|
|
57999
|
-
panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom / element.clientHeight, scope.object.matrix );
|
|
58000
|
-
|
|
58001
|
-
} else {
|
|
58002
|
-
|
|
58003
|
-
// camera neither orthographic nor perspective
|
|
58004
|
-
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
|
|
58005
|
-
scope.enablePan = false;
|
|
58006
|
-
|
|
58007
|
-
}
|
|
58008
|
-
|
|
58009
|
-
};
|
|
58010
|
-
|
|
58011
|
-
}();
|
|
58012
|
-
|
|
58013
|
-
function dollyOut( dollyScale ) {
|
|
58014
|
-
|
|
58015
|
-
if ( scope.object.isPerspectiveCamera || scope.object.isOrthographicCamera ) {
|
|
58016
|
-
|
|
58017
|
-
scale /= dollyScale;
|
|
58018
|
-
|
|
58019
|
-
} else {
|
|
58020
|
-
|
|
58021
|
-
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
|
|
58022
|
-
scope.enableZoom = false;
|
|
58023
|
-
|
|
58024
|
-
}
|
|
58025
|
-
|
|
58026
|
-
}
|
|
58027
|
-
|
|
58028
|
-
function dollyIn( dollyScale ) {
|
|
58029
|
-
|
|
58030
|
-
if ( scope.object.isPerspectiveCamera || scope.object.isOrthographicCamera ) {
|
|
58031
|
-
|
|
58032
|
-
scale *= dollyScale;
|
|
58033
|
-
|
|
58034
|
-
} else {
|
|
58035
|
-
|
|
58036
|
-
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
|
|
58037
|
-
scope.enableZoom = false;
|
|
58038
|
-
|
|
58039
|
-
}
|
|
58040
|
-
|
|
58041
|
-
}
|
|
58042
|
-
|
|
58043
|
-
function updateMouseParameters( event ) {
|
|
58044
|
-
|
|
58045
|
-
if ( ! scope.zoomToCursor ) {
|
|
58046
|
-
|
|
58047
|
-
return;
|
|
58048
|
-
|
|
58049
|
-
}
|
|
58050
|
-
|
|
58051
|
-
performCursorZoom = true;
|
|
58052
|
-
|
|
58053
|
-
const rect = scope.domElement.getBoundingClientRect();
|
|
58054
|
-
const x = event.clientX - rect.left;
|
|
58055
|
-
const y = event.clientY - rect.top;
|
|
58056
|
-
const w = rect.width;
|
|
58057
|
-
const h = rect.height;
|
|
58058
|
-
|
|
58059
|
-
mouse.x = ( x / w ) * 2 - 1;
|
|
58060
|
-
mouse.y = - ( y / h ) * 2 + 1;
|
|
58061
|
-
|
|
58062
|
-
dollyDirection.set( mouse.x, mouse.y, 1 ).unproject( scope.object ).sub( scope.object.position ).normalize();
|
|
58063
|
-
|
|
58064
|
-
}
|
|
58065
|
-
|
|
58066
|
-
function clampDistance( dist ) {
|
|
58067
|
-
|
|
58068
|
-
return Math.max( scope.minDistance, Math.min( scope.maxDistance, dist ) );
|
|
58069
|
-
|
|
58070
|
-
}
|
|
58071
|
-
|
|
58072
|
-
//
|
|
58073
|
-
// event callbacks - update the object state
|
|
58074
|
-
//
|
|
58075
|
-
|
|
58076
|
-
function handleMouseDownRotate( event ) {
|
|
58077
|
-
|
|
58078
|
-
rotateStart.set( event.clientX, event.clientY );
|
|
58079
|
-
|
|
58080
|
-
}
|
|
58081
|
-
|
|
58082
|
-
function handleMouseDownDolly( event ) {
|
|
58083
|
-
|
|
58084
|
-
updateMouseParameters( event );
|
|
58085
|
-
dollyStart.set( event.clientX, event.clientY );
|
|
58086
|
-
|
|
58087
|
-
}
|
|
58088
|
-
|
|
58089
|
-
function handleMouseDownPan( event ) {
|
|
58090
|
-
|
|
58091
|
-
panStart.set( event.clientX, event.clientY );
|
|
58092
|
-
|
|
58093
|
-
}
|
|
58094
|
-
|
|
58095
|
-
function handleMouseMoveRotate( event ) {
|
|
58096
|
-
|
|
58097
|
-
rotateEnd.set( event.clientX, event.clientY );
|
|
58098
|
-
|
|
58099
|
-
rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
|
|
58100
|
-
|
|
58101
|
-
const element = scope.domElement;
|
|
58102
|
-
|
|
58103
|
-
rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientHeight ); // yes, height
|
|
58104
|
-
|
|
58105
|
-
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
|
|
58106
|
-
|
|
58107
|
-
rotateStart.copy( rotateEnd );
|
|
58108
|
-
|
|
58109
|
-
scope.update();
|
|
58110
|
-
|
|
58111
|
-
}
|
|
58112
|
-
|
|
58113
|
-
function handleMouseMoveDolly( event ) {
|
|
58114
|
-
|
|
58115
|
-
dollyEnd.set( event.clientX, event.clientY );
|
|
58116
|
-
|
|
58117
|
-
dollyDelta.subVectors( dollyEnd, dollyStart );
|
|
58118
|
-
|
|
58119
|
-
if ( dollyDelta.y > 0 ) {
|
|
58120
|
-
|
|
58121
|
-
dollyOut( getZoomScale() );
|
|
58122
|
-
|
|
58123
|
-
} else if ( dollyDelta.y < 0 ) {
|
|
58124
|
-
|
|
58125
|
-
dollyIn( getZoomScale() );
|
|
58126
|
-
|
|
58127
|
-
}
|
|
58128
|
-
|
|
58129
|
-
dollyStart.copy( dollyEnd );
|
|
58130
|
-
|
|
58131
|
-
scope.update();
|
|
58132
|
-
|
|
58133
|
-
}
|
|
58134
|
-
|
|
58135
|
-
function handleMouseMovePan( event ) {
|
|
58136
|
-
|
|
58137
|
-
panEnd.set( event.clientX, event.clientY );
|
|
58138
|
-
|
|
58139
|
-
panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
|
|
58140
|
-
|
|
58141
|
-
pan( panDelta.x, panDelta.y );
|
|
58142
|
-
|
|
58143
|
-
panStart.copy( panEnd );
|
|
58144
|
-
|
|
58145
|
-
scope.update();
|
|
58146
|
-
|
|
58147
|
-
}
|
|
58148
|
-
|
|
58149
|
-
function handleMouseWheel( event ) {
|
|
58150
|
-
|
|
58151
|
-
updateMouseParameters( event );
|
|
58152
|
-
|
|
58153
|
-
if ( event.deltaY < 0 ) {
|
|
58154
|
-
|
|
58155
|
-
dollyIn( getZoomScale() );
|
|
58156
|
-
|
|
58157
|
-
} else if ( event.deltaY > 0 ) {
|
|
58158
|
-
|
|
58159
|
-
dollyOut( getZoomScale() );
|
|
58160
|
-
|
|
58161
|
-
}
|
|
58162
|
-
|
|
58163
|
-
scope.update();
|
|
58164
|
-
|
|
58165
|
-
}
|
|
58166
|
-
|
|
58167
|
-
function handleKeyDown( event ) {
|
|
58168
|
-
|
|
58169
|
-
let needsUpdate = false;
|
|
58170
|
-
|
|
58171
|
-
switch ( event.code ) {
|
|
58172
|
-
|
|
58173
|
-
case scope.keys.UP:
|
|
58174
|
-
|
|
58175
|
-
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
58176
|
-
|
|
58177
|
-
rotateUp( 2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight );
|
|
58178
|
-
|
|
58179
|
-
} else {
|
|
58180
|
-
|
|
58181
|
-
pan( 0, scope.keyPanSpeed );
|
|
58182
|
-
|
|
58183
|
-
}
|
|
58184
|
-
|
|
58185
|
-
needsUpdate = true;
|
|
58186
|
-
break;
|
|
58187
|
-
|
|
58188
|
-
case scope.keys.BOTTOM:
|
|
58189
|
-
|
|
58190
|
-
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
58191
|
-
|
|
58192
|
-
rotateUp( - 2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight );
|
|
58193
|
-
|
|
58194
|
-
} else {
|
|
58195
|
-
|
|
58196
|
-
pan( 0, - scope.keyPanSpeed );
|
|
58197
|
-
|
|
58198
|
-
}
|
|
58199
|
-
|
|
58200
|
-
needsUpdate = true;
|
|
58201
|
-
break;
|
|
58202
|
-
|
|
58203
|
-
case scope.keys.LEFT:
|
|
58204
|
-
|
|
58205
|
-
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
58206
|
-
|
|
58207
|
-
rotateLeft( 2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight );
|
|
58208
|
-
|
|
58209
|
-
} else {
|
|
58210
|
-
|
|
58211
|
-
pan( scope.keyPanSpeed, 0 );
|
|
58212
|
-
|
|
58213
|
-
}
|
|
58214
|
-
|
|
58215
|
-
needsUpdate = true;
|
|
58216
|
-
break;
|
|
58217
|
-
|
|
58218
|
-
case scope.keys.RIGHT:
|
|
58219
|
-
|
|
58220
|
-
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
58221
|
-
|
|
58222
|
-
rotateLeft( - 2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight );
|
|
58223
|
-
|
|
58224
|
-
} else {
|
|
58225
|
-
|
|
58226
|
-
pan( - scope.keyPanSpeed, 0 );
|
|
58227
|
-
|
|
58228
|
-
}
|
|
58229
|
-
|
|
58230
|
-
needsUpdate = true;
|
|
58231
|
-
break;
|
|
58232
|
-
|
|
58233
|
-
}
|
|
58234
|
-
|
|
58235
|
-
if ( needsUpdate ) {
|
|
58236
|
-
|
|
58237
|
-
// prevent the browser from scrolling on cursor keys
|
|
58238
|
-
event.preventDefault();
|
|
58239
|
-
|
|
58240
|
-
scope.update();
|
|
58241
|
-
|
|
58242
|
-
}
|
|
58243
|
-
|
|
58244
|
-
|
|
58245
|
-
}
|
|
58246
|
-
|
|
58247
|
-
function handleTouchStartRotate() {
|
|
58248
|
-
|
|
58249
|
-
if ( pointers.length === 1 ) {
|
|
58250
|
-
|
|
58251
|
-
rotateStart.set( pointers[ 0 ].pageX, pointers[ 0 ].pageY );
|
|
58252
|
-
|
|
58253
|
-
} else {
|
|
58254
|
-
|
|
58255
|
-
const x = 0.5 * ( pointers[ 0 ].pageX + pointers[ 1 ].pageX );
|
|
58256
|
-
const y = 0.5 * ( pointers[ 0 ].pageY + pointers[ 1 ].pageY );
|
|
58257
|
-
|
|
58258
|
-
rotateStart.set( x, y );
|
|
58259
|
-
|
|
58260
|
-
}
|
|
58261
|
-
|
|
58262
|
-
}
|
|
58263
|
-
|
|
58264
|
-
function handleTouchStartPan() {
|
|
58265
|
-
|
|
58266
|
-
if ( pointers.length === 1 ) {
|
|
58267
|
-
|
|
58268
|
-
panStart.set( pointers[ 0 ].pageX, pointers[ 0 ].pageY );
|
|
58269
|
-
|
|
58270
|
-
} else {
|
|
58271
|
-
|
|
58272
|
-
const x = 0.5 * ( pointers[ 0 ].pageX + pointers[ 1 ].pageX );
|
|
58273
|
-
const y = 0.5 * ( pointers[ 0 ].pageY + pointers[ 1 ].pageY );
|
|
58274
|
-
|
|
58275
|
-
panStart.set( x, y );
|
|
58276
|
-
|
|
58277
|
-
}
|
|
58278
|
-
|
|
58279
|
-
}
|
|
58280
|
-
|
|
58281
|
-
function handleTouchStartDolly() {
|
|
58282
|
-
|
|
58283
|
-
const dx = pointers[ 0 ].pageX - pointers[ 1 ].pageX;
|
|
58284
|
-
const dy = pointers[ 0 ].pageY - pointers[ 1 ].pageY;
|
|
58285
|
-
|
|
58286
|
-
const distance = Math.sqrt( dx * dx + dy * dy );
|
|
58287
|
-
|
|
58288
|
-
dollyStart.set( 0, distance );
|
|
58289
|
-
|
|
58290
|
-
}
|
|
58291
|
-
|
|
58292
|
-
function handleTouchStartDollyPan() {
|
|
58293
|
-
|
|
58294
|
-
if ( scope.enableZoom ) handleTouchStartDolly();
|
|
58295
|
-
|
|
58296
|
-
if ( scope.enablePan ) handleTouchStartPan();
|
|
58297
|
-
|
|
58298
|
-
}
|
|
58299
|
-
|
|
58300
|
-
function handleTouchStartDollyRotate() {
|
|
58301
|
-
|
|
58302
|
-
if ( scope.enableZoom ) handleTouchStartDolly();
|
|
58303
|
-
|
|
58304
|
-
if ( scope.enableRotate ) handleTouchStartRotate();
|
|
58305
|
-
|
|
58306
|
-
}
|
|
58307
|
-
|
|
58308
|
-
function handleTouchMoveRotate( event ) {
|
|
58309
|
-
|
|
58310
|
-
if ( pointers.length == 1 ) {
|
|
58311
|
-
|
|
58312
|
-
rotateEnd.set( event.pageX, event.pageY );
|
|
58313
|
-
|
|
58314
|
-
} else {
|
|
58315
|
-
|
|
58316
|
-
const position = getSecondPointerPosition( event );
|
|
58317
|
-
|
|
58318
|
-
const x = 0.5 * ( event.pageX + position.x );
|
|
58319
|
-
const y = 0.5 * ( event.pageY + position.y );
|
|
58320
|
-
|
|
58321
|
-
rotateEnd.set( x, y );
|
|
58322
|
-
|
|
58323
|
-
}
|
|
58324
|
-
|
|
58325
|
-
rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
|
|
58326
|
-
|
|
58327
|
-
const element = scope.domElement;
|
|
58328
|
-
|
|
58329
|
-
rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientHeight ); // yes, height
|
|
58330
|
-
|
|
58331
|
-
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
|
|
58332
|
-
|
|
58333
|
-
rotateStart.copy( rotateEnd );
|
|
58334
|
-
|
|
58335
|
-
}
|
|
58336
|
-
|
|
58337
|
-
function handleTouchMovePan( event ) {
|
|
58338
|
-
|
|
58339
|
-
if ( pointers.length === 1 ) {
|
|
58340
|
-
|
|
58341
|
-
panEnd.set( event.pageX, event.pageY );
|
|
58342
|
-
|
|
58343
|
-
} else {
|
|
58344
|
-
|
|
58345
|
-
const position = getSecondPointerPosition( event );
|
|
58346
|
-
|
|
58347
|
-
const x = 0.5 * ( event.pageX + position.x );
|
|
58348
|
-
const y = 0.5 * ( event.pageY + position.y );
|
|
58349
|
-
|
|
58350
|
-
panEnd.set( x, y );
|
|
58351
|
-
|
|
58352
|
-
}
|
|
58353
|
-
|
|
58354
|
-
panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
|
|
58355
|
-
|
|
58356
|
-
pan( panDelta.x, panDelta.y );
|
|
58357
|
-
|
|
58358
|
-
panStart.copy( panEnd );
|
|
58359
|
-
|
|
58360
|
-
}
|
|
58361
|
-
|
|
58362
|
-
function handleTouchMoveDolly( event ) {
|
|
58363
|
-
|
|
58364
|
-
const position = getSecondPointerPosition( event );
|
|
58365
|
-
|
|
58366
|
-
const dx = event.pageX - position.x;
|
|
58367
|
-
const dy = event.pageY - position.y;
|
|
58368
|
-
|
|
58369
|
-
const distance = Math.sqrt( dx * dx + dy * dy );
|
|
58370
|
-
|
|
58371
|
-
dollyEnd.set( 0, distance );
|
|
58372
|
-
|
|
58373
|
-
dollyDelta.set( 0, Math.pow( dollyEnd.y / dollyStart.y, scope.zoomSpeed ) );
|
|
58374
|
-
|
|
58375
|
-
dollyOut( dollyDelta.y );
|
|
58376
|
-
|
|
58377
|
-
dollyStart.copy( dollyEnd );
|
|
58378
|
-
|
|
58379
|
-
}
|
|
58380
|
-
|
|
58381
|
-
function handleTouchMoveDollyPan( event ) {
|
|
58382
|
-
|
|
58383
|
-
if ( scope.enableZoom ) handleTouchMoveDolly( event );
|
|
58384
|
-
|
|
58385
|
-
if ( scope.enablePan ) handleTouchMovePan( event );
|
|
58386
|
-
|
|
58387
|
-
}
|
|
58388
|
-
|
|
58389
|
-
function handleTouchMoveDollyRotate( event ) {
|
|
58390
|
-
|
|
58391
|
-
if ( scope.enableZoom ) handleTouchMoveDolly( event );
|
|
58392
|
-
|
|
58393
|
-
if ( scope.enableRotate ) handleTouchMoveRotate( event );
|
|
58394
|
-
|
|
58395
|
-
}
|
|
58396
|
-
|
|
58397
|
-
//
|
|
58398
|
-
// event handlers - FSM: listen for events and reset state
|
|
58399
|
-
//
|
|
58400
|
-
|
|
58401
|
-
function onPointerDown( event ) {
|
|
58402
|
-
|
|
58403
|
-
if ( scope.enabled === false ) return;
|
|
58404
|
-
|
|
58405
|
-
if ( pointers.length === 0 ) {
|
|
58406
|
-
|
|
58407
|
-
scope.domElement.setPointerCapture( event.pointerId );
|
|
58408
|
-
|
|
58409
|
-
scope.domElement.addEventListener( 'pointermove', onPointerMove );
|
|
58410
|
-
scope.domElement.addEventListener( 'pointerup', onPointerUp );
|
|
58411
|
-
|
|
58412
|
-
}
|
|
58413
|
-
|
|
58414
|
-
//
|
|
58415
|
-
|
|
58416
|
-
addPointer( event );
|
|
58417
|
-
|
|
58418
|
-
if ( event.pointerType === 'touch' ) {
|
|
58419
|
-
|
|
58420
|
-
onTouchStart( event );
|
|
58421
|
-
|
|
58422
|
-
} else {
|
|
58423
|
-
|
|
58424
|
-
onMouseDown( event );
|
|
58425
|
-
|
|
58426
|
-
}
|
|
58427
|
-
|
|
58428
|
-
}
|
|
58429
|
-
|
|
58430
|
-
function onPointerMove( event ) {
|
|
58431
|
-
|
|
58432
|
-
if ( scope.enabled === false ) return;
|
|
58433
|
-
|
|
58434
|
-
if ( event.pointerType === 'touch' ) {
|
|
58435
|
-
|
|
58436
|
-
onTouchMove( event );
|
|
58437
|
-
|
|
58438
|
-
} else {
|
|
58439
|
-
|
|
58440
|
-
onMouseMove( event );
|
|
58441
|
-
|
|
58442
|
-
}
|
|
58443
|
-
|
|
58444
|
-
}
|
|
58445
|
-
|
|
58446
|
-
function onPointerUp( event ) {
|
|
58447
|
-
|
|
58448
|
-
removePointer( event );
|
|
58449
|
-
|
|
58450
|
-
if ( pointers.length === 0 ) {
|
|
58451
|
-
|
|
58452
|
-
scope.domElement.releasePointerCapture( event.pointerId );
|
|
58453
|
-
|
|
58454
|
-
scope.domElement.removeEventListener( 'pointermove', onPointerMove );
|
|
58455
|
-
scope.domElement.removeEventListener( 'pointerup', onPointerUp );
|
|
58456
|
-
|
|
58457
|
-
}
|
|
58458
|
-
|
|
58459
|
-
scope.dispatchEvent( _endEvent );
|
|
58460
|
-
|
|
58461
|
-
state = STATE.NONE;
|
|
58462
|
-
|
|
58463
|
-
}
|
|
58464
|
-
|
|
58465
|
-
function onMouseDown( event ) {
|
|
58466
|
-
|
|
58467
|
-
let mouseAction;
|
|
58468
|
-
|
|
58469
|
-
switch ( event.button ) {
|
|
58470
|
-
|
|
58471
|
-
case 0:
|
|
58472
|
-
|
|
58473
|
-
mouseAction = scope.mouseButtons.LEFT;
|
|
58474
|
-
break;
|
|
58475
|
-
|
|
58476
|
-
case 1:
|
|
58477
|
-
|
|
58478
|
-
mouseAction = scope.mouseButtons.MIDDLE;
|
|
58479
|
-
break;
|
|
58480
|
-
|
|
58481
|
-
case 2:
|
|
58482
|
-
|
|
58483
|
-
mouseAction = scope.mouseButtons.RIGHT;
|
|
58484
|
-
break;
|
|
58485
|
-
|
|
58486
|
-
default:
|
|
58487
|
-
|
|
58488
|
-
mouseAction = - 1;
|
|
58489
|
-
|
|
58490
|
-
}
|
|
58491
|
-
|
|
58492
|
-
switch ( mouseAction ) {
|
|
58493
|
-
|
|
58494
|
-
case MOUSE.DOLLY:
|
|
58495
|
-
|
|
58496
|
-
if ( scope.enableZoom === false ) return;
|
|
58497
|
-
|
|
58498
|
-
handleMouseDownDolly( event );
|
|
58499
|
-
|
|
58500
|
-
state = STATE.DOLLY;
|
|
58501
|
-
|
|
58502
|
-
break;
|
|
58503
|
-
|
|
58504
|
-
case MOUSE.ROTATE:
|
|
58505
|
-
|
|
58506
|
-
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
58507
|
-
|
|
58508
|
-
if ( scope.enablePan === false ) return;
|
|
58509
|
-
|
|
58510
|
-
handleMouseDownPan( event );
|
|
58511
|
-
|
|
58512
|
-
state = STATE.PAN;
|
|
58513
|
-
|
|
58514
|
-
} else {
|
|
58515
|
-
|
|
58516
|
-
if ( scope.enableRotate === false ) return;
|
|
58517
|
-
|
|
58518
|
-
handleMouseDownRotate( event );
|
|
58519
|
-
|
|
58520
|
-
state = STATE.ROTATE;
|
|
58521
|
-
|
|
58522
|
-
}
|
|
58523
|
-
|
|
58524
|
-
break;
|
|
58525
|
-
|
|
58526
|
-
case MOUSE.PAN:
|
|
58527
|
-
|
|
58528
|
-
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
58529
|
-
|
|
58530
|
-
if ( scope.enableRotate === false ) return;
|
|
58531
|
-
|
|
58532
|
-
handleMouseDownRotate( event );
|
|
58533
|
-
|
|
58534
|
-
state = STATE.ROTATE;
|
|
58535
|
-
|
|
58536
|
-
} else {
|
|
58537
|
-
|
|
58538
|
-
if ( scope.enablePan === false ) return;
|
|
58539
|
-
|
|
58540
|
-
handleMouseDownPan( event );
|
|
58541
|
-
|
|
58542
|
-
state = STATE.PAN;
|
|
58543
|
-
|
|
58544
|
-
}
|
|
58545
|
-
|
|
58546
|
-
break;
|
|
58547
|
-
|
|
58548
|
-
default:
|
|
58549
|
-
|
|
58550
|
-
state = STATE.NONE;
|
|
58551
|
-
|
|
58552
|
-
}
|
|
58553
|
-
|
|
58554
|
-
if ( state !== STATE.NONE ) {
|
|
58555
|
-
|
|
58556
|
-
scope.dispatchEvent( _startEvent );
|
|
58557
|
-
|
|
58558
|
-
}
|
|
58559
|
-
|
|
58560
|
-
}
|
|
58561
|
-
|
|
58562
|
-
function onMouseMove( event ) {
|
|
58563
|
-
|
|
58564
|
-
switch ( state ) {
|
|
58565
|
-
|
|
58566
|
-
case STATE.ROTATE:
|
|
58567
|
-
|
|
58568
|
-
if ( scope.enableRotate === false ) return;
|
|
58569
|
-
|
|
58570
|
-
handleMouseMoveRotate( event );
|
|
58571
|
-
|
|
58572
|
-
break;
|
|
58573
|
-
|
|
58574
|
-
case STATE.DOLLY:
|
|
58575
|
-
|
|
58576
|
-
if ( scope.enableZoom === false ) return;
|
|
58577
|
-
|
|
58578
|
-
handleMouseMoveDolly( event );
|
|
58579
|
-
|
|
58580
|
-
break;
|
|
58581
|
-
|
|
58582
|
-
case STATE.PAN:
|
|
58583
|
-
|
|
58584
|
-
if ( scope.enablePan === false ) return;
|
|
58585
|
-
|
|
58586
|
-
handleMouseMovePan( event );
|
|
58587
|
-
|
|
58588
|
-
break;
|
|
58589
|
-
|
|
58590
|
-
}
|
|
58591
|
-
|
|
58592
|
-
}
|
|
58593
|
-
|
|
58594
|
-
function onMouseWheel( event ) {
|
|
58595
|
-
|
|
58596
|
-
if ( scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE ) return;
|
|
58597
|
-
|
|
58598
|
-
event.preventDefault();
|
|
58599
|
-
|
|
58600
|
-
scope.dispatchEvent( _startEvent );
|
|
58601
|
-
|
|
58602
|
-
handleMouseWheel( event );
|
|
58603
|
-
|
|
58604
|
-
scope.dispatchEvent( _endEvent );
|
|
58605
|
-
|
|
58606
|
-
}
|
|
58607
|
-
|
|
58608
|
-
function onKeyDown( event ) {
|
|
58609
|
-
|
|
58610
|
-
if ( scope.enabled === false || scope.enablePan === false ) return;
|
|
58611
|
-
|
|
58612
|
-
handleKeyDown( event );
|
|
58613
|
-
|
|
58614
|
-
}
|
|
58615
|
-
|
|
58616
|
-
function onTouchStart( event ) {
|
|
58617
|
-
|
|
58618
|
-
trackPointer( event );
|
|
58619
|
-
|
|
58620
|
-
switch ( pointers.length ) {
|
|
58621
|
-
|
|
58622
|
-
case 1:
|
|
58623
|
-
|
|
58624
|
-
switch ( scope.touches.ONE ) {
|
|
58625
|
-
|
|
58626
|
-
case TOUCH.ROTATE:
|
|
58627
|
-
|
|
58628
|
-
if ( scope.enableRotate === false ) return;
|
|
58629
|
-
|
|
58630
|
-
handleTouchStartRotate();
|
|
58631
|
-
|
|
58632
|
-
state = STATE.TOUCH_ROTATE;
|
|
58633
|
-
|
|
58634
|
-
break;
|
|
58635
|
-
|
|
58636
|
-
case TOUCH.PAN:
|
|
58637
|
-
|
|
58638
|
-
if ( scope.enablePan === false ) return;
|
|
58639
|
-
|
|
58640
|
-
handleTouchStartPan();
|
|
58641
|
-
|
|
58642
|
-
state = STATE.TOUCH_PAN;
|
|
58643
|
-
|
|
58644
|
-
break;
|
|
58645
|
-
|
|
58646
|
-
default:
|
|
58647
|
-
|
|
58648
|
-
state = STATE.NONE;
|
|
58649
|
-
|
|
58650
|
-
}
|
|
58651
|
-
|
|
58652
|
-
break;
|
|
58653
|
-
|
|
58654
|
-
case 2:
|
|
58655
|
-
|
|
58656
|
-
switch ( scope.touches.TWO ) {
|
|
58657
|
-
|
|
58658
|
-
case TOUCH.DOLLY_PAN:
|
|
58659
|
-
|
|
58660
|
-
if ( scope.enableZoom === false && scope.enablePan === false ) return;
|
|
58661
|
-
|
|
58662
|
-
handleTouchStartDollyPan();
|
|
58663
|
-
|
|
58664
|
-
state = STATE.TOUCH_DOLLY_PAN;
|
|
58665
|
-
|
|
58666
|
-
break;
|
|
58667
|
-
|
|
58668
|
-
case TOUCH.DOLLY_ROTATE:
|
|
58669
|
-
|
|
58670
|
-
if ( scope.enableZoom === false && scope.enableRotate === false ) return;
|
|
58671
|
-
|
|
58672
|
-
handleTouchStartDollyRotate();
|
|
58673
|
-
|
|
58674
|
-
state = STATE.TOUCH_DOLLY_ROTATE;
|
|
58675
|
-
|
|
58676
|
-
break;
|
|
58677
|
-
|
|
58678
|
-
default:
|
|
58679
|
-
|
|
58680
|
-
state = STATE.NONE;
|
|
58681
|
-
|
|
58682
|
-
}
|
|
58683
|
-
|
|
58684
|
-
break;
|
|
58685
|
-
|
|
58686
|
-
default:
|
|
58687
|
-
|
|
58688
|
-
state = STATE.NONE;
|
|
58689
|
-
|
|
58690
|
-
}
|
|
58691
|
-
|
|
58692
|
-
if ( state !== STATE.NONE ) {
|
|
58693
|
-
|
|
58694
|
-
scope.dispatchEvent( _startEvent );
|
|
58695
|
-
|
|
58696
|
-
}
|
|
58697
|
-
|
|
58698
|
-
}
|
|
58699
|
-
|
|
58700
|
-
function onTouchMove( event ) {
|
|
58701
|
-
|
|
58702
|
-
trackPointer( event );
|
|
58703
|
-
|
|
58704
|
-
switch ( state ) {
|
|
58705
|
-
|
|
58706
|
-
case STATE.TOUCH_ROTATE:
|
|
58707
|
-
|
|
58708
|
-
if ( scope.enableRotate === false ) return;
|
|
58709
|
-
|
|
58710
|
-
handleTouchMoveRotate( event );
|
|
58711
|
-
|
|
58712
|
-
scope.update();
|
|
58713
|
-
|
|
58714
|
-
break;
|
|
58715
|
-
|
|
58716
|
-
case STATE.TOUCH_PAN:
|
|
58717
|
-
|
|
58718
|
-
if ( scope.enablePan === false ) return;
|
|
58719
|
-
|
|
58720
|
-
handleTouchMovePan( event );
|
|
58721
|
-
|
|
58722
|
-
scope.update();
|
|
58723
|
-
|
|
58724
|
-
break;
|
|
58725
|
-
|
|
58726
|
-
case STATE.TOUCH_DOLLY_PAN:
|
|
58727
|
-
|
|
58728
|
-
if ( scope.enableZoom === false && scope.enablePan === false ) return;
|
|
58729
|
-
|
|
58730
|
-
handleTouchMoveDollyPan( event );
|
|
58731
|
-
|
|
58732
|
-
scope.update();
|
|
58733
|
-
|
|
58734
|
-
break;
|
|
58735
|
-
|
|
58736
|
-
case STATE.TOUCH_DOLLY_ROTATE:
|
|
58737
|
-
|
|
58738
|
-
if ( scope.enableZoom === false && scope.enableRotate === false ) return;
|
|
58739
|
-
|
|
58740
|
-
handleTouchMoveDollyRotate( event );
|
|
58741
|
-
|
|
58742
|
-
scope.update();
|
|
58743
|
-
|
|
58744
|
-
break;
|
|
58745
|
-
|
|
58746
|
-
default:
|
|
58747
|
-
|
|
58748
|
-
state = STATE.NONE;
|
|
58749
|
-
|
|
58750
|
-
}
|
|
58751
|
-
|
|
58752
|
-
}
|
|
58753
|
-
|
|
58754
|
-
function onContextMenu( event ) {
|
|
58755
|
-
|
|
58756
|
-
if ( scope.enabled === false ) return;
|
|
58757
|
-
|
|
58758
|
-
event.preventDefault();
|
|
58759
|
-
|
|
58760
|
-
}
|
|
58761
|
-
|
|
58762
|
-
function addPointer( event ) {
|
|
58763
|
-
|
|
58764
|
-
pointers.push( event );
|
|
58765
|
-
|
|
58766
|
-
}
|
|
58767
|
-
|
|
58768
|
-
function removePointer( event ) {
|
|
58769
|
-
|
|
58770
|
-
delete pointerPositions[ event.pointerId ];
|
|
58771
|
-
|
|
58772
|
-
for ( let i = 0; i < pointers.length; i ++ ) {
|
|
58773
|
-
|
|
58774
|
-
if ( pointers[ i ].pointerId == event.pointerId ) {
|
|
58775
|
-
|
|
58776
|
-
pointers.splice( i, 1 );
|
|
58777
|
-
return;
|
|
58778
|
-
|
|
58779
|
-
}
|
|
58780
|
-
|
|
58781
|
-
}
|
|
58782
|
-
|
|
58783
|
-
}
|
|
58784
|
-
|
|
58785
|
-
function trackPointer( event ) {
|
|
58786
|
-
|
|
58787
|
-
let position = pointerPositions[ event.pointerId ];
|
|
58788
|
-
|
|
58789
|
-
if ( position === undefined ) {
|
|
58790
|
-
|
|
58791
|
-
position = new Vector2();
|
|
58792
|
-
pointerPositions[ event.pointerId ] = position;
|
|
58793
|
-
|
|
58794
|
-
}
|
|
58795
|
-
|
|
58796
|
-
position.set( event.pageX, event.pageY );
|
|
58797
|
-
|
|
58798
|
-
}
|
|
58799
|
-
|
|
58800
|
-
function getSecondPointerPosition( event ) {
|
|
58801
|
-
|
|
58802
|
-
const pointer = ( event.pointerId === pointers[ 0 ].pointerId ) ? pointers[ 1 ] : pointers[ 0 ];
|
|
58803
|
-
|
|
58804
|
-
return pointerPositions[ pointer.pointerId ];
|
|
58805
|
-
|
|
58806
|
-
}
|
|
58807
|
-
|
|
58808
|
-
//
|
|
58809
|
-
|
|
58810
|
-
scope.domElement.addEventListener( 'contextmenu', onContextMenu );
|
|
58811
|
-
|
|
58812
|
-
scope.domElement.addEventListener( 'pointerdown', onPointerDown );
|
|
58813
|
-
scope.domElement.addEventListener( 'pointercancel', onPointerUp );
|
|
58814
|
-
scope.domElement.addEventListener( 'wheel', onMouseWheel, { passive: false } );
|
|
58815
|
-
|
|
58816
|
-
// force an update at start
|
|
58817
|
-
|
|
58818
|
-
this.update();
|
|
58819
|
-
|
|
58820
|
-
}
|
|
58821
|
-
|
|
58822
|
-
}
|
|
58823
|
-
|
|
58824
|
-
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
58825
|
-
// License, v2.0. If a copy of the MPL was not distributed with this
|
|
58826
|
-
// file, You can obtain one at http://mozilla.org/MPL/2.0/
|
|
58827
|
-
|
|
58828
|
-
const DEFAULT_CAMERA_STATE = {
|
|
58829
|
-
distance: 20,
|
|
58830
|
-
perspective: true,
|
|
58831
|
-
phi: 60,
|
|
58832
|
-
target: [0, 0, 0],
|
|
58833
|
-
targetOffset: [0, 0, 0],
|
|
58834
|
-
targetOrientation: [0, 0, 0, 1],
|
|
58835
|
-
thetaOffset: 45,
|
|
58836
|
-
fovy: 45,
|
|
58837
|
-
near: 0.5,
|
|
58838
|
-
far: 5000
|
|
58839
|
-
};
|
|
59997
|
+
const DEFAULT_CAMERA_STATE = {
|
|
59998
|
+
distance: 20,
|
|
59999
|
+
perspective: true,
|
|
60000
|
+
phi: 60,
|
|
60001
|
+
target: [0, 0, 0],
|
|
60002
|
+
targetOffset: [0, 0, 0],
|
|
60003
|
+
targetOrientation: [0, 0, 0, 1],
|
|
60004
|
+
thetaOffset: 45,
|
|
60005
|
+
fovy: 45,
|
|
60006
|
+
near: 0.5,
|
|
60007
|
+
far: 5000
|
|
60008
|
+
};
|
|
58840
60009
|
|
|
58841
60010
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
58842
60011
|
// License, v2.0. If a copy of the MPL was not distributed with this
|
|
58843
60012
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/
|
|
58844
|
-
|
|
58845
60013
|
const DISPLAY_FRAME_NOT_FOUND = "DISPLAY_FRAME_NOT_FOUND";
|
|
58846
|
-
const UNIT_X = new Vector3(1, 0, 0);
|
|
58847
|
-
const UNIT_Z = new Vector3(0, 0, 1);
|
|
58848
|
-
const PI_2 = Math.PI / 2;
|
|
58849
|
-
|
|
58850
|
-
// used for holding unfollowPoseSnapshot in render frame every new frame
|
|
58851
60014
|
const snapshotInRenderFrame = makePose();
|
|
58852
60015
|
const tempVec3$1 = new Vector3();
|
|
58853
60016
|
const tempSpherical = new Spherical();
|
|
58854
|
-
const tempEuler$1 = new Euler();
|
|
58855
60017
|
const FOLLOW_TF_PATH$1 = ["general", "followTf"];
|
|
60018
|
+
const AZIMUTH_SENSITIVITY = 0.25;
|
|
60019
|
+
const POLAR_SENSITIVITY = 0.25;
|
|
60020
|
+
const MIN_POLAR_DEG = 1;
|
|
60021
|
+
const MAX_POLAR_DEG = 179;
|
|
58856
60022
|
class CameraStateSettings extends SceneExtension {
|
|
58857
|
-
// The frameId's of the fixed and render frames used to create the current unfollowPoseSnapshot
|
|
58858
60023
|
#unfollowSnapshotFrameIds;
|
|
58859
|
-
|
|
58860
|
-
// The pose of the render frame in the fixed frame when following was disabled
|
|
58861
|
-
// This is used to position and orient the camera from the fixed frame in the render frame
|
|
58862
|
-
|
|
58863
60024
|
#controls;
|
|
58864
60025
|
#isUpdatingCameraState = false;
|
|
58865
60026
|
#canvas;
|
|
58866
|
-
|
|
58867
|
-
// This group is used to transform the cameras based on the Frame follow mode
|
|
58868
|
-
// quaternion is affected in stationary and position-only follow modes
|
|
58869
|
-
// both position and quaternion of the group are affected in stationary mode
|
|
58870
60027
|
#cameraGroup;
|
|
58871
60028
|
#perspectiveCamera;
|
|
58872
60029
|
#orthographicCamera;
|
|
58873
60030
|
#aspect;
|
|
60031
|
+
#lastTargetOffset = new Vector3();
|
|
60032
|
+
#isDraggingForRotation = false;
|
|
60033
|
+
#lastMouseX = 1;
|
|
60034
|
+
#lastMouseY = 1;
|
|
58874
60035
|
constructor(renderer, canvas, aspect) {
|
|
58875
60036
|
super("foxglove.CameraStateSettings", renderer);
|
|
58876
|
-
|
|
58877
|
-
|
|
58878
|
-
|
|
58879
|
-
|
|
58880
|
-
renderer.
|
|
58881
|
-
renderer.settings.errors.on("
|
|
58882
|
-
renderer.settings.errors.on("
|
|
60037
|
+
this.renderer = renderer;
|
|
60038
|
+
CameraControls.install({
|
|
60039
|
+
THREE: THREE$1
|
|
60040
|
+
});
|
|
60041
|
+
this.renderer.on("transformTreeUpdated", this.#handleTransformTreeUpdated);
|
|
60042
|
+
this.renderer.settings.errors.on("update", this.#handleErrorChange);
|
|
60043
|
+
this.renderer.settings.errors.on("clear", this.#handleErrorChange);
|
|
60044
|
+
this.renderer.settings.errors.on("remove", this.#handleErrorChange);
|
|
58883
60045
|
this.#canvas = canvas;
|
|
58884
60046
|
this.#perspectiveCamera = new PerspectiveCamera();
|
|
58885
60047
|
this.#orthographicCamera = new OrthographicCamera();
|
|
@@ -58887,38 +60049,70 @@ class CameraStateSettings extends SceneExtension {
|
|
|
58887
60049
|
this.#cameraGroup.add(this.#perspectiveCamera);
|
|
58888
60050
|
this.#cameraGroup.add(this.#orthographicCamera);
|
|
58889
60051
|
this.add(this.#cameraGroup);
|
|
58890
|
-
this.#controls = new
|
|
58891
|
-
this.#controls.
|
|
58892
|
-
this.#controls.mouseButtons.
|
|
58893
|
-
this.#controls.mouseButtons.
|
|
58894
|
-
this.#controls.
|
|
58895
|
-
this.#controls.touches.
|
|
58896
|
-
this.#controls.
|
|
58897
|
-
|
|
58898
|
-
|
|
58899
|
-
|
|
58900
|
-
|
|
58901
|
-
|
|
58902
|
-
|
|
60052
|
+
this.#controls = new CameraControls(this.#perspectiveCamera, this.#canvas);
|
|
60053
|
+
this.#controls.dampingFactor = 0.05;
|
|
60054
|
+
this.#controls.mouseButtons.left = CameraControls.ACTION.NONE;
|
|
60055
|
+
this.#controls.mouseButtons.right = CameraControls.ACTION.TRUCK;
|
|
60056
|
+
this.#controls.mouseButtons.wheel = CameraControls.ACTION.ZOOM;
|
|
60057
|
+
this.#controls.touches.one = CameraControls.ACTION.TOUCH_SCREEN_PAN;
|
|
60058
|
+
this.#controls.infinityDolly = true;
|
|
60059
|
+
this.#perspectiveCamera.rotation.set(0, Math.PI, Math.PI);
|
|
60060
|
+
this.#perspectiveCamera.up.set(0, -1, 0);
|
|
60061
|
+
this.#controls.update(0);
|
|
60062
|
+
const euler = new Euler().setFromQuaternion(this.#perspectiveCamera.quaternion, "ZYX");
|
|
60063
|
+
this.#perspectiveCamera.quaternion.setFromEuler(euler);
|
|
60064
|
+
this.#controls.addEventListener("update", this.#handleControlsUpdate);
|
|
60065
|
+
const controls = this.#controls;
|
|
60066
|
+
const animate = () => {
|
|
60067
|
+
controls.update(1.0);
|
|
60068
|
+
requestAnimationFrame(animate);
|
|
60069
|
+
};
|
|
60070
|
+
animate();
|
|
58903
60071
|
canvas.tabIndex = 1000;
|
|
58904
60072
|
this.#aspect = aspect;
|
|
58905
|
-
this.#
|
|
58906
|
-
|
|
58907
|
-
|
|
58908
|
-
|
|
58909
|
-
|
|
58910
|
-
|
|
58911
|
-
|
|
60073
|
+
canvas.addEventListener("mousedown", this.#handleMouseDown);
|
|
60074
|
+
canvas.addEventListener("mousemove", this.#handleMouseMove);
|
|
60075
|
+
window.addEventListener("mouseup", this.#handleMouseUp);
|
|
60076
|
+
canvas.addEventListener("mouseleave", this.#handleMouseLeave);
|
|
60077
|
+
canvas.addEventListener("contextmenu", event => event.preventDefault());
|
|
60078
|
+
|
|
60079
|
+
// Set camera state to default
|
|
60080
|
+
setTimeout(() => {
|
|
60081
|
+
const activeCamera = this.getActiveCamera();
|
|
60082
|
+
activeCamera.updateMatrixWorld(true);
|
|
60083
|
+
this.renderer.queueAnimationFrame();
|
|
60084
|
+
this.#applyCameraStateToControls(this.renderer.config.cameraState, undefined);
|
|
60085
|
+
this.#controls.update(0);
|
|
60086
|
+
}, 10);
|
|
60087
|
+
// Rotates the camera to the default position
|
|
60088
|
+
setTimeout(() => {
|
|
60089
|
+
const currentTarget = new Vector3();
|
|
60090
|
+
this.#controls.getTarget(currentTarget);
|
|
60091
|
+
const currentPosition = new Vector3();
|
|
60092
|
+
this.#perspectiveCamera.getWorldPosition(currentPosition);
|
|
60093
|
+
const offset = currentPosition.clone().sub(currentTarget);
|
|
60094
|
+
const spherical = new Spherical();
|
|
60095
|
+
spherical.setFromVector3(offset);
|
|
60096
|
+
spherical.theta = Math.max(0.001, Math.min(Math.PI - 0.001, spherical.theta + Math.PI));
|
|
60097
|
+
const newOffset = new Vector3().setFromSpherical(spherical);
|
|
60098
|
+
const newCameraPosition = currentTarget.clone().add(newOffset);
|
|
60099
|
+
this.#controls.setLookAt(newCameraPosition.x, newCameraPosition.y, newCameraPosition.z, currentTarget.x, currentTarget.y, currentTarget.z, false);
|
|
60100
|
+
this.#controls.update(0);
|
|
60101
|
+
this.renderer.queueAnimationFrame();
|
|
60102
|
+
}, 100);
|
|
58912
60103
|
}
|
|
58913
60104
|
dispose() {
|
|
58914
|
-
// for camera settings
|
|
58915
|
-
this.renderer.off("cameraMove", this.#handleCameraMove);
|
|
58916
|
-
|
|
58917
|
-
// for frame settings
|
|
58918
60105
|
this.renderer.off("transformTreeUpdated", this.#handleTransformTreeUpdated);
|
|
58919
60106
|
this.renderer.settings.errors.off("update", this.#handleErrorChange);
|
|
58920
60107
|
this.renderer.settings.errors.off("clear", this.#handleErrorChange);
|
|
58921
60108
|
this.renderer.settings.errors.off("remove", this.#handleErrorChange);
|
|
60109
|
+
this.#controls.removeEventListener("update", this.#handleControlsUpdate);
|
|
60110
|
+
this.#canvas.removeEventListener("mousedown", this.#handleMouseDown);
|
|
60111
|
+
this.#canvas.removeEventListener("mousemove", this.#handleMouseMove);
|
|
60112
|
+
window.removeEventListener("mouseup", this.#handleMouseUp);
|
|
60113
|
+
this.#canvas.removeEventListener("mouseleave", this.#handleMouseLeave);
|
|
60114
|
+
this.#canvas.removeEventListener("contextmenu", event => event.preventDefault());
|
|
60115
|
+
this.#controls.dispose();
|
|
58922
60116
|
super.dispose();
|
|
58923
60117
|
}
|
|
58924
60118
|
settingsNodes() {
|
|
@@ -58926,9 +60120,7 @@ class CameraStateSettings extends SceneExtension {
|
|
|
58926
60120
|
}
|
|
58927
60121
|
#cameraSettingsNode() {
|
|
58928
60122
|
const config = this.renderer.config;
|
|
58929
|
-
const
|
|
58930
|
-
cameraState: camera
|
|
58931
|
-
} = config;
|
|
60123
|
+
const camera = config.cameraState;
|
|
58932
60124
|
const handler = this.handleSettingsAction;
|
|
58933
60125
|
return {
|
|
58934
60126
|
path: ["cameraState"],
|
|
@@ -58953,7 +60145,7 @@ class CameraStateSettings extends SceneExtension {
|
|
|
58953
60145
|
input: "number",
|
|
58954
60146
|
step: 1,
|
|
58955
60147
|
precision: PRECISION_DISTANCE,
|
|
58956
|
-
value: camera.distance
|
|
60148
|
+
value: camera.distance ?? config.cameraState.distance
|
|
58957
60149
|
},
|
|
58958
60150
|
perspective: {
|
|
58959
60151
|
label: t$1("threeDee:perspective"),
|
|
@@ -58965,23 +60157,23 @@ class CameraStateSettings extends SceneExtension {
|
|
|
58965
60157
|
input: "vec3",
|
|
58966
60158
|
labels: ["X", "Y", "Z"],
|
|
58967
60159
|
precision: PRECISION_DISTANCE,
|
|
58968
|
-
value: [...camera.targetOffset]
|
|
60160
|
+
value: [...(camera.targetOffset ?? config.cameraState.targetOffset)]
|
|
58969
60161
|
},
|
|
58970
60162
|
thetaOffset: {
|
|
58971
60163
|
label: t$1("threeDee:theta"),
|
|
58972
60164
|
input: "number",
|
|
58973
60165
|
step: 1,
|
|
58974
60166
|
precision: PRECISION_DEGREES,
|
|
58975
|
-
value: camera.thetaOffset
|
|
60167
|
+
value: camera.thetaOffset ?? config.cameraState.thetaOffset
|
|
60168
|
+
},
|
|
60169
|
+
phi: {
|
|
60170
|
+
label: t$1("threeDee:phi"),
|
|
60171
|
+
input: "number",
|
|
60172
|
+
step: 1,
|
|
60173
|
+
precision: PRECISION_DEGREES,
|
|
60174
|
+
value: camera.phi ?? config.cameraState.phi
|
|
58976
60175
|
},
|
|
58977
60176
|
...(camera.perspective && {
|
|
58978
|
-
phi: {
|
|
58979
|
-
label: t$1("threeDee:phi"),
|
|
58980
|
-
input: "number",
|
|
58981
|
-
step: 1,
|
|
58982
|
-
precision: PRECISION_DEGREES,
|
|
58983
|
-
value: camera.phi
|
|
58984
|
-
},
|
|
58985
60177
|
fovy: {
|
|
58986
60178
|
label: t$1("threeDee:fovy"),
|
|
58987
60179
|
input: "number",
|
|
@@ -59002,7 +60194,7 @@ class CameraStateSettings extends SceneExtension {
|
|
|
59002
60194
|
input: "number",
|
|
59003
60195
|
step: 1,
|
|
59004
60196
|
precision: PRECISION_DISTANCE,
|
|
59005
|
-
value: camera.far
|
|
60197
|
+
value: camera.far ?? config.cameraState.far
|
|
59006
60198
|
}
|
|
59007
60199
|
}
|
|
59008
60200
|
}
|
|
@@ -59011,14 +60203,9 @@ class CameraStateSettings extends SceneExtension {
|
|
|
59011
60203
|
#frameSettingsNode() {
|
|
59012
60204
|
const config = this.renderer.config;
|
|
59013
60205
|
const handler = this.handleSettingsAction;
|
|
59014
|
-
|
|
59015
|
-
// If the user-selected frame does not exist, show it in the dropdown
|
|
59016
|
-
// anyways. A settings node error will be displayed
|
|
59017
60206
|
let followTfOptions = this.renderer.coordinateFrameList;
|
|
59018
60207
|
const followFrameId = this.renderer.followFrameId;
|
|
59019
60208
|
this.#updateFollowTfError();
|
|
59020
|
-
|
|
59021
|
-
// always show current config value if it exists
|
|
59022
60209
|
const followTfValue = config.followTf ?? followFrameId;
|
|
59023
60210
|
if (followTfValue != undefined && !this.renderer.transformTree.hasFrame(followTfValue)) {
|
|
59024
60211
|
followTfOptions = [{
|
|
@@ -59037,7 +60224,7 @@ class CameraStateSettings extends SceneExtension {
|
|
|
59037
60224
|
label: t$1("threeDee:fixed"),
|
|
59038
60225
|
value: "follow-none"
|
|
59039
60226
|
}];
|
|
59040
|
-
const followModeValue =
|
|
60227
|
+
const followModeValue = config.followMode;
|
|
59041
60228
|
return {
|
|
59042
60229
|
path: ["general"],
|
|
59043
60230
|
node: {
|
|
@@ -59066,71 +60253,68 @@ class CameraStateSettings extends SceneExtension {
|
|
|
59066
60253
|
}
|
|
59067
60254
|
handleSettingsAction = action => {
|
|
59068
60255
|
if (action.action === "perform-node-action" && action.payload.id === "reset-camera") {
|
|
60256
|
+
const previousState = cloneDeep(this.renderer.config.cameraState);
|
|
59069
60257
|
this.renderer.updateConfig(draft => {
|
|
59070
60258
|
draft.cameraState = cloneDeep(DEFAULT_CAMERA_STATE);
|
|
59071
60259
|
});
|
|
59072
|
-
this.
|
|
60260
|
+
this.#applyCameraStateToControls(this.renderer.config.cameraState, previousState);
|
|
60261
|
+
this.renderer.emit("cameraMove", this.renderer);
|
|
59073
60262
|
return;
|
|
59074
60263
|
}
|
|
59075
60264
|
if (action.action !== "update" || action.payload.path.length === 0) {
|
|
59076
60265
|
return;
|
|
59077
60266
|
}
|
|
59078
60267
|
const {
|
|
59079
|
-
path: [category],
|
|
59080
60268
|
path,
|
|
59081
60269
|
value
|
|
59082
60270
|
} = action.payload;
|
|
59083
|
-
|
|
59084
|
-
// camera settings
|
|
60271
|
+
const category = path[0];
|
|
59085
60272
|
if (category === "cameraState") {
|
|
60273
|
+
const previousState = cloneDeep(this.renderer.config.cameraState);
|
|
59086
60274
|
if (path[1] === "syncCamera") {
|
|
59087
|
-
// Update the configuration. This is done manually since syncCamera is under `scene`, not `cameraState`
|
|
59088
60275
|
this.renderer.updateConfig(draft => {
|
|
59089
60276
|
draft.scene.syncCamera = value;
|
|
59090
60277
|
});
|
|
59091
60278
|
} else {
|
|
59092
|
-
this.renderer.updateConfig(draft =>
|
|
60279
|
+
this.renderer.updateConfig(draft => {
|
|
60280
|
+
set$4(draft, path, value);
|
|
60281
|
+
});
|
|
60282
|
+
this.#applyCameraStateToControls(this.renderer.config.cameraState, previousState);
|
|
60283
|
+
this.renderer.emit("cameraMove", this.renderer);
|
|
59093
60284
|
}
|
|
59094
|
-
this.updateSettingsTree();
|
|
59095
60285
|
}
|
|
59096
|
-
|
|
59097
|
-
// frame settings
|
|
59098
60286
|
if (category === "general") {
|
|
60287
|
+
const previousState = cloneDeep(this.renderer.config.cameraState);
|
|
59099
60288
|
if (path[1] === "followTf") {
|
|
59100
60289
|
const followTf = value;
|
|
59101
|
-
// Update the configuration. This is done manually since followTf is at the top level of
|
|
59102
|
-
// config, not under `general`
|
|
59103
60290
|
this.renderer.updateConfig(draft => {
|
|
59104
60291
|
draft.followTf = followTf;
|
|
59105
60292
|
});
|
|
59106
60293
|
this.#updateFollowFrameId();
|
|
59107
|
-
this.renderer.settings.errors.clearPath(
|
|
60294
|
+
this.renderer.settings.errors.clearPath(FOLLOW_TF_PATH$1);
|
|
59108
60295
|
} else if (path[1] === "followMode") {
|
|
59109
60296
|
const followMode = value;
|
|
59110
|
-
// Update the configuration. This is done manually since followMode is at the top level of
|
|
59111
|
-
// config, not under `general`
|
|
59112
60297
|
this.renderer.updateConfig(draft => {
|
|
59113
|
-
|
|
59114
|
-
// stationary -> any follow clear offset (center on frame)
|
|
59115
|
-
if (draft.followMode === "follow-none") {
|
|
60298
|
+
if (draft.followMode === "follow-none" || followMode === "follow-pose") {
|
|
59116
60299
|
draft.cameraState.targetOffset = [...DEFAULT_CAMERA_STATE.targetOffset];
|
|
59117
|
-
|
|
59118
|
-
|
|
60300
|
+
}
|
|
60301
|
+
if (followMode === "follow-pose") {
|
|
59119
60302
|
draft.cameraState.thetaOffset = DEFAULT_CAMERA_STATE.thetaOffset;
|
|
59120
60303
|
}
|
|
59121
60304
|
draft.followMode = followMode;
|
|
59122
60305
|
});
|
|
60306
|
+
this.#applyCameraStateToControls(this.renderer.config.cameraState, previousState);
|
|
60307
|
+
this.renderer.emit("cameraMove", this.renderer);
|
|
60308
|
+
} else {
|
|
60309
|
+
this.renderer.updateConfig(draft => {
|
|
60310
|
+
set$4(draft, path, value);
|
|
60311
|
+
});
|
|
59123
60312
|
}
|
|
59124
|
-
this.updateSettingsTree();
|
|
59125
60313
|
}
|
|
59126
60314
|
};
|
|
59127
|
-
|
|
59128
|
-
// this extension has NO RENDERABLES so the parent startFrame would do nothing
|
|
59129
60315
|
startFrame(currentTime, renderFrameId, fixedFrameId) {
|
|
59130
60316
|
const followMode = this.renderer.config.followMode;
|
|
59131
|
-
if (followMode === "follow-pose" ||
|
|
59132
|
-
// we don't need the unfollow pose snapshot when there are no transforms
|
|
59133
|
-
fixedFrameId === CoordinateFrame.FALLBACK_FRAME_ID || renderFrameId === CoordinateFrame.FALLBACK_FRAME_ID) {
|
|
60317
|
+
if (followMode === "follow-pose" || fixedFrameId === CoordinateFrame.FALLBACK_FRAME_ID || renderFrameId === CoordinateFrame.FALLBACK_FRAME_ID) {
|
|
59134
60318
|
this.#unfollowSnapshotFrameIds = undefined;
|
|
59135
60319
|
this.unfollowPoseSnapshot = undefined;
|
|
59136
60320
|
this.#cameraGroup.position.set(0, 0, 0);
|
|
@@ -59140,34 +60324,78 @@ class CameraStateSettings extends SceneExtension {
|
|
|
59140
60324
|
const poseSnapshot = this.#getUnfollowPoseSnapshot(fixedFrameId, renderFrameId, currentTime);
|
|
59141
60325
|
const transformTree = this.renderer.transformTree;
|
|
59142
60326
|
if (poseSnapshot) {
|
|
59143
|
-
// transform position of snapshot in fixed frame to the render frame
|
|
59144
60327
|
const appliedTransform = Boolean(transformTree.apply(snapshotInRenderFrame, poseSnapshot, renderFrameId, fixedFrameId, fixedFrameId, currentTime, currentTime));
|
|
59145
60328
|
if (!appliedTransform) {
|
|
59146
60329
|
return;
|
|
59147
60330
|
}
|
|
59148
|
-
/**
|
|
59149
|
-
* the application of the unfollowPoseSnapshot position and orientation
|
|
59150
|
-
* components makes the camera position and rotation static relative to the fixed frame.
|
|
59151
|
-
* So when the display frame changes the angle of the camera relative
|
|
59152
|
-
* to the scene will not change because only the snapshotPose orientation is applied
|
|
59153
|
-
*/
|
|
59154
60331
|
if (followMode === "follow-position") {
|
|
59155
|
-
// only make orientation static/stationary in this mode
|
|
59156
|
-
// the position still follows the frame
|
|
59157
60332
|
this.#cameraGroup.position.set(0, 0, 0);
|
|
59158
60333
|
} else {
|
|
59159
60334
|
this.#cameraGroup.position.set(snapshotInRenderFrame.position.x, snapshotInRenderFrame.position.y, snapshotInRenderFrame.position.z);
|
|
59160
60335
|
}
|
|
59161
|
-
// this negates the rotation of the changes in renderFrame
|
|
59162
60336
|
this.#cameraGroup.quaternion.set(snapshotInRenderFrame.orientation.x, snapshotInRenderFrame.orientation.y, snapshotInRenderFrame.orientation.z, snapshotInRenderFrame.orientation.w);
|
|
59163
60337
|
}
|
|
59164
60338
|
}
|
|
59165
|
-
#
|
|
59166
|
-
this
|
|
60339
|
+
#handleControlsUpdate = () => {
|
|
60340
|
+
if (!this.#isUpdatingCameraState && !this.#isDraggingForRotation) {
|
|
60341
|
+
const newDistance = this.#controls.distance;
|
|
60342
|
+
this.#controls.getTarget(tempVec3$1);
|
|
60343
|
+
const state = this.renderer.config.cameraState;
|
|
60344
|
+
const distChanged = Math.abs(state.distance - newDistance) > 1e-6;
|
|
60345
|
+
const targetChanged = !isEqual(state.targetOffset, [tempVec3$1.x, tempVec3$1.y, tempVec3$1.z]);
|
|
60346
|
+
if (distChanged || targetChanged) {
|
|
60347
|
+
this.renderer.updateConfig(draft => {
|
|
60348
|
+
if (distChanged) draft.cameraState.distance = newDistance;
|
|
60349
|
+
if (targetChanged) draft.cameraState.targetOffset = [tempVec3$1.x, tempVec3$1.y, tempVec3$1.z];
|
|
60350
|
+
});
|
|
60351
|
+
this.#lastTargetOffset.copy(tempVec3$1);
|
|
60352
|
+
this.renderer.emit("cameraMove", this.renderer);
|
|
60353
|
+
}
|
|
60354
|
+
}
|
|
60355
|
+
};
|
|
60356
|
+
#handleMouseDown = event => {
|
|
60357
|
+
if (event.button === 0) {
|
|
60358
|
+
event.preventDefault();
|
|
60359
|
+
this.#isDraggingForRotation = true;
|
|
60360
|
+
this.#lastMouseX = event.clientX;
|
|
60361
|
+
this.#lastMouseY = event.clientY;
|
|
60362
|
+
}
|
|
60363
|
+
};
|
|
60364
|
+
#handleMouseMove = event => {
|
|
60365
|
+
if (!this.#isDraggingForRotation) {
|
|
60366
|
+
return;
|
|
60367
|
+
}
|
|
60368
|
+
const deltaX = event.clientX - this.#lastMouseX;
|
|
60369
|
+
const deltaY = event.clientY - this.#lastMouseY;
|
|
60370
|
+
this.#lastMouseX = event.clientX;
|
|
60371
|
+
this.#lastMouseY = event.clientY;
|
|
60372
|
+
if (deltaX === 0 && deltaY === 0) {
|
|
60373
|
+
return;
|
|
60374
|
+
}
|
|
60375
|
+
const deltaAzimuth = -deltaX * AZIMUTH_SENSITIVITY;
|
|
60376
|
+
const deltaPolar = deltaY * POLAR_SENSITIVITY;
|
|
60377
|
+
const previousState = cloneDeep(this.renderer.config.cameraState);
|
|
60378
|
+
this.renderer.updateConfig(draft => {
|
|
60379
|
+
let currentPhi = draft.cameraState.phi + deltaPolar;
|
|
60380
|
+
currentPhi = Math.max(MIN_POLAR_DEG, Math.min(MAX_POLAR_DEG, currentPhi));
|
|
60381
|
+
draft.cameraState.phi = currentPhi;
|
|
60382
|
+
draft.cameraState.thetaOffset += deltaAzimuth;
|
|
60383
|
+
});
|
|
60384
|
+
this.#applyCameraStateToControls(this.renderer.config.cameraState, previousState);
|
|
60385
|
+
this.renderer.emit("cameraMove", this.renderer);
|
|
60386
|
+
};
|
|
60387
|
+
#handleMouseUp = event => {
|
|
60388
|
+
if (event.button === 0 && this.#isDraggingForRotation) {
|
|
60389
|
+
this.#isDraggingForRotation = false;
|
|
60390
|
+
}
|
|
60391
|
+
};
|
|
60392
|
+
#handleMouseLeave = () => {
|
|
60393
|
+
if (this.#isDraggingForRotation) {
|
|
60394
|
+
this.#isDraggingForRotation = false;
|
|
60395
|
+
}
|
|
59167
60396
|
};
|
|
59168
60397
|
#handleTransformTreeUpdated = () => {
|
|
59169
60398
|
this.#updateFollowFrameId();
|
|
59170
|
-
this.updateSettingsTree();
|
|
59171
60399
|
};
|
|
59172
60400
|
#updateFollowFrameId() {
|
|
59173
60401
|
const {
|
|
@@ -59182,11 +60410,8 @@ class CameraStateSettings extends SceneExtension {
|
|
|
59182
60410
|
this.renderer.setFollowFrameId(followTf);
|
|
59183
60411
|
return;
|
|
59184
60412
|
}
|
|
59185
|
-
|
|
59186
|
-
|
|
59187
|
-
// heuristically most valid frame (if any frames are present)
|
|
59188
|
-
const followFrameId = transformTree.getDefaultFollowFrameId();
|
|
59189
|
-
this.renderer.setFollowFrameId(followFrameId);
|
|
60413
|
+
const defaultFollowFrameId = transformTree.getDefaultFollowFrameId();
|
|
60414
|
+
this.renderer.setFollowFrameId(defaultFollowFrameId);
|
|
59190
60415
|
}
|
|
59191
60416
|
#updateFollowTfError = () => {
|
|
59192
60417
|
const {
|
|
@@ -59196,27 +60421,23 @@ class CameraStateSettings extends SceneExtension {
|
|
|
59196
60421
|
transformTree
|
|
59197
60422
|
} = this.renderer;
|
|
59198
60423
|
if (followTf != undefined) {
|
|
59199
|
-
|
|
59200
|
-
if (followTfFrameExists) {
|
|
60424
|
+
if (transformTree.hasFrame(followTf)) {
|
|
59201
60425
|
this.renderer.settings.errors.remove(FOLLOW_TF_PATH$1, DISPLAY_FRAME_NOT_FOUND);
|
|
59202
60426
|
} else {
|
|
59203
60427
|
this.renderer.settings.errors.add(FOLLOW_TF_PATH$1, DISPLAY_FRAME_NOT_FOUND, t$1("threeDee:frameNotFound", {
|
|
59204
60428
|
frameId: followTf
|
|
59205
60429
|
}));
|
|
59206
60430
|
}
|
|
60431
|
+
} else {
|
|
60432
|
+
this.renderer.settings.errors.remove(FOLLOW_TF_PATH$1, DISPLAY_FRAME_NOT_FOUND);
|
|
59207
60433
|
}
|
|
59208
60434
|
};
|
|
59209
|
-
#handleErrorChange = () => {
|
|
59210
|
-
this.updateSettingsTree();
|
|
59211
|
-
};
|
|
59212
|
-
|
|
59213
|
-
// Redefine follow pose snapshot whenever renderFrame or fixedFrame changes
|
|
60435
|
+
#handleErrorChange = () => {};
|
|
59214
60436
|
#getUnfollowPoseSnapshot(fixedFrameId, renderFrameId, currentTime) {
|
|
59215
60437
|
const transformTree = this.renderer.transformTree;
|
|
59216
|
-
if (this.#unfollowSnapshotFrameIds?.fixed !== fixedFrameId || this.#unfollowSnapshotFrameIds
|
|
60438
|
+
if (this.#unfollowSnapshotFrameIds?.fixed !== fixedFrameId || this.#unfollowSnapshotFrameIds?.render !== renderFrameId) {
|
|
59217
60439
|
this.unfollowPoseSnapshot = makePose();
|
|
59218
|
-
|
|
59219
|
-
transformTree.apply(this.unfollowPoseSnapshot, this.unfollowPoseSnapshot, fixedFrameId, fixedFrameId, renderFrameId, currentTime, currentTime);
|
|
60440
|
+
transformTree.apply(this.unfollowPoseSnapshot, makePose(), fixedFrameId, renderFrameId, fixedFrameId, currentTime, currentTime);
|
|
59220
60441
|
this.#unfollowSnapshotFrameIds = {
|
|
59221
60442
|
fixed: fixedFrameId,
|
|
59222
60443
|
render: renderFrameId
|
|
@@ -59232,74 +60453,58 @@ class CameraStateSettings extends SceneExtension {
|
|
|
59232
60453
|
this.setCameraState(this.renderer.config.cameraState);
|
|
59233
60454
|
}
|
|
59234
60455
|
getCameraState() {
|
|
59235
|
-
|
|
59236
|
-
return {
|
|
59237
|
-
perspective: config.cameraState.perspective,
|
|
59238
|
-
distance: this.#controls.getDistance(),
|
|
59239
|
-
phi: MathUtils.radToDeg(this.#controls.getPolarAngle()),
|
|
59240
|
-
thetaOffset: MathUtils.radToDeg(-this.#controls.getAzimuthalAngle()),
|
|
59241
|
-
targetOffset: [this.#controls.target.x, this.#controls.target.y, this.#controls.target.z],
|
|
59242
|
-
target: config.cameraState.target,
|
|
59243
|
-
targetOrientation: config.cameraState.targetOrientation,
|
|
59244
|
-
fovy: config.cameraState.fovy,
|
|
59245
|
-
near: config.cameraState.near,
|
|
59246
|
-
far: config.cameraState.far
|
|
59247
|
-
};
|
|
60456
|
+
return cloneDeep(this.renderer.config.cameraState);
|
|
59248
60457
|
}
|
|
59249
60458
|
setCameraState(cameraState) {
|
|
60459
|
+
const previousState = cloneDeep(this.renderer.config.cameraState);
|
|
59250
60460
|
this.#isUpdatingCameraState = true;
|
|
59251
|
-
this.#
|
|
59252
|
-
|
|
59253
|
-
// due to the fact that they are manipulating the camera after update with the `cameraGroup`
|
|
59254
|
-
if (this.renderer.config.followMode === "follow-pose") {
|
|
59255
|
-
this.#controls.update();
|
|
59256
|
-
}
|
|
60461
|
+
this.#updateRawCameras(cameraState);
|
|
60462
|
+
this.#applyCameraStateToControls(cameraState, previousState);
|
|
59257
60463
|
this.#isUpdatingCameraState = false;
|
|
59258
60464
|
}
|
|
59259
|
-
|
|
59260
|
-
/** Translate a CameraState to the three.js coordinate system */
|
|
59261
|
-
#updateCameras(cameraState) {
|
|
59262
|
-
const targetOffset = tempVec3$1;
|
|
59263
|
-
const config = this.renderer.config;
|
|
59264
|
-
targetOffset.fromArray(cameraState.targetOffset);
|
|
59265
|
-
const phi = MathUtils.degToRad(cameraState.phi);
|
|
59266
|
-
const theta = -MathUtils.degToRad(cameraState.thetaOffset);
|
|
59267
|
-
|
|
59268
|
-
// Always update the perspective camera even if the current mode is orthographic. This is needed
|
|
59269
|
-
// to make the OrbitControls work properly since they track the perspective camera.
|
|
59270
|
-
// https://github.com/foxglove/studio/issues/4138
|
|
59271
|
-
|
|
59272
|
-
// Convert the camera spherical coordinates (radius, phi, theta) to Cartesian (X, Y, Z)
|
|
59273
|
-
tempSpherical.set(cameraState.distance, phi, theta);
|
|
59274
|
-
this.#perspectiveCamera.position.setFromSpherical(tempSpherical).applyAxisAngle(UNIT_X, PI_2);
|
|
59275
|
-
this.#perspectiveCamera.position.add(targetOffset);
|
|
59276
|
-
|
|
59277
|
-
// Convert the camera spherical coordinates (phi, theta) to a quaternion rotation
|
|
59278
|
-
this.#perspectiveCamera.quaternion.setFromEuler(tempEuler$1.set(phi, 0, theta, "ZYX"));
|
|
60465
|
+
#updateRawCameras(cameraState) {
|
|
59279
60466
|
this.#perspectiveCamera.fov = cameraState.fovy;
|
|
59280
60467
|
this.#perspectiveCamera.near = cameraState.near;
|
|
59281
60468
|
this.#perspectiveCamera.far = cameraState.far;
|
|
59282
60469
|
this.#perspectiveCamera.aspect = this.#aspect;
|
|
59283
60470
|
this.#perspectiveCamera.updateProjectionMatrix();
|
|
59284
|
-
|
|
60471
|
+
if (!cameraState.perspective) {
|
|
60472
|
+
const orthoHeight = cameraState.distance * Math.tan(MathUtils.degToRad(cameraState.fovy * 0.5)) * 2;
|
|
60473
|
+
const orthoWidth = orthoHeight * this.#aspect;
|
|
60474
|
+
this.#orthographicCamera.left = -orthoWidth / 2;
|
|
60475
|
+
this.#orthographicCamera.right = orthoWidth / 2;
|
|
60476
|
+
this.#orthographicCamera.top = orthoHeight / 2;
|
|
60477
|
+
this.#orthographicCamera.bottom = -orthoHeight / 2;
|
|
60478
|
+
this.#orthographicCamera.near = cameraState.near;
|
|
60479
|
+
this.#orthographicCamera.far = cameraState.far;
|
|
60480
|
+
this.#orthographicCamera.updateProjectionMatrix();
|
|
60481
|
+
}
|
|
60482
|
+
}
|
|
60483
|
+
#applyCameraStateToControls(cameraState, previousState) {
|
|
60484
|
+
const targetOffset = tempVec3$1.fromArray(cameraState.targetOffset);
|
|
60485
|
+
const distance = cameraState.distance;
|
|
60486
|
+
const phiRad = MathUtils.degToRad(cameraState.phi);
|
|
60487
|
+
const azimuthRad = -MathUtils.degToRad(cameraState.thetaOffset);
|
|
60488
|
+
const propsChanged = !previousState || Math.abs(previousState.distance - distance) > 1e-6 || Math.abs(previousState.phi - cameraState.phi) > 1e-6 || Math.abs(previousState.thetaOffset - cameraState.thetaOffset) > 1e-6 || !isEqual(previousState.targetOffset, cameraState.targetOffset);
|
|
60489
|
+
if (propsChanged) {
|
|
60490
|
+
tempSpherical.set(distance, phiRad, azimuthRad);
|
|
60491
|
+
const cameraPosition = new Vector3().setFromSpherical(tempSpherical);
|
|
60492
|
+
cameraPosition.add(targetOffset);
|
|
60493
|
+
this.#controls.setLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z, targetOffset.x, targetOffset.y, targetOffset.z, false);
|
|
60494
|
+
this.#lastTargetOffset.copy(targetOffset);
|
|
60495
|
+
}
|
|
59285
60496
|
if (cameraState.perspective) {
|
|
59286
|
-
// Unlock the polar angle (pitch axis)
|
|
59287
60497
|
this.#controls.minPolarAngle = 0;
|
|
59288
60498
|
this.#controls.maxPolarAngle = Math.PI;
|
|
59289
60499
|
} else {
|
|
59290
|
-
|
|
59291
|
-
|
|
59292
|
-
this.#controls.
|
|
59293
|
-
this.#
|
|
59294
|
-
this.#orthographicCamera.
|
|
59295
|
-
this.#orthographicCamera.
|
|
59296
|
-
this.#orthographicCamera.right = cameraState.distance / 2 * this.#aspect;
|
|
59297
|
-
this.#orthographicCamera.top = cameraState.distance / 2;
|
|
59298
|
-
this.#orthographicCamera.bottom = -cameraState.distance / 2;
|
|
59299
|
-
this.#orthographicCamera.near = cameraState.near;
|
|
59300
|
-
this.#orthographicCamera.far = cameraState.far;
|
|
59301
|
-
this.#orthographicCamera.updateProjectionMatrix();
|
|
60500
|
+
this.#controls.minPolarAngle = 0;
|
|
60501
|
+
this.#controls.maxPolarAngle = Math.PI;
|
|
60502
|
+
this.#controls.getPosition(this.#orthographicCamera.position);
|
|
60503
|
+
this.#controls.getTarget(tempVec3$1);
|
|
60504
|
+
this.#orthographicCamera.lookAt(tempVec3$1);
|
|
60505
|
+
this.#orthographicCamera.updateMatrixWorld();
|
|
59302
60506
|
}
|
|
60507
|
+
this.#controls.update(0);
|
|
59303
60508
|
}
|
|
59304
60509
|
}
|
|
59305
60510
|
|