@zappar/zappar-cv 0.3.13 → 0.4.0-beta.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 (61) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +2 -2
  3. package/lib/additional.d.ts +2 -1
  4. package/lib/camera-source-map.d.ts +10 -0
  5. package/lib/camera-source-map.js +40 -0
  6. package/lib/camera-source.d.ts +3 -5
  7. package/lib/camera-source.js +8 -15
  8. package/lib/deserializer.d.ts +1 -0
  9. package/lib/deserializer.js +7 -0
  10. package/lib/drawcamera.js +2 -1
  11. package/lib/gen/zappar-client.d.ts +1 -0
  12. package/lib/gen/zappar-client.js +78 -41
  13. package/lib/gen/zappar-cwrap.js +71 -20
  14. package/lib/gen/zappar-native.d.ts +20 -3
  15. package/lib/gen/zappar-native.js +13 -1
  16. package/lib/gen/zappar-server.d.ts +3 -0
  17. package/lib/gen/zappar-server.js +70 -34
  18. package/lib/gen/zappar.d.ts +29 -1
  19. package/lib/gen/zappar.js +5 -3
  20. package/lib/gfx.d.ts +1 -0
  21. package/lib/gfx.js +4 -0
  22. package/lib/gl-state-manager.d.ts +9 -0
  23. package/lib/gl-state-manager.js +35 -0
  24. package/lib/html-element-source.d.ts +7 -22
  25. package/lib/html-element-source.js +30 -289
  26. package/lib/image-process-gl.d.ts +37 -0
  27. package/lib/image-process-gl.js +298 -0
  28. package/lib/imagebitmap-camera-source.d.ts +36 -0
  29. package/lib/imagebitmap-camera-source.js +277 -0
  30. package/lib/imagetracker.d.ts +28 -0
  31. package/lib/imagetracker.js +119 -0
  32. package/lib/index.d.ts +1 -1
  33. package/lib/mstp-camera-source.d.ts +29 -0
  34. package/lib/mstp-camera-source.js +230 -0
  35. package/lib/native.js +129 -6
  36. package/lib/pipeline.d.ts +22 -2
  37. package/lib/pipeline.js +140 -19
  38. package/lib/profile.d.ts +2 -0
  39. package/lib/profile.js +21 -6
  40. package/lib/riff-reader.d.ts +18 -0
  41. package/lib/riff-reader.js +56 -0
  42. package/lib/sequencerecorder.d.ts +83 -0
  43. package/lib/sequencerecorder.js +283 -0
  44. package/lib/sequencesource.d.ts +23 -0
  45. package/lib/sequencesource.js +170 -0
  46. package/lib/serializer.d.ts +1 -0
  47. package/lib/serializer.js +1 -0
  48. package/lib/source.d.ts +10 -3
  49. package/lib/version.d.ts +1 -1
  50. package/lib/version.js +1 -1
  51. package/lib/worker-imagebitmap.d.ts +5 -0
  52. package/lib/worker-imagebitmap.js +63 -0
  53. package/lib/worker-server.js +124 -8
  54. package/lib/workerinterface.d.ts +50 -1
  55. package/lib/zcv.js +121 -197
  56. package/lib/zcv.wasm +0 -0
  57. package/package.json +34 -31
  58. package/umd/e9486c1cdadb21608a4f7e2fa3be9517.wasm +0 -0
  59. package/umd/zappar-cv.js +1 -9
  60. package/umd/zappar-cv.worker.js +1 -1
  61. package/umd/0bdbfe863a384bcd2935e7437d8f1153.wasm +0 -0
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImageTracker = void 0;
4
+ const riff_reader_1 = require("./riff-reader");
5
+ let byId = new Map();
6
+ const decoder = new TextDecoder();
7
+ class ImageTracker {
8
+ constructor(_client, _impl) {
9
+ this._client = _client;
10
+ this._impl = _impl;
11
+ this._targets = [];
12
+ }
13
+ static create(pipeline, client) {
14
+ let ret = client.image_tracker_create(pipeline);
15
+ byId.set(ret, new ImageTracker(client, ret));
16
+ return ret;
17
+ }
18
+ static get(p) {
19
+ return byId.get(p);
20
+ }
21
+ destroy() {
22
+ this._client.image_tracker_destroy(this._impl);
23
+ byId.delete(this._impl);
24
+ }
25
+ loadFromMemory(data) {
26
+ this._targets.push({ data });
27
+ this._client.image_tracker_target_load_from_memory(this._impl, data);
28
+ }
29
+ targetCount() {
30
+ return this._targets.length;
31
+ }
32
+ getTargetInfo(i) {
33
+ let current = this._targets[i];
34
+ if (current && current.info)
35
+ return current.info;
36
+ current.info = {
37
+ topRadius: -1,
38
+ bottomRadius: -1,
39
+ sideLength: -1,
40
+ physicalScaleFactor: -1
41
+ };
42
+ try {
43
+ const reader = new riff_reader_1.RiffReader(current.data, false);
44
+ const imgChunk = reader.find("IMG ");
45
+ if (imgChunk) {
46
+ let mimeType = "image/png";
47
+ const mimeTypeChunk = reader.find("IMGM");
48
+ if (mimeTypeChunk)
49
+ mimeType = decoder.decode(mimeTypeChunk.data);
50
+ current.info.preview = { mimeType, compressed: imgChunk.data };
51
+ }
52
+ const odleChunk = reader.find("ODLE");
53
+ if (odleChunk) {
54
+ const odle = decoder.decode(odleChunk.data);
55
+ this._parseOdle(odle, current.info);
56
+ }
57
+ }
58
+ catch (err) { }
59
+ return current.info;
60
+ }
61
+ _parseOdle(data, info) {
62
+ let currentOffset = 0;
63
+ let version = "0";
64
+ [version, currentOffset] = readLine(currentOffset, data);
65
+ if (version === "3") {
66
+ let treeOrFlat = "0";
67
+ [treeOrFlat, currentOffset] = readLine(currentOffset, data);
68
+ if (treeOrFlat !== "0" && treeOrFlat !== "1")
69
+ return;
70
+ let numberTargets = "0";
71
+ [numberTargets, currentOffset] = readLine(currentOffset, data);
72
+ const parsedTargets = parseInt(numberTargets);
73
+ if (isNaN(parsedTargets) || parsedTargets < 1)
74
+ return;
75
+ let emptyLine = "";
76
+ [emptyLine, currentOffset] = readLine(currentOffset, data);
77
+ if (emptyLine.length !== 0)
78
+ return;
79
+ let infoLine = "";
80
+ [infoLine, currentOffset] = readLine(currentOffset, data);
81
+ const infoLineParts = infoLine.split(" ");
82
+ if (infoLineParts.length < 7)
83
+ return;
84
+ info.physicalScaleFactor = parseFloat(infoLineParts[6]);
85
+ if (isNaN(info.physicalScaleFactor))
86
+ info.physicalScaleFactor = -1;
87
+ if (infoLineParts.length >= 8) {
88
+ info.topRadius = parseFloat(infoLineParts[7]);
89
+ if (isNaN(info.topRadius))
90
+ info.topRadius = -1;
91
+ info.bottomRadius = info.topRadius;
92
+ }
93
+ if (infoLineParts.length >= 9) {
94
+ info.bottomRadius = parseFloat(infoLineParts[8]);
95
+ if (isNaN(info.bottomRadius))
96
+ info.bottomRadius = -1;
97
+ }
98
+ if (infoLineParts.length >= 10) {
99
+ info.sideLength = parseFloat(infoLineParts[9]);
100
+ if (isNaN(info.sideLength))
101
+ info.sideLength = -1;
102
+ }
103
+ }
104
+ }
105
+ getDecodedPreview(i) {
106
+ const info = this.getTargetInfo(i);
107
+ if (!info.preview)
108
+ return new Image();
109
+ const blob = new Blob([info.preview.compressed], { type: info.preview.mimeType });
110
+ const image = new Image();
111
+ image.src = URL.createObjectURL(blob);
112
+ return image;
113
+ }
114
+ }
115
+ exports.ImageTracker = ImageTracker;
116
+ function readLine(offset, str) {
117
+ let indx = str.indexOf("\n", offset);
118
+ return [str.substring(offset, indx >= 0 ? indx : undefined).replace("\r", ""), indx + 1];
119
+ }
package/lib/index.d.ts CHANGED
@@ -2,4 +2,4 @@ import { zappar } from "./gen/zappar";
2
2
  import { Additional } from "./additional";
