@zappar/zappar-cv 3.0.1-alpha.14 → 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/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/{f3b68cdcdf971ab7e1b7.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/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;
|
package/lib/gen/zappar-server.js
CHANGED
|
@@ -417,7 +417,7 @@ export class zappar_server {
|
|
|
417
417
|
let obj = this._world_tracker_by_instance.get(clientId);
|
|
418
418
|
if (obj === undefined)
|
|
419
419
|
return;
|
|
420
|
-
this._impl.
|
|
420
|
+
this._impl.world_tracker_plane_detection_enabled_set(obj, msg.bool());
|
|
421
421
|
break;
|
|
422
422
|
}
|
|
423
423
|
case 49: {
|
|
@@ -425,10 +425,18 @@ export class zappar_server {
|
|
|
425
425
|
let obj = this._world_tracker_by_instance.get(clientId);
|
|
426
426
|
if (obj === undefined)
|
|
427
427
|
return;
|
|
428
|
-
this._impl.
|
|
428
|
+
this._impl.world_tracker_reset(obj);
|
|
429
429
|
break;
|
|
430
430
|
}
|
|
431
431
|
case 50: {
|
|
432
|
+
let clientId = msg.type();
|
|
433
|
+
let obj = this._world_tracker_by_instance.get(clientId);
|
|
434
|
+
if (obj === undefined)
|
|
435
|
+
return;
|
|
436
|
+
this._impl.world_tracker_tracks_data_enabled_set(obj, msg.bool());
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
case 51: {
|
|
432
440
|
let clientId = msg.type();
|
|
433
441
|
let obj = this._world_tracker_by_instance.get(clientId);
|
|
434
442
|
if (obj === undefined)
|
|
@@ -688,11 +696,19 @@ export class zappar_server {
|
|
|
688
696
|
msg.type(k);
|
|
689
697
|
msg.floatArray(this._impl.world_tracker_tracks_data(v));
|
|
690
698
|
});
|
|
691
|
-
serializer.sendMessage(
|
|
699
|
+
serializer.sendMessage(36, msg => {
|
|
700
|
+
msg.type(k);
|
|
701
|
+
msg.int(this._impl.world_tracker_tracks_type_data_size(v));
|
|
702
|
+
});
|
|
703
|
+
serializer.sendMessage(35, msg => {
|
|
704
|
+
msg.type(k);
|
|
705
|
+
msg.ucharArray(this._impl.world_tracker_tracks_type_data(v));
|
|
706
|
+
});
|
|
707
|
+
serializer.sendMessage(39, msg => {
|
|
692
708
|
msg.type(k);
|
|
693
709
|
msg.int(this._impl.world_tracker_projections_data_size(v));
|
|
694
710
|
});
|
|
695
|
-
serializer.sendMessage(
|
|
711
|
+
serializer.sendMessage(38, msg => {
|
|
696
712
|
msg.type(k);
|
|
697
713
|
msg.floatArray(this._impl.world_tracker_projections_data(v));
|
|
698
714
|
});
|
package/lib/gen/zappar.d.ts
CHANGED
|
@@ -205,6 +205,8 @@ export interface zappar {
|
|
|
205
205
|
world_tracker_enabled(o: zappar_world_tracker_t): boolean;
|
|
206
206
|
world_tracker_enabled_set(o: zappar_world_tracker_t, enabled: boolean): void;
|
|
207
207
|
world_tracker_quality(o: zappar_world_tracker_t): number;
|
|
208
|
+
world_tracker_plane_detection_enabled(o: zappar_world_tracker_t): boolean;
|
|
209
|
+
world_tracker_plane_detection_enabled_set(o: zappar_world_tracker_t, plane_detection_enabled: boolean): void;
|
|
208
210
|
world_tracker_plane_count(o: zappar_world_tracker_t): number;
|
|
209
211
|
world_tracker_plane_pose_raw(o: zappar_world_tracker_t, indx: number): Float32Array;
|
|
210
212
|
world_tracker_plane_pose_camera_relative(o: zappar_world_tracker_t, indx: number, mirror: boolean): Float32Array;
|
|
@@ -222,6 +224,8 @@ export interface zappar {
|
|
|
222
224
|
world_tracker_tracks_data_enabled_set(o: zappar_world_tracker_t, tracks_data_enabled: boolean): void;
|
|
223
225
|
world_tracker_tracks_data_size(o: zappar_world_tracker_t): number;
|
|
224
226
|
world_tracker_tracks_data(o: zappar_world_tracker_t): Float32Array;
|
|
227
|
+
world_tracker_tracks_type_data_size(o: zappar_world_tracker_t): number;
|
|
228
|
+
world_tracker_tracks_type_data(o: zappar_world_tracker_t): Uint8Array;
|
|
225
229
|
world_tracker_projections_data_enabled(o: zappar_world_tracker_t): boolean;
|
|
226
230
|
world_tracker_projections_data_enabled_set(o: zappar_world_tracker_t, projections_data_enabled: boolean): void;
|
|
227
231
|
world_tracker_projections_data_size(o: zappar_world_tracker_t): number;
|
|
@@ -15,6 +15,7 @@ export declare class HTMLElementSource extends Source {
|
|
|
15
15
|
private _cameraToDeviceTransformUserFacing;
|
|
16
16
|
private _cameraModel;
|
|
17
17
|
private _profile;
|
|
18
|
+
private _waitingForFrame;
|
|
18
19
|
static createVideoElementSource(p: zappar_pipeline_t, element: HTMLVideoElement | HTMLImageElement): zappar_html_element_source_t;
|
|
19
20
|
static getVideoElementSource(m: zappar_html_element_source_t): HTMLElementSource | undefined;
|
|
20
21
|
constructor(_video: HTMLVideoElement | HTMLImageElement, _pipeline: zappar_pipeline_t);
|
|
@@ -23,6 +24,8 @@ export declare class HTMLElementSource extends Source {
|
|
|
23
24
|
pause(): void;
|
|
24
25
|
start(): void;
|
|
25
26
|
getFrame(currentlyProcessing: boolean): void;
|
|
27
|
+
private _lastPresentedFrames;
|
|
28
|
+
private _requestVideoFrameCallback;
|
|
26
29
|
private _processFrame;
|
|
27
30
|
uploadGL(): void;
|
|
28
31
|
setProfile(p: camera_profile_t): void;
|
|
@@ -21,6 +21,8 @@ export class HTMLElementSource extends Source {
|
|
|
21
21
|
this._cameraToDeviceTransformUserFacing = mat4.create();
|
|
22
22
|
this._cameraModel = new Float32Array([300, 300, 160, 120, 0, 0]);
|
|
23
23
|
this._profile = camera_profile_t.DEFAULT;
|
|
24
|
+
this._waitingForFrame = false;
|
|
25
|
+
this._lastPresentedFrames = -1;
|
|
24
26
|
mat4.fromScaling(this._cameraToDeviceTransformUserFacing, [-1, 1, -1]);
|
|
25
27
|
let video = this._video;
|
|
26
28
|
if (this._video instanceof HTMLVideoElement) {
|
|
@@ -99,6 +101,25 @@ export class HTMLElementSource extends Source {
|
|
|
99
101
|
}
|
|
100
102
|
return;
|
|
101
103
|
}
|
|
104
|
+
_requestVideoFrameCallback() {
|
|
105
|
+
const video = this._video;
|
|
106
|
+
if (!(video === null || video === void 0 ? void 0 : video.requestVideoFrameCallback))
|
|
107
|
+
return;
|
|
108
|
+
video.requestVideoFrameCallback((time, metadata) => {
|
|
109
|
+
if (typeof metadata === 'object' && typeof metadata.presentedFrames === 'number') {
|
|
110
|
+
if (this._lastPresentedFrames === metadata.presentedFrames) {
|
|
111
|
+
console.log('Avoided identical frame');
|
|
112
|
+
this._requestVideoFrameCallback();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this._lastPresentedFrames = metadata.presentedFrames;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
this._waitingForFrame = false;
|
|
120
|
+
});
|
|
121
|
+
this._waitingForFrame = true;
|
|
122
|
+
}
|
|
102
123
|
_processFrame(gl, rotation, currentlyProcessing) {
|
|
103
124
|
let pipeline = Pipeline.get(this._pipeline);
|
|
104
125
|
if (!pipeline)
|
|
@@ -106,12 +127,15 @@ export class HTMLElementSource extends Source {
|
|
|
106
127
|
if (!this._imageProcessor)
|
|
107
128
|
this._imageProcessor = new ImageProcessGL(gl);
|
|
108
129
|
if (this._isUploadFrame) {
|
|
130
|
+
if (this._waitingForFrame)
|
|
131
|
+
return;
|
|
109
132
|
if (!this._currentVideoTexture) {
|
|
110
133
|
this._currentVideoTexture = pipeline.getVideoTexture();
|
|
111
134
|
}
|
|
112
135
|
if (!this._currentVideoTexture)
|
|
113
136
|
return undefined;
|
|
114
137
|
this._imageProcessor.uploadFrame(this._currentVideoTexture, this._video, rotation, this._isUserFacing, this._profile);
|
|
138
|
+
this._requestVideoFrameCallback();
|
|
115
139
|
this._isUploadFrame = !this._isUploadFrame;
|
|
116
140
|
return undefined;
|
|
117
141
|
}
|
|
@@ -131,7 +155,7 @@ export class HTMLElementSource extends Source {
|
|
|
131
155
|
}
|
|
132
156
|
let tex = this._currentVideoTexture;
|
|
133
157
|
this._currentVideoTexture = undefined;
|
|
134
|
-
let focalLength =
|
|
158
|
+
let focalLength = 240.0 * dataWidth / 320.0;
|
|
135
159
|
this._cameraModel[0] = focalLength;
|
|
136
160
|
this._cameraModel[1] = focalLength;
|
|
137
161
|
this._cameraModel[2] = dataWidth * 0.5;
|
package/lib/serializer.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface MessageAppender {
|
|
|
8
8
|
type: (t: number) => void;
|
|
9
9
|
matrix4x4: (a: Float32Array) => void;
|
|
10
10
|
matrix3x3: (a: Float32Array) => void;
|
|
11
|
+
ucharArray: (a: Uint8Array) => void;
|
|
11
12
|
floatArray: (a: Float32Array) => void;
|
|
12
13
|
cameraModel: (a: Float32Array) => void;
|
|
13
14
|
identityCoefficients: (a: Float32Array) => void;
|
package/lib/serializer.js
CHANGED
|
@@ -23,6 +23,7 @@ export class MessageSerializer {
|
|
|
23
23
|
matrix4x4: i => this.float32ArrayBuffer(i),
|
|
24
24
|
matrix3x3: i => this.float32ArrayBuffer(i),
|
|
25
25
|
floatArray: i => this.float32ArrayBuffer(i),
|
|
26
|
+
ucharArray: i => this.uint8ArrayBuffer(i),
|
|
26
27
|
identityCoefficients: i => this.float32ArrayBuffer(i),
|
|
27
28
|
expressionCoefficients: i => this.float32ArrayBuffer(i),
|
|
28
29
|
cameraModel: i => this.float32ArrayBuffer(i),
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "3.0.1-alpha.
|
|
1
|
+
export declare const VERSION = "3.0.1-alpha.15";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0.1-alpha.
|
|
1
|
+
export const VERSION = "3.0.1-alpha.15";
|
package/lib/worker-server.js
CHANGED
|
@@ -266,7 +266,7 @@ function consumeReader(mod, r, reader, p, userFacing, server, source, workerMess
|
|
|
266
266
|
mat4.fromScaling(cameraToDeviceTransform, [-1, 1, -1]);
|
|
267
267
|
else
|
|
268
268
|
mat4.identity(cameraToDeviceTransform);
|
|
269
|
-
let focalLength =
|
|
269
|
+
let focalLength = 240.0 * dataWidth / 320.0;
|
|
270
270
|
cameraModel[0] = focalLength;
|
|
271
271
|
cameraModel[1] = focalLength;
|
|
272
272
|
cameraModel[2] = dataWidth * 0.5;
|