@needle-tools/engine 4.8.8-next.937fc15 → 4.8.8-next.aa09526

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 (38) hide show
  1. package/components.needle.json +1 -1
  2. package/dist/{needle-engine.bundle-CAvlLwYK.umd.cjs → needle-engine.bundle-C5WmZ20c.umd.cjs} +93 -93
  3. package/dist/{needle-engine.bundle--r19rtjt.min.js → needle-engine.bundle-DDQrIop6.min.js} +95 -95
  4. package/dist/{needle-engine.bundle-Dao6Iztd.js → needle-engine.bundle-xO7DnXAE.js} +1980 -1969
  5. package/dist/needle-engine.d.ts +7 -0
  6. package/dist/needle-engine.js +2 -2
  7. package/dist/needle-engine.min.js +1 -1
  8. package/dist/needle-engine.umd.cjs +1 -1
  9. package/lib/engine/engine_addressables.js +2 -0
  10. package/lib/engine/engine_addressables.js.map +1 -1
  11. package/lib/engine/engine_animation.js +4 -4
  12. package/lib/engine/engine_animation.js.map +1 -1
  13. package/lib/engine/engine_assetdatabase.js +6 -6
  14. package/lib/engine/engine_assetdatabase.js.map +1 -1
  15. package/lib/engine/engine_gameobject.js +2 -2
  16. package/lib/engine/engine_gameobject.js.map +1 -1
  17. package/lib/engine/engine_gltf_builtin_components.js +11 -11
  18. package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
  19. package/lib/engine/extensions/NEEDLE_lightmaps.js +1 -1
  20. package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -1
  21. package/lib/engine/js-extensions/Object3D.d.ts +1 -1
  22. package/lib/engine/js-extensions/Vector.d.ts +5 -0
  23. package/lib/engine/js-extensions/Vector.js.map +1 -1
  24. package/lib/engine-components/NestedGltf.d.ts +9 -4
  25. package/lib/engine-components/NestedGltf.js +32 -26
  26. package/lib/engine-components/NestedGltf.js.map +1 -1
  27. package/lib/engine-components/Renderer.js +2 -1
  28. package/lib/engine-components/Renderer.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/engine/engine_addressables.ts +2 -0
  31. package/src/engine/engine_animation.ts +4 -4
  32. package/src/engine/engine_assetdatabase.ts +7 -7
  33. package/src/engine/engine_gameobject.ts +2 -2
  34. package/src/engine/engine_gltf_builtin_components.ts +12 -11
  35. package/src/engine/extensions/NEEDLE_lightmaps.ts +1 -1
  36. package/src/engine/js-extensions/Vector.ts +6 -0
  37. package/src/engine-components/NestedGltf.ts +33 -24
  38. package/src/engine-components/Renderer.ts +2 -1
@@ -166,9 +166,9 @@ export function destroy(instance: Object3D | Component, recursive: boolean = tru
166
166
  setDestroyed(obj, true);
167
167
  if (dispose) {
168
168
  disposeObjectResources(obj);
169
+ // This needs to be called after disposing because it removes the references to resources
170
+ __internalRemoveReferences(obj);
169
171
  }
170
- // This needs to be called after disposing because it removes the references to resources
171
- __internalRemoveReferences(obj);
172
172
  }
173
173
  destroyed_objects.length = 0;
174
174
  destroyed_components.length = 0;
