@zappar/zappar-cv 3.0.1-beta.6 → 3.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/android-bridge-message-handler.d.ts +11 -0
- package/lib/android-bridge-message-handler.js +167 -0
- package/lib/array-from-string.d.ts +2 -0
- package/lib/array-from-string.js +48 -0
- package/lib/bridged-camera-source.d.ts +39 -0
- package/lib/bridged-camera-source.js +383 -0
- package/lib/bridged-message-parser.d.ts +12 -0
- package/lib/bridged-message-parser.js +56 -0
- package/lib/bridged-message.d.ts +64 -0
- package/lib/bridged-message.js +1 -0
- package/lib/bridged-world-tracker.d.ts +20 -0
- package/lib/bridged-world-tracker.js +426 -0
- package/lib/camera-source-map.d.ts +2 -1
- package/lib/camera-source-map.js +4 -1
- package/lib/drawmesh.d.ts +14 -0
- package/lib/drawmesh.js +123 -0
- package/lib/drawquad.d.ts +2 -0
- package/lib/drawquad.js +99 -0
- package/lib/gen/zappar.d.ts +16 -0
- package/lib/html-element-source.js +1 -1
- package/lib/index-standalone.js +1 -1
- package/lib/native.js +59 -14
- package/lib/options.d.ts +1 -0
- package/lib/permission.js +6 -0
- package/lib/pipeline.js +2 -1
- package/lib/profile.js +2 -1
- package/lib/source.d.ts +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/worker-server.js +1 -1
- package/lib/yuv-conversion-gl.d.ts +44 -0
- package/lib/yuv-conversion-gl.js +416 -0
- package/lib/zappar-cv.js +1 -1
- package/lib/zappar-cv.wasm +0 -0
- package/package.json +6 -16
- package/umd/287.zappar-cv.js +1 -0
- package/umd/{d4dad9f6d6bd944162fa.wasm → 641e1456d6d56783d581.wasm} +0 -0
- package/umd/867.zappar-cv.js +1 -1
- package/umd/zappar-cv-ceres.worker.js +1 -0
- package/umd/zappar-cv.js +1 -1
- package/umd/zappar-cv.worker.js +1 -1
- package/umd/751.zappar-cv.js +0 -1
package/lib/drawmesh.js
ADDED
|
@@ -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
|
+
}`;
|
package/lib/drawquad.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { compileShader, linkProgram } from "./shader";
|
|
2
|
+
let shader;
|
|
3
|
+
let vbo;
|
|
4
|
+
export function disposeDrawQuad() {
|
|
5
|
+
shader = undefined;
|
|
6
|
+
vbo = undefined;
|
|
7
|
+
}
|
|
8
|
+
function generate(gl) {
|
|
9
|
+
if (vbo)
|
|
10
|
+
return vbo;
|
|
11
|
+
vbo = gl.createBuffer();
|
|
12
|
+
if (!vbo)
|
|
13
|
+
throw new Error("Unable to create buffer object");
|
|
14
|
+
let coords = [
|
|
15
|
+
-0.5, 0.5, 0,
|
|
16
|
+
-0.5, -0.5, 0,
|
|
17
|
+
0.5, 0.5, 0,
|
|
18
|
+
0.5, -0.5, 0
|
|
19
|
+
];
|
|
20
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
21
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(coords), gl.STATIC_DRAW);
|
|
22
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
23
|
+
return vbo;
|
|
24
|
+
}
|
|
25
|
+
export function drawQuad(gl, projectionMatrix, modelviewMatrix, color) {
|
|
26
|
+
let shader = getShader(gl);
|
|
27
|
+
let v = generate(gl);
|
|
28
|
+
gl.useProgram(shader.prog);
|
|
29
|
+
gl.uniformMatrix4fv(shader.unif_projection, false, projectionMatrix);
|
|
30
|
+
gl.uniformMatrix4fv(shader.unif_modelView, false, modelviewMatrix);
|
|
31
|
+
gl.uniform4fv(shader.unif_color, color);
|
|
32
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, v);
|
|
33
|
+
gl.vertexAttribPointer(shader.attr_position, 3, gl.FLOAT, false, 3 * 4, 0);
|
|
34
|
+
gl.enableVertexAttribArray(shader.attr_position);
|
|
35
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
36
|
+
gl.disableVertexAttribArray(shader.attr_position);
|
|
37
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
38
|
+
}
|
|
39
|
+
let vertexShaderSrc = `
|
|
40
|
+
#ifndef GL_ES
|
|
41
|
+
#define highp
|
|
42
|
+
#define mediump
|
|
43
|
+
#define lowp
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
uniform mat4 projMatrix;
|
|
47
|
+
uniform mat4 modelViewMatrix;
|
|
48
|
+
attribute vec4 position;
|
|
49
|
+
|
|
50
|
+
void main()
|
|
51
|
+
{
|
|
52
|
+
gl_Position = projMatrix * modelViewMatrix * position;
|
|
53
|
+
}`;
|
|
54
|
+
let fragmentShaderSrc = `
|
|
55
|
+
#define highp mediump
|
|
56
|
+
#ifdef GL_ES
|
|
57
|
+
// define default precision for float, vec, mat.
|
|
58
|
+
precision highp float;
|
|
59
|
+
#else
|
|
60
|
+
#define highp
|
|
61
|
+
#define mediump
|
|
62
|
+
#define lowp
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
uniform vec4 color;
|
|
66
|
+
|
|
67
|
+
void main()
|
|
68
|
+
{
|
|
69
|
+
gl_FragColor = color;
|
|
70
|
+
}`;
|
|
71
|
+
function getShader(gl) {
|
|
72
|
+
if (shader)
|
|
73
|
+
return shader;
|
|
74
|
+
let prog = gl.createProgram();
|
|
75
|
+
if (!prog)
|
|
76
|
+
throw new Error("Unable to create program");
|
|
77
|
+
let vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSrc);
|
|
78
|
+
let fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSrc);
|
|
79
|
+
gl.attachShader(prog, vertexShader);
|
|
80
|
+
gl.attachShader(prog, fragmentShader);
|
|
81
|
+
linkProgram(gl, prog);
|
|
82
|
+
let unif_projection = gl.getUniformLocation(prog, "projMatrix");
|
|
83
|
+
if (!unif_projection)
|
|
84
|
+
throw new Error("Unable to get uniform location projMatrix");
|
|
85
|
+
let unif_modelView = gl.getUniformLocation(prog, "modelViewMatrix");
|
|
86
|
+
if (!unif_modelView)
|
|
87
|
+
throw new Error("Unable to get uniform location modelViewMatrix");
|
|
88
|
+
let unif_color = gl.getUniformLocation(prog, "color");
|
|
89
|
+
if (!unif_color)
|
|
90
|
+
throw new Error("Unable to get uniform location color");
|
|
91
|
+
shader = {
|
|
92
|
+
prog,
|
|
93
|
+
unif_modelView,
|
|
94
|
+
unif_projection,
|
|
95
|
+
unif_color,
|
|
96
|
+
attr_position: gl.getAttribLocation(prog, "position"),
|
|
97
|
+
};
|
|
98
|
+
return shader;
|
|
99
|
+
}
|
package/lib/gen/zappar.d.ts
CHANGED
|
@@ -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;
|
|
@@ -159,7 +159,7 @@ export class HTMLElementSource extends Source {
|
|
|
159
159
|
}
|
|
160
160
|
let tex = this._currentVideoTexture;
|
|
161
161
|
this._currentVideoTexture = undefined;
|
|
162
|
-
let focalLength = 240.0 * dataWidth / 320.0;
|
|
162
|
+
let focalLength = (this._isUserFacing ? 300.0 : 240.0) * dataWidth / 320.0;
|
|
163
163
|
this._cameraModel[0] = focalLength;
|
|
164
164
|
this._cameraModel[1] = focalLength;
|
|
165
165
|
this._cameraModel[2] = dataWidth * 0.5;
|
package/lib/index-standalone.js
CHANGED
|
@@ -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,7 @@ 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";
|
|
32
33
|
let client;
|
|
33
34
|
const pipelineByWorldTracker = new Map();
|
|
34
35
|
const _temporaryMatrix = mat4.create();
|
|
@@ -49,10 +50,27 @@ export function initialize(opts) {
|
|
|
49
50
|
});
|
|
50
51
|
const uid = getUID();
|
|
51
52
|
let hasPersistedUID = false;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
let hasSetID = false;
|
|
54
|
+
try {
|
|
55
|
+
/** @ts-ignore */
|
|
56
|
+
const cookies = Object.fromEntries(document.cookie.split('; ').map(v => v.split(/=(.*)/s).map(decodeURIComponent)));
|
|
57
|
+
if (cookies['zw-uar-project']) {
|
|
58
|
+
const parsed = JSON.parse(cookies['zw-uar-project']);
|
|
59
|
+
if (typeof parsed === 'object' && typeof parsed['id'] === 'string') {
|
|
60
|
+
c.impl.analytics_project_id_set(".wiz" + parsed['id'], uid);
|
|
61
|
+
hasSetID = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (err) { }
|
|
66
|
+
if (!hasSetID) {
|
|
67
|
+
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) {
|
|
68
|
+
let pathParts = window.location.pathname.split("/");
|
|
69
|
+
if (pathParts.length > 1 && pathParts[1].length > 0) {
|
|
70
|
+
c.impl.analytics_project_id_set(".wiz" + pathParts[1], uid);
|
|
71
|
+
hasSetID = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
56
74
|
}
|
|
57
75
|
messageManager.onIncomingMessage.bind(msg => {
|
|
58
76
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -91,7 +109,7 @@ export function initialize(opts) {
|
|
|
91
109
|
break;
|
|
92
110
|
}
|
|
93
111
|
case "setupCeresWorker": {
|
|
94
|
-
launchCeresWorker(msg.port);
|
|
112
|
+
launchCeresWorker(msg.port, opts === null || opts === void 0 ? void 0 : opts.ceresWorker);
|
|
95
113
|
break;
|
|
96
114
|
}
|
|
97
115
|
case "_z_datadownload": {
|
|
@@ -153,7 +171,13 @@ export function initialize(opts) {
|
|
|
153
171
|
}
|
|
154
172
|
});
|
|
155
173
|
const customAnchors = new Map();
|
|
156
|
-
|
|
174
|
+
// Override world tracking functions if the bridge is available
|
|
175
|
+
let bridgedWtApi;
|
|
176
|
+
if (BridgedWorldTracker.IsSupported())
|
|
177
|
+
bridgedWtApi = BridgedWorldTracker.SharedInstance();
|
|
178
|
+
let bridgedWtImpl = (bridgedWtApi === null || bridgedWtApi === void 0 ? void 0 : bridgedWtApi.impl) || {};
|
|
179
|
+
const wtImpl = (bridgedWtApi === null || bridgedWtApi === void 0 ? void 0 : bridgedWtApi.impl) || c.impl;
|
|
180
|
+
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
181
|
let res = applyScreenCounterRotation(undefined, raw_pose);
|
|
158
182
|
if (mirror) {
|
|
159
183
|
let scale = mat4.create();
|
|
@@ -229,7 +253,7 @@ export function initialize(opts) {
|
|
|
229
253
|
return mat4.create();
|
|
230
254
|
}
|
|
231
255
|
if (entry.expectedPoseVersion <= client.custom_anchor_pose_version(o))
|
|
232
|
-
return
|
|
256
|
+
return wtImpl.custom_anchor_pose_raw(o);
|
|
233
257
|
const world_anchor_raw = client.world_tracker_world_anchor_pose_raw(entry.wt).slice();
|
|
234
258
|
const ret = mat4.create();
|
|
235
259
|
mat4.multiply(ret, world_anchor_raw, entry.poseRelativeToWorldAnchor);
|
|
@@ -243,7 +267,7 @@ export function initialize(opts) {
|
|
|
243
267
|
if (entry.expectedPoseVersion === 0)
|
|
244
268
|
return anchor_status_t.ANCHOR_STATUS_STOPPED;
|
|
245
269
|
if (entry.expectedPoseVersion <= client.custom_anchor_pose_version(o))
|
|
246
|
-
return
|
|
270
|
+
return wtImpl.custom_anchor_status(o);
|
|
247
271
|
return anchor_status_t.ANCHOR_STATUS_INITIALIZING;
|
|
248
272
|
}, custom_anchor_pose_camera_relative: (o, mirror) => {
|
|
249
273
|
let res = applyScreenCounterRotation(undefined, client.custom_anchor_pose_raw(o));
|
|
@@ -265,7 +289,7 @@ export function initialize(opts) {
|
|
|
265
289
|
mat4.multiply(res, cameraPose, res);
|
|
266
290
|
return res;
|
|
267
291
|
}, custom_anchor_create: (p, wt, id) => {
|
|
268
|
-
const ret =
|
|
292
|
+
const ret = wtImpl.custom_anchor_create(p, wt, id);
|
|
269
293
|
customAnchors.set(ret, { id, wt, expectedPoseVersion: 0, poseRelativeToWorldAnchor: mat4.create() });
|
|
270
294
|
return ret;
|
|
271
295
|
}, custom_anchor_id: (o) => {
|
|
@@ -440,7 +464,7 @@ export function initialize(opts) {
|
|
|
440
464
|
}
|
|
441
465
|
entry.expectedPoseVersion++;
|
|
442
466
|
mat4.copy(entry.poseRelativeToWorldAnchor, pose);
|
|
443
|
-
|
|
467
|
+
wtImpl.custom_anchor_pose_set(o, pose);
|
|
444
468
|
}, custom_anchor_pose_set_with_parent: (o, pose, anchor_id) => {
|
|
445
469
|
const entry = customAnchors.get(o);
|
|
446
470
|
if (entry === undefined) {
|
|
@@ -449,10 +473,10 @@ export function initialize(opts) {
|
|
|
449
473
|
}
|
|
450
474
|
entry.expectedPoseVersion++;
|
|
451
475
|
mat4.copy(entry.poseRelativeToWorldAnchor, pose);
|
|
452
|
-
|
|
476
|
+
wtImpl.custom_anchor_pose_set_with_parent(o, pose, anchor_id);
|
|
453
477
|
}, custom_anchor_destroy: (o) => {
|
|
454
478
|
customAnchors.delete(o);
|
|
455
|
-
|
|
479
|
+
wtImpl.custom_anchor_destroy(o);
|
|
456
480
|
}, 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
481
|
let obj = ImageTracker.get(t);
|
|
458
482
|
if (!obj) {
|
|
@@ -775,7 +799,7 @@ export function initialize(opts) {
|
|
|
775
799
|
}
|
|
776
800
|
return obj.anchor_pose;
|
|
777
801
|
}, world_tracker_create: (pipeline) => {
|
|
778
|
-
const ret =
|
|
802
|
+
const ret = wtImpl.world_tracker_create(pipeline);
|
|
779
803
|
pipelineByWorldTracker.set(ret, pipeline);
|
|
780
804
|
return ret;
|
|
781
805
|
}, world_tracker_reset: (wt) => {
|
|
@@ -785,7 +809,7 @@ export function initialize(opts) {
|
|
|
785
809
|
entry.expectedPoseVersion = 0;
|
|
786
810
|
}
|
|
787
811
|
}
|
|
788
|
-
|
|
812
|
+
wtImpl.world_tracker_reset(wt);
|
|
789
813
|
}, world_tracker_points_data_matrix: (wt, screenWidth, screenHeight, mirror) => {
|
|
790
814
|
const pipeline = pipelineByWorldTracker.get(wt);
|
|
791
815
|
if (pipeline === undefined || !client)
|
|
@@ -849,7 +873,28 @@ export function initialize(opts) {
|
|
|
849
873
|
}
|
|
850
874
|
return res;
|
|
851
875
|
}, world_tracker_vertical_plane_detection_supported: (o) => {
|
|
876
|
+
if (bridgedWtApi)
|
|
877
|
+
return true;
|
|
852
878
|
return false;
|
|
879
|
+
}, world_tracker_mesh_anchor_pose_camera_relative: (o, indx, mirror) => {
|
|
880
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_mesh_anchor_pose_raw(o, indx));
|
|
881
|
+
if (mirror) {
|
|
882
|
+
let scale = mat4.create();
|
|
883
|
+
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
884
|
+
mat4.multiply(res, scale, res);
|
|
885
|
+
mat4.multiply(res, res, scale);
|
|
886
|
+
}
|
|
887
|
+
return res;
|
|
888
|
+
}, world_tracker_mesh_anchor_pose: (o, indx, cameraPose, mirror) => {
|
|
889
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_mesh_anchor_pose_raw(o, indx));
|
|
890
|
+
if (mirror) {
|
|
891
|
+
let scale = mat4.create();
|
|
892
|
+
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
893
|
+
mat4.multiply(res, scale, res);
|
|
894
|
+
mat4.multiply(res, res, scale);
|
|
895
|
+
}
|
|
896
|
+
mat4.multiply(res, cameraPose, res);
|
|
897
|
+
return res;
|
|
853
898
|
}, 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 => {
|
|
854
899
|
setLogLevel(l);
|
|
855
900
|
c.impl.log_level_set(l);
|
package/lib/options.d.ts
CHANGED
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:
|
|
19
|
+
preferMediaStreamTrackProcessorCamera: !AndroidBridgeMessageHandler.IsSupported(),
|
|
19
20
|
preferImageBitmapCamera: false,
|
|
20
21
|
ios164CameraSelection: false,
|
|
21
22
|
relyOnConstraintsForCameraSelection: false,
|
package/lib/source.d.ts
CHANGED
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "3.0
|
|
1
|
+
export declare const VERSION = "3.1.0-beta.1";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0
|
|
1
|
+
export const VERSION = "3.1.0-beta.1";
|
package/lib/worker-server.js
CHANGED
|
@@ -266,7 +266,7 @@ function consumeReader(mod, r, reader, p, userFacing, server, source, workerMess
|
|
|
266
266
|
mat4.fromScaling(cameraToDeviceTransform, [-1, 1, -1]);
|
|
267
267
|
else
|
|
268
268
|
mat4.identity(cameraToDeviceTransform);
|
|
269
|
-
let focalLength = 240.0 * dataWidth / 320.0;
|
|
269
|
+
let focalLength = (userFacing ? 300.0 : 240.0) * dataWidth / 320.0;
|
|
270
270
|
cameraModel[0] = focalLength;
|
|
271
271
|
cameraModel[1] = focalLength;
|
|
272
272
|
cameraModel[2] = dataWidth * 0.5;
|
|
@@ -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
|
+
}
|