@zappar/zappar-cv 3.0.1-alpha.2 → 3.0.1-alpha.4
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 +3 -0
- package/lib/data-download.d.ts +8 -0
- package/lib/data-download.js +8 -0
- package/lib/deserializer.d.ts +1 -0
- package/lib/deserializer.js +7 -0
- package/lib/direct.js +1 -1
- 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 +6 -0
- package/lib/gen/zappar-client.js +76 -0
- package/lib/gen/zappar-cwrap.js +53 -0
- package/lib/gen/zappar-native.d.ts +6 -0
- package/lib/gen/zappar-server.js +24 -0
- package/lib/gen/zappar.d.ts +6 -0
- package/lib/native.js +20 -0
- package/lib/serializer.d.ts +1 -0
- package/lib/serializer.js +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/worker-client.js +2 -1
- package/lib/worker-server.d.ts +1 -1
- package/lib/worker-server.js +21 -5
- package/lib/worker.js +2 -1
- package/lib/zappar-cv.js +133 -133
- package/lib/zappar-cv.wasm +0 -0
- package/package.json +1 -1
- package/umd/{36d6b6985808cbeca829.wasm → 5e1d4d2ab3d542d30625.wasm} +0 -0
- package/umd/751.zappar-cv.js +1 -0
- package/umd/867.zappar-cv.js +1 -1
- package/umd/zappar-cv.js +1 -1
- package/umd/zappar-cv.worker.js +1 -1
- package/umd/429.zappar-cv.js +0 -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.4/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.4/zappar-cv.zip](https://libs.zappar.com/zappar-cv/3.0.1-alpha.4/zappar-cv.zip)
|
package/lib/additional.d.ts
CHANGED
|
@@ -11,7 +11,10 @@ export interface Additional {
|
|
|
11
11
|
pipeline_draw_face_project(pipeline: zappar_pipeline_t, drawwMatrix: Float32Array, vertices: Float32Array, uvMatrix: Float32Array, uvs: Float32Array, indices: Uint16Array, texture: WebGLTexture): void;
|
|
12
12
|
pipeline_camera_frame_data_raw_enabled_set(pipeline: zappar_pipeline_t, enabled: boolean): void;
|
|
13
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;
|
|
14
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;
|
|
15
18
|
image_tracker_target_image(o: zappar_image_tracker_t, indx: number): HTMLImageElement | undefined;
|
|
16
19
|
face_mesh_load_default(o: zappar_face_mesh_t): Promise<void>;
|
|
17
20
|
face_mesh_load_default_face(o: zappar_face_mesh_t, fillMouth: boolean, fillEyeL: boolean, fillEyeR: boolean): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as ZNM from "./zappar-cv";
|
|
2
|
+
export interface DataDownloadAPI {
|
|
3
|
+
data_download_clear: () => void;
|
|
4
|
+
data_download_size: () => number;
|
|
5
|
+
data_download: () => number;
|
|
6
|
+
data_should_record_set: (v: number) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare function getDataDownloadAPI(mod: ZNM.Module): DataDownloadAPI;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function getDataDownloadAPI(mod) {
|
|
2
|
+
return {
|
|
3
|
+
data_download_clear: mod.cwrap("data_download_clear", null, []),
|
|
4
|
+
data_download_size: mod.cwrap("data_download_size", "number", []),
|
|
5
|
+
data_download: mod.cwrap("data_download", "number", []),
|
|
6
|
+
data_should_record_set: mod.cwrap("data_should_record_set", null, ["number"]),
|
|
7
|
+
};
|
|
8
|
+
}
|
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/direct.js
CHANGED
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
|
+
}
|
|
@@ -117,4 +117,10 @@ export interface zappar {
|
|
|
117
117
|
world_tracker_ground_anchor_valid(o: zappar_world_tracker_t): boolean;
|
|
118
118
|
world_tracker_ground_anchor_pose_raw(o: zappar_world_tracker_t): Float32Array;
|
|
119
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;
|
|
120
126
|
}
|
package/lib/gen/zappar-client.js
CHANGED
|
@@ -611,6 +611,11 @@ export class zappar_client {
|
|
|
611
611
|
world_anchor_pose: new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]),
|
|
612
612
|
ground_anchor_valid: true,
|
|
613
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,
|
|
614
619
|
quality: 0,
|
|
615
620
|
};
|
|
616
621
|
this._world_tracker_state_by_instance.set(newId, s);
|
|
@@ -694,6 +699,45 @@ export class zappar_client {
|
|
|
694
699
|
m.type(o);
|
|
695
700
|
});
|
|
696
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
|
+
},
|
|
697
741
|
};
|
|
698
742
|
}
|
|
699
743
|
processMessages(a) {
|
|
@@ -917,6 +961,38 @@ export class zappar_client {
|
|
|
917
961
|
inst.ground_anchor_pose = msg.matrix4x4();
|
|
918
962
|
break;
|
|
919
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
|
+
}
|
|
920
996
|
}
|
|
921
997
|
});
|
|
922
998
|
}
|
package/lib/gen/zappar-cwrap.js
CHANGED
|
@@ -232,6 +232,25 @@ export function getRuntimeObject(mod) {
|
|
|
232
232
|
let world_tracker_reset_wrapped = mod.cwrap("zappar_world_tracker_reset", null, [
|
|
233
233
|
"number"
|
|
234
234
|
]);
|
|
235
|
+
let world_tracker_debug_enabled_wrapped = mod.cwrap("zappar_world_tracker_debug_enabled", "number", [
|
|
236
|
+
"number"
|
|
237
|
+
]);
|
|
238
|
+
let world_tracker_debug_enabled_set_wrapped = mod.cwrap("zappar_world_tracker_debug_enabled_set", null, [
|
|
239
|
+
"number",
|
|
240
|
+
"number"
|
|
241
|
+
]);
|
|
242
|
+
let world_tracker_debug_tracks_data_size_wrapped = mod.cwrap("zappar_world_tracker_debug_tracks_data_size", "number", [
|
|
243
|
+
"number"
|
|
244
|
+
]);
|
|
245
|
+
let world_tracker_debug_tracks_data_wrapped = mod.cwrap("zappar_world_tracker_debug_tracks_data", "number", [
|
|
246
|
+
"number"
|
|
247
|
+
]);
|
|
248
|
+
let world_tracker_debug_projections_data_size_wrapped = mod.cwrap("zappar_world_tracker_debug_projections_data_size", "number", [
|
|
249
|
+
"number"
|
|
250
|
+
]);
|
|
251
|
+
let world_tracker_debug_projections_data_wrapped = mod.cwrap("zappar_world_tracker_debug_projections_data", "number", [
|
|
252
|
+
"number"
|
|
253
|
+
]);
|
|
235
254
|
let dataArrayArgLength = 32;
|
|
236
255
|
let dataArrayArg = mod._malloc(dataArrayArgLength);
|
|
237
256
|
let floatDataArrayArgLength = 16 * 4;
|
|
@@ -707,5 +726,39 @@ export function getRuntimeObject(mod) {
|
|
|
707
726
|
let ret = world_tracker_reset_wrapped(o);
|
|
708
727
|
return ret;
|
|
709
728
|
},
|
|
729
|
+
world_tracker_debug_enabled: (o) => {
|
|
730
|
+
let ret = world_tracker_debug_enabled_wrapped(o);
|
|
731
|
+
ret = ret === 1;
|
|
732
|
+
return ret;
|
|
733
|
+
},
|
|
734
|
+
world_tracker_debug_enabled_set: (o, debug_enabled) => {
|
|
735
|
+
let arg_debug_enabled = debug_enabled ? 1 : 0;
|
|
736
|
+
let ret = world_tracker_debug_enabled_set_wrapped(o, arg_debug_enabled);
|
|
737
|
+
return ret;
|
|
738
|
+
},
|
|
739
|
+
world_tracker_debug_tracks_data_size: (o) => {
|
|
740
|
+
let ret = world_tracker_debug_tracks_data_size_wrapped(o);
|
|
741
|
+
return ret;
|
|
742
|
+
},
|
|
743
|
+
world_tracker_debug_tracks_data: (o) => {
|
|
744
|
+
let ret = world_tracker_debug_tracks_data_wrapped(o);
|
|
745
|
+
let retsize = world_tracker_debug_tracks_data_size_wrapped(o);
|
|
746
|
+
let ab = new Float32Array(retsize);
|
|
747
|
+
ab.set(mod.HEAPF32.subarray(ret / 4, retsize + ret / 4));
|
|
748
|
+
ret = ab;
|
|
749
|
+
return ret;
|
|
750
|
+
},
|
|
751
|
+
world_tracker_debug_projections_data_size: (o) => {
|
|
752
|
+
let ret = world_tracker_debug_projections_data_size_wrapped(o);
|
|
753
|
+
return ret;
|
|
754
|
+
},
|
|
755
|
+
world_tracker_debug_projections_data: (o) => {
|
|
756
|
+
let ret = world_tracker_debug_projections_data_wrapped(o);
|
|
757
|
+
let retsize = world_tracker_debug_projections_data_size_wrapped(o);
|
|
758
|
+
let ab = new Float32Array(retsize);
|
|
759
|
+
ab.set(mod.HEAPF32.subarray(ret / 4, retsize + ret / 4));
|
|
760
|
+
ret = ab;
|
|
761
|
+
return ret;
|
|
762
|
+
},
|
|
710
763
|
};
|
|
711
764
|
}
|
|
@@ -179,4 +179,10 @@ export interface zappar_cwrap {
|
|
|
179
179
|
world_tracker_ground_anchor_valid(o: zappar_world_tracker_t): boolean;
|
|
180
180
|
world_tracker_ground_anchor_pose_raw(o: zappar_world_tracker_t): Float32Array;
|
|
181
181
|
world_tracker_reset(o: zappar_world_tracker_t): void;
|
|
182
|
+
world_tracker_debug_enabled(o: zappar_world_tracker_t): boolean;
|
|
183
|
+
world_tracker_debug_enabled_set(o: zappar_world_tracker_t, debug_enabled: boolean): void;
|
|
184
|
+
world_tracker_debug_tracks_data_size(o: zappar_world_tracker_t): number;
|
|
185
|
+
world_tracker_debug_tracks_data(o: zappar_world_tracker_t): Float32Array;
|
|
186
|
+
world_tracker_debug_projections_data_size(o: zappar_world_tracker_t): number;
|
|
187
|
+
world_tracker_debug_projections_data(o: zappar_world_tracker_t): Float32Array;
|
|
182
188
|
}
|
package/lib/gen/zappar-server.js
CHANGED
|
@@ -384,6 +384,14 @@ export class zappar_server {
|
|
|
384
384
|
this._impl.world_tracker_reset(obj);
|
|
385
385
|
break;
|
|
386
386
|
}
|
|
387
|
+
case 45: {
|
|
388
|
+
let clientId = msg.type();
|
|
389
|
+
let obj = this._world_tracker_by_instance.get(clientId);
|
|
390
|
+
if (obj === undefined)
|
|
391
|
+
return;
|
|
392
|
+
this._impl.world_tracker_debug_enabled_set(obj, msg.bool());
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
387
395
|
}
|
|
388
396
|
});
|
|
389
397
|
}
|
|
@@ -598,6 +606,22 @@ export class zappar_server {
|
|
|
598
606
|
msg.type(k);
|
|
599
607
|
msg.matrix4x4(this._impl.world_tracker_ground_anchor_pose_raw(v));
|
|
600
608
|
});
|
|
609
|
+
serializer.sendMessage(29, msg => {
|
|
610
|
+
msg.type(k);
|
|
611
|
+
msg.int(this._impl.world_tracker_debug_tracks_data_size(v));
|
|
612
|
+
});
|
|
613
|
+
serializer.sendMessage(28, msg => {
|
|
614
|
+
msg.type(k);
|
|
615
|
+
msg.floatArray(this._impl.world_tracker_debug_tracks_data(v));
|
|
616
|
+
});
|
|
617
|
+
serializer.sendMessage(31, msg => {
|
|
618
|
+
msg.type(k);
|
|
619
|
+
msg.int(this._impl.world_tracker_debug_projections_data_size(v));
|
|
620
|
+
});
|
|
621
|
+
serializer.sendMessage(30, msg => {
|
|
622
|
+
msg.type(k);
|
|
623
|
+
msg.floatArray(this._impl.world_tracker_debug_projections_data(v));
|
|
624
|
+
});
|
|
601
625
|
}
|
|
602
626
|
}
|
|
603
627
|
}
|
package/lib/gen/zappar.d.ts
CHANGED
|
@@ -201,4 +201,10 @@ export interface zappar {
|
|
|
201
201
|
world_tracker_ground_anchor_pose_camera_relative(o: zappar_world_tracker_t, mirror: boolean): Float32Array;
|
|
202
202
|
world_tracker_ground_anchor_pose(o: zappar_world_tracker_t, camera_pose: Float32Array, mirror: boolean): Float32Array;
|
|
203
203
|
world_tracker_reset(o: zappar_world_tracker_t): void;
|
|
204
|
+
world_tracker_debug_enabled(o: zappar_world_tracker_t): boolean;
|
|
205
|
+
world_tracker_debug_enabled_set(o: zappar_world_tracker_t, debug_enabled: boolean): void;
|
|
206
|
+
world_tracker_debug_tracks_data_size(o: zappar_world_tracker_t): number;
|
|
207
|
+
world_tracker_debug_tracks_data(o: zappar_world_tracker_t): Float32Array;
|
|
208
|
+
world_tracker_debug_projections_data_size(o: zappar_world_tracker_t): number;
|
|
209
|
+
world_tracker_debug_projections_data(o: zappar_world_tracker_t): Float32Array;
|
|
204
210
|
}
|