ohzi-core 13.0.2 → 13.0.3

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 (42) hide show
  1. package/README.md +1 -1
  2. package/build/index.mjs +1 -1
  3. package/build/index.mjs.map +1 -1
  4. package/package.json +1 -1
  5. package/src/BaseApplication.ts +3 -0
  6. package/src/Debug.ts +1 -1
  7. package/src/Graphics.ts +0 -1
  8. package/src/Initializer.ts +1 -1
  9. package/src/KeyboardInput.ts +8 -8
  10. package/src/RenderLoop.ts +1 -1
  11. package/src/camera_controller/CameraController.ts +537 -0
  12. package/src/camera_controller/movement_mode/CameraMovementMode.ts +22 -0
  13. package/src/camera_controller/movement_mode/ImmediateMode.ts +60 -0
  14. package/src/camera_controller/states/common/AbstractCameraState.ts +32 -0
  15. package/src/camera_controller/states/common/CommonCameraState.ts +207 -0
  16. package/src/components/mouse_interactors/ObjectRotator.ts +1 -1
  17. package/src/index.ts +8 -2
  18. package/src/{components → lib}/Input.ts +8 -21
  19. package/src/lib/Vector2.ts +49 -0
  20. package/src/raycast/GroupRaycaster.ts +1 -1
  21. package/src/raycast/PlaneDragResolver.ts +1 -1
  22. package/src/raycast/SurfaceDragResolver.ts +1 -1
  23. package/src/resource_loader/ResourceBatch.ts +1 -1
  24. package/src/scenes/AbstractScene.ts +13 -7
  25. package/src/scenes/loading_states/LoadingState.ts +11 -11
  26. package/src/utilities/CameraUtilities.ts +5 -4
  27. package/src/utilities/ModelUtilities.ts +1 -1
  28. package/src/view_components/ViewComponent.ts +1 -1
  29. package/src/view_components/ViewComponentManager.ts +1 -1
  30. package/src/view_components/ViewManager.ts +1 -1
  31. package/src/view_components/transition/ViewStateTransitionHandler.ts +2 -2
  32. package/types/camera_controller/CameraController.d.ts +88 -0
  33. package/types/camera_controller/movement_mode/CameraMovementMode.d.ts +6 -0
  34. package/types/camera_controller/movement_mode/ImmediateMode.d.ts +14 -0
  35. package/types/camera_controller/states/common/AbstractCameraState.d.ts +8 -0
  36. package/types/camera_controller/states/common/CommonCameraState.d.ts +24 -0
  37. package/types/components/mouse_interactors/ObjectRotator.d.ts +1 -1
  38. package/types/lib/Input.d.ts +41 -0
  39. package/types/lib/Vector2.d.ts +48 -0
  40. package/types/raycast/GroupRaycaster.d.ts +1 -1
  41. package/types/raycast/PlaneDragResolver.d.ts +1 -1
  42. package/types/raycast/SurfaceDragResolver.d.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohzi-core",
3
- "version": "13.0.2",
3
+ "version": "13.0.3",
4
4
  "description": "OHZI Interactive Core Library",
5
5
  "type": "module",
6
6
  "source": "src/index.ts",
@@ -28,6 +28,9 @@ class BaseApplication
28
28
 
29
29
  on_frame_end()
30
30
  {}
31
+
32
+ dispose()
33
+ {}
31
34
  }
32
35
 
33
36
  export { BaseApplication };
package/src/Debug.ts CHANGED
@@ -101,7 +101,7 @@ class Debug
101
101
  return line;
102
102
  }
103
103
 
