@needle-tools/engine 4.12.0-next.de80571 → 4.12.0-next.e42c144

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 (193) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/components.needle.json +1 -1
  3. package/dist/generateMeshBVH.worker-iyfPIK6R.js +21 -0
  4. package/dist/{gltf-progressive-DZrY8VT6.min.js → gltf-progressive-BmSygnAC.min.js} +2 -2
  5. package/dist/{gltf-progressive-DgYz5BYa.js → gltf-progressive-DnLBuGK5.js} +24 -24
  6. package/dist/{gltf-progressive-DWcmTMCh.umd.cjs → gltf-progressive-Rs-ojtXy.umd.cjs} +1 -1
  7. package/dist/{loader.worker-Dip-PthR.js → loader.worker-DWzfDpAl.js} +4 -4
  8. package/dist/needle-engine.bundle-CW5U4a3u.umd.cjs +1647 -0
  9. package/dist/needle-engine.bundle-HNQiYV9e.min.js +1647 -0
  10. package/dist/{needle-engine.bundle-CbrIHiN8.js → needle-engine.bundle-qrrKb_xn.js} +8886 -8598
  11. package/dist/needle-engine.d.ts +108 -43
  12. package/dist/needle-engine.js +48 -48
  13. package/dist/needle-engine.min.js +1 -1
  14. package/dist/needle-engine.umd.cjs +1 -1
  15. package/dist/{postprocessing-DYDtB188.min.js → postprocessing-B5ksn9-G.min.js} +54 -54
  16. package/dist/{postprocessing-CMgoN5t5.umd.cjs → postprocessing-DZtb9Nnn.umd.cjs} +81 -81
  17. package/dist/{postprocessing-BTW9pD_s.js → postprocessing-__7s9wON.js} +450 -441
  18. package/dist/{three-DfMvBzXi.js → three-BCCkyCA5.js} +1 -7
  19. package/dist/{three-qj71I7J3.umd.cjs → three-Bf2NBxAw.umd.cjs} +2 -2
  20. package/dist/{three-B7CT31Bt.min.js → three-W7zWTcfP.min.js} +1 -1
  21. package/dist/{three-examples-CsW4_6LI.umd.cjs → three-examples-Dho7cuu4.umd.cjs} +4 -4
  22. package/dist/{three-examples-D1P7eEhn.min.js → three-examples-MsJjauyk.min.js} +10 -10
  23. package/dist/{three-examples-D1SK93ek.js → three-examples-y2GeYlze.js} +2 -20
  24. package/dist/{three-mesh-ui-C_uSB5dD.js → three-mesh-ui-3nSSizT4.js} +1 -1
  25. package/dist/{three-mesh-ui-LQ44s0AL.min.js → three-mesh-ui-CIez6qJQ.min.js} +1 -1
  26. package/dist/{three-mesh-ui-DpATDXwU.umd.cjs → three-mesh-ui-zsOOA5Pq.umd.cjs} +1 -1
  27. package/dist/{vendor-D0zoswDa.js → vendor-DMZcbVO1.js} +3707 -3527
  28. package/dist/vendor-sURMCFSI.min.js +1116 -0
  29. package/dist/{vendor-UCpFAwt1.umd.cjs → vendor-tyBvnMF-.umd.cjs} +39 -39
  30. package/lib/engine/codegen/register_types.js +0 -2
  31. package/lib/engine/codegen/register_types.js.map +1 -1
  32. package/lib/engine/debug/debug_console.js +403 -1
  33. package/lib/engine/debug/debug_console.js.map +1 -1
  34. package/lib/engine/engine_components.js +3 -3
  35. package/lib/engine/engine_components.js.map +1 -1
  36. package/lib/engine/engine_context.js +2 -0
  37. package/lib/engine/engine_context.js.map +1 -1
  38. package/lib/engine/engine_input.d.ts +5 -0
  39. package/lib/engine/engine_input.js +6 -0
  40. package/lib/engine/engine_input.js.map +1 -1
  41. package/lib/engine/engine_license.d.ts +18 -0
  42. package/lib/engine/engine_license.js +115 -18
  43. package/lib/engine/engine_license.js.map +1 -1
  44. package/lib/engine/engine_networking.js +5 -5
  45. package/lib/engine/engine_networking.js.map +1 -1
  46. package/lib/engine/engine_physics.js.map +1 -1
  47. package/lib/engine/engine_physics_rapier.js +1 -1
  48. package/lib/engine/engine_physics_rapier.js.map +1 -1
  49. package/lib/engine/engine_serialization_builtin_serializer.js +1 -1
  50. package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -1
  51. package/lib/engine/engine_utils.d.ts +4 -1
  52. package/lib/engine/engine_utils.js +28 -4
  53. package/lib/engine/engine_utils.js.map +1 -1
  54. package/lib/engine/extensions/extensions.d.ts +29 -7
  55. package/lib/engine/extensions/extensions.js.map +1 -1
  56. package/lib/engine/webcomponents/WebXRButtons.js +13 -5
  57. package/lib/engine/webcomponents/WebXRButtons.js.map +1 -1
  58. package/lib/engine/webcomponents/needle menu/needle-menu.js +4 -5
  59. package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
  60. package/lib/engine/webcomponents/needle-engine.ar-overlay.js +4 -0
  61. package/lib/engine/webcomponents/needle-engine.ar-overlay.js.map +1 -1
  62. package/lib/engine/webcomponents/needle-engine.js +1 -1
  63. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  64. package/lib/engine/xr/NeedleXRSession.d.ts +1 -1
  65. package/lib/engine/xr/NeedleXRSession.js +101 -22
  66. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  67. package/lib/engine/xr/TempXRContext.js +12 -2
  68. package/lib/engine/xr/TempXRContext.js.map +1 -1
  69. package/lib/engine/xr/usdz.js +6 -2
  70. package/lib/engine/xr/usdz.js.map +1 -1
  71. package/lib/engine-components/AlignmentConstraint.d.ts +1 -1
  72. package/lib/engine-components/AlignmentConstraint.js +1 -1
  73. package/lib/engine-components/Animation.d.ts +1 -1
  74. package/lib/engine-components/Animation.js +1 -1
  75. package/lib/engine-components/Animator.d.ts +1 -1
  76. package/lib/engine-components/Animator.js +1 -1
  77. package/lib/engine-components/AudioListener.d.ts +1 -1
  78. package/lib/engine-components/AudioListener.js +1 -1
  79. package/lib/engine-components/AudioSource.d.ts +1 -1
  80. package/lib/engine-components/AudioSource.js +1 -1
  81. package/lib/engine-components/Camera.d.ts +1 -1
  82. package/lib/engine-components/Camera.js +5 -2
  83. package/lib/engine-components/Camera.js.map +1 -1
  84. package/lib/engine-components/CharacterController.d.ts +6 -2
  85. package/lib/engine-components/CharacterController.js +6 -2
  86. package/lib/engine-components/CharacterController.js.map +1 -1
  87. package/lib/engine-components/Collider.d.ts +1 -1
  88. package/lib/engine-components/Collider.js.map +1 -1
  89. package/lib/engine-components/Component.d.ts +2 -1
  90. package/lib/engine-components/Component.js +3 -2
  91. package/lib/engine-components/Component.js.map +1 -1
  92. package/lib/engine-components/DragControls.js +4 -1
  93. package/lib/engine-components/DragControls.js.map +1 -1
  94. package/lib/engine-components/Joints.d.ts +14 -0
  95. package/lib/engine-components/Joints.js +14 -0
  96. package/lib/engine-components/Joints.js.map +1 -1
  97. package/lib/engine-components/LookAtConstraint.d.ts +1 -1
  98. package/lib/engine-components/LookAtConstraint.js +1 -1
  99. package/lib/engine-components/OrbitControls.d.ts +1 -1
  100. package/lib/engine-components/OrbitControls.js +1 -1
  101. package/lib/engine-components/Renderer.d.ts +6 -0
  102. package/lib/engine-components/Renderer.js +6 -0
  103. package/lib/engine-components/Renderer.js.map +1 -1
  104. package/lib/engine-components/RendererInstancing.js +5 -3
  105. package/lib/engine-components/RendererInstancing.js.map +1 -1
  106. package/lib/engine-components/SceneSwitcher.js +18 -14
  107. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  108. package/lib/engine-components/SpectatorCamera.js +15 -7
  109. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  110. package/lib/engine-components/SpriteRenderer.d.ts +2 -1
  111. package/lib/engine-components/SpriteRenderer.js +2 -1
  112. package/lib/engine-components/SpriteRenderer.js.map +1 -1
  113. package/lib/engine-components/api.d.ts +1 -0
  114. package/lib/engine-components/api.js +1 -0
  115. package/lib/engine-components/api.js.map +1 -1
  116. package/lib/engine-components/codegen/components.d.ts +0 -1
  117. package/lib/engine-components/codegen/components.js +0 -1
  118. package/lib/engine-components/codegen/components.js.map +1 -1
  119. package/lib/engine-components/timeline/SignalAsset.d.ts +1 -1
  120. package/lib/engine-components/timeline/SignalAsset.js +1 -1
  121. package/lib/engine-components/ui/Raycaster.d.ts +3 -2
  122. package/lib/engine-components/ui/Raycaster.js +3 -2
  123. package/lib/engine-components/ui/Raycaster.js.map +1 -1
  124. package/lib/engine-components/ui/RectTransform.d.ts +6 -0
  125. package/lib/engine-components/ui/RectTransform.js +6 -0
  126. package/lib/engine-components/ui/RectTransform.js.map +1 -1
  127. package/lib/engine-components/utils/LookAt.d.ts +2 -1
  128. package/lib/engine-components/utils/LookAt.js +2 -1
  129. package/lib/engine-components/utils/LookAt.js.map +1 -1
  130. package/lib/engine-components/web/CursorFollow.d.ts +1 -1
  131. package/lib/engine-components/web/CursorFollow.js +1 -1
  132. package/lib/engine-components/web/HoverAnimation.d.ts +1 -1
  133. package/lib/engine-components/web/HoverAnimation.js +1 -1
  134. package/lib/engine-components/web/ViewBox.d.ts +1 -1
  135. package/lib/engine-components/web/ViewBox.js +1 -1
  136. package/lib/engine-components/webxr/Avatar.js +2 -0
  137. package/lib/engine-components/webxr/Avatar.js.map +1 -1
  138. package/lib/engine-components/webxr/WebXR.js +18 -12
  139. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  140. package/package.json +3 -3
  141. package/plugins/vite/poster-client.js +8 -1
  142. package/src/engine/codegen/register_types.ts +0 -2
  143. package/src/engine/debug/debug_console.ts +449 -1
  144. package/src/engine/engine_components.ts +4 -4
  145. package/src/engine/engine_context.ts +2 -0
  146. package/src/engine/engine_input.ts +7 -0
  147. package/src/engine/engine_license.ts +128 -17
  148. package/src/engine/engine_networking.ts +5 -5
  149. package/src/engine/engine_physics.ts +3 -3
  150. package/src/engine/engine_physics_rapier.ts +1 -1
  151. package/src/engine/engine_serialization_builtin_serializer.ts +1 -1
  152. package/src/engine/engine_utils.ts +23 -4
  153. package/src/engine/extensions/extensions.ts +30 -6
  154. package/src/engine/webcomponents/WebXRButtons.ts +15 -5
  155. package/src/engine/webcomponents/needle menu/needle-menu.ts +4 -5
  156. package/src/engine/webcomponents/needle-engine.ar-overlay.ts +6 -0
  157. package/src/engine/webcomponents/needle-engine.ts +2 -2
  158. package/src/engine/xr/NeedleXRSession.ts +114 -24
  159. package/src/engine/xr/TempXRContext.ts +12 -2
  160. package/src/engine/xr/usdz.ts +6 -1
  161. package/src/engine-components/AlignmentConstraint.ts +1 -1
  162. package/src/engine-components/Animation.ts +1 -1
  163. package/src/engine-components/Animator.ts +1 -1
  164. package/src/engine-components/AudioListener.ts +1 -1
  165. package/src/engine-components/AudioSource.ts +1 -1
  166. package/src/engine-components/Camera.ts +5 -2
  167. package/src/engine-components/CharacterController.ts +6 -2
  168. package/src/engine-components/Collider.ts +1 -1
  169. package/src/engine-components/Component.ts +5 -4
  170. package/src/engine-components/DragControls.ts +5 -1
  171. package/src/engine-components/Joints.ts +14 -0
  172. package/src/engine-components/LookAtConstraint.ts +1 -1
  173. package/src/engine-components/OrbitControls.ts +1 -1
  174. package/src/engine-components/Renderer.ts +6 -0
  175. package/src/engine-components/RendererInstancing.ts +6 -3
  176. package/src/engine-components/SceneSwitcher.ts +17 -17
  177. package/src/engine-components/SpectatorCamera.ts +21 -10
  178. package/src/engine-components/SpriteRenderer.ts +2 -1
  179. package/src/engine-components/api.ts +2 -1
  180. package/src/engine-components/codegen/components.ts +0 -1
  181. package/src/engine-components/timeline/SignalAsset.ts +1 -1
  182. package/src/engine-components/ui/Raycaster.ts +3 -2
  183. package/src/engine-components/ui/RectTransform.ts +6 -0
  184. package/src/engine-components/utils/LookAt.ts +2 -1
  185. package/src/engine-components/web/CursorFollow.ts +1 -1
  186. package/src/engine-components/web/HoverAnimation.ts +1 -1
  187. package/src/engine-components/web/ViewBox.ts +1 -1
  188. package/src/engine-components/webxr/Avatar.ts +4 -0
  189. package/src/engine-components/webxr/WebXR.ts +19 -11
  190. package/dist/generateMeshBVH.worker-mO20N_b8.js +0 -21
  191. package/dist/needle-engine.bundle-BGixCtrn.umd.cjs +0 -1647
  192. package/dist/needle-engine.bundle-S3PalR7r.min.js +0 -1647
  193. package/dist/vendor-BKGa4GE0.min.js +0 -1116
