@zappar/zappar-cv 3.8.0-beta.2 → 3.8.3

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.
package/README.md CHANGED
@@ -18,8 +18,8 @@ npm i @zappar/zappar-cv
18
18
 
19
19
  You can use our CDN from within your HTML:
20
20
  ```
21
- <script src="https://libs.zappar.com/zappar-cv/3.8.0-beta.2/zappar-cv.js"></script>
21
+ <script src="https://libs.zappar.com/zappar-cv/3.8.3/zappar-cv.js"></script>
22
22
  ```
23
23
 
24
24
  Or you can download and host our standalone JavaScript bundle:
25
- [https://libs.zappar.com/zappar-cv/3.8.0-beta.2/zappar-cv.zip](https://libs.zappar.com/zappar-cv/3.8.0-beta.2/zappar-cv.zip)
25
+ [https://libs.zappar.com/zappar-cv/3.8.3/zappar-cv.zip](https://libs.zappar.com/zappar-cv/3.8.3/zappar-cv.zip)
package/lib/permission.js CHANGED
@@ -16,6 +16,7 @@ let _permissionGrantedCamera = false;
16
16
  let _permissionGrantedMotion = false;
17
17
  let _permissionDeniedCamera = false;
18
18
  let _permissionDeniedMotion = false;
19
+ let _hadOneSuccessfulActivation = false;
19
20
  if (!window.DeviceOrientationEvent || !window.DeviceOrientationEvent.requestPermission) {
20
21
  _permissionGrantedMotion = true;
21
22
  }
@@ -166,6 +167,7 @@ export function permissionRequestUI(options) {
166
167
  return false;
167
168
  }
168
169
  if (permissionGrantedAll()) {
170
+ _hadOneSuccessfulActivation = true;
169
171
  return true;
170
172
  }
171
173
  }
@@ -173,7 +175,7 @@ export function permissionRequestUI(options) {
173
175
  });
174
176
  }
175
177
  try {
176
- if (_isWebXRSupported && !((_d = navigator.userActivation) === null || _d === void 0 ? void 0 : _d.isActive))
178
+ if (_isWebXRSupported && (!((_d = navigator.userActivation) === null || _d === void 0 ? void 0 : _d.isActive) || _hadOneSuccessfulActivation))
177
179
  throw new Error("WebXR - need user interaction");
178
180
  return yield attempt();
179
181
  }
