Needle Engine

Changes between version 3.37.8-alpha and 3.37.8-alpha.2
Files changed (8) hide show
  1. src/engine-components/Camera.ts +14 -8
  2. src/engine/engine_lightdata.ts +4 -1
  3. src/engine/engine_loaders.ts +6 -3
  4. src/engine/engine_scenelighting.ts +1 -1
  5. src/engine/engine_utils_screenshot.ts +20 -1
  6. src/engine-components/Skybox.ts +2 -2
  7. plugins/types/userconfig.d.ts +3 -0
  8. plugins/gltf-packer.mjs +1 -0
src/engine-components/Camera.ts CHANGED
@@ -293,7 +293,7 @@
293
293
  this.context.setCurrentCamera(this);
294
294
  handleFreeCam(this);
295
295
  }
296
- this.applyClearFlagsIfIsActiveCamera();
296
+ this.applyClearFlagsIfIsActiveCamera({ applySkybox: true });
297
297
  }
298
298
 
299
299
  /** @internal */
@@ -385,14 +385,14 @@
385
385
  }
386
386
  }
387
387
 
388
- applyClearFlagsIfIsActiveCamera() {
388
+ applyClearFlagsIfIsActiveCamera(opts?: { applySkybox: boolean }) {
389
389
  if (this.context.mainCameraComponent === this) {
390
- this.applyClearFlags();
390
+ this.applyClearFlags(opts);
391
391
  }
392
392
  }
393
393
 
394
394
  /** Apply this camera's clear flags and related settings to the renderer */
395
- applyClearFlags() {
395
+ applyClearFlags(opts?: { applySkybox: boolean }) {
396
396
  if (!this._cam) {
397
397
  if (debug) console.log("Camera does not exist (apply clear flags)")
398
398
  return;
@@ -414,8 +414,11 @@
414
414
  return;
415
415
  }
416
416
  }
417
- this.enableSkybox();
418
417
 
418
+ // apply the skybox only if it is not already set or if it's the first time (e.g. if the _skybox is not set yet)
419
+ if (!this.scene.background || !this._skybox || opts?.applySkybox === true)
420
+ this.applySceneSkybox();
421
+
419
422
  // set background blurriness and intensity
420
423
  if (this._backgroundBlurriness !== undefined)
421
424
  this.context.scene.backgroundBlurriness = this._backgroundBlurriness;
@@ -446,10 +449,13 @@
446
449
  }
447
450
  }
448
451
 
