@mml-io/3d-web-client-core 0.0.0-experimental-b7ccddd-20231027 → 0.0.0-experimental-b8fa489-20231107

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,23 @@ 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;
34
+ private fixedOnTarget;
29
35
  constructor(targetElement: HTMLElement, collisionsManager: CollisionsManager, initialPhi?: number, initialTheta?: number);
30
36
  private onMouseDown;
31
37
  private onMouseUp;
32
38
  private onMouseMove;
33
39
  private onMouseWheel;
34
40
  setTarget(target: Vector3): void;
41
+ setLerpedTarget(target: Vector3): void;
35
42
  private reverseUpdateFromPositions;
36
43
  adjustCameraPosition(): void;
37
44
  dispose(): void;
45
+ private easeOutExpo;
46
+ updateAspect(aspect: number): void;
38
47
  update(): void;
39
48
  }
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,12 @@ 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;
117
+ this.fixedOnTarget = false;
115
118
  this.phi = initialPhi;
116
119
  this.targetPhi = initialPhi;
117
120
  this.theta = initialTheta;
@@ -135,6 +138,7 @@ var CameraManager = class {
135
138
  onMouseMove(event) {
136
139
  if (!this.dragging || getTweakpaneActive())
137
140
  return;
141
+ this.fixedOnTarget = false;
138
142
  if (this.targetTheta === null || this.targetPhi === null)
139
143
  return;
140
144
  this.targetTheta += event.movementX * 0.01;
@@ -143,6 +147,7 @@ var CameraManager = class {
143
147
  event.preventDefault();
144
148
  }
145
149
  onMouseWheel(event) {
150
+ this.fixedOnTarget = false;
146
151
  const scrollAmount = event.deltaY * 1e-3;
147
152
  this.targetDistance += scrollAmount;
148
153
  this.targetDistance = Math.max(
@@ -153,12 +158,23 @@ var CameraManager = class {
153
158
  event.preventDefault();
154
159
  }
155
160
  setTarget(target) {
156
- this.target.copy(target);
161
+ if (!this.isLerping) {
162
+ this.target.copy(target);
163
+ } else {
164
+ this.finalTarget.copy(target);
165
+ this.lerpTarget.copy(this.target);
166
+ this.lerpFactor = 0;
167
+ }
157
168
  if (!this.hadTarget) {
158
169
  this.hadTarget = true;
159
170
  this.reverseUpdateFromPositions();
160
171
  }
161
172
  }
173
+ setLerpedTarget(target) {
174
+ this.isLerping = true;
175
+ this.fixedOnTarget = true;
176
+ this.setTarget(target);
177
+ }
162
178
  reverseUpdateFromPositions() {
163
179
  if (this.phi === null || this.theta == null)
164
180
  return;
@@ -189,9 +205,20 @@ var CameraManager = class {
189
205
  dispose() {
190
206
  this.eventHandlerCollection.clear();
191
207
  }
208
+ easeOutExpo(x) {
209
+ return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
210
+ }
211
+ updateAspect(aspect) {
212
+ this.camera.aspect = aspect;
213
+ }
192
214
  update() {
193
- if (this.target === null)
194
- return;
215
+ if (this.isLerping && this.lerpFactor < 1) {
216
+ this.lerpFactor += 0.01 / this.lerpDuration;
217
+ this.lerpFactor = Math.min(1, this.lerpFactor);
218
+ this.target.lerpVectors(this.lerpTarget, this.finalTarget, this.easeOutExpo(this.lerpFactor));
219
+ } else if (!this.fixedOnTarget) {
220
+ this.adjustCameraPosition();
221
+ }
195
222
  if (this.phi !== null && this.targetPhi !== null && this.theta !== null && this.targetTheta !== null) {
196
223
  this.distance += (this.targetDistance - this.distance) * this.dampingFactor * 0.21;
197
224
  this.phi += (this.targetPhi - this.phi) * this.dampingFactor;
@@ -206,13 +233,14 @@ var CameraManager = class {
206
233
  this.minFOV,
207
234
  this.maxFOV
208
235
  );
209
- this.fov += ease(this.targetFOV, this.fov, 0.07);
236
+ this.fov += (this.targetFOV - this.fov) * this.dampingFactor;
210
237
  this.camera.fov = this.fov;
211
238
  this.camera.updateProjectionMatrix();
212
- this.camera.updateMatrixWorld();
213
- this.camera.position.set(x, clamp(y, 0.1, Infinity), z);
214
- this.adjustCameraPosition();
239
+ this.camera.position.set(x, y, z);
215
240
  this.camera.lookAt(this.target);
241
+ if (this.isLerping && this.lerpFactor >= 1) {
242
+ this.isLerping = false;
243
+ }
216
244
  }
217
245
  }
218
246
  };
@@ -1869,6 +1897,7 @@ var MMLCompositionScene = class {
1869
1897
  this.audioListener = audioListener;
1870
1898
  this.collisionsManager = collisionsManager;
1871
1899
  this.getUserPositionAndRotation = getUserPositionAndRotation;
1900
+ this.chatProbes = /* @__PURE__ */ new Set();
1872
1901
  this.group = new Group2();
1873
1902
  this.promptManager = PromptManager.init(targetElement);
1874
1903
  const { interactionListener, interactionManager } = InteractionManager.init(
@@ -1903,12 +1932,25 @@ var MMLCompositionScene = class {
1903
1932
  removeInteraction: (interaction) => {
1904
1933
  this.interactionListener.removeInteraction(interaction);
1905
1934
  },
1935
+ addChatProbe: (chatProbe) => {
1936
+ this.chatProbes.add(chatProbe);
1937
+ },
1938
+ updateChatProbe: () => {
1939
+ },
1940
+ removeChatProbe: (chatProbe) => {
1941
+ this.chatProbes.delete(chatProbe);
1942
+ },
1906
1943
  prompt: (promptProps, callback) => {
1907
1944
  this.promptManager.prompt(promptProps, callback);
1908
1945
  }
1909
1946
  };
1910
1947
  this.clickTrigger = MMLClickTrigger.init(targetElement, this.mmlScene);
1911
1948
  }
1949
+ onChatMessage(message) {
1950
+ for (const chatProbe of this.chatProbes) {
1951
+ chatProbe.trigger(message);
1952
+ }
1953
+ }
1912
1954
  dispose() {
1913
1955
  this.promptManager.dispose();
1914
1956
  this.clickTrigger.dispose();