@zappar/zappar-cv 3.0.1-alpha.7 → 3.0.1-beta.0

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 (55) hide show
  1. package/README.md +2 -2
  2. package/lib/additional.d.ts +3 -1
  3. package/lib/deserializer.d.ts +5 -1
  4. package/lib/deserializer.js +12 -0
  5. package/lib/direct.js +1 -1
  6. package/lib/drawaxis.d.ts +2 -0
  7. package/lib/drawaxis.js +137 -0
  8. package/lib/drawgrid.js +5 -2
  9. package/lib/drawpoints.d.ts +1 -0
  10. package/lib/drawpoints.js +2 -2
  11. package/lib/drawpointswithtype.d.ts +13 -0
  12. package/lib/drawpointswithtype.js +190 -0
  13. package/lib/drawpolygon.d.ts +5 -0
  14. package/lib/drawpolygon.js +94 -0
  15. package/lib/gen/zappar-bridge.d.ts +44 -11
  16. package/lib/gen/zappar-bridge.js +3 -0
  17. package/lib/gen/zappar-client.d.ts +1 -0
  18. package/lib/gen/zappar-client.js +347 -47
  19. package/lib/gen/zappar-cwrap.js +251 -41
  20. package/lib/gen/zappar-native.d.ts +56 -13
  21. package/lib/gen/zappar-native.js +23 -1
  22. package/lib/gen/zappar-server.d.ts +3 -0
  23. package/lib/gen/zappar-server.js +166 -21
  24. package/lib/gen/zappar.d.ts +51 -13
  25. package/lib/gen/zappar.js +3 -0
  26. package/lib/html-element-source.d.ts +4 -0
  27. package/lib/html-element-source.js +30 -2
  28. package/lib/index.d.ts +1 -1
  29. package/lib/index.js +1 -1
  30. package/lib/mstp-camera-source.js +2 -1
  31. package/lib/native.js +59 -4
  32. package/lib/permission.js +35 -9
  33. package/lib/pipeline.d.ts +1 -1
  34. package/lib/pipeline.js +3 -2
  35. package/lib/sequencesource.js +1 -1
  36. package/lib/serializer.d.ts +5 -1
  37. package/lib/serializer.js +4 -0
  38. package/lib/tr.js +1 -1
  39. package/lib/version.d.ts +1 -1
  40. package/lib/version.js +1 -1
  41. package/lib/worker-client.js +4 -1
  42. package/lib/worker-imagebitmap.js +1 -1
  43. package/lib/worker-server.d.ts +1 -1
  44. package/lib/worker-server.js +5 -5
  45. package/lib/worker.js +1 -1
  46. package/lib/workerinterface.d.ts +1 -0
  47. package/lib/zappar-cv.js +1 -180
  48. package/lib/zappar-cv.wasm +0 -0
  49. package/package.json +1 -1
  50. package/umd/751.zappar-cv.js +1 -1
  51. package/umd/867.zappar-cv.js +1 -1
  52. package/umd/c8e05439176ea756192a.wasm +0 -0
  53. package/umd/zappar-cv.js +1 -1
  54. package/umd/zappar-cv.worker.js +1 -1
  55. package/umd/7e63bec626d6ccda2134.wasm +0 -0
package/lib/permission.js CHANGED
@@ -82,6 +82,7 @@ export function permissionRequestUI() {
82
82
  }
83
83
  let div = document.createElement("div");
84
84
  div.classList.add("zappar-permission-request");
85
+ div.classList.add("zappar-permission-request-without-button");
85
86
  div.innerHTML = `
86
87
  <style>
87
88
  .zappar-permission-request {
@@ -99,7 +100,21 @@ export function permissionRequestUI() {
99
100
  align-items: center;
100
101
  justify-content: center;
101
102
  }
103
+ .zappar-permission-request-without-button {
104
+ justify-content: flex-start;
105
+ }
106
+
107
+ .zappar-permission-request-without-button #zappar-permission-request-button {
108
+ display: none;
109
+ }
110
+
111
+ .zappar-permission-request-without-button .zappar-inner {
112
+ max-width: 300px;
113
+ }
114
+
102
115
  .zappar-inner {
116
+ margin-top: 30%;
117
+ margin-bottom: 30%;
103
118
  max-width: 400px;
104
119
  text-align: center;
105
120
  }
@@ -127,24 +142,35 @@ export function permissionRequestUI() {
127
142
  </div>
128
143
  `;
