@needle-tools/engine 3.27.3-beta → 3.27.5-beta

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 (37) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/needle-engine.js +2988 -2967
  3. package/dist/needle-engine.light.js +2967 -2946
  4. package/dist/needle-engine.light.min.js +124 -122
  5. package/dist/needle-engine.light.umd.cjs +164 -162
  6. package/dist/needle-engine.min.js +124 -122
  7. package/dist/needle-engine.umd.cjs +164 -162
  8. package/lib/engine/engine_context.js +4 -0
  9. package/lib/engine/engine_context.js.map +1 -1
  10. package/lib/engine/engine_setup.js.map +1 -1
  11. package/lib/engine/engine_shims.d.ts +3 -0
  12. package/lib/engine/engine_shims.js +24 -0
  13. package/lib/engine/engine_shims.js.map +1 -0
  14. package/lib/engine-components/Component.d.ts +2 -0
  15. package/lib/engine-components/Component.js.map +1 -1
  16. package/lib/engine-components/Renderer.js +8 -7
  17. package/lib/engine-components/Renderer.js.map +1 -1
  18. package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +3 -4
  19. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +1 -0
  20. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
  21. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.d.ts +1 -0
  22. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js +14 -6
  23. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -1
  24. package/lib/engine-components/ui/EventSystem.js +7 -1
  25. package/lib/engine-components/ui/EventSystem.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/engine/codegen/register_types.ts +2 -2
  28. package/src/engine/engine.ts +1 -2
  29. package/src/engine/engine_context.ts +7 -2
  30. package/src/engine/engine_setup.ts +1 -1
  31. package/src/engine/engine_shims.ts +31 -0
  32. package/src/engine-components/Component.ts +4 -0
  33. package/src/engine-components/Renderer.ts +9 -7
  34. package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +3 -7
  35. package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +21 -7
  36. package/src/engine-components/ui/EventSystem.ts +9 -1
  37. package/src/engine-schemes/flatc.exe +0 -0
@@ -998,13 +998,6 @@ class InstancedMeshRenderer {
998
998
  }
999
999
  this.inst = new THREE.InstancedMesh(geo, material, count);
1000
1000
  this.inst[$instancingAutoUpdateBounds] = true;
1001
- this.inst.onBeforeRender = () => {
1002
- if (this._needUpdateBounds && this.inst[$instancingAutoUpdateBounds] === true) {
1003
- if (debugInstancing)
1004
- console.log("Update instancing bounds", this.name);
1005
- this.updateBounds();
1006
- }
1007
- };
1008
1001
  this.inst.count = 0;
1009
1002
  this.inst.layers.set(2);
1010
1003
  this.inst.visible = true;