@@ -1 +1 @@
1
- export declare const VERSION = "3.8.0-beta.2";
1
+ export declare const VERSION = "3.8.3";
@@ -52,6 +52,7 @@ export declare class WebXRCameraSource extends Source {
52
52
  private _planeHitTestSource;
53
53
  private _customAnchorSetRequests;
54
54
  private _customAnchors;
55
+ private _groundH;
55
56
  static IsSupported(): boolean;
56
57
  constructor(_impl: zappar_camera_source_t, _pipeline: zappar_pipeline_t);
57
58
  destroy(): void;
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "3.8.0-beta.2";
1
+ export declare const VERSION = "3.8.3";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "3.8.0-beta.2";
1
+ export const VERSION = "3.8.3";
@@ -52,6 +52,7 @@ export declare class WebXRCameraSource extends Source {
52
52
  private _planeHitTestSource;
53
53
  private _customAnchorSetRequests;
54
54
  private _customAnchors;
55
+ private _groundH;
55
56
  static IsSupported(): boolean;
56
57
  constructor(_impl: zappar_camera_source_t, _pipeline: zappar_pipeline_t);
57
58
  destroy(): void;
@@ -26,6 +26,7 @@ for (let i = 0; i < 32; i++) {
26
26
  const _quat = quat.create();
27
27
  const _trans = vec3.create();
28
28
  const _up = vec3.fromValues(0, 1, 0);
29
+ const _ground = mat4.create();
29
30
  export class WebXRCameraSource extends Source {
30
31
  constructor(_impl, _pipeline) {
31
32
  super();
@@ -55,7 +56,7 @@ export class WebXRCameraSource extends Source {
55
56
  this._customAnchorSetRequests = new Map();
56
57
  this._customAnchors = new Map();
57
58
  this._onXRFrame = (time, frame) => {
58
- var _a, _b, _c, _d, _e;
59
+ var _a, _b, _c, _d, _e, _f;
59
60
  if (this._isPaused)
60
61
  return;
61
62
  (_a = this._xrSession) === null || _a === void 0 ? void 0 : _a.requestAnimationFrame(this._onXRFrame);
@@ -203,6 +204,16 @@ export class WebXRCameraSource extends Source {
203
204
  continue; // skip vertical planes if not requested
204
205
  }
205
206
  if (poseInCamera) {
207
+ // Update ground height to the lowest detected plane
208
+ if (localPose) {
209
+ const planeY = worldPose.transform.matrix[13];
210
+ const viewerHeight = localPose.transform.matrix[13] - planeY;
211
+ if (viewerHeight > 0.8 && viewerHeight < 1.8) {
212
+ if (this._groundH === undefined || planeY < this._groundH) {
213
+ this._groundH = planeY;
214
+ }
215
+ }
216
+ }
206
217
  plane_anchors.push({
207
218
  id: "plane-" + plane_anchors.length,
208
219
  horizontal: true,
@@ -236,11 +247,15 @@ export class WebXRCameraSource extends Source {
236
247
  }
237
248
  else {
238
249
  const world_pose = rotateMatrix(localPose.transform.inverse.matrix, rot);
250
+ let ground_pose = mat4.create();
251
+ mat4.fromTranslation(_ground, [0, (_f = this._groundH) !== null && _f !== void 0 ? _f : -1.5, 0]);
252
+ mat4.multiply(ground_pose, localPose.transform.inverse.matrix, _ground);
253
+ ground_pose = rotateMatrix(ground_pose, rot);
239
254
  this._latestWtData = {
240
255
  world_anchor_status: anchor_status_t.ANCHOR_STATUS_TRACKING,
241
256
  world_anchor_pose: world_pose,
242
- ground_anchor_pose: mat4.create(),
243
- ground_anchor_status: anchor_status_t.ANCHOR_STATUS_INITIALIZING,
257
+ ground_anchor_pose: ground_pose,
258
+ ground_anchor_status: this._groundH === undefined ? anchor_status_t.ANCHOR_STATUS_INITIALIZING : anchor_status_t.ANCHOR_STATUS_TRACKING,
244
259
  plane_anchors,
245
260
  custom_anchors,
246
261
  quality: world_tracker_quality_t.WORLD_TRACKER_QUALITY_GOOD,
@@ -255,6 +270,7 @@ export class WebXRCameraSource extends Source {
255
270
  this._customAnchorSetRequests.clear();
256
271
  this._customAnchors.clear();
257
272
  this._planeHitTestSource = null;
273
+ this._groundH = undefined;
258
274
  if (this._isPaused)
259
275
  return;
260
276
  if (this._permissionRequestShown)
@@ -445,8 +461,11 @@ export class WebXRCameraSource extends Source {
445
461
  this._xrSession = session;
446
462
  this._xrLocalSpace = refSpace;
447
463
  this._xrGlBinding = new XRWebGLBinding(session, this._offscreenContext);
464
+ // Create a reference space that is a ray pointing down [0, -0.3] in normalized device coordinates
465
+ const offsetRay = new XRRay(new DOMPointReadOnly(0, 0, 0), { x: 0, y: -0.3, z: -1, w: 0 });
448
466
  (_c = (_b = session.requestHitTestSource) === null || _b === void 0 ? void 0 : _b.call(session, {
449
467
  space: this._xrViewerSpace,
468
+ offsetRay: offsetRay,
450
469
  entityTypes: ['plane']
451
470
  })) === null || _c === void 0 ? void 0 : _c.then((hitTestSource) => {
452
471
  this._planeHitTestSource = hitTestSource;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zappar/zappar-cv",
3
- "version": "3.8.0-beta.2",
3
+ "version": "3.8.3",
4
4
  "description": "Zappar's core computer vision library, supporting image, face and world tracking.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",