@needle-tools/engine 4.3.2-beta.3 → 4.3.2-beta.4

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.
@@ -189,6 +189,10 @@ export class Context implements IContext {
189
189
  ContextRegistry.Current = context;
190
190
  }
191
191
 
192
+ static get All(): Context[] {
193
+ return ContextRegistry.All as Context[];
194
+ }
195
+
192
196
  /** The name of the context */
193
197
  name: string;
194
198
  /** An alias for the context */
@@ -1,5 +1,7 @@
1
1
  import { type IComponent, type IContext, type LoadedModel } from "./engine_types.js";
2
2
 
3
+ const debug = typeof window !== undefined ? window.location.search.includes("debugcontext") : false;
4
+
3
5
  /** The various events that can be dispatched by a Needle Engine {@link IContext} instance
4
6
  */
5
7
  export enum ContextEvent {
@@ -62,6 +64,8 @@ export class ContextRegistry {
62
64
 
63
65
  /** @internal Internal use only */
64
66
  static register(ctx: IContext) {
67
+ if (this.Registered.indexOf(ctx) !== -1) return;
68
+ if (debug) console.warn("Registering context");
65
69
  this.Registered.push(ctx);
66
70
  this.dispatchCallback(ContextEvent.ContextRegistered, ctx);
67
71
  }
@@ -70,6 +74,7 @@ export class ContextRegistry {
70
74
  static unregister(ctx: IContext) {
71
75
  const index = this.Registered.indexOf(ctx);
72
76
  if (index === -1) return;
77
+ if (debug) console.warn("Unregistering context");
73
78
  this.Registered.splice(index, 1);
74
79
  }
75
80
 
@@ -61,7 +61,11 @@ export async function tryDetermineFileTypeFromURL(url: string, useExtension: boo
61
61
 
62
62
  // If the URL doesnt contain a filetype we need to check the header
63
63
  // This is the case for example if we load a file from a data url
64
- const header = await fetch(url, {
64
+ const newUrl = new URL(url);
65
+ // Adding a URL parameter to avoid the brower to bust the full cache
66
+ // If we don't do this the file that might already be disc cached will be deleted from the cache
67
+ newUrl.searchParams.append("range", "true");
68
+ const header = await fetch(newUrl, {
65
69
  method: "GET",
66
70
  headers: {
67
71
  "range": "bytes=0-32"
@@ -5,7 +5,7 @@ import { KTX2Loader } from "three/examples/jsm/loaders/KTX2Loader.js";
5
5
  import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
6
6
 
7
7
  import { disposeObjectResources, setDisposable } from "../engine/engine_assetdatabase.js";
8
- import { ContextRegistry } from "../engine/engine_context_registry.js";
8
+ import { ContextEvent, ContextRegistry } from "../engine/engine_context_registry.js";
9
9
  import { registerObservableAttribute } from "../engine/engine_element_extras.js";
10
10
  import { syncField } from "../engine/engine_networking_auto.js";
11
11
  import { serializable } from "../engine/engine_serialization_decorator.js";
@@ -39,11 +39,11 @@ function createRemoteSkyboxComponent(context: IContext, url: string, skybox: boo
39
39
  return remote.setSkybox(url);
40
40
  }
41
41
 
42
- ContextRegistry.addContextCreatedCallback((args) => {
42
+ const promises = new Array<Promise<any>>();
43
+ ContextRegistry.registerCallback(ContextEvent.ContextCreationStart, (args) => {
43
44
  const context = args.context;
44
45
  const skyboxImage = context.domElement.getAttribute("skybox-image") || context.domElement.getAttribute("background-image");
45
46
  const environmentImage = context.domElement.getAttribute("environment-image");
46
- const promises = new Array<Promise<any>>();
47
47
  if (skyboxImage) {
48
48
  if (debug)
49
49
  console.log("Creating remote skybox to load " + skyboxImage);
@@ -60,10 +60,11 @@ ContextRegistry.addContextCreatedCallback((args) => {
60
60
  const promise = createRemoteSkyboxComponent(context, environmentImage, false, true, "environment-image");
61
61
  promises.push(promise);
62
62
  }
63
- if (promises.length > 0) {
64
- return PromiseAllWithErrors(promises);
65
- }
66
- return Promise.resolve();
63
+ });
64
+ ContextRegistry.registerCallback(ContextEvent.ContextCreationStart, () => {
65
+ return Promise.all(promises).finally(() => {
66
+ promises.length = 0;
67
+ })
67
68
  });
68
69
 
69
70
  declare type SkyboxCacheEntry = { src: string, texture: Promise<Texture> };