@@ -72,13 +72,13 @@ export async function createBuiltinComponents(context: Context, gltfId: SourceId
72
72
 
73
73
  if (gltf.scenes) {
74
74
  for (const scene of gltf.scenes) {
75
- await onCreateBuiltinComponents(serializationContext, scene, deserializeQueue, lateResolve);
75
+ await onCreateBuiltinComponents(serializationContext, scene, deserializeQueue, lateResolve, 0);
76
76
  }
77
77
  }
78
78
  // TODO: when is the gltf here an object3d?
79
79
  if (gltf.children) {
80
80
  for (const ch of gltf.children) {
81
- await onCreateBuiltinComponents(serializationContext, ch, deserializeQueue, lateResolve);
81
+ await onCreateBuiltinComponents(serializationContext, ch, deserializeQueue, lateResolve, 0);
82
82
  }
83
83
  }
84
84
 
@@ -202,7 +202,7 @@ const unknownComponentsBuffer: Array<string> = [];
202
202
 
203
203
 
204
204
  async function onCreateBuiltinComponents(context: SerializationContext, obj: Object3D,
205
- deserialize: DeserializeData[], lateResolve: LateResolveCallback[]) {
205
+ deserialize: DeserializeData[], lateResolve: LateResolveCallback[], level: number) {
206
206
  if (!obj) return;
207
207
 
208
208
  // iterate injected data
@@ -267,20 +267,21 @@ async function onCreateBuiltinComponents(context: SerializationContext, obj: Obj
267
267
  }
268
268
  // console.debug("finished adding gltf builtin components", obj);
269
269
  }
270
- if (unknownComponentsBuffer.length > 0) {
271
- const unknown = unknownComponentsBuffer.join(", ");
272
- console.warn("unknown components: " + unknown);
273
- unknownComponentsBuffer.length = 0;
274
- if (isLocalNetwork())
275
- showBalloonMessage(`<strong>Unknown components in scene</strong>:\n\n${unknown}\n\nThis could mean you forgot to add a npmdef to your ExportInfo\n<a href="https://engine.needle.tools/docs/project_structure.html#creating-and-installing-a-npmdef" target="_blank">documentation</a>`, LogType.Warn);
276
- }
277
270
  }
278
271
 
279
272
  if (obj.children) {
280
273
  for (const ch of obj.children) {
281
- await onCreateBuiltinComponents(context, ch, deserialize, lateResolve);
274
+ await onCreateBuiltinComponents(context, ch, deserialize, lateResolve, level + 1);
282
275
  }
283
276
  }
277
+
278
+ if (unknownComponentsBuffer.length > 0 && level === 0) {
279
+ const unknown = unknownComponentsBuffer.join(", ");
280
+ console.warn(`Unknown components in scene: ${unknown}`);
281
+ unknownComponentsBuffer.length = 0;
282
+ if (isLocalNetwork())
283
+ showBalloonMessage(`<strong>Unknown components in scene</strong>:\n\n${unknown}\n\nThis could mean you forgot to add a npmdef to your ExportInfo\n<a href="https://engine.needle.tools/docs/project_structure.html#creating-and-installing-a-npmdef" target="_blank">documentation</a>`, LogType.Warn);
284
+ }
284
285
  }
285
286
 
