vim-web 0.4.0 → 0.4.1-dev.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.
@@ -17,7 +17,7 @@ export declare class Camera implements ICamera {
17
17
  camPerspective: PerspectiveCamera;
18
18
  camOrthographic: OrthographicCamera;
19
19
  private _viewport;
20
- _scene: RenderScene;
20
+ private _scene;
21
21
  private _lerp;
22
22
  private _movement;
23
23
  private _inputVelocity;
@@ -29,8 +29,7 @@ export declare class Camera implements ICamera {
29
29
  private _lastTarget;
30
30
  private _tmp1;
31
31
  private _tmp2;
32
- _savedPosition: THREE.Vector3;
33
- _savedTarget: THREE.Vector3;
32
+ private _savedState;
34
33
  /**
35
34
  * A signal that is dispatched when camera settings change.
36
35
  */
@@ -126,7 +125,7 @@ export declare class Camera implements ICamera {
126
125
  * The target at which the camera is looking at and around which it rotates.
127
126
  */
128
127
  get target(): THREE.Vector3;
129
- applySettings(settings: ViewerSettings): void;
128
+ private applySettings;
130
129
  /**
131
130
  * The distance from the camera to the target.
132
131
  */
@@ -96,3 +96,12 @@ export interface ICamera {
96
96
  */
97
97
  orthographic: boolean;
98
98
  }
99
+ export declare class CameraSaveState {
100
+ private _camera;
101
+ private _position;
102
+ private _target;
103
+ constructor(camera: ICamera);
104
+ save(): void;
105
+ get position(): THREE.Vector3;
106
+ get target(): THREE.Vector3;
107
+ }
@@ -6,9 +6,12 @@ import { Element3D } from '../../loader/element3d';
6
6
  import { Selectable } from '../selection';
7
7
  import * as THREE from 'three';
8
8
  import { Vim } from '../../loader/vim';
9
+ import { CameraSaveState } from './cameraInterface';
9
10
  export declare abstract class CameraMovement {
10
11
  protected _camera: Camera;
11
- constructor(camera: Camera);
12
+ private _savedState;
13
+ private _getBoundingBox;
14
+ constructor(camera: Camera, savedState: CameraSaveState, getBoundingBox: () => THREE.Box3);
12
15
  /**
13
16
  * Moves the camera by the specified 3D vector.
14
17
  * @param {THREE.Vector3} vector - The 3D vector representing the direction and distance of movement.
@@ -59,7 +62,7 @@ export declare abstract class CameraMovement {
59
62
  /**
60
63
  * Resets the camera to its last saved position and orientation.
61
64
  */
62
- abstract reset(): void;
65
+ reset(): void;
63
66
  /**
64
67
  * Moves both the camera and its target to the given positions.
65
68
  * @param {THREE.Vector3} position - The new position of the camera.
@@ -6,12 +6,13 @@ import { Camera } from './camera';
6
6
  import { Element3D } from '../../loader/element3d';
7
7
  import { CameraMovementSnap } from './cameraMovementSnap';
8
8
  import { CameraMovement } from './cameraMovement';
9
+ import { CameraSaveState } from './cameraInterface';
9
10
  export declare class CameraLerp extends CameraMovement {
10
11
  _movement: CameraMovementSnap;
11
12
  _clock: THREE.Clock;
12
13
  onProgress: ((progress: number) => void) | undefined;
13
14
  _duration: number;
14
- constructor(camera: Camera, movement: CameraMovementSnap);
15
+ constructor(camera: Camera, movement: CameraMovementSnap, savedState: CameraSaveState, getBoundingBox: () => THREE.Box3);
15
16
  get isLerping(): boolean;
16
17
  init(duration: number): void;
17
18
  cancel(): void;
@@ -23,6 +24,5 @@ export declare class CameraLerp extends CameraMovement {
23
24
  setDistance(dist: number): void;
24
25
  orbit(angle: THREE.Vector2): void;
25
26
  target(target: Element3D | THREE.Vector3): Promise<void>;
26
- reset(): void;
27
27
  set(position: THREE.Vector3, target?: THREE.Vector3): void;
28
28
  }
@@ -10,7 +10,6 @@ export declare class CameraMovementSnap extends CameraMovement {
10
10
  * @param amount movement size.
11
11
  */
12
12
  zoom(amount: number): void;
13
- reset(): void;
14
13
  setDistance(dist: number): void;
15
14
  rotate(angle: THREE.Vector2): void;
16
15
  applyRotation(quaternion: THREE.Quaternion): void;
@@ -5,8 +5,7 @@ import * as THREE from 'three';
5
5
  import { ViewerSettings } from '../settings/viewerSettings';
6
6
  export declare class OrthographicCamera {
7
7
  camera: THREE.OrthographicCamera;
8
- constructor(camera: THREE.OrthographicCamera);
8
+ constructor(camera: THREE.OrthographicCamera, settings: ViewerSettings);
9
9
  frustrumSizeAt(point: THREE.Vector3): THREE.Vector2;
10
- applySettings(settings: ViewerSettings): void;
11
10
  updateProjection(size: THREE.Vector2, aspect: number): void;
12
11
  }
@@ -5,8 +5,7 @@ import * as THREE from 'three';
5
5
  import { ViewerSettings } from '../settings/viewerSettings';
6
6
  export declare class PerspectiveCamera {
7
7
  camera: THREE.PerspectiveCamera;
8
- constructor(camera: THREE.PerspectiveCamera);
9
- applySettings(settings: ViewerSettings): void;
8
+ constructor(camera: THREE.PerspectiveCamera, settings: ViewerSettings);
10
9
  updateProjection(aspect: number): void;
11
10
  frustrumSizeAt(point: THREE.Vector3): THREE.Vector2;
12
11
  }
@@ -50047,6 +50047,24 @@ void main() {
50047
50047
  createTransparent,
50048
50048
  createWireframe
50049
50049
  }, Symbol.toStringTag, { value: "Module" }));
50050
+ class CameraSaveState {
50051
+ constructor(camera2) {
50052
+ __publicField(this, "_camera");
50053
+ __publicField(this, "_position", new Vector3());
50054
+ __publicField(this, "_target", new Vector3());
50055
+ this._camera = camera2;
50056
+ }
50057
+ save() {
50058
+ this._position.copy(this._camera.position);
50059
+ this._target.copy(this._camera.target);
50060
+ }
50061
+ get position() {
50062
+ return this._position;
50063
+ }
50064
+ get target() {
50065
+ return this._target;
50066
+ }
50067
+ }
50050
50068
  const _Marker = class _Marker {
50051
50069
  /**
50052
50070
  * Constructs a new Marker object.
@@ -50230,9 +50248,13 @@ void main() {
50230
50248
  __publicField(_Marker, "_unitVector", new Vector3(1, 1, 1));
50231
50249
  let Marker = _Marker;
50232
50250
  class CameraMovement {
50233
- constructor(camera2) {
50251
+ constructor(camera2, savedState, getBoundingBox) {
50234
50252
  __publicField(this, "_camera");
50253
+ __publicField(this, "_savedState");
50254
+ __publicField(this, "_getBoundingBox");
50235
50255
  this._camera = camera2;
50256
+ this._savedState = savedState;
50257
+ this._getBoundingBox = getBoundingBox;
50236
50258
  }
50237
50259
  /**
50238
50260
  * Moves the camera in a specified 2D direction within a plane defined by the given axes.
@@ -50280,6 +50302,12 @@ void main() {
50280
50302
  angle.multiplyScalar(180 / Math.PI);
50281
50303
  this.orbit(angle);
50282
50304
  }
50305
+ /**
50306
+ * Resets the camera to its last saved position and orientation.
50307
+ */
50308
+ reset() {
50309
+ this.set(this._camera.position, this._camera.target);
50310
+ }
50283
50311
  /**
50284
50312
  * Sets the camera's orientation and position to focus on the specified target.
50285
50313
  * @param {IObject | Vim | THREE.Sphere | THREE.Box3 | 'all' | undefined} target - The target object, or 'all' to frame all objects.
@@ -50294,7 +50322,7 @@ void main() {
50294
50322
  }
50295
50323
  if (target === "all") {
50296
50324
  console.log("frame all");
50297
- target = this._camera._scene.getAverageBoundingBox();
50325
+ target = this._getBoundingBox();
50298
50326
  }
50299
50327
  if (target instanceof Box3) {
50300
50328
  target = target.getBoundingSphere(new Sphere());
@@ -50326,8 +50354,8 @@ void main() {
50326
50354
  }
50327
50355
  }
50328
50356
  class CameraLerp extends CameraMovement {
50329
- constructor(camera2, movement) {
50330
- super(camera2);
50357
+ constructor(camera2, movement, savedState, getBoundingBox) {
50358
+ super(camera2, savedState, getBoundingBox);
50331
50359
  __publicField(this, "_movement");
50332
50360
  __publicField(this, "_clock", new Clock());
50333
50361
  // position
@@ -50368,11 +50396,11 @@ void main() {
50368
50396
  const start = this._camera.position.clone();
50369
50397
  const end = this._camera.position.clone().add(v);
50370
50398
  const pos = new Vector3();
50399
+ const offset = this._camera.forward.multiplyScalar(this._camera.orbitDistance);
50371
50400
  this.onProgress = (progress) => {
50372
- console.log("progress", progress);
50373
50401
  pos.copy(start);
50374
50402
  pos.lerp(end, progress);
50375
- this._movement.move3(pos);
50403
+ this._movement.set(pos, pos.clone().add(offset));
50376
50404
  };
50377
50405
  }
50378
50406
  rotate(angle) {
@@ -50428,9 +50456,6 @@ void main() {
50428
50456
  this._movement.applyRotation(r);
50429
50457
  };
50430
50458
  }
50431
- reset() {
50432
- this.set(this._camera._savedPosition, this._camera._savedTarget);
50433
- }
50434
50459
  set(position, target) {
50435
50460
  const endTarget = target ?? this._camera.target;
50436
50461
  const startPos = this._camera.position.clone();
@@ -50452,9 +50477,6 @@ void main() {
50452
50477
  const dist2 = this._camera.orbitDistance * amount;
50453
50478
  this.setDistance(dist2);
50454
50479
  }
50455
- reset() {
50456
- this.set(this._camera._savedPosition, this._camera._savedTarget);
50457
- }
50458
50480
  setDistance(dist2) {
50459
50481
  const pos = this._camera.target.clone().sub(this._camera.forward.multiplyScalar(dist2));
50460
50482
  this.set(pos, this._camera.target);
@@ -51154,10 +51176,14 @@ void main() {
51154
51176
  );
51155
51177
  }
51156
51178
  class OrthographicCamera {
51157
- constructor(camera2) {
51179
+ constructor(camera2, settings2) {
51158
51180
  __publicField(this, "camera");
51159
51181
  this.camera = camera2;
51160
51182
  this.camera.layers.enable(Layers.NoRaycast);
51183
+ this.camera.zoom = settings2.camera.zoom;
51184
+ this.camera.near = -settings2.camera.far;
51185
+ this.camera.far = settings2.camera.far;
51186
+ this.camera.updateProjectionMatrix();
51161
51187
  }
51162
51188
  frustrumSizeAt(point) {
51163
51189
  return new Vector2(
@@ -51165,12 +51191,6 @@ void main() {
51165
51191
  this.camera.top - this.camera.bottom
51166
51192
  );
51167
51193
  }
51168
- applySettings(settings2) {
51169
- this.camera.zoom = settings2.camera.zoom;
51170
- this.camera.near = -settings2.camera.far;
51171
- this.camera.far = settings2.camera.far;
51172
- this.camera.updateProjectionMatrix();
51173
- }
51174
51194
  updateProjection(size, aspect2) {
51175
51195
  const max2 = Math.max(size.x, size.y);
51176
51196
  this.camera.left = -max2 * aspect2;
@@ -51181,12 +51201,10 @@ void main() {
51181
51201
  }
51182
51202
  }
51183
51203
  class PerspectiveCamera {
51184
- constructor(camera2) {
51204
+ constructor(camera2, settings2) {
51185
51205
  __publicField(this, "camera");
51186
51206
  this.camera = camera2;
51187
51207
  this.camera.layers.enable(Layers.NoRaycast);
51188
- }
51189
- applySettings(settings2) {
51190
51208
  this.camera.fov = settings2.camera.fov;
51191
51209
  this.camera.zoom = settings2.camera.zoom;
51192
51210
  this.camera.near = settings2.camera.near;
@@ -51226,8 +51244,7 @@ void main() {
51226
51244
  __publicField(this, "_tmp1", new Vector3());
51227
51245
  __publicField(this, "_tmp2", new Vector3());
51228
51246
  // saves
51229
- __publicField(this, "_savedPosition", new Vector3(0, 0, -5));
51230
- __publicField(this, "_savedTarget", new Vector3(0, 0, 0));
51247
+ __publicField(this, "_savedState", new CameraSaveState(this));
51231
51248
  __publicField(this, "_onValueChanged", new distExports$1.SignalDispatcher());
51232
51249
  __publicField(this, "_hasMoved");
51233
51250
  __publicField(this, "_onMoved", new distExports$1.SignalDispatcher());
@@ -51245,18 +51262,24 @@ void main() {
51245
51262
  __publicField(this, "_defaultForward", new Vector3(1, -1, 1).normalize());
51246
51263
  // Settings
51247
51264
  __publicField(this, "_velocityBlendFactor", 1e-4);
51248
- this.camPerspective = new PerspectiveCamera(new PerspectiveCamera$1());
51265
+ this.camPerspective = new PerspectiveCamera(new PerspectiveCamera$1(), settings2);
51249
51266
  this.camPerspective.camera.up = new Vector3(0, 0, 1);
51250
51267
  this.camPerspective.camera.lookAt(new Vector3(0, 1, 0));
51251
51268
  this.camOrthographic = new OrthographicCamera(
51252
- new OrthographicCamera$1()
51269
+ new OrthographicCamera$1(),
51270
+ settings2
51253
51271
  );
51254
- this._movement = new CameraMovementSnap(this);
51255
- this._lerp = new CameraLerp(this, this._movement);
51272
+ this._savedState = new CameraSaveState(this);
51273
+ this._movement = new CameraMovementSnap(this, this._savedState, () => this._scene.getBoundingBox());
51274
+ this._lerp = new CameraLerp(this, this._movement, this._savedState, () => this._scene.getBoundingBox());
51256
51275
  this._scene = scene;
51257
51276
  this._viewport = viewport;
51258
51277
  this._viewport.onResize.sub(() => this.updateProjection());
51259
- this.applySettings(settings2);
51278
+ this.defaultForward = settings2.camera.forward;
51279
+ this._orthographic = settings2.camera.orthographic;
51280
+ this.allowedMovement = settings2.camera.allowedMovement;
51281
+ this.allowedRotation = settings2.camera.allowedRotation;
51282
+ this._onValueChanged.dispatch();
51260
51283
  this.snap(true).setDistance(-1e3);
51261
51284
  this.snap(true).orbitTowards(this._defaultForward);
51262
51285
  this.updateProjection();
@@ -51407,13 +51430,6 @@ void main() {
51407
51430
  return this._target;
51408
51431
  }
51409
51432
  applySettings(settings2) {
51410
- this.defaultForward = settings2.camera.forward;
51411
- this._orthographic = settings2.camera.orthographic;
51412
- this.allowedMovement = settings2.camera.allowedMovement;
51413
- this.allowedRotation = settings2.camera.allowedRotation;
51414
- this.camPerspective.applySettings(settings2);
51415
- this.camOrthographic.applySettings(settings2);
51416
- this._onValueChanged.dispatch();
51417
51433
  }
51418
51434
  /**
51419
51435
  * The distance from the camera to the target.
@@ -51426,8 +51442,7 @@ void main() {
51426
51442
  */
51427
51443
  save() {
51428
51444
  this._lerp.cancel();
51429
- this._savedPosition.copy(this.position);
51430
- this._savedTarget.copy(this._target);
51445
+ this._savedState.save();
51431
51446
  }
51432
51447
  /**
51433
51448
  * Represents whether the camera projection is orthographic.