104
- draw_cube(pos: Vector3, size: number, color: number | string)
104
+ draw_cube(pos?: Vector3, size?: number, color?: number | string)
105
105
  {
106
106
  size = size || 1;
107
107
  color = color || 0xff0000;
package/src/Graphics.ts CHANGED
@@ -23,7 +23,6 @@ export interface CoreAttributes {
23
23
  xr_enabled: boolean;
24
24
  }
25
25
  export interface RendererAttributes {
26
- canvas: HTMLCanvasElement,
27
26
  alpha: boolean,
28
27
  logarithmicDepthBuffer: boolean,
29
28
  antialias: boolean,
@@ -1,10 +1,10 @@
1
1
  import { Browser } from './Browser';
2
2
  import { CameraManager } from './CameraManager';
3
3
  import { Capabilities } from './Capabilities';
4
- import type { Input } from './components/Input';
5
4
  import { Debug } from './Debug';
6
5
  import { Graphics } from './Graphics';
7
6
  import type { RenderLoop } from './index';
7
+ import type { Input } from './lib/Input';
8
8
  import { OS } from './OS';
9
9
  import { OScreen } from './OScreen';
10
10
  import { ReflectionPlaneContext } from './ReflectionPlaneContext';
@@ -1,6 +1,6 @@
1
1
  class KeyboardInput
2
2
  {
3
- container: HTMLElement;
3
+ container: Element | Document;
4
4
  ctrlz_fired: boolean;
5
5
  ctrlz_pressed: boolean;
6
6
  keys: {
@@ -14,7 +14,7 @@ class KeyboardInput
14
14
  };
15
15
  keys_keys: string[];
16
16
 
17
- init(container: HTMLElement)
17
+ init(container: Element | Document)
18
18
  {
19
19
  this.ctrlz_pressed = false;
20
20
  this.ctrlz_fired = false;
@@ -23,11 +23,11 @@ class KeyboardInput
23
23
  this.keys_keys = [];
24
24
  this.container = container;
25
25
 
26
- this.container.addEventListener('keydown', this.on_key_down.bind(this), false);
27
- this.container.addEventListener('keyup', this.on_key_up.bind(this), false);
26
+ this.container.addEventListener('keydown', this.on_key_down, false);
27
+ this.container.addEventListener('keyup', this.on_key_up, false);
28
28
  }
29
29
 
30
- on_key_down(e: KeyboardEvent)
30
+ on_key_down = (e: KeyboardEvent) =>
31
31
  {
32
32
  if (e.keyCode === 90 && e.ctrlKey && !this.ctrlz_fired)
33
33
  {
@@ -41,7 +41,7 @@ class KeyboardInput
41
41
  }
42
42
  }
43
43
 
44
- on_key_up(e: KeyboardEvent)
44
+ on_key_up = (e: KeyboardEvent) =>
45
45
  {
46
46
  this.release_key(e.code);
47
47
  }
@@ -145,8 +145,8 @@ class KeyboardInput
145
145
 
146
146
  dispose()
147
147
  {
148
- this.container.removeEventListener('keydown', this.on_key_down.bind(this), false);
149
- this.container.removeEventListener('keyup', this.on_key_up.bind(this), false);
148
+ this.container.removeEventListener('keydown', this.on_key_down, false);
149
+ this.container.removeEventListener('keyup', this.on_key_up, false);
150
150
  }
151
151
  }
152
152
 
package/src/RenderLoop.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BaseApplication } from './BaseApplication';
2
- import type { Input } from './components/Input';
3
2
  import { Debug } from './Debug';
4
3
  import type { Graphics } from './Graphics';
4
+ import type { Input } from './lib/Input';
5
5
  import { Time } from './Time';
6
6
  import { TransitionManager } from './view_components/TransitionManager';
7
7
  import { ViewComponentManager } from './view_components/ViewComponentManager';
@@ -0,0 +1,537 @@
1
+ import { ImmediateMode } from './movement_mode/ImmediateMode';
2
+
3
+ import type { Camera, Points } from 'three';
4
+ import { PlaneHelper, Quaternion, Vector3 } from 'three';
5
+ // import { PlaneHelper } from 'three';
6
+ import { Plane } from 'three';
7
+ // import { Sphere } from 'three';
8
+ import { Box3, Ray } from 'three';
9
+
10
+ import { OScreen } from '../OScreen';
11
+ import type { OrthographicCamera } from '../OrthographicCamera';
12
+ import type { PerspectiveCamera } from '../PerspectiveCamera';
13
+ import type { Input } from '../lib/Input';
14
+ import type { Cube } from '../primitives/Cube';
15
+ import type { Sphere } from '../primitives/Sphere';
16
+ import { OMath } from '../utilities/OMath';
17
+ import { OrthographicFrustumPointFitter } from '../utilities/OrthographicFrustumPointFitter';
18
+ import { PerspectiveFrustumPointFitter } from '../utilities/PerspectiveFrustumPointFitter';
19
+ import type { CameraMovementMode } from './movement_mode/CameraMovementMode';
20
+ import { AbstractCameraState } from './states/common/AbstractCameraState';
21
+
22
+ export class CameraController
23
+ {
24
+ __last_reference_position: Vector3;
25
+ camera: Camera;
26
+ camera_initial_pos: Vector3;
27
+ camera_initial_rot: Quaternion;
28
+ current_azimuth: number;
29
+ current_mode: CameraMovementMode;
30
+ current_orientation: number;
31
+ current_state: AbstractCameraState;
32
+ current_tilt: number;
33
+ debug_box: Cube;
34
+ input: Input;
35
+ input_enabled: boolean;
36
+ max_zoom: number;
37
+ min_zoom: number;
38
+ normalized_zoom: number;
39
+ old_orientation: number;
40
+ orientation: number;
41
+ point_of_interest: Vector3;
42
+ projected_points: Points[];
43
+ projection_plane_helper: PlaneHelper;
44
+ projection_sphere_helper: Sphere;
45
+ raised_look_at_position: Vector3;
46
+ reference_position: Vector3;
47
+ reference_rotation: Quaternion;
48
+ reference_zoom: number;
49
+ tilt: number;
50
+ tmp_dir: Vector3;
51
+ tmp_forward: Vector3;
52
+ tmp_quat: Quaternion;
53
+ tmp_right: Vector3;
54
+ tmp_size: Vector3;
55
+ use_raised_look_at_direction: number;
56
+ vector_forward_axis: Vector3;
57
+ vector_right_axis: Vector3;
58
+ vector_up_axis: Vector3;
59
+ zoom: number;
60
+
61
+ constructor(input: Input)
62
+ {
63
+ this.input = input;
64
+
65
+ this.camera = undefined;
66
+ this.camera_initial_rot = undefined;
67
+ this.camera_initial_pos = undefined;
68
+ this.current_state = new AbstractCameraState();
69
+
70
+ this.current_mode = new ImmediateMode();
71
+
72
+ this.point_of_interest = new Vector3();
73
+ this.normalized_zoom = 0;
74
+
75
+ this.vector_up_axis = new Vector3(0, 1, 0);
76
+ this.vector_right_axis = new Vector3(1, 0, 0);
77
+ this.vector_forward_axis = new Vector3(0, 0, 1);
78
+ this.tmp_forward = this.vector_forward_axis.clone();
79
+ this.tmp_right = this.vector_right_axis.clone();
80
+
81
+ this.tmp_dir = new Vector3();
82
+
83
+ this.zoom = 10;
84
+ this.reference_zoom = 10;
85
+ this.orientation = 27; // degrees
86
+ this.tilt = 70;
87
+
88
+ this.reference_rotation = new Quaternion();
89
+ this.reference_position = new Vector3();
90
+ this.__last_reference_position = new Vector3();
91
+
92
+ this.tmp_size = new Vector3();
93
+ this.tmp_quat = new Quaternion();
94
+
95
+ this.min_zoom = 1;
96
+ this.max_zoom = 400;
97
+
98
+ this.current_tilt = 0;
99
+ this.current_orientation = 0;
100
+ this.current_azimuth = 0;
101
+
102
+ this.projection_plane_helper = new PlaneHelper(new Plane(), 1, 0xffff00);
103
+
104
+ this.input_enabled = true;
105
+ // this.debug_box = Debug.draw_cube(undefined,15);
106
+ // this.debug_zoom_box = Debug.draw_sphere(undefined,15, 0x00ff00);
107
+
108
+ this.raised_look_at_position = new Vector3(-82.2986094900191, 0, 39.7538467209173);
109
+ this.use_raised_look_at_direction = 0;
110
+ }
111
+
112
+ enable()
113
+ {
114
+ this.input_enabled = true;
115
+ }
116
+
117
+ disable()
118
+ {
119
+ this.input_enabled = false;
120
+ }
121
+
122
+ set_camera(camera: Camera)
123
+ {
124
+ this.camera = camera;
125
+ this.camera_initial_rot = camera.quaternion.clone();
126
+ this.camera_initial_pos = camera.position.clone();
127
+ }
128
+
129
+ set_state(state: AbstractCameraState)
130
+ {
131
+ // console.log("camera controller state switch to: " + state.constructor.name);
132
+ this.current_state.on_exit(this);
133
+ this.current_state = state;
134
+ this.current_state.on_enter(this);
135
+ }
136
+
137
+ set_mode(mode: CameraMovementMode)
138
+ {
139
+ // console.log("camera controller mode switch to: " + mode.constructor.name);
140
+
141
+ this.current_mode.on_exit(this);
142
+ this.current_mode = mode;
143
+ this.current_mode.on_enter(this);
144
+ }
145
+
146
+ set_normalized_zoom(zoom: number)
147
+ {
148
+ this.normalized_zoom = OMath.clamp(zoom, 0, 1);
149
+ }
150
+
151
+ update_normalized_zoom(min_zoom: number, max_zoom: number)
152
+ {
153
+ const zoom = this.camera.position.distanceTo(this.reference_position);
154
+ this.normalized_zoom = OMath.linear_map(zoom, min_zoom, max_zoom, 1, 0);
155
+ this.normalized_zoom = OMath.clamp(this.normalized_zoom, 0, 1);
156
+ }
157
+
158
+ // update_initial_rotation()
159
+ // {
160
+ // this.current_state.update_initial_rotation();
161
+ // }
162
+
163
+ update()
164
+ {
165
+ if (this.debug_box)
166
+ {
167
+ this.debug_box.position.copy(this.reference_position);
168
+ }
169
+
170
+ // this.debug_zoom_box.position.copy(this.reference_position)
171
+ // this.debug_zoom_box.position.add(new Vector3(0,0,1).applyQuaternion(this.camera.quaternion).multiplyScalar(this.reference_zoom));
172
+
173
+ this.current_state.update(this);
174
+ this.current_mode.update(this);
175
+ this.update_normalized_zoom(this.min_zoom, this.max_zoom);
176
+ }
177
+
178
+ set_idle()
179
+ {
180
+ this.set_state(new AbstractCameraState());
181
+ }
182
+
183
+ camera_is_zoomed_out()
184
+ {
185
+ return this.normalized_zoom < 0.2;
186
+ }
187
+
188
+ set_rotation(tilt: number, orientation: number, azimuth = 0)
189
+ {
190
+ this.old_orientation = this.current_orientation;
191
+
192
+ this.current_tilt = tilt || this.current_tilt;
193
+ this.current_orientation = orientation || this.current_orientation;
194
+ this.current_azimuth = azimuth || this.current_azimuth;
195
+
196
+ this.set_quaternion(this.build_rotation(this.current_tilt, this.current_orientation)); //, this.current_azimuth
197
+ }
198
+
199
+ set_rotation_delta(tilt: number, orientation: number, azimuth = 0)
200
+ {
201
+ this.lerp_rotation(
202
+ this.current_tilt, this.current_tilt + tilt,
203
+ this.current_orientation, this.current_orientation + orientation,
204
+ this.current_azimuth, this.current_azimuth + azimuth,
205
+ 1
206
+ );
207
+ }
208
+
209
+ lerp_tilt(from_tilt: number, to_tilt: number, t: number)
210
+ {
211
+ this.lerp_rotation(
212
+ from_tilt, to_tilt,
213
+ this.current_orientation, this.current_orientation,
214
+ this.current_azimuth, this.current_azimuth,
215
+ t);
216
+ }
217
+
218
+ set_quaternion(q: Quaternion)
219
+ {
220
+ const xΘ = Math.atan2(q.x, q.w) * 2;
221
+ const yΘ = Math.atan2(q.y, q.w) * 2;
222
+
223
+ this.current_orientation = OMath.radToDeg(yΘ) % 360;
224
+ this.current_tilt = OMath.radToDeg(xΘ) * -1;
225
+
226
+ this.reference_rotation.copy(q);
227
+ }
228
+
229
+ lerp_quaternion(q: Quaternion, t: number)
230
+ {
231
+ this.set_quaternion(this.reference_rotation.clone().slerp(q, t));
232
+ }
233
+
234
+ lerp_orientation(from_orientation: number, to_orientation: number, t: number)
235
+ {
236
+ this.lerp_rotation(
237
+ this.current_tilt, this.current_tilt,
238
+ from_orientation, to_orientation,
239
+ this.current_azimuth, this.current_azimuth,
240
+ t);
241
+ }
242
+
243
+ lerp_azimuth(from_azimuth: number, to_azimuth: number, t: number)
244
+ {
245
+
246
+ }
247
+
248
+ lerp_rotation(from_tilt: number, to_tilt: number, from_orientation: number, to_orientation: number, from_azimuth: number, to_azimuth: number, t: number)
249
+ {
250
+ const from_quat = this.build_rotation(from_tilt, from_orientation);
251
+ const to_quat = this.build_rotation(to_tilt, to_orientation);
252
+
253
+ from_quat.slerp(to_quat, t);
254
+
255
+ this.set_quaternion(from_quat);
256
+ }
257
+
258
+ build_rotation(tilt: number, orientation: number)
259
+ {
260
+ if (orientation < 0)
261
+ {
262
+ orientation = orientation + 360;
263
+ }
264
+ const new_orientation = new Quaternion().setFromAxisAngle(this.vector_up_axis, ((orientation % 360) / 360) * Math.PI * 2);
265
+ const new_tilt = new Quaternion().setFromAxisAngle(this.vector_right_axis, (-tilt / 360) * Math.PI * 2);
266
+
267
+ return new_orientation.multiply(new_tilt);
268
+ }
269
+
270
+ translate_forward(amount: number)
271
+ {
272
+ this.tmp_forward.copy(this.vector_forward_axis);
273
+ this.tmp_forward.applyQuaternion(this.camera.quaternion);
274
+ this.reference_position.add(this.tmp_forward.multiplyScalar(amount));
275
+ }
276
+
277
+ translate_right(amount: number)
278
+ {
279
+ this.tmp_right.copy(this.vector_right_axis);
280
+ this.tmp_right.applyQuaternion(this.camera.quaternion);
281
+ this.reference_position.add(this.tmp_right.multiplyScalar(amount));
282
+ }
283
+
284
+ focus_on_bounding_box(bb: Box3, scale = 1)
285
+ {
286
+ if ((this.camera as OrthographicCamera).isOrthographicCamera)
287
+ {
288
+ bb.getSize(this.tmp_size);
289
+
290
+ const obj_x = this.tmp_size.x;
291
+ const obj_y = this.tmp_size.y;
292
+ const object_aspect = obj_x / obj_y;
293
+ if (OScreen.aspect_ratio / object_aspect > 1)
294
+ {
295
+ (this.camera as PerspectiveCamera).zoom = OScreen.height / obj_y;
296
+ }
297
+ else
298
+ {
299
+ (this.camera as PerspectiveCamera).zoom = OScreen.width / obj_x;
300
+ }
301
+
302
+ bb.getCenter(this.reference_position);
303
+ }
304
+ else
305
+ {
306
+ const dir = new Vector3();
307
+ dir.copy(bb.max).sub(bb.min);
308
+
309
+ const p1 = bb.min.clone();
310
+
311
+ const p2 = p1.clone().add(new Vector3(dir.x, 0, 0));
312
+ const p3 = p1.clone().add(new Vector3(0, dir.y, 0));
313
+ const p4 = p1.clone().add(new Vector3(0, 0, dir.z));
314
+
315
+ const p5 = p1.clone().add(new Vector3(dir.x, 0, dir.z));
316
+ const p6 = p1.clone().add(new Vector3(0, dir.y, dir.z));
317
+ const p7 = bb.max.clone();
318
+ const p8 = p1.clone().add(new Vector3(dir.x, dir.y, 0));
319
+
320
+ this.focus_camera_on_points([p1, p2, p3, p4, p5, p6, p7, p8], scale);
321
+ }
322
+ }
323
+
324
+ // get_zoom_to_focus_on_bounding_box(bb, tilt, orientation)
325
+ // {
326
+ // if (tilt !== undefined && orientation !== undefined)
327
+ // {
328
+ // this.tmp_quat.copy(this.reference_rotation); // backup quaternion
329
+ // this.reference_rotation.copy(this.build_rotation(tilt, orientation, this.current_azimuth));
330
+ // }
331
+ // const original_zoom = this.reference_zoom;
332
+ // const original_pos = new Vector3().copy(this.reference_position);
333
+ // this.focus_camera_on_bounding_box(bb);
334
+ // const target_zoom = this.reference_zoom;
335
+ // this.reference_position.copy(original_pos);
336
+ // this.reference_zoom = original_zoom;
337
+
338
+ // if (tilt !== undefined && orientation !== undefined)
339
+ // {
340
+ // this.reference_rotation.copy(this.tmp_quat);
341
+ // }
342
+
343
+ // return target_zoom;
344
+ // }
345
+
346
+ get_zoom_to_focus_on_points(points: Vector3[], scale: number)
347
+ {
348
+ const old_zoom = this.reference_zoom;
349
+ const old_pos = new Vector3().copy(this.reference_position);
350
+ this.focus_camera_on_points(points, scale);
351
+ const new_zoom = this.reference_zoom;
352
+ this.reference_zoom = old_zoom;
353
+ this.reference_position.copy(old_pos);
354
+ return new_zoom;
355
+ }
356
+
357
+ get_target_pos_to_focus_on_points(points: Vector3[], scale: number)
358
+ {
359
+ const old_zoom = this.reference_zoom;
360
+ const old_pos = new Vector3().copy(this.reference_position);
361
+ this.focus_camera_on_points(points, scale);
362
+
363
+ const new_pos = this.reference_position.clone();
364
+ this.reference_zoom = old_zoom;
365
+ this.reference_position.copy(old_pos);
366
+
367
+ return new_pos;
368
+ }
369
+
370
+ focus_camera_on_sphere(sphere: Sphere, debug: boolean)
371
+ {
372
+ this.reference_zoom = this.get_zoom_to_sphere(sphere, debug);
373
+ this.reference_position.copy(sphere.center);
374
+ }
375
+
376
+ get_zoom_to_sphere(sphere: Sphere, debug: boolean)
377
+ {
378
+ const v_fov = ((this.camera as PerspectiveCamera).fov / 2) * Math.PI / 180;
379
+ const h_fov = (2 * Math.atan(Math.tan(v_fov) * (this.camera as PerspectiveCamera).aspect)) / 2;
380
+
381
+ // if(debug )
382
+ // {
383
+ // Debug.draw_math_sphere(sphere);
384
+ // }
385
+ // this.camera.zoom = 1/((sphere.radius*2) /(ViewApi.map.camera_controller.camera.top*2));
386
+ // this.camera.updateProjectionMatrix();
387
+
388
+ const distV = sphere.radius / Math.tan(v_fov);
389
+ const distH = sphere.radius / Math.tan(h_fov);
390
+ return Math.max(Math.abs(distH), Math.abs(distV));
391
+ }
392
+
393
+ hide_projected_points()
394
+ {
395
+ for (let i = 0; i < this.projected_points.length; i++)
396
+ {
397
+ this.projected_points[i].visible = false;
398
+ }
399
+ }
400
+
401
+ show_projected_points(points: Vector3[])
402
+ {
403
+ this.hide_projected_points();
404
+ for (let i = 0; i < points.length; i++)
405
+ {
406
+ this.projected_points[i].visible = true;
407
+ this.projected_points[i].position.copy(points[i]);
408
+ }
409
+ }
410
+
411
+ show_plane_projection(plane: Plane, size = 1)
412
+ {
413
+ this.projection_plane_helper.plane = plane;
414
+ this.projection_plane_helper.size = size;
415
+ this.projection_plane_helper.updateMatrixWorld();
416
+ this.projection_plane_helper.visible = true;
417
+ }
418
+
419
+ show_sphere_projection(sphere: Sphere)
420
+ {
421
+ this.projection_sphere_helper.scale.set(sphere.radius, sphere.radius, sphere.radius);
422
+ this.projection_sphere_helper.position.copy(sphere.center);
423
+ this.projection_sphere_helper.visible = true;
424
+ }
425
+
426
+ fit_points(quaternion: Quaternion, points: Vector3[], zoom_scale = 1)
427
+ {
428
+ if ((this.camera as PerspectiveCamera).isPerspectiveCamera)
429
+ {
430
+ const camera_forward_dir = new Vector3(0, 0, -1).applyQuaternion(quaternion);
431
+ const camera_backward_dir = camera_forward_dir.clone().multiplyScalar(-1);
432
+
433
+ const fitter = new PerspectiveFrustumPointFitter();
434
+
435
+ const aspect_ratio = OScreen.aspect_ratio;
436
+
437
+ const camera_pos = fitter.fit_points(points, quaternion, ((this.camera as PerspectiveCamera).fov * zoom_scale), aspect_ratio);
438
+ const box = new Box3().setFromPoints(points);
439
+ const center = new Vector3();
440
+ box.getCenter(center);
441
+
442
+ const reference_position_plane = new Plane().setFromNormalAndCoplanarPoint(camera_backward_dir, center);
443
+
444
+ const camera_ray = new Ray(camera_pos, camera_forward_dir);
445
+
446
+ const reference_position = new Vector3();
447
+ camera_ray.intersectPlane(reference_position_plane, reference_position);
448
+
449
+ const zoom = camera_pos.distanceTo(reference_position);
450
+
451
+ return {
452
+ zoom: zoom,
453
+ reference_position: reference_position,
454
+ camera_position: camera_pos
455
+ };
456
+ }
457
+ else
458
+ {
459
+ const fitter = new OrthographicFrustumPointFitter();
460
+ const result = fitter.fit_points(points, this.reference_rotation, ((this.camera as PerspectiveCamera).fov * zoom_scale), OScreen.aspect_ratio);
461
+
462
+ this.reference_position.copy(result.center);
463
+ this.reference_zoom = result.distance_to_center;
464
+
465
+ const forward = new Vector3(0, 0, 1).applyQuaternion(quaternion);
466
+ return {
467
+ zoom: result.distance_to_center,
468
+ reference_position: result.center,
469
+ camera_position: forward.multiplyScalar(result.distance_to_center)
470
+ };
471
+ }
472
+ }
473
+
474
+ focus_camera_on_points(points: Vector3[], zoom_scale = 1)
475
+ {
476
+ if ((this.camera as PerspectiveCamera).isPerspectiveCamera)
477
+ {
478
+ const camera_forward_dir = new Vector3(0, 0, -1).applyQuaternion(this.reference_rotation);
479
+ const camera_backward_dir = camera_forward_dir.clone().multiplyScalar(-1);
480
+
481
+ const fitter = new PerspectiveFrustumPointFitter();
482
+
483
+ const aspect_ratio = OScreen.aspect_ratio;
484
+
485
+ const camera_pos = fitter.fit_points(points, this.reference_rotation, ((this.camera as PerspectiveCamera).fov * zoom_scale), aspect_ratio);
486
+ const box = new Box3().setFromPoints(points);
487
+ const center = new Vector3();
488
+ box.getCenter(center);
489
+
490
+ const reference_position_plane = new Plane().setFromNormalAndCoplanarPoint(camera_backward_dir, center);
491
+
492
+ const camera_ray = new Ray(camera_pos, camera_forward_dir);
493
+
494
+ const reference_position = new Vector3();
495
+ camera_ray.intersectPlane(reference_position_plane, reference_position);
496
+
497
+ const zoom = camera_pos.distanceTo(reference_position);
498
+
499
+ this.reference_zoom = zoom;
500
+ this.reference_position.copy(reference_position);
501
+ }
502
+ else
503
+ {
504
+ const fitter = new OrthographicFrustumPointFitter();
505
+ const result = fitter.fit_points(points, this.reference_rotation, ((this.camera as PerspectiveCamera).fov * zoom_scale), OScreen.aspect_ratio);
506
+
507
+ this.reference_position.copy(result.center);
508
+ this.reference_zoom = result.distance_to_center;
509
+ }
510
+ }
511
+
512
+ get_current_tilt()
513
+ {
514
+ return this.current_tilt;
515
+ }
516
+
517
+ get_current_orientation()
518
+ {
519
+ return this.current_orientation;
520
+ }
521
+
522
+ get_current_azimuth()
523
+ {
524
+ return this.current_azimuth;
525
+ }
526
+
527
+ __get_zoom_to_show_rect(width: number, height: number, scale = 1)
528
+ {
529
+ // let v_fov = (this.camera.fov/2) * Math.PI/180;
530
+ const v_fov = OMath.degToRad((this.camera as PerspectiveCamera).fov / 2);
531
+ const h_fov = (2 * Math.atan(Math.tan(v_fov) * (this.camera as PerspectiveCamera).aspect)) / 2;
532
+
533
+ const distV = height / Math.tan(v_fov * scale);
534
+ const distH = width / Math.tan(h_fov * scale);
535
+ return Math.max(Math.abs(distH), Math.abs(distV));
536
+ }
537
+ }
@@ -0,0 +1,22 @@
1
+ export class CameraMovementMode
2
+ {
3
+ constructor()
4
+ {
5
+
6
+ }
7
+
8
+ on_enter(camera_controller: any)
9
+ {
10
+
11
+ }
12
+
13
+ on_exit(camera_controller: any)
14
+ {
15
+
16
+ }
17
+
18
+ update(camera_controller: any)
19
+ {
20
+
21
+ }
22
+ }