286
287
  function handleDeserialization(data: DeserializeData, context: SerializationContext) {
@@ -70,7 +70,7 @@ export class NEEDLE_lightmaps implements GLTFLoaderPlugin {
70
70
  console.log(entry);
71
71
  let res: Promise<any> | null = null;
72
72
  // Check if the pointer is a json pointer:
73
- if (entry.pointer.startsWith("/textures/")) {
73
+ if (entry.pointer.startsWith("/textures/") || /** legacy support e.g. SOC */entry.pointer.startsWith("textures/")) {
74
74
  if (debug) console.log("Load texture from gltf", entry.pointer);
75
75
  res = resolveReferences(this.parser, entry.pointer).then(res => this.resolveTexture(entry, res));
76
76
  }
@@ -10,6 +10,12 @@ export function apply(object: Vector3) {
10
10
  }
11
11
  }
12
12
 
13
+ // NOTE: keep in sync with method declarations below
14
+ declare module 'three' {
15
+ export interface Vector3 {
16
+ slerp(end: Vector3, t: number): Vector3;
17
+ }
18
+ }
13
19
 
14
20
  Vector3.prototype["slerp"] = function (end: Vector3, t: number) {
15
21
  return slerp(this, end, t);
@@ -4,6 +4,7 @@ import { InstantiateIdProvider } from "../engine/engine_networking_instantiate.j
4
4
  import { serializable } from "../engine/engine_serialization_decorator.js";
5
5
  import { getParam } from "../engine/engine_utils.js";
6
6
  import { Behaviour } from "../engine-components/Component.js";
7
+ import { EventList } from "./EventList.js";
7
8
 
8
9
  const debug = getParam("debugnestedgltf");
9
10
 
@@ -11,17 +12,21 @@ const debug = getParam("debugnestedgltf");
11
12
  * It will load the gltf file and instantiate it as a child of the parent of the GameObject that has this component
12
13
  */
13
14
  export class NestedGltf extends Behaviour {
14
- /**
15
- * A reference to the gltf file that should be loaded
16
- */
15
+
16
+ /** A reference to the gltf file that should be loaded */
17
17
  @serializable(AssetReference)
18
18
  filePath?: AssetReference;
19
19
 
20
+ /** Invoked when the nested glTF file has been instantiated */
21
+ @serializable(EventList)
22
+ loaded: EventList<{ component: NestedGltf, instance: any, asset: AssetReference }> = new EventList();
23
+
20
24
  /**
21
25
  * EXPERIMENTAL for cloud asset loading
22
26
  */
23
27
  loadAssetInParent = true;
24
28
 
29
+
25
30
  private _isLoadingOrDoneLoading: boolean = false;
26
31
 
27
32
  /** Register a callback that will be called when the progress of the loading changes */
@@ -31,7 +36,7 @@ export class NestedGltf extends Behaviour {
31
36
 
32
37
  /** Begin loading the referenced gltf file in filePath */
33
38
  preload() {
34
- this.filePath?.preload();
39
+ return this.filePath?.preload() || null;
35
40
  }
36
41
 
37
42
  /** @internal */
@@ -41,27 +46,31 @@ export class NestedGltf extends Behaviour {
41
46
 
42
47
  const parent = this.gameObject.parent;
43
48
  if (parent) {
44
- this._isLoadingOrDoneLoading = true;
45
- const opts = new InstantiateOptions();
46
- // we need to provide stable guids for creating nested gltfs
47
- opts.idProvider = new InstantiateIdProvider(this.hash(this.guid));
48
- opts.parent = this.loadAssetInParent !== false ? parent : this.gameObject;
49
- this.gameObject.updateMatrix();
50
- const matrix = this.gameObject.matrix;
51
- if (debug) console.log("Load nested:", this.filePath?.url ?? this.filePath, this.gameObject.position);
52
- const res = await this.filePath?.instantiate?.call(this.filePath, opts);
53
- if (debug) console.log("Nested loaded:", this.filePath?.url ?? this.filePath, res);
54
- if (res && this.loadAssetInParent !== false) {
55
- res.matrixAutoUpdate = false;
56
- res.matrix.identity();
57
- res.applyMatrix4(matrix);
58
- res.matrixAutoUpdate = true;
59
- res.layers.disableAll();
60
- res.layers.set(this.layer);
61
-
62
- this.dispatchEvent(new CustomEvent("loaded", { detail: { instance: res, assetReference: this.filePath } }));
49
+
50
+ if (this.filePath) {
51
+
52
+ this._isLoadingOrDoneLoading = true;
53
+ const opts = new InstantiateOptions();
54
+ // we need to provide stable guids for creating nested gltfs
55
+ opts.idProvider = new InstantiateIdProvider(this.hash(this.guid));
56
+ opts.parent = this.loadAssetInParent !== false ? parent : this.gameObject;
57
+ this.gameObject.updateMatrix();
58
+ const matrix = this.gameObject.matrix;
59
+ if (debug) console.log("Load nested:", this.filePath?.url ?? this.filePath, this.gameObject.position);
60
+ const res = await this.filePath?.instantiate?.call(this.filePath, opts);
61
+ if (debug) console.log("Nested loaded:", this.filePath?.url ?? this.filePath, res);
62
+ if (res && this.loadAssetInParent !== false) {
63
+ res.matrixAutoUpdate = false;
64
+ res.matrix.identity();
65
+ res.applyMatrix4(matrix);
66
+ res.matrixAutoUpdate = true;
67
+ res.layers.disableAll();
68
+ res.layers.set(this.layer);
69
+ this.loaded.invoke({ component: this, instance: res, asset: this.filePath });
70
+ }
71
+ if (debug) console.log("Nested loading done:", this.filePath?.url ?? this.filePath, res);
63
72
  }
64
- if (debug) console.log("Nested loading done:", this.filePath?.url ?? this.filePath, res);
73
+
65
74
  }
66
75
  }
67
76
 
@@ -706,7 +706,8 @@ export class Renderer extends Behaviour implements IRenderer {
706
706
  }
707
707
 
708
708
  if (this.reflectionProbeUsage !== ReflectionProbeUsage.Off && this._reflectionProbe) {
709
- this._reflectionProbe.onSet(this);
709
+ if (!this._lightmaps?.length) // Currently reflectionprobes cant be used with lightmaps
710
+ this._reflectionProbe.onSet(this);
710
711
  }
711
712
  // since three 163 we need to set the envMap to the scene envMap if it is not set
712
713
  // otherwise the envmapIntensity has no effect: https://github.com/mrdoob/three.js/pull/27903