@needle-tools/engine 4.1.0-beta → 4.1.0-beta.2

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 (85) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/components.needle.json +1 -1
  3. package/dist/gltf-progressive.js +103 -102
  4. package/dist/gltf-progressive.light.js +103 -102
  5. package/dist/gltf-progressive.light.min.js +6 -6
  6. package/dist/gltf-progressive.light.umd.cjs +6 -6
  7. package/dist/gltf-progressive.min.js +6 -6
  8. package/dist/gltf-progressive.umd.cjs +6 -6
  9. package/dist/needle-engine.bundle.js +7820 -7561
  10. package/dist/needle-engine.bundle.light.js +7773 -7514
  11. package/dist/needle-engine.bundle.light.min.js +131 -132
  12. package/dist/needle-engine.bundle.light.umd.cjs +134 -135
  13. package/dist/needle-engine.bundle.min.js +131 -132
  14. package/dist/needle-engine.bundle.umd.cjs +134 -135
  15. package/dist/needle-engine.js +596 -590
  16. package/dist/needle-engine.light.js +596 -590
  17. package/dist/needle-engine.light.min.js +1 -1
  18. package/dist/needle-engine.light.umd.cjs +1 -1
  19. package/dist/needle-engine.min.js +1 -1
  20. package/dist/needle-engine.umd.cjs +1 -1
  21. package/dist/three-examples.js +26 -26
  22. package/dist/three-examples.light.js +26 -26
  23. package/dist/three-examples.light.min.js +1 -1
  24. package/dist/three-examples.light.umd.cjs +1 -1
  25. package/dist/three-examples.min.js +1 -1
  26. package/dist/three-examples.umd.cjs +1 -1
  27. package/dist/vendor.js +0 -2
  28. package/dist/vendor.light.js +0 -2
  29. package/dist/vendor.light.min.js +2 -2
  30. package/dist/vendor.light.umd.cjs +2 -2
  31. package/dist/vendor.min.js +2 -2
  32. package/dist/vendor.umd.cjs +2 -2
  33. package/lib/engine/engine.d.ts +4 -0
  34. package/lib/engine/engine.js +12 -0
  35. package/lib/engine/engine.js.map +1 -0
  36. package/lib/engine/engine_web_api.d.ts +12 -0
  37. package/lib/engine/engine_web_api.js +113 -0
  38. package/lib/engine/engine_web_api.js.map +1 -0
  39. package/lib/engine/xr/NeedleXRSession.js +3 -0
  40. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  41. package/lib/engine-components/FlyControls.d.ts +10 -0
  42. package/lib/engine-components/FlyControls.js +29 -0
  43. package/lib/engine-components/FlyControls.js.map +1 -0
  44. package/lib/engine-components/GroundProjection.d.ts +1 -1
  45. package/lib/engine-components/GroundProjection.js +39 -32
  46. package/lib/engine-components/GroundProjection.js.map +1 -1
  47. package/lib/engine-components/OrbitControls.js +8 -0
  48. package/lib/engine-components/OrbitControls.js.map +1 -1
  49. package/lib/engine-components/RigidBody.js +10 -4
  50. package/lib/engine-components/RigidBody.js.map +1 -1
  51. package/lib/engine-components/SpatialTrigger.d.ts +2 -2
  52. package/lib/engine-components/SpatialTrigger.js +4 -4
  53. package/lib/engine-components/SpatialTrigger.js.map +1 -1
  54. package/lib/engine-components/TransformGizmo.d.ts +7 -1
  55. package/lib/engine-components/TransformGizmo.js +39 -32
  56. package/lib/engine-components/TransformGizmo.js.map +1 -1
  57. package/lib/engine-components/VideoPlayer.js +0 -1
  58. package/lib/engine-components/VideoPlayer.js.map +1 -1
  59. package/lib/engine-components/particlesystem/ParticleSystemModules.js +1 -1
  60. package/lib/engine-components/particlesystem/ParticleSystemModules.js.map +1 -1
  61. package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +2 -0
  62. package/lib/engine-components/postprocessing/Effects/Sharpening.js +15 -6
  63. package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
  64. package/lib/engine-components/webxr/WebXRImageTracking.d.ts +4 -0
  65. package/lib/engine-components/webxr/WebXRImageTracking.js +14 -4
  66. package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
  67. package/lib/engine-components/webxr/WebXRRig.d.ts +11 -1
  68. package/lib/engine-components/webxr/WebXRRig.js +13 -1
  69. package/lib/engine-components/webxr/WebXRRig.js.map +1 -1
  70. package/lib/needle-engine.js +5 -5
  71. package/lib/needle-engine.js.map +1 -1
  72. package/package.json +3 -3
  73. package/src/engine/codegen/register_types.ts +2 -2
  74. package/src/engine/xr/NeedleXRSession.ts +3 -0
  75. package/src/engine-components/GroundProjection.ts +46 -38
  76. package/src/engine-components/OrbitControls.ts +8 -0
  77. package/src/engine-components/RigidBody.ts +11 -5
  78. package/src/engine-components/SpatialTrigger.ts +6 -6
  79. package/src/engine-components/TransformGizmo.ts +41 -33
  80. package/src/engine-components/VideoPlayer.ts +0 -1
  81. package/src/engine-components/particlesystem/ParticleSystemModules.ts +1 -1
  82. package/src/engine-components/postprocessing/Effects/Sharpening.ts +16 -7
  83. package/src/engine-components/webxr/WebXRImageTracking.ts +18 -4
  84. package/src/engine-components/webxr/WebXRRig.ts +15 -2
  85. package/src/needle-engine.ts +5 -5
