@zappar/zappar-cv 3.0.0-beta.7 → 3.0.1-alpha.1

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 (46) hide show
  1. package/README.md +2 -2
  2. package/lib/additional.d.ts +0 -3
  3. package/lib/camera-source.js +8 -4
  4. package/lib/ceres-worker.d.ts +1 -0
  5. package/lib/ceres-worker.js +67 -0
  6. package/lib/direct.js +3 -1
  7. package/lib/gen/zappar-client.d.ts +2 -2
  8. package/lib/gen/zappar-client.js +5 -0
  9. package/lib/gen/zappar-cwrap.js +4 -31
  10. package/lib/gen/zappar-native.d.ts +1 -5
  11. package/lib/gen/zappar.d.ts +0 -1
  12. package/lib/html-element-source.js +0 -1
  13. package/lib/imagetracker.d.ts +2 -3
  14. package/lib/index.d.ts +0 -1
  15. package/lib/mstp-camera-source.d.ts +9 -0
  16. package/lib/mstp-camera-source.js +79 -6
  17. package/lib/native.js +8 -18
  18. package/lib/pipeline.d.ts +3 -11
  19. package/lib/pipeline.js +3 -72
  20. package/lib/source.d.ts +0 -1
  21. package/lib/version.d.ts +1 -1
  22. package/lib/version.js +1 -1
  23. package/lib/worker-client.d.ts +1 -0
  24. package/lib/worker-client.js +19 -1
  25. package/lib/worker-messages.d.ts +10 -0
  26. package/lib/worker-messages.js +10 -0
  27. package/lib/worker-server.d.ts +1 -1
  28. package/lib/worker-server.js +52 -56
  29. package/lib/worker.js +1 -1
  30. package/lib/workerinterface.d.ts +0 -16
  31. package/lib/zappar-cv.js +177 -134
  32. package/lib/zappar-cv.wasm +0 -0
  33. package/package.json +4 -3
  34. package/umd/169.zappar-cv.js +1 -1
  35. package/umd/25.zappar-cv.js +1 -0
  36. package/umd/429.zappar-cv.js +1 -0
  37. package/umd/501114eb92cddf5f56fe.wasm +0 -0
  38. package/umd/867.zappar-cv.js +1 -0
  39. package/umd/zappar-cv.js +1 -1
  40. package/umd/zappar-cv.worker.js +1 -1
  41. package/lib/camera-frame-data.d.ts +0 -5
  42. package/lib/camera-frame-data.js +0 -1
  43. package/lib/gen/zappar-bridge.d.ts +0 -120
  44. package/lib/gen/zappar-bridge.js +0 -7
  45. package/umd/51b1854609f16d933fe2.wasm +0 -0
  46. package/umd/56.zappar-cv.js +0 -1
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.0.0-beta.7/zappar-cv.js"></script>
21
+ <script src="https://libs.zappar.com/zappar-cv/3.0.1-alpha.1/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.0.0-beta.7/zappar-cv.zip](https://libs.zappar.com/zappar-cv/3.0.0-beta.7/zappar-cv.zip)
25
+ [https://libs.zappar.com/zappar-cv/3.0.1-alpha.1/zappar-cv.zip](https://libs.zappar.com/zappar-cv/3.0.1-alpha.1/zappar-cv.zip)
@@ -1,4 +1,3 @@
1
- import { CameraFrameData } from "./camera-frame-data";
2
1
  import { zappar_face_mesh_t, zappar_face_tracker_t, zappar_pipeline_t, zappar_image_tracker_t, zappar_sequence_source_t } from "./gen/zappar";
3
2
  export declare type zappar_html_element_source_t = number & {
4
3
  _: 'zappar_html_element_source_t';
@@ -9,8 +8,6 @@ export interface Additional {
9
8
  pipeline_draw_face(pipeline: zappar_pipeline_t, projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, o: zappar_face_mesh_t): void;
10
9
  pipeline_draw_image_target_preview(pipeline: zappar_pipeline_t, projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, o: zappar_image_tracker_t, indx: number): void;
11
10
  pipeline_draw_face_project(pipeline: zappar_pipeline_t, drawwMatrix: Float32Array, vertices: Float32Array, uvMatrix: Float32Array, uvs: Float32Array, indices: Uint16Array, texture: WebGLTexture): void;
12
- pipeline_camera_frame_data_raw_enabled_set(pipeline: zappar_pipeline_t, enabled: boolean): void;
13
- pipeline_camera_frame_data_raw(pipeline: zappar_pipeline_t): Promise<CameraFrameData | undefined>;
14
11
  draw_plane(gl: WebGLRenderingContext, projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, texture: string): void;
15
12
  image_tracker_target_image(o: zappar_image_tracker_t, indx: number): HTMLImageElement | undefined;
16
13
  face_mesh_load_default(o: zappar_face_mesh_t): Promise<void>;
@@ -35,11 +35,15 @@ export class CameraSource extends HTMLElementSource {
35
35
  if (!pipeline)
36
36
  return;
37
37
  let timeStamp = (ev.timeStamp !== undefined && ev.timeStamp !== null) ? ev.timeStamp : performance.now();
38
- let interval = ev.interval * profile.intervalMultiplier;
39
- if (this._lastTimestamp > -1 && !profile.trustSensorIntervals) {
40
- interval = Math.max(timeStamp - this._lastTimestamp, interval);
38
+ const interval = ev.interval * profile.intervalMultiplier;
39
+ if (profile.trustSensorIntervals) {
40
+ if (this._lastTimestamp === -1)
41
+ this._lastTimestamp = timeStamp;
42
+ else {
43
+ this._lastTimestamp += interval;
44
+ timeStamp = this._lastTimestamp;
45
+ }
41
46
  }
42
- this._lastTimestamp = timeStamp;
43
47
  if (ev.acceleration !== null &&
44
48
  ev.acceleration.x !== null &&
45
49
  ev.acceleration.y !== null &&
@@ -0,0 +1 @@
1
+ export declare function launchCeresWorker(wasmUrl: string, module: WebAssembly.Module, port: MessagePort): Promise<void>;
@@ -0,0 +1,67 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getWorkerMessageAPI } from "./worker-messages";
11
+ import * as ZNM from "./zappar-cv";
12
+ const ctx = self;
13
+ let launchHandler = (evt) => {
14
+ if (evt && evt.data && evt.data.t === "wasm") {
15
+ let url = location.href.startsWith("blob") ? evt.data.url : new URL("./zappar-cv.wasm", import.meta.url).toString();
16
+ launchCeresWorker(url, evt.data.module, evt.data.port);
17
+ ctx.removeEventListener("message", launchHandler);
18
+ }
19
+ };
20
+ ctx.addEventListener("message", launchHandler);
21
+ export function launchCeresWorker(wasmUrl, module, port) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ let mod = ZNM.default({
24
+ locateFile: (path, prefix) => {
25
+ if (path.endsWith("zappar-cv.wasm")) {
26
+ return wasmUrl;
27
+ }
28
+ return prefix + path;
29
+ },
30
+ instantiateWasm: (imports, successCallback) => {
31
+ const instance = new WebAssembly.Instance(module, imports);
32
+ successCallback(instance);
33
+ return instance.exports;
34
+ },
35
+ onRuntimeInitialized: () => {
36
+ const ceres_worker = mod.cwrap('ceres_worker', null, []);
37
+ const messageAPI = getWorkerMessageAPI(mod);
38
+ port.addEventListener('message', evt => {
39
+ if (evt.data.t !== 'msgsend')
40
+ return;
41
+ const data = evt.data.data;
42
+ const reference = evt.data.reference;
43
+ const ptr = mod._malloc(data.byteLength);
44
+ mod.HEAPU8.set(data, ptr);
45
+ messageAPI.worker_message_receive(reference, data.byteLength, ptr);
46
+ mod._free(ptr);
47
+ ceres_worker();
48
+ const toSend = messageAPI.worker_message_send_count();
49
+ for (let i = 0; i < toSend; i++) {
50
+ const reference = messageAPI.worker_message_send_reference(i);
51
+ const dataSize = messageAPI.worker_message_send_data_size(i);
52
+ const dataPtr = messageAPI.worker_message_send_data(i);
53
+ const data = mod.HEAPU8.slice(dataPtr, dataPtr + dataSize);
54
+ port.postMessage({
55
+ t: 'msgrec',
56
+ data,
57
+ reference
58
+ }, [data.buffer]);
59
+ }
60
+ messageAPI.worker_message_send_clear();
61
+ });
62
+ port.start();
63
+ }
64
+ });
65
+ });
66
+ }
67
+ ;
package/lib/direct.js CHANGED
@@ -13,6 +13,8 @@ import { messageManager as workerMessageManager } from "./worker-server";
13
13
  export let messageManager = new MsgManager();
14
14
  export function launchWorker(wasm) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
+ const response = yield fetch(new URL("./zappar-cv.wasm", import.meta.url).toString());
17
+ const module = yield WebAssembly.compileStreaming(response);
16
18
  messageManager.onOutgoingMessage.bind(() => {
17
19
  let msgs = messageManager.getOutgoingMessages();
18
20
  for (let msg of msgs)
@@ -23,6 +25,6 @@ export function launchWorker(wasm) {
23
25
  for (let msg of msgs)
24
26
  messageManager.postIncomingMessage(msg.msg);
25
27
  });
26
- launchWorkerServer(wasm);
28
+ launchWorkerServer(wasm, module);
27
29
  });
28
30
  }
