@onerjs/core 8.31.0 → 8.31.1

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.
Files changed (92) hide show
  1. package/Animations/animationGroup.js +1 -4
  2. package/Animations/animationGroup.js.map +1 -1
  3. package/Cameras/Inputs/geospatialCameraKeyboardInput.d.ts +81 -0
  4. package/Cameras/Inputs/geospatialCameraKeyboardInput.js +223 -0
  5. package/Cameras/Inputs/geospatialCameraKeyboardInput.js.map +1 -0
  6. package/Cameras/Inputs/geospatialCameraMouseWheelInput.js +1 -1
  7. package/Cameras/Inputs/geospatialCameraMouseWheelInput.js.map +1 -1
  8. package/Cameras/Inputs/geospatialCameraPointersInput.d.ts +7 -20
  9. package/Cameras/Inputs/geospatialCameraPointersInput.js +27 -75
  10. package/Cameras/Inputs/geospatialCameraPointersInput.js.map +1 -1
  11. package/Cameras/Limits/geospatialLimits.d.ts +60 -0
  12. package/Cameras/Limits/geospatialLimits.js +89 -0
  13. package/Cameras/Limits/geospatialLimits.js.map +1 -0
  14. package/Cameras/cameraMovement.js +1 -1
  15. package/Cameras/cameraMovement.js.map +1 -1
  16. package/Cameras/geospatialCamera.d.ts +53 -49
  17. package/Cameras/geospatialCamera.js +172 -192
  18. package/Cameras/geospatialCamera.js.map +1 -1
  19. package/Cameras/geospatialCameraInputsManager.d.ts +5 -0
  20. package/Cameras/geospatialCameraInputsManager.js +9 -0
  21. package/Cameras/geospatialCameraInputsManager.js.map +1 -1
  22. package/Cameras/geospatialCameraMovement.d.ts +66 -0
  23. package/Cameras/geospatialCameraMovement.js +199 -0
  24. package/Cameras/geospatialCameraMovement.js.map +1 -0
  25. package/Engines/Native/nativeInterfaces.d.ts +14 -6
  26. package/Engines/Native/nativeInterfaces.js +6 -1
  27. package/Engines/Native/nativeInterfaces.js.map +1 -1
  28. package/Engines/nativeEngine.js +2 -2
  29. package/Engines/nativeEngine.js.map +1 -1
  30. package/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.js +1 -1
  31. package/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.js.map +1 -1
  32. package/FlowGraph/flowGraphMath.d.ts +25 -0
  33. package/FlowGraph/flowGraphMath.js +40 -0
  34. package/FlowGraph/flowGraphMath.js.map +1 -0
  35. package/Materials/GaussianSplatting/gaussianSplattingMaterial.js +1 -1
  36. package/Materials/GaussianSplatting/gaussianSplattingMaterial.js.map +1 -1
  37. package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.js +5 -1
  38. package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.js.map +1 -1
  39. package/Materials/Node/Blocks/GaussianSplatting/splatReaderBlock.js +6 -5
  40. package/Materials/Node/Blocks/GaussianSplatting/splatReaderBlock.js.map +1 -1
  41. package/Materials/shaderMaterial.js +4 -2
  42. package/Materials/shaderMaterial.js.map +1 -1
  43. package/Maths/math.vector.functions.d.ts +5 -24
  44. package/Maths/math.vector.functions.js +32 -35
  45. package/Maths/math.vector.functions.js.map +1 -1
  46. package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +1 -0
  47. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +51 -16
  48. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
  49. package/Meshes/csg2.js +1 -1
  50. package/Meshes/csg2.js.map +1 -1
  51. package/Meshes/thinInstanceMesh.js +15 -0
  52. package/Meshes/thinInstanceMesh.js.map +1 -1
  53. package/Misc/fileTools.js.map +1 -1
  54. package/Misc/tools.d.ts +3 -0
  55. package/Misc/tools.js +43 -4
  56. package/Misc/tools.js.map +1 -1
  57. package/Particles/Node/Blocks/Update/basicPositionUpdateBlock.js +2 -2
  58. package/Particles/Node/Blocks/Update/basicPositionUpdateBlock.js.map +1 -1
  59. package/Particles/Node/nodeParticleBuildState.js +4 -4
  60. package/Particles/Node/nodeParticleBuildState.js.map +1 -1
  61. package/Particles/Node/nodeParticleSystemSet.helper.js +147 -144
  62. package/Particles/Node/nodeParticleSystemSet.helper.js.map +1 -1
  63. package/Particles/particle.d.ts +4 -0
  64. package/Particles/particle.js +2 -0
  65. package/Particles/particle.js.map +1 -1
  66. package/Particles/thinParticleSystem.d.ts +0 -4
  67. package/Particles/thinParticleSystem.function.d.ts +1 -1
  68. package/Particles/thinParticleSystem.function.js +9 -6
  69. package/Particles/thinParticleSystem.function.js.map +1 -1
  70. package/Particles/thinParticleSystem.js +1 -3
  71. package/Particles/thinParticleSystem.js.map +1 -1
  72. package/Shaders/ShadersInclude/gaussianSplatting.js +5 -1
  73. package/Shaders/ShadersInclude/gaussianSplatting.js.map +1 -1
  74. package/Shaders/ShadersInclude/gaussianSplattingUboDeclaration.js +2 -1
  75. package/Shaders/ShadersInclude/gaussianSplattingUboDeclaration.js.map +1 -1
  76. package/Shaders/ShadersInclude/gaussianSplattingVertexDeclaration.js +1 -1
  77. package/Shaders/ShadersInclude/gaussianSplattingVertexDeclaration.js.map +1 -1
  78. package/Shaders/gaussianSplatting.vertex.js +3 -3
  79. package/Shaders/gaussianSplatting.vertex.js.map +1 -1
  80. package/Shaders/gaussianSplattingDepth.vertex.js +2 -2
  81. package/Shaders/gaussianSplattingDepth.vertex.js.map +1 -1
  82. package/ShadersWGSL/ShadersInclude/gaussianSplatting.js +35 -1
  83. package/ShadersWGSL/ShadersInclude/gaussianSplatting.js.map +1 -1
  84. package/ShadersWGSL/ShadersInclude/gaussianSplattingUboDeclaration.js +2 -1
  85. package/ShadersWGSL/ShadersInclude/gaussianSplattingUboDeclaration.js.map +1 -1
  86. package/ShadersWGSL/ShadersInclude/gaussianSplattingVertexDeclaration.js +1 -2
  87. package/ShadersWGSL/ShadersInclude/gaussianSplattingVertexDeclaration.js.map +1 -1
  88. package/ShadersWGSL/gaussianSplatting.vertex.js +3 -3
  89. package/ShadersWGSL/gaussianSplatting.vertex.js.map +1 -1
  90. package/ShadersWGSL/gaussianSplattingDepth.vertex.js +2 -2
  91. package/ShadersWGSL/gaussianSplattingDepth.vertex.js.map +1 -1
  92. package/package.json +1 -1
@@ -1,66 +1,154 @@
1
1
  import { GeospatialCameraInputsManager } from "./geospatialCameraInputsManager.js";
2
2
  import { Vector3, Matrix, TmpVectors } from "../Maths/math.vector.js";
3
3
  import { Epsilon } from "../Maths/math.constants.js";
4
- import { Scalar } from "../Maths/math.scalar.js";
5
4
  import { Camera } from "./camera.js";
6
- import { Ray } from "../Culling/ray.js";
5
+ import { GeospatialLimits } from "./Limits/geospatialLimits.js";
6
+ import { ComputeLocalBasisToRefs, GeospatialCameraMovement } from "./geospatialCameraMovement.js";
7
+ import { Vector3CopyToRef, Vector3Dot } from "../Maths/math.vector.functions.js";
8
+ import { Clamp } from "../Maths/math.scalar.functions.js";
7
9
  /**
8
10
  * @experimental
9
11
  * This camera's movements are limited to a camera orbiting a globe, and as the API evolves it will introduce conversions between cartesian coordinates and true lat/long/alt
10
12
  *
11
13
  * Please note this is marked as experimental and the API (including the constructor!) will change until we remove that flag
12
- *
13
- * Still TODO:
14
- * - Pitch/yaw limits, input speeds
15
- * - ZoomToPoint
16
- * - Conversion between lat/long/alt and cartesian coordinates
17
14
  */
