@zappar/zappar-cv 3.0.1-beta.8 → 3.1.0-beta.2

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 (41) hide show
  1. package/README.md +2 -2
  2. package/lib/additional.d.ts +1 -0
  3. package/lib/android-bridge-message-handler.d.ts +11 -0
  4. package/lib/android-bridge-message-handler.js +167 -0
  5. package/lib/array-from-string.d.ts +2 -0
  6. package/lib/array-from-string.js +48 -0
  7. package/lib/bridged-camera-source.d.ts +39 -0
  8. package/lib/bridged-camera-source.js +383 -0
  9. package/lib/bridged-message-parser.d.ts +12 -0
  10. package/lib/bridged-message-parser.js +56 -0
  11. package/lib/bridged-message.d.ts +64 -0
  12. package/lib/bridged-message.js +1 -0
  13. package/lib/bridged-world-tracker.d.ts +20 -0
  14. package/lib/bridged-world-tracker.js +426 -0
  15. package/lib/camera-source-map.d.ts +2 -1
  16. package/lib/camera-source-map.js +4 -1
  17. package/lib/drawmesh.d.ts +14 -0
  18. package/lib/drawmesh.js +123 -0
  19. package/lib/gen/zappar-client.js +12 -0
  20. package/lib/gen/zappar.d.ts +16 -0
  21. package/lib/index-standalone.js +1 -1
  22. package/lib/native.js +61 -15
  23. package/lib/options.d.ts +1 -0
  24. package/lib/permission.js +6 -0
  25. package/lib/pipeline.js +2 -1
  26. package/lib/profile.js +2 -1
  27. package/lib/source.d.ts +1 -0
  28. package/lib/version.d.ts +1 -1
  29. package/lib/version.js +1 -1
  30. package/lib/yuv-conversion-gl.d.ts +44 -0
  31. package/lib/yuv-conversion-gl.js +416 -0
  32. package/lib/zappar-cv.js +1 -1
  33. package/lib/zappar-cv.wasm +0 -0
  34. package/package.json +6 -16
  35. package/umd/287.zappar-cv.js +1 -0
  36. package/umd/{7fd693559466ec5f412e.wasm → 641e1456d6d56783d581.wasm} +0 -0
  37. package/umd/867.zappar-cv.js +1 -1
  38. package/umd/zappar-cv-ceres.worker.js +1 -0
  39. package/umd/zappar-cv.js +1 -1
  40. package/umd/zappar-cv.worker.js +1 -1
  41. package/umd/751.zappar-cv.js +0 -1
