@zappar/zappar-cv 3.0.1-alpha.1 → 3.0.1-alpha.10

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 (60) hide show
  1. package/README.md +2 -2
  2. package/lib/additional.d.ts +8 -1
  3. package/lib/camera-frame-data.d.ts +5 -0
  4. package/lib/camera-frame-data.js +1 -0
  5. package/lib/data-download.d.ts +8 -0
  6. package/lib/data-download.js +8 -0
  7. package/lib/deserializer.d.ts +1 -0
  8. package/lib/deserializer.js +7 -0
  9. package/lib/direct.js +1 -1
  10. package/lib/drawgrid.d.ts +2 -0
  11. package/lib/drawgrid.js +136 -0
  12. package/lib/drawpoints.d.ts +11 -0
  13. package/lib/drawpoints.js +180 -0
  14. package/lib/gen/zappar-bridge.d.ts +140 -0
  15. package/lib/gen/zappar-bridge.js +8 -0
  16. package/lib/gen/zappar-client.d.ts +3 -2
  17. package/lib/gen/zappar-client.js +208 -18
  18. package/lib/gen/zappar-cwrap.js +171 -3
  19. package/lib/gen/zappar-native.d.ts +28 -1
  20. package/lib/gen/zappar-native.js +6 -0
  21. package/lib/gen/zappar-server.d.ts +3 -0
  22. package/lib/gen/zappar-server.js +108 -10
  23. package/lib/gen/zappar.d.ts +25 -0
  24. package/lib/gen/zappar.js +1 -0
  25. package/lib/html-element-source.d.ts +3 -1
  26. package/lib/html-element-source.js +13 -6
  27. package/lib/image-process-gl.d.ts +3 -2
  28. package/lib/image-process-gl.js +9 -7
  29. package/lib/imagebitmap-camera-source.d.ts +3 -1
  30. package/lib/imagebitmap-camera-source.js +10 -4
  31. package/lib/imagetracker.d.ts +3 -2
  32. package/lib/index.d.ts +2 -1
  33. package/lib/index.js +1 -1
  34. package/lib/mstp-camera-source.d.ts +2 -1
  35. package/lib/mstp-camera-source.js +5 -0
  36. package/lib/native.js +67 -3
  37. package/lib/pipeline.d.ts +14 -4
  38. package/lib/pipeline.js +84 -5
  39. package/lib/profile.d.ts +2 -2
  40. package/lib/profile.js +3 -3
  41. package/lib/serializer.d.ts +1 -0
  42. package/lib/serializer.js +1 -0
  43. package/lib/source.d.ts +1 -0
  44. package/lib/version.d.ts +1 -1
  45. package/lib/version.js +1 -1
  46. package/lib/worker-client.js +5 -1
  47. package/lib/worker-imagebitmap.js +5 -4
  48. package/lib/worker-server.d.ts +1 -1
  49. package/lib/worker-server.js +84 -12
  50. package/lib/worker.js +2 -1
  51. package/lib/workerinterface.d.ts +24 -1
  52. package/lib/zappar-cv.js +203 -165
  53. package/lib/zappar-cv.wasm +0 -0
  54. package/package.json +1 -1
  55. package/umd/751.zappar-cv.js +1 -0
  56. package/umd/867.zappar-cv.js +1 -1
  57. package/umd/{501114eb92cddf5f56fe.wasm → ca409d4e8cebe454b816.wasm} +0 -0
  58. package/umd/zappar-cv.js +1 -1
  59. package/umd/zappar-cv.worker.js +1 -1
  60. package/umd/429.zappar-cv.js +0 -1
package/lib/native.js CHANGED
@@ -26,7 +26,10 @@ import { createCameraSource, getCameraSource } from "./camera-source-map";
26
26
  import { gfx } from "./gfx";
27
27
  import { ImageTracker } from "./imagetracker";
28
28
  import { MSTPCameraSource } from "./mstp-camera-source";
