@zappar/zappar-cv 3.0.1-alpha.1 → 3.0.1-alpha.3
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/additional.d.ts +6 -0
- package/lib/camera-frame-data.d.ts +5 -0
- package/lib/camera-frame-data.js +1 -0
- package/lib/deserializer.d.ts +1 -0
- package/lib/deserializer.js +7 -0
- package/lib/drawgrid.d.ts +2 -0
- package/lib/drawgrid.js +136 -0
- package/lib/drawpoints.d.ts +10 -0
- package/lib/drawpoints.js +180 -0
- package/lib/gen/zappar-bridge.d.ts +126 -0
- package/lib/gen/zappar-bridge.js +7 -0
- package/lib/gen/zappar-client.d.ts +2 -2
- package/lib/gen/zappar-client.js +76 -5
- package/lib/gen/zappar-cwrap.js +81 -0
- package/lib/gen/zappar-native.d.ts +10 -0
- package/lib/gen/zappar-server.js +24 -0
- package/lib/gen/zappar.d.ts +7 -0
- package/lib/html-element-source.js +1 -0
- package/lib/imagetracker.d.ts +3 -2
- package/lib/index.d.ts +1 -0
- package/lib/native.js +28 -3
- package/lib/pipeline.d.ts +11 -3
- package/lib/pipeline.js +72 -3
- package/lib/serializer.d.ts +1 -0
- package/lib/serializer.js +1 -0
- 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 +48 -3
- package/lib/workerinterface.d.ts +16 -0
- package/lib/zappar-cv.js +134 -133
- package/lib/zappar-cv.wasm +0 -0
- package/package.json +1 -1
- package/umd/429.zappar-cv.js +1 -1
- package/umd/867.zappar-cv.js +1 -1
- package/umd/{501114eb92cddf5f56fe.wasm → a5f074b0d01366261164.wasm} +0 -0
- package/umd/zappar-cv.js +1 -1
- package/umd/zappar-cv.worker.js +1 -1
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ npm i @zappar/zappar-cv
|
|
|
18
18
|
|
|
19
19
|
You can use our CDN from within your HTML:
|
|
20
20
|
```
|
|
21
|
-
<script src="https://libs.zappar.com/zappar-cv/3.0.1-alpha.
|
|
21
|
+
<script src="https://libs.zappar.com/zappar-cv/3.0.1-alpha.3/zappar-cv.js"></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
Or you can download and host our standalone JavaScript bundle:
|
|
25
|
-
[https://libs.zappar.com/zappar-cv/3.0.1-alpha.
|
|
25
|
+
[https://libs.zappar.com/zappar-cv/3.0.1-alpha.3/zappar-cv.zip](https://libs.zappar.com/zappar-cv/3.0.1-alpha.3/zappar-cv.zip)
|
package/lib/additional.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CameraFrameData } from "./camera-frame-data";
|
|
1
2
|
import { zappar_face_mesh_t, zappar_face_tracker_t, zappar_pipeline_t, zappar_image_tracker_t, zappar_sequence_source_t } from "./gen/zappar";
|
|
2
3
|
export declare type zappar_html_element_source_t = number & {
|
|
3
4
|
_: 'zappar_html_element_source_t';
|
|
@@ -8,7 +9,12 @@ export interface Additional {
|
|
|
8
9
|
pipeline_draw_face(pipeline: zappar_pipeline_t, projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, o: zappar_face_mesh_t): void;
|
|
9
10
|
pipeline_draw_image_target_preview(pipeline: zappar_pipeline_t, projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, o: zappar_image_tracker_t, indx: number): void;
|
|
10
11
|
pipeline_draw_face_project(pipeline: zappar_pipeline_t, drawwMatrix: Float32Array, vertices: Float32Array, uvMatrix: Float32Array, uvs: Float32Array, indices: Uint16Array, texture: WebGLTexture): void;
|
|
12
|
+
pipeline_camera_frame_data_raw_enabled_set(pipeline: zappar_pipeline_t, enabled: boolean): void;
|
|
13
|
+
pipeline_camera_frame_data_raw(pipeline: zappar_pipeline_t): Promise<CameraFrameData | undefined>;
|
|
14
|
+
pipeline_camera_frame_data_width(pipeline: zappar_pipeline_t): number;
|
|
15
|
+
pipeline_camera_frame_data_height(pipeline: zappar_pipeline_t): number;
|
|
11
16
|
draw_plane(gl: WebGLRenderingContext, projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, texture: string): void;
|
|
17
|
+
draw_grid(gl: WebGLRenderingContext, projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array): void;
|
|
12
18
|
image_tracker_target_image(o: zappar_image_tracker_t, indx: number): HTMLImageElement | undefined;
|
|
13
19
|
face_mesh_load_default(o: zappar_face_mesh_t): Promise<void>;
|
|
14
20
|
face_mesh_load_default_face(o: zappar_face_mesh_t, fillMouth: boolean, fillEyeL: boolean, fillEyeR: boolean): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/deserializer.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface Message {
|
|
|
8
8
|
type: () => number;
|
|
9
9
|
matrix4x4: () => Float32Array;
|
|
10
10
|
matrix3x3: () => Float32Array;
|
|
11
|
+
floatArray: () => Float32Array;
|
|
11
12
|
identityCoefficients: () => Float32Array;
|
|
12
13
|
expressionCoefficients: () => Float32Array;
|
|
13
14
|
cameraModel: () => Float32Array;
|
package/lib/deserializer.js
CHANGED
|
@@ -40,6 +40,13 @@ export class MessageDeserializer {
|
|
|
40
40
|
this._startOffset++;
|
|
41
41
|
return ret.buffer;
|
|
42
42
|
},
|
|
43
|
+
floatArray: () => {
|
|
44
|
+
let len = this._i32View[this._startOffset++];
|
|
45
|
+
let ret = new Float32Array(len);
|
|
46
|
+
ret.set(this._f32View.subarray(this._startOffset, this._startOffset + len));
|
|
47
|
+
this._startOffset += len;
|
|
48
|
+
return ret;
|
|
49
|
+
},
|
|
43
50
|
matrix4x4: () => {
|
|
44
51
|
let len = this._i32View[this._startOffset++];
|
|
45
52
|
let ret = new Float32Array(len);
|
package/lib/drawgrid.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { compileShader, linkProgram } from "./shader";
|
|
2
|
+
let shader;
|
|
3
|
+
let vbo;
|
|
4
|
+
let uvbo;
|
|
5
|
+
export function disposeDrawGrid() {
|
|
6
|
+
shader = undefined;
|
|
7
|
+
vbo = undefined;
|
|
8
|
+
uvbo = undefined;
|
|
9
|
+
}
|
|
10
|
+
function generate(gl) {
|
|
11
|
+
if (vbo)
|
|
12
|
+
return vbo;
|
|
13
|
+
vbo = gl.createBuffer();
|
|
14
|
+
if (!vbo)
|
|
15
|
+
throw new Error("Unable to create buffer object");
|
|
16
|
+
let coords = [
|
|
17
|
+
-0.5, 0, 0.5,
|
|
18
|
+
-0.5, 0, -0.5,
|
|
19
|
+
0.5, 0, 0.5,
|
|
20
|
+
0.5, 0, -0.5
|
|
21
|
+
];
|
|
22
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
23
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(coords), gl.STATIC_DRAW);
|
|
24
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
25
|
+
return vbo;
|
|
26
|
+
}
|
|
27
|
+
function generateUVBO(gl) {
|
|
28
|
+
if (uvbo)
|
|
29
|
+
return uvbo;
|
|
30
|
+
uvbo = gl.createBuffer();
|
|
31
|
+
if (!uvbo)
|
|
32
|
+
throw new Error("Unable to create buffer object");
|
|
33
|
+
let coords = [
|
|
34
|
+
0, 1,
|
|
35
|
+
0, 0,
|
|
36
|
+
1, 1,
|
|
37
|
+
1, 0
|
|
38
|
+
];
|
|
39
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, uvbo);
|
|
40
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(coords), gl.STATIC_DRAW);
|
|
41
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
42
|
+
return uvbo;
|
|
43
|
+
}
|
|
44
|
+
export function drawGrid(gl, projectionMatrix, cameraMatrix, targetMatrix) {
|
|
45
|
+
let shader = getShader(gl);
|
|
46
|
+
let v = generate(gl);
|
|
47
|
+
let uvbo = generateUVBO(gl);
|
|
48
|
+
gl.disable(gl.DEPTH_TEST);
|
|
49
|
+
gl.useProgram(shader.prog);
|
|
50
|
+
gl.uniformMatrix4fv(shader.unif_proj, false, projectionMatrix);
|
|
51
|
+
gl.uniformMatrix4fv(shader.unif_camera, false, cameraMatrix);
|
|
52
|
+
gl.uniformMatrix4fv(shader.unif_matrix, false, targetMatrix);
|
|
53
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, v);
|
|
54
|
+
gl.vertexAttribPointer(shader.attr_position, 3, gl.FLOAT, false, 3 * 4, 0);
|
|
55
|
+
gl.enableVertexAttribArray(shader.attr_position);
|
|
56
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, uvbo);
|
|
57
|
+
gl.vertexAttribPointer(shader.attr_textureCoord, 2, gl.FLOAT, false, 2 * 4, 0);
|
|
58
|
+
gl.enableVertexAttribArray(shader.attr_textureCoord);
|
|
59
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
60
|
+
gl.disableVertexAttribArray(shader.attr_position);
|
|
61
|
+
gl.disableVertexAttribArray(shader.attr_textureCoord);
|
|
62
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
63
|
+
}
|
|
64
|
+
let vertexShaderSrc = `
|
|
65
|
+
#ifndef GL_ES
|
|
66
|
+
#define highp
|
|
67
|
+
#define mediump
|
|
68
|
+
#define lowp
|
|
69
|
+
#endif
|
|
70
|
+
|
|
71
|
+
uniform mat4 projMatrix;
|
|
72
|
+
uniform mat4 cameraMatrix;
|
|
73
|
+
uniform mat4 modelViewMatrix;
|
|
74
|
+
attribute vec4 position;
|
|
75
|
+
attribute vec2 textureCoord;
|
|
76
|
+
|
|
77
|
+
varying highp vec2 vTextureCoord;
|
|
78
|
+
|
|
79
|
+
void main()
|
|
80
|
+
{
|
|
81
|
+
gl_Position = projMatrix * cameraMatrix * modelViewMatrix * position;
|
|
82
|
+
vTextureCoord = textureCoord;
|
|
83
|
+
}`;
|
|
84
|
+
let fragmentShaderSrc = `
|
|
85
|
+
#define highp mediump
|
|
86
|
+
#ifdef GL_ES
|
|
87
|
+
// define default precision for float, vec, mat.
|
|
88
|
+
precision highp float;
|
|
89
|
+
#else
|
|
90
|
+
#define highp
|
|
91
|
+
#define mediump
|
|
92
|
+
#define lowp
|
|
93
|
+
#endif
|
|
94
|
+
|
|
95
|
+
varying highp vec2 vTextureCoord;
|
|
96
|
+
uniform sampler2D skinSampler;
|
|
97
|
+
|
|
98
|
+
void main()
|
|
99
|
+
{
|
|
100
|
+
vec2 pixels = 100.0 * vTextureCoord + 0.5;
|
|
101
|
+
if ((int(mod(pixels.x, 10.0)) == 0) || (int(mod(pixels.y, 10.0)) == 0)) {
|
|
102
|
+
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
|
103
|
+
} else {
|
|
104
|
+
discard;
|
|
105
|
+
}
|
|
106
|
+
}`;
|
|
107
|
+
function getShader(gl) {
|
|
108
|
+
if (shader)
|
|
109
|
+
return shader;
|
|
110
|
+
let prog = gl.createProgram();
|
|
111
|
+
if (!prog)
|
|
112
|
+
throw new Error("Unable to create program");
|
|
113
|
+
let vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSrc);
|
|
114
|
+
let fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSrc);
|
|
115
|
+
gl.attachShader(prog, vertexShader);
|
|
116
|
+
gl.attachShader(prog, fragmentShader);
|
|
117
|
+
linkProgram(gl, prog);
|
|
118
|
+
let unif_proj = gl.getUniformLocation(prog, "projMatrix");
|
|
119
|
+
if (!unif_proj)
|
|
120
|
+
throw new Error("Unable to get uniform location projMatrix");
|
|
121
|
+
let unif_matrix = gl.getUniformLocation(prog, "modelViewMatrix");
|
|
122
|
+
if (!unif_matrix)
|
|
123
|
+
throw new Error("Unable to get uniform location modelViewMatrix");
|
|
124
|
+
let unif_camera = gl.getUniformLocation(prog, "cameraMatrix");
|
|
125
|
+
if (!unif_camera)
|
|
126
|
+
throw new Error("Unable to get uniform location cameraMatrix");
|
|
127
|
+
shader = {
|
|
128
|
+
prog,
|
|
129
|
+
unif_matrix,
|
|
130
|
+
unif_proj,
|
|
131
|
+
unif_camera,
|
|
132
|
+
attr_position: gl.getAttribLocation(prog, "position"),
|
|
133
|
+
attr_textureCoord: gl.getAttribLocation(prog, "textureCoord")
|
|
134
|
+
};
|
|
135
|
+
return shader;
|
|
136
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class PointsDraw {
|
|
2
|
+
private _gl;
|
|
3
|
+
private _vbo;
|
|
4
|
+
private _shader;
|
|
5
|
+
constructor(_gl: WebGLRenderingContext);
|
|
6
|
+
dispose(): void;
|
|
7
|
+
private _generate;
|
|
8
|
+
drawPoints(screenWidth: number, screenHeight: number, dataWidth: number, dataHeight: number, points: Float32Array, mirror: boolean, color: [number, number, number], pointSize: number): void;
|
|
9
|
+
private _getCameraShader;
|
|
10
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { profile } from "./profile";
|
|
2
|
+
import { compileShader, linkProgram } from "./shader";
|
|
3
|
+
import { mat4 } from "gl-matrix";
|
|
4
|
+
let identity = mat4.create();
|
|
5
|
+
export class PointsDraw {
|
|
6
|
+
constructor(_gl) {
|
|
7
|
+
this._gl = _gl;
|
|
8
|
+
}
|
|
9
|
+
dispose() {
|
|
10
|
+
if (this._vbo)
|
|
11
|
+
this._gl.deleteBuffer(this._vbo);
|
|
12
|
+
this._vbo = undefined;
|
|
13
|
+
if (this._shader)
|
|
14
|
+
this._gl.deleteProgram(this._shader.prog);
|
|
15
|
+
this._shader = undefined;
|
|
16
|
+
}
|
|
17
|
+
_generate(gl, points) {
|
|
18
|
+
if (!this._vbo)
|
|
19
|
+
this._vbo = gl.createBuffer();
|
|
20
|
+
if (!this._vbo)
|
|
21
|
+
throw new Error("Unable to create buffer object");
|
|
22
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._vbo);
|
|
23
|
+
gl.bufferData(gl.ARRAY_BUFFER, points, gl.DYNAMIC_DRAW);
|
|
24
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
25
|
+
return this._vbo;
|
|
26
|
+
}
|
|
27
|
+
drawPoints(screenWidth, screenHeight, dataWidth, dataHeight, points, mirror, color, pointSize) {
|
|
28
|
+
if (points.length === 0)
|
|
29
|
+
return; // points = new Float32Array([0, 1, 0, 1]);
|
|
30
|
+
let gl = this._gl;
|
|
31
|
+
const reenableDepthTest = gl.isEnabled(gl.DEPTH_TEST);
|
|
32
|
+
const reenableScissorTest = gl.isEnabled(gl.SCISSOR_TEST);
|
|
33
|
+
const reenableCullFace = gl.isEnabled(gl.CULL_FACE);
|
|
34
|
+
const reenableStencilTest = gl.isEnabled(gl.STENCIL_TEST);
|
|
35
|
+
const reenableBlend = gl.isEnabled(gl.BLEND);
|
|
36
|
+
const previousBoundTexture = gl.getParameter(gl.TEXTURE_BINDING_2D);
|
|
37
|
+
const previousBoundFramebuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
|
|
38
|
+
const previousProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
39
|
+
const previousActiveTexture = gl.getParameter(gl.ACTIVE_TEXTURE);
|
|
40
|
+
gl.disable(gl.DEPTH_TEST);
|
|
41
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
42
|
+
gl.disable(gl.CULL_FACE);
|
|
43
|
+
gl.disable(gl.STENCIL_TEST);
|
|
44
|
+
gl.disable(gl.BLEND);
|
|
45
|
+
let shader = this._getCameraShader(gl);
|
|
46
|
+
let vbo = this._generate(gl, points);
|
|
47
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
48
|
+
gl.useProgram(shader.prog);
|
|
49
|
+
gl.uniform3f(shader.unif_color, color[0], color[1], color[2]);
|
|
50
|
+
gl.uniform1f(shader.unif_pointSize, pointSize);
|
|
51
|
+
gl.uniformMatrix4fv(shader.unif_skinTexTransform, false, getMatrix(dataWidth, dataHeight, screenWidth, screenHeight, mirror));
|
|
52
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
53
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
54
|
+
gl.vertexAttribPointer(shader.attr_position, 2, gl.FLOAT, false, 0, 0);
|
|
55
|
+
gl.enableVertexAttribArray(shader.attr_position);
|
|
56
|
+
gl.drawArrays(gl.POINTS, 0, points.length / 2);
|
|
57
|
+
gl.disableVertexAttribArray(shader.attr_position);
|
|
58
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, previousBoundFramebuffer);
|
|
59
|
+
gl.useProgram(previousProgram);
|
|
60
|
+
gl.bindTexture(gl.TEXTURE_2D, previousBoundTexture);
|
|
61
|
+
gl.activeTexture(previousActiveTexture);
|
|
62
|
+
if (reenableBlend)
|
|
63
|
+
gl.enable(gl.BLEND);
|
|
64
|
+
if (reenableCullFace)
|
|
65
|
+
gl.enable(gl.CULL_FACE);
|
|
66
|
+
if (reenableDepthTest)
|
|
67
|
+
gl.enable(gl.DEPTH_TEST);
|
|
68
|
+
if (reenableScissorTest)
|
|
69
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
70
|
+
if (reenableStencilTest)
|
|
71
|
+
gl.enable(gl.STENCIL_TEST);
|
|
72
|
+
}
|
|
73
|
+
_getCameraShader(gl) {
|
|
74
|
+
if (this._shader)
|
|
75
|
+
return this._shader;
|
|
76
|
+
let prog = gl.createProgram();
|
|
77
|
+
if (!prog)
|
|
78
|
+
throw new Error("Unable to create program");
|
|
79
|
+
let vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSrc);
|
|
80
|
+
let fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSrc);
|
|
81
|
+
gl.attachShader(prog, vertexShader);
|
|
82
|
+
gl.attachShader(prog, fragmentShader);
|
|
83
|
+
linkProgram(gl, prog);
|
|
84
|
+
let unif_skinTexTransform = gl.getUniformLocation(prog, "skinTexTransform");
|
|
85
|
+
if (!unif_skinTexTransform)
|
|
86
|
+
throw new Error("Unable to get uniform location skinTexTransform");
|
|
87
|
+
let unif_color = gl.getUniformLocation(prog, "color");
|
|
88
|
+
if (!unif_color)
|
|
89
|
+
throw new Error("Unable to get uniform location color");
|
|
90
|
+
let unif_pointSize = gl.getUniformLocation(prog, "pointSize");
|
|
91
|
+
if (!unif_pointSize)
|
|
92
|
+
throw new Error("Unable to get uniform location pointSize");
|
|
93
|
+
this._shader = {
|
|
94
|
+
prog,
|
|
95
|
+
unif_skinTexTransform,
|
|
96
|
+
unif_color,
|
|
97
|
+
unif_pointSize,
|
|
98
|
+
attr_position: gl.getAttribLocation(prog, "position"),
|
|
99
|
+
};
|
|
100
|
+
return this._shader;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
let vertexShaderSrc = `
|
|
104
|
+
#ifndef GL_ES
|
|
105
|
+
#define highp
|
|
106
|
+
#define mediump
|
|
107
|
+
#define lowp
|
|
108
|
+
#endif
|
|
109
|
+
|
|
110
|
+
attribute vec2 position;
|
|
111
|
+
uniform mat4 skinTexTransform;
|
|
112
|
+
uniform float pointSize;
|
|
113
|
+
|
|
114
|
+
void main()
|
|
115
|
+
{
|
|
116
|
+
gl_Position = skinTexTransform * vec4(position, 0.0, 1.0);
|
|
117
|
+
// gl_Position = vec4(position.x * 0.0, position.y * 0.0, 0.0, 1.0);
|
|
118
|
+
gl_PointSize = pointSize;
|
|
119
|
+
}`;
|
|
120
|
+
let fragmentShaderSrc = `
|
|
121
|
+
#define highp mediump
|
|
122
|
+
#ifdef GL_ES
|
|
123
|
+
// define default precision for float, vec, mat.
|
|
124
|
+
precision highp float;
|
|
125
|
+
#else
|
|
126
|
+
#define highp
|
|
127
|
+
#define mediump
|
|
128
|
+
#define lowp
|
|
129
|
+
#endif
|
|
130
|
+
|
|
131
|
+
uniform vec3 color;
|
|
132
|
+
|
|
133
|
+
void main()
|
|
134
|
+
{
|
|
135
|
+
gl_FragColor = vec4(color, 1.0);
|
|
136
|
+
}`;
|
|
137
|
+
function cameraRotationForScreenOrientation() {
|
|
138
|
+
if (window.screen.orientation && !profile.forceWindowOrientation) {
|
|
139
|
+
switch (window.screen.orientation.type) {
|
|
140
|
+
case "portrait-primary":
|
|
141
|
+
return 270;
|
|
142
|
+
case "landscape-secondary":
|
|
143
|
+
return 180;
|
|
144
|
+
case "portrait-secondary":
|
|
145
|
+
return 90;
|
|
146
|
+
default:
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else if (window.orientation !== undefined) {
|
|
151
|
+
switch (window.orientation) {
|
|
152
|
+
case 0: return 270;
|
|
153
|
+
case 90: return 0;
|
|
154
|
+
case 180: return 90;
|
|
155
|
+
case -90: return 180;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
function getMatrix(frameWidth, frameHeight, screenWidth, screenHeight, mirror) {
|
|
161
|
+
let ret = mat4.create();
|
|
162
|
+
let trans = mat4.create();
|
|
163
|
+
// Translate to centre UV coords
|
|
164
|
+
mat4.fromTranslation(trans, [-0.5 * frameWidth, -0.5 * frameHeight, 0]);
|
|
165
|
+
mat4.multiply(ret, trans, ret);
|
|
166
|
+
mat4.fromScaling(trans, [2 / frameWidth, 2 / -frameHeight, 1]);
|
|
167
|
+
mat4.multiply(ret, trans, ret);
|
|
168
|
+
if (mirror) {
|
|
169
|
+
mat4.fromScaling(trans, [-1, 1, 1]);
|
|
170
|
+
mat4.multiply(ret, trans, ret);
|
|
171
|
+
}
|
|
172
|
+
let screenAspect = screenWidth > screenHeight ? (screenWidth / screenHeight) : (screenHeight / screenWidth);
|
|
173
|
+
let frameAspect = frameWidth / frameHeight;
|
|
174
|
+
mat4.fromScaling(trans, [1, screenAspect / frameAspect, 1]);
|
|
175
|
+
mat4.multiply(ret, trans, ret);
|
|
176
|
+
// Apply rotation back into ZCV's landscape space
|
|
177
|
+
mat4.fromRotation(trans, cameraRotationForScreenOrientation() * Math.PI / 180.0, [0, 0, 1]);
|
|
178
|
+
mat4.multiply(ret, trans, ret);
|
|
179
|
+
return ret;
|
|
180
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { barcode_format_t } from "./zappar-native";
|
|
2
|
+
export { barcode_format_t } from "./zappar-native";
|
|
3
|
+
import { face_landmark_name_t } from "./zappar-native";
|
|
4
|
+
export { face_landmark_name_t } from "./zappar-native";
|
|
5
|
+
export { frame_pixel_format_t } from "./zappar-native";
|
|
6
|
+
import { instant_world_tracker_transform_orientation_t } from "./zappar-native";
|
|
7
|
+
export { instant_world_tracker_transform_orientation_t } from "./zappar-native";
|
|
8
|
+
import { log_level_t } from "./zappar-native";
|
|
9
|
+
export { log_level_t } from "./zappar-native";
|
|
10
|
+
export { image_target_type_t } from "./zappar-native";
|
|
11
|
+
export { world_tracker_quality_t } from "./zappar-native";
|
|
12
|
+
export declare type zappar_pipeline_t = number & {
|
|
13
|
+
_: 'zappar_pipeline_t';
|
|
14
|
+
};
|
|
15
|
+
export declare type zappar_camera_source_t = number & {
|
|
16
|
+
_: 'zappar_camera_source_t';
|
|
17
|
+
};
|
|
18
|
+
export declare type zappar_sequence_source_t = number & {
|
|
19
|
+
_: 'zappar_sequence_source_t';
|
|
20
|
+
};
|
|
21
|
+
export declare type zappar_image_tracker_t = number & {
|
|
22
|
+
_: 'zappar_image_tracker_t';
|
|
23
|
+
};
|
|
24
|
+
export declare type zappar_face_tracker_t = number & {
|
|
25
|
+
_: 'zappar_face_tracker_t';
|
|
26
|
+
};
|
|
27
|
+
export declare type zappar_face_mesh_t = number & {
|
|
28
|
+
_: 'zappar_face_mesh_t';
|
|
29
|
+
};
|
|
30
|
+
export declare type zappar_face_landmark_t = number & {
|
|
31
|
+
_: 'zappar_face_landmark_t';
|
|
32
|
+
};
|
|
33
|
+
export declare type zappar_barcode_finder_t = number & {
|
|
34
|
+
_: 'zappar_barcode_finder_t';
|
|
35
|
+
};
|
|
36
|
+
export declare type zappar_instant_world_tracker_t = number & {
|
|
37
|
+
_: 'zappar_instant_world_tracker_t';
|
|
38
|
+
};
|
|
39
|
+
export declare type zappar_world_tracker_t = number & {
|
|
40
|
+
_: 'zappar_world_tracker_t';
|
|
41
|
+
};
|
|
42
|
+
export interface zappar {
|
|
43
|
+
log_level(): log_level_t;
|
|
44
|
+
log_level_set(level: log_level_t): void;
|
|
45
|
+
analytics_project_id_set(id: string, uid: string): void;
|
|
46
|
+
pipeline_create(): zappar_pipeline_t;
|
|
47
|
+
pipeline_destroy(o: zappar_pipeline_t): void;
|
|
48
|
+
pipeline_frame_update(o: zappar_pipeline_t): void;
|
|
49
|
+
pipeline_frame_number(o: zappar_pipeline_t): number;
|
|
50
|
+
pipeline_camera_model(o: zappar_pipeline_t): Float32Array;
|
|
51
|
+
pipeline_camera_frame_user_data(o: zappar_pipeline_t): number;
|
|
52
|
+
pipeline_camera_frame_submit(o: zappar_pipeline_t, data: ArrayBuffer, width: number, height: number, user_data: number, camera_to_device_transform: Float32Array, camera_model: Float32Array, user_facing: boolean): void;
|
|
53
|
+
pipeline_camera_frame_camera_attitude(o: zappar_pipeline_t): Float32Array;
|
|
54
|
+
pipeline_camera_frame_device_attitude(o: zappar_pipeline_t): Float32Array;
|
|
55
|
+
pipeline_motion_accelerometer_submit(o: zappar_pipeline_t, time: number, x: number, y: number, z: number): void;
|
|
56
|
+
pipeline_motion_accelerometer_with_gravity_submit_int(o: zappar_pipeline_t, time: number, interval: number, x: number, y: number, z: number): void;
|
|
57
|
+
pipeline_motion_accelerometer_without_gravity_submit_int(o: zappar_pipeline_t, time: number, interval: number, x: number, y: number, z: number): void;
|
|
58
|
+
pipeline_motion_rotation_rate_submit(o: zappar_pipeline_t, time: number, x: number, y: number, z: number): void;
|
|
59
|
+
pipeline_motion_rotation_rate_submit_int(o: zappar_pipeline_t, time: number, interval: number, x: number, y: number, z: number): void;
|
|
60
|
+
pipeline_motion_attitude_submit(o: zappar_pipeline_t, time: number, x: number, y: number, z: number): void;
|
|
61
|
+
pipeline_motion_attitude_submit_int(o: zappar_pipeline_t, time: number, interval: number, x: number, y: number, z: number): void;
|
|
62
|
+
pipeline_motion_attitude_matrix_submit(o: zappar_pipeline_t, mat: Float32Array): void;
|
|
63
|
+
camera_source_create(pipeline: zappar_pipeline_t, device_id: string): zappar_camera_source_t;
|
|
64
|
+
camera_source_destroy(o: zappar_camera_source_t): void;
|
|
65
|
+
sequence_source_create(pipeline: zappar_pipeline_t): zappar_sequence_source_t;
|
|
66
|
+
sequence_source_destroy(o: zappar_sequence_source_t): void;
|
|
67
|
+
image_tracker_create(pipeline: zappar_pipeline_t): zappar_image_tracker_t;
|
|
68
|
+
image_tracker_destroy(o: zappar_image_tracker_t): void;
|
|
69
|
+
image_tracker_target_load_from_memory(o: zappar_image_tracker_t, data: ArrayBuffer): void;
|
|
70
|
+
image_tracker_target_loaded_version(o: zappar_image_tracker_t): number;
|
|
71
|
+
image_tracker_enabled(o: zappar_image_tracker_t): boolean;
|
|
72
|
+
image_tracker_enabled_set(o: zappar_image_tracker_t, enabled: boolean): void;
|
|
73
|
+
image_tracker_anchor_count(o: zappar_image_tracker_t): number;
|
|
74
|
+
image_tracker_anchor_id(o: zappar_image_tracker_t, indx: number): string;
|
|
75
|
+
image_tracker_anchor_pose_raw(o: zappar_image_tracker_t, indx: number): Float32Array;
|
|
76
|
+
face_tracker_create(pipeline: zappar_pipeline_t): zappar_face_tracker_t;
|
|
77
|
+
face_tracker_destroy(o: zappar_face_tracker_t): void;
|
|
78
|
+
face_tracker_model_load_from_memory(o: zappar_face_tracker_t, data: ArrayBuffer): void;
|
|
79
|
+
face_tracker_model_loaded_version(o: zappar_face_tracker_t): number;
|
|
80
|
+
face_tracker_enabled_set(o: zappar_face_tracker_t, enabled: boolean): void;
|
|
81
|
+
face_tracker_enabled(o: zappar_face_tracker_t): boolean;
|
|
82
|
+
face_tracker_max_faces_set(o: zappar_face_tracker_t, num: number): void;
|
|
83
|
+
face_tracker_max_faces(o: zappar_face_tracker_t): number;
|
|
84
|
+
face_tracker_anchor_count(o: zappar_face_tracker_t): number;
|
|
85
|
+
face_tracker_anchor_id(o: zappar_face_tracker_t, indx: number): string;
|
|
86
|
+
face_tracker_anchor_pose_raw(o: zappar_face_tracker_t, indx: number): Float32Array;
|
|
87
|
+
face_tracker_anchor_identity_coefficients(o: zappar_face_tracker_t, indx: number): Float32Array;
|
|
88
|
+
face_tracker_anchor_expression_coefficients(o: zappar_face_tracker_t, indx: number): Float32Array;
|
|
89
|
+
face_mesh_create(): zappar_face_mesh_t;
|
|
90
|
+
face_mesh_destroy(o: zappar_face_mesh_t): void;
|
|
91
|
+
face_landmark_create(landmark: face_landmark_name_t): zappar_face_landmark_t;
|
|
92
|
+
face_landmark_destroy(o: zappar_face_landmark_t): void;
|
|
93
|
+
barcode_finder_create(pipeline: zappar_pipeline_t): zappar_barcode_finder_t;
|
|
94
|
+
barcode_finder_destroy(o: zappar_barcode_finder_t): void;
|
|
95
|
+
barcode_finder_enabled_set(o: zappar_barcode_finder_t, enabled: boolean): void;
|
|
96
|
+
barcode_finder_enabled(o: zappar_barcode_finder_t): boolean;
|
|
97
|
+
barcode_finder_found_number(o: zappar_barcode_finder_t): number;
|
|
98
|
+
barcode_finder_found_text(o: zappar_barcode_finder_t, indx: number): string;
|
|
99
|
+
barcode_finder_found_format(o: zappar_barcode_finder_t, indx: number): barcode_format_t;
|
|
100
|
+
barcode_finder_formats(o: zappar_barcode_finder_t): barcode_format_t;
|
|
101
|
+
barcode_finder_formats_set(o: zappar_barcode_finder_t, f: barcode_format_t): void;
|
|
102
|
+
instant_world_tracker_create(pipeline: zappar_pipeline_t): zappar_instant_world_tracker_t;
|
|
103
|
+
instant_world_tracker_destroy(o: zappar_instant_world_tracker_t): void;
|
|
104
|
+
instant_world_tracker_enabled_set(o: zappar_instant_world_tracker_t, enabled: boolean): void;
|
|
105
|
+
instant_world_tracker_enabled(o: zappar_instant_world_tracker_t): boolean;
|
|
106
|
+
instant_world_tracker_anchor_pose_raw(o: zappar_instant_world_tracker_t): Float32Array;
|
|
107
|
+
instant_world_tracker_anchor_pose_set_from_camera_offset_raw(o: zappar_instant_world_tracker_t, x: number, y: number, z: number, orientation: instant_world_tracker_transform_orientation_t): void;
|
|
108
|
+
world_tracker_create(pipeline: zappar_pipeline_t): zappar_world_tracker_t;
|
|
109
|
+
world_tracker_destroy(o: zappar_world_tracker_t): void;
|
|
110
|
+
world_tracker_enabled(o: zappar_world_tracker_t): boolean;
|
|
111
|
+
world_tracker_enabled_set(o: zappar_world_tracker_t, enabled: boolean): void;
|
|
112
|
+
world_tracker_quality(o: zappar_world_tracker_t): number;
|
|
113
|
+
world_tracker_plane_count(o: zappar_world_tracker_t): number;
|
|
114
|
+
world_tracker_plane_pose_raw(o: zappar_world_tracker_t, indx: number): Float32Array;
|
|
115
|
+
world_tracker_world_anchor_valid(o: zappar_world_tracker_t): boolean;
|
|
116
|
+
world_tracker_world_anchor_pose_raw(o: zappar_world_tracker_t): Float32Array;
|
|
117
|
+
world_tracker_ground_anchor_valid(o: zappar_world_tracker_t): boolean;
|
|
118
|
+
world_tracker_ground_anchor_pose_raw(o: zappar_world_tracker_t): Float32Array;
|
|
119
|
+
world_tracker_reset(o: zappar_world_tracker_t): void;
|
|
120
|
+
world_tracker_debug_enabled(o: zappar_world_tracker_t): boolean;
|
|
121
|
+
world_tracker_debug_enabled_set(o: zappar_world_tracker_t, debug_enabled: boolean): void;
|
|
122
|
+
world_tracker_debug_tracks_data_size(o: zappar_world_tracker_t): number;
|
|
123
|
+
world_tracker_debug_tracks_data(o: zappar_world_tracker_t): Float32Array;
|
|
124
|
+
world_tracker_debug_projections_data_size(o: zappar_world_tracker_t): number;
|
|
125
|
+
world_tracker_debug_projections_data(o: zappar_world_tracker_t): Float32Array;
|
|
126
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { barcode_format_t } from "./zappar-native";
|
|
2
|
+
export { face_landmark_name_t } from "./zappar-native";
|
|
3
|
+
export { frame_pixel_format_t } from "./zappar-native";
|
|
4
|
+
export { instant_world_tracker_transform_orientation_t } from "./zappar-native";
|
|
5
|
+
export { log_level_t } from "./zappar-native";
|
|
6
|
+
export { image_target_type_t } from "./zappar-native";
|
|
7
|
+
export { world_tracker_quality_t } from "./zappar-native";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MessageSerializer } from "../serializer";
|
|
2
2
|
import { MessageDeserializer } from "../deserializer";
|
|
3
|
-
import {
|
|
3
|
+
import { zappar } from "./zappar-bridge";
|
|
4
4
|
export declare class zappar_client {
|
|
5
5
|
private _messageSender;
|
|
6
6
|
constructor(_messageSender: (ab: ArrayBuffer) => void);
|
|
@@ -18,6 +18,6 @@ export declare class zappar_client {
|
|
|
18
18
|
private _barcode_finder_state_by_instance;
|
|
19
19
|
private _instant_world_tracker_state_by_instance;
|
|
20
20
|
private _world_tracker_state_by_instance;
|
|
21
|
-
impl:
|
|
21
|
+
impl: zappar;
|
|
22
22
|
processMessages(a: ArrayBuffer): void;
|
|
23
23
|
}
|
package/lib/gen/zappar-client.js
CHANGED
|
@@ -103,11 +103,6 @@ export class zappar_client {
|
|
|
103
103
|
m.bool(user_facing);
|
|
104
104
|
});
|
|
105
105
|
},
|
|
106
|
-
pipeline_camera_frame_submit_raw_pointer: (o, data, dataLength, format, width, height, user_data, camera_to_device_transform, rotation, camera_model, user_facing, timestamp) => {
|
|
107
|
-
let s = this._pipeline_state_by_instance.get(o);
|
|
108
|
-
if (!s)
|
|
109
|
-
throw new Error("This object has been destroyed");
|
|
110
|
-
},
|
|
111
106
|
pipeline_camera_frame_camera_attitude: (o) => {
|
|
112
107
|
let s = this._pipeline_state_by_instance.get(o);
|
|
113
108
|
if (!s)
|
|
@@ -616,6 +611,11 @@ export class zappar_client {
|
|
|
616
611
|
world_anchor_pose: new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]),
|
|
617
612
|
ground_anchor_valid: true,
|
|
618
613
|
ground_anchor_pose: new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]),
|
|
614
|
+
debug_enabled: false,
|
|
615
|
+
debug_tracks_data: new Float32Array([]),
|
|
616
|
+
debug_tracks_data_size: 0,
|
|
617
|
+
debug_projections_data: new Float32Array([]),
|
|
618
|
+
debug_projections_data_size: 0,
|
|
619
619
|
quality: 0,
|
|
620
620
|
};
|
|
621
621
|
this._world_tracker_state_by_instance.set(newId, s);
|
|
@@ -699,6 +699,45 @@ export class zappar_client {
|
|
|
699
699
|
m.type(o);
|
|
700
700
|
});
|
|
701
701
|
},
|
|
702
|
+
world_tracker_debug_enabled: (o) => {
|
|
703
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
704
|
+
if (!s)
|
|
705
|
+
throw new Error("This object has been destroyed");
|
|
706
|
+
return s.debug_enabled;
|
|
707
|
+
},
|
|
708
|
+
world_tracker_debug_enabled_set: (o, debug_enabled) => {
|
|
709
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
710
|
+
if (!s)
|
|
711
|
+
throw new Error("This object has been destroyed");
|
|
712
|
+
this.serializer.sendMessage(45, m => {
|
|
713
|
+
m.type(o);
|
|
714
|
+
m.bool(debug_enabled);
|
|
715
|
+
});
|
|
716
|
+
},
|
|
717
|
+
world_tracker_debug_tracks_data_size: (o) => {
|
|
718
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
719
|
+
if (!s)
|
|
720
|
+
throw new Error("This object has been destroyed");
|
|
721
|
+
return s.debug_tracks_data_size;
|
|
722
|
+
},
|
|
723
|
+
world_tracker_debug_tracks_data: (o) => {
|
|
724
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
725
|
+
if (!s)
|
|
726
|
+
throw new Error("This object has been destroyed");
|
|
727
|
+
return s.debug_tracks_data;
|
|
728
|
+
},
|
|
729
|
+
world_tracker_debug_projections_data_size: (o) => {
|
|
730
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
731
|
+
if (!s)
|
|
732
|
+
throw new Error("This object has been destroyed");
|
|
733
|
+
return s.debug_projections_data_size;
|
|
734
|
+
},
|
|
735
|
+
world_tracker_debug_projections_data: (o) => {
|
|
736
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
737
|
+
if (!s)
|
|
738
|
+
throw new Error("This object has been destroyed");
|
|
739
|
+
return s.debug_projections_data;
|
|
740
|
+
},
|
|
702
741
|
};
|
|
703
742
|
}
|
|
704
743
|
processMessages(a) {
|
|
@@ -922,6 +961,38 @@ export class zappar_client {
|
|
|
922
961
|
inst.ground_anchor_pose = msg.matrix4x4();
|
|
923
962
|
break;
|
|
924
963
|
}
|
|
964
|
+
case 29: {
|
|
965
|
+
let handle = msg.type();
|
|
966
|
+
let inst = this._world_tracker_state_by_instance.get(handle);
|
|
967
|
+
if (!inst)
|
|
968
|
+
return;
|
|
969
|
+
inst.debug_tracks_data_size = msg.int();
|
|
970
|
+
break;
|
|
971
|
+
}
|
|
972
|
+
case 28: {
|
|
973
|
+
let handle = msg.type();
|
|
974
|
+
let inst = this._world_tracker_state_by_instance.get(handle);
|
|
975
|
+
if (!inst)
|
|
976
|
+
return;
|
|
977
|
+
inst.debug_tracks_data = msg.floatArray();
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
980
|
+
case 31: {
|
|
981
|
+
let handle = msg.type();
|
|
982
|
+
let inst = this._world_tracker_state_by_instance.get(handle);
|
|
983
|
+
if (!inst)
|
|
984
|
+
return;
|
|
985
|
+
inst.debug_projections_data_size = msg.int();
|
|
986
|
+
break;
|
|
987
|
+
}
|
|
988
|
+
case 30: {
|
|
989
|
+
let handle = msg.type();
|
|
990
|
+
let inst = this._world_tracker_state_by_instance.get(handle);
|
|
991
|
+
if (!inst)
|
|
992
|
+
return;
|
|
993
|
+
inst.debug_projections_data = msg.floatArray();
|
|
994
|
+
break;
|
|
995
|
+
}
|
|
925
996
|
}
|
|
926
997
|
});
|
|
927
998
|
}
|