@needle-tools/engine 4.7.0-next.4ec920e → 4.7.0-next.598a777

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/{needle-engine.bundle-CaRf1SjI.umd.cjs → needle-engine.bundle-C6_Q9p9H.umd.cjs} +117 -114
  3. package/dist/{needle-engine.bundle-C00XXoql.min.js → needle-engine.bundle-DNmnR0bU.min.js} +115 -112
  4. package/dist/{needle-engine.bundle-DDM6UaI6.js → needle-engine.bundle-DWTaMxD9.js} +3911 -3901
  5. package/dist/needle-engine.js +2 -2
  6. package/dist/needle-engine.min.js +1 -1
  7. package/dist/needle-engine.umd.cjs +1 -1
  8. package/lib/engine/engine_addressables.d.ts +1 -3
  9. package/lib/engine/engine_addressables.js +5 -12
  10. package/lib/engine/engine_addressables.js.map +1 -1
  11. package/lib/engine/engine_context.js +1 -1
  12. package/lib/engine/engine_context.js.map +1 -1
  13. package/lib/engine/engine_lightdata.js +12 -2
  14. package/lib/engine/engine_lightdata.js.map +1 -1
  15. package/lib/engine/engine_three_utils.js +4 -0
  16. package/lib/engine/engine_three_utils.js.map +1 -1
  17. package/lib/engine/webcomponents/needle-engine.attributes.d.ts +1 -1
  18. package/lib/engine-components/Camera.js +1 -1
  19. package/lib/engine-components/Camera.js.map +1 -1
  20. package/lib/engine-components/CameraUtils.js +5 -3
  21. package/lib/engine-components/CameraUtils.js.map +1 -1
  22. package/lib/engine-components/Skybox.js +4 -4
  23. package/lib/engine-components/Skybox.js.map +1 -1
  24. package/lib/engine-components/postprocessing/Effects/Antialiasing.js +8 -1
  25. package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -1
  26. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +1 -1
  27. package/lib/engine-components/postprocessing/PostProcessingHandler.js +15 -1
  28. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  29. package/lib/engine-components/postprocessing/Volume.js +1 -1
  30. package/lib/engine-components/postprocessing/Volume.js.map +1 -1
  31. package/package.json +2 -2
  32. package/plugins/common/logger.js +321 -0
  33. package/plugins/types/userconfig.d.ts +6 -2
  34. package/plugins/vite/alias.js +55 -40
  35. package/plugins/vite/imports-logger.js +1 -1
  36. package/plugins/vite/index.js +4 -0
  37. package/plugins/vite/logger.client.js +262 -0
  38. package/plugins/vite/logger.js +101 -0
  39. package/plugins/vite/materialx.js +32 -0
  40. package/plugins/vite/transform.js +1 -0
  41. package/src/engine/engine_addressables.ts +6 -15
  42. package/src/engine/engine_context.ts +1 -1
  43. package/src/engine/engine_lightdata.ts +10 -2
  44. package/src/engine/engine_three_utils.ts +3 -0
  45. package/src/engine/webcomponents/needle-engine.attributes.ts +1 -1
  46. package/src/engine-components/Camera.ts +1 -1
  47. package/src/engine-components/CameraUtils.ts +5 -3
  48. package/src/engine-components/Skybox.ts +5 -5
  49. package/src/engine-components/postprocessing/Effects/Antialiasing.ts +8 -1
  50. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -1
  51. package/src/engine-components/postprocessing/PostProcessingHandler.ts +14 -2
  52. package/src/engine-components/postprocessing/Volume.ts +1 -1