@@ -1,6 +1,6 @@
1
1
  import { MessageSerializer } from "../serializer";
2
2
  import { MessageDeserializer } from "../deserializer";
3
- import { zappar } from "./zappar-bridge";
3
+ import { zappar_cwrap } from "./zappar-native";
4
4
  export declare class zappar_client {
5
5
  private _messageSender;
6
6
  constructor(_messageSender: (ab: ArrayBuffer) => void);
@@ -18,6 +18,6 @@ export declare class zappar_client {
18
18
  private _barcode_finder_state_by_instance;
19
19
  private _instant_world_tracker_state_by_instance;
20
20
  private _world_tracker_state_by_instance;
21
- impl: zappar;
21
+ impl: zappar_cwrap;
22
22
  processMessages(a: ArrayBuffer): void;
23
23
  }
@@ -103,6 +103,11 @@ export class zappar_client {
103
103
  m.bool(user_facing);
104
104
  });
105
105
  },
106
+ pipeline_camera_frame_submit_raw_pointer: (o, data, dataLength, format, width, height, user_data, camera_to_device_transform, rotation, camera_model, user_facing, timestamp) => {
107
+ let s = this._pipeline_state_by_instance.get(o);
108
+ if (!s)
109
+ throw new Error("This object has been destroyed");
110
+ },
106
111
  pipeline_camera_frame_camera_attitude: (o) => {
107
112
  let s = this._pipeline_state_by_instance.get(o);
108
113
  if (!s)
@@ -8,18 +8,6 @@ export function getRuntimeObject(mod) {
8
8
  ]);