3
3
  export declare type Zappar = zappar & Additional;
4
4
  export declare function initialize(): Zappar;
5
- export { zappar_image_tracker_t, zappar_instant_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 } from "./gen/zappar";
5
+ export { zappar_image_tracker_t, zappar_instant_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 } from "./gen/zappar";
@@ -0,0 +1,29 @@
1
+ import { zappar_camera_source_t, zappar_pipeline_t } from "./gen/zappar";
2
+ import { CameraFrameInfo, Source } from "./source";
3
+ export declare class MSTPCameraSource extends Source {
4
+ private _impl;
5
+ private _pipeline;
6
+ private _deviceId;
7
+ static USER_DEFAULT_DEVICE_ID: string;
8
+ static DEFAULT_DEVICE_ID: string;
9
+ private _currentStream;
10
+ private _activeDeviceId;
11
+ private _isPaused;
12
+ private _isUserFacing;
13
+ private _cameraToScreenRotation;
14
+ constructor(_impl: zappar_camera_source_t, _pipeline: zappar_pipeline_t, _deviceId: string);
15
+ destroy(): void;
16
+ private _stop;
17
+ pause(): void;
18
+ start(): void;
19
+ private _getConstraints;
20
+ getFrame(allowRead: boolean): void;
21
+ private _getUserMedia;
22
+ private _syncCamera;
23
+ private _hasStartedOrientation;
24
+ private _deviceMotionListener;
25
+ private _startDeviceOrientation;
26
+ private _startDeviceMotion;
27
+ private _stopDeviceMotion;
28
+ uploadGL(info: CameraFrameInfo): void;
29
+ }
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MSTPCameraSource = void 0;
13
+ const profile_1 = require("./profile");
14
+ const pipeline_1 = require("./pipeline");
15
+ const source_1 = require("./source");
16
+ const cameramodel_1 = require("./cameramodel");
17
+ const loglevel_1 = require("./loglevel");
18
+ const camera_source_map_1 = require("./camera-source-map");
19
+ class MSTPCameraSource extends source_1.Source {
20
+ constructor(_impl, _pipeline, _deviceId) {
21
+ super();
22
+ this._impl = _impl;
23
+ this._pipeline = _pipeline;
24
+ this._deviceId = _deviceId;
25
+ this._currentStream = null;
26
+ this._activeDeviceId = null;
27
+ this._isPaused = true;
28
+ this._isUserFacing = false;
29
+ this._cameraToScreenRotation = 0;
30
+ this._hasStartedOrientation = false;
31
+ this._deviceMotionListener = (ev) => {
32
+ let pipeline = pipeline_1.Pipeline.get(this._pipeline);
33
+ if (!pipeline)
34
+ return;
35
+ let timeStamp = (ev.timeStamp !== undefined && ev.timeStamp !== null) ? ev.timeStamp : performance.now();
36
+ if (ev.accelerationIncludingGravity !== null &&
37
+ ev.accelerationIncludingGravity.x !== null &&
38
+ ev.accelerationIncludingGravity.y !== null &&
39
+ ev.accelerationIncludingGravity.z !== null) {
40
+ pipeline.motionAccelerometerSubmit(timeStamp, ev.accelerationIncludingGravity.x * profile_1.profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.y * profile_1.profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.z * profile_1.profile.deviceMotionMutliplier);
41
+ }
42
+ if (ev.rotationRate !== null &&
43
+ ev.rotationRate.alpha !== null &&
44
+ ev.rotationRate.beta !== null &&
45
+ ev.rotationRate.gamma !== null && !this._hasStartedOrientation) {
46
+ ev.timeStamp;
47
+ pipeline.motionRotationRateSubmit(timeStamp, ev.rotationRate.alpha * Math.PI / -180.0, ev.rotationRate.beta * Math.PI / -180.0, ev.rotationRate.gamma * Math.PI / -180.0);
48
+ }
49
+ else if (!this._hasStartedOrientation) {
50
+ this._startDeviceOrientation();
51
+ }
52
+ };
53
+ loglevel_1.zcout("Using MSTP camera source");
54
+ }
55
+ destroy() {
56
+ this.pause();
57
+ camera_source_map_1.deleteCameraSource(this._impl);
58
+ }
59
+ _stop() {
60
+ if (!this._currentStream)
61
+ return;
62
+ let tracks = this._currentStream.getTracks();
63
+ tracks.forEach(t => t.stop());
64
+ this._currentStream = null;
65
+ }
66
+ pause() {
67
+ this._isPaused = true;
68
+ let p = pipeline_1.Pipeline.get(this._pipeline);
69
+ if (p && p.currentCameraSource === this)
70
+ p.currentCameraSource = undefined;
71
+ this._stopDeviceMotion();
72
+ this._syncCamera();
73
+ }
74
+ start() {
75
+ var _a;
76
+ let p = pipeline_1.Pipeline.get(this._pipeline);
77
+ if (p && p.currentCameraSource !== this) {
78
+ (_a = p.currentCameraSource) === null || _a === void 0 ? void 0 : _a.pause();
79
+ p.currentCameraSource = this;
80
+ }
81
+ this._isPaused = false;
82
+ this._startDeviceMotion();
83
+ this._syncCamera();
84
+ }
85
+ _getConstraints() {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ let deviceId;
88
+ let facingMode;
89
+ if (this._deviceId !== MSTPCameraSource.DEFAULT_DEVICE_ID &&
90
+ this._deviceId !== MSTPCameraSource.USER_DEFAULT_DEVICE_ID) {
91
+ // Custom device
92
+ deviceId = this._deviceId;
93
+ }
94
+ else {
95
+ facingMode = (this._deviceId === MSTPCameraSource.DEFAULT_DEVICE_ID) ? "environment" : "user";
96
+ }
97
+ let constraints = {
98
+ audio: false,
99
+ video: {
100
+ facingMode: facingMode,
101
+ width: profile_1.profile.videoWidth,
102
+ height: profile_1.profile.videoHeight,
103
+ frameRate: profile_1.profile.requestHighFrameRate ? 60 : 30,
104
+ deviceId: deviceId
105
+ }
106
+ };
107
+ if (deviceId)
108
+ return constraints;
109
+ if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices)
110
+ return constraints;
111
+ let devices = yield navigator.mediaDevices.enumerateDevices();
112
+ let hasHadCapabilities = false;
113
+ devices = devices.filter(val => {
114
+ // Remove non-video devices
115
+ if (val.kind !== "videoinput")
116
+ return false;
117
+ // If the media info object contains capabilities, use it to filter to the correct facing cameras
118
+ if (val.getCapabilities) {
119
+ hasHadCapabilities = true;
120
+ let capabilities = val.getCapabilities();
121
+ if (capabilities && capabilities.facingMode && capabilities.facingMode.indexOf(facingMode === "user" ? "user" : "environment") < 0)
122
+ return false;
123
+ }
124
+ return true;
125
+ });
126
+ // If none of the devices had capability info, or we have no devices left, fall back to the standard constraints
127
+ if (!hasHadCapabilities || devices.length === 0) {
128
+ return constraints;
129
+ }
130
+ if (typeof constraints.video === "object") {
131
+ loglevel_1.zcout("choosing device ID", devices[devices.length - 1].deviceId);
132
+ constraints.video.deviceId = devices[devices.length - 1].deviceId;
133
+ }
134
+ return constraints;
135
+ });
136
+ }
137
+ getFrame(allowRead) {
138
+ var _a, _b;
139
+ let rotation = cameramodel_1.cameraRotationForScreenOrientation(false);
140
+ if (rotation != this._cameraToScreenRotation) {
141
+ (_b = (_a = pipeline_1.Pipeline.get(this._pipeline)) === null || _a === void 0 ? void 0 : _a.sendCameraToScreenRotationToWorker) === null || _b === void 0 ? void 0 : _b.call(_a, rotation);
142
+ this._cameraToScreenRotation = rotation;
143
+ }
144
+ return;
145
+ }
146
+ _getUserMedia() {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ let constraints = yield this._getConstraints();
149
+ if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia)
150
+ return yield navigator.mediaDevices.getUserMedia(constraints);
151
+ return yield new Promise((resolve, reject) => {
152
+ navigator.getUserMedia(constraints, resolve, reject);
153
+ });
154
+ });
155
+ }
156
+ _syncCamera() {
157
+ return __awaiter(this, void 0, void 0, function* () {
158
+ if (this._currentStream && this._isPaused) {
159
+ this._stop();
160
+ return;
161
+ }
162
+ if (this._currentStream && this._activeDeviceId !== this._deviceId)
163
+ this._stop();
164
+ if (!this._isPaused) {
165
+ this._activeDeviceId = this._deviceId;
166
+ this._currentStream = yield this._getUserMedia();
167
+ if (this._isPaused) {
168
+ yield this._syncCamera();
169
+ return;
170
+ }
171
+ this._isUserFacing = false;
172
+ if (this._currentStream) {
173
+ let videoTracks = this._currentStream.getVideoTracks();
174
+ if (videoTracks.length > 0) {
175
+ this._isUserFacing = videoTracks[0].getSettings().facingMode === "user";
176
+ let processor = new MediaStreamTrackProcessor({
177
+ track: videoTracks[0]
178
+ });
179
+ let p = pipeline_1.Pipeline.get(this._pipeline);
180
+ if (p)
181
+ p.sendCameraStreamToWorker(this._impl, processor.readable, this._isUserFacing);
182
+ }
183
+ }
184
+ }
185
+ });
186
+ }
187
+ _startDeviceOrientation() {
188
+ if (this._hasStartedOrientation)
189
+ return;
190
+ this._hasStartedOrientation = true;
191
+ window.addEventListener("deviceorientation", (ev) => {
192
+ let pipeline = pipeline_1.Pipeline.get(this._pipeline);
193
+ if (!pipeline)
194
+ return;
195
+ let timeStamp = (ev.timeStamp !== undefined && ev.timeStamp !== null) ? ev.timeStamp : performance.now();
196
+ if (ev.alpha === null || ev.beta === null || ev.gamma === null)
197
+ return;
198
+ pipeline.motionAttitudeSubmit(timeStamp, ev.alpha, ev.beta, ev.gamma);
199
+ });
200
+ }
201
+ _startDeviceMotion() {
202
+ window.addEventListener("devicemotion", this._deviceMotionListener, false);
203
+ }
204
+ _stopDeviceMotion() {
205
+ window.removeEventListener("devicemotion", this._deviceMotionListener);
206
+ }
207
+ uploadGL(info) {
208
+ const pipeline = pipeline_1.Pipeline.get(this._pipeline);
209
+ const gl = pipeline === null || pipeline === void 0 ? void 0 : pipeline.glContext;
210
+ if (!info ||
211
+ info.texture ||
212
+ !info.frame ||
213
+ !pipeline ||
214
+ !gl)
215
+ return;
216
+ let texture = pipeline.getVideoTexture();
217
+ if (!texture)
218
+ return;
219
+ gl.bindTexture(gl.TEXTURE_2D, texture);
220
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
221
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, info.frame);
222
+ gl.bindTexture(gl.TEXTURE_2D, null);
223
+ info.texture = texture;
224
+ info.frame.close();
225
+ delete info.frame;
226
+ }
227
+ }
228
+ exports.MSTPCameraSource = MSTPCameraSource;
229
+ MSTPCameraSource.USER_DEFAULT_DEVICE_ID = "Simulated User Default Device ID: a908df7f-5661-4d20-b227-a1c15d2fdb4b";
230
+ MSTPCameraSource.DEFAULT_DEVICE_ID = "Simulated Default Device ID: a908df7f-5661-4d20-b227-a1c15d2fdb4b";
package/lib/native.js CHANGED
@@ -23,6 +23,10 @@ const html_element_source_1 = require("./html-element-source");
23
23
  const facelandmark_1 = require("./facelandmark");