29
+ import { drawGrid } from "./drawgrid";
30
+ import { getPointsDataMatrix } from "./drawpoints";
29
31
  let client;
32
+ const pipelineByWorldTracker = new Map();
30
33
  export function initialize(opts) {
31
34
  if (client)
32
35
  return client;
@@ -49,7 +52,7 @@ export function initialize(opts) {
49
52
  c.impl.analytics_project_id_set(".wiz" + pathParts[1], uid);
50
53
  }
51
54
  messageManager.onIncomingMessage.bind(msg => {
52
- var _a, _b, _c, _d, _e, _f, _g;
55
+ var _a, _b, _c, _d, _e, _f, _g, _h;
53
56
  switch (msg.t) {
54
57
  case "zappar":
55
58
  (_a = Pipeline.get(msg.p)) === null || _a === void 0 ? void 0 : _a.pendingMessages.push(msg.d);
@@ -72,6 +75,11 @@ export function initialize(opts) {
72
75
  (_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
76
  break;
74
77
  }
78
+ case "raw": {
79
+ let msgt = msg;
80
+ (_h = Pipeline.get(msgt.p)) === null || _h === void 0 ? void 0 : _h.cameraFrameDataRawResult(msgt);
81
+ break;
82
+ }
75
83
  case "streamEndedS2C": {
76
84
  let msgt = msg;
77
85
  const src = getCameraSource(msgt.source);
@@ -83,6 +91,15 @@ export function initialize(opts) {
83
91
  launchCeresWorker(msg.port);
84
92
  break;
85
93
  }
94
+ case "_z_datadownload": {
95
+ let blob = new Blob([msg.data], { type: "application/octet-stream" });
96
+ let url = URL.createObjectURL(blob);
97
+ let a = document.createElement("a");
98
+ a.download = "sequencedata.bin";
99
+ a.href = url;
100
+ a.click();
101
+ break;
102
+ }
86
103
  case "licerr": {
87
104
  let div = document.createElement("div");
88
105
  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.";
@@ -132,11 +149,30 @@ export function initialize(opts) {
132
149
  }
133
150
  }
134
151
  });
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) => {
152
+ 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_source_profile_set: (cam, p) => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.setProfile(p); }, 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) => {
153
+ let res = applyScreenCounterRotation(undefined, raw_pose);
154
+ if (mirror) {
155
+ let scale = mat4.create();
156
+ mat4.fromScaling(scale, [-1, 1, 1]);
157
+ mat4.multiply(res, scale, res);
158
+ mat4.multiply(res, res, scale);
159
+ }
160
+ return res;
161
+ }, 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) => {
136
162
  var _a;
137
163
  (_a = Pipeline.get(pipeline)) === null || _a === void 0 ? void 0 : _a.cameraFrameDrawGL(screenWidth, screenHeight, mirror);
164
+ }, pipeline_camera_frame_data_width: (pipeline) => {
165
+ var _a, _b;
166
+ const info = (_a = Pipeline.get(pipeline)) === null || _a === void 0 ? void 0 : _a.getCurrentCameraInfo();
167
+ return (_b = info === null || info === void 0 ? void 0 : info.dataWidth) !== null && _b !== void 0 ? _b : 0;
168
+ }, pipeline_camera_frame_data_height: (pipeline) => {
169
+ var _a, _b;
170
+ const info = (_a = Pipeline.get(pipeline)) === null || _a === void 0 ? void 0 : _a.getCurrentCameraInfo();
171
+ return (_b = info === null || info === void 0 ? void 0 : info.dataHeight) !== null && _b !== void 0 ? _b : 0;
138
172
  }, draw_plane: (gl, projectionMatrix, cameraMatrix, targetMatrix, texture) => {
139
173
  drawPlane(gl, projectionMatrix, cameraMatrix, targetMatrix, texture);
174
+ }, draw_grid: (gl, projectionMatrix, cameraMatrix, targetMatrix) => {
175
+ drawGrid(gl, projectionMatrix, cameraMatrix, targetMatrix);
140
176
  }, pipeline_draw_face: (p, projectionMatrix, cameraMatrix, targetMatrix, o) => {
141
177
  var _a;
142
178
  let obj = getFaceMesh(o);
@@ -156,7 +192,7 @@ export function initialize(opts) {
156
192
  return;
157
193
  }
158
194
  (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.drawImageTargetPreview(projectionMatrix, cameraMatrix, targetMatrix, indx, obj);
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) => {
195
+ }, 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) => {
160
196
  let res = applyScreenCounterRotation(undefined, c.impl.instant_world_tracker_anchor_pose_raw(o));
161
197
  if (mirror) {
162
198
  let scale = mat4.create();
@@ -343,6 +379,25 @@ export function initialize(opts) {
343
379
  return 0;
344
380
  }
345
381
  return obj.getPreviewMesh(indx).normals.length;
382
+ }, zapcode_tracker_anchor_pose_camera_relative: (o, indx, mirror) => {
383
+ let res = applyScreenCounterRotation(undefined, c.impl.zapcode_tracker_anchor_pose_raw(o, indx));
384
+ if (mirror) {
385
+ let scale = mat4.create();
386
+ mat4.fromScaling(scale, [-1, 1, 1]);
387
+ mat4.multiply(res, scale, res);
388
+ mat4.multiply(res, res, scale);
389
+ }
390
+ return res;
391
+ }, zapcode_tracker_anchor_pose: (o, indx, cameraPose, mirror) => {
392
+ let res = applyScreenCounterRotation(undefined, c.impl.zapcode_tracker_anchor_pose_raw(o, indx));
393
+ if (mirror) {
394
+ let scale = mat4.create();
395
+ mat4.fromScaling(scale, [-1, 1, 1]);
396
+ mat4.multiply(res, scale, res);
397
+ mat4.multiply(res, res, scale);
398
+ }
399
+ mat4.multiply(res, cameraPose, res);
400
+ return res;
346
401
  }, face_tracker_anchor_pose_camera_relative: (o, indx, mirror) => {
347
402
  let res = applyScreenCounterRotation(undefined, c.impl.face_tracker_anchor_pose_raw(o, indx));
348
403
  if (mirror) {
@@ -490,6 +545,15 @@ export function initialize(opts) {
490
545
  return mat4.create();
491
546
  }
492
547
  return obj.anchor_pose;
548
+ }, world_tracker_create: (pipeline) => {
549
+ const ret = c.impl.world_tracker_create(pipeline);
550
+ pipelineByWorldTracker.set(ret, pipeline);
551
+ return ret;
552
+ }, world_tracker_points_data_matrix: (wt, screenWidth, screenHeight, mirror) => {
553
+ const pipeline = pipelineByWorldTracker.get(wt);
554
+ if (pipeline === undefined || !client)
555
+ return mat4.create();
556
+ return getPointsDataMatrix(client.pipeline_camera_frame_data_width(pipeline), client.pipeline_camera_frame_data_height(pipeline), screenWidth, screenHeight, mirror);
493
557
  }, world_tracker_plane_pose_camera_relative: (o, indx, mirror) => {
494
558
  let res = applyScreenCounterRotation(undefined, c.impl.world_tracker_plane_pose_raw(o, indx));
495
559
  if (mirror) {
package/lib/pipeline.d.ts CHANGED
@@ -1,13 +1,15 @@
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
+ import { camera_profile_t } from "./gen/zappar-native";
4
4
  import { zappar_client } from "./gen/zappar-client";
5
5
  import { MsgManager } from "./messages";
6
6
  import { Source, CameraFrameInfo } from "./source";
7
- import { CameraFrameReturnS2C, ImageBitmapS2C, VideoFrameS2C } from "./workerinterface";
7
+ import { CameraDataRawS2C, CameraFrameReturnS2C, ImageBitmapS2C, VideoFrameS2C } from "./workerinterface";
8
8
  import { FaceMesh } from "./facemesh";
9
9
  import { Event } from "./event";
10
10
  import { ImageTracker } from "./imagetracker";
11
+ import { zappar } from "./gen/zappar-bridge";
12
+ import { CameraFrameData } from "./camera-frame-data";
11
13
  export declare class Pipeline {
12
14
  private _client;
13
15
  private _impl;
@@ -27,12 +29,17 @@ export declare class Pipeline {
27
29
  private _sequenceRecorder;
28
30
  private _sequenceRecordDeviceAttitudeMatrices;
29
31
  private _sequenceRecorderFirstCameraToken;
32
+ private _cameraFrameDataPromises;
33
+ private _cameraFrameDataResolves;
34
+ private _cameraFrameDataRejects;
35
+ private _cameraFrameDataEnabled;
30
36
  onGLContextReset: Event;
31
- static create(client: zappar_cwrap, mgr: MsgManager): zappar_pipeline_t;
37
+ static create(client: zappar, mgr: MsgManager): zappar_pipeline_t;
32
38
  static get(p: zappar_pipeline_t): Pipeline | undefined;
33
39
  private constructor();
34
40
  frameUpdate(client: zappar_client): void;
35
41
  cleanOldFrames(): void;
42
+ cameraFrameDataRawResult(msg: CameraDataRawS2C): void;
36
43
  cameraTokenReturn(msg: CameraFrameReturnS2C): void;
37
44
  sequenceRecordStart(expectedFrames: number): void;
38
45
  sequenceRecordStop(): void;
@@ -40,6 +47,8 @@ export declare class Pipeline {
40
47
  sequenceRecordClear(): void;
41
48
  sequenceRecordDeviceAttitudeMatrices(v: boolean): void;
42
49
  getVideoTexture(): WebGLTexture | undefined;
50
+ getCameraFrameDataRaw(): Promise<CameraFrameData | undefined>;
51
+ setCameraFrameDataRawEnabled(e: boolean): void;
43
52
  destroy(): void;
44
53
  getCurrentCameraInfo(): CameraFrameInfo | undefined;
45
54
  cameraFrameDrawGL(screenWidth: number, screenHeight: number, mirror?: boolean): void;
@@ -66,8 +75,9 @@ export declare class Pipeline {
66
75
  motionAttitudeSubmit(timestamp: number, x: number, y: number, z: number): void;
67
76
  motionAttitudeMatrix(m: Float32Array): void;
68
77
  sendCameraStreamToWorker(source: zappar_camera_source_t, stream: ReadableStream<VideoFrame>, userFacing: boolean): void;
78
+ sendCameraProfileToWorker(source: zappar_camera_source_t, profile: camera_profile_t): void;
69
79
  sendCameraToScreenRotationToWorker(rot: number): void;
70
- sendImageBitmapToWorker(img: ImageBitmap, rot: number, userFacing: boolean, tokenId: number, cameraModel: Float32Array, cameraToDevice: Float32Array): void;
80
+ sendImageBitmapToWorker(img: ImageBitmap, rot: number, userFacing: boolean, tokenId: number, cameraModel: Float32Array, cameraToDevice: Float32Array, cp: camera_profile_t): void;
71
81
  sendDataToWorker(data: ArrayBuffer, token: number, width: number, height: number, userFacing: boolean, cameraToDevice: Float32Array, cameraModel: Float32Array): void;
72
82
  }
73
83
  export declare function applyScreenCounterRotation(info: CameraFrameInfo | undefined, inp: Float32Array): Float32Array;
package/lib/pipeline.js CHANGED
@@ -24,6 +24,10 @@ export class Pipeline {
24
24
  this.cameraPixelArrays = [];
25
25
  this._sequenceRecordDeviceAttitudeMatrices = true;
26
26
  this._sequenceRecorderFirstCameraToken = 0;
27
+ this._cameraFrameDataPromises = new Map();
28
+ this._cameraFrameDataResolves = new Map();
29
+ this._cameraFrameDataRejects = new Map();
30
+ this._cameraFrameDataEnabled = false;
27
31
  this.onGLContextReset = new Event();
28
32
  }
29
33
  static create(client, mgr) {
@@ -56,14 +60,34 @@ export class Pipeline {
56
60
  if (t[1].texture)
57
61
  this.videoTextures.push(t[1].texture);
58
62
  (_b = (_a = t[1].frame) === null || _a === void 0 ? void 0 : _a.close) === null || _b === void 0 ? void 0 : _b.call(_a);
63
+ if (t[1].data) {
64
+ this.cameraPixelArrays.push(t[1].data);
65
+ t[1].data = undefined;
66
+ }
59
67
  this.cameraTokens.delete(t[0]);
60
68
  }
61
69
  }
62
70
  }
71
+ cameraFrameDataRawResult(msg) {
72
+ var _a, _b;
73
+ let info = this.cameraTokens.get(msg.token);
74
+ if (!info)
75
+ return;
76
+ if (msg.data === null) {
77
+ (_a = this._cameraFrameDataRejects.get(info)) === null || _a === void 0 ? void 0 : _a(new Error('Raw camera data not available'));
78
+ }
79
+ else {
80
+ info.data = msg.data.data;
81
+ (_b = this._cameraFrameDataResolves.get(info)) === null || _b === void 0 ? void 0 : _b(msg.data);
82
+ }
83
+ this._cameraFrameDataRejects.delete(info);
84
+ this._cameraFrameDataResolves.delete(info);
85
+ this._cameraFrameDataPromises.delete(info);
86
+ }
63
87
  cameraTokenReturn(msg) {
88
+ let info = this.cameraTokens.get(msg.token);
64
89
  if (this._sequenceRecorder && this._sequenceRecordDeviceAttitudeMatrices
65
90
  && msg.token >= this._sequenceRecorderFirstCameraToken) {
66
- let info = this.cameraTokens.get(msg.token);
67
91
  if (info) {
68
92
  if (msg.att)
69
93
  this._sequenceRecorder.appendAttitudeMatrix(msg.att);
@@ -71,7 +95,20 @@ export class Pipeline {
71
95
  this._sequenceRecorder.appendCameraFrame(info);
72
96
  }
73
97
  }
74
- this.cameraPixelArrays.push(msg.d);
98
+ if (info && !info.data && msg.d) {
99
+ info.data = msg.d;
100
+ const rawRequestResolve = this._cameraFrameDataResolves.get(info);
101
+ if (rawRequestResolve) {
102
+ rawRequestResolve({
103
+ data: info.data,
104
+ width: info.dataWidth,
105
+ height: info.dataHeight,
106
+ });
107
+ }
108
+ this._cameraFrameDataRejects.delete(info);
109
+ this._cameraFrameDataResolves.delete(info);
110
+ this._cameraFrameDataPromises.delete(info);
111
+ }
75
112
  this.tokensInFlight--;
76
113
  }
77
114
  sequenceRecordStart(expectedFrames) {
@@ -97,6 +134,37 @@ export class Pipeline {
97
134
  getVideoTexture() {
98
135
  return this.videoTextures.pop();
99
136
  }
137
+ getCameraFrameDataRaw() {
138
+ if (!this._cameraFrameDataEnabled)
139
+ throw new Error('Raw camera frame data is not enabled.');
140
+ const info = this.getCurrentCameraInfo();
141
+ if (!info)
142
+ return Promise.resolve(undefined);
143
+ if (info.data)
144
+ return Promise.resolve({ data: info.data.slice(0), width: info.dataWidth, height: info.dataHeight });
145
+ let existing = this._cameraFrameDataPromises.get(info);
146
+ if (!existing) {
147
+ existing = new Promise((resolve, reject) => {
148
+ if (typeof info.remoteToken !== 'undefined') {
149
+ const msg = {
150
+ t: "rawrequest",
151
+ token: info.remoteToken,
152
+ p: this._impl,
153
+ };
154
+ this._mgr.postOutgoingMessage(msg, []);
155
+ }
156
+ this._cameraFrameDataResolves.set(info, resolve);
157
+ this._cameraFrameDataRejects.set(info, reject);
158
+ });
159
+ this._cameraFrameDataPromises.set(info, existing);
160
+ }
161
+ return existing;
162
+ }
163
+ setCameraFrameDataRawEnabled(e) {
164
+ this._cameraFrameDataEnabled = e;
165
+ const msg = { t: 'rawenabled', v: e };
166
+ this._mgr.postOutgoingMessage(msg, []);
167
+ }
100
168
  destroy() {
101
169
  this._client.pipeline_destroy(this._impl);
102
170
  byId.delete(this._impl);
@@ -226,7 +294,8 @@ export class Pipeline {
226
294
  uvTransform: msg.uvTransform,
227
295
  cameraModel: msg.cameraModel,
228
296
  cameraToDevice: msg.cameraToDevice,
229
- cameraSource
297
+ cameraSource,
298
+ remoteToken: msg.token,
230
299
  });
231
300
  this.cleanOldFrames();
232
301
  }
@@ -379,6 +448,15 @@ export class Pipeline {
379
448
  };
380
449
  this._mgr.postOutgoingMessage(msg, [msg.s]);
381
450
  }
451
+ sendCameraProfileToWorker(source, profile) {
452
+ let msg = {
453
+ t: "cameraProfileC2S",
454
+ p: this._impl,
455
+ source,
456
+ profile
457
+ };
458
+ this._mgr.postOutgoingMessage(msg, []);
459
+ }
382
460
  sendCameraToScreenRotationToWorker(rot) {
383
461
  let msg = {
384
462
  p: this._impl,
@@ -387,7 +465,7 @@ export class Pipeline {
387
465
  };
388
466
  this._mgr.postOutgoingMessage(msg, []);
389
467
  }
390
- sendImageBitmapToWorker(img, rot, userFacing, tokenId, cameraModel, cameraToDevice) {
468
+ sendImageBitmapToWorker(img, rot, userFacing, tokenId, cameraModel, cameraToDevice, cp) {
391
469
  let msg = {
392
470
  p: this._impl,
393
471
  t: "imageBitmapC2S",
@@ -396,7 +474,8 @@ export class Pipeline {
396
474
  tokenId,
397
475
  userFacing,
398
476
  cameraModel,
399
- cameraToDevice
477
+ cameraToDevice,
478
+ cp
400
479
  };
401
480
  this._mgr.postOutgoingMessage(msg, [img]);
402
481
  }
package/lib/profile.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { camera_profile_t } from "./gen/zappar-native";
1
2
  export declare enum EmbeddedVideoImplementation {
2
3
  OBJECT_URL = 0,
3
4
  SRC_OBJECT = 1
@@ -10,8 +11,7 @@ export declare let profile: {
10
11
  requestHighFrameRate: boolean;
11
12
  videoWidth: number;
12
13
  videoHeight: number;
13
- dataWidth: number;
14
- dataHeight: number;
14
+ getDataSize: (p: camera_profile_t) => number[];
15
15
  videoElementInDOM: boolean;
16
16
  preferMediaStreamTrackProcessorCamera: boolean;
17
17
  preferImageBitmapCamera: boolean;
package/lib/profile.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as UAParser from "ua-parser-js";
2
+ import { camera_profile_t } from "./gen/zappar-native";
2
3
  export var EmbeddedVideoImplementation;
3
4
  (function (EmbeddedVideoImplementation) {
4
5
  EmbeddedVideoImplementation[EmbeddedVideoImplementation["OBJECT_URL"] = 0] = "OBJECT_URL";
@@ -12,8 +13,7 @@ export let profile = {
12
13
  requestHighFrameRate: false,
13
14
  videoWidth: 640,
14
15
  videoHeight: 480,
15
- dataWidth: 320,
16
- dataHeight: 240,
16
+ getDataSize: (p) => p === camera_profile_t.HIGH ? [640, 480] : [320, 240],
17
17
  videoElementInDOM: false,
18
18
  preferMediaStreamTrackProcessorCamera: true,
19
19
  preferImageBitmapCamera: false,
@@ -80,7 +80,7 @@ function iDevice(version) {
80
80
  // Avoid bug where iOS letterboxes 16:9 into 4:3 for high fps
81
81
  // Doesn't seem needed with newer versions of iOS, tested on 14.8.1 and 15.2
82
82
  profile.videoHeight = 360;
83
- profile.dataHeight = 180;
83
+ profile.getDataSize = (p) => p === camera_profile_t.HIGH ? [640, 360] : [320, 180];
84
84
  }
85
85
  }
86
86
  if (majorVersion === 16 && minorVersion >= 4) {
@@ -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
+ floatArray: (a: Float32Array) => void;
11
12
  cameraModel: (a: Float32Array) => void;
12
13
  identityCoefficients: (a: Float32Array) => void;
13
14
  expressionCoefficients: (a: Float32Array) => void;
package/lib/serializer.js CHANGED
@@ -22,6 +22,7 @@ export class MessageSerializer {
22
22
  type: i => this.int(i),
23
23
  matrix4x4: i => this.float32ArrayBuffer(i),
24
24
  matrix3x3: i => this.float32ArrayBuffer(i),
25
+ floatArray: i => this.float32ArrayBuffer(i),
25
26
  identityCoefficients: i => this.float32ArrayBuffer(i),
26
27
  expressionCoefficients: i => this.float32ArrayBuffer(i),
27
28
  cameraModel: i => this.float32ArrayBuffer(i),
package/lib/source.d.ts CHANGED
@@ -10,6 +10,7 @@ export interface CameraFrameInfo {
10
10
  cameraSourceData?: any;
11
11
  uvTransform?: Float32Array;
12
12
  userFacing: boolean;
13
+ remoteToken?: number;
13
14
  frame?: VideoFrame | ImageBitmap;
14
15
  }
15
16
  export declare abstract class Source {
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "3.0.1-alpha.1";
1
+ export declare const VERSION = "3.0.1-alpha.10";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "3.0.1-alpha.1";
1
+ export const VERSION = "3.0.1-alpha.10";
@@ -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);
@@ -21,7 +24,8 @@ export function launchWorker(worker) {
21
24
  worker.postMessage({
22
25
  t: "wasm",
23
26
  url: new URL("./zappar-cv.wasm", import.meta.url).toString(),
24
- module: yield wasmModule
27
+ module: yield wasmModule,
28
+ shouldRecordData
25
29
  });
26
30
  yield waitForLoad(worker);
27
31
  function sendOutgoing() {
@@ -34,12 +34,13 @@ export function handleImageBitmap(m, r, server, mgr) {
34
34
  }
35
35
  if (!texture)
36
36
  return;
37
- if (!pixels || pixels.byteLength < profile.dataWidth * profile.dataHeight) {
37
+ const [dataWidth, dataHeight] = profile.getDataSize(m.cp);
38
+ if (!pixels || pixels.byteLength < dataWidth * dataHeight) {
38
39
  // console.log("Generating pixel buffer", profile.dataWidth * profile.dataHeight);
39
- pixels = new ArrayBuffer(profile.dataWidth * profile.dataHeight);
40
+ pixels = new ArrayBuffer(dataWidth * dataHeight);
40
41
  }
41
- imageProcessor.uploadFrame(texture, m.i, m.r, m.userFacing);
42
- let info = imageProcessor.readFrame(texture, pixels);
42
+ imageProcessor.uploadFrame(texture, m.i, m.r, m.userFacing, m.cp);
43
+ let info = imageProcessor.readFrame(texture, pixels, m.cp);
43
44
  let msg = {
44
45
  t: "imageBitmapS2C",
45
46
  dataWidth: info.dataWidth,
@@ -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): Promise<void>;
3
+ export declare function launchWorkerServer(wasmUrl: string, module: WebAssembly.Module, shouldRecordData: number): Promise<void>;