@mml-io/3d-web-client-core 0.0.0-experimental-45912e3-20240802 → 0.0.0-experimental-4934217-20240805

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.
package/build/index.js CHANGED
@@ -2489,7 +2489,8 @@ import {
2489
2489
  InteractionManager,
2490
2490
  MMLClickTrigger,
2491
2491
  PromptManager,
2492
- LoadingProgressManager
2492
+ LoadingProgressManager,
2493
+ MMLDocumentTimeManager
2493
2494
  } from "mml-web";
2494
2495
  import { Group as Group3 } from "three";
2495
2496
  var MMLCompositionScene = class {
@@ -2506,6 +2507,7 @@ var MMLCompositionScene = class {
2506
2507
  this.interactionManager = interactionManager;
2507
2508
  this.interactionListener = interactionListener;
2508
2509
  this.loadingProgressManager = new LoadingProgressManager();
2510
+ this.documentTimeManager = new MMLDocumentTimeManager();
2509
2511
  this.mmlScene = {
2510
2512
  getAudioListener: () => this.config.audioListener,
2511
2513
  getRenderer: () => this.config.renderer,
@@ -3445,24 +3447,27 @@ var TweakPane = class {
3445
3447
  this.characterControls = new CharacterControlsFolder(this.gui, false);
3446
3448
  this.toneMappingFolder.folder.hidden = rendererValues.toneMapping === 5 ? false : true;
3447
3449
  this.export = this.gui.addFolder({ title: "import / export", expanded: false });
3448
- this.setupGUIListeners();
3449
- window.addEventListener("keydown", (e) => {
3450
- this.processKey(e);
3451
- });
3452
- }
3453
- setupGUIListeners() {
3450
+ this.eventHandlerCollection = new EventHandlerCollection();
3454
3451
  const gui = this.gui;
3455
3452
  const paneElement = gui.containerElem_;
3456
3453
  paneElement.style.right = this.guiVisible ? "0px" : "-450px";
3457
- this.gui.element.addEventListener("mouseenter", () => setTweakpaneActive(true));
3458
- this.gui.element.addEventListener("mousemove", () => setTweakpaneActive(true));
3459
- this.gui.element.addEventListener("mousedown", () => setTweakpaneActive(true));
3460
- this.gui.element.addEventListener("mouseleave", () => setTweakpaneActive(false));
3461
- this.gui.element.addEventListener("mouseup", () => setTweakpaneActive(false));
3454
+ this.eventHandlerCollection.add(this.gui.element, "mouseenter", () => setTweakpaneActive(true));
3455
+ this.eventHandlerCollection.add(this.gui.element, "mousemove", () => setTweakpaneActive(true));
3456
+ this.eventHandlerCollection.add(this.gui.element, "mousedown", () => setTweakpaneActive(true));
3457
+ this.eventHandlerCollection.add(
3458
+ this.gui.element,
3459
+ "mouseleave",
3460
+ () => setTweakpaneActive(false)
3461
+ );
3462
+ this.eventHandlerCollection.add(this.gui.element, "mouseup", () => setTweakpaneActive(false));
3463
+ this.eventHandlerCollection.add(window, "keydown", (e) => {
3464
+ this.processKey(e);
3465
+ });
3462
3466
  }
3463
3467
  processKey(e) {
3464
- if (e.key === "p")
3468
+ if (e.key === "p") {
3465
3469
  this.toggleGUI();
3470
+ }
3466
3471
  }
3467
3472
  setupRenderPane(composer, normalPass, ppssaoEffect, ppssaoPass, n8aopass, toneMappingEffect, toneMappingPass, brightnessContrastSaturation, bloomEffect, gaussGrainEffect, hasLighting, sun, setHDR, setSkyboxAzimuthalAngle, setSkyboxPolarAngle, setAmbientLight, setFog) {
3468
3473
  this.rendererFolder.setupChangeEvent(
@@ -3496,6 +3501,7 @@ var TweakPane = class {
3496
3501
  });
3497
3502
  }
3498
3503
  dispose() {
3504
+ this.eventHandlerCollection.clear();
3499
3505
  this.gui.dispose();
3500
3506
  this.tweakPaneWrapper.remove();
3501
3507
  }
@@ -5153,12 +5159,12 @@ var Composer = class {
5153
5159
  this.width = 1;
5154
5160
  this.height = 1;
5155
5161
  this.resolution = new Vector27(this.width, this.height);
5156
- this.isEnvHDRI = false;
5157
5162
  this.bcs = BrightnessContrastSaturation;
5158
5163
  this.gaussGrainEffect = GaussGrainEffect;
5159
5164
  this.ambientLight = null;
5165
+ this.skyboxState = { src: {}, latestPromise: null };
5160
5166
  this.sun = null;
5161
- var _a;
5167
+ var _a, _b;
5162
5168
  this.scene = scene;
5163
5169
  this.postPostScene = new Scene4();
5164
5170
  this.camera = camera;
@@ -5271,6 +5277,13 @@ var Composer = class {
5271
5277
  this.sun = new Sun();
5272
5278
  this.scene.add(this.sun);
5273
5279
  }
5280
+ if ((_b = this.environmentConfiguration) == null ? void 0 : _b.skybox) {
5281
+ if ("hdrJpgUrl" in this.environmentConfiguration.skybox) {
5282
+ this.useHDRJPG(this.environmentConfiguration.skybox.hdrJpgUrl);
5283
+ } else if ("hdrUrl" in this.environmentConfiguration.skybox) {
5284
+ this.useHDRI(this.environmentConfiguration.skybox.hdrUrl);
5285
+ }
5286
+ }
5274
5287
  this.updateSunValues();
5275
5288
  this.resizeListener = () => {
5276
5289
  this.fitContainer();
@@ -5278,6 +5291,19 @@ var Composer = class {
5278
5291
  window.addEventListener("resize", this.resizeListener, false);
5279
5292
  this.fitContainer();
5280
5293
  }
5294
+ updateEnvironmentConfiguration(environmentConfiguration) {
5295
+ this.environmentConfiguration = environmentConfiguration;
5296
+ if (environmentConfiguration.skybox) {
5297
+ if ("hdrJpgUrl" in environmentConfiguration.skybox) {
5298
+ this.useHDRJPG(environmentConfiguration.skybox.hdrJpgUrl);
5299
+ } else if ("hdrUrl" in environmentConfiguration.skybox) {
5300
+ this.useHDRI(environmentConfiguration.skybox.hdrUrl);
5301
+ }
5302
+ }
5303
+ this.updateSkyboxAndEnvValues();
5304
+ this.updateAmbientLightValues();
5305
+ this.updateSunValues();
5306
+ }
5281
5307
  setupTweakPane(tweakPane) {
5282
5308
  tweakPane.setupRenderPane(
5283
5309
  this.effectComposer,
@@ -5368,71 +5394,71 @@ var Composer = class {
5368
5394
  0
5369
5395
  );
5370
5396
  }
5371
- useHDRJPG(url, fromFile = false) {
5372
- const pmremGenerator = new PMREMGenerator(this.renderer);
5373
- const hdrJpg = new HDRJPGLoader(this.renderer).load(url, () => {
5374
- const hdrJpgEquirectangularMap = hdrJpg.renderTarget.texture;
5375
- hdrJpgEquirectangularMap.mapping = EquirectangularReflectionMapping;
5376
- hdrJpgEquirectangularMap.needsUpdate = true;
5377
- const envMap = pmremGenerator.fromEquirectangular(hdrJpgEquirectangularMap).texture;
5378
- if (envMap) {
5379
- envMap.colorSpace = LinearSRGBColorSpace;
5380
- envMap.needsUpdate = true;
5381
- this.scene.environment = envMap;
5382
- this.scene.environmentIntensity = envValues.envMapIntensity;
5383
- this.scene.environmentRotation = new Euler3(
5384
- MathUtils.degToRad(envValues.skyboxPolarAngle),
5385
- MathUtils.degToRad(envValues.skyboxAzimuthalAngle),
5386
- 0
5387
- );
5388
- this.scene.background = envMap;
5389
- this.scene.backgroundIntensity = envValues.skyboxIntensity;
5390
- this.scene.backgroundBlurriness = envValues.skyboxBlurriness;
5391
- this.scene.backgroundRotation = new Euler3(
5392
- MathUtils.degToRad(envValues.skyboxPolarAngle),
5393
- MathUtils.degToRad(envValues.skyboxAzimuthalAngle),
5394
- 0
5395
- );
5396
- this.isEnvHDRI = true;
5397
+ async loadHDRJPG(url) {
5398
+ return new Promise((resolve, reject) => {
5399
+ const pmremGenerator = new PMREMGenerator(this.renderer);
5400
+ const hdrJpg = new HDRJPGLoader(this.renderer).load(url, () => {
5401
+ const hdrJpgEquirectangularMap = hdrJpg.renderTarget.texture;
5402
+ hdrJpgEquirectangularMap.mapping = EquirectangularReflectionMapping;
5403
+ hdrJpgEquirectangularMap.needsUpdate = true;
5404
+ const envMap = pmremGenerator.fromEquirectangular(hdrJpgEquirectangularMap).texture;
5397
5405
  hdrJpgEquirectangularMap.dispose();
5398
5406
  pmremGenerator.dispose();
5399
- }
5400
- hdrJpg.dispose();
5407
+ hdrJpg.dispose();
5408
+ if (envMap) {
5409
+ envMap.colorSpace = LinearSRGBColorSpace;
5410
+ envMap.needsUpdate = true;
5411
+ resolve(envMap);
5412
+ } else {
5413
+ reject("Failed to generate environment map");
5414
+ }
5415
+ });
5401
5416
  });
5402
5417
  }
5403
- useHDRI(url, fromFile = false) {
5404
- if (this.isEnvHDRI && fromFile === false || !this.renderer) {
5405
- return;
5406
- }
5407
- const pmremGenerator = new PMREMGenerator(this.renderer);
5408
- new RGBELoader(new LoadingManager()).load(
5409
- url,
5410
- (texture) => {
5418
+ async loadHDRi(url) {
5419
+ return new Promise((resolve, reject) => {
5420
+ const pmremGenerator = new PMREMGenerator(this.renderer);
5421
+ new RGBELoader(new LoadingManager()).load(url, (texture) => {
5411
5422
  const envMap = pmremGenerator.fromEquirectangular(texture).texture;
5423
+ texture.dispose();
5424
+ pmremGenerator.dispose();
5412
5425
  if (envMap) {
5413
5426
  envMap.colorSpace = LinearSRGBColorSpace;
5414
5427
  envMap.needsUpdate = true;
5415
- this.scene.environment = envMap;
5416
- this.scene.environmentIntensity = envValues.envMapIntensity;
5417
- this.scene.environmentRotation = new Euler3(
5418
- MathUtils.degToRad(envValues.skyboxPolarAngle),
5419
- MathUtils.degToRad(envValues.skyboxAzimuthalAngle),
5420
- 0
5421
- );
5422
- this.scene.background = envMap;
5423
- this.scene.backgroundIntensity = envValues.skyboxIntensity;
5424
- this.scene.backgroundBlurriness = envValues.skyboxBlurriness;
5425
- this.isEnvHDRI = true;
5426
- texture.dispose();
5427
- pmremGenerator.dispose();
5428
+ resolve(envMap);
5429
+ } else {
5430
+ reject("Failed to generate environment map");
5428
5431
  }
5429
- },
5430
- () => {
5431
- },
5432
- (error) => {
5433
- console.error(`Can't load ${url}: ${JSON.stringify(error)}`);
5432
+ });
5433
+ });
5434
+ }
5435
+ useHDRJPG(url, fromFile = false) {
5436
+ if (this.skyboxState.src.hdrJpgUrl === url) {
5437
+ return;
5438
+ }
5439
+ const hdrJPGPromise = this.loadHDRJPG(url);
5440
+ this.skyboxState.src = { hdrJpgUrl: url };
5441
+ this.skyboxState.latestPromise = hdrJPGPromise;
5442
+ hdrJPGPromise.then((envMap) => {
5443
+ if (this.skyboxState.latestPromise !== hdrJPGPromise) {
5444
+ return;
5434
5445
  }
5435
- );
5446
+ this.applyEnvMap(envMap);
5447
+ });
5448
+ }
5449
+ useHDRI(url) {
5450
+ if (this.skyboxState.src.hdrUrl === url) {
5451
+ return;
5452
+ }
5453
+ const hdrPromise = this.loadHDRi(url);
5454
+ this.skyboxState.src = { hdrUrl: url };
5455
+ this.skyboxState.latestPromise = hdrPromise;
5456
+ hdrPromise.then((envMap) => {
5457
+ if (this.skyboxState.latestPromise !== hdrPromise) {
5458
+ return;
5459
+ }
5460
+ this.applyEnvMap(envMap);
5461
+ });
5436
5462
  }
5437
5463
  setHDRIFromFile() {
5438
5464
  if (!this.renderer)
@@ -5451,7 +5477,7 @@ var Composer = class {
5451
5477
  const fileURL = URL.createObjectURL(file);
5452
5478
  if (fileURL) {
5453
5479
  if (extension === "hdr") {
5454
- this.useHDRI(fileURL, true);
5480
+ this.useHDRI(fileURL);
5455
5481
  } else if (extension === "jpg") {
5456
5482
  this.useHDRJPG(fileURL);
5457
5483
  } else {
@@ -5533,6 +5559,23 @@ var Composer = class {
5533
5559
  }
5534
5560
  this.setAmbientLight();
5535
5561
  }
5562
+ applyEnvMap(envMap) {
5563
+ this.scene.environment = envMap;
5564
+ this.scene.environmentIntensity = envValues.envMapIntensity;
5565
+ this.scene.environmentRotation = new Euler3(
5566
+ MathUtils.degToRad(envValues.skyboxPolarAngle),
5567
+ MathUtils.degToRad(envValues.skyboxAzimuthalAngle),
5568
+ 0
5569
+ );
5570
+ this.scene.background = envMap;
5571
+ this.scene.backgroundIntensity = envValues.skyboxIntensity;
5572
+ this.scene.backgroundBlurriness = envValues.skyboxBlurriness;
5573
+ this.scene.backgroundRotation = new Euler3(
5574
+ MathUtils.degToRad(envValues.skyboxPolarAngle),
5575
+ MathUtils.degToRad(envValues.skyboxAzimuthalAngle),
5576
+ 0
5577
+ );
5578
+ }
5536
5579
  };
5537
5580
 
5538
5581
  // src/time/TimeManager.ts