24
24
  const compatibility_1 = require("./compatibility");
25
25
  const loglevel_1 = require("./loglevel");
26
+ const sequencesource_1 = require("./sequencesource");
27
+ const camera_source_map_1 = require("./camera-source-map");
28
+ const gfx_1 = require("./gfx");
29
+ const imagetracker_1 = require("./imagetracker");
26
30
  let client;
27
31
  function initialize() {
28
32
  if (client)
@@ -44,7 +48,7 @@ function initialize() {
44
48
  c.impl.analytics_project_id_set(".wiz" + pathParts[1]);
45
49
  }
46
50
  worker_client_1.messageManager.onIncomingMessage.bind(msg => {
47
- var _a, _b;
51
+ var _a, _b, _c, _d, _e, _f, _g;
48
52
  switch (msg.t) {
49
53
  case "zappar":
50
54
  (_a = pipeline_1.Pipeline.get(msg.p)) === null || _a === void 0 ? void 0 : _a.pendingMessages.push(msg.d);
@@ -52,10 +56,21 @@ function initialize() {
52
56
  case "buf":
53
57
  c.serializer.bufferReturn(msg.d);
54
58
  break;
55
- case "cameraFrameRecycleS2C":
59
+ case "cameraFrameRecycleS2C": {
56
60
  let msgt = msg;
57
- (_b = pipeline_1.Pipeline.get(msgt.p)) === null || _b === void 0 ? void 0 : _b.cameraTokenReturn(msgt.token, msgt.d);
61
+ (_c = (_b = pipeline_1.Pipeline.get(msgt.p)) === null || _b === void 0 ? void 0 : _b.cameraTokenReturn) === null || _c === void 0 ? void 0 : _c.call(_b, msg);
58
62
  break;
63
+ }
64
+ case "videoFrameS2C": {
65
+ let msgt = msg;
66
+ (_e = (_d = pipeline_1.Pipeline.get(msgt.p)) === null || _d === void 0 ? void 0 : _d.videoFrameFromWorker) === null || _e === void 0 ? void 0 : _e.call(_d, msgt);
67
+ break;
68
+ }
69
+ case "imageBitmapS2C": {
70
+ let msgt = msg;
71
+ (_g = (_f = pipeline_1.Pipeline.get(msgt.p)) === null || _f === void 0 ? void 0 : _f.imageBitmapFromWorker) === null || _g === void 0 ? void 0 : _g.call(_f, msgt);
72
+ break;
73
+ }
59
74
  case "licerr": {
60
75
  let div = document.createElement("div");
61
76
  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.";
@@ -81,9 +96,31 @@ function initialize() {
81
96
  }, 1000);
82
97
  document.body.append(div);
83
98
  }
99
+ case "gfx": {
100
+ let div = document.createElement("div");
101
+ div.innerHTML = gfx_1.gfx;
102
+ div.style.position = "absolute";
103
+ div.style.bottom = "20px";
104
+ div.style.width = "250px";
105
+ div.style.left = "50%";
106
+ div.style.marginLeft = "-125px";
107
+ div.style.zIndex = Number.MAX_SAFE_INTEGER.toString();
108
+ div.style.opacity = "0";
109
+ div.style.transition = "opacity 0.5s";
110
+ document.body.append(div);
111
+ setTimeout(function () {
112
+ div.style.opacity = "1";
113
+ }, 500);
114
+ setTimeout(function () {
115
+ div.style.opacity = "0";
116
+ }, 3000);
117
+ setTimeout(function () {
118
+ div.remove();
119
+ }, 4000);
120
+ }
84
121
  }
85
122
  });
86
- client = Object.assign(Object.assign({}, c.impl), { loaded: () => loaded, camera_default_device_id: userFacing => userFacing ? camera_source_1.CameraSource.USER_DEFAULT_DEVICE_ID : camera_source_1.CameraSource.DEFAULT_DEVICE_ID, camera_source_create: (p, deviceId) => camera_source_1.CameraSource.create(p, deviceId), camera_source_destroy: cam => { var _a; return (_a = camera_source_1.CameraSource.get(cam)) === null || _a === void 0 ? void 0 : _a.destroy(); }, camera_source_pause: cam => { var _a; return (_a = camera_source_1.CameraSource.get(cam)) === null || _a === void 0 ? void 0 : _a.pause(); }, camera_source_start: cam => { var _a; return (_a = camera_source_1.CameraSource.get(cam)) === null || _a === void 0 ? void 0 : _a.start(); }, pipeline_create: () => pipeline_1.Pipeline.create(c.impl, worker_client_1.messageManager), pipeline_frame_update: (p) => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.frameUpdate(c); }, pipeline_camera_frame_draw_gl: (pipeline, screenWidth, screenHeight, mirror) => {
123
+ client = Object.assign(Object.assign({}, c.impl), { loaded: () => loaded, camera_default_device_id: userFacing => userFacing ? camera_source_1.CameraSource.USER_DEFAULT_DEVICE_ID : camera_source_1.CameraSource.DEFAULT_DEVICE_ID, camera_source_create: (p, deviceId) => camera_source_map_1.createCameraSource(p, deviceId), camera_source_destroy: cam => { var _a; return (_a = camera_source_map_1.getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.destroy(); }, camera_source_pause: cam => { var _a; return (_a = camera_source_map_1.getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.pause(); }, camera_source_start: cam => { var _a; return (_a = camera_source_map_1.getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.start(); }, pipeline_create: () => pipeline_1.Pipeline.create(c.impl, worker_client_1.messageManager), pipeline_frame_update: (p) => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.frameUpdate(c); }, pipeline_camera_frame_draw_gl: (pipeline, screenWidth, screenHeight, mirror) => {
87
124
  var _a;
88
125
  (_a = pipeline_1.Pipeline.get(pipeline)) === null || _a === void 0 ? void 0 : _a.cameraFrameDrawGL(screenWidth, screenHeight, mirror);
89
126
  }, draw_plane: (gl, projectionMatrix, cameraMatrix, targetMatrix, texture) => {
@@ -99,7 +136,7 @@ function initialize() {
99
136
  }, pipeline_draw_face_project: (p, matrix, vertices, uvMatrix, uvs, indices, texture) => {
100
137
  var _a;
101
138
  (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.drawFaceProject(matrix, vertices, uvMatrix, uvs, indices, texture);
102
- }, projection_matrix_from_camera_model: cameramodel_1.projectionMatrix, projection_matrix_from_camera_model_ext: cameramodel_1.projectionMatrix, pipeline_process_gl: p => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.processGL(); }, pipeline_gl_context_set: (p, gl, texturePool) => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.glContextSet(gl, texturePool); }, pipeline_gl_context_lost: (p) => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.glContextLost(); }, pipeline_camera_frame_upload_gl: () => { }, pipeline_camera_frame_texture_gl: p => { var _a; return (_a = pipeline_1.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_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameTextureMatrix(sw, sh, mirror)) || gl_matrix_1.mat4.create(); }, pipeline_camera_frame_user_facing: p => { var _a; return ((_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameUserFacing()) || false; }, pipeline_camera_pose_default: () => gl_matrix_1.mat4.create(), pipeline_camera_pose_with_attitude: (p, mirror) => { var _a; return ((_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraPoseWithAttitude(mirror)) || gl_matrix_1.mat4.create(); }, pipeline_camera_pose_with_origin: (p, o) => { let res = gl_matrix_1.mat4.create(); gl_matrix_1.mat4.invert(res, o); return res; }, instant_world_tracker_anchor_pose_camera_relative: (o, mirror) => {
139
+ }, projection_matrix_from_camera_model: cameramodel_1.projectionMatrix, projection_matrix_from_camera_model_ext: cameramodel_1.projectionMatrix, pipeline_process_gl: p => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.processGL(); }, pipeline_gl_context_set: (p, gl, texturePool) => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.glContextSet(gl, texturePool); }, pipeline_gl_context_lost: (p) => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.glContextLost(); }, pipeline_camera_frame_upload_gl: p => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.uploadGL(); }, pipeline_camera_frame_texture_gl: p => { var _a; return (_a = pipeline_1.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_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameTextureMatrix(sw, sh, mirror)) || gl_matrix_1.mat4.create(); }, pipeline_camera_frame_user_facing: p => { var _a; return ((_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameUserFacing()) || false; }, pipeline_camera_pose_default: () => gl_matrix_1.mat4.create(), pipeline_camera_pose_with_attitude: (p, mirror) => { var _a; return ((_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraPoseWithAttitude(mirror)) || gl_matrix_1.mat4.create(); }, pipeline_camera_pose_with_origin: (p, o) => { let res = gl_matrix_1.mat4.create(); gl_matrix_1.mat4.invert(res, o); return res; }, pipeline_sequence_record_clear: p => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordClear(); }, pipeline_sequence_record_start: (p, expectedFrames) => { var _a; return (_a = pipeline_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordStart(expectedFrames); }, pipeline_sequence_record_stop: p => { var _a; return (_a = pipeline_1.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_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordDeviceAttitudeMatrices(v); }, pipeline_sequence_record_data: p => { var _a; return ((_a = pipeline_1.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_1.Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordData().byteLength) || 0; }, instant_world_tracker_anchor_pose_camera_relative: (o, mirror) => {
103
140
  let res = pipeline_1.applyScreenCounterRotation(undefined, c.impl.instant_world_tracker_anchor_pose_raw(o));
104
141
  if (mirror) {
105
142
  let scale = gl_matrix_1.mat4.create();
@@ -118,6 +155,92 @@ function initialize() {
118
155
  }
119
156
  gl_matrix_1.mat4.multiply(res, cameraPose, res);
120
157
  return res;
158
+ }, instant_world_tracker_anchor_pose_set_from_camera_offset: (o, x, y, z, orientation) => {
159
+ // TODO - add an _ext function if we need to support mirrored cameras with an extra param
160
+ // if(mirror) {
161
+ // x *= -1;
162
+ // }
163
+ // TODO - can we access the appropriate pipeline here to call pipeline_camera_frame_user_facing(p)?
164
+ let userFacing = false;
165
+ let rotation = cameramodel_1.cameraRotationForScreenOrientation(userFacing) * Math.PI / 180.0;
166
+ let rotationMat = gl_matrix_1.mat4.create();
167
+ gl_matrix_1.mat4.fromRotation(rotationMat, -rotation, [0, 0, 1]);
168
+ let rawVec = gl_matrix_1.vec3.create();
169
+ gl_matrix_1.vec3.transformMat4(rawVec, [x, y, z], rotationMat);
170
+ c.impl.instant_world_tracker_anchor_pose_set_from_camera_offset_raw(o, rawVec[0], rawVec[1], rawVec[2], orientation);
171
+ }, image_tracker_create: pipeline => imagetracker_1.ImageTracker.create(pipeline, c.impl), image_tracker_destroy: t => { var _a; return (_a = imagetracker_1.ImageTracker.get(t)) === null || _a === void 0 ? void 0 : _a.destroy(); }, image_tracker_target_count: t => {
172
+ let obj = imagetracker_1.ImageTracker.get(t);
173
+ if (!obj) {
174
+ loglevel_1.zcwarn("attempting to call image_tracker_target_count on a destroyed zappar_image_tracker_t");
175
+ return 0;
176
+ }
177
+ return obj.targetCount();
178
+ }, image_tracker_target_load_from_memory: (t, data) => {
179
+ let obj = imagetracker_1.ImageTracker.get(t);
180
+ if (!obj) {
181
+ loglevel_1.zcwarn("attempting to call image_tracker_target_load_from_memory on a destroyed zappar_image_tracker_t");
182
+ return 0;
183
+ }
184
+ obj.loadFromMemory(data);
185
+ }, image_tracker_target_preview_compressed: (t, i) => {
186
+ var _a;
187
+ let obj = imagetracker_1.ImageTracker.get(t);
188
+ if (!obj) {
189
+ loglevel_1.zcwarn("attempting to call image_tracker_target_preview_compressed on a destroyed zappar_image_tracker_t");
190
+ return new Uint8Array(0);
191
+ }
192
+ return ((_a = obj.getTargetInfo(i).preview) === null || _a === void 0 ? void 0 : _a.compressed) || new Uint8Array(0);
193
+ }, image_tracker_target_preview_compressed_mimetype: (t, i) => {
194
+ var _a;
195
+ let obj = imagetracker_1.ImageTracker.get(t);
196
+ if (!obj) {
197
+ loglevel_1.zcwarn("attempting to call image_tracker_target_preview_compressed_mimetype on a destroyed zappar_image_tracker_t");
198
+ return "";
199
+ }
200
+ return ((_a = obj.getTargetInfo(i).preview) === null || _a === void 0 ? void 0 : _a.mimeType) || "";
201
+ }, image_tracker_target_preview_compressed_size: (t, i) => {
202
+ var _a, _b;
203
+ let obj = imagetracker_1.ImageTracker.get(t);
204
+ if (!obj) {
205
+ loglevel_1.zcwarn("attempting to call image_tracker_target_preview_compressed_size on a destroyed zappar_image_tracker_t");
206
+ return 0;
207
+ }
208
+ return ((_b = (_a = obj.getTargetInfo(i).preview) === null || _a === void 0 ? void 0 : _a.compressed) === null || _b === void 0 ? void 0 : _b.byteLength) || 0;
209
+ }, image_tracker_target_physical_scale_factor: (t, i) => {
210
+ let obj = imagetracker_1.ImageTracker.get(t);
211
+ if (!obj) {
212
+ loglevel_1.zcwarn("attempting to call image_tracker_target_physical_scale_factor on a destroyed zappar_image_tracker_t");
213
+ return 0;
214
+ }
215
+ return obj.getTargetInfo(i).physicalScaleFactor;
216
+ }, image_tracker_target_radius_top: (t, i) => {
217
+ let obj = imagetracker_1.ImageTracker.get(t);
218
+ if (!obj) {
219
+ loglevel_1.zcwarn("attempting to call image_tracker_target_radius_top on a destroyed zappar_image_tracker_t");
220
+ return 0;
221
+ }
222
+ return obj.getTargetInfo(i).topRadius;
223
+ }, image_tracker_target_radius_bottom: (t, i) => {
224
+ let obj = imagetracker_1.ImageTracker.get(t);
225
+ if (!obj) {
226
+ loglevel_1.zcwarn("attempting to call image_tracker_target_radius_bottom on a destroyed zappar_image_tracker_t");
227
+ return 0;
228
+ }
229
+ return obj.getTargetInfo(i).bottomRadius;
230
+ }, image_tracker_target_side_length: (t, i) => {
231
+ let obj = imagetracker_1.ImageTracker.get(t);
232
+ if (!obj) {
233
+ loglevel_1.zcwarn("attempting to call image_tracker_target_side_length on a destroyed zappar_image_tracker_t");
234
+ return 0;
235
+ }
236
+ return obj.getTargetInfo(i).sideLength;
237
+ }, image_tracker_target_image: (t, i) => {
238
+ let obj = imagetracker_1.ImageTracker.get(t);
239
+ if (!obj) {
240
+ loglevel_1.zcwarn("attempting to call image_tracker_target_image on a destroyed zappar_image_tracker_t");
241
+ return new Image();
242
+ }
243
+ return obj.getDecodedPreview(i);
121
244
  }, image_tracker_anchor_pose_camera_relative: (o, indx, mirror) => {
122
245
  let res = pipeline_1.applyScreenCounterRotation(undefined, c.impl.image_tracker_anchor_pose_raw(o, indx));
123
246
  if (mirror) {
@@ -290,7 +413,7 @@ function initialize() {
290
413
  return gl_matrix_1.mat4.create();
291
414
  }
292
415
  return obj.anchor_pose;
293
- }, html_element_source_create: (pipeline, elm) => html_element_source_1.HTMLElementSource.createVideoElementSource(pipeline, elm), html_element_source_start: o => { var _a; return (_a = html_element_source_1.HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.start(); }, html_element_source_pause: o => { var _a; return (_a = html_element_source_1.HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, html_element_source_destroy: o => { var _a; return (_a = html_element_source_1.HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, permission_granted_all: permission_1.permissionGrantedAll, permission_granted_camera: permission_1.permissionGrantedCamera, permission_granted_motion: permission_1.permissionGrantedMotion, permission_denied_any: permission_1.permissionDeniedAny, permission_denied_camera: permission_1.permissionDeniedCamera, permission_denied_motion: permission_1.permissionDeniedMotion, permission_request_motion: permission_1.permissionRequestMotion, permission_request_camera: permission_1.permissionRequestCamera, permission_request_all: permission_1.permissionRequestAll, permission_request_ui: permission_1.permissionRequestUI, permission_request_ui_promise: permission_1.permissionRequestUI, permission_denied_ui: permission_1.permissionDeniedUI, browser_incompatible: compatibility_1.default.incompatible, browser_incompatible_ui: compatibility_1.default.incompatible_ui, log_level_set: l => {
416
+ }, html_element_source_create: (pipeline, elm) => html_element_source_1.HTMLElementSource.createVideoElementSource(pipeline, elm), html_element_source_start: o => { var _a; return (_a = html_element_source_1.HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.start(); }, html_element_source_pause: o => { var _a; return (_a = html_element_source_1.HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, html_element_source_destroy: o => { var _a; return (_a = html_element_source_1.HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, sequence_source_create: p => sequencesource_1.SequenceSource.create(p), sequence_source_load_from_memory: (o, data) => { var _a; return (_a = sequencesource_1.SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.loadFromMemory(data); }, sequence_source_pause: o => { var _a; return (_a = sequencesource_1.SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, sequence_source_start: o => { var _a; return (_a = sequencesource_1.SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.start(); }, sequence_source_max_playback_fps_set: (o, fps) => { var _a; return (_a = sequencesource_1.SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.maxPlaybackFpsSet(fps); }, sequence_source_destroy: o => { var _a; return (_a = sequencesource_1.SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, permission_granted_all: permission_1.permissionGrantedAll, permission_granted_camera: permission_1.permissionGrantedCamera, permission_granted_motion: permission_1.permissionGrantedMotion, permission_denied_any: permission_1.permissionDeniedAny, permission_denied_camera: permission_1.permissionDeniedCamera, permission_denied_motion: permission_1.permissionDeniedMotion, permission_request_motion: permission_1.permissionRequestMotion, permission_request_camera: permission_1.permissionRequestCamera, permission_request_all: permission_1.permissionRequestAll, permission_request_ui: permission_1.permissionRequestUI, permission_request_ui_promise: permission_1.permissionRequestUI, permission_denied_ui: permission_1.permissionDeniedUI, browser_incompatible: compatibility_1.default.incompatible, browser_incompatible_ui: compatibility_1.default.incompatible_ui, log_level_set: l => {
294
417
  loglevel_1.setLogLevel(l);
295
418
  c.impl.log_level_set(l);
296
419
  } });
package/lib/pipeline.d.ts CHANGED
@@ -1,9 +1,11 @@
1
- import { zappar_pipeline_t } from "./gen/zappar";
1
+ /// <reference types="dom-webcodecs" />
2
+ import { zappar_pipeline_t, zappar_camera_source_t } from "./gen/zappar";
2
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 { mat4 } from "gl-matrix";
6
7
  import { Source, CameraFrameInfo } from "./source";
8
+ import { CameraFrameReturnS2C, ImageBitmapS2C, VideoFrameS2C } from "./workerinterface";
7
9
  import { FaceMesh } from "./facemesh";
8
10
  import { Event } from "./event";
9
11
  export declare class Pipeline {
@@ -21,12 +23,21 @@ export declare class Pipeline {
21
23
  private _cameraDraw;
22
24
  private _faceDraw;
23
25
  private _faceProjectDraw;
26
+ private _sequenceRecorder;
27
+ private _sequenceRecordDeviceAttitudeMatrices;
28
+ private _sequenceRecorderFirstCameraToken;
24
29
  onGLContextReset: Event;
25
30
  static create(client: zappar_cwrap, mgr: MsgManager): zappar_pipeline_t;
26
31
  static get(p: zappar_pipeline_t): Pipeline | undefined;
27
32
  private constructor();
28
33
  frameUpdate(client: zappar_client): void;
29
- cameraTokenReturn(tokenId: number, pixelArray: ArrayBuffer): void;
34
+ cleanOldFrames(): void;
35
+ cameraTokenReturn(msg: CameraFrameReturnS2C): void;
36
+ sequenceRecordStart(expectedFrames: number): void;
37
+ sequenceRecordStop(): void;
38
+ sequenceRecordData(): Uint8Array;
39
+ sequenceRecordClear(): void;
40
+ sequenceRecordDeviceAttitudeMatrices(v: boolean): void;
30
41
  getVideoTexture(): WebGLTexture | undefined;
31
42
  destroy(): void;
32
43
  getCurrentCameraInfo(): CameraFrameInfo | undefined;
@@ -39,9 +50,18 @@ export declare class Pipeline {
39
50
  cameraFrameTextureMatrix(sw: number, sh: number, mirror: boolean): Float32Array;
40
51
  cameraFrameUserFacing(): boolean;
41
52
  cameraPoseWithAttitude(mirror: boolean): Float32Array;
53
+ videoFrameFromWorker(msg: VideoFrameS2C): void;
54
+ imageBitmapFromWorker(msg: ImageBitmapS2C): void;
55
+ uploadGL(): void;
56
+ registerToken(info: CameraFrameInfo): number;
42
57
  processGL(): void;
43
58
  motionAccelerometerSubmit(timestamp: number, x: number, y: number, z: number): void;
44
59
  motionRotationRateSubmit(timestamp: number, x: number, y: number, z: number): void;
45
60
  motionAttitudeSubmit(timestamp: number, x: number, y: number, z: number): void;
61
+ motionAttitudeMatrix(m: Float32Array): void;
62
+ sendCameraStreamToWorker(source: zappar_camera_source_t, stream: ReadableStream<VideoFrame>, userFacing: boolean): void;
63
+ sendCameraToScreenRotationToWorker(rot: number): void;
64
+ sendImageBitmapToWorker(img: ImageBitmap, rot: number, userFacing: boolean, tokenId: number, cameraModel: Float32Array, cameraToDevice: Float32Array): void;
65
+ sendDataToWorker(data: ArrayBuffer, token: number, width: number, height: number, userFacing: boolean, cameraToDevice: Float32Array, cameraModel: Float32Array): void;
46
66
  }
47
67
  export declare function applyScreenCounterRotation(info: CameraFrameInfo | undefined, inp: Float32Array): mat4;