@@ -43,6 +43,7 @@ import { deepClone, delay, DeviceUtilities, getParam } from './engine_utils.js';
43
43
  import type { INeedleXRSessionEventReceiver, NeedleXRSession } from './engine_xr.js';
44
44
  import { NeedleMenu } from './webcomponents/needle menu/needle-menu.js';
45
45
  import type { NeedleEngineWebComponent } from './webcomponents/needle-engine.js';
46
+ import { Telemetry } from './engine_license.js';
46
47
 
47
48
  const debug = getParam("debugcontext");
48
49
  const stats = getParam("stats");
@@ -1403,6 +1404,7 @@ export class Context implements IContext {
1403
1404
  if (this._renderlooperrors >= 3) {
1404
1405
  console.warn("Stopping render loop due to error")
1405
1406
  this.renderer.setAnimationLoop(null);
1407
+ Telemetry.sendError(Context.Current, "renderloop", err instanceof Error ? err : new Error(String(err)) );
1406
1408
  }
1407
1409
  this.domElement.dispatchEvent(new CustomEvent("error", { detail: err }));
1408
1410
  }
@@ -150,6 +150,12 @@ export class NEPointerEvent extends PointerEvent {
150
150
  override get pointerType(): PointerTypeNames { return this._pointerType; }
151
151
  private readonly _pointerType: PointerTypeNames;
152
152
 
153
+ /**
154
+ * The button name that raised this event (e.g. for mouse events "left", "right", "middle" or for XRTrigger "xr-standard-trigger" or "xr-standard-thumbstick")
155
+ * Use {@link button} to get the numeric button index (e.g. 0, 1, 2...) on the controller or mouse.
156
+ */
157
+ readonly buttonName?: ButtonName | "none" = undefined;
158
+
153
159
  // this is set via the init arguments (we override it here for intellisense to show the string options)
154
160
  /** The input that raised this event like `pointerdown` */
155
161
  override get type(): InputEventNames { return this._type; }
@@ -176,6 +182,7 @@ export class NEPointerEvent extends PointerEvent {
176
182
  this.mode = init.mode;
177
183
  this._ray = init.ray;
178
184
  this.space = init.device;
185
+ this.buttonName = init.buttonName;
179
186
  }
180
187
 
181
188
  private _immediatePropagationStopped = false;
@@ -4,6 +4,7 @@ import { ContextEvent, ContextRegistry } from "./engine_context_registry.js";
4
4
  import { Context } from "./engine_setup.js";
5
5
  import type { IContext } from "./engine_types.js";
6
6
  import { getParam } from "./engine_utils.js";
7
+ import { InternalAttributeUtils } from "./engine_utils_attributes.js";
7
8
 
8
9
  const debug = getParam("debuglicense");
9
10
 
@@ -67,6 +68,126 @@ function invokeLicenseCheckResultChanged(result: boolean) {
67
68
  }
68
69
  }