@@ -0,0 +1,123 @@
1
+ import { compileShader, linkProgram } from "./shader";
2
+ export class MeshDraw {
3
+ constructor(_gl) {
4
+ this._gl = _gl;
5
+ }
6
+ dispose() {
7
+ if (this._vbo)
8
+ this._gl.deleteBuffer(this._vbo);
9
+ if (this._uvbo)
10
+ this._gl.deleteBuffer(this._uvbo);
11
+ if (this._ibo)
12
+ this._gl.deleteBuffer(this._ibo);
13
+ if (this._shader)
14
+ this._gl.deleteProgram(this._shader.prog);
15
+ this._vbo = undefined;
16
+ this._uvbo = undefined;
17
+ this._ibo = undefined;
18
+ this._shader = undefined;
19
+ }
20
+ _generateIBO(indices, gl) {
21
+ if (this._ibo && this._lastIndices === indices)
22
+ return this._ibo;
23
+ this._lastIndices = indices;
24
+ if (!this._ibo)
25
+ this._ibo = gl.createBuffer();
26
+ if (!this._ibo)
27
+ throw new Error("Unable to create buffer object");
28
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._ibo);
29
+ gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.DYNAMIC_DRAW);
30
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
31
+ return this._ibo;
32
+ }
33
+ _generateVBO(face, gl) {
34
+ if (!this._vbo)
35
+ this._vbo = gl.createBuffer();
36
+ if (!this._vbo)
37
+ throw new Error("Unable to create buffer object");
38
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._vbo);
39
+ gl.bufferData(gl.ARRAY_BUFFER, face, gl.DYNAMIC_DRAW);
40
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
41
+ return this._vbo;
42
+ }
43
+ draw(projectionMatrix, cameraMatrix, targetMatrix, vertices, indices, vertexOffset, vertexStride, indicesCount) {
44
+ let gl = this._gl;
45
+ let shader = this._getShader(gl);
46
+ let v = this._generateVBO(vertices, gl);
47
+ let i = this._generateIBO(indices, gl);
48
+ gl.disable(gl.DEPTH_TEST);
49
+ gl.disable(gl.CULL_FACE);
50
+ gl.useProgram(shader.prog);
51
+ gl.uniformMatrix4fv(shader.unif_proj, false, projectionMatrix);
52
+ gl.uniformMatrix4fv(shader.unif_camera, false, cameraMatrix);
53
+ gl.uniformMatrix4fv(shader.unif_matrix, false, targetMatrix);
54
+ gl.bindBuffer(gl.ARRAY_BUFFER, v);
55
+ gl.vertexAttribPointer(shader.attr_position, 3, gl.FLOAT, false, vertexStride, vertexOffset);
56
+ gl.enableVertexAttribArray(shader.attr_position);
57
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, i);
58
+ gl.drawElements(gl.LINE_STRIP, indicesCount, gl.UNSIGNED_INT, 0);
59
+ gl.disableVertexAttribArray(shader.attr_position);
60
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
61
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
62
+ }
63
+ _getShader(gl) {
64
+ if (this._shader)
65
+ return this._shader;
66
+ let prog = gl.createProgram();
67
+ if (!prog)
68
+ throw new Error("Unable to create program");
69
+ let vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSrc);
70
+ let fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSrc);
71
+ gl.attachShader(prog, vertexShader);
72
+ gl.attachShader(prog, fragmentShader);
73
+ linkProgram(gl, prog);
74
+ let unif_proj = gl.getUniformLocation(prog, "projMatrix");
75
+ if (!unif_proj)
76
+ throw new Error("Unable to get uniform location projMatrix");
77
+ let unif_matrix = gl.getUniformLocation(prog, "modelViewMatrix");
78
+ if (!unif_matrix)
79
+ throw new Error("Unable to get uniform location modelViewMatrix");
80
+ let unif_camera = gl.getUniformLocation(prog, "cameraMatrix");
81
+ if (!unif_camera)
82
+ throw new Error("Unable to get uniform location cameraMatrix");
83
+ this._shader = {
84
+ prog,
85
+ unif_matrix,
86
+ unif_camera,
87
+ unif_proj,
88
+ attr_position: gl.getAttribLocation(prog, "position"),
89
+ };
90
+ return this._shader;
91
+ }
92
+ }
93
+ let vertexShaderSrc = `
94
+ #ifndef GL_ES
95
+ #define highp
96
+ #define mediump
97
+ #define lowp
98
+ #endif
99
+
100
+ uniform mat4 projMatrix;
101
+ uniform mat4 cameraMatrix;
102
+ uniform mat4 modelViewMatrix;
103
+ attribute vec4 position;
104
+
105
+ void main()
106
+ {
107
+ gl_Position = projMatrix * cameraMatrix * modelViewMatrix * position;
108
+ }`;
109
+ let fragmentShaderSrc = `
110
+ #define highp mediump
111
+ #ifdef GL_ES
112
+ // define default precision for float, vec, mat.
113
+ precision highp float;
114
+ #else
115
+ #define highp
116
+ #define mediump
117
+ #define lowp
118
+ #endif
119
+
120
+ void main()
121
+ {
122
+ gl_FragColor = vec4(1.0, 0.0, 0.0, 0.5);
123
+ }`;
@@ -325,6 +325,7 @@ export class zappar_client {
325
325
  m.type(o);
326
326
  m.bool(enabled);
327
327
  });
328
+ s.enabled = enabled;
328
329
  },
329
330
  image_tracker_anchor_count: (o) => {
330
331
  let s = this._image_tracker_state_by_instance.get(o);
@@ -396,6 +397,7 @@ export class zappar_client {
396
397
  m.type(o);
397
398
  m.bool(enabled);
398
399
  });
400
+ s.enabled = enabled;
399
401
  },
400
402
  face_tracker_enabled: (o) => {
401
403
  let s = this._face_tracker_state_by_instance.get(o);
@@ -411,6 +413,7 @@ export class zappar_client {
411
413
  m.type(o);
412
414
  m.int(num);
413
415
  });
416
+ s.max_faces = num;
414
417
  },