9
9
  let pipeline_create_wrapped = mod.cwrap("zappar_pipeline_create", "number", []);
10
10
  let pipeline_destroy_wrapped = mod.cwrap("zappar_pipeline_destroy", null, ["number"]);
11
- let pipeline_camera_frame_data_raw_wrapped = mod.cwrap("zappar_pipeline_camera_frame_data_raw", "number", [
12
- "number"
13
- ]);
14
- let pipeline_camera_frame_data_raw_size_wrapped = mod.cwrap("zappar_pipeline_camera_frame_data_raw_size", "number", [
15
- "number"
16
- ]);
17
- let pipeline_camera_frame_data_raw_width_wrapped = mod.cwrap("zappar_pipeline_camera_frame_data_raw_width", "number", [
18
- "number"
19
- ]);
20
- let pipeline_camera_frame_data_raw_height_wrapped = mod.cwrap("zappar_pipeline_camera_frame_data_raw_height", "number", [
21
- "number"
22
- ]);
23
11
  let pipeline_frame_update_wrapped = mod.cwrap("zappar_pipeline_frame_update", null, [
24
12
  "number"
25
13
  ]);
@@ -38,7 +26,7 @@ export function getRuntimeObject(mod) {
38
26
  ]);
39
27
  let pipeline_camera_frame_submit_raw_pointer_wrapped = mod.cwrap("zappar_pipeline_camera_frame_submit_raw_pointer", null, [
40
28
  "number",
41
- "number", "number", "number", "number", "number", "number", "number", "number", "number", "number"
29
+ "number", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number"
42
30
  ]);
