@mml-io/3d-web-client-core 0.0.0-experimental-8e179c2-20240414 → 0.0.0-experimental-a61f041-20240424

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.
@@ -15,9 +15,16 @@ export type CharacterDescription = {
15
15
  meshFileUrl?: string;
16
16
  mmlCharacterUrl?: string;
17
17
  mmlCharacterString?: string;
18
- };
18
+ } & ({
19
+ meshFileUrl: string;
20
+ } | {
21
+ mmlCharacterUrl: string;
22
+ } | {
23
+ mmlCharacterString: string;
24
+ });
19
25
  export declare class Character extends Group {
20
- private readonly characterDescription;
26
+ private username;
27
+ private characterDescription;
21
28
  private readonly animationConfig;
22
29
  private readonly characterModelLoader;
23
30
  private readonly characterId;
@@ -27,9 +34,10 @@ export declare class Character extends Group {
27
34
  private readonly isLocal;
28
35
  private model;
29
36
  color: Color;
30
- tooltip: CharacterTooltip | null;
37
+ tooltip: CharacterTooltip;
31
38
  speakingIndicator: CharacterSpeakingIndicator | null;
32
- constructor(characterDescription: CharacterDescription, animationConfig: AnimationConfig, characterModelLoader: CharacterModelLoader, characterId: number, modelLoadedCallback: () => void, cameraManager: CameraManager, composer: Composer, isLocal: boolean);
39
+ constructor(username: string, characterDescription: CharacterDescription, animationConfig: AnimationConfig, characterModelLoader: CharacterModelLoader, characterId: number, modelLoadedCallback: () => void, cameraManager: CameraManager, composer: Composer, isLocal: boolean);
40
+ updateCharacter(username: string, characterDescription: CharacterDescription): void;
33
41
  private load;
34
42
  updateAnimation(targetAnimation: AnimationState): void;
35
43
  update(time: number, deltaTime: number): void;
@@ -19,10 +19,10 @@ export declare class CharacterManager {
19
19
  private readonly clientStates;
20
20
  private readonly sendUpdate;
21
21
  private readonly animationConfig;
22
- private readonly characterDescription;
22
+ private readonly characterResolve;
23
23
  private updateLocationHash;
24
24
  readonly headTargetOffset: Vector3;
25
- private id;
25
+ private localClientId;
26
26
  remoteCharacters: Map<number, Character>;
27
27
  remoteCharacterControllers: Map<number, RemoteController>;
28
28
  private localCharacterSpawned;
@@ -30,11 +30,15 @@ export declare class CharacterManager {
30
30
  localCharacter: Character | null;
31
31
  private speakingCharacters;
32
32
  readonly group: Group;
33
- constructor(composer: Composer, characterModelLoader: CharacterModelLoader, collisionsManager: CollisionsManager, cameraManager: CameraManager, timeManager: TimeManager, keyInputManager: KeyInputManager, clientStates: Map<number, CharacterState>, sendUpdate: (update: CharacterState) => void, animationConfig: AnimationConfig, characterDescription: CharacterDescription);
34
- spawnLocalCharacter(characterDescription: CharacterDescription, id: number, spawnPosition?: Vector3, spawnRotation?: Euler): void;
35
- spawnRemoteCharacter(characterDescription: CharacterDescription, id: number, spawnPosition?: Vector3, spawnRotation?: Euler): void;
33
+ constructor(composer: Composer, characterModelLoader: CharacterModelLoader, collisionsManager: CollisionsManager, cameraManager: CameraManager, timeManager: TimeManager, keyInputManager: KeyInputManager, clientStates: Map<number, CharacterState>, sendUpdate: (update: CharacterState) => void, animationConfig: AnimationConfig, characterResolve: (clientId: number) => {
34
+ username: string;
35
+ characterDescription: CharacterDescription;
36
+ });
37
+ spawnLocalCharacter(id: number, username: string, characterDescription: CharacterDescription, spawnPosition?: Vector3, spawnRotation?: Euler): void;
38
+ spawnRemoteCharacter(id: number, username: string, characterDescription: CharacterDescription, spawnPosition?: Vector3, spawnRotation?: Euler): void;
36
39
  getLocalCharacterPositionAndRotation(): PositionAndRotation;
37
40
  clear(): void;
38
41
  setSpeakingCharacter(id: number, value: boolean): void;
42
+ respawnIfPresent(id: number): void;
39
43
  update(): void;
40
44
  }
package/build/index.js CHANGED
@@ -1175,7 +1175,7 @@ var defaultLabelColor = new Color2(0);
1175
1175
  var defaultFontColor = new Color2(16777215);
1176
1176
  var defaultLabelAlignment = "center" /* center */;
1177
1177
  var defaultLabelFontSize = 8;
1178
- var defaultLabelPadding = 0;
1178
+ var defaultLabelPadding = 8;
1179
1179
  var defaultLabelWidth = 0.25;
1180
1180
  var defaultLabelHeight = 0.1;
1181
1181
  var defaultLabelCastShadows = true;
@@ -1231,10 +1231,6 @@ var CharacterTooltip = class extends Mesh3 {
1231
1231
  b: this.props.color.b * 255,
1232
1232
  a: 1
1233
1233
  },
1234
- dimensions: {
1235
- width: this.props.width * (100 * fontScale),
1236
- height: this.props.height * (100 * fontScale)
1237
- },
1238
1234
  alignment: this.props.alignment
1239
1235
  });
1240
1236
  this.tooltipMaterial.map = texture;
@@ -1246,7 +1242,8 @@ var CharacterTooltip = class extends Mesh3 {
1246
1242
  this.position.y = 1.4;
1247
1243
  }
1248
1244
  setText(text, temporary = false) {
1249
- this.redrawText(text);
1245
+ const sanitizedText = text.replace(/(\r\n|\n|\r)/gm, "");
1246
+ this.redrawText(sanitizedText);
1250
1247
  this.visible = true;
1251
1248
  this.targetOpacity = this.visibleOpacity;
1252
1249
  if (temporary) {
@@ -1287,8 +1284,9 @@ var CharacterTooltip = class extends Mesh3 {
1287
1284
 
1288
1285
  // src/character/Character.ts
1289
1286
  var Character = class extends Group {
1290
- constructor(characterDescription, animationConfig, characterModelLoader, characterId, modelLoadedCallback, cameraManager, composer, isLocal) {
1287
+ constructor(username, characterDescription, animationConfig, characterModelLoader, characterId, modelLoadedCallback, cameraManager, composer, isLocal) {
1291
1288
  super();
1289
+ this.username = username;
1292
1290
  this.characterDescription = characterDescription;
1293
1291
  this.animationConfig = animationConfig;
1294
1292
  this.characterModelLoader = characterModelLoader;
@@ -1299,13 +1297,22 @@ var Character = class extends Group {
1299
1297
  this.isLocal = isLocal;
1300
1298
  this.model = null;
1301
1299
  this.color = new Color3();
1302
- this.tooltip = null;
1303
1300
  this.speakingIndicator = null;
1304
1301
  this.tooltip = new CharacterTooltip();
1302
+ this.tooltip.setText(this.username, isLocal);
1305
1303
  this.add(this.tooltip);
1304
+ this.load().then(() => {
1305
+ this.modelLoadedCallback();
1306
+ });
1307
+ }
1308
+ updateCharacter(username, characterDescription) {
1309
+ this.username = username;
1310
+ this.characterDescription = characterDescription;
1306
1311
  this.load();
1312
+ this.tooltip.setText(username, this.isLocal);
1307
1313
  }
1308
- async load() {
1314
+ async load(callback) {
1315
+ const previousModel = this.model;
1309
1316
  this.model = new CharacterModel(
1310
1317
  this.characterDescription,
1311
1318
  this.animationConfig,
@@ -1315,11 +1322,13 @@ var Character = class extends Group {
1315
1322
  this.isLocal
1316
1323
  );
1317
1324
  await this.model.init();
1325
+ if (previousModel && previousModel.mesh) {
1326
+ this.remove(previousModel.mesh);
1327
+ }
1318
1328
  this.add(this.model.mesh);
1319
1329
  if (this.speakingIndicator === null) {
1320
1330
  this.speakingIndicator = new CharacterSpeakingIndicator(this.composer.postPostScene);
1321
1331
  }
1322
- this.modelLoadedCallback();
1323
1332
  }
1324
1333
  updateAnimation(targetAnimation) {
1325
1334
  var _a;
@@ -1732,7 +1741,7 @@ function decodeCharacterAndCamera(hash) {
1732
1741
 
1733
1742
  // src/character/CharacterManager.ts
1734
1743
  var CharacterManager = class {
1735
- constructor(composer, characterModelLoader, collisionsManager, cameraManager, timeManager, keyInputManager, clientStates, sendUpdate, animationConfig, characterDescription) {
1744
+ constructor(composer, characterModelLoader, collisionsManager, cameraManager, timeManager, keyInputManager, clientStates, sendUpdate, animationConfig, characterResolve) {
1736
1745
  this.composer = composer;
1737
1746
  this.characterModelLoader = characterModelLoader;
1738
1747
  this.collisionsManager = collisionsManager;
@@ -1742,10 +1751,10 @@ var CharacterManager = class {
1742
1751
  this.clientStates = clientStates;
1743
1752
  this.sendUpdate = sendUpdate;
1744
1753
  this.animationConfig = animationConfig;
1745
- this.characterDescription = characterDescription;
1754
+ this.characterResolve = characterResolve;
1746
1755
  this.updateLocationHash = true;
1747
1756
  this.headTargetOffset = new Vector38(0, 1.3, 0);
1748
- this.id = 0;
1757
+ this.localClientId = 0;
1749
1758
  this.remoteCharacters = /* @__PURE__ */ new Map();
1750
1759
  this.remoteCharacterControllers = /* @__PURE__ */ new Map();
1751
1760
  this.localCharacterSpawned = false;
@@ -1753,9 +1762,9 @@ var CharacterManager = class {
1753
1762
  this.speakingCharacters = /* @__PURE__ */ new Map();
1754
1763
  this.group = new Group2();
1755
1764
  }
1756
- spawnLocalCharacter(characterDescription, id, spawnPosition = new Vector38(), spawnRotation = new Euler2()) {
1757
- var _a;
1765
+ spawnLocalCharacter(id, username, characterDescription, spawnPosition = new Vector38(), spawnRotation = new Euler2()) {
1758
1766
  const character = new Character(
1767
+ username,
1759
1768
  characterDescription,
1760
1769
  this.animationConfig,
1761
1770
  this.characterModelLoader,
@@ -1777,11 +1786,11 @@ var CharacterManager = class {
1777
1786
  rotation: { quaternionY: quaternion.y, quaternionW: quaternion.w },
1778
1787
  state: 0 /* idle */
1779
1788
  });
1780
- this.id = id;
1789
+ this.localClientId = id;
1781
1790
  this.localCharacter = character;
1782
1791
  this.localController = new LocalController(
1783
1792
  this.localCharacter,
1784
- this.id,
1793
+ this.localClientId,
1785
1794
  this.collisionsManager,
1786
1795
  this.keyInputManager,
1787
1796
  this.cameraManager,
@@ -1789,13 +1798,12 @@ var CharacterManager = class {
1789
1798
  );
1790
1799
  this.localCharacter.position.set(spawnPosition.x, spawnPosition.y, spawnPosition.z);
1791
1800
  this.localCharacter.rotation.set(spawnRotation.x, spawnRotation.y, spawnRotation.z);
1792
- (_a = character.tooltip) == null ? void 0 : _a.setText(`${id}`, true);
1793
1801
  this.group.add(character);
1794
1802
  this.localCharacterSpawned = true;
1795
1803
  }
1796
- spawnRemoteCharacter(characterDescription, id, spawnPosition = new Vector38(), spawnRotation = new Euler2()) {
1797
- var _a;
1804
+ spawnRemoteCharacter(id, username, characterDescription, spawnPosition = new Vector38(), spawnRotation = new Euler2()) {
1798
1805
  const character = new Character(
1806
+ username,
1799
1807
  characterDescription,
1800
1808
  this.animationConfig,
1801
1809
  this.characterModelLoader,
@@ -1811,7 +1819,6 @@ var CharacterManager = class {
1811
1819
  remoteController.character.position.set(spawnPosition.x, spawnPosition.y, spawnPosition.z);
1812
1820
  remoteController.character.rotation.set(spawnRotation.x, spawnRotation.y, spawnRotation.z);
1813
1821
  this.remoteCharacterControllers.set(id, remoteController);
1814
- (_a = character.tooltip) == null ? void 0 : _a.setText(`${id}`);
1815
1822
  this.group.add(character);
1816
1823
  }
1817
1824
  getLocalCharacterPositionAndRotation() {
@@ -1840,12 +1847,27 @@ var CharacterManager = class {
1840
1847
  setSpeakingCharacter(id, value) {
1841
1848
  this.speakingCharacters.set(id, value);
1842
1849
  }
1850
+ respawnIfPresent(id) {
1851
+ const characterInfo = this.characterResolve(id);
1852
+ if (this.localCharacter && this.localClientId == id) {
1853
+ this.localCharacter.updateCharacter(
1854
+ characterInfo.username,
1855
+ characterInfo.characterDescription
1856
+ );
1857
+ }
1858
+ const remoteCharacter = this.remoteCharacters.get(id);
1859
+ if (remoteCharacter) {
1860
+ remoteCharacter.updateCharacter(characterInfo.username, characterInfo.characterDescription);
1861
+ }
1862
+ }
1843
1863
  update() {
1844
1864
  var _a, _b, _c;
1845
1865
  if (this.localCharacter) {
1846
1866
  this.localCharacter.update(this.timeManager.time, this.timeManager.deltaTime);
1847
- if (this.speakingCharacters.has(this.id)) {
1848
- (_a = this.localCharacter.speakingIndicator) == null ? void 0 : _a.setSpeaking(this.speakingCharacters.get(this.id));
1867
+ if (this.speakingCharacters.has(this.localClientId)) {
1868
+ (_a = this.localCharacter.speakingIndicator) == null ? void 0 : _a.setSpeaking(
1869
+ this.speakingCharacters.get(this.localClientId)
1870
+ );
1849
1871
  }
1850
1872
  this.localController.update();
1851
1873
  if (this.timeManager.frame % 2 === 0) {
@@ -1861,9 +1883,11 @@ var CharacterManager = class {
1861
1883
  }
1862
1884
  const { position } = update;
1863
1885
  if (!this.remoteCharacters.has(id) && this.localCharacterSpawned === true) {
1886
+ const characterInfo = this.characterResolve(id);
1864
1887
  this.spawnRemoteCharacter(
1865
- this.characterDescription,
1866
1888
  id,
1889
+ characterInfo.username,
1890
+ characterInfo.characterDescription,
1867
1891
  new Vector38(position.x, position.y, position.z)
1868
1892
  );
1869
1893
  }