@@ -24,30 +24,39 @@ export class SharpeningEffect extends PostProcessingEffect {
24
24
  private _effect?: any;
25
25
 
26
26
  onCreateEffect() {
27
+ this._effect ??= new (createSharpeningEffectType())();
27
28
  return this.effect;
28
29
  }
29
30
 
30
31
  private get effect() {
31
- this._effect ??= new (createSharpeningEffectType())();
32
- // return null;
33
32
  return this._effect;
34
33
  }
35
34
 
36
35
  @serializable()
37
36
  set amount(value: number) {
38
- this.effect.uniforms.get("amount")!.value = value;
37
+ this._amount = value;
38
+ if (this._effect)
39
+ this._effect.uniforms.get("amount")!.value = value;
39
40
  }
40
41
  get amount() {
41
- return this.effect.uniforms.get("amount")!.value;
42
+ if (this._effect)
43
+ return this._effect.uniforms.get("amount")!.value;
44
+ return this._amount;
42
45
  }
46
+ private _amount = 1;
43
47
 
44
48
  @serializable()
45
49
  set radius(value: number) {
46
- this.effect.uniforms.get("radius")!.value = value;
50
+ this._radius = value;
51
+ if (this._effect)
52
+ this._effect.uniforms.get("radius")!.value = value;
47
53
  }
48
54
  get radius() {
49
- return this.effect.uniforms.get("radius")!.value;
55
+ if (this._effect)
56
+ return this._effect.uniforms.get("radius")!.value;
57
+ return this._radius;
50
58
  }
59
+ private _radius = 1;
51
60
 
52
61
  // @serializable()
53
62
  // set threshold(value: number) {
@@ -110,7 +119,7 @@ function createSharpeningEffectType() {
110
119
  }
111
120
 
112
121
  `
113
-
122
+
114
123
  class _SharpeningEffect extends MODULES.POSTPROCESSING.MODULE!.Effect {
115
124
  constructor() {
116
125
  super("Sharpening", frag, {
@@ -4,7 +4,7 @@ import { Object3DEventMap } from "three";
4
4
  import { isDevEnvironment, showBalloonWarning } from "../../engine/debug/index.js";
5
5
  import { AssetReference } from "../../engine/engine_addressables.js";
6
6
  import { serializable } from "../../engine/engine_serialization.js";
7
- import { CircularBuffer, getParam } from "../../engine/engine_utils.js";
7
+ import { CircularBuffer, DeviceUtilities, getParam } from "../../engine/engine_utils.js";
8
8
  import { type NeedleXREventArgs, NeedleXRSession } from "../../engine/xr/api.js";
9
9
  import { IUSDExporterExtension } from "../../engine-components/export/usdz/Extension.js";
10
10
  import { imageToCanvas, USDObject, USDWriter, USDZExporterContext } from "../../engine-components/export/usdz/ThreeUSDZExporter.js";
@@ -236,11 +236,17 @@ export class WebXRImageTracking extends Behaviour {
236
236
  trackedImages?: WebXRImageTrackingModel[];
237
237
 
238
238
  /** Applies smoothing based on detected jitter to the tracked image. */
239
+ @serializable()
239
240
  smooth: boolean = true;
240
241
 
241
242
  private readonly trackedImageIndexMap: Map<number, WebXRImageTrackingModel> = new Map();
242
243
  private static _imageElements: Map<string, ImageBitmap | null> = new Map();
243
244
 
245
+ /** @returns true if image tracking is supported on this device. This may return false at runtime if the user's browser did not enable webxr incubations */
246
+ get supported() { return this._supported; }
247
+
248
+ private _supported: boolean = true;
249
+
244
250
  awake(): void {
245
251
  if (debug) console.log(this)
246
252
  if (!this.trackedImages) return;
@@ -324,6 +330,11 @@ export class WebXRImageTracking extends Behaviour {
324
330
  };
325
331
 
326
332
  onLeaveXR(_args: NeedleXREventArgs): void {
333
+
334
+ if(!this.supported && DeviceUtilities.isAndroidDevice()) {
335
+ showBalloonWarning(this.webXRIncubationsWarning);
336
+ }
337
+
327
338
  if (this.trackedImages) {
328
339
  for (const trackedImage of this.trackedImages) {
329
340
  if (trackedImage.object?.asset) {
@@ -347,6 +358,9 @@ export class WebXRImageTracking extends Behaviour {
347
358
  private readonly imageToObjectMap = new Map<WebXRImageTrackingModel, { object: GameObject | null, frames: number, lastTrackingTime: number }>();
348
359
  private readonly currentImages: WebXRTrackedImage[] = [];
349
360
 
361
+
362
+ private readonly webXRIncubationsWarning = "Image tracking is currently not supported on this device. On Chrome for Android, you can enable the <a target=\"_blank\" href=\"#\" onclick=\"() => console.log('I')\">chrome://flags/#webxr-incubations</a> flag.";
363
+
350
364
  onUpdateXR(args: NeedleXREventArgs): void {
351
365
  this.currentImages.length = 0;
352
366
 
@@ -354,12 +368,12 @@ export class WebXRImageTracking extends Behaviour {
354
368
  if (!frame) return;
355
369
 
356
370
  if (!("getImageTrackingResults" in frame)) {
357
- const warning = "Image tracking is currently not supported on this device. On Chrome for Android, you can enable the <a target=\"_blank\" href=\"#\" onclick=\"() => console.log('I')\">chrome://flags/#webxr-incubations</a> flag.";
358
371
  if (!this["didPrintWarning"]) {
359
372
  this["didPrintWarning"] = true;
360
- console.log(warning);
373
+ console.log(this.webXRIncubationsWarning);
361
374
  }
362
- showBalloonWarning(warning);
375
+ this._supported = false;
376
+ showBalloonWarning(this.webXRIncubationsWarning);
363
377
  return;
364
378
  }
365
379
  // Check if enabled features (if available) contains image tracking - if it's not available this statement should not catch
@@ -23,11 +23,21 @@ export class XRRig extends Behaviour implements IXRRig {
23
23
 
24
24
  get isActive() { return this.activeAndEnabled && this.gameObject.visible; }
25
25
 
26
- /** Sets this rig to be the active XR rig (needs to be called during an active XR session) */
26
+ /**
27
+ * Sets this rig to be the active XR rig (needs to be called during an active XR session)
28
+ * Note that this might modify the priority of this rig to be the highest.
29
+ */
27
30
  setAsActiveXRRig() {
28
31
  NeedleXRSession.active?.setRigActive(this);
29
32
  }
33
+ /**
34
+ * Sets the priority of the rig.
35
+ */
36
+ setPriority(value: number) {
37
+ this.priority = value;
38
+ }
30
39
 
40
+ /** @internal */
31
41
  awake(): void {
32
42
  if (debug) {
33
43
  const gizmoObj = new Object3D() as IGameObject;
@@ -51,15 +61,18 @@ export class XRRig extends Behaviour implements IXRRig {
51
61
 
52
62
  private _startScale?: Vector3;
53
63
 
64
+ /** @internal */
54
65
  onEnterXR(args: NeedleXREventArgs): void {
55
66
  this._startScale = this.gameObject.scale.clone();
56
67
  args.xr.addRig(this);
57
- if(debug) console.log("WebXR: add Rig", this.name, this.priority);
68
+ if (debug) console.log("WebXR: add Rig", this.name, this.priority);
58
69
  }
70
+ /** @internal */
59
71
  onLeaveXR(args: NeedleXREventArgs): void {
60
72
  args.xr.removeRig(this);
61
73
  if (this._startScale && this.gameObject)
62
74
  this.gameObject.scale.copy(this._startScale);
63
75
  }
64
76
 
77
+
65
78
  }
@@ -29,11 +29,11 @@ function registerGlobal(obj: object) {
29
29
  Needle[key] = obj[key];
30
30
  }
31
31
  }
32
- // import * as Component from "./engine-components/Component.js";
33
- // registerGlobal(Component);
32
+ import * as Component from "./engine-components/Component.js";
33
+ registerGlobal(Component);
34
34
 
35
- // import * as Components from "./engine-components/codegen/components.js";
36
- // registerGlobal(Components);
35
+ import * as Components from "./engine-components/codegen/components.js";
36
+ registerGlobal(Components);
37
37
 
38
38
  import { GameObject } from "./engine-components/Component.js";
39
39
  for (const method of Object.getOwnPropertyNames(GameObject)) {
@@ -64,5 +64,5 @@ import * as THREE from "three";
64
64
  if (!globalThis["THREE"]) {
65
65
  globalThis["THREE"] = THREE;
66
66
  }
67
- else console.warn("Threejs is already imported");
67
+ else console.warn("Three.js is already imported");
68
68