@zappar/zappar-cv 3.0.1-alpha.13 → 3.0.1-alpha.15
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/deserializer.d.ts +1 -0
- package/lib/deserializer.js +9 -0
- package/lib/drawaxis.d.ts +2 -0
- package/lib/drawaxis.js +172 -0
- package/lib/drawgrid.js +3 -0
- package/lib/drawpointswithtype.d.ts +13 -0
- package/lib/drawpointswithtype.js +190 -0
- package/lib/gen/zappar-bridge.d.ts +4 -0
- package/lib/gen/zappar-client.js +51 -5
- package/lib/gen/zappar-cwrap.js +35 -0
- package/lib/gen/zappar-native.d.ts +4 -0
- package/lib/gen/zappar-server.js +20 -4
- package/lib/gen/zappar.d.ts +4 -0
- package/lib/html-element-source.d.ts +3 -0
- package/lib/html-element-source.js +25 -1
- 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-server.js +1 -1
- package/lib/zappar-cv.js +1 -1
- package/lib/zappar-cv.wasm +0 -0
- package/package.json +1 -1
- package/umd/751.zappar-cv.js +1 -1
- package/umd/867.zappar-cv.js +1 -1
- package/umd/{7a7455e00ac55a4f34d3.wasm → 97ab16ef8d251feb4f5d.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.15/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.15/zappar-cv.zip](https://libs.zappar.com/zappar-cv/3.0.1-alpha.15/zappar-cv.zip)
|
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
|
+
ucharArray: () => Uint8Array;
|
|
11
12
|
floatArray: () => Float32Array;
|
|
12
13
|
identityCoefficients: () => Float32Array;
|
|
13
14
|
expressionCoefficients: () => Float32Array;
|
package/lib/deserializer.js
CHANGED
|
@@ -40,6 +40,15 @@ export class MessageDeserializer {
|
|
|
40
40
|
this._startOffset++;
|
|
41
41
|
return ret.buffer;
|
|
42
42
|
},
|
|
43
|
+
ucharArray: () => {
|
|
44
|
+
let len = this._i32View[this._startOffset++];
|
|
45
|
+
let ret = new Uint8Array(len);
|
|
46
|
+
ret.set(this._u8View.subarray(this._startOffset * 4, this._startOffset * 4 + len));
|
|
47
|
+
this._startOffset += (ret.byteLength >> 2);
|
|
48
|
+
if ((ret.byteLength & 3) !== 0)
|
|
49
|
+
this._startOffset++;
|
|
50
|
+
return ret;
|
|
51
|
+
},
|
|
43
52
|
floatArray: () => {
|
|
44
53
|
let len = this._i32View[this._startOffset++];
|
|
45
54
|
let ret = new Float32Array(len);
|
package/lib/drawaxis.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { compileShader, linkProgram } from "./shader";
|
|
2
|
+
let shader;
|
|
3
|
+
let vbo;
|
|
4
|
+
let uvbo;
|
|
5
|
+
let texturesByUrl = {};
|
|
6
|
+
export function disposeDrawPlane() {
|
|
7
|
+
shader = undefined;
|
|
8
|
+
vbo = undefined;
|
|
9
|
+
uvbo = undefined;
|
|
10
|
+
texturesByUrl = {};
|
|
11
|
+
}
|
|
12
|
+
function generate(gl) {
|
|
13
|
+
if (vbo)
|
|
14
|
+
return vbo;
|
|
15
|
+
vbo = gl.createBuffer();
|
|
16
|
+
if (!vbo)
|
|
17
|
+
throw new Error("Unable to create buffer object");
|
|
18
|
+
let coords = [
|
|
19
|
+
0, 0, 0, 1, 0, 0,
|
|
20
|
+
0, 0, 0, 0, 1, 0,
|
|
21
|
+
0, 0, 0, 0, 0, 1
|
|
22
|
+
];
|
|
23
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
24
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(coords), gl.STATIC_DRAW);
|
|
25
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
26
|
+
return vbo;
|
|
27
|
+
}
|
|
28
|
+
function generateColor(gl) {
|
|
29
|
+
if (uvbo)
|
|
30
|
+
return uvbo;
|
|
31
|
+
uvbo = gl.createBuffer();
|
|
32
|
+
if (!uvbo)
|
|
33
|
+
throw new Error("Unable to create buffer object");
|
|
34
|
+
let coords = [
|
|
35
|
+
1, 0, 0, 1, 1, 0, 0, 1,
|
|
36
|
+
0, 1, 0, 1, 0, 1, 0, 1,
|
|
37
|
+
0, 0, 1, 1, 0, 0, 1, 1
|
|
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 drawAxis(gl, projectionMatrix, cameraMatrix, targetMatrix) {
|
|
45
|
+
let shader = getShader(gl);
|
|
46
|
+
let v = generate(gl);
|
|
47
|
+
let uvbo = generateColor(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.activeTexture(gl.TEXTURE0);
|
|
55
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
56
|
+
gl.vertexAttribPointer(shader.attr_position, 3, gl.FLOAT, false, 3 * 4, 0);
|
|
57
|
+
gl.enableVertexAttribArray(shader.attr_position);
|
|
58
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, uvbo);
|
|
59
|
+
gl.vertexAttribPointer(shader.attr_color, 4, gl.FLOAT, false, 4 * 4, 0);
|
|
60
|
+
gl.enableVertexAttribArray(shader.attr_color);
|
|
61
|
+
gl.lineWidth(10);
|
|
62
|
+
gl.drawArrays(gl.LINES, 0, 6);
|
|
63
|
+
gl.disableVertexAttribArray(shader.attr_position);
|
|
64
|
+
gl.disableVertexAttribArray(shader.attr_color);
|
|
65
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
66
|
+
}
|
|
67
|
+
function generateLocalMatrix() {
|
|
68
|
+
let position = [0, 0, -5];
|
|
69
|
+
return new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, position[0], position[1], position[2], 1]);
|
|
70
|
+
}
|
|
71
|
+
let vertexShaderSrc = `
|
|
72
|
+
#ifndef GL_ES
|
|
73
|
+
#define highp
|
|
74
|
+
#define mediump
|
|
75
|
+
#define lowp
|
|
76
|
+
#endif
|
|
77
|
+
|
|
78
|
+
uniform mat4 projMatrix;
|
|
79
|
+
uniform mat4 cameraMatrix;
|
|
80
|
+
uniform mat4 modelViewMatrix;
|
|
81
|
+
attribute vec4 position;
|
|
82
|
+
attribute vec4 color;
|
|
83
|
+
|
|
84
|
+
varying highp vec4 vColor;
|
|
85
|
+
|
|
86
|
+
void main()
|
|
87
|
+
{
|
|
88
|
+
gl_Position = projMatrix * cameraMatrix * modelViewMatrix * position;
|
|
89
|
+
vColor = color;
|
|
90
|
+
}`;
|
|
91
|
+
let fragmentShaderSrc = `
|
|
92
|
+
#define highp mediump
|
|
93
|
+
#ifdef GL_ES
|
|
94
|
+
// define default precision for float, vec, mat.
|
|
95
|
+
precision highp float;
|
|
96
|
+
#else
|
|
97
|
+
#define highp
|
|
98
|
+
#define mediump
|
|
99
|
+
#define lowp
|
|
100
|
+
#endif
|
|
101
|
+
|
|
102
|
+
varying highp vec4 vColor;
|
|
103
|
+
|
|
104
|
+
void main()
|
|
105
|
+
{
|
|
106
|
+
gl_FragColor = vColor;
|
|
107
|
+
}`;
|
|
108
|
+
function getShader(gl) {
|
|
109
|
+
if (shader)
|
|
110
|
+
return shader;
|
|
111
|
+
let prog = gl.createProgram();
|
|
112
|
+
if (!prog)
|
|
113
|
+
throw new Error("Unable to create program");
|
|
114
|
+
let vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSrc);
|
|
115
|
+
let fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSrc);
|
|
116
|
+
gl.attachShader(prog, vertexShader);
|
|
117
|
+
gl.attachShader(prog, fragmentShader);
|
|
118
|
+
linkProgram(gl, prog);
|
|
119
|
+
let unif_proj = gl.getUniformLocation(prog, "projMatrix");
|
|
120
|
+
if (!unif_proj)
|
|
121
|
+
throw new Error("Unable to get uniform location projMatrix");
|
|
122
|
+
let unif_matrix = gl.getUniformLocation(prog, "modelViewMatrix");
|
|
123
|
+
if (!unif_matrix)
|
|
124
|
+
throw new Error("Unable to get uniform location modelViewMatrix");
|
|
125
|
+
let unif_camera = gl.getUniformLocation(prog, "cameraMatrix");
|
|
126
|
+
if (!unif_camera)
|
|
127
|
+
throw new Error("Unable to get uniform location cameraMatrix");
|
|
128
|
+
shader = {
|
|
129
|
+
prog,
|
|
130
|
+
unif_matrix,
|
|
131
|
+
unif_proj,
|
|
132
|
+
unif_camera,
|
|
133
|
+
attr_position: gl.getAttribLocation(prog, "position"),
|
|
134
|
+
attr_color: gl.getAttribLocation(prog, "color")
|
|
135
|
+
};
|
|
136
|
+
return shader;
|
|
137
|
+
}
|
|
138
|
+
function loadTexture(gl, url) {
|
|
139
|
+
if (texturesByUrl[url])
|
|
140
|
+
return texturesByUrl[url];
|
|
141
|
+
let texture = gl.createTexture();
|
|
142
|
+
if (!texture)
|
|
143
|
+
throw new Error("Unable to create texture");
|
|
144
|
+
texturesByUrl[url] = texture;
|
|
145
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
146
|
+
// Because images have to be download over the internet
|
|
147
|
+
// they might take a moment until they are ready.
|
|
148
|
+
// Until then put a single pixel in the texture so we can
|
|
149
|
+
// use it immediately. When the image has finished downloading
|
|
150
|
+
// we'll update the texture with the contents of the image.
|
|
151
|
+
const level = 0;
|
|
152
|
+
const internalFormat = gl.RGBA;
|
|
153
|
+
const width = 1;
|
|
154
|
+
const height = 1;
|
|
155
|
+
const border = 0;
|
|
156
|
+
const srcFormat = gl.RGBA;
|
|
157
|
+
const srcType = gl.UNSIGNED_BYTE;
|
|
158
|
+
const pixel = new Uint8Array([0, 0, 255, 255]); // opaque blue
|
|
159
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
160
|
+
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, width, height, border, srcFormat, srcType, pixel);
|
|
161
|
+
const image = new Image();
|
|
162
|
+
image.onload = function () {
|
|
163
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
164
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
165
|
+
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, srcFormat, srcType, image);
|
|
166
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
167
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
168
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
169
|
+
};
|
|
170
|
+
image.src = url;
|
|
171
|
+
return texture;
|
|
172
|
+
}
|
package/lib/drawgrid.js
CHANGED
|
@@ -2,6 +2,7 @@ import { compileShader, linkProgram } from "./shader";
|
|
|
2
2
|
let shader;
|
|
3
3
|
let vbo;
|
|
4
4
|
let uvbo;
|
|
5
|
+
const gridSize = 10;
|
|
5
6
|
export function disposeDrawGrid() {
|
|
6
7
|
shader = undefined;
|
|
7
8
|
vbo = undefined;
|
|
@@ -19,6 +20,7 @@ function generate(gl) {
|
|
|
19
20
|
0.5, 0, 0.5,
|
|
20
21
|
0.5, 0, -0.5
|
|
21
22
|
];
|
|
23
|
+
coords = coords.map(entry => entry * gridSize);
|
|
22
24
|
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
23
25
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(coords), gl.STATIC_DRAW);
|
|
24
26
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
@@ -36,6 +38,7 @@ function generateUVBO(gl) {
|
|
|
36
38
|
1, 1,
|
|
37
39
|
1, 0
|
|
38
40
|
];
|
|
41
|
+
coords = coords.map(entry => entry * gridSize);
|
|
39
42
|
gl.bindBuffer(gl.ARRAY_BUFFER, uvbo);
|
|
40
43
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(coords), gl.STATIC_DRAW);
|
|
41
44
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class PointsWithTypeDraw {
|
|
2
|
+
private _gl;
|
|
3
|
+
private _vbo;
|
|
4
|
+
private _typebo;
|
|
5
|
+
private _shader;
|
|
6
|
+
constructor(_gl: WebGL2RenderingContext);
|
|
7
|
+
dispose(): void;
|
|
8
|
+
private _generate;
|
|
9
|
+
private _generateTypes;
|
|
10
|
+
drawPoints(screenWidth: number, screenHeight: number, dataWidth: number, dataHeight: number, points: Float32Array, mirror: boolean, type: Uint8Array, pointSize: number): void;
|
|
11
|
+
private _getCameraShader;
|
|
12
|
+
}
|
|
13
|
+
export declare function getPointsDataMatrix(frameWidth: number, frameHeight: number, screenWidth: number, screenHeight: number, mirror: boolean): Float32Array;
|
|
@@ -0,0 +1,190 @@
|
|
|
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 PointsWithTypeDraw {
|
|
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
|
+
_generateTypes(gl, points) {
|
|
28
|
+
if (!this._typebo)
|
|
29
|
+
this._typebo = gl.createBuffer();
|
|
30
|
+
if (!this._typebo)
|
|
31
|
+
throw new Error("Unable to create buffer object");
|
|
32
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._typebo);
|
|
33
|
+
gl.bufferData(gl.ARRAY_BUFFER, points, gl.DYNAMIC_DRAW);
|
|
34
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
35
|
+
return this._typebo;
|
|
36
|
+
}
|
|
37
|
+
drawPoints(screenWidth, screenHeight, dataWidth, dataHeight, points, mirror, type, pointSize) {
|
|
38
|
+
if (points.length === 0)
|
|
39
|
+
return; // points = new Float32Array([0, 1, 0, 1]);
|
|
40
|
+
let gl = this._gl;
|
|
41
|
+
const reenableDepthTest = gl.isEnabled(gl.DEPTH_TEST);
|
|
42
|
+
const reenableScissorTest = gl.isEnabled(gl.SCISSOR_TEST);
|
|
43
|
+
const reenableCullFace = gl.isEnabled(gl.CULL_FACE);
|
|
44
|
+
const reenableStencilTest = gl.isEnabled(gl.STENCIL_TEST);
|
|
45
|
+
const reenableBlend = gl.isEnabled(gl.BLEND);
|
|
46
|
+
const previousBoundTexture = gl.getParameter(gl.TEXTURE_BINDING_2D);
|
|
47
|
+
const previousBoundFramebuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
|
|
48
|
+
const previousProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
49
|
+
const previousActiveTexture = gl.getParameter(gl.ACTIVE_TEXTURE);
|
|
50
|
+
gl.disable(gl.DEPTH_TEST);
|
|
51
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
52
|
+
gl.disable(gl.CULL_FACE);
|
|
53
|
+
gl.disable(gl.STENCIL_TEST);
|
|
54
|
+
gl.disable(gl.BLEND);
|
|
55
|
+
let shader = this._getCameraShader(gl);
|
|
56
|
+
let vbo = this._generate(gl, points);
|
|
57
|
+
let typebo = this._generateTypes(gl, type);
|
|
58
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
59
|
+
gl.useProgram(shader.prog);
|
|
60
|
+
gl.uniform1f(shader.unif_pointSize, pointSize);
|
|
61
|
+
gl.uniformMatrix4fv(shader.unif_skinTexTransform, false, getPointsDataMatrix(dataWidth, dataHeight, screenWidth, screenHeight, mirror));
|
|
62
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
63
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
64
|
+
gl.vertexAttribPointer(shader.attr_position, 2, gl.FLOAT, false, 0, 0);
|
|
65
|
+
gl.enableVertexAttribArray(shader.attr_position);
|
|
66
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, typebo);
|
|
67
|
+
gl.vertexAttribIPointer(shader.attr_type, 1, gl.UNSIGNED_BYTE, 0, 0);
|
|
68
|
+
gl.enableVertexAttribArray(shader.attr_type);
|
|
69
|
+
gl.drawArrays(gl.POINTS, 0, points.length / 2);
|
|
70
|
+
gl.disableVertexAttribArray(shader.attr_type);
|
|
71
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
72
|
+
gl.disableVertexAttribArray(shader.attr_position);
|
|
73
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, previousBoundFramebuffer);
|
|
74
|
+
gl.useProgram(previousProgram);
|
|
75
|
+
gl.bindTexture(gl.TEXTURE_2D, previousBoundTexture);
|
|
76
|
+
gl.activeTexture(previousActiveTexture);
|
|
77
|
+
if (reenableBlend)
|
|
78
|
+
gl.enable(gl.BLEND);
|
|
79
|
+
if (reenableCullFace)
|
|
80
|
+
gl.enable(gl.CULL_FACE);
|
|
81
|
+
if (reenableDepthTest)
|
|
82
|
+
gl.enable(gl.DEPTH_TEST);
|
|
83
|
+
if (reenableScissorTest)
|
|
84
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
85
|
+
if (reenableStencilTest)
|
|
86
|
+
gl.enable(gl.STENCIL_TEST);
|
|
87
|
+
}
|
|
88
|
+
_getCameraShader(gl) {
|
|
89
|
+
if (this._shader)
|
|
90
|
+
return this._shader;
|
|
91
|
+
let prog = gl.createProgram();
|
|
92
|
+
if (!prog)
|
|
93
|
+
throw new Error("Unable to create program");
|
|
94
|
+
let vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSrc);
|
|
95
|
+
let fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSrc);
|
|
96
|
+
gl.attachShader(prog, vertexShader);
|
|
97
|
+
gl.attachShader(prog, fragmentShader);
|
|
98
|
+
linkProgram(gl, prog);
|
|
99
|
+
let unif_skinTexTransform = gl.getUniformLocation(prog, "skinTexTransform");
|
|
100
|
+
if (!unif_skinTexTransform)
|
|
101
|
+
throw new Error("Unable to get uniform location skinTexTransform");
|
|
102
|
+
let unif_pointSize = gl.getUniformLocation(prog, "pointSize");
|
|
103
|
+
if (!unif_pointSize)
|
|
104
|
+
throw new Error("Unable to get uniform location pointSize");
|
|
105
|
+
this._shader = {
|
|
106
|
+
prog,
|
|
107
|
+
unif_skinTexTransform,
|
|
108
|
+
unif_pointSize,
|
|
109
|
+
attr_position: gl.getAttribLocation(prog, "pos"),
|
|
110
|
+
attr_type: gl.getAttribLocation(prog, "aType"),
|
|
111
|
+
};
|
|
112
|
+
return this._shader;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
let vertexShaderSrc = `#version 300 es
|
|
116
|
+
|
|
117
|
+
in vec2 pos;
|
|
118
|
+
in uint aType;
|
|
119
|
+
uniform mat4 skinTexTransform;
|
|
120
|
+
uniform float pointSize;
|
|
121
|
+
|
|
122
|
+
out vec4 vColor;
|
|
123
|
+
|
|
124
|
+
void main()
|
|
125
|
+
{
|
|
126
|
+
gl_Position = skinTexTransform * vec4(pos, 0.0, 1.0);
|
|
127
|
+
vColor = vec4(1.0, 0.0, 0.0, 1.0);
|
|
128
|
+
if (aType == 1u) {
|
|
129
|
+
vColor = vec4(1.0, 0.7, 0.0, 1.0);
|
|
130
|
+
} else if (aType >= 4u) {
|
|
131
|
+
vColor = vec4(0.0, 0.0, 1.0, 1.0);
|
|
132
|
+
} else if (aType > 1u) {
|
|
133
|
+
vColor = vec4(0.0, 1.0, 0.0, 1.0);
|
|
134
|
+
}
|
|
135
|
+
gl_PointSize = pointSize;
|
|
136
|
+
}`;
|
|
137
|
+
let fragmentShaderSrc = `#version 300 es
|
|
138
|
+
precision highp float;
|
|
139
|
+
|
|
140
|
+
in vec4 vColor;
|
|
141
|
+
out vec4 outColor;
|
|
142
|
+
|
|
143
|
+
void main()
|
|
144
|
+
{
|
|
145
|
+
outColor = vColor;
|
|
146
|
+
}`;
|
|
147
|
+
function cameraRotationForScreenOrientation() {
|
|
148
|
+
if (window.screen.orientation && !profile.forceWindowOrientation) {
|
|
149
|
+
switch (window.screen.orientation.type) {
|
|
150
|
+
case "portrait-primary":
|
|
151
|
+
return 270;
|
|
152
|
+
case "landscape-secondary":
|
|
153
|
+
return 180;
|
|
154
|
+
case "portrait-secondary":
|
|
155
|
+
return 90;
|
|
156
|
+
default:
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else if (window.orientation !== undefined) {
|
|
161
|
+
switch (window.orientation) {
|
|
162
|
+
case 0: return 270;
|
|
163
|
+
case 90: return 0;
|
|
164
|
+
case 180: return 90;
|
|
165
|
+
case -90: return 180;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
170
|
+
export function getPointsDataMatrix(frameWidth, frameHeight, screenWidth, screenHeight, mirror) {
|
|
171
|
+
let ret = mat4.create();
|
|
172
|
+
let trans = mat4.create();
|
|
173
|
+
// Translate to centre UV coords
|
|
174
|
+
mat4.fromTranslation(trans, [-0.5 * frameWidth, -0.5 * frameHeight, 0]);
|
|
175
|
+
mat4.multiply(ret, trans, ret);
|
|
176
|
+
mat4.fromScaling(trans, [2 / frameWidth, 2 / -frameHeight, 1]);
|
|
177
|
+
mat4.multiply(ret, trans, ret);
|
|
178
|
+
if (mirror) {
|
|
179
|
+
mat4.fromScaling(trans, [-1, 1, 1]);
|
|
180
|
+
mat4.multiply(ret, trans, ret);
|
|
181
|
+
}
|
|
182
|
+
let screenAspect = screenWidth > screenHeight ? (screenWidth / screenHeight) : (screenHeight / screenWidth);
|
|
183
|
+
let frameAspect = frameWidth / frameHeight;
|
|
184
|
+
mat4.fromScaling(trans, [1, screenAspect / frameAspect, 1]);
|
|
185
|
+
mat4.multiply(ret, trans, ret);
|
|
186
|
+
// Apply rotation back into ZCV's landscape space
|
|
187
|
+
mat4.fromRotation(trans, cameraRotationForScreenOrientation() * Math.PI / 180.0, [0, 0, 1]);
|
|
188
|
+
mat4.multiply(ret, trans, ret);
|
|
189
|
+
return ret;
|
|
190
|
+
}
|
|
@@ -123,6 +123,8 @@ export interface zappar {
|
|
|
123
123
|
world_tracker_enabled(o: zappar_world_tracker_t): boolean;
|
|
124
124
|
world_tracker_enabled_set(o: zappar_world_tracker_t, enabled: boolean): void;
|
|
125
125
|
world_tracker_quality(o: zappar_world_tracker_t): number;
|
|
126
|
+
world_tracker_plane_detection_enabled(o: zappar_world_tracker_t): boolean;
|
|
127
|
+
world_tracker_plane_detection_enabled_set(o: zappar_world_tracker_t, plane_detection_enabled: boolean): void;
|
|
126
128
|
world_tracker_plane_count(o: zappar_world_tracker_t): number;
|
|
127
129
|
world_tracker_plane_pose_raw(o: zappar_world_tracker_t, indx: number): Float32Array;
|
|
128
130
|
world_tracker_world_anchor_valid(o: zappar_world_tracker_t): boolean;
|
|
@@ -134,6 +136,8 @@ export interface zappar {
|
|
|
134
136
|
world_tracker_tracks_data_enabled_set(o: zappar_world_tracker_t, tracks_data_enabled: boolean): void;
|
|
135
137
|
world_tracker_tracks_data_size(o: zappar_world_tracker_t): number;
|
|
136
138
|
world_tracker_tracks_data(o: zappar_world_tracker_t): Float32Array;
|
|
139
|
+
world_tracker_tracks_type_data_size(o: zappar_world_tracker_t): number;
|
|
140
|
+
world_tracker_tracks_type_data(o: zappar_world_tracker_t): Uint8Array;
|
|
137
141
|
world_tracker_projections_data_enabled(o: zappar_world_tracker_t): boolean;
|
|
138
142
|
world_tracker_projections_data_enabled_set(o: zappar_world_tracker_t, projections_data_enabled: boolean): void;
|
|
139
143
|
world_tracker_projections_data_size(o: zappar_world_tracker_t): number;
|
package/lib/gen/zappar-client.js
CHANGED
|
@@ -680,6 +680,7 @@ export class zappar_client {
|
|
|
680
680
|
let newId = (this._latestId++);
|
|
681
681
|
let s = {
|
|
682
682
|
enabled: true,
|
|
683
|
+
plane_detection_enabled: true,
|
|
683
684
|
plane_count: 0,
|
|
684
685
|
plane_pose: [],
|
|
685
686
|
world_anchor_valid: false,
|
|
@@ -689,6 +690,8 @@ export class zappar_client {
|
|
|
689
690
|
tracks_data_enabled: false,
|
|
690
691
|
tracks_data: new Float32Array([]),
|
|
691
692
|
tracks_data_size: 0,
|
|
693
|
+
tracks_type_data: new Uint8Array([]),
|
|
694
|
+
tracks_type_data_size: 0,
|
|
692
695
|
projections_data_enabled: false,
|
|
693
696
|
projections_data: new Float32Array([]),
|
|
694
697
|
projections_data_size: 0,
|
|
@@ -731,6 +734,21 @@ export class zappar_client {
|
|
|
731
734
|
throw new Error("This object has been destroyed");
|
|
732
735
|
return s.quality;
|
|
733
736
|
},
|
|
737
|
+
world_tracker_plane_detection_enabled: (o) => {
|
|
738
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
739
|
+
if (!s)
|
|
740
|
+
throw new Error("This object has been destroyed");
|
|
741
|
+
return s.plane_detection_enabled;
|
|
742
|
+
},
|
|
743
|
+
world_tracker_plane_detection_enabled_set: (o, plane_detection_enabled) => {
|
|
744
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
745
|
+
if (!s)
|
|
746
|
+
throw new Error("This object has been destroyed");
|
|
747
|
+
this.serializer.sendMessage(48, m => {
|
|
748
|
+
m.type(o);
|
|
749
|
+
m.bool(plane_detection_enabled);
|
|
750
|
+
});
|
|
751
|
+
},
|
|
734
752
|
world_tracker_plane_count: (o) => {
|
|
735
753
|
let s = this._world_tracker_state_by_instance.get(o);
|
|
736
754
|
if (!s)
|
|
@@ -771,7 +789,7 @@ export class zappar_client {
|
|
|
771
789
|
let s = this._world_tracker_state_by_instance.get(o);
|
|
772
790
|
if (!s)
|
|
773
791
|
throw new Error("This object has been destroyed");
|
|
774
|
-
this.serializer.sendMessage(
|
|
792
|
+
this.serializer.sendMessage(49, m => {
|
|
775
793
|
m.type(o);
|
|
776
794
|
});
|
|
777
795
|
},
|
|
@@ -785,7 +803,7 @@ export class zappar_client {
|
|
|
785
803
|
let s = this._world_tracker_state_by_instance.get(o);
|
|
786
804
|
if (!s)
|
|
787
805
|
throw new Error("This object has been destroyed");
|
|
788
|
-
this.serializer.sendMessage(
|
|
806
|
+
this.serializer.sendMessage(50, m => {
|
|
789
807
|
m.type(o);
|
|
790
808
|
m.bool(tracks_data_enabled);
|
|
791
809
|
});
|
|
@@ -802,6 +820,18 @@ export class zappar_client {
|
|
|
802
820
|
throw new Error("This object has been destroyed");
|
|
803
821
|
return s.tracks_data;
|
|
804
822
|
},
|
|
823
|
+
world_tracker_tracks_type_data_size: (o) => {
|
|
824
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
825
|
+
if (!s)
|
|
826
|
+
throw new Error("This object has been destroyed");
|
|
827
|
+
return s.tracks_type_data_size;
|
|
828
|
+
},
|
|
829
|
+
world_tracker_tracks_type_data: (o) => {
|
|
830
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
831
|
+
if (!s)
|
|
832
|
+
throw new Error("This object has been destroyed");
|
|
833
|
+
return s.tracks_type_data;
|
|
834
|
+
},
|
|
805
835
|
world_tracker_projections_data_enabled: (o) => {
|
|
806
836
|
let s = this._world_tracker_state_by_instance.get(o);
|
|
807
837
|
if (!s)
|
|
@@ -812,7 +842,7 @@ export class zappar_client {
|
|
|
812
842
|
let s = this._world_tracker_state_by_instance.get(o);
|
|
813
843
|
if (!s)
|
|
814
844
|
throw new Error("This object has been destroyed");
|
|
815
|
-
this.serializer.sendMessage(
|
|
845
|
+
this.serializer.sendMessage(51, m => {
|
|
816
846
|
m.type(o);
|
|
817
847
|
m.bool(projections_data_enabled);
|
|
818
848
|
});
|
|
@@ -1102,7 +1132,23 @@ export class zappar_client {
|
|
|
1102
1132
|
inst.tracks_data = msg.floatArray();
|
|
1103
1133
|
break;
|
|
1104
1134
|
}
|
|
1105
|
-
case
|
|
1135
|
+
case 36: {
|
|
1136
|
+
let handle = msg.type();
|
|
1137
|
+
let inst = this._world_tracker_state_by_instance.get(handle);
|
|
1138
|
+
if (!inst)
|
|
1139
|
+
return;
|
|
1140
|
+
inst.tracks_type_data_size = msg.int();
|
|
1141
|
+
break;
|
|
1142
|
+
}
|
|
1143
|
+
case 35: {
|
|
1144
|
+
let handle = msg.type();
|
|
1145
|
+
let inst = this._world_tracker_state_by_instance.get(handle);
|
|
1146
|
+
if (!inst)
|
|
1147
|
+
return;
|
|
1148
|
+
inst.tracks_type_data = msg.ucharArray();
|
|
1149
|
+
break;
|
|
1150
|
+
}
|
|
1151
|
+
case 39: {
|
|
1106
1152
|
let handle = msg.type();
|
|
1107
1153
|
let inst = this._world_tracker_state_by_instance.get(handle);
|
|
1108
1154
|
if (!inst)
|
|
@@ -1110,7 +1156,7 @@ export class zappar_client {
|
|
|
1110
1156
|
inst.projections_data_size = msg.int();
|
|
1111
1157
|
break;
|
|
1112
1158
|
}
|
|
1113
|
-
case
|
|
1159
|
+
case 38: {
|
|
1114
1160
|
let handle = msg.type();
|
|
1115
1161
|
let inst = this._world_tracker_state_by_instance.get(handle);
|
|
1116
1162
|
if (!inst)
|
package/lib/gen/zappar-cwrap.js
CHANGED
|
@@ -237,6 +237,13 @@ export function getRuntimeObject(mod) {
|
|
|
237
237
|
let world_tracker_quality_wrapped = mod.cwrap("zappar_world_tracker_quality", "number", [
|
|
238
238
|
"number"
|
|
239
239
|
]);
|
|
240
|
+
let world_tracker_plane_detection_enabled_wrapped = mod.cwrap("zappar_world_tracker_plane_detection_enabled", "number", [
|
|
241
|
+
"number"
|
|
242
|
+
]);
|
|
243
|
+
let world_tracker_plane_detection_enabled_set_wrapped = mod.cwrap("zappar_world_tracker_plane_detection_enabled_set", null, [
|
|
244
|
+
"number",
|
|
245
|
+
"number"
|
|
246
|
+
]);
|
|
240
247
|
let world_tracker_plane_count_wrapped = mod.cwrap("zappar_world_tracker_plane_count", "number", [
|
|
241
248
|
"number"
|
|
242
249
|
]);
|
|
@@ -272,6 +279,12 @@ export function getRuntimeObject(mod) {
|
|
|
272
279
|
let world_tracker_tracks_data_wrapped = mod.cwrap("zappar_world_tracker_tracks_data", "number", [
|
|
273
280
|
"number"
|
|
274
281
|
]);
|
|
282
|
+
let world_tracker_tracks_type_data_size_wrapped = mod.cwrap("zappar_world_tracker_tracks_type_data_size", "number", [
|
|
283
|
+
"number"
|
|
284
|
+
]);
|
|
285
|
+
let world_tracker_tracks_type_data_wrapped = mod.cwrap("zappar_world_tracker_tracks_type_data", "number", [
|
|
286
|
+
"number"
|
|
287
|
+
]);
|
|
275
288
|
let world_tracker_projections_data_enabled_wrapped = mod.cwrap("zappar_world_tracker_projections_data_enabled", "number", [
|
|
276
289
|
"number"
|
|
277
290
|
]);
|
|
@@ -771,6 +784,16 @@ export function getRuntimeObject(mod) {
|
|
|
771
784
|
let ret = world_tracker_quality_wrapped(o);
|
|
772
785
|
return ret;
|
|
773
786
|
},
|
|
787
|
+
world_tracker_plane_detection_enabled: (o) => {
|
|
788
|
+
let ret = world_tracker_plane_detection_enabled_wrapped(o);
|
|
789
|
+
ret = ret === 1;
|
|
790
|
+
return ret;
|
|
791
|
+
},
|
|
792
|
+
world_tracker_plane_detection_enabled_set: (o, plane_detection_enabled) => {
|
|
793
|
+
let arg_plane_detection_enabled = plane_detection_enabled ? 1 : 0;
|
|
794
|
+
let ret = world_tracker_plane_detection_enabled_set_wrapped(o, arg_plane_detection_enabled);
|
|
795
|
+
return ret;
|
|
796
|
+
},
|
|
774
797
|
world_tracker_plane_count: (o) => {
|
|
775
798
|
let ret = world_tracker_plane_count_wrapped(o);
|
|
776
799
|
return ret;
|
|
@@ -833,6 +856,18 @@ export function getRuntimeObject(mod) {
|
|
|
833
856
|
ret = ab;
|
|
834
857
|
return ret;
|
|
835
858
|
},
|
|
859
|
+
world_tracker_tracks_type_data_size: (o) => {
|
|
860
|
+
let ret = world_tracker_tracks_type_data_size_wrapped(o);
|
|
861
|
+
return ret;
|
|
862
|
+
},
|
|
863
|
+
world_tracker_tracks_type_data: (o) => {
|
|
864
|
+
let ret = world_tracker_tracks_type_data_wrapped(o);
|
|
865
|
+
let retsize = world_tracker_tracks_type_data_size_wrapped(o);
|
|
866
|
+
let ab = new Uint8Array(retsize);
|
|
867
|
+
ab.set(mod.HEAPU8.subarray(ret, retsize + ret));
|
|
868
|
+
ret = ab;
|
|
869
|
+
return ret;
|
|
870
|
+
},
|
|
836
871
|
world_tracker_projections_data_enabled: (o) => {
|
|
837
872
|
let ret = world_tracker_projections_data_enabled_wrapped(o);
|
|
838
873
|
ret = ret === 1;
|
|
@@ -188,6 +188,8 @@ export interface zappar_cwrap {
|
|
|
188
188
|
world_tracker_enabled(o: zappar_world_tracker_t): boolean;
|
|
189
189
|
world_tracker_enabled_set(o: zappar_world_tracker_t, enabled: boolean): void;
|
|
190
190
|
world_tracker_quality(o: zappar_world_tracker_t): number;
|
|
191
|
+
world_tracker_plane_detection_enabled(o: zappar_world_tracker_t): boolean;
|
|
192
|
+
world_tracker_plane_detection_enabled_set(o: zappar_world_tracker_t, plane_detection_enabled: boolean): void;
|
|
191
193
|
world_tracker_plane_count(o: zappar_world_tracker_t): number;
|
|
192
194
|
world_tracker_plane_pose_raw(o: zappar_world_tracker_t, indx: number): Float32Array;
|
|
193
195
|
world_tracker_world_anchor_valid(o: zappar_world_tracker_t): boolean;
|
|
@@ -199,6 +201,8 @@ export interface zappar_cwrap {
|
|
|
199
201
|
world_tracker_tracks_data_enabled_set(o: zappar_world_tracker_t, tracks_data_enabled: boolean): void;
|
|
200
202
|
world_tracker_tracks_data_size(o: zappar_world_tracker_t): number;
|
|
201
203
|
world_tracker_tracks_data(o: zappar_world_tracker_t): Float32Array;
|
|
204
|
+
world_tracker_tracks_type_data_size(o: zappar_world_tracker_t): number;
|
|
205
|
+
world_tracker_tracks_type_data(o: zappar_world_tracker_t): Uint8Array;
|
|
202
206
|
world_tracker_projections_data_enabled(o: zappar_world_tracker_t): boolean;
|
|
203
207
|
world_tracker_projections_data_enabled_set(o: zappar_world_tracker_t, projections_data_enabled: boolean): void;
|
|
204
208
|
world_tracker_projections_data_size(o: zappar_world_tracker_t): number;
|