@@ -1012,6 +1005,7 @@ class InstancedMeshRenderer {
1012
1005
  // this.inst.castShadow = true;
1013
1006
  // this.inst.receiveShadow = true;
1014
1007
  this.context.scene.add(this.inst);
1008
+ context.pre_render_callbacks.push(this.onBeforeRender);
1015
1009
  // console.log(this.inst);
1016
1010
  // this.context.pre_render_callbacks.push(this.onPreRender.bind(this));
1017
1011
 
@@ -1020,6 +1014,14 @@ class InstancedMeshRenderer {
1020
1014
  // }, 500);
1021
1015
  }
1022
1016
 
1017
+ private onBeforeRender = () => {
1018
+ if (this._needUpdateBounds && this.inst[$instancingAutoUpdateBounds] === true) {
1019
+ if (debugInstancing)
1020
+ console.log("Update instancing bounds", this.name, this.inst.matrixWorldNeedsUpdate);
1021
+ this.updateBounds();
1022
+ }
1023
+ }
1024
+
1023
1025
  private randomColor() {
1024
1026
  return new THREE.Color(Math.random(), Math.random(), Math.random());
1025
1027
  }
@@ -1,5 +1,7 @@
1
1
  import { Renderer } from '../../Renderer.js';
2
2
  import { GameObject } from '../../Component.js';
3
+ import type { OffscreenCanvasExt } from '../../../engine/engine_shims.js';
4
+ import '../../../engine/engine_shims.js';
3
5
  import {
4
6
  PlaneGeometry,
5
7
  Texture,
@@ -77,12 +79,6 @@ function findStructuralNodesInBoneHierarchy(bones: Array<Object3D>) {
77
79
  return structuralNodes;
78
80
  }
79
81
 
80
- // TODO: remove once we update to TypeScript 5 that has proper types for OffscreenCanvas
81
- declare type OffsetCanvasExt = OffscreenCanvas & {
82
- convertToBlob: (options?: any) => Promise<Blob>;
83
-
84
- }
85
-
86
82
  class USDObject {
87
83
 
88
84
  static USDObject_export_id = 0;
@@ -975,7 +971,7 @@ async function imageToCanvas( image, color: string | undefined = undefined, flip
975
971
 
976
972
  }
977
973
 
978
- return canvas as OffsetCanvasExt;
974
+ return canvas as OffscreenCanvasExt;
979
975
 
980
976
  } else {
981
977
 
@@ -477,11 +477,7 @@ export class PlayAudioOnClick extends Behaviour implements IPointerClickHandler,
477
477
  ensureRaycaster(this.gameObject);
478
478
  }
479
479
 
480
- onPointerClick(args: PointerEventData) {
481
- args.use();
482
-
483
- if (!this.clip) return;
484
-
480
+ ensureAudioSource() {
485
481
  if (!this.target) {
486
482
  const newAudioSource = this.gameObject.addNewComponent(AudioSource);
487
483
  if (newAudioSource) {
@@ -491,6 +487,14 @@ export class PlayAudioOnClick extends Behaviour implements IPointerClickHandler,
491
487
  newAudioSource.loop = false;
492
488
  }
493
489
  }
490
+ }
491
+
492
+ onPointerClick(args: PointerEventData) {
493
+ args.use();
494
+
495
+ if (!this.clip) return;
496
+
497
+ this.ensureAudioSource();
494
498
 
495
499
  if (this.target) {
496
500
 
@@ -519,11 +523,21 @@ export class PlayAudioOnClick extends Behaviour implements IPointerClickHandler,
519
523
  const clipName = clipUrl.split("/").pop();
520
524
  const volume = this.target ? this.target.volume : 1;
521
525
  const auralMode = this.target && this.target.spatialBlend == 0 ? AuralMode.NonSpatial : AuralMode.Spatial;
522
- const playClip = new BehaviorModel("playAudio " + this.name,
526
+
527
+ const playClipOnTap = new BehaviorModel("playAudio " + this.name,
523
528
  TriggerBuilder.tapTrigger(this.gameObject),
524
529
  ActionBuilder.playAudioAction(playbackTarget, "audio/" + clipName, PlayAction.Play, volume, auralMode),
525
530
  );
526
- ext.addBehavior(playClip);
531
+ ext.addBehavior(playClipOnTap);
532
+
533
+ // automatically play audio on start too if the referenced AudioSource has playOnAwake enabled
534
+ if (this.target && this.target.playOnAwake && this.target.enabled) {
535
+ const playClipOnStart = new BehaviorModel("playAudioOnStart " + this.name,
536
+ TriggerBuilder.sceneStartTrigger(),
537
+ ActionBuilder.playAudioAction(playbackTarget, "audio/" + clipName, PlayAction.Play, volume, auralMode),
538
+ );
539
+ ext.addBehavior(playClipOnStart);
540
+ }
527
541
  }
528
542
  }
529
543
 
@@ -7,7 +7,7 @@ import { Context } from "../../engine/engine_setup.js";
7
7
  import { type IPointerEventHandler, PointerEventData, hasPointerEventComponent } from "./PointerEvents.js";
8
8
  import { ObjectRaycaster, Raycaster } from "./Raycaster.js";
9
9
  import { InputEvents, NEPointerEvent, PointerType } from "../../engine/engine_input.js";
10
- import { Object3D } from "three";
10
+ import { Mesh, Object3D } from "three";
11
11
  import type { ICanvasGroup } from "./Interfaces.js";
12
12
  import { getParam } from "../../engine/engine_utils.js";
13
13
  import { UIRaycastUtils } from "./RaycastUtils.js";
@@ -295,6 +295,14 @@ export class EventSystem extends Behaviour {
295
295
  * */
296
296
  private shouldRaycastObject = (obj: Object3D): RaycastTestObjectReturnType => {
297
297
 
298
+ if (!(obj instanceof Mesh))
299
+ return "continue in children";
300
+
301
+ // Layer 2 is IgnoreRaycast
302
+ if (obj.layers.isEnabled(2)) {
303
+ return "continue in children"
304
+ }
305
+
298
306
  // check if this object is actually a UI shadow hierarchy object
299
307
  let shadowComponent: Object3D | null = null;
300
308
  const isUI = isUIObject(obj);
Binary file