449
- private enableSkybox() {
452
+ /**
453
+ * Apply the skybox to the scene
454
+ */
455
+ applySceneSkybox() {
450
456
  if (!this._skybox)
451
457
  this._skybox = new CameraSkybox(this);
452
- this._skybox.enable();
458
+ this._skybox.apply();
453
459
  }
454
460
 
455
461
  /** Used to determine if the background should be transparent when in pass through AR
@@ -496,7 +502,7 @@
496
502
  this._camera = camera;
497
503
  }
498
504
 
499
- enable() {
505
+ apply() {
500
506
  this._skybox = this.context.lightmaps.tryGetSkybox(this._camera.sourceId) as Texture;
501
507
  if (!this._skybox) {
502
508
  if (!this["_did_log_failed_to_find_skybox"]) {
src/engine/engine_lightdata.ts CHANGED
@@ -65,7 +65,10 @@
65
65
  if (debugLightmap) console.warn("Missing source id");
66
66
  return null;
67
67
  }
68
- const arr = this._lightmaps.get(sourceId)?.get(type) ?? null;
68
+ const entry = this._lightmaps.get(sourceId);
69
+ if (!entry) return null;
70
+ const arr = entry.get(type);
71
+ if (arr === undefined) return null;
69
72
  if (!arr?.length || arr.length <= index) return null;
70
73
  return arr[index];
71
74
  }
src/engine/engine_loaders.ts CHANGED
@@ -79,7 +79,10 @@
79
79
  else
80
80
  console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures will probably fail");
81
81
 
82
- loader.setDRACOLoader(dracoLoader);
83
- loader.setKTX2Loader(ktx2Loader);
84
- loader.setMeshoptDecoder(meshoptDecoder);
82
+ if (!loader.dracoLoader)
83
+ loader.setDRACOLoader(dracoLoader);
84
+ if (!(loader as any).ktx2Loader)
85
+ loader.setKTX2Loader(ktx2Loader);
86
+ if (!(loader as any).meshoptDecoder)
87
+ loader.setMeshoptDecoder(meshoptDecoder);
85
88
  }
src/engine/engine_scenelighting.ts CHANGED
@@ -161,7 +161,7 @@
161
161
  const settings = this._sceneLightSettings?.get(sourceId);
162
162
 
163
163
  if (debug) {
164
- console.log("Enable reflection", sourceId, settings ? AmbientMode[settings.ambientMode] : "Unknown ambient mode");
164
+ console.log("Enable reflection", sourceId, settings ? AmbientMode[settings.ambientMode] : "Unknown ambient mode", settings);
165
165
  }
166
166
 
167
167
  switch (settings?.ambientMode) {
src/engine/engine_utils_screenshot.ts CHANGED
@@ -7,6 +7,17 @@
7
7
 
8
8
  /**
9
9
  * Take a screenshot from the current scene
10
+ * @param context The context to take the screenshot from
11
+ * @param width The width of the screenshot
12
+ * @param height The height of the screenshot
13
+ * @param mimeType The mime type of the image
14
+ * @param camera The camera to use for the screenshot
15
+ * @returns The data url of the screenshot. Returns null if the screenshot could not be taken.
16
+ * @example
17
+ * ```ts
18
+ * const dataUrl = screenshot();
19
+ * saveImage(dataUrl, "screenshot.png");
20
+ * ```
10
21
  */
11
22
  export function screenshot(context?: Context, width?: number, height?: number, mimeType: ImageMimeType = "image/webp", camera?: Camera | null): string | null {
12
23
 
@@ -68,7 +79,15 @@
68
79
 
69
80
  let saveImageElement: HTMLAnchorElement | null = null;
70
81
 
71
- /** Download a image (must be a data url) */
82
+ /** Download a image (must be a data url).
83
+ * @param dataUrl The data url of the image
84
+ * @param filename The filename of the image
85
+ * @example
86
+ * ```ts
87
+ * const dataUrl = screenshot();
88
+ * saveImage(dataUrl, "screenshot.png");
89
+ * ```
90
+ */
72
91
  export function saveImage(dataUrl: string | null, filename: string) {
73
92
  if (!dataUrl) {
74
93
  return;
src/engine-components/Skybox.ts CHANGED
@@ -191,7 +191,7 @@
191
191
  console.warn("Potentially invalid skybox url", name, "on", this.name);
192
192
  }
193
193
 
194
- if (debug) console.log("Remote skybox url?: " + url);
194
+ if (debug) console.log("Set remote skybox url: " + url);
195
195
 
196
196
  if (this._prevUrl === url && this._prevLoadedEnvironment) {
197
197
  this.applySkybox();
@@ -261,7 +261,7 @@
261
261
  this._prevBackground = this.context.scene.background;
262
262
  if (this.context.scene.environment !== envMap)
263
263
  this._prevEnvironment = this.context.scene.environment;
264
- if (debug) console.log("Set remote skybox", this.url);
264
+ if (debug) console.log("Set remote skybox", this.url, !Camera.backgroundShouldBeTransparent(this.context));
265
265
  if (this.environment)
266
266
  this.context.scene.environment = envMap;
267
267
  if (this.background && !Camera.backgroundShouldBeTransparent(this.context))
plugins/types/userconfig.d.ts CHANGED
@@ -24,6 +24,9 @@
24
24
  noPeer: boolean;
25
25
  /** set to true to disable reload plugin */
26
26
  noReload: boolean;
27
+ /** Set to false to disable hot reload for the needle plugin. */
28
+ allowHotReload: boolean;
29
+
27
30
  noCodegenTransform: boolean;
28
31
  noFacebookInstantGames: boolean;
29
32
  /** Set to true to create an imports.log file that shows all module imports. The file is generated when stopping the server. */
plugins/gltf-packer.mjs ADDED
@@ -0,0 +1,1 @@
1
+ console.error('ERR: this is an old version of the gltf packer, please update gltf-pack in your package.json. The pack-gltf script should now look something like this: "npm run pack-gltf --prefix node_modules/@needle-tools/engine" \nSee the ExportInfo component for more info.');