18
15
  export class GeospatialCamera extends Camera {
19
- /** The point on the globe that we are anchoring around. If no alternate rotation point is supplied, this will represent the center of screen*/
16
+ constructor(name, scene, options, pickPredicate) {
17
+ super(name, new Vector3(), scene);
18
+ // Temp vars
19
+ this._tempPosition = new Vector3();
20
+ this._viewMatrix = new Matrix();
21
+ this._lookAtVector = new Vector3();
22
+ this._center = new Vector3();
23
+ this._yaw = 0;
24
+ this._pitch = 0;
25
+ this._radius = 0;
26
+ this._tempVect = new Vector3();
27
+ this._tempEast = new Vector3();
28
+ this._tempNorth = new Vector3();
29
+ this._tempUp = new Vector3();
30
+ this._limits = new GeospatialLimits(options.planetRadius);
31
+ this._resetToDefault(this._limits);
32
+ this.movement = new GeospatialCameraMovement(scene, this._limits, this.position, this.center, this._lookAtVector, pickPredicate);
33
+ this.pickPredicate = pickPredicate;
34
+ this.inputs = new GeospatialCameraInputsManager(this);
35
+ this.inputs.addMouse().addMouseWheel().addKeyboard();
36
+ }
37
+ /** The point on the globe that we are anchoring around. If no alternate rotation point is present, this will represent the center of screen*/
20
38
  get center() {
21
- // NOTE that for now we are falling back to target if no pick on globe (because that shouldn't happen with current implemented inputs)
22
- // but eventually we want to return a point on the globe even if the camera is looking off into space
23
- return this._pickAlongLook?.pickedPoint ?? this._target;
39
+ return this._center;
40
+ }
41
+ /**
42
+ * Sets the camera position to orbit around a new center point
43
+ * @param center The world position (ECEF) to orbit around
44
+ */
45
+ set center(center) {
46
+ this._center.copyFromFloats(center.x, center.y, center.z);
47
+ this._setOrientation(this._yaw, this._pitch, this._radius, this._center);
48
+ }
49
+ /**
50
+ * Gets the camera's yaw (rotation around the geocentric normal) in radians
51
+ */
52
+ get yaw() {
53
+ return this._yaw;
54
+ }
55
+ /**
56
+ * Sets the camera's yaw (rotation around the geocentric normal)
57
+ * @param yaw The desired yaw angle in radians (0 = north, π/2 = east)
58
+ */
59
+ set yaw(yaw) {
60
+ this._setOrientation(yaw, this.pitch, this.radius, this.center);
24
61
  }
25
- /** Target of camera when looking along lookAtVector from current position. This does not necessarily represent a point on the globe */
26
- get _target() {
27
- return this.position.addToRef(this._lookAtVector, this._tempPosition);
62
+ /**
63
+ * Gets the camera's pitch (angle from looking straight at globe)
64
+ * Pitch is measured from looking straight down at planet center:
65
+ * - zero pitch = looking straight at planet center (down)
66
+ * - positive pitch = tilting up away from planet
67
+ * - π/2 pitch = looking at horizon (perpendicular to geocentric normal)
68
+ */
69
+ get pitch() {
70
+ return this._pitch;
71
+ }
72
+ /**
73
+ * Sets the camera's pitch (angle from looking straight at globe)
74
+ * @param pitch The desired pitch angle in radians (0 = looking at planet center, π/2 = looking at horizon)
75
+ */
76
+ set pitch(pitch) {
77
+ this._setOrientation(this.yaw, pitch, this.radius, this.center);
78
+ }
79
+ get radius() {
80
+ return this._radius;
81
+ }
82
+ /**
83
+ * Sets the camera's distance from the current center point
84
+ * @param radius The desired radius
85
+ */
86
+ set radius(radius) {
87
+ this._setOrientation(this.yaw, this.pitch, radius, this.center);
88
+ }
89
+ _checkLimits() {
90
+ const limits = this.limits;
91
+ this._yaw = Clamp(this._yaw, limits.yawMin, limits.yawMax);
92
+ this._pitch = Clamp(this._pitch, limits.pitchMin, limits.pitchMax);
93
+ this._radius = Clamp(this._radius, limits.radiusMin, limits.radiusMax);
94
+ }
95
+ _setOrientation(yaw, pitch, radius, center) {
96
+ this._yaw = yaw;
97
+ this._pitch = pitch;
98
+ this._radius = radius;
99
+ Vector3CopyToRef(center, this._center);
100
+ // Clamp to limits
101
+ this._checkLimits();
102
+ // Refresh local basis at center (treat these as read-only for the whole call)
103
+ ComputeLocalBasisToRefs(this._center, this._tempEast, this._tempNorth, this._tempUp);
104
+ // Trig
105
+ const yawScale = this._scene.useRightHandedSystem ? 1 : -1;
106
+ const cosYaw = Math.cos(this._yaw * yawScale);
107
+ const sinYaw = Math.sin(this._yaw * yawScale);
108
+ const sinPitch = Math.sin(this._pitch); // horizontal weight
109
+ const cosPitch = Math.cos(this._pitch); // vertical weight (toward center)
110
+ // Temps
111
+ const horiz = TmpVectors.Vector3[0];
112
+ const t1 = TmpVectors.Vector3[1];
113
+ const t2 = TmpVectors.Vector3[2];
114
+ const right = TmpVectors.Vector3[3];
115
+ // horizontalDirection = North*cosYaw + East*sinYaw (avoids mutating _temp basis vectors)
116
+ horiz.copyFrom(this._tempNorth).scaleInPlace(cosYaw).addInPlace(t1.copyFrom(this._tempEast).scaleInPlace(sinYaw));
117
+ // look = horiz*sinPitch - Up*cosPitch
118
+ this._lookAtVector.copyFrom(horiz).scaleInPlace(sinPitch).addInPlace(t2.copyFrom(this._tempUp).scaleInPlace(-cosPitch)).normalize(); // keep it unit
119
+ // Build an orthonormal up aligned with geocentric Up
120
+ // right = normalize(cross(upRef, look))
121
+ Vector3.CrossToRef(this._tempUp, this._lookAtVector, right);
122
+ // up = normalize(cross(look, right))
123
+ Vector3.CrossToRef(this._lookAtVector, right, this.upVector);
124
+ // Position = center - look * radius (preserve unit look)
125
+ this._tempVect.copyFrom(this._lookAtVector).scaleInPlace(-this._radius);
126
+ this._tempPosition.copyFrom(this._center).addInPlace(this._tempVect);
127
+ this._position.copyFrom(this._tempPosition);
128
+ this._isViewMatrixDirty = true;
28
129
  }
29
130
  /** The point around which the camera will geocentrically rotate. Uses center (pt we are anchored to) if no alternateRotationPt is defined */
30
131
  get _geocentricRotationPt() {
31
- return this._alternateRotationPt ?? this.center;
132
+ return this.movement.alternateRotationPt ?? this.center;
32
133
  }
33
- constructor(name, scene, options, pickPredicate) {
34
- super(name, Vector3.Zero(), scene);
35
- this._resetToDefault(options);
36
- this.pickPredicate = pickPredicate;
37
- this.inputs = new GeospatialCameraInputsManager(this);
38
- this.inputs.addMouse().addMouseWheel();
134
+ get limits() {
135
+ return this._limits;
39
136
  }
40
- _resetToDefault(options) {
137
+ _resetToDefault(limits) {
41
138
  // Camera configuration vars
42
- this._minAltitude = options.minAltitude ?? 5;
43
- this._maxAltitude = options.maxAltitude;
44
- this._planetRadius = options.planetRadius;
45
- this._maxCameraRadius = this._maxAltitude ? this._planetRadius + this._maxAltitude : undefined;
46
- this._restingAltitude = options.restingAltitude ?? this._maxCameraRadius ?? this._planetRadius * 4;
47
- this.position.copyFromFloats(0, 0, -this._restingAltitude);
48
- // Input vars
49
- this._perFrameGeocentricRotation = Vector3.Zero();
50
- this._perFrameGeocentricTranslation = Vector3.Zero();
51
- this._perFrameZoom = 0;
139
+ const maxCameraRadius = limits.altitudeMax !== undefined ? limits.planetRadius + limits.altitudeMax : undefined;
140
+ const restingAltitude = maxCameraRadius ?? limits.planetRadius * 4;
141
+ this.position.copyFromFloats(restingAltitude, 0, 0);
142
+ this._center.copyFromFloats(limits.planetRadius, 0, 0);
143
+ this._radius = Vector3.Distance(this.position, this.center);
52
144
  // Temp vars
53
- this._tempPosition = Vector3.Zero();
54
- this._tempRotationAxis = Vector3.Right(); // starting axis used to calculate pitch rotation matrix
55
- this._tempRotationMatrix = Matrix.Identity();
56
- this._tempGeocentricNormal = Vector3.Zero();
57
- this._tempPickingRay = new Ray(this.position, this._lookAtVector);
58
- this._tempPickingRay.direction = Vector3.Zero();
145
+ this._tempPosition = new Vector3();
59
146
  // View matrix calculation vars
60
- this.upVector = Vector3.Up(); // Up vector of the camera
61
- this._lookAtVector = this.position.negate().normalize(); // Lookat vector of the camera
62
147
  this._viewMatrix = Matrix.Identity();
148
+ this._center.subtractToRef(this._position, this._lookAtVector).normalize(); // Lookat vector of the camera
149
+ this.upVector = Vector3.Up(); // Up vector of the camera (does work for -X look at)
63
150
  this._isViewMatrixDirty = true;
151
+ this._setOrientation(this._yaw, this._pitch, this._radius, this._center);
64
152
  }
65
153
  /** @internal */
66
154
  _getViewMatrix() {
@@ -71,12 +159,12 @@ export class GeospatialCamera extends Camera {
71
159
  // Ensure vectors are normalized
72
160
  this.upVector.normalize();
73
161
  this._lookAtVector.normalize();
74
- // Calculate view matrix with camera position and target
162
+ // Calculate view matrix with camera position and center
75
163
  if (this.getScene().useRightHandedSystem) {
76
- Matrix.LookAtRHToRef(this.position, this._target, this.upVector, this._viewMatrix);
164
+ Matrix.LookAtRHToRef(this.position, this._center, this.upVector, this._viewMatrix);
77
165
  }
78
166
  else {
79
- Matrix.LookAtLHToRef(this.position, this._target, this.upVector, this._viewMatrix);
167
+ Matrix.LookAtLHToRef(this.position, this._center, this.upVector, this._viewMatrix);
80
168
  }
81
169
  return this._viewMatrix;
82
170
  }
@@ -87,133 +175,65 @@ export class GeospatialCamera extends Camera {
87
175
  }
88
176
  return true;
89
177
  }
90
- /**
91
- * Applies rotation correction to the camera by calculating a changeOfBasis matrix from the camera's current position to the new position
92
- * and transforming the lookAt and up vectors by that matrix before updating the camera position and marking the view matrix as dirty
93
- * @param newPos The camera's desired position, before correction is applied
94
- */
95
- _applyRotationCorrectionAndSetPos(newPos) {
96
- // Compute changeOfBasis between current camera position and new position
97
- ComputeChangeOfBasisToRef(this.position, newPos, this._tempRotationMatrix);
98
- // Apply rotation correction to lookat/up vectors
99
- Vector3.TransformNormalToRef(this._lookAtVector, this._tempRotationMatrix, this._lookAtVector);
100
- Vector3.TransformNormalToRef(this.upVector, this._tempRotationMatrix, this.upVector);
101
- // Apply position change and mark viewMatrix as dirty
102
- this.position.copyFrom(newPos);
103
- this._isViewMatrixDirty = true;
104
- }
105
- /**
106
- * When the geocentric normal has any translation change (due to dragging), we must ensure the camera remains orbiting around the world origin
107
- * We thus need to perform 2 correction steps
108
- * 1. Translation correction that keeps the camera at the same radius as before the drag
109
- * 2. Rotation correction that keeps the camera facing the globe (so that as we pan, the globe stays centered on screen)
110
- */
111
178
  _applyGeocentricTranslation() {
112
179
  // Store pending position (without any corrections applied)
113
- this.position.addToRef(this._perFrameGeocentricTranslation, this._tempPosition);
114
- // 1. Calculate the altitude correction to keep camera at the same radius when applying translation
115
- const tempPositionScaled = TmpVectors.Vector3[2];
116
- const offset = TmpVectors.Vector3[3];
117
- this._tempPosition.normalizeToRef(tempPositionScaled).scaleInPlace(this.position.length()); // what would tempPosition be if it were scaled to same radius as before
118
- this._tempPosition.subtractToRef(tempPositionScaled, offset); // find offset between tempPosition and the tempScaledPosition
119
- this._tempPosition.subtractInPlace(offset); // reduce tempPosition by that offset
120
- // 2. Calculate the rotation correction to keep camera facing globe
121
- this._applyRotationCorrectionAndSetPos(this._tempPosition);
180
+ this.center.addToRef(this.movement.panDeltaCurrentFrame, this._tempPosition);
181
+ if (!this.movement.isInterpolating) {
182
+ // Calculate the position correction to keep camera at the same radius when applying translation
183
+ this._tempPosition.normalize().scaleInPlace(this.center.length());
184
+ }
185
+ // Set center which will call _setOrientation
186
+ this.center = this._tempPosition;
122
187
  }
123
188
  /**
124
189
  * This rotation keeps the camera oriented towards the globe as it orbits around it. This is different from cameraCentricRotation which is when the camera rotates around its own axis
125
190
  */
126
191
  _applyGeocentricRotation() {
127
- // Normalize key vectors
128
- this._geocentricRotationPt.normalizeToRef(this._tempGeocentricNormal);
129
- this.upVector.normalize();
130
- this._lookAtVector.normalize();
131
- const pitchRotationMatrix = Matrix.Identity();
132
- const yawRotationMatrix = Matrix.Identity();
133
- // First apply pitch
134
- if (this._perFrameGeocentricRotation.x !== 0) {
135
- // Compute a rotation axis that is perpendicular to both the upVector and the geocentricNormalOfPitchPoint
136
- Vector3.CrossToRef(this.upVector, this._tempGeocentricNormal, this._tempRotationAxis);
137
- // If upVector and geocentricNormalOfPitchPoint are parallel, fall back to cross(lookAtDirection, geocentricNormalOfPitchPoint)
138
- if (this._tempRotationAxis.lengthSquared() <= Epsilon) {
139
- Vector3.CrossToRef(this._lookAtVector, this._tempGeocentricNormal, this._tempRotationAxis);
140
- }
141
- const pitchSign = Math.sign(Vector3.Dot(this._tempGeocentricNormal, this.upVector)); // If negative, camera is upside down
142
- // Since these are pointed in opposite directions, we must negate the dot product to get the proper angle
143
- const currentPitch = pitchSign * Math.acos(Scalar.Clamp(-Vector3.Dot(this._lookAtVector, this._tempGeocentricNormal), -1, 1));
144
- const newPitch = Scalar.Clamp(currentPitch + this._perFrameGeocentricRotation.x, 0, 0.5 * Math.PI - Epsilon);
145
- // Build rotation matrix around normalized axis
146
- Matrix.RotationAxisToRef(this._tempRotationAxis.normalize(), newPitch - currentPitch, pitchRotationMatrix);
147
- }
148
- // Then apply yaw
149
- if (this._perFrameGeocentricRotation.y !== 0) {
150
- Matrix.RotationAxisToRef(this._tempGeocentricNormal, this._perFrameGeocentricRotation.y, yawRotationMatrix); // this axis changes if we aren't using center of screen for tilt
151
- }
152
- pitchRotationMatrix.multiplyToRef(yawRotationMatrix, this._tempRotationMatrix);
153
- // Offset camera to be (position-pitchPoint) distance from geocentricOrigin, apply rotation to position/up/lookat vectors, then add back the pitchPoint offset
154
- this.position.subtractInPlace(this._geocentricRotationPt);
155
- Vector3.TransformCoordinatesToRef(this.position, this._tempRotationMatrix, this.position);
156
- Vector3.TransformNormalToRef(this.upVector, this._tempRotationMatrix, this.upVector);
157
- Vector3.TransformNormalToRef(this._lookAtVector, this._tempRotationMatrix, this._lookAtVector);
158
- this.position.addInPlace(this._geocentricRotationPt);
159
- }
160
- _clampZoomDistance(requestedDistance, pickResultDistance) {
161
- // If pickResult is defined
162
- if (requestedDistance > 0) {
163
- if (pickResultDistance !== undefined) {
164
- // If there is a pick, allow movement up to pick - minAltitude
165
- if (pickResultDistance - this._minAltitude < 0) {
166
- return 0;
167
- }
168
- return Math.min(requestedDistance, pickResultDistance - this._minAltitude);
169
- }
170
- else {
171
- return requestedDistance;
172
- }
173
- }
174
- if (requestedDistance < 0) {
175
- const maxZoomOut = this._maxCameraRadius ? this._maxCameraRadius - this.position.length() : Number.POSITIVE_INFINITY;
176
- return Math.max(requestedDistance, -maxZoomOut);
192
+ const currentFrameRotationDelta = this.movement.rotationDeltaCurrentFrame;
193
+ if (currentFrameRotationDelta.x !== 0 || currentFrameRotationDelta.y !== 0) {
194
+ const pitch = currentFrameRotationDelta.x !== 0 ? Clamp(this._pitch + currentFrameRotationDelta.x, 0, 0.5 * Math.PI - Epsilon) : this._pitch;
195
+ const yaw = currentFrameRotationDelta.y !== 0 ? this._yaw + currentFrameRotationDelta.y : this._yaw;
196
+ // TODO: If _geocentricRotationPt is not the center, this will need to be adjusted.
197
+ this._setOrientation(yaw, pitch, this._radius, this._geocentricRotationPt);
177
198
  }
178
- return 0;
179
199
  }
180
- _applyZoom(distance) {
181
- const pickResult = this._scene.pick(this._scene.pointerX, this._scene.pointerY, this.pickPredicate);
182
- if (pickResult.hit && pickResult.ray) {
183
- // Zoom to cursor
184
- this._moveCameraAlongVectorByDistance(pickResult.ray.direction, this._clampZoomDistance(distance, pickResult.distance));
185
- }
186
- else {
187
- // If no hit under cursor, zoom along lookVector instead
188
- this._moveCameraAlongVectorByDistance(this._lookAtVector, this._clampZoomDistance(distance, this._pickAlongLook?.distance));
189
- }
190
- }
191
- _moveCameraAlongVectorByDistance(vector, distance) {
192
- if (distance) {
193
- vector.scaleAndAddToRef(distance, this._tempPosition);
194
- this._applyRotationCorrectionAndSetPos(this._tempPosition);
195
- }
196
- }
197
- get _pickAlongLook() {
198
- this._tempPickingRay.origin.copyFrom(this.position);
199
- this._tempPickingRay.direction.copyFrom(this._lookAtVector);
200
- return this._scene.pickWithRay(this._tempPickingRay, this.pickPredicate);
200
+ _applyZoom(zoomVector, distance) {
201
+ // TODO this function will be re-worked shortly after checkin, becuase today it breaks down if you zoom to a point past the center
202
+ // (ex: tilted view zooming towards cursor near horizon where the center is closer than the cursor point).
203
+ // Project zoom vector onto lookAt vector to find the amount the camera-to-center distance should change.
204
+ // - zoom vector is normalized
205
+ // - distance is how much to move in this call
206
+ const directionDotLookAt = Vector3Dot(zoomVector, this._lookAtVector);
207
+ const hasRadialComponent = Math.abs(directionDotLookAt) > Epsilon;
208
+ const requestedRadius = hasRadialComponent ? this._radius - distance * directionDotLookAt : this._radius;
209
+ const newRadius = Clamp(requestedRadius, this.limits.radiusMin, this.limits.radiusMax);
210
+ const actualRadiusChange = newRadius - this._radius;
211
+ const actualDistanceChange = hasRadialComponent ? actualRadiusChange / directionDotLookAt : 0;
212
+ // Use this to compute new camera position and new center position.
213
+ const newCameraPosition = this._position.add(zoomVector.scale(-actualDistanceChange));
214
+ const newCenter = newCameraPosition.add(this._lookAtVector.scaleToRef(newRadius, TmpVectors.Vector3[3]));
215
+ // Rescale new center to maintain same altitude as the old center.
216
+ const currentCenterRadius = this._center.length();
217
+ const newCenterRadius = newCenter.length();
218
+ const newCenterRescale = currentCenterRadius / newCenterRadius;
219
+ newCenter.scaleInPlace(newCenterRescale);
220
+ // Apply changes
221
+ this._setOrientation(this._yaw, this._pitch, newRadius, newCenter);
201
222
  }
202
223
  _checkInputs() {
203
224
  this.inputs.checkInputs();
204
- if (this._perFrameGeocentricTranslation.lengthSquared() > 0) {
225
+ // Let movement class handle all per-frame logic
226
+ this.movement.computeCurrentFrameDeltas();
227
+ if (this.movement.panDeltaCurrentFrame.lengthSquared() > 0) {
205
228
  this._applyGeocentricTranslation();
206
- this._perFrameGeocentricTranslation.setAll(0);
207
229
  this._isViewMatrixDirty = true;
208
230
  }
209
- if (this._perFrameGeocentricRotation.lengthSquared() > 0) {
231
+ if (this.movement.rotationDeltaCurrentFrame.lengthSquared() > 0) {
210
232
  this._applyGeocentricRotation();
211
- this._perFrameGeocentricRotation.setAll(0);
212
233
  this._isViewMatrixDirty = true;
213
234
  }
214
- if (this._perFrameZoom !== 0) {
215
- this._applyZoom(this._perFrameZoom);
216
- this._perFrameZoom = 0;
235
+ if (Math.abs(this.movement.zoomDeltaCurrentFrame) > Epsilon) {
236
+ this._applyZoom(this.movement.computedPerFrameZoomVector, this.movement.zoomDeltaCurrentFrame);
217
237
  this._isViewMatrixDirty = true;
218
238
  }
219
239
  super._checkInputs();
@@ -225,44 +245,4 @@ export class GeospatialCamera extends Camera {
225
245
  this.inputs.detachElement();
226
246
  }
227
247
  }
228
- // Helper to build east/north/up basis vectors at a world position
229
- function ComputeLocalBasisToRefs(worldPos, refEast, refNorth, refUp) {
230
- // up = normalized position (geocentric normal)
231
- refUp.copyFrom(worldPos).normalize();
232
- // east = normalize(up × worldUp)
233
- // (cross product of up with world Y gives east except at poles)
234
- const worldUp = Vector3.Up(); // (0,1,0)
235
- Vector3.CrossToRef(refUp, worldUp, refEast);
236
- // at poles, cross with worldForward instead
237
- if (refEast.lengthSquared() < Epsilon) {
238
- Vector3.CrossToRef(refUp, Vector3.Forward(), refEast);
239
- }
240
- refEast.normalize();
241
- // north = up × east (completes right-handed basis)
242
- Vector3.CrossToRef(refUp, refEast, refNorth);
243
- refNorth.normalize();
244
- }
245
- /**
246
- * Calculates changeOfBasis matrix from currentPos to newPos and stores it in ref
247
- * @param currentPos
248
- * @param newPos
249
- * @param ref
250
- * @returns The changeOfBasis matrix from currentPos to newPos
251
- */
252
- function ComputeChangeOfBasisToRef(currentPos, newPos, ref) {
253
- const currentBasis = TmpVectors.Matrix[5];
254
- const newBasis = TmpVectors.Matrix[6];
255
- const inverse = TmpVectors.Matrix[7];
256
- const east = TmpVectors.Vector3[3];
257
- const north = TmpVectors.Vector3[4];
258
- const up = TmpVectors.Vector3[5];
259
- ComputeLocalBasisToRefs(currentPos, east, north, up);
260
- Matrix.FromXYZAxesToRef(east, north, up, currentBasis);
261
- ComputeLocalBasisToRefs(newPos, east, north, up);
262
- Matrix.FromXYZAxesToRef(east, north, up, newBasis);
263
- // Change of basis matrix = basis2 * basis1.inverse()
264
- // (since orthonormal, inverse = transpose)
265
- currentBasis.transposeToRef(inverse).multiplyToRef(newBasis, ref);
266
- return ref;
267
- }
268
248
  //# sourceMappingURL=geospatialCamera.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geospatialCamera.js","sourceRoot":"","sources":["../../../../dev/core/src/Cameras/geospatialCamera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAYrC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,gBAAiB,SAAQ,MAAM;IAoBxC,+IAA+I;IAC/I,IAAW,MAAM;QACb,sIAAsI;QACtI,qGAAqG;QACrG,OAAO,IAAI,CAAC,cAAc,EAAE,WAAW,IAAI,IAAI,CAAC,OAAO,CAAC;IAC5D,CAAC;IAoBD,uIAAuI;IACvI,IAAY,OAAO;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC1E,CAAC;IAED,6IAA6I;IAC7I,IAAY,qBAAqB;QAC7B,OAAO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;IAEpB,mDAAmD;IACnD,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7C,QAAQ,CAAC,SAAS,EAAE,CAAC;AACzB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,yBAAyB,CAAC,UAAmB,EAAE,MAAe,EAAE,GAAW;IAChF,MAAM,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAEjC,uBAAuB,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IACrD,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,YAAY,CAAC,CAAC;IAEvD,uBAAuB,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IACjD,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;IAEnD,qDAAqD;IACrD,2CAA2C;IAC3C,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAElE,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import { GeospatialCameraInputsManager } from \"./geospatialCameraInputsManager\";\r\nimport { Vector3, Matrix, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Epsilon } from \"../Maths/math.constants\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport { Camera } from \"./camera\";\r\nimport { Ray } from \"../Culling/ray\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { MeshPredicate } from \"../Culling/ray.core\";\r\nimport type { Nullable } from \"../types\";\r\n\r\ntype CameraOptions = {\r\n planetRadius: number; // Radius of the planet\r\n minAltitude?: number; // Minimum altitude of the camera above the planet surface\r\n maxAltitude?: number; // Maximum altitude of the camera above the planet surface\r\n restingAltitude?: number; // The altitude the camera will return to when not being actively zoomed in or out\r\n};\r\n\r\n/**\r\n * @experimental\r\n * This camera's movements are limited to a camera orbiting a globe, and as the API evolves it will introduce conversions between cartesian coordinates and true lat/long/alt\r\n *\r\n * Please note this is marked as experimental and the API (including the constructor!) will change until we remove that flag\r\n *\r\n * Still TODO:\r\n * - Pitch/yaw limits, input speeds\r\n * - ZoomToPoint\r\n * - Conversion between lat/long/alt and cartesian coordinates\r\n */\r\nexport class GeospatialCamera extends Camera {\r\n override inputs: GeospatialCameraInputsManager;\r\n\r\n // Changed by the inputs, reset on every frame\r\n /** @internal */\r\n public _perFrameGeocentricTranslation: Vector3; // Translation that keeps camera at the same radius from the center of the globe\r\n /** @internal */\r\n public _perFrameGeocentricRotation: Vector3; // Rotation around center (distinct from rotation around camera that can cause looking off into space)\r\n /** @internal */\r\n public _perFrameZoom: number;\r\n\r\n /** If supplied, will be used when picking the globe */\r\n public pickPredicate?: MeshPredicate;\r\n\r\n /**\r\n * Enables rotation around a specific point, instead of default rotation around center\r\n * @internal\r\n */\r\n public _alternateRotationPt: Nullable<Vector3>;\r\n\r\n /** The point on the globe that we are anchoring around. If no alternate rotation point is supplied, this will represent the center of screen*/\r\n public get center(): Vector3 {\r\n // NOTE that for now we are falling back to target if no pick on globe (because that shouldn't happen with current implemented inputs)\r\n // but eventually we want to return a point on the globe even if the camera is looking off into space\r\n return this._pickAlongLook?.pickedPoint ?? this._target;\r\n }\r\n\r\n // Temp vars\r\n private _tempGeocentricNormal: Vector3;\r\n private _tempRotationAxis: Vector3;\r\n private _tempRotationMatrix: Matrix;\r\n private _tempPickingRay: Ray;\r\n private _tempPosition: Vector3;\r\n\r\n private _viewMatrix: Matrix;\r\n private _isViewMatrixDirty: boolean;\r\n private _lookAtVector: Vector3;\r\n\r\n // Camera configuration vars\r\n private _planetRadius: number;\r\n private _minAltitude: number;\r\n private _maxAltitude?: number;\r\n private _maxCameraRadius?: number;\r\n private _restingAltitude: number;\r\n\r\n /** Target of camera when looking along lookAtVector from current position. This does not necessarily represent a point on the globe */\r\n private get _target(): Vector3 {\r\n return this.position.addToRef(this._lookAtVector, this._tempPosition);\r\n }\r\n\r\n /** The point around which the camera will geocentrically rotate. Uses center (pt we are anchored to) if no alternateRotationPt is defined */\r\n private get _geocentricRotationPt(): Vector3 {\r\n return this._alternateRotationPt ?? this.center;\r\n }\r\n\r\n constructor(name: string, scene: Scene, options: CameraOptions, pickPredicate?: MeshPredicate) {\r\n super(name, Vector3.Zero(), scene);\r\n this._resetToDefault(options);\r\n this.pickPredicate = pickPredicate;\r\n this.inputs = new GeospatialCameraInputsManager(this);\r\n this.inputs.addMouse().addMouseWheel();\r\n }\r\n\r\n private _resetToDefault(options: CameraOptions): void {\r\n // Camera configuration vars\r\n this._minAltitude = options.minAltitude ?? 5;\r\n this._maxAltitude = options.maxAltitude;\r\n this._planetRadius = options.planetRadius;\r\n this._maxCameraRadius = this._maxAltitude ? this._planetRadius + this._maxAltitude : undefined;\r\n this._restingAltitude = options.restingAltitude ?? this._maxCameraRadius ?? this._planetRadius * 4;\r\n this.position.copyFromFloats(0, 0, -this._restingAltitude);\r\n\r\n // Input vars\r\n this._perFrameGeocentricRotation = Vector3.Zero();\r\n this._perFrameGeocentricTranslation = Vector3.Zero();\r\n this._perFrameZoom = 0;\r\n\r\n // Temp vars\r\n this._tempPosition = Vector3.Zero();\r\n this._tempRotationAxis = Vector3.Right(); // starting axis used to calculate pitch rotation matrix\r\n this._tempRotationMatrix = Matrix.Identity();\r\n this._tempGeocentricNormal = Vector3.Zero();\r\n this._tempPickingRay = new Ray(this.position, this._lookAtVector);\r\n this._tempPickingRay.direction = Vector3.Zero();\r\n\r\n // View matrix calculation vars\r\n this.upVector = Vector3.Up(); // Up vector of the camera\r\n this._lookAtVector = this.position.negate().normalize(); // Lookat vector of the camera\r\n this._viewMatrix = Matrix.Identity();\r\n this._isViewMatrixDirty = true;\r\n }\r\n\r\n /** @internal */\r\n override _getViewMatrix() {\r\n if (!this._isViewMatrixDirty) {\r\n return this._viewMatrix;\r\n }\r\n this._isViewMatrixDirty = false;\r\n\r\n // Ensure vectors are normalized\r\n this.upVector.normalize();\r\n this._lookAtVector.normalize();\r\n\r\n // Calculate view matrix with camera position and target\r\n if (this.getScene().useRightHandedSystem) {\r\n Matrix.LookAtRHToRef(this.position, this._target, this.upVector, this._viewMatrix);\r\n } else {\r\n Matrix.LookAtLHToRef(this.position, this._target, this.upVector, this._viewMatrix);\r\n }\r\n\r\n return this._viewMatrix;\r\n }\r\n\r\n /** @internal */\r\n override _isSynchronizedViewMatrix(): boolean {\r\n if (!super._isSynchronizedViewMatrix() || this._isViewMatrixDirty) {\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Applies rotation correction to the camera by calculating a changeOfBasis matrix from the camera's current position to the new position\r\n * and transforming the lookAt and up vectors by that matrix before updating the camera position and marking the view matrix as dirty\r\n * @param newPos The camera's desired position, before correction is applied\r\n */\r\n private _applyRotationCorrectionAndSetPos(newPos: Vector3): void {\r\n // Compute changeOfBasis between current camera position and new position\r\n ComputeChangeOfBasisToRef(this.position, newPos, this._tempRotationMatrix);\r\n\r\n // Apply rotation correction to lookat/up vectors\r\n Vector3.TransformNormalToRef(this._lookAtVector, this._tempRotationMatrix, this._lookAtVector);\r\n Vector3.TransformNormalToRef(this.upVector, this._tempRotationMatrix, this.upVector);\r\n\r\n // Apply position change and mark viewMatrix as dirty\r\n this.position.copyFrom(newPos);\r\n this._isViewMatrixDirty = true;\r\n }\r\n\r\n /**\r\n * When the geocentric normal has any translation change (due to dragging), we must ensure the camera remains orbiting around the world origin\r\n * We thus need to perform 2 correction steps\r\n * 1. Translation correction that keeps the camera at the same radius as before the drag\r\n * 2. Rotation correction that keeps the camera facing the globe (so that as we pan, the globe stays centered on screen)\r\n */\r\n private _applyGeocentricTranslation() {\r\n // Store pending position (without any corrections applied)\r\n this.position.addToRef(this._perFrameGeocentricTranslation, this._tempPosition);\r\n\r\n // 1. Calculate the altitude correction to keep camera at the same radius when applying translation\r\n const tempPositionScaled = TmpVectors.Vector3[2];\r\n const offset = TmpVectors.Vector3[3];\r\n this._tempPosition.normalizeToRef(tempPositionScaled).scaleInPlace(this.position.length()); // what would tempPosition be if it were scaled to same radius as before\r\n this._tempPosition.subtractToRef(tempPositionScaled, offset); // find offset between tempPosition and the tempScaledPosition\r\n this._tempPosition.subtractInPlace(offset); // reduce tempPosition by that offset\r\n\r\n // 2. Calculate the rotation correction to keep camera facing globe\r\n this._applyRotationCorrectionAndSetPos(this._tempPosition);\r\n }\r\n\r\n /**\r\n * This rotation keeps the camera oriented towards the globe as it orbits around it. This is different from cameraCentricRotation which is when the camera rotates around its own axis\r\n */\r\n private _applyGeocentricRotation(): void {\r\n // Normalize key vectors\r\n this._geocentricRotationPt.normalizeToRef(this._tempGeocentricNormal);\r\n this.upVector.normalize();\r\n this._lookAtVector.normalize();\r\n\r\n const pitchRotationMatrix = Matrix.Identity();\r\n const yawRotationMatrix = Matrix.Identity();\r\n // First apply pitch\r\n if (this._perFrameGeocentricRotation.x !== 0) {\r\n // Compute a rotation axis that is perpendicular to both the upVector and the geocentricNormalOfPitchPoint\r\n Vector3.CrossToRef(this.upVector, this._tempGeocentricNormal, this._tempRotationAxis);\r\n\r\n // If upVector and geocentricNormalOfPitchPoint are parallel, fall back to cross(lookAtDirection, geocentricNormalOfPitchPoint)\r\n if (this._tempRotationAxis.lengthSquared() <= Epsilon) {\r\n Vector3.CrossToRef(this._lookAtVector, this._tempGeocentricNormal, this._tempRotationAxis);\r\n }\r\n\r\n const pitchSign = Math.sign(Vector3.Dot(this._tempGeocentricNormal, this.upVector)); // If negative, camera is upside down\r\n // Since these are pointed in opposite directions, we must negate the dot product to get the proper angle\r\n const currentPitch = pitchSign * Math.acos(Scalar.Clamp(-Vector3.Dot(this._lookAtVector, this._tempGeocentricNormal), -1, 1));\r\n const newPitch = Scalar.Clamp(currentPitch + this._perFrameGeocentricRotation.x, 0, 0.5 * Math.PI - Epsilon);\r\n // Build rotation matrix around normalized axis\r\n Matrix.RotationAxisToRef(this._tempRotationAxis.normalize(), newPitch - currentPitch, pitchRotationMatrix);\r\n }\r\n\r\n // Then apply yaw\r\n if (this._perFrameGeocentricRotation.y !== 0) {\r\n Matrix.RotationAxisToRef(this._tempGeocentricNormal, this._perFrameGeocentricRotation.y, yawRotationMatrix); // this axis changes if we aren't using center of screen for tilt\r\n }\r\n pitchRotationMatrix.multiplyToRef(yawRotationMatrix, this._tempRotationMatrix);\r\n\r\n // Offset camera to be (position-pitchPoint) distance from geocentricOrigin, apply rotation to position/up/lookat vectors, then add back the pitchPoint offset\r\n this.position.subtractInPlace(this._geocentricRotationPt);\r\n\r\n Vector3.TransformCoordinatesToRef(this.position, this._tempRotationMatrix, this.position);\r\n Vector3.TransformNormalToRef(this.upVector, this._tempRotationMatrix, this.upVector);\r\n Vector3.TransformNormalToRef(this._lookAtVector, this._tempRotationMatrix, this._lookAtVector);\r\n\r\n this.position.addInPlace(this._geocentricRotationPt);\r\n }\r\n\r\n private _clampZoomDistance(requestedDistance: number, pickResultDistance: number | undefined): number {\r\n // If pickResult is defined\r\n if (requestedDistance > 0) {\r\n if (pickResultDistance !== undefined) {\r\n // If there is a pick, allow movement up to pick - minAltitude\r\n if (pickResultDistance - this._minAltitude < 0) {\r\n return 0;\r\n }\r\n return Math.min(requestedDistance, pickResultDistance - this._minAltitude);\r\n } else {\r\n return requestedDistance;\r\n }\r\n }\r\n\r\n if (requestedDistance < 0) {\r\n const maxZoomOut = this._maxCameraRadius ? this._maxCameraRadius - this.position.length() : Number.POSITIVE_INFINITY;\r\n return Math.max(requestedDistance, -maxZoomOut);\r\n }\r\n return 0;\r\n }\r\n\r\n private _applyZoom(distance: number) {\r\n const pickResult = this._scene.pick(this._scene.pointerX, this._scene.pointerY, this.pickPredicate);\r\n if (pickResult.hit && pickResult.ray) {\r\n // Zoom to cursor\r\n this._moveCameraAlongVectorByDistance(pickResult.ray.direction, this._clampZoomDistance(distance, pickResult.distance));\r\n } else {\r\n // If no hit under cursor, zoom along lookVector instead\r\n this._moveCameraAlongVectorByDistance(this._lookAtVector, this._clampZoomDistance(distance, this._pickAlongLook?.distance));\r\n }\r\n }\r\n\r\n private _moveCameraAlongVectorByDistance(vector: Vector3, distance: number) {\r\n if (distance) {\r\n vector.scaleAndAddToRef(distance, this._tempPosition);\r\n this._applyRotationCorrectionAndSetPos(this._tempPosition);\r\n }\r\n }\r\n\r\n private get _pickAlongLook() {\r\n this._tempPickingRay.origin.copyFrom(this.position);\r\n this._tempPickingRay.direction.copyFrom(this._lookAtVector);\r\n return this._scene.pickWithRay(this._tempPickingRay, this.pickPredicate);\r\n }\r\n\r\n override _checkInputs(): void {\r\n this.inputs.checkInputs();\r\n if (this._perFrameGeocentricTranslation.lengthSquared() > 0) {\r\n this._applyGeocentricTranslation();\r\n this._perFrameGeocentricTranslation.setAll(0);\r\n this._isViewMatrixDirty = true;\r\n }\r\n if (this._perFrameGeocentricRotation.lengthSquared() > 0) {\r\n this._applyGeocentricRotation();\r\n this._perFrameGeocentricRotation.setAll(0);\r\n this._isViewMatrixDirty = true;\r\n }\r\n if (this._perFrameZoom !== 0) {\r\n this._applyZoom(this._perFrameZoom);\r\n this._perFrameZoom = 0;\r\n this._isViewMatrixDirty = true;\r\n }\r\n super._checkInputs();\r\n }\r\n\r\n override attachControl(noPreventDefault?: boolean): void {\r\n this.inputs.attachElement(noPreventDefault);\r\n }\r\n\r\n override detachControl(): void {\r\n this.inputs.detachElement();\r\n }\r\n}\r\n\r\n// Helper to build east/north/up basis vectors at a world position\r\nfunction ComputeLocalBasisToRefs(worldPos: Vector3, refEast: Vector3, refNorth: Vector3, refUp: Vector3) {\r\n // up = normalized position (geocentric normal)\r\n refUp.copyFrom(worldPos).normalize();\r\n\r\n // east = normalize(up × worldUp)\r\n // (cross product of up with world Y gives east except at poles)\r\n const worldUp = Vector3.Up(); // (0,1,0)\r\n Vector3.CrossToRef(refUp, worldUp, refEast);\r\n\r\n // at poles, cross with worldForward instead\r\n if (refEast.lengthSquared() < Epsilon) {\r\n Vector3.CrossToRef(refUp, Vector3.Forward(), refEast);\r\n }\r\n refEast.normalize();\r\n\r\n // north = up × east (completes right-handed basis)\r\n Vector3.CrossToRef(refUp, refEast, refNorth);\r\n refNorth.normalize();\r\n}\r\n\r\n/**\r\n * Calculates changeOfBasis matrix from currentPos to newPos and stores it in ref\r\n * @param currentPos\r\n * @param newPos\r\n * @param ref\r\n * @returns The changeOfBasis matrix from currentPos to newPos\r\n */\r\nfunction ComputeChangeOfBasisToRef(currentPos: Vector3, newPos: Vector3, ref: Matrix): Matrix {\r\n const currentBasis = TmpVectors.Matrix[5];\r\n const newBasis = TmpVectors.Matrix[6];\r\n const inverse = TmpVectors.Matrix[7];\r\n const east = TmpVectors.Vector3[3];\r\n const north = TmpVectors.Vector3[4];\r\n const up = TmpVectors.Vector3[5];\r\n\r\n ComputeLocalBasisToRefs(currentPos, east, north, up);\r\n Matrix.FromXYZAxesToRef(east, north, up, currentBasis);\r\n\r\n ComputeLocalBasisToRefs(newPos, east, north, up);\r\n Matrix.FromXYZAxesToRef(east, north, up, newBasis);\r\n\r\n // Change of basis matrix = basis2 * basis1.inverse()\r\n // (since orthonormal, inverse = transpose)\r\n currentBasis.transposeToRef(inverse).multiplyToRef(newBasis, ref);\r\n\r\n return ref;\r\n}\r\n"]}
1
+ {"version":3,"file":"geospatialCamera.js","sourceRoot":"","sources":["../../../../dev/core/src/Cameras/geospatialCamera.ts"],"names":[],"mappings":"AAAA,O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0B;QAC7C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAChD,CAAC;IAEQ,aAAa;QAClB,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;IAChC,CAAC;CACJ","sourcesContent":["import { GeospatialCameraInputsManager } from \"./geospatialCameraInputsManager\";\r\nimport { Vector3, Matrix, TmpVectors } from \"../Maths/math.vector\";\r\nimport { Epsilon } from \"../Maths/math.constants\";\r\nimport { Camera } from \"./camera\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { MeshPredicate } from \"../Culling/ray.core\";\r\nimport type { DeepImmutable } from \"../types\";\r\nimport { GeospatialLimits } from \"./Limits/geospatialLimits\";\r\nimport { ComputeLocalBasisToRefs, GeospatialCameraMovement } from \"./geospatialCameraMovement\";\r\nimport type { IVector3Like } from \"../Maths/math.like\";\r\nimport { Vector3CopyToRef, Vector3Dot } from \"../Maths/math.vector.functions\";\r\nimport { Clamp } from \"../Maths/math.scalar.functions\";\r\n\r\ntype CameraOptions = {\r\n planetRadius: number; // Radius of the planet\r\n};\r\n\r\n/**\r\n * @experimental\r\n * This camera's movements are limited to a camera orbiting a globe, and as the API evolves it will introduce conversions between cartesian coordinates and true lat/long/alt\r\n *\r\n * Please note this is marked as experimental and the API (including the constructor!) will change until we remove that flag\r\n */\r\nexport class GeospatialCamera extends Camera {\r\n override inputs: GeospatialCameraInputsManager;\r\n\r\n /** If supplied, will be used when picking the globe */\r\n public pickPredicate?: MeshPredicate;\r\n\r\n /** Movement controller that turns input pixelDeltas into currentFrameDeltas used by camera*/\r\n public readonly movement: GeospatialCameraMovement;\r\n\r\n // Temp vars\r\n private _tempPosition: Vector3 = new Vector3();\r\n\r\n private _viewMatrix = new Matrix();\r\n private _isViewMatrixDirty: boolean;\r\n private _lookAtVector: Vector3 = new Vector3();\r\n\r\n constructor(name: string, scene: Scene, options: CameraOptions, pickPredicate?: MeshPredicate) {\r\n super(name, new Vector3(), scene);\r\n\r\n this._limits = new GeospatialLimits(options.planetRadius);\r\n this._resetToDefault(this._limits);\r\n\r\n this.movement = new GeospatialCameraMovement(scene, this._limits, this.position, this.center, this._lookAtVector, pickPredicate);\r\n\r\n this.pickPredicate = pickPredicate;\r\n this.inputs = new GeospatialCameraInputsManager(this);\r\n this.inputs.addMouse().addMouseWheel().addKeyboard();\r\n }\r\n\r\n private _center: Vector3 = new Vector3();\r\n /** The point on the globe that we are anchoring around. If no alternate rotation point is present, this will represent the center of screen*/\r\n public get center(): Vector3 {\r\n return this._center;\r\n }\r\n\r\n /**\r\n * Sets the camera position to orbit around a new center point\r\n * @param center The world position (ECEF) to orbit around\r\n */\r\n public set center(center: IVector3Like) {\r\n this._center.copyFromFloats(center.x, center.y, center.z);\r\n this._setOrientation(this._yaw, this._pitch, this._radius, this._center);\r\n }\r\n\r\n private _yaw: number = 0;\r\n /**\r\n * Gets the camera's yaw (rotation around the geocentric normal) in radians\r\n */\r\n public get yaw(): number {\r\n return this._yaw;\r\n }\r\n\r\n /**\r\n * Sets the camera's yaw (rotation around the geocentric normal)\r\n * @param yaw The desired yaw angle in radians (0 = north, π/2 = east)\r\n */\r\n public set yaw(yaw: number) {\r\n this._setOrientation(yaw, this.pitch, this.radius, this.center);\r\n }\r\n\r\n private _pitch: number = 0;\r\n\r\n /**\r\n * Gets the camera's pitch (angle from looking straight at globe)\r\n * Pitch is measured from looking straight down at planet center:\r\n * - zero pitch = looking straight at planet center (down)\r\n * - positive pitch = tilting up away from planet\r\n * - π/2 pitch = looking at horizon (perpendicular to geocentric normal)\r\n */\r\n public get pitch(): number {\r\n return this._pitch;\r\n }\r\n\r\n /**\r\n * Sets the camera's pitch (angle from looking straight at globe)\r\n * @param pitch The desired pitch angle in radians (0 = looking at planet center, π/2 = looking at horizon)\r\n */\r\n public set pitch(pitch: number) {\r\n this._setOrientation(this.yaw, pitch, this.radius, this.center);\r\n }\r\n\r\n private _radius: number = 0;\r\n public get radius(): number {\r\n return this._radius;\r\n }\r\n\r\n /**\r\n * Sets the camera's distance from the current center point\r\n * @param radius The desired radius\r\n */\r\n public set radius(radius: number) {\r\n this._setOrientation(this.yaw, this.pitch, radius, this.center);\r\n }\r\n\r\n protected _checkLimits() {\r\n const limits = this.limits;\r\n this._yaw = Clamp(this._yaw, limits.yawMin, limits.yawMax);\r\n this._pitch = Clamp(this._pitch, limits.pitchMin, limits.pitchMax);\r\n this._radius = Clamp(this._radius, limits.radiusMin, limits.radiusMax);\r\n }\r\n\r\n private _tempVect = new Vector3();\r\n private _tempEast = new Vector3();\r\n private _tempNorth = new Vector3();\r\n private _tempUp = new Vector3();\r\n\r\n private _setOrientation(yaw: number, pitch: number, radius: number, center: DeepImmutable<IVector3Like>): void {\r\n this._yaw = yaw;\r\n this._pitch = pitch;\r\n this._radius = radius;\r\n\r\n Vector3CopyToRef(center, this._center);\r\n\r\n // Clamp to limits\r\n this._checkLimits();\r\n\r\n // Refresh local basis at center (treat these as read-only for the whole call)\r\n ComputeLocalBasisToRefs(this._center, this._tempEast, this._tempNorth, this._tempUp);\r\n\r\n // Trig\r\n const yawScale = this._scene.useRightHandedSystem ? 1 : -1;\r\n const cosYaw = Math.cos(this._yaw * yawScale);\r\n const sinYaw = Math.sin(this._yaw * yawScale);\r\n const sinPitch = Math.sin(this._pitch); // horizontal weight\r\n const cosPitch = Math.cos(this._pitch); // vertical weight (toward center)\r\n\r\n // Temps\r\n const horiz = TmpVectors.Vector3[0];\r\n const t1 = TmpVectors.Vector3[1];\r\n const t2 = TmpVectors.Vector3[2];\r\n const right = TmpVectors.Vector3[3];\r\n\r\n // horizontalDirection = North*cosYaw + East*sinYaw (avoids mutating _temp basis vectors)\r\n horiz.copyFrom(this._tempNorth).scaleInPlace(cosYaw).addInPlace(t1.copyFrom(this._tempEast).scaleInPlace(sinYaw));\r\n\r\n // look = horiz*sinPitch - Up*cosPitch\r\n this._lookAtVector.copyFrom(horiz).scaleInPlace(sinPitch).addInPlace(t2.copyFrom(this._tempUp).scaleInPlace(-cosPitch)).normalize(); // keep it unit\r\n\r\n // Build an orthonormal up aligned with geocentric Up\r\n // right = normalize(cross(upRef, look))\r\n Vector3.CrossToRef(this._tempUp, this._lookAtVector, right);\r\n\r\n // up = normalize(cross(look, right))\r\n Vector3.CrossToRef(this._lookAtVector, right, this.upVector);\r\n\r\n // Position = center - look * radius (preserve unit look)\r\n this._tempVect.copyFrom(this._lookAtVector).scaleInPlace(-this._radius);\r\n this._tempPosition.copyFrom(this._center).addInPlace(this._tempVect);\r\n\r\n this._position.copyFrom(this._tempPosition);\r\n\r\n this._isViewMatrixDirty = true;\r\n }\r\n\r\n /** The point around which the camera will geocentrically rotate. Uses center (pt we are anchored to) if no alternateRotationPt is defined */\r\n private get _geocentricRotationPt(): Vector3 {\r\n return this.movement.alternateRotationPt ?? this.center;\r\n }\r\n\r\n private _limits: GeospatialLimits;\r\n public get limits(): GeospatialLimits {\r\n return this._limits;\r\n }\r\n\r\n private _resetToDefault(limits: GeospatialLimits): void {\r\n // Camera configuration vars\r\n const maxCameraRadius = limits.altitudeMax !== undefined ? limits.planetRadius + limits.altitudeMax : undefined;\r\n const restingAltitude = maxCameraRadius ?? limits.planetRadius * 4;\r\n this.position.copyFromFloats(restingAltitude, 0, 0);\r\n this._center.copyFromFloats(limits.planetRadius, 0, 0);\r\n this._radius = Vector3.Distance(this.position, this.center);\r\n\r\n // Temp vars\r\n this._tempPosition = new Vector3();\r\n\r\n // View matrix calculation vars\r\n this._viewMatrix = Matrix.Identity();\r\n this._center.subtractToRef(this._position, this._lookAtVector).normalize(); // Lookat vector of the camera\r\n this.upVector = Vector3.Up(); // Up vector of the camera (does work for -X look at)\r\n this._isViewMatrixDirty = true;\r\n\r\n this._setOrientation(this._yaw, this._pitch, this._radius, this._center);\r\n }\r\n\r\n /** @internal */\r\n override _getViewMatrix() {\r\n if (!this._isViewMatrixDirty) {\r\n return this._viewMatrix;\r\n }\r\n this._isViewMatrixDirty = false;\r\n\r\n // Ensure vectors are normalized\r\n this.upVector.normalize();\r\n this._lookAtVector.normalize();\r\n\r\n // Calculate view matrix with camera position and center\r\n if (this.getScene().useRightHandedSystem) {\r\n Matrix.LookAtRHToRef(this.position, this._center, this.upVector, this._viewMatrix);\r\n } else {\r\n Matrix.LookAtLHToRef(this.position, this._center, this.upVector, this._viewMatrix);\r\n }\r\n\r\n return this._viewMatrix;\r\n }\r\n\r\n /** @internal */\r\n override _isSynchronizedViewMatrix(): boolean {\r\n if (!super._isSynchronizedViewMatrix() || this._isViewMatrixDirty) {\r\n return false;\r\n }\r\n return true;\r\n }\r\n\r\n private _applyGeocentricTranslation() {\r\n // Store pending position (without any corrections applied)\r\n this.center.addToRef(this.movement.panDeltaCurrentFrame, this._tempPosition);\r\n\r\n if (!this.movement.isInterpolating) {\r\n // Calculate the position correction to keep camera at the same radius when applying translation\r\n this._tempPosition.normalize().scaleInPlace(this.center.length());\r\n }\r\n // Set center which will call _setOrientation\r\n this.center = this._tempPosition;\r\n }\r\n\r\n /**\r\n * This rotation keeps the camera oriented towards the globe as it orbits around it. This is different from cameraCentricRotation which is when the camera rotates around its own axis\r\n */\r\n private _applyGeocentricRotation(): void {\r\n const currentFrameRotationDelta = this.movement.rotationDeltaCurrentFrame;\r\n if (currentFrameRotationDelta.x !== 0 || currentFrameRotationDelta.y !== 0) {\r\n const pitch = currentFrameRotationDelta.x !== 0 ? Clamp(this._pitch + currentFrameRotationDelta.x, 0, 0.5 * Math.PI - Epsilon) : this._pitch;\r\n const yaw = currentFrameRotationDelta.y !== 0 ? this._yaw + currentFrameRotationDelta.y : this._yaw;\r\n\r\n // TODO: If _geocentricRotationPt is not the center, this will need to be adjusted.\r\n this._setOrientation(yaw, pitch, this._radius, this._geocentricRotationPt);\r\n }\r\n }\r\n\r\n private _applyZoom(zoomVector: Vector3, distance: number) {\r\n // TODO this function will be re-worked shortly after checkin, becuase today it breaks down if you zoom to a point past the center\r\n // (ex: tilted view zooming towards cursor near horizon where the center is closer than the cursor point).\r\n\r\n // Project zoom vector onto lookAt vector to find the amount the camera-to-center distance should change.\r\n // - zoom vector is normalized\r\n // - distance is how much to move in this call\r\n const directionDotLookAt = Vector3Dot(zoomVector, this._lookAtVector);\r\n const hasRadialComponent = Math.abs(directionDotLookAt) > Epsilon;\r\n const requestedRadius = hasRadialComponent ? this._radius - distance * directionDotLookAt : this._radius;\r\n const newRadius = Clamp(requestedRadius, this.limits.radiusMin, this.limits.radiusMax);\r\n const actualRadiusChange = newRadius - this._radius;\r\n const actualDistanceChange = hasRadialComponent ? actualRadiusChange / directionDotLookAt : 0;\r\n\r\n // Use this to compute new camera position and new center position.\r\n const newCameraPosition = this._position.add(zoomVector.scale(-actualDistanceChange));\r\n const newCenter = newCameraPosition.add(this._lookAtVector.scaleToRef(newRadius, TmpVectors.Vector3[3]));\r\n\r\n // Rescale new center to maintain same altitude as the old center.\r\n const currentCenterRadius = this._center.length();\r\n const newCenterRadius = newCenter.length();\r\n const newCenterRescale = currentCenterRadius / newCenterRadius;\r\n newCenter.scaleInPlace(newCenterRescale);\r\n\r\n // Apply changes\r\n this._setOrientation(this._yaw, this._pitch, newRadius, newCenter);\r\n }\r\n\r\n override _checkInputs(): void {\r\n this.inputs.checkInputs();\r\n\r\n // Let movement class handle all per-frame logic\r\n this.movement.computeCurrentFrameDeltas();\r\n\r\n if (this.movement.panDeltaCurrentFrame.lengthSquared() > 0) {\r\n this._applyGeocentricTranslation();\r\n this._isViewMatrixDirty = true;\r\n }\r\n if (this.movement.rotationDeltaCurrentFrame.lengthSquared() > 0) {\r\n this._applyGeocentricRotation();\r\n this._isViewMatrixDirty = true;\r\n }\r\n\r\n if (Math.abs(this.movement.zoomDeltaCurrentFrame) > Epsilon) {\r\n this._applyZoom(this.movement.computedPerFrameZoomVector, this.movement.zoomDeltaCurrentFrame);\r\n this._isViewMatrixDirty = true;\r\n }\r\n\r\n super._checkInputs();\r\n }\r\n\r\n override attachControl(noPreventDefault?: boolean): void {\r\n this.inputs.attachElement(noPreventDefault);\r\n }\r\n\r\n override detachControl(): void {\r\n this.inputs.detachElement();\r\n }\r\n}\r\n"]}
@@ -20,4 +20,9 @@ export declare class GeospatialCameraInputsManager extends CameraInputsManager<G
20
20
  * @returns the current input manager
21
21
  */
22
22
  addMouseWheel(): GeospatialCameraInputsManager;
23
+ /**
24
+ * Add mouse wheel input support to the input manager
25
+ * @returns the current input manager
26
+ */
27
+ addKeyboard(): GeospatialCameraInputsManager;
23
28
  }
@@ -1,6 +1,7 @@
1
1
  import { CameraInputsManager } from "./cameraInputsManager.js";
2
2
  import { GeospatialCameraPointersInput } from "./Inputs/geospatialCameraPointersInput.js";
3
3
  import { GeospatialCameraMouseWheelInput } from "./Inputs/geospatialCameraMouseWheelInput.js";
4
+ import { GeospatialCameraKeyboardInput } from "./Inputs/geospatialCameraKeyboardInput.js";
4
5
  /**
5
6
  * Default Inputs manager for the GeospatialCamera.
6
7
  * It groups all the default supported inputs for ease of use.
@@ -29,5 +30,13 @@ export class GeospatialCameraInputsManager extends CameraInputsManager {
29
30
  this.add(new GeospatialCameraMouseWheelInput());
30
31
  return this;
31
32
  }
33
+ /**
34
+ * Add mouse wheel input support to the input manager
35
+ * @returns the current input manager
36
+ */
37
+ addKeyboard() {
38
+ this.add(new GeospatialCameraKeyboardInput());
39
+ return this;
40
+ }
32
41
  }
33
42
  //# sourceMappingURL=geospatialCameraInputsManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geospatialCameraInputsManager.js","sourceRoot":"","sources":["../../../../dev/core/src/Cameras/geospatialCameraInputsManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAC;AAE3F;;;GAGG;AACH,MAAM,OAAO,6BAA8B,SAAQ,mBAAqC;IACpF;;;OAGG;IACH,YAAY,MAAwB;QAChC,KAAK,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAED;;;OAGG;IACI,QAAQ;QACX,IAAI,CAAC,GAAG,CAAC,IAAI,6BAA6B,EAAE,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACI,aAAa;QAChB,IAAI,CAAC,GAAG,CAAC,IAAI,+BAA+B,EAAE,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import { CameraInputsManager } from \"./cameraInputsManager\";\r\nimport type { GeospatialCamera } from \"./geospatialCamera\";\r\nimport { GeospatialCameraPointersInput } from \"./Inputs/geospatialCameraPointersInput\";\r\nimport { GeospatialCameraMouseWheelInput } from \"./Inputs/geospatialCameraMouseWheelInput\";\r\n\r\n/**\r\n * Default Inputs manager for the GeospatialCamera.\r\n * It groups all the default supported inputs for ease of use.\r\n */\r\nexport class GeospatialCameraInputsManager extends CameraInputsManager<GeospatialCamera> {\r\n /**\r\n * Instantiates a new GeospatialCameraInputsManager.\r\n * @param camera Defines the camera the inputs belong to\r\n */\r\n constructor(camera: GeospatialCamera) {\r\n super(camera);\r\n }\r\n\r\n /**\r\n * Add mouse input support to the input manager\r\n * @returns the current input manager\r\n */\r\n public addMouse(): GeospatialCameraInputsManager {\r\n this.add(new GeospatialCameraPointersInput());\r\n return this;\r\n }\r\n\r\n /**\r\n * Add mouse wheel input support to the input manager\r\n * @returns the current input manager\r\n */\r\n public addMouseWheel(): GeospatialCameraInputsManager {\r\n this.add(new GeospatialCameraMouseWheelInput());\r\n return this;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"geospatialCameraInputsManager.js","sourceRoot":"","sources":["../../../../dev/core/src/Cameras/geospatialCameraInputsManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAC;AAC3F,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAEvF;;;GAGG;AACH,MAAM,OAAO,6BAA8B,SAAQ,mBAAqC;IACpF;;;OAGG;IACH,YAAY,MAAwB;QAChC,KAAK,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAED;;;OAGG;IACI,QAAQ;QACX,IAAI,CAAC,GAAG,CAAC,IAAI,6BAA6B,EAAE,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACI,aAAa;QAChB,IAAI,CAAC,GAAG,CAAC,IAAI,+BAA+B,EAAE,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACI,WAAW;QACd,IAAI,CAAC,GAAG,CAAC,IAAI,6BAA6B,EAAE,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ","sourcesContent":["import { CameraInputsManager } from \"./cameraInputsManager\";\r\nimport type { GeospatialCamera } from \"./geospatialCamera\";\r\nimport { GeospatialCameraPointersInput } from \"./Inputs/geospatialCameraPointersInput\";\r\nimport { GeospatialCameraMouseWheelInput } from \"./Inputs/geospatialCameraMouseWheelInput\";\r\nimport { GeospatialCameraKeyboardInput } from \"./Inputs/geospatialCameraKeyboardInput\";\r\n\r\n/**\r\n * Default Inputs manager for the GeospatialCamera.\r\n * It groups all the default supported inputs for ease of use.\r\n */\r\nexport class GeospatialCameraInputsManager extends CameraInputsManager<GeospatialCamera> {\r\n /**\r\n * Instantiates a new GeospatialCameraInputsManager.\r\n * @param camera Defines the camera the inputs belong to\r\n */\r\n constructor(camera: GeospatialCamera) {\r\n super(camera);\r\n }\r\n\r\n /**\r\n * Add mouse input support to the input manager\r\n * @returns the current input manager\r\n */\r\n public addMouse(): GeospatialCameraInputsManager {\r\n this.add(new GeospatialCameraPointersInput());\r\n return this;\r\n }\r\n\r\n /**\r\n * Add mouse wheel input support to the input manager\r\n * @returns the current input manager\r\n */\r\n public addMouseWheel(): GeospatialCameraInputsManager {\r\n this.add(new GeospatialCameraMouseWheelInput());\r\n return this;\r\n }\r\n\r\n /**\r\n * Add mouse wheel input support to the input manager\r\n * @returns the current input manager\r\n */\r\n public addKeyboard(): GeospatialCameraInputsManager {\r\n this.add(new GeospatialCameraKeyboardInput());\r\n return this;\r\n }\r\n}\r\n"]}