@mml-io/3d-web-client-core 0.9.0 → 0.10.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.
@@ -26,14 +26,22 @@ export declare class CameraManager {
26
26
  private hadTarget;
27
27
  private rayCaster;
28
28
  private eventHandlerCollection;
29
+ private isLerping;
30
+ private finalTarget;
31
+ private lerpTarget;
32
+ private lerpFactor;
33
+ private lerpDuration;
29
34
  constructor(targetElement: HTMLElement, collisionsManager: CollisionsManager, initialPhi?: number, initialTheta?: number);
30
35
  private onMouseDown;
31
36
  private onMouseUp;
32
37
  private onMouseMove;
33
38
  private onMouseWheel;
34
39
  setTarget(target: Vector3): void;
40
+ setLerpedTarget(target: Vector3, targetDistance: number): void;
35
41
  private reverseUpdateFromPositions;
36
42
  adjustCameraPosition(): void;
37
43
  dispose(): void;
44
+ private easeOutExpo;
45
+ updateAspect(aspect: number): void;
38
46
  update(): void;
39
47
  }
package/build/index.js CHANGED
@@ -34,9 +34,6 @@ var round = (n, digits) => {
34
34
  var ease = (target, n, factor) => {
35
35
  return round((target - n) * factor, 5);
36
36
  };
37
- function clamp(value, min, max) {
38
- return Math.min(Math.max(value, min), max);
39
- }
40
37
  var remap = (value, minValue, maxValue, minScaledValue, maxScaledValue) => {
41
38
  return minScaledValue + (maxScaledValue - minScaledValue) * (value - minValue) / (maxValue - minValue);
42
39
  };
@@ -112,6 +109,11 @@ var CameraManager = class {
112
109
  this.dragging = false;
113
110
  this.target = new Vector32(0, 1.55, 0);
114
111
  this.hadTarget = false;
112
+ this.isLerping = false;
113
+ this.finalTarget = new Vector32();
114
+ this.lerpTarget = new Vector32();
115
+ this.lerpFactor = 0;
116
+ this.lerpDuration = 2.1;
115
117
  this.phi = initialPhi;
116
118
  this.targetPhi = initialPhi;
117
119
  this.theta = initialTheta;
@@ -153,12 +155,24 @@ var CameraManager = class {
153
155
  event.preventDefault();
154
156
  }
155
157
  setTarget(target) {
156
- this.target.copy(target);
158
+ if (!this.isLerping) {
159
+ this.target.copy(target);
160
+ } else {
161
+ this.finalTarget.copy(target);
162
+ this.lerpTarget.copy(this.target);
163
+ this.lerpFactor = 0;
164
+ }
157
165
  if (!this.hadTarget) {
158
166
  this.hadTarget = true;
159
167
  this.reverseUpdateFromPositions();
160
168
  }
161
169
  }
170
+ setLerpedTarget(target, targetDistance) {
171
+ this.isLerping = true;
172
+ this.targetDistance = targetDistance;
173
+ this.desiredDistance = targetDistance;
174
+ this.setTarget(target);
175
+ }
162
176
  reverseUpdateFromPositions() {
163
177
  if (this.phi === null || this.theta == null)
164
178
  return;
@@ -189,9 +203,20 @@ var CameraManager = class {
189
203
  dispose() {
190
204
  this.eventHandlerCollection.clear();
191
205
  }
206
+ easeOutExpo(x) {
207
+ return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
208
+ }
209
+ updateAspect(aspect) {
210
+ this.camera.aspect = aspect;
211
+ }
192
212
  update() {
193
- if (this.target === null)
194
- return;
213
+ if (this.isLerping && this.lerpFactor < 1) {
214
+ this.lerpFactor += 0.01 / this.lerpDuration;
215
+ this.lerpFactor = Math.min(1, this.lerpFactor);
216
+ this.target.lerpVectors(this.lerpTarget, this.finalTarget, this.easeOutExpo(this.lerpFactor));
217
+ } else {
218
+ this.adjustCameraPosition();
219
+ }
195
220
  if (this.phi !== null && this.targetPhi !== null && this.theta !== null && this.targetTheta !== null) {
196
221
  this.distance += (this.targetDistance - this.distance) * this.dampingFactor * 0.21;
197
222
  this.phi += (this.targetPhi - this.phi) * this.dampingFactor;
@@ -206,13 +231,14 @@ var CameraManager = class {
206
231
  this.minFOV,
207
232
  this.maxFOV
208
233
  );
209
- this.fov += ease(this.targetFOV, this.fov, 0.07);
234
+ this.fov += (this.targetFOV - this.fov) * this.dampingFactor;
210
235
  this.camera.fov = this.fov;
211
236
  this.camera.updateProjectionMatrix();
212
- this.camera.updateMatrixWorld();
213
- this.camera.position.set(x, clamp(y, 0.1, Infinity), z);
214
- this.adjustCameraPosition();
237
+ this.camera.position.set(x, y, z);
215
238
  this.camera.lookAt(this.target);
239
+ if (this.isLerping && this.lerpFactor >= 1) {
240
+ this.isLerping = false;
241
+ }
216
242
  }
217
243
  }
218
244
  };
@@ -1869,6 +1895,7 @@ var MMLCompositionScene = class {
1869
1895
  this.audioListener = audioListener;
1870
1896
  this.collisionsManager = collisionsManager;
1871
1897
  this.getUserPositionAndRotation = getUserPositionAndRotation;
1898
+ this.chatProbes = /* @__PURE__ */ new Set();
1872
1899
  this.group = new Group2();
1873
1900
  this.promptManager = PromptManager.init(targetElement);
1874
1901
  const { interactionListener, interactionManager } = InteractionManager.init(
@@ -1903,12 +1930,25 @@ var MMLCompositionScene = class {
1903
1930
  removeInteraction: (interaction) => {
1904
1931
  this.interactionListener.removeInteraction(interaction);
1905
1932
  },
1933
+ addChatProbe: (chatProbe) => {
1934
+ this.chatProbes.add(chatProbe);
1935
+ },
1936
+ updateChatProbe: () => {
1937
+ },
1938
+ removeChatProbe: (chatProbe) => {
1939
+ this.chatProbes.delete(chatProbe);
1940
+ },
1906
1941
  prompt: (promptProps, callback) => {
1907
1942
  this.promptManager.prompt(promptProps, callback);
1908
1943
  }
1909
1944
  };
1910
1945
  this.clickTrigger = MMLClickTrigger.init(targetElement, this.mmlScene);
1911
1946
  }
1947
+ onChatMessage(message) {
1948
+ for (const chatProbe of this.chatProbes) {
1949
+ chatProbe.trigger(message);
1950
+ }
1951
+ }
1912
1952
  dispose() {
1913
1953
  this.promptManager.dispose();
1914
1954
  this.clickTrigger.dispose();