69
70
 
71
+
72
+
73
+ export namespace Telemetry {
74
+
75
+ export function isAllowed(context: IContext | null | undefined): boolean {
76
+ let domElement = context?.domElement as HTMLElement | null;
77
+ if (!domElement) domElement = document.querySelector<HTMLElement>("needle-engine");
78
+ if (!domElement && !context) return false;
79
+
80
+ const attribute = domElement?.getAttribute("no-telemetry");
81
+ if (attribute === "" || attribute === "true" || attribute === "1") {
82
+ if (NEEDLE_ENGINE_LICENSE_TYPE === "pro" || NEEDLE_ENGINE_LICENSE_TYPE === "enterprise") {
83
+ if (debug) console.debug("Telemetry is disabled via no-telemetry attribute");
84
+ return false;
85
+ }
86
+ }
87
+ return true;
88
+ }
89
+
90
+ const id = "dabb8317376f";
91
+
92
+ /**
93
+ * Sends a telemetry event
94
+ */
95
+ export async function sendEvent(context: IContext | null | undefined, eventName: string, properties?: Record<string, any>) {
96
+ if (!isAllowed(context)) {
97
+ if (debug) console.debug("Telemetry is disabled");
98
+ return;
99
+ }
100
+ const body = {
101
+ site_id: id,
102
+ type: "custom_event",
103
+ pathname: window.location.pathname,
104
+ event_name: eventName,
105
+ properties: properties ? JSON.stringify(properties) : undefined,
106
+ }
107
+ return doFetch(body);
108
+ }
109
+
110
+ type ErrorData = {
111
+ message?: string;
112
+ stack?: string;
113
+ filename?: string;
114
+ lineno?: number;
115
+ colno?: number;
116
+ timestamp?: number;
117
+ }
118
+ function isErrorData(obj: any): obj is ErrorData {
119
+ return obj && (typeof obj.message === "string" || typeof obj.stack === "string");
120
+ }
121
+
122
+ export async function sendError(context: IContext, errorName: string, error: ErrorData | ErrorEvent | Error) {
123
+
124
+ if (!isAllowed(context)) {
125
+ if (debug) console.debug("Telemetry is disabled");
126
+ return;
127
+ }
128
+
129
+ if (error instanceof ErrorEvent) {
130
+ error = {
131
+ message: error.message,
132
+ stack: error.error?.stack,
133
+ filename: error.filename,
134
+ lineno: error.lineno,
135
+ colno: error.colno,
136
+ timestamp: error.timeStamp || Date.now(),
137
+
138
+ };
139
+ }
140
+ else if (error instanceof Error) {
141
+ error = {
142
+ message: error.message,
143
+ stack: error.stack,
144
+ timestamp: Date.now(),
145
+ };
146
+ }
147
+ const body = {
148
+ site_id: id,
149
+ type: "error",
150
+ properties: {
151
+ error_name: errorName,
152
+ message: error.message,
153
+ stack: error.stack,
154
+ filename: error.filename,
155
+ lineno: error.lineno,
156
+ colno: error.colno,
157
+ timestamp: error.timestamp,
158
+ }
159
+ }
160
+ return doFetch(body);
161
+ }
162
+
163
+ function doFetch(body: Record<string, any>) {
164
+ try {
165
+ const url = "https://needle.tools/api/v1/rum/t";
166
+ return fetch(url, {
167
+ method: "POST",
168
+ body: JSON.stringify(body),
169
+ headers: {
170
+ 'Content-Type': 'application/json'
171
+ },
172
+ // Ensures request completes even if page unloads
173
+ keepalive: true,
174
+ // Allow CORS requests
175
+ mode: 'cors',
176
+ // Low priority to avoid blocking other requests
177
+ // @ts-ignore
178
+ priority: 'low',
179
+ }).catch(e => {
180
+ if (debug) console.error("Failed to send telemetry", e);
181
+ })
182
+ }
183
+ catch (err) {
184
+ if (debug) console.error(err);
185
+ }
186
+ return Promise.resolve();
187
+ }
188
+ }
189
+
190
+
70
191
  ContextRegistry.registerCallback(ContextEvent.ContextRegistered, evt => {
71
192
  showLicenseInfo(evt.context);
72
193
  handleForbidden(evt.context);
@@ -81,7 +202,7 @@ async function checkLicense() {
81
202
  if (runtimeLicenseCheckPromise) return runtimeLicenseCheckPromise;
82
203
  if (NEEDLE_ENGINE_LICENSE_TYPE === "basic") {
83
204
  try {
84
- const licenseUrl = "https://engine.needle.tools/licensing/check?location=" + encodeURIComponent(window.location.href) + "&version=" + VERSION + "&generator=" + encodeURIComponent(GENERATOR);
205
+ const licenseUrl = "https://needle.tools/api/v1/needle-engine/check?location=" + encodeURIComponent(window.location.href) + "&version=" + VERSION + "&generator=" + encodeURIComponent(GENERATOR);
85
206
  const res = await fetch(licenseUrl, {
86
207
  method: "GET",
87
208
  }).catch(_err => {
@@ -341,28 +462,18 @@ async function sendUsageMessageToAnalyticsBackend(context: IContext) {
341
462
  // We can't send beacons from cross-origin isolated pages
342
463
  if (window.crossOriginIsolated) return;
343
464
 
344
- const licenseType = NEEDLE_ENGINE_LICENSE_TYPE;
345
- if (licenseType === "pro" || licenseType === "enterprise") {
346
- const attribute = context?.domElement?.getAttribute("no-telemetry");
347
- if (attribute === "" || attribute === "true" || attribute === "1") {
348
- if (debug) console.debug("Telemetry is disabled");
349
- return;
350
- }
351
- if (debug) console.debug("Telemetry attribute: " + attribute);
465
+ if (!Telemetry.isAllowed(context)) {
466
+ if (debug) console.debug("Telemetry is disabled via no-telemetry attribute");
467
+ return;
352
468
  }
353
469
 
354
470
  try {
355
- const analyticsUrl = "htt" + "ps://nee" + "dle.tools/api/v1/ana" + "lytics";
471
+ const analyticsUrl = "htt" + "ps://" + "needle" + ".tools/" + "api/v1/needle-engine/ping";
356
472
  if (analyticsUrl) {
357
473
 
358
474
  // current url without query parameters
359
475
  const currentUrl = window.location.href.split("?")[0];
360
-
361
- let endpoint = "api/v2/new/request";
362
- if (!analyticsUrl.endsWith("/")) endpoint = "/" + endpoint;
363
476
  const license = NEEDLE_ENGINE_LICENSE_TYPE;
364
- const finalUrl = `${analyticsUrl}${endpoint}`;
365
- if (debug) console.debug("Sending beacon");
366
477
 
367
478
  const beaconData = {
368
479
  license,
@@ -376,7 +487,7 @@ async function sendUsageMessageToAnalyticsBackend(context: IContext) {
376
487
  build_time: BUILD_TIME,
377
488
  public_key: PUBLIC_KEY,
378
489
  };
379
- const res = navigator.sendBeacon?.(finalUrl, JSON.stringify(beaconData));
490
+ const res = navigator.sendBeacon?.(analyticsUrl, JSON.stringify(beaconData));
380
491
  if (debug) console.debug("Sent beacon: " + res);
381
492
  }
382
493
  }
@@ -384,4 +495,4 @@ async function sendUsageMessageToAnalyticsBackend(context: IContext) {
384
495
  if (debug)
385
496
  console.log("Failed to send non-commercial usage message to analytics backend", err);
386
497
  }
387
- }
498
+ }
@@ -629,7 +629,7 @@ export class NetworkConnection implements INetworkConnection {
629
629
  return;
630
630
  }
631
631
 
632
- console.debug("Connecting to networking backend on\n" + networkingServerUrl)
632
+ console.debug("Connecting to networking backend on\n" + networkingServerUrl)
633
633
  const pkg = await import('websocket-ts');
634
634
  // @ts-ignore
635
635
  const WebsocketBuilder = pkg.default?.WebsocketBuilder ?? pkg.WebsocketBuilder;
@@ -641,8 +641,8 @@ export class NetworkConnection implements INetworkConnection {
641
641
  this._connectingToWebsocketPromise = null;
642
642
  this._ws = ws;
643
643
  this.connected = true;
644
- if (isDevEnvironment() || debugNet) console.log("Connected to networking backend\n" + networkingServerUrl);
645
- else console.debug("Connected to networking backend", networkingServerUrl);
644
+ if (isDevEnvironment() || debugNet) console.log("Connected to networking backend\n" + networkingServerUrl);
645
+ else console.debug("Connected to networking backend", networkingServerUrl);
646
646
  resolve(true);
647
647
  this.onSendQueued(SendQueue.OnConnection);
648
648
  })
@@ -656,10 +656,10 @@ export class NetworkConnection implements INetworkConnection {
656
656
  console.error(msg);
657
657
  })
658
658
  .onError((_e) => {
659
- console.error("Websocket connection failed...");
659
+ console.error("Websocket connection failed...");
660
660
  resolve(false);
661
661
  })
662
- .onRetry(() => { console.log("Retry connecting to networking websocket") })
662
+ .onRetry(() => { console.log("Retry connecting to networking websocket") })
663
663
  .build();
664
664
  ws.addEventListener(pkg.WebsocketEvent.message, (socket, msg) => {
665
665
  this.onMessage(socket, msg);
@@ -1,7 +1,7 @@
1
1
  import { getRaycastMesh } from '@needle-tools/gltf-progressive';
2
2
  import { ArrayCamera, Box3, BufferGeometry, Camera, type Intersection, Layers, Line, Matrix3, Matrix4, Mesh, Object3D, PerspectiveCamera, Plane, Ray, Raycaster, SkinnedMesh, Sphere, SphereGeometry, Vector2, Vector3 } from 'three'
3
3
  import { GroundedSkybox } from 'three/examples/jsm/objects/GroundedSkybox.js';
4
- import type { MeshBVH, MeshBVHOptions, StaticGeometryGenerator } from 'three-mesh-bvh';
4
+ import type { ComputeBVHOptions, GeometryBVH, MeshBVH, StaticGeometryGenerator } from 'three-mesh-bvh';
5
5
  import type { GenerateMeshBVHWorker } from 'three-mesh-bvh/src/workers/GenerateMeshBVHWorker.js';
6
6
 
7
7
  import { isDevEnvironment } from './debug/index.js';
@@ -762,7 +762,7 @@ namespace NEMeshBVH {
762
762
  return true;
763
763
  }
764
764
  else if (method instanceof Sphere) {
765
- const bvh = geom.boundsTree;
765
+ const bvh = geom.boundsTree as MeshBVH | undefined;
766
766
  if (bvh) {
767
767
  const sphere = method;
768
768
  // Gizmos.DrawWireSphere(sphere.center, sphere.radius, 0xdddd00, 1, false);
@@ -789,7 +789,7 @@ namespace NEMeshBVH {
789
789
  let _acceleratedRaycast: Function | null = null;
790
790
  let _MeshBVH: ConstructorConcrete<MeshBVH> | null = null;
791
791
  let _StaticGeometryGenerator: ConstructorConcrete<StaticGeometryGenerator> | null = null;
792
- let _computeBoundsTree: ((_opt?: MeshBVHOptions) => MeshBVH) | null = null;
792
+ let _computeBoundsTree: (( options?: ComputeBVHOptions ) => GeometryBVH) | null = null;
793
793
 
794
794
  function loadMeshBVHLibrary() {
795
795
  if (didLoadMeshBVHLibrary) return;
@@ -273,7 +273,7 @@ export class RapierPhysics implements IPhysicsEngine {
273
273
  if (MODULES.RAPIER_PHYSICS.MAYBEMODULE == undefined) {
274
274
  if (debugPhysics) console.trace("Loading rapier physics engine");
275
275
  const module = await MODULES.RAPIER_PHYSICS.load();
276
- // https://github.com/dimforge/rapier/issues/811
276
+ // https://github.com/dimforge/rapier/issues/811 < but single object parameter still warns
277
277
  await module.init();
278
278
  }
279
279
  if (debugPhysics) console.log("Physics engine initialized, creating world...");
@@ -337,7 +337,7 @@ class EventListSerializer extends TypeSerializer {
337
337
  args = call.arguments.map(deserializeArgument);
338
338
  }
339
339
  const method = target[call.method];
340
- if (!method) {
340
+ if (method === undefined) {
341
341
  console.warn(`EventList method not found: \"${call.method}\" on ${target?.name}`);
342
342
  }
343
343
  else {
@@ -606,7 +606,8 @@ export namespace DeviceUtilities {
606
606
  /** @returns `true` if we're currently on an iPad */
607
607
  export function isiPad() {
608
608
  if (__isiPad !== undefined) return __isiPad;
609
- return __isiPad = /iPad/.test(navigator.userAgent);
609
+ const userAgent = navigator.userAgent.toLowerCase();
610
+ return __isiPad = /iPad/.test(navigator.userAgent) || userAgent.includes("macintosh") && "ontouchend" in document;
610
611
  }
611
612
 
612
613
  let __isAndroidDevice: boolean | undefined;
@@ -623,17 +624,25 @@ export namespace DeviceUtilities {
623
624
  return __isMozillaXR = /WebXRViewer\//i.test(navigator.userAgent);
624
625
  }
625
626
 
627
+ let __isNeedleAppClip: boolean | undefined;
628
+ /** @returns `true` if we're currently in the Needle App Clip */
629
+ export function isNeedleAppClip() {
630
+ if (__isNeedleAppClip !== undefined) return __isNeedleAppClip;
631
+ return __isNeedleAppClip = /NeedleAppClip\//i.test(navigator.userAgent);
632
+ }
633
+
626
634
  let __isMacOS: boolean | undefined;
627
635
  // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgentData
628
636
  /** @returns `true` for MacOS devices */
629
637
  export function isMacOS() {
630
638
  if (__isMacOS !== undefined) return __isMacOS;
639
+ if (isiOS() || isiPad()) return __isMacOS = false;
640
+ const userAgent = navigator.userAgent.toLowerCase();
631
641
  if (navigator.userAgentData) {
632
642
  // Use modern UA Client Hints API if available
633
643
  return __isMacOS = navigator.userAgentData.platform === 'macOS';
634
644
  } else {
635
645
  // Fallback to user agent string parsing
636
- const userAgent = navigator.userAgent.toLowerCase();
637
646
  return __isMacOS = userAgent.includes('mac os x') || userAgent.includes('macintosh');
638
647
  }
639
648
  }
@@ -642,13 +651,13 @@ export namespace DeviceUtilities {
642
651
  /** @returns `true` for VisionOS devices */
643
652
  export function isVisionOS() {
644
653
  if (__isVisionOS !== undefined) return __isVisionOS;
645
- return __isVisionOS = (isMacOS() && "xr" in navigator);
654
+ return __isVisionOS = (isiPad() && "xr" in navigator && supportsQuickLookAR());
646
655
  }
647
656
 
648
657
  let __isiOS: boolean | undefined;
649
658
  const iosDevices = ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'];
650
659
 
651
- /** @returns `true` for iOS devices like iPad, iPhone, iPod... */
660
+ /** @returns `true` for mobile Apple devices like iPad, iPhone, iPod, Vision Pro, ... */
652
661
  export function isiOS() {
653
662
  if (__isiOS !== undefined) return __isiOS;
654
663
  // eslint-disable-next-line deprecation/deprecation
@@ -725,6 +734,16 @@ export namespace DeviceUtilities {
725
734
  else __chromeVersion = null;
726
735
  return __chromeVersion;
727
736
  }
737
+
738
+ let __safariVersion: string | null | undefined;
739
+ export function getSafariVersion() {
740
+ if (__safariVersion !== undefined) return __safariVersion;
741
+ const match = navigator.userAgent.match(/Version\/(\d+\.\d+)/);
742
+ if (match && isSafari()) {
743
+ __safariVersion = match[1];
744
+ } else __safariVersion = null;
745
+ return __safariVersion;
746
+ }
728
747
  }
729
748
 
730
749
  /**
@@ -30,20 +30,44 @@ const KHR_ANIMATIONPOINTER_IMPORT = import("@needle-tools/three-animation-pointe
30
30
  });
31
31
 
32
32
 
33
- declare type OnImportCallback = (loader: GLTFLoader, url: string, context: Context) => void;
34
- declare type OnExportCallback = (exporter: GLTFExporter, context: Context) => void;
33
+ /**
34
+ * Callback type for glTF import plugins. See {@link INeedleGLTFExtensionPlugin.onImport}
35
+ */
36
+ export type OnImportCallback = (loader: GLTFLoader, url: string, context: Context) => void;
37
+
38
+ /**
39
+ * Callback type for glTF export plugins. See {@link INeedleGLTFExtensionPlugin.onExport}
40
+ */
41
+ export type OnExportCallback = (exporter: GLTFExporter, context: Context) => void;
35
42
 
36
43
  /**
37
- * Interface for registering custom glTF extensions to the Needle Engine GLTFLoaders. Register your plugin via {@link addCustomExtensionPlugin}
44
+ * Interface for registering custom glTF extensions to the Needle Engine GLTFLoaders.
45
+ * Register your plugin using the {@link addCustomExtensionPlugin} method
38
46
  */
39
47
  export interface INeedleGLTFExtensionPlugin {
40
48
  /** The Name of your plugin */
41
49
  name: string;
42
- /** Called before starting to load a glTF file. This callback can be used to add custom extensions to the GLTFLoader */
50
+ /** Called before starting to load a glTF file. This callback can be used to add custom extensions to the [GLTFLoader](https://threejs.org/docs/#GLTFLoader.register)
51
+ *
52
+ * @example Add a custom extension to the GLTFloader
53
+ * ```ts
54
+ * onImport: (loader, url, context) => {
55
+ * loader.register((parser) => new MyCustomExtension(parser));
56
+ * }
57
+ * ```
58
+ */
43
59
  onImport?: OnImportCallback;
44
- /** Called after the glTF has been loaded */
60
+ /** Called after a glTF file has been loaded */
45
61
  onLoaded?: (url: string, gltf: GLTF, context: Context) => void;
46
- /** Called before starting to export a glTF file. This callback can be used to add custom extensions to the GLTFExporter */
62
+ /** Called before starting to export a glTF file. This callback can be used to add custom extensions to the [GLTFExporter](https://threejs.org/docs/#examples/en/exporters/GLTFExporter.register)
63
+ *
64
+ * @example Add a custom extension to the GLTFExporter
65
+ * ```ts
66
+ * onExport: (exporter, context) => {
67
+ * exporter.register((writer) => new MyCustomExportExtension(writer));
68
+ * }
69
+ *
70
+ */
47
71
  onExport?: OnExportCallback;
48
72
  }
49
73
 
@@ -57,13 +57,16 @@ export class WebXRButtonFactory {
57
57
  this._quicklookButton = button;
58
58
  button.dataset["needle"] = "quicklook-button";
59
59
  const supportsQuickLook = DeviceUtilities.supportsQuickLookAR();
60
+ let buttonText = "View in AR";
60
61
  // we can immediately enter this scene, because the platform supports rel="ar" links
61
- if (supportsQuickLook) {
62
- button.innerText = "View in AR";
62
+ if (DeviceUtilities.isVisionOS()) {
63
+ buttonText = "View in AR";
63
64
  }
64
- else {
65
- button.innerText = "View in AR";
65
+ else if (supportsQuickLook || DeviceUtilities.isiOS()) {
66
+ buttonText = "Open in Quicklook";
66
67
  }
68
+
69
+ button.innerText = buttonText;
67
70
  button.prepend(getIconElement("view_in_ar"));
68
71
 
69
72
  let createdExporter = false;
@@ -209,13 +212,20 @@ export class WebXRButtonFactory {
209
212
  }
210
213
 
211
214
  private updateSessionSupported(button: HTMLButtonElement, mode: XRSessionMode) {
215
+ if (mode === "immersive-ar" && DeviceUtilities.isiOS() && !DeviceUtilities.isVisionOS()) {
216
+ // on iOS, we can forward to the AppClip experience from the same button,
217
+ // so we always show the button. No AppClip support on VisionOS for now, so
218
+ // button state depends on WebXR support there.
219
+ return;
220
+ }
221
+
212
222
  if (!("xr" in navigator)) {
213
223
  button.style.display = "none";
214
224
  return;
215
225
  }
216
226
  NeedleXRSession.isSessionSupported(mode).then(supported => {
217
227
  button.style.display = !supported ? "none" : "";
218
- if (isDevEnvironment() && !supported) console.log("[WebXR] \"" + mode + "\" is not supported on this device make sure your server runs using HTTPS and you have a device connected that supports " + mode);
228
+ if (isDevEnvironment() && !supported) console.log("[WebXR] \"" + mode + "\" is not supported on this device. Make sure your server runs using HTTPS and you have a device connected that supports " + mode);
219
229
  });
220
230
  }
221
231
 
@@ -601,16 +601,15 @@ export class NeedleMenuElement extends HTMLElement {
601
601
  bottom: calc(100% + 5px);
602
602
  z-index: 100;
603
603
  width: auto;
604
- left: .2rem;
605
- right: .2rem;
606
- padding: .2rem;
604
+ max-width: 90vw;
605
+ left: 50%;
606
+ transform: translateX(-50%);
607
+ padding: .2rem 1em;
607
608
 
608
609
  }
609
610
  .compact.logo-hidden .foldout {
610
611
  /** for when there's no logo we want to center the foldout **/
611
612
  min-width: 24ch;
612
- margin-left: 50%;
613
- transform: translateX(calc(-50% - .2rem));
614
613
  }
615
614
 
616
615
  .compact.top .foldout {
@@ -118,6 +118,12 @@ export class AROverlayHandler {
118
118
  }
119
119
 
120
120
  private ensureQuitARButton(element: HTMLElement) {
121
+
122
+ // No quit button in app clips, we provide one via the native UI
123
+ if (DeviceUtilities.isNeedleAppClip()) {
124
+ return;
125
+ }
126
+
121
127
  const quitARSlot = document.createElement("slot");
122
128
  quitARSlot.setAttribute("name", "quit-ar");
123
129
  this.appendElement(quitARSlot, element);
@@ -356,7 +356,7 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
356
356
  case "loadfinished":
357
357
  if (typeof newValue === "string" && newValue.length > 0) {
358
358
  if (debug) console.log(name + " attribute changed", newValue);
359
- this.registerEventFromAttribute("loadfinished", newValue);
359
+ this.registerEventFromAttribute(name, newValue);
360
360
  }
361
361
  break;
362
362
  case "dracoDecoderPath":
@@ -708,7 +708,7 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
708
708
  if (attributeValue)
709
709
  this.registerEventFromAttribute("loadstart", attributeValue);
710
710
  }
711
- private registerEventFromAttribute(eventName: 'loadfinished' | 'loadstart', code: string) {
711
+ private registerEventFromAttribute(eventName: 'loadfinished' | 'loadstart' | 'progress', code: string) {
712
712
  const prev = this._previouslyRegisteredMap.get(eventName);
713
713
  if (prev) {
714
714
  this._previouslyRegisteredMap.delete(eventName);