129
144
  document.body.append(div);
130
- let button = div.querySelector("#zappar-permission-request-button");
131
- return yield new Promise(resolve => {
132
- button === null || button === void 0 ? void 0 : button.addEventListener("click", () => __awaiter(this, void 0, void 0, function* () {
145
+ function attempt() {
146
+ return __awaiter(this, void 0, void 0, function* () {
133
147
  yield permissionRequestAll();
134
148
  div.remove();
135
149
  while (true) {
136
150
  yield nextFrame();
137
151
  if (permissionDeniedAny()) {
138
- resolve(false);
139
- return;
152
+ return false;
140
153
  }
141
154
  if (permissionGrantedAll()) {
142
- resolve(true);
143
- return;
155
+ return true;
144
156
  }
145
157
  }
158
+ return false;
159
+ });
160
+ }
161
+ try {
162
+ return yield attempt();
163
+ }
164
+ catch (err) {
165
+ // We may need a user interaction
166
+ div.classList.remove("zappar-permission-request-without-button");
167
+ let button = div.querySelector("#zappar-permission-request-button");
168
+ return yield new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
169
+ button === null || button === void 0 ? void 0 : button.addEventListener('click', () => __awaiter(this, void 0, void 0, function* () {
170
+ resolve(yield attempt());
171
+ }));
146
172
  }));
147
- });
173
+ }
148
174
  });
149
175
  }