43
31
  let pipeline_camera_frame_camera_attitude_wrapped = mod.cwrap("zappar_pipeline_camera_frame_camera_attitude", "number", [
44
32
  "number"
@@ -269,22 +257,6 @@ export function getRuntimeObject(mod) {
269
257
  pipeline_destroy: () => {
270
258
  pipeline_destroy_wrapped();
271
259
  },
272
- pipeline_camera_frame_data_raw: (o) => {
273
- let ret = pipeline_camera_frame_data_raw_wrapped(o);
274
- return ret;
275
- },
276
- pipeline_camera_frame_data_raw_size: (o) => {
277
- let ret = pipeline_camera_frame_data_raw_size_wrapped(o);
278
- return ret;
279
- },
280
- pipeline_camera_frame_data_raw_width: (o) => {
281
- let ret = pipeline_camera_frame_data_raw_width_wrapped(o);
282
- return ret;
283
- },
284
- pipeline_camera_frame_data_raw_height: (o) => {
285
- let ret = pipeline_camera_frame_data_raw_height_wrapped(o);
286
- return ret;
287
- },
288
260
  pipeline_frame_update: (o) => {
289
261
  let ret = pipeline_frame_update_wrapped(o);
290
262
  return ret;
@@ -324,7 +296,7 @@ export function getRuntimeObject(mod) {
324
296
  let ret = pipeline_camera_frame_submit_wrapped(o, arg_data, arg_len_data, arg_width, arg_height, arg_user_data, arg_camera_to_device_transform, arg_camera_model, arg_user_facing);
325
297
  return ret;
326
298
  },
327
- pipeline_camera_frame_submit_raw_pointer: (o, data, dataLength, format, width, height, user_data, camera_to_device_transform, rotation, camera_model, user_facing) => {
299
+ pipeline_camera_frame_submit_raw_pointer: (o, data, dataLength, format, width, height, user_data, camera_to_device_transform, rotation, camera_model, user_facing, timestamp) => {
328
300
  let arg_data = data;
329
301
  let arg_dataLength = dataLength;
330
302
  let arg_format = format;
@@ -337,7 +309,8 @@ export function getRuntimeObject(mod) {
337
309
  let arg_camera_model = getFloatDataArrayForArgIndex(8, camera_model.byteLength);
338
310
  mod.HEAPF32.set(camera_model, arg_camera_model / 4);
339
311
  let arg_user_facing = user_facing ? 1 : 0;
340
- let ret = pipeline_camera_frame_submit_raw_pointer_wrapped(o, arg_data, arg_dataLength, arg_format, arg_width, arg_height, arg_user_data, arg_camera_to_device_transform, arg_rotation, arg_camera_model, arg_user_facing);
312
+ let arg_timestamp = timestamp;
313
+ let ret = pipeline_camera_frame_submit_raw_pointer_wrapped(o, arg_data, arg_dataLength, arg_format, arg_width, arg_height, arg_user_data, arg_camera_to_device_transform, arg_rotation, arg_camera_model, arg_user_facing, arg_timestamp);
341
314
  return ret;
342
315
  },
343
316
  pipeline_camera_frame_camera_attitude: (o) => {
@@ -102,16 +102,12 @@ export interface zappar_cwrap {
102
102
  analytics_project_id_set(id: string, uid: string): void;
103
103
  pipeline_create(): zappar_pipeline_t;
104
104
  pipeline_destroy(o: zappar_pipeline_t): void;
105
- pipeline_camera_frame_data_raw(o: zappar_pipeline_t): number;
106
- pipeline_camera_frame_data_raw_size(o: zappar_pipeline_t): number;
107
- pipeline_camera_frame_data_raw_width(o: zappar_pipeline_t): number;
108
- pipeline_camera_frame_data_raw_height(o: zappar_pipeline_t): number;
109
105
  pipeline_frame_update(o: zappar_pipeline_t): void;
110
106
  pipeline_frame_number(o: zappar_pipeline_t): number;
111
107
  pipeline_camera_model(o: zappar_pipeline_t): Float32Array;
112
108
  pipeline_camera_frame_user_data(o: zappar_pipeline_t): number;
113
109
  pipeline_camera_frame_submit(o: zappar_pipeline_t, data: ArrayBuffer, width: number, height: number, user_data: number, camera_to_device_transform: Float32Array, camera_model: Float32Array, user_facing: boolean): void;
114
- pipeline_camera_frame_submit_raw_pointer(o: zappar_pipeline_t, data: number, dataLength: number, format: frame_pixel_format_t, width: number, height: number, user_data: number, camera_to_device_transform: Float32Array, rotation: number, camera_model: Float32Array, user_facing: boolean): void;
110
+ pipeline_camera_frame_submit_raw_pointer(o: zappar_pipeline_t, data: number, dataLength: number, format: frame_pixel_format_t, width: number, height: number, user_data: number, camera_to_device_transform: Float32Array, rotation: number, camera_model: Float32Array, user_facing: boolean, timestamp: number): void;
115
111
  pipeline_camera_frame_camera_attitude(o: zappar_pipeline_t): Float32Array;
116
112
  pipeline_camera_frame_device_attitude(o: zappar_pipeline_t): Float32Array;
117
113
  pipeline_motion_accelerometer_submit(o: zappar_pipeline_t, time: number, x: number, y: number, z: number): void;
@@ -49,7 +49,6 @@ export interface zappar {
49
49
  camera_user_facing(indx: number): boolean;
50
50
  projection_matrix_from_camera_model(model: Float32Array, renderWidth: number, renderHeight: number): Float32Array;
51
51
  projection_matrix_from_camera_model_ext(model: Float32Array, renderWidth: number, renderHeight: number, zNear: number, zFar: number): Float32Array;
52
- pose_from_raw(raw_pose: Float32Array, mirror: boolean): Float32Array;
53
52
  log_level(): log_level_t;
54
53
  log_level_set(level: log_level_t): void;
55
54
  permission_request_ui(): void;
@@ -89,7 +89,6 @@ export class HTMLElementSource extends Source {
89
89
  if (info) {
90
90
  let token = pipeline.registerToken(info);
91
91
  pipeline.sendDataToWorker(info.data || new ArrayBuffer(0), token, info.dataWidth, info.dataHeight, info.userFacing, info.cameraToDevice, info.cameraModel);
92
- info.data = undefined;
93
92
  }
94
93
  }
95
94
  catch (ex) {
@@ -1,6 +1,5 @@
1
1
  import { zappar_image_tracker_t, zappar_pipeline_t } from "./gen/zappar";
2
- import { zappar } from "./gen/zappar-bridge";
3
- import { image_target_type_t } from "./gen/zappar-native";
2
+ import { image_target_type_t, zappar_cwrap } from "./gen/zappar-native";
4
3
  interface PreviewInfo {
5
4
  compressed: Uint8Array;
6
5
  mimeType: string;
@@ -27,7 +26,7 @@ export declare class ImageTracker {
27
26
  private _client;
28
27
  private _impl;
29
28
  private _targets;
30
- static create(pipeline: zappar_pipeline_t, client: zappar): zappar_image_tracker_t;
29
+ static create(pipeline: zappar_pipeline_t, client: zappar_cwrap): zappar_image_tracker_t;
31
30
  static get(p: zappar_image_tracker_t): ImageTracker | undefined;
32
31
  private constructor();
33
32
  destroy(): void;
package/lib/index.d.ts CHANGED
@@ -3,5 +3,4 @@ import { Additional } from "./additional";
3
3
  import { Options } from "./options";
4
4
  export declare type Zappar = zappar & Additional;
5
5
  export declare function initialize(opts?: Options): Zappar;
6
- export { CameraFrameData } from './camera-frame-data';
7
6
  export { zappar_image_tracker_t, zappar_instant_world_tracker_t, zappar_world_tracker_t, zappar_barcode_finder_t, zappar_face_tracker_t, zappar_face_landmark_t, barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, zappar_face_mesh_t, zappar_pipeline_t, zappar_camera_source_t, zappar_sequence_source_t, image_target_type_t, world_tracker_quality_t } from "./gen/zappar";
@@ -11,6 +11,9 @@ export declare class MSTPCameraSource extends Source {
11
11
  private _isPaused;
12
12
  private _isUserFacing;
13
13
  private _cameraToScreenRotation;
14
+ private _accelerometer?;
15
+ private _linearAcceleration?;
16
+ private _gyroscope?;
14
17
  constructor(_impl: zappar_camera_source_t, _pipeline: zappar_pipeline_t, _deviceId: string);
15
18
  destroy(): void;
16
19
  private _stop;
@@ -26,6 +29,12 @@ export declare class MSTPCameraSource extends Source {
26
29
  private _deviceMotionListener;
27
30
  private _startDeviceOrientation;
28
31
  private _startDeviceMotion;
32
+ private _lastAccelerometerTimestamp;
33
+ private _accelerometerReading;
34
+ private _lastLinearAccelerationTimestamp;
35
+ private _linearAccelerationReading;
36
+ private _lastGyroscopeReading;
37
+ private _gyroscopeReading;
29
38
  private _stopDeviceMotion;
30
39
  uploadGL(info: CameraFrameInfo): void;
31
40
  }
@@ -31,12 +31,15 @@ export class MSTPCameraSource extends Source {
31
31
  if (!pipeline)
32
32
  return;
33
33
  let timeStamp = (ev.timeStamp !== undefined && ev.timeStamp !== null) ? ev.timeStamp : performance.now();
34
- let interval = ev.interval;
35
- if (this._lastTimestamp > -1 && !profile.trustSensorIntervals) {
36
- interval = Math.max(timeStamp - this._lastTimestamp, interval);
34
+ const interval = ev.interval * profile.intervalMultiplier;
35
+ if (profile.trustSensorIntervals) {
36
+ if (this._lastTimestamp === -1)
37
+ this._lastTimestamp = timeStamp;
38
+ else {
39
+ this._lastTimestamp += interval;
40
+ timeStamp = this._lastTimestamp;
41
+ }
37
42
  }
38
- this._lastTimestamp = timeStamp;
39
- interval *= profile.intervalMultiplier;
40
43
  if (ev.acceleration !== null &&
41
44
  ev.acceleration.x !== null &&
42
45
  ev.acceleration.y !== null &&
@@ -61,6 +64,47 @@ export class MSTPCameraSource extends Source {
61
64
  this._startDeviceOrientation();
62
65
  }
63
66
  };
67
+ this._lastAccelerometerTimestamp = -1;
68
+ this._accelerometerReading = () => {
69
+ var _a;
70
+ if (!this._accelerometer || this._accelerometer.x === undefined || this._accelerometer.y === undefined || this._accelerometer.z === undefined)
71
+ return;
72
+ let pipeline = Pipeline.get(this._pipeline);
73
+ if (!pipeline)
74
+ return;
75
+ const timestamp = (_a = this._accelerometer.timestamp) !== null && _a !== void 0 ? _a : performance.now();
76
+ const interval = this._lastAccelerometerTimestamp > -1 ? timestamp - this._lastAccelerometerTimestamp : 30;
77
+ this._lastAccelerometerTimestamp = timestamp;
78
+ pipeline.motionAccelerometerSubmit(timestamp, this._accelerometer.x * profile.deviceMotionMutliplier, this._accelerometer.y * profile.deviceMotionMutliplier, this._accelerometer.z * profile.deviceMotionMutliplier);
79
+ pipeline.motionAccelerometerWithGravitySubmitInt(timestamp, interval, this._accelerometer.x * profile.deviceMotionMutliplier, this._accelerometer.y * profile.deviceMotionMutliplier, this._accelerometer.z * profile.deviceMotionMutliplier);
80
+ };
81
+ this._lastLinearAccelerationTimestamp = -1;
82
+ this._linearAccelerationReading = () => {
83
+ var _a;
84
+ if (!this._linearAcceleration || this._linearAcceleration.x === undefined || this._linearAcceleration.y === undefined || this._linearAcceleration.z === undefined)
85
+ return;
86
+ let pipeline = Pipeline.get(this._pipeline);
87
+ if (!pipeline)
88
+ return;
89
+ const timestamp = (_a = this._linearAcceleration.timestamp) !== null && _a !== void 0 ? _a : performance.now();
90
+ const interval = this._lastLinearAccelerationTimestamp > -1 ? timestamp - this._lastLinearAccelerationTimestamp : 30;
91
+ this._lastLinearAccelerationTimestamp = timestamp;
92
+ pipeline.motionAccelerometerWithoutGravitySubmitInt(timestamp, interval, this._linearAcceleration.x * profile.deviceMotionMutliplier, this._linearAcceleration.y * profile.deviceMotionMutliplier, this._linearAcceleration.z * profile.deviceMotionMutliplier);
93
+ };
94
+ this._lastGyroscopeReading = -1;
95
+ this._gyroscopeReading = () => {
96
+ var _a;
97
+ if (!this._gyroscope || this._gyroscope.x === undefined || this._gyroscope.y === undefined || this._gyroscope.z === undefined)
98
+ return;
99
+ let pipeline = Pipeline.get(this._pipeline);
100
+ if (!pipeline)
101
+ return;
102
+ const timestamp = (_a = this._gyroscope.timestamp) !== null && _a !== void 0 ? _a : performance.now();
103
+ const interval = this._lastGyroscopeReading > -1 ? timestamp - this._lastGyroscopeReading : 30;
104
+ this._lastGyroscopeReading = timestamp;
105
+ pipeline.motionRotationRateSubmit(timestamp, -this._gyroscope.x, -this._gyroscope.y, -this._gyroscope.z);
106
+ pipeline.motionRotationRateSubmitInt(timestamp, interval, this._gyroscope.x * 180 / Math.PI, this._gyroscope.y * 180 / Math.PI, this._gyroscope.z * 180 / Math.PI);
107
+ };
64
108
  zcout("Using MSTP camera source");
65
109
  }
66
110
  destroy() {
@@ -221,9 +265,38 @@ export class MSTPCameraSource extends Source {
221
265
  });
222
266
  }
223
267
  _startDeviceMotion() {
224
- window.addEventListener("devicemotion", this._deviceMotionListener, false);
268
+ try {
269
+ this._accelerometer = new Accelerometer({ frequency: 60 });
270
+ this._linearAcceleration = new LinearAccelerationSensor({ frequency: 60 });
271
+ this._gyroscope = new Gyroscope({ frequency: 60 });
272
+ // throw new Error();
273
+ this._accelerometer.addEventListener('reading', this._accelerometerReading);
274
+ this._accelerometer.start();
275
+ this._linearAcceleration.addEventListener('reading', this._linearAccelerationReading);
276
+ this._linearAcceleration.start();
277
+ this._gyroscope.addEventListener('reading', this._gyroscopeReading);
278
+ this._gyroscope.start();
279
+ }
280
+ catch (err) {
281
+ window.addEventListener("devicemotion", this._deviceMotionListener, false);
282
+ }
225
283
  }
226
284
  _stopDeviceMotion() {
285
+ if (this._accelerometer) {
286
+ this._accelerometer.stop();
287
+ this._accelerometer.removeEventListener('reading', this._accelerometerReading);
288
+ delete this._accelerometer;
289
+ }
290
+ if (this._linearAcceleration) {
291
+ this._linearAcceleration.stop();
292
+ this._linearAcceleration.removeEventListener('reading', this._linearAccelerationReading);
293
+ delete this._linearAcceleration;
294
+ }
295
+ if (this._gyroscope) {
296
+ this._gyroscope.stop();
297
+ this._gyroscope.removeEventListener('reading', this._gyroscopeReading);
298
+ delete this._gyroscope;
299
+ }
227
300
  window.removeEventListener("devicemotion", this._deviceMotionListener);
228
301
  }
229
302
  uploadGL(info) {
package/lib/native.js CHANGED
@@ -12,7 +12,7 @@ import { zappar_client } from "./gen/zappar-client";
12
12
  import { drawPlane } from "./drawplane";
13
13
  import { cameraRotationForScreenOrientation, projectionMatrix } from "./cameramodel";
14
14
  import { mat4, vec3 } from "gl-matrix";
15
- import { launchWorker, messageManager } from "./worker-client";
15
+ import { launchCeresWorker, launchWorker, messageManager } from "./worker-client";
16
16
  import { permissionRequestUI, permissionGrantedAll, permissionGrantedCamera, permissionGrantedMotion, permissionDeniedAny, permissionDeniedCamera, permissionDeniedMotion, permissionRequestMotion, permissionRequestCamera, permissionRequestAll, permissionDeniedUI } from "./permission";
17
17
  import { createFaceMesh, destroyFaceMesh, getFaceMesh } from "./facemesh";
18
18
  import { Pipeline, applyScreenCounterRotation } from "./pipeline";
@@ -49,7 +49,7 @@ export function initialize(opts) {
49
49
  c.impl.analytics_project_id_set(".wiz" + pathParts[1], uid);
50
50
  }
51
51
  messageManager.onIncomingMessage.bind(msg => {
52
- var _a, _b, _c, _d, _e, _f, _g, _h;
52
+ var _a, _b, _c, _d, _e, _f, _g;
53
53
  switch (msg.t) {
54
54
  case "zappar":
55
55
  (_a = Pipeline.get(msg.p)) === null || _a === void 0 ? void 0 : _a.pendingMessages.push(msg.d);
@@ -72,11 +72,6 @@ export function initialize(opts) {
72
72
  (_g = (_f = Pipeline.get(msgt.p)) === null || _f === void 0 ? void 0 : _f.imageBitmapFromWorker) === null || _g === void 0 ? void 0 : _g.call(_f, msgt);
73
73
  break;
74
74
  }
75
- case "raw": {
76
- let msgt = msg;
77
- (_h = Pipeline.get(msgt.p)) === null || _h === void 0 ? void 0 : _h.cameraFrameDataRawResult(msgt);
78
- break;
79
- }
80
75
  case "streamEndedS2C": {
81
76
  let msgt = msg;
82
77
  const src = getCameraSource(msgt.source);
@@ -84,6 +79,10 @@ export function initialize(opts) {
84
79
  src.streamEnded();
85
80
  break;
86
81
  }
82
+ case "setupCeresWorker": {
83
+ launchCeresWorker(msg.port);
84
+ break;
85
+ }
87
86
  case "licerr": {
88
87
  let div = document.createElement("div");
89
88
  div.innerHTML = "Visit <a href='https://docs.zap.works/universal-ar/licensing/' style='color: white;'>our licensing page</a> to find out about hosting on your own domain.";
@@ -133,16 +132,7 @@ export function initialize(opts) {
133
132
  }
134
133
  }
135
134
  });
136
- client = Object.assign(Object.assign({}, c.impl), { loaded: () => loaded, camera_default_device_id: userFacing => userFacing ? CameraSource.USER_DEFAULT_DEVICE_ID : CameraSource.DEFAULT_DEVICE_ID, camera_source_create: (p, deviceId) => createCameraSource(p, deviceId), camera_source_destroy: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.destroy(); }, camera_source_pause: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.pause(); }, camera_source_start: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.start(); }, camera_count: () => 2, camera_id: indx => indx === 0 ? CameraSource.DEFAULT_DEVICE_ID : CameraSource.USER_DEFAULT_DEVICE_ID, camera_name: indx => indx === 0 ? "Rear-facing Camera" : "User-facing Camera", camera_user_facing: indx => indx !== 0, pose_from_raw: (raw_pose, mirror) => {
137
- let res = applyScreenCounterRotation(undefined, raw_pose);
138
- if (mirror) {
139
- let scale = mat4.create();
140
- mat4.fromScaling(scale, [-1, 1, 1]);
141
- mat4.multiply(res, scale, res);
142
- mat4.multiply(res, res, scale);
143
- }
144
- return res;
145
- }, pipeline_create: () => Pipeline.create(c.impl, messageManager), pipeline_frame_update: (p) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.frameUpdate(c); }, pipeline_camera_frame_draw_gl: (pipeline, screenWidth, screenHeight, mirror) => {
135
+ client = Object.assign(Object.assign({}, c.impl), { loaded: () => loaded, camera_default_device_id: userFacing => userFacing ? CameraSource.USER_DEFAULT_DEVICE_ID : CameraSource.DEFAULT_DEVICE_ID, camera_source_create: (p, deviceId) => createCameraSource(p, deviceId), camera_source_destroy: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.destroy(); }, camera_source_pause: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.pause(); }, camera_source_start: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.start(); }, camera_count: () => 2, camera_id: indx => indx === 0 ? CameraSource.DEFAULT_DEVICE_ID : CameraSource.USER_DEFAULT_DEVICE_ID, camera_name: indx => indx === 0 ? "Rear-facing Camera" : "User-facing Camera", camera_user_facing: indx => indx !== 0, pipeline_create: () => Pipeline.create(c.impl, messageManager), pipeline_frame_update: (p) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.frameUpdate(c); }, pipeline_camera_frame_draw_gl: (pipeline, screenWidth, screenHeight, mirror) => {
146
136
  var _a;
147
137
  (_a = Pipeline.get(pipeline)) === null || _a === void 0 ? void 0 : _a.cameraFrameDrawGL(screenWidth, screenHeight, mirror);
148
138
  }, draw_plane: (gl, projectionMatrix, cameraMatrix, targetMatrix, texture) => {
@@ -166,7 +156,7 @@ export function initialize(opts) {
166
156
  return;
167
157
  }
168
158
  (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.drawImageTargetPreview(projectionMatrix, cameraMatrix, targetMatrix, indx, obj);
169
- }, projection_matrix_from_camera_model: projectionMatrix, projection_matrix_from_camera_model_ext: projectionMatrix, pipeline_process_gl: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.processGL(); }, pipeline_gl_context_set: (p, gl, texturePool) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.glContextSet(gl, texturePool); }, pipeline_gl_context_lost: (p) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.glContextLost(); }, pipeline_camera_frame_upload_gl: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.uploadGL(); }, pipeline_camera_frame_texture_gl: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameTexture(); }, pipeline_camera_frame_texture_matrix: (p, sw, sh, mirror) => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameTextureMatrix(sw, sh, mirror)) || mat4.create(); }, pipeline_camera_frame_user_facing: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameUserFacing()) || false; }, pipeline_camera_pose_default: () => mat4.create(), pipeline_camera_pose_with_attitude: (p, mirror) => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraPoseWithAttitude(mirror)) || mat4.create(); }, pipeline_camera_pose_with_origin: (p, o) => { let res = mat4.create(); mat4.invert(res, o); return res; }, pipeline_sequence_record_clear: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordClear(); }, pipeline_sequence_record_start: (p, expectedFrames) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordStart(expectedFrames); }, pipeline_sequence_record_stop: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordStop(); }, pipeline_sequence_record_device_attitude_matrices_set: (p, v) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordDeviceAttitudeMatrices(v); }, pipeline_sequence_record_data: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordData()) || new Uint8Array(0); }, pipeline_sequence_record_data_size: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordData().byteLength) || 0; }, pipeline_camera_frame_data_raw: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.getCameraFrameDataRaw()) || Promise.reject(); }, pipeline_camera_frame_data_raw_enabled_set: (p, v) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.setCameraFrameDataRawEnabled(v); }, instant_world_tracker_anchor_pose_camera_relative: (o, mirror) => {
159
+ }, projection_matrix_from_camera_model: projectionMatrix, projection_matrix_from_camera_model_ext: projectionMatrix, pipeline_process_gl: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.processGL(); }, pipeline_gl_context_set: (p, gl, texturePool) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.glContextSet(gl, texturePool); }, pipeline_gl_context_lost: (p) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.glContextLost(); }, pipeline_camera_frame_upload_gl: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.uploadGL(); }, pipeline_camera_frame_texture_gl: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameTexture(); }, pipeline_camera_frame_texture_matrix: (p, sw, sh, mirror) => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameTextureMatrix(sw, sh, mirror)) || mat4.create(); }, pipeline_camera_frame_user_facing: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameUserFacing()) || false; }, pipeline_camera_pose_default: () => mat4.create(), pipeline_camera_pose_with_attitude: (p, mirror) => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraPoseWithAttitude(mirror)) || mat4.create(); }, pipeline_camera_pose_with_origin: (p, o) => { let res = mat4.create(); mat4.invert(res, o); return res; }, pipeline_sequence_record_clear: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordClear(); }, pipeline_sequence_record_start: (p, expectedFrames) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordStart(expectedFrames); }, pipeline_sequence_record_stop: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordStop(); }, pipeline_sequence_record_device_attitude_matrices_set: (p, v) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordDeviceAttitudeMatrices(v); }, pipeline_sequence_record_data: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordData()) || new Uint8Array(0); }, pipeline_sequence_record_data_size: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordData().byteLength) || 0; }, instant_world_tracker_anchor_pose_camera_relative: (o, mirror) => {
170
160
  let res = applyScreenCounterRotation(undefined, c.impl.instant_world_tracker_anchor_pose_raw(o));
171
161
  if (mirror) {
172
162
  let scale = mat4.create();
package/lib/pipeline.d.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  /// <reference types="dom-webcodecs" />
2
2
  import { zappar_pipeline_t, zappar_camera_source_t } from "./gen/zappar";
3
+ import { zappar_cwrap } from "./gen/zappar-native";
3
4
  import { zappar_client } from "./gen/zappar-client";
4
5
  import { MsgManager } from "./messages";
5
6
  import { Source, CameraFrameInfo } from "./source";
6
- import { CameraDataRawS2C, CameraFrameReturnS2C, ImageBitmapS2C, VideoFrameS2C } from "./workerinterface";
7
+ import { CameraFrameReturnS2C, ImageBitmapS2C, VideoFrameS2C } from "./workerinterface";
7
8
  import { FaceMesh } from "./facemesh";
8
9
  import { Event } from "./event";
9
10
  import { ImageTracker } from "./imagetracker";
10
- import { zappar } from "./gen/zappar-bridge";
11
- import { CameraFrameData } from "./camera-frame-data";
12
11
  export declare class Pipeline {
13
12
  private _client;
14
13
  private _impl;
@@ -28,17 +27,12 @@ export declare class Pipeline {
28
27
  private _sequenceRecorder;
29
28
  private _sequenceRecordDeviceAttitudeMatrices;
30
29
  private _sequenceRecorderFirstCameraToken;
31
- private _cameraFrameDataPromises;
32
- private _cameraFrameDataResolves;
33
- private _cameraFrameDataRejects;
34
- private _cameraFrameDataEnabled;
35
30
  onGLContextReset: Event;
36
- static create(client: zappar, mgr: MsgManager): zappar_pipeline_t;
31
+ static create(client: zappar_cwrap, mgr: MsgManager): zappar_pipeline_t;
37
32
  static get(p: zappar_pipeline_t): Pipeline | undefined;
38
33
  private constructor();
39
34
  frameUpdate(client: zappar_client): void;
40
35
  cleanOldFrames(): void;
41
- cameraFrameDataRawResult(msg: CameraDataRawS2C): void;
42
36
  cameraTokenReturn(msg: CameraFrameReturnS2C): void;
43
37
  sequenceRecordStart(expectedFrames: number): void;
44
38
  sequenceRecordStop(): void;
@@ -46,8 +40,6 @@ export declare class Pipeline {
46
40
  sequenceRecordClear(): void;
47
41
  sequenceRecordDeviceAttitudeMatrices(v: boolean): void;
48
42
  getVideoTexture(): WebGLTexture | undefined;
49
- getCameraFrameDataRaw(): Promise<CameraFrameData | undefined>;
50
- setCameraFrameDataRawEnabled(e: boolean): void;
51
43
  destroy(): void;
52
44
  getCurrentCameraInfo(): CameraFrameInfo | undefined;
53
45
  cameraFrameDrawGL(screenWidth: number, screenHeight: number, mirror?: boolean): void;