415
418
  face_tracker_max_faces: (o) => {
416
419
  let s = this._face_tracker_state_by_instance.get(o);
@@ -521,6 +524,7 @@ export class zappar_client {
521
524
  m.type(o);
522
525
  m.bool(enabled);
523
526
  });
527
+ s.enabled = enabled;
524
528
  },
525
529
  barcode_finder_enabled: (o) => {
526
530
  let s = this._barcode_finder_state_by_instance.get(o);
@@ -560,6 +564,7 @@ export class zappar_client {
560
564
  m.type(o);
561
565
  m.barcodeFormat(f);
562
566
  });
567
+ s.formats = f;
563
568
  },
564
569
  // #### instant_world_tracker ####
565
570
  instant_world_tracker_create: (pipeline) => {
@@ -592,6 +597,7 @@ export class zappar_client {
592
597
  m.type(o);
593
598
  m.bool(enabled);
594
599
  });
600
+ s.enabled = enabled;
595
601
  },
596
602
  instant_world_tracker_enabled: (o) => {
597
603
  let s = this._instant_world_tracker_state_by_instance.get(o);
@@ -672,6 +678,7 @@ export class zappar_client {
672
678
  m.type(o);
673
679
  m.bool(enabled);
674
680
  });
681
+ s.enabled = enabled;
675
682
  },
676
683
  zapcode_tracker_anchor_count: (o) => {
677
684
  let s = this._zapcode_tracker_state_by_instance.get(o);
@@ -752,6 +759,7 @@ export class zappar_client {
752
759
  m.type(o);
753
760
  m.bool(enabled);
754
761
  });
762
+ s.enabled = enabled;
755
763
  },
756
764
  world_tracker_quality: (o) => {
757
765
  let s = this._world_tracker_state_by_instance.get(o);
@@ -773,6 +781,7 @@ export class zappar_client {
773
781
  m.type(o);
774
782
  m.bool(horizontal_plane_detection_enabled);
775
783
  });
784
+ s.horizontal_plane_detection_enabled = horizontal_plane_detection_enabled;
776
785
  },
777
786
  world_tracker_vertical_plane_detection_enabled: (o) => {
778
787
  let s = this._world_tracker_state_by_instance.get(o);
@@ -788,6 +797,7 @@ export class zappar_client {
788
797
  m.type(o);
789
798
  m.bool(vertical_plane_detection_enabled);
790
799
  });
800
+ s.vertical_plane_detection_enabled = vertical_plane_detection_enabled;
791
801
  },
792
802
  world_tracker_plane_anchor_count: (o) => {
793
803
  let s = this._world_tracker_state_by_instance.get(o);
@@ -895,6 +905,7 @@ export class zappar_client {
895
905
  m.type(o);
896
906
  m.bool(tracks_data_enabled);
897
907
  });
908
+ s.tracks_data_enabled = tracks_data_enabled;
898
909
  },
899
910
  world_tracker_tracks_data_size: (o) => {
900
911
  let s = this._world_tracker_state_by_instance.get(o);
@@ -934,6 +945,7 @@ export class zappar_client {
934
945
  m.type(o);
935
946
  m.bool(projections_data_enabled);
936
947
  });
948
+ s.projections_data_enabled = projections_data_enabled;
937
949
  },