150
176
  function nextFrame() {
@@ -254,7 +280,7 @@ function permissionDeniedUIChrome() {
254
280
  </style>
255
281
  <div class="zappar-inner">
256
282
  <div class="zappar-title">Permission is Needed</div>
257
- <div class="zappar-text">Permission to access your device's camera and motion sensors is necessary for this experience.<br/><br/>To grant access, please tap the ! button in the address bar of your browser, then "Site settings", and finally "Clear and reset". You can then reload the page to try again.</div>
283
+ <div class="zappar-text">Permission to access your device's camera and motion sensors is necessary for this experience.<br/><br/>To grant access, please tap the <svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 -960 960 960" width="16px" fill="white"><path d="M696-144q-60.48 0-102.24-41.76T552-288q0-60.48 41.76-102.24T696-432q60.48 0 102.24 41.76T840-288q0 60.48-41.76 102.24T696-144Zm.12-72Q726-216 747-237.12q21-21.12 21-51T746.88-339q-21.12-21-51-21T645-338.88q-21 21.12-21 51T645.12-237q21.12 21 51 21ZM168-252v-72h312v72H168Zm96-276q-60.48 0-102.24-41.76T120-672q0-60.48 41.76-102.24T264-816q60.48 0 102.24 41.76T408-672q0 60.48-41.76 102.24T264-528Zm.12-72Q294-600 315-621.12q21-21.12 21-51T314.88-723q-21.12-21-51-21T213-722.88q-21 21.12-21 51T213.12-621q21.12 21 51 21ZM480-636v-72h312v72H480Zm216 348ZM264-672Z"/></svg> button in the address bar of your browser, then "Permissions", and finally "Reset permissions". You can then reload the page to try again.</div>
258
284
  <button id="zappar-permission-reload-button">Reload</button>
259
285
  </div>
260
286
  `;
package/lib/pipeline.d.ts CHANGED
@@ -78,6 +78,6 @@ export declare class Pipeline {
78
78
  sendCameraProfileToWorker(source: zappar_camera_source_t, profile: camera_profile_t): void;
79
79
  sendCameraToScreenRotationToWorker(rot: number): void;
80
80
  sendImageBitmapToWorker(img: ImageBitmap, rot: number, userFacing: boolean, tokenId: number, cameraModel: Float32Array, cameraToDevice: Float32Array, cp: camera_profile_t): void;
81
- sendDataToWorker(data: ArrayBuffer, token: number, width: number, height: number, userFacing: boolean, cameraToDevice: Float32Array, cameraModel: Float32Array): void;
81
+ sendDataToWorker(data: ArrayBuffer, token: number, width: number, height: number, userFacing: boolean, cameraToDevice: Float32Array, cameraModel: Float32Array, captureTime: number): void;
82
82
  }
83
83
  export declare function applyScreenCounterRotation(info: CameraFrameInfo | undefined, inp: Float32Array): Float32Array;
package/lib/pipeline.js CHANGED
@@ -479,14 +479,15 @@ export class Pipeline {
479
479
  };
480
480
  this._mgr.postOutgoingMessage(msg, [img]);
481
481
  }
482
- sendDataToWorker(data, token, width, height, userFacing, cameraToDevice, cameraModel) {
482
+ sendDataToWorker(data, token, width, height, userFacing, cameraToDevice, cameraModel, captureTime) {
483
483
  let msg = {
484
484
  d: data,
485
485
  p: this._impl,
486
486
  width, height, token, userFacing,
487
487
  c2d: cameraToDevice,
488
488
  cm: cameraModel,
489
- t: "cameraFrameC2S"
489
+ t: "cameraFrameC2S",
490
+ captureTime
490
491
  };
491
492
  this._mgr.postOutgoingMessage(msg, [data]);
492
493
  }
@@ -97,7 +97,7 @@ export class SequenceSource extends Source {
97
97
  // updates will be one frame later
98
98
  this._submitMotionUpdates(pipeline);
99
99
  const token = pipeline.registerToken(info);
100
- pipeline.sendDataToWorker(info.data || new ArrayBuffer(0), token, info.dataWidth, info.dataHeight, info.userFacing, info.cameraToDevice, info.cameraModel);
100
+ pipeline.sendDataToWorker(info.data || new ArrayBuffer(0), token, info.dataWidth, info.dataHeight, info.userFacing, info.cameraToDevice, info.cameraModel, -1);
101
101
  }
102
102
  destroy() {
103
103
  byId.delete(this._impl);
@@ -1,4 +1,4 @@
1
- import { barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t } from "./gen/zappar-native";
1
+ import { barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, transform_orientation_t, log_level_t, plane_orientation_t, anchor_status_t } from "./gen/zappar-native";
2
2
  export interface MessageAppender {
3
3
  int: (i: number) => void;
4
4
  bool: (i: boolean) => void;
@@ -8,6 +8,7 @@ export interface MessageAppender {
8
8
  type: (t: number) => void;
9
9
  matrix4x4: (a: Float32Array) => void;
10
10
  matrix3x3: (a: Float32Array) => void;
11
+ ucharArray: (a: Uint8Array) => void;
11
12
  floatArray: (a: Float32Array) => void;
12
13
  cameraModel: (a: Float32Array) => void;
13
14
  identityCoefficients: (a: Float32Array) => void;
@@ -16,6 +17,9 @@ export interface MessageAppender {
16
17
  barcodeFormat: (f: barcode_format_t) => void;
17
18
  faceLandmarkName: (f: face_landmark_name_t) => void;
18
19
  instantTrackerTransformOrientation: (f: instant_world_tracker_transform_orientation_t) => void;
20
+ transformOrientation: (f: transform_orientation_t) => void;
21
+ planeOrientation: (f: plane_orientation_t) => void;
22
+ anchorStatus: (f: anchor_status_t) => void;
19
23
  logLevel: (f: log_level_t) => void;
20
24
  }
21
25
  export declare class MessageSerializer {
package/lib/serializer.js CHANGED
@@ -23,6 +23,7 @@ export class MessageSerializer {
23
23
  matrix4x4: i => this.float32ArrayBuffer(i),
24
24
  matrix3x3: i => this.float32ArrayBuffer(i),
25
25
  floatArray: i => this.float32ArrayBuffer(i),
26
+ ucharArray: i => this.uint8ArrayBuffer(i),
26
27
  identityCoefficients: i => this.float32ArrayBuffer(i),
27
28
  expressionCoefficients: i => this.float32ArrayBuffer(i),
28
29
  cameraModel: i => this.float32ArrayBuffer(i),
@@ -30,6 +31,9 @@ export class MessageSerializer {
30
31
  barcodeFormat: i => this.int(i),
31
32
  faceLandmarkName: i => this.int(i),
32
33
  instantTrackerTransformOrientation: i => this.int(i),
34
+ transformOrientation: i => this.int(i),
35
+ planeOrientation: i => this.int(i),
36
+ anchorStatus: i => this.int(i),
33
37
  logLevel: i => this.int(i),
34
38
  };
35
39
  this._freeBufferPool.push(new ArrayBuffer(16));
package/lib/tr.js CHANGED
@@ -35,7 +35,7 @@ export function tr(str) {
35
35
  }
36
36
  switch (str) {
37
37
  case STRINGS.PermissionTitle: return "Almost there...";
38
- case STRINGS.PermissionDescription: return "In order to provide this augmented reality experience, we need access to your device's camera and motion sensors.";
38
+ case STRINGS.PermissionDescription: return "In order to provide this immersive experience, we need access to your device's camera and motion sensors.";
39
39
  case STRINGS.PermissionButton: return "Grant Access";
40
40
  }
41
41
  return "";
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "3.0.1-alpha.7";
1
+ export declare const VERSION = "3.0.1-beta.0";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "3.0.1-alpha.7";
1
+ export const VERSION = "3.0.1-beta.0";
@@ -7,8 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ var _a;
10
11
  import { MsgManager } from "./messages";
11
12
  export let messageManager = new MsgManager();
13
+ const params = new URLSearchParams(window.location.search);
14
+ const shouldRecordData = parseInt((_a = params.get('_zrecorddata')) !== null && _a !== void 0 ? _a : '0');
12
15
  const wasmModule = (() => __awaiter(void 0, void 0, void 0, function* () {
13
16
  const response = yield fetch(new URL("./zappar-cv.wasm", import.meta.url).toString());
14
17
  const module = yield WebAssembly.compileStreaming(response);
@@ -22,7 +25,7 @@ export function launchWorker(worker) {
22
25
  t: "wasm",
23
26
  url: new URL("./zappar-cv.wasm", import.meta.url).toString(),
24
27
  module: yield wasmModule,
25
- shouldRecordData: window.location.href.indexOf("_zrecorddata") >= 0
28
+ shouldRecordData
26
29
  });
27
30
  yield waitForLoad(worker);
28
31
  function sendOutgoing() {
@@ -53,7 +53,7 @@ export function handleImageBitmap(m, r, server, mgr) {
53
53
  mgr.postOutgoingMessage(msg, [m.i]);
54
54
  let pipeline = server._pipeline_by_instance.get(m.p);
55
55
  if (pipeline) {
56
- r.pipeline_camera_frame_submit(pipeline, pixels, info.dataWidth, info.dataHeight, m.tokenId, m.cameraToDevice, m.cameraModel, info.userFacing);
56
+ r.pipeline_camera_frame_submit(pipeline, pixels, info.dataWidth, info.dataHeight, m.tokenId, m.cameraToDevice, m.cameraModel, info.userFacing, performance.now());
57
57
  r.pipeline_frame_update(pipeline);
58
58
  server.exploreState();
59
59
  }
@@ -1,3 +1,3 @@
1
1
  import { MsgManager } from "./messages";
2
2
  export declare let messageManager: MsgManager;
3
- export declare function launchWorkerServer(wasmUrl: string, module: WebAssembly.Module, shouldRecordData: boolean): Promise<void>;
3
+ export declare function launchWorkerServer(wasmUrl: string, module: WebAssembly.Module, shouldRecordData: number): Promise<void>;
@@ -39,8 +39,8 @@ export function launchWorkerServer(wasmUrl, module, shouldRecordData) {
39
39
  onRuntimeInitialized: () => {
40
40
  let r = getRuntimeObject(mod);
41
41
  const workerMessageAPI = getWorkerMessageAPI(mod);
42
- const dataDownloadAPI = shouldRecordData ? getDataDownloadAPI(mod) : undefined;
43
- dataDownloadAPI === null || dataDownloadAPI === void 0 ? void 0 : dataDownloadAPI.data_should_record_set(1); // Only happens if dataDownloadAPI is defined
42
+ const dataDownloadAPI = (shouldRecordData > 0) ? getDataDownloadAPI(mod) : undefined;
43
+ dataDownloadAPI === null || dataDownloadAPI === void 0 ? void 0 : dataDownloadAPI.data_should_record_set(shouldRecordData); // Only happens if dataDownloadAPI is defined
44
44
  let server = new zappar_server(r, (pipelineId, ab) => {
45
45
  messageManager.postOutgoingMessage({
46
46
  p: pipelineId,
@@ -64,7 +64,7 @@ export function launchWorkerServer(wasmUrl, module, shouldRecordData) {
64
64
  let pipeline = server._pipeline_by_instance.get(msgt.p);
65
65
  let att;
66
66
  if (pipeline) {
67
- r.pipeline_camera_frame_submit(pipeline, msgt.d, msgt.width, msgt.height, msgt.token, msgt.c2d, msgt.cm, msgt.userFacing);
67
+ r.pipeline_camera_frame_submit(pipeline, msgt.d, msgt.width, msgt.height, msgt.token, msgt.c2d, msgt.cm, msgt.userFacing, msgt.captureTime);
68
68
  r.pipeline_frame_update(pipeline);
69
69
  att = r.pipeline_camera_frame_device_attitude(pipeline);
70
70
  server.exploreState();
@@ -266,7 +266,7 @@ function consumeReader(mod, r, reader, p, userFacing, server, source, workerMess
266
266
  mat4.fromScaling(cameraToDeviceTransform, [-1, 1, -1]);
267
267
  else
268
268
  mat4.identity(cameraToDeviceTransform);
269
- let focalLength = 300.0 * dataWidth / 320.0;
269
+ let focalLength = 240.0 * dataWidth / 320.0;
270
270
  cameraModel[0] = focalLength;
271
271
  cameraModel[1] = focalLength;
272
272
  cameraModel[2] = dataWidth * 0.5;
@@ -288,7 +288,7 @@ function consumeReader(mod, r, reader, p, userFacing, server, source, workerMess
288
288
  const pipeline = server._pipeline_by_instance.get(p);
289
289
  if (pipeline) {
290
290
  try {
291
- r.pipeline_camera_frame_submit_raw_pointer(pipeline, streamDataBufferPointer, size, framePixelFormatFromFormat(frame.format), width, height, token, cameraToDeviceTransform, latestCameraToScreenRotation, cameraModel, userFacing, (_b = frame.timestamp) !== null && _b !== void 0 ? _b : -1, downSample);
291
+ r.pipeline_camera_frame_submit_raw_pointer(pipeline, streamDataBufferPointer, size, framePixelFormatFromFormat(frame.format), width, height, token, cameraToDeviceTransform, latestCameraToScreenRotation, cameraModel, userFacing, ((_b = frame.timestamp) !== null && _b !== void 0 ? _b : -1) * 1e-6, downSample);
292
292
  handleMessages(mod, workerMessageAPI);
293
293
  if (dataDownloadAPI)
294
294
  handleDataDownload(mod, dataDownloadAPI);
package/lib/worker.js CHANGED
@@ -10,7 +10,7 @@ let launchHandler = (evt) => {
10
10
  var _a;
11
11
  if (evt && evt.data && evt.data.t === "wasm") {
12
12
  let url = location.href.startsWith("blob") ? evt.data.url : new URL("./zappar-cv.wasm", import.meta.url).toString();
13
- launchWorkerServer(url, evt.data.module, (_a = evt.data.shouldRecordData) !== null && _a !== void 0 ? _a : false);
13
+ launchWorkerServer(url, evt.data.module, (_a = evt.data.shouldRecordData) !== null && _a !== void 0 ? _a : 0);
14
14
  ctx.removeEventListener("message", launchHandler);
15
15
  }
16
16
  };
@@ -11,6 +11,7 @@ export interface CameraFrameC2S {
11
11
  token: number;
12
12
  width: number;
13
13
  height: number;
14
+ captureTime: number;
14
15
  }
15
16
  export interface CameraFrameReturnS2C {
16
17
  t: "cameraFrameRecycleS2C";