@@ -188,14 +188,11 @@ export class AssetReference {
188
188
  private _urlName: string;
189
189
  private _progressListeners: ProgressCallback[] = [];
190
190
 
191
- private _hash?: string;
192
- private _hashedUri: string;
193
-
194
191
  private _isLoadingRawBinary: boolean = false;
195
192
  private _rawBinary?: ArrayBufferLike | null;
196
193
 
197
194
  /** @internal */
198
- constructor(uri: string, hash?: string, asset: any = null) {
195
+ constructor(uri: string, _hash?: string, asset: any = null) {
199
196
  this._url = uri;
200
197
 
201
198
  const lastUriPart = uri.lastIndexOf("/");
@@ -210,14 +207,8 @@ export class AssetReference {
210
207
  else {
211
208
  this._urlName = uri;
212
209
  }
213
-
214
- this._hash = hash;
215
- if (uri.includes("?v="))
216
- this._hashedUri = uri;
217
- else
218
- this._hashedUri = hash ? uri + "?v=" + hash : uri;
210
+
219
211
  if (asset !== null) this.asset = asset;
220
-
221
212
  registerPrefabProvider(this._url, this.onResolvePrefab.bind(this));
222
213
  }
223
214
 
@@ -263,8 +254,8 @@ export class AssetReference {
263
254
  if (this._isLoadingRawBinary) return null;
264
255
  if (this._rawBinary !== undefined) return this._rawBinary;
265
256
  this._isLoadingRawBinary = true;
266
- if (debug) console.log("Preload", this._hashedUri);
267
- const res = await BlobStorage.download(this._hashedUri, p => {
257
+ if (debug) console.log("Preload", this.url);
258
+ const res = await BlobStorage.download(this.url, p => {
268
259
  this.raiseProgressEvent(p);
269
260
  });
270
261
  this._rawBinary = res?.buffer ?? null;
@@ -294,7 +285,7 @@ export class AssetReference {
294
285
  // console.log("START LOADING");
295
286
  if (this._rawBinary) {
296
287
  if (!(this._rawBinary instanceof ArrayBuffer)) {
297
- console.error("Invalid raw binary data", this._rawBinary);
288
+ console.error("Failed loading: Invalid raw binary data. Must be of type ArrayBuffer. " + (typeof this._rawBinary));
298
289
  return null;
299
290
  }
300
291
  this._loading = getLoader().parseSync(context, this._rawBinary, this.url, null);
@@ -302,7 +293,7 @@ export class AssetReference {
302
293
  }
303
294
  else {
304
295
  if (debug) console.log("Load async", this.url);
305
- this._loading = getLoader().loadSync(context, this._hashedUri, this.url, null, prog => {
296
+ this._loading = getLoader().loadSync(context, this.url, this.url, null, prog => {
306
297
  this.raiseProgressEvent(prog);
307
298
  });
308
299
  }
@@ -751,7 +751,7 @@ export class Context implements IContext {
751
751
  ContextRegistry.dispatchCallback(ContextEvent.ContextClearing, this);
752
752
  invokeLifecycleFunctions(this, ContextEvent.ContextClearing);
753
753
  // NOTE: this does dispose the environment/background image too
754
- // which is probably not desired if it is set via the skybox-image attribute
754
+ // which is probably not desired if it is set via the background-image attribute
755
755
  destroy(this.scene, true, true);
756
756
  this.scene = new Scene();
757
757
  this.addressables?.dispose();
@@ -53,10 +53,12 @@ export class LightDataRegistry implements ILightDataRegistry {
53
53
  }
54
54
 
55
55
  tryGetSkybox(sourceId?: SourceIdentifier | null): Texture | null {
56
+ if (debugLightmap) console.log("[Get Skybox]", sourceId, this._lightmaps)
56
57
  return this.tryGet(sourceId, LightmapType.Skybox, 0);
57
58
  }
58
59
 
59
60
  tryGetReflection(sourceId?: SourceIdentifier | null): Texture | null {
61
+ if (debugLightmap) console.log("[Get Reflection]", sourceId, this._lightmaps)
60
62
  return this.tryGet(sourceId, LightmapType.Reflection, 0);
61
63
  }
62
64
 
@@ -66,9 +68,15 @@ export class LightDataRegistry implements ILightDataRegistry {
66
68
  return null;
67
69
  }
68
70
  const entry = this._lightmaps.get(sourceId);
69
- if (!entry) return null;
71
+ if (!entry) {
72
+ if (debugLightmap) console.warn(`[Lighting] No ${LightmapType[type]} texture entry for`, sourceId);
73
+ return null;
74
+ }
70
75
  const arr = entry.get(type);
71
- if (arr === undefined) return null;
76
+ if (arr === undefined) {
77
+ if (debugLightmap) console.warn(`[Lighting] No ${LightmapType[type]} texture for`, sourceId, "index", index);
78
+ return null;
79
+ }
72
80
  if (!arr?.length || arr.length <= index) return null;
73
81
  return arr[index];
74
82
  }
@@ -734,6 +734,9 @@ export function getBoundingBox(objects: Object3D | Object3D[], ignore: ((obj: Ob
734
734
  console.warn(`Object \"${obj.name}\" has NaN values in position or scale.... will ignore it`, pos, scale);
735
735
  return;
736
736
  }
737
+ // Sanitize for the three.js method that only checks for undefined here
738
+ // @ts-ignore
739
+ if (obj.geometry === null) obj.geometry = undefined;
737
740
  box.expandByObject(obj, true);
738
741
  obj.children = children;
739
742
  }
@@ -44,7 +44,7 @@ type LoadingAttributes = {
44
44
  }
45
45
 
46
46
  type SkyboxAttributes = {
47
- /** use background-image instead - URL to .exr, .hdr, .png, .jpg to be used as skybox */
47
+ /** @deprecated. Use background-image instead - URL to .exr, .hdr, .png, .jpg to be used as skybox */
48
48
  "skybox-image"?: string,
49
49
  /** URL to .exr, .hdr, .png, .jpg to be used as skybox */
50
50
  "background-image"?: string,
@@ -560,7 +560,7 @@ export class Camera extends Behaviour implements ICamera {
560
560
  console.debug(msg);
561
561
  }
562
562
 
563
- const hasBackgroundImageOrColorAttribute = this.context.domElement.getAttribute("background-image") || this.context.domElement.getAttribute("background-color") || this.context.domElement.getAttribute("skybox-image");
563
+ const hasBackgroundImageOrColorAttribute = this.context.domElement.getAttribute("background-image") || this.context.domElement.getAttribute("background-color");
564
564
 
565
565
  switch (this._clearFlags) {
566
566
  case ClearFlags.None:
@@ -36,12 +36,14 @@ ContextRegistry.registerCallback(ContextEvent.MissingCamera, (evt) => {
36
36
  if (transparentAttribute != undefined) {
37
37
  camInstance.clearFlags = ClearFlags.Uninitialized;
38
38
  }
39
- // Set the clearFlags to a skybox if we have one OR if the user set a skybox image attribute
40
- else if (evt.context.domElement.getAttribute("skybox-image")?.length || evt.context.domElement.getAttribute("background-image")?.length || (evt.context as Context).lightmaps.tryGetSkybox(camInstance.sourceId)) {
39
+ // Set the clearFlags to a skybox if we have one OR if the user set a background-image attribute
40
+ else if (evt.context.domElement.getAttribute("background-image")?.length || (evt.context as Context).lightmaps.tryGetSkybox(camInstance.sourceId)) {
41
41
  camInstance.clearFlags = ClearFlags.Skybox;
42
42
  // TODO: can we store the backgroundBlurriness in the gltf file somewhere except inside the camera?
43
43
  // e.g. when we export a scene from blender without a camera in the scene
44
- camInstance.backgroundBlurriness = .2; // same as in blender 0.5
44
+ if (evt.context.domElement.getAttribute("background-blurriness") === null) {
45
+ evt.context.scene.backgroundBlurriness = 0.2; // default value, same as in Blender
46
+ }
45
47
  }
46
48
  else {
47
49
  camInstance.clearFlags = ClearFlags.SolidColor;
@@ -16,10 +16,10 @@ import { Behaviour, GameObject } from "./Component.js";
16
16
 
17
17
  const debug = getParam("debugskybox");
18
18
 
19
- registerObservableAttribute("skybox-image");
19
+ registerObservableAttribute("background-image");
20
20
  registerObservableAttribute("environment-image");
21
21
 
22
- function createRemoteSkyboxComponent(context: IContext, url: string, skybox: boolean, environment: boolean, attribute: "skybox-image" | "environment-image") {
22
+ function createRemoteSkyboxComponent(context: IContext, url: string, skybox: boolean, environment: boolean, attribute: "background-image" | "environment-image") {
23
23
  const remote = new RemoteSkybox();
24
24
  remote.allowDrop = false;
25
25
  remote.allowNetworking = false;
@@ -42,7 +42,7 @@ function createRemoteSkyboxComponent(context: IContext, url: string, skybox: boo
42
42
  const promises = new Array<Promise<any>>();
43
43
  ContextRegistry.registerCallback(ContextEvent.ContextCreationStart, (args) => {
44
44
  const context = args.context;
45
- const skyboxImage = context.domElement.getAttribute("skybox-image") || context.domElement.getAttribute("background-image");
45
+ const skyboxImage = context.domElement.getAttribute("background-image");
46
46
  const environmentImage = context.domElement.getAttribute("environment-image");
47
47
  if (skyboxImage) {
48
48
  if (debug)
@@ -50,8 +50,8 @@ ContextRegistry.registerCallback(ContextEvent.ContextCreationStart, (args) => {
50
50
  // if the user is loading a GLB without a camera then the CameraUtils (which creates the default camera)
51
51
  // checks if we have this attribute set and then sets the skybox clearflags accordingly
52
52
  // if the user has a GLB with a camera but set to solid color then the skybox image is not visible -> we will just warn then and not override the camera settings
53
- if (context.mainCameraComponent?.clearFlags !== ClearFlags.Skybox) console.warn("\"skybox-image\"/\"background-image\" attribute has no effect: camera clearflags are not set to \"Skybox\"");
54
- const promise = createRemoteSkyboxComponent(context, skyboxImage, true, false, "skybox-image");
53
+ if (context.mainCameraComponent?.clearFlags !== ClearFlags.Skybox) console.warn("\"background-image\" attribute has no effect: camera clear flags are not set to \"Skybox\"");
54
+ const promise = createRemoteSkyboxComponent(context, skyboxImage, true, false, "background-image");
55
55
  promises.push(promise);
56
56
  }
57
57
  if (environmentImage) {
@@ -1,10 +1,13 @@
1
1
  import { MODULES } from "../../../engine/engine_modules.js";
2
2
  import { serializable } from "../../../engine/engine_serialization.js";
3
+ import { getParam } from "../../../engine/engine_utils.js";
3
4
  import { type EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect.js";
4
5
  import { VolumeParameter } from "../VolumeParameter.js";
5
6
  import { registerCustomEffectType } from "../VolumeProfile.js";
6
7
 
7
8
 
9
+ const debug = getParam("debugpost");
10
+
8
11
 
9
12
  export enum QualityLevel {
10
13
  LOW = 0,
@@ -32,15 +35,19 @@ export class Antialiasing extends PostProcessingEffect {
32
35
 
33
36
  onCreateEffect(): EffectProviderResult {
34
37
  const effect = new MODULES.POSTPROCESSING.MODULE.SMAAEffect({
35
- preset: MODULES.POSTPROCESSING.MODULE.SMAAPreset.HIGH,
38
+ preset: this.preset?.value ?? MODULES.POSTPROCESSING.MODULE.SMAAPreset.HIGH,
36
39
  edgeDetectionMode: MODULES.POSTPROCESSING.MODULE.EdgeDetectionMode.LUMA,
37
40
  // Keep predication mode disabled (default) since it looks better
38
41
  // predicationMode: MODULES.POSTPROCESSING.MODULE.PredicationMode.DEPTH,
39
42
  });
40
43
 
41
44
  this.preset.onValueChanged = (newValue) => {
45
+ if(debug) console.log("Antialiasing preset changed to", newValue);
42
46
  effect.applyPreset(newValue);
43
47
  };
48
+ // setInterval(()=> {
49
+ // effect.applyPreset(Math.floor(Math.random()*3))
50
+ // }, 1000)
44
51
 
45
52
  // effect.edgeDetectionMaterial.edgeDetectionThreshold = .01;
46
53
 
@@ -124,7 +124,7 @@ export class ScreenSpaceAmbientOcclusionN8 extends PostProcessingEffect {
124
124
  cam,
125
125
  width, height
126
126
  ) as N8AOPostPass;
127
- ssao.name = "SSAO N8";
127
+ ssao.name = "SSAO_N8";
128
128
 
129
129
  const mode = ScreenSpaceAmbientOcclusionN8QualityMode[this.quality];
130
130
  ssao.setQualityMode(mode);
@@ -162,9 +162,11 @@ export class PostProcessingHandler {
162
162
  const res = component.apply(ctx);
163
163
  if (!res) continue;
164
164
 
165
+ const name = component.typeName || component.constructor.name;
165
166
 
166
167
  if (Array.isArray(res)) {
167
168
  for (const effect of res) {
169
+ if (!validateEffect(name, effect)) continue;
168
170
  this._effects.push({
169
171
  effect,
170
172
  typeName: component.typeName,
@@ -173,12 +175,23 @@ export class PostProcessingHandler {
173
175
  }
174
176
  }
175
177
  else {
178
+ if (!validateEffect(name, res)) continue;
176
179
  this._effects.push({
177
180
  effect: res,
178
181
  typeName: component.typeName,
179
182
  priority: component.order
180
183
  });
181
184
  }
185
+
186
+ function validateEffect(source: string, effect: Effect | Pass): boolean {
187
+ if (!effect) {
188
+ return false;
189
+ }
190
+ if (!(effect instanceof MODULES.POSTPROCESSING.MODULE.Effect || effect instanceof MODULES.POSTPROCESSING.MODULE.Pass)) {
191
+ console.warn(`PostprocessingEffect ${source} created neither Effect nor Pass - this might be caused by a bundler error or false import. Below you find some possible solutions:\n- If you create custom effect try creating it like this: 'new NEEDLE_ENGINE_MODULES.POSTPROCESSING.MODULE.Effect(...)' instead of 'new Effect(...)'`);
192
+ }
193
+ return true;
194
+ }
182
195
  }
183
196
  }
184
197
  else {
@@ -403,7 +416,7 @@ export class PostProcessingHandler {
403
416
  if (attributes & convolution) {
404
417
  if (debug) console.log("[PostProcessing] Convolution effect: " + ef.name);
405
418
  if (hasConvolutionEffectInArray) {
406
- if (debug) console.log("[PostProcessing] Merging effects with convolution", effectsToMerge.map(e => e.name).join(", "));
419
+ if (debug) console.log("[PostProcessing] Merging effects [" + effectsToMerge.map(e => e.name).join(", ") + "]");
407
420
  this.createPassForMergeableEffects(effectsToMerge, composer, cam, scene);
408
421
  }
409
422
  hasConvolutionEffectInArray = true;
@@ -448,7 +461,6 @@ export class PostProcessingHandler {
448
461
  }
449
462
  foundEnabled = true;
450
463
  }
451
-
452
464
  pass.renderToScreen = renderToScreen;
453
465
 
454
466
  if ((pass as any)?.configuration !== undefined) {
@@ -194,7 +194,7 @@ export class Volume extends Behaviour implements IEditorModificationReceiver, IP
194
194
  if (this._postprocessing.multisampling !== 0) {
195
195
  this._postprocessing.multisampling = 0;
196
196
  if (debug || isDevEnvironment()) {
197
- console.warn(`[PostProcessing] Disabling multisampling you're using SMAA and have set the 'multisampling: auto' on your PostprocessingManager/Volume component. If you need anti-aliasing, consider adding an Antialiasing component or SMAA effect to the PostprocessingManager.`);
197
+ console.log(`[PostProcessing] multisampling is disabled because it's set to 'auto' on your PostprocessingManager/Volume component that also has an SMAA effect.\n\nIf you need multisampling consider changing 'auto' to a fixed value (e.g. 4).`);
198
198
  }
199
199
  }
200
200
  }