938
950
  world_tracker_projections_data_size: (o) => {
939
951
  let s = this._world_tracker_state_by_instance.get(o);
@@ -252,6 +252,22 @@ export interface zappar {
252
252
  world_tracker_projections_data_enabled_set(o: zappar_world_tracker_t, projections_data_enabled: boolean): void;
253
253
  world_tracker_projections_data_size(o: zappar_world_tracker_t): number;
254
254
  world_tracker_projections_data(o: zappar_world_tracker_t): Float32Array;
255
+ world_tracker_mesh_anchors_enabled(o: zappar_world_tracker_t): boolean;
256
+ world_tracker_mesh_anchors_enabled_set(o: zappar_world_tracker_t, mesh_anchors_enabled: boolean): void;
257
+ world_tracker_mesh_anchor_count(o: zappar_world_tracker_t): number;
258
+ world_tracker_mesh_anchor_id(o: zappar_world_tracker_t, indx: number): string;
259
+ world_tracker_mesh_anchor_status(o: zappar_world_tracker_t, indx: number): anchor_status_t;
260
+ world_tracker_mesh_anchor_pose_raw(o: zappar_world_tracker_t, indx: number): Float32Array;
261
+ world_tracker_mesh_anchor_pose_camera_relative(o: zappar_world_tracker_t, indx: number, mirror: boolean): Float32Array;
262
+ world_tracker_mesh_anchor_pose(o: zappar_world_tracker_t, indx: number, camera_pose: Float32Array, mirror: boolean): Float32Array;
263
+ world_tracker_mesh_anchor_vertices(o: zappar_world_tracker_t, indx: number): Float32Array;
264
+ world_tracker_mesh_anchor_vertices_offset(o: zappar_world_tracker_t, indx: number): number;
265
+ world_tracker_mesh_anchor_vertices_stride(o: zappar_world_tracker_t, indx: number): number;
266
+ world_tracker_mesh_anchor_vertices_count(o: zappar_world_tracker_t, indx: number): number;
267
+ world_tracker_mesh_anchor_vertices_size(o: zappar_world_tracker_t, indx: number): number;
268
+ world_tracker_mesh_anchor_indices(o: zappar_world_tracker_t, indx: number): Uint32Array;
269
+ world_tracker_mesh_anchor_indices_count(o: zappar_world_tracker_t, indx: number): number;
270
+ world_tracker_mesh_anchor_indices_size(o: zappar_world_tracker_t, indx: number): number;
255
271
  custom_anchor_create(pipeline: zappar_pipeline_t, worldtracker: zappar_world_tracker_t, id: string): zappar_custom_anchor_t;
256
272
  custom_anchor_destroy(o: zappar_custom_anchor_t): void;
257
273
  custom_anchor_id(o: zappar_custom_anchor_t): string;
@@ -1,5 +1,5 @@
1
1
  import { initialize as init } from "./index";
2
2
  export * from "./index";
3
3
  export function initialize(opts) {
4
- return init(Object.assign(Object.assign({}, opts), { worker: (opts === null || opts === void 0 ? void 0 : opts.worker) || new (require("worker-loader?inline=fallback!./worker").default)() }));
4
+ return init(Object.assign(Object.assign({}, opts), { worker: (opts === null || opts === void 0 ? void 0 : opts.worker) || new (require("worker-loader?inline=fallback!./worker").default)(), ceresWorker: (opts === null || opts === void 0 ? void 0 : opts.ceresWorker) || new (require("worker-loader?inline=fallback&filename=zappar-cv-ceres.worker.js!./ceres-worker").default)() }));
5
5
  }
package/lib/native.js CHANGED
@@ -29,6 +29,8 @@ import { MSTPCameraSource } from "./mstp-camera-source";
29
29
  import { drawGrid } from "./drawgrid";
30
30
  import { getPointsDataMatrix } from "./drawpoints";
31
31
  import { drawAxis } from "./drawaxis";
32
+ import { BridgedWorldTracker } from "./bridged-world-tracker";
33
+ import { BridgedCameraSource } from "./bridged-camera-source";
32
34
  let client;
33
35
  const pipelineByWorldTracker = new Map();
34
36
  const _temporaryMatrix = mat4.create();
@@ -49,10 +51,27 @@ export function initialize(opts) {
49
51
  });
50
52
  const uid = getUID();
51
53
  let hasPersistedUID = false;
52
- if (window.location.hostname.toLowerCase().indexOf(".zappar.io") > 0 || window.location.hostname.toLowerCase().indexOf(".webar.run") > 0 || window.location.hostname.toLowerCase().indexOf(".arweb.app") > 0 || window.location.hostname.toLowerCase().indexOf(".zappar-us.io") > 0 || window.location.hostname.toLowerCase().indexOf(".zappar-eu.io") > 0) {
53
- let pathParts = window.location.pathname.split("/");
54
- if (pathParts.length > 1 && pathParts[1].length > 0)
55
- c.impl.analytics_project_id_set(".wiz" + pathParts[1], uid);
54
+ let hasSetID = false;
55
+ try {
56
+ /** @ts-ignore */
57
+ const cookies = Object.fromEntries(document.cookie.split('; ').map(v => v.split(/=(.*)/s).map(decodeURIComponent)));
58
+ if (cookies['zw-uar-project']) {
59
+ const parsed = JSON.parse(cookies['zw-uar-project']);
60
+ if (typeof parsed === 'object' && typeof parsed['id'] === 'string') {
61
+ c.impl.analytics_project_id_set(".wiz" + parsed['id'], uid);
62
+ hasSetID = true;
63
+ }
64
+ }
65
+ }
66
+ catch (err) { }
67
+ if (!hasSetID) {
68
+ if (window.location.hostname.toLowerCase().indexOf(".zappar.io") > 0 || window.location.hostname.toLowerCase().indexOf(".webar.run") > 0 || window.location.hostname.toLowerCase().indexOf(".arweb.app") > 0 || window.location.hostname.toLowerCase().indexOf(".zappar-us.io") > 0 || window.location.hostname.toLowerCase().indexOf(".zappar-eu.io") > 0) {
69
+ let pathParts = window.location.pathname.split("/");
70
+ if (pathParts.length > 1 && pathParts[1].length > 0) {
71
+ c.impl.analytics_project_id_set(".wiz" + pathParts[1], uid);
72
+ hasSetID = true;
73
+ }
74
+ }
56
75
  }
57
76
  messageManager.onIncomingMessage.bind(msg => {
58
77
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -91,7 +110,7 @@ export function initialize(opts) {
91
110
  break;
92
111
  }
93
112
  case "setupCeresWorker": {
94
- launchCeresWorker(msg.port);
113
+ launchCeresWorker(msg.port, opts === null || opts === void 0 ? void 0 : opts.ceresWorker);
95
114
  break;
96
115
  }
97
116
  case "_z_datadownload": {
@@ -153,7 +172,13 @@ export function initialize(opts) {
153
172
  }
154
173
  });
155
174
  const customAnchors = new Map();
156
- 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) => {
175
+ // Override world tracking functions if the bridge is available
176
+ let bridgedWtApi;
177
+ if (BridgedWorldTracker.IsSupported())
178
+ bridgedWtApi = BridgedWorldTracker.SharedInstance();
179
+ let bridgedWtImpl = (bridgedWtApi === null || bridgedWtApi === void 0 ? void 0 : bridgedWtApi.impl) || {};
180
+ const wtImpl = (bridgedWtApi === null || bridgedWtApi === void 0 ? void 0 : bridgedWtApi.impl) || c.impl;
181
+ client = Object.assign(Object.assign(Object.assign(Object.assign({}, c.impl), { world_tracker_mesh_anchor_count: () => 0, world_tracker_mesh_anchor_id: () => "", world_tracker_mesh_anchor_indices: () => new Uint32Array(0), world_tracker_mesh_anchor_indices_count: () => 0, world_tracker_mesh_anchor_indices_size: () => 0, world_tracker_mesh_anchor_vertices: () => new Float32Array(0), world_tracker_mesh_anchor_vertices_count: () => 0, world_tracker_mesh_anchor_vertices_size: () => 0, world_tracker_mesh_anchor_vertices_offset: () => 0, world_tracker_mesh_anchor_vertices_stride: () => 0, world_tracker_mesh_anchor_pose_raw: () => new Float32Array(), world_tracker_mesh_anchor_status: () => anchor_status_t.ANCHOR_STATUS_STOPPED, world_tracker_mesh_anchors_enabled: () => false, world_tracker_mesh_anchors_enabled_set: () => { } }), bridgedWtImpl), { 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) => {
157
182
  let res = applyScreenCounterRotation(undefined, raw_pose);
158
183
  if (mirror) {
159
184
  let scale = mat4.create();
@@ -229,7 +254,7 @@ export function initialize(opts) {
229
254
  return mat4.create();
230
255
  }
231
256
  if (entry.expectedPoseVersion <= client.custom_anchor_pose_version(o))
232
- return c.impl.custom_anchor_pose_raw(o);
257
+ return wtImpl.custom_anchor_pose_raw(o);
233
258
  const world_anchor_raw = client.world_tracker_world_anchor_pose_raw(entry.wt).slice();
234
259
  const ret = mat4.create();
235
260
  mat4.multiply(ret, world_anchor_raw, entry.poseRelativeToWorldAnchor);
@@ -243,7 +268,7 @@ export function initialize(opts) {
243
268
  if (entry.expectedPoseVersion === 0)
244
269
  return anchor_status_t.ANCHOR_STATUS_STOPPED;
245
270
  if (entry.expectedPoseVersion <= client.custom_anchor_pose_version(o))
246
- return c.impl.custom_anchor_status(o);
271
+ return wtImpl.custom_anchor_status(o);
247
272
  return anchor_status_t.ANCHOR_STATUS_INITIALIZING;
248
273
  }, custom_anchor_pose_camera_relative: (o, mirror) => {
249
274
  let res = applyScreenCounterRotation(undefined, client.custom_anchor_pose_raw(o));
@@ -265,7 +290,7 @@ export function initialize(opts) {
265
290
  mat4.multiply(res, cameraPose, res);
266
291
  return res;
267
292
  }, custom_anchor_create: (p, wt, id) => {
268
- const ret = c.impl.custom_anchor_create(p, wt, id);
293
+ const ret = wtImpl.custom_anchor_create(p, wt, id);
269
294
  customAnchors.set(ret, { id, wt, expectedPoseVersion: 0, poseRelativeToWorldAnchor: mat4.create() });
270
295
  return ret;
271
296
  }, custom_anchor_id: (o) => {
@@ -440,7 +465,7 @@ export function initialize(opts) {
440
465
  }
441
466
  entry.expectedPoseVersion++;
442
467
  mat4.copy(entry.poseRelativeToWorldAnchor, pose);
443
- c.impl.custom_anchor_pose_set(o, pose);
468
+ wtImpl.custom_anchor_pose_set(o, pose);
444
469
  }, custom_anchor_pose_set_with_parent: (o, pose, anchor_id) => {
445
470
  const entry = customAnchors.get(o);
446
471
  if (entry === undefined) {
@@ -449,10 +474,10 @@ export function initialize(opts) {
449
474
  }
450
475
  entry.expectedPoseVersion++;
451
476
  mat4.copy(entry.poseRelativeToWorldAnchor, pose);
452
- c.impl.custom_anchor_pose_set_with_parent(o, pose, anchor_id);
477
+ wtImpl.custom_anchor_pose_set_with_parent(o, pose, anchor_id);
453
478
  }, custom_anchor_destroy: (o) => {
454
479
  customAnchors.delete(o);
455
- c.impl.custom_anchor_destroy(o);
480
+ wtImpl.custom_anchor_destroy(o);
456
481
  }, image_tracker_create: pipeline => ImageTracker.create(pipeline, c.impl), image_tracker_destroy: t => { var _a; return (_a = ImageTracker.get(t)) === null || _a === void 0 ? void 0 : _a.destroy(); }, image_tracker_target_type: (t, i) => {
457
482
  let obj = ImageTracker.get(t);
458
483
  if (!obj) {
@@ -775,7 +800,7 @@ export function initialize(opts) {
775
800
  }
776
801
  return obj.anchor_pose;
777
802
  }, world_tracker_create: (pipeline) => {
778
- const ret = c.impl.world_tracker_create(pipeline);
803
+ const ret = wtImpl.world_tracker_create(pipeline);
779
804
  pipelineByWorldTracker.set(ret, pipeline);
780
805
  return ret;
781
806
  }, world_tracker_reset: (wt) => {
@@ -785,7 +810,7 @@ export function initialize(opts) {
785
810
  entry.expectedPoseVersion = 0;
786
811
  }
787
812
  }
788
- c.impl.world_tracker_reset(wt);
813
+ wtImpl.world_tracker_reset(wt);
789
814
  }, world_tracker_points_data_matrix: (wt, screenWidth, screenHeight, mirror) => {
790
815
  const pipeline = pipelineByWorldTracker.get(wt);
791
816
  if (pipeline === undefined || !client)
@@ -849,8 +874,29 @@ export function initialize(opts) {
849
874
  }
850
875
  return res;
851
876
  }, world_tracker_vertical_plane_detection_supported: (o) => {
877
+ if (bridgedWtApi)
878
+ return true;
852
879
  return false;
853
- }, html_element_source_create: (pipeline, elm) => HTMLElementSource.createVideoElementSource(pipeline, elm), html_element_source_start: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.start(); }, html_element_source_pause: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, html_element_source_destroy: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, sequence_source_create: p => SequenceSource.create(p), sequence_source_load_from_memory: (o, data) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.loadFromMemory(data); }, sequence_source_pause: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, sequence_source_start: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.start(); }, sequence_source_max_playback_fps_set: (o, fps) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.maxPlaybackFpsSet(fps); }, sequence_source_time_set: (o, t) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.setTime(t); }, sequence_source_destroy: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, permission_granted_all: permissionGrantedAll, permission_granted_camera: permissionGrantedCamera, permission_granted_motion: permissionGrantedMotion, permission_denied_any: permissionDeniedAny, permission_denied_camera: permissionDeniedCamera, permission_denied_motion: permissionDeniedMotion, permission_request_motion: permissionRequestMotion, permission_request_camera: permissionRequestCamera, permission_request_all: permissionRequestAll, permission_request_ui: permissionRequestUI, permission_request_ui_promise: permissionRequestUI, permission_denied_ui: permissionDeniedUI, browser_incompatible: compatibility.incompatible, browser_incompatible_ui: compatibility.incompatible_ui, log_level_set: l => {
880
+ }, world_tracker_mesh_anchor_pose_camera_relative: (o, indx, mirror) => {
881
+ let res = applyScreenCounterRotation(undefined, client.world_tracker_mesh_anchor_pose_raw(o, indx));
882
+ if (mirror) {
883
+ let scale = mat4.create();
884
+ mat4.fromScaling(scale, [-1, 1, 1]);
885
+ mat4.multiply(res, scale, res);
886
+ mat4.multiply(res, res, scale);
887
+ }
888
+ return res;
889
+ }, world_tracker_mesh_anchor_pose: (o, indx, cameraPose, mirror) => {
890
+ let res = applyScreenCounterRotation(undefined, client.world_tracker_mesh_anchor_pose_raw(o, indx));
891
+ if (mirror) {
892
+ let scale = mat4.create();
893
+ mat4.fromScaling(scale, [-1, 1, 1]);
894
+ mat4.multiply(res, scale, res);
895
+ mat4.multiply(res, res, scale);
896
+ }
897
+ mat4.multiply(res, cameraPose, res);
898
+ return res;
899
+ }, html_element_source_create: (pipeline, elm) => HTMLElementSource.createVideoElementSource(pipeline, elm), html_element_source_start: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.start(); }, html_element_source_pause: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, html_element_source_destroy: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, sequence_source_create: p => SequenceSource.create(p), sequence_source_load_from_memory: (o, data) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.loadFromMemory(data); }, sequence_source_pause: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, sequence_source_start: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.start(); }, sequence_source_max_playback_fps_set: (o, fps) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.maxPlaybackFpsSet(fps); }, sequence_source_time_set: (o, t) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.setTime(t); }, sequence_source_destroy: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, permission_granted_all: permissionGrantedAll, permission_granted_camera: permissionGrantedCamera, permission_granted_motion: permissionGrantedMotion, permission_denied_any: permissionDeniedAny, permission_denied_camera: permissionDeniedCamera, permission_denied_motion: permissionDeniedMotion, permission_request_motion: permissionRequestMotion, permission_request_camera: permissionRequestCamera, permission_request_all: permissionRequestAll, permission_request_ui: permissionRequestUI, permission_request_ui_promise: permissionRequestUI, permission_denied_ui: permissionDeniedUI, browser_incompatible: compatibility.incompatible, browser_incompatible_ui: compatibility.incompatible_ui, in_app_clip: () => BridgedCameraSource.IsSupported(), log_level_set: l => {
854
900
  setLogLevel(l);
855
901
  c.impl.log_level_set(l);
856
902
  }, cookies_permitted: p => {
package/lib/options.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export interface Options {
2
2
  worker?: Worker;
3
+ ceresWorker?: Worker;
3
4
  }
package/lib/permission.js CHANGED
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { UAParser } from "ua-parser-js";
11
11
  import { STRINGS, tr } from "./tr";
12
+ import { BridgedCameraSource } from "./bridged-camera-source";
12
13
  let parser = new UAParser();
13
14
  let _permissionGrantedCamera = false;
14
15
  let _permissionGrantedMotion = false;
@@ -61,6 +62,11 @@ export function permissionRequestCamera() {
61
62
  }
62
63
  export function permissionRequestMotion() {
63
64
  return __awaiter(this, void 0, void 0, function* () {
65
+ if (BridgedCameraSource.IsSupported()) {
66
+ _permissionGrantedMotion = true;
67
+ _permissionDeniedMotion = false;
68
+ return;
69
+ }
64
70
  if (window.DeviceOrientationEvent && window.DeviceOrientationEvent.requestPermission) {
65
71
  let permissionResult = yield window.DeviceOrientationEvent.requestPermission();
66
72
  if (permissionResult !== 'granted') {
package/lib/pipeline.js CHANGED
@@ -51,7 +51,7 @@ export class Pipeline {
51
51
  this.cleanOldFrames();
52
52
  }
53
53
  cleanOldFrames() {
54
- var _a, _b;
54
+ var _a, _b, _c, _d;
55
55
  let currentToken = this._client.pipeline_camera_frame_user_data(this._impl);
56
56
  if (!currentToken)
57
57
  return;
@@ -60,6 +60,7 @@ export class Pipeline {
60
60
  if (t[1].texture)
61
61
  this.videoTextures.push(t[1].texture);
62
62
  (_b = (_a = t[1].frame) === null || _a === void 0 ? void 0 : _a.close) === null || _b === void 0 ? void 0 : _b.call(_a);
63
+ (_d = (_c = t[1].cameraSource).recycle) === null || _d === void 0 ? void 0 : _d.call(_c, t[1]);
63
64
  if (t[1].data) {
64
65
  this.cameraPixelArrays.push(t[1].data);
65
66
  t[1].data = undefined;
package/lib/profile.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as UAParser from "ua-parser-js";
2
2
  import { camera_profile_t } from "./gen/zappar-native";
3
+ import { AndroidBridgeMessageHandler } from "./android-bridge-message-handler";
3
4
  export var EmbeddedVideoImplementation;
4
5
  (function (EmbeddedVideoImplementation) {
5
6
  EmbeddedVideoImplementation[EmbeddedVideoImplementation["OBJECT_URL"] = 0] = "OBJECT_URL";
@@ -15,7 +16,7 @@ export let profile = {
15
16
  videoHeight: 480,
16
17
  getDataSize: (p) => p === camera_profile_t.HIGH ? [640, 480] : [320, 240],
17
18
  videoElementInDOM: false,
18
- preferMediaStreamTrackProcessorCamera: true,
19
+ preferMediaStreamTrackProcessorCamera: !AndroidBridgeMessageHandler.IsSupported(),
19
20
  preferImageBitmapCamera: false,
20
21
  ios164CameraSelection: false,
21
22
  relyOnConstraintsForCameraSelection: false,
package/lib/source.d.ts CHANGED
@@ -17,4 +17,5 @@ export declare abstract class Source {
17
17
  abstract getFrame(currentlyProcessing: boolean): void;
18
18
  abstract pause(): void;
19
19
  abstract uploadGL(info: CameraFrameInfo): void;
20
+ recycle?(info: CameraFrameInfo): void;
20
21
  }
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "3.0.1-beta.8";
1
+ export declare const VERSION = "3.1.0-beta.2";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "3.0.1-beta.8";
1
+ export const VERSION = "3.1.0-beta.2";
@@ -0,0 +1,44 @@
1
+ export interface PlaneData {
2
+ width: number;
3
+ height: number;
4
+ data: Uint8Array;
5
+ }
6
+ export interface UvPlaneData {
7
+ width: number;
8
+ height: number;
9
+ data: Uint8Array;
10
+ dataVPlane?: Uint8Array;
11
+ }
12
+ export declare enum UvLayout {
13
+ INTERLEAVED_UV = 0,
14
+ INTERLEAVED_VU = 1,
15
+ PLANAR_UV = 2
16
+ }
17
+ export declare class YUVConversionGL {
18
+ private _gl;
19
+ private _yTexture;
20
+ private _uvTexture;
21
+ private _uvTextureSinglePlane;
22
+ private _vTexture;
23
+ private _framebufferId;
24
+ private _vao;
25
+ private _vertexBuffer;
26
+ private _conversionShaders;
27
+ private _isWebGL2;
28
+ private _useVao;
29
+ private _oneComponentInternalFormat;
30
+ private _oneComponentFormat;
31
+ private _twoComponentInternalFormat;
32
+ private _twoComponentFormat;
33
+ private _vaoExtension;
34
+ private _instancedArraysExtension;
35
+ constructor(_gl: WebGL2RenderingContext | WebGLRenderingContext);
36
+ resetGLContext(): void;
37
+ destroy(): void;
38
+ yuvToTexture(y: PlaneData, uv: UvPlaneData, uvLayout: UvLayout, destination: WebGLTexture): void;
39
+ private _getVertexAttribState;
40
+ private _prepareContext;
41
+ private _prepareConversionShader;
42
+ private _prepareTextures;
43
+ private _createSizedTexture;
44
+ }