@zappar/zappar-cv 3.0.1-alpha.10 → 3.0.1-alpha.14
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/drawaxis.d.ts +2 -0
- package/lib/drawaxis.js +172 -0
- package/lib/gen/zappar-bridge.d.ts +2 -1
- package/lib/gen/zappar-client.js +8 -2
- package/lib/gen/zappar-cwrap.js +11 -3
- package/lib/gen/zappar-native.d.ts +2 -1
- package/lib/gen/zappar.d.ts +2 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/zappar-cv.js +1 -212
- 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/{ca409d4e8cebe454b816.wasm → f3b68cdcdf971ab7e1b7.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.14/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.14/zappar-cv.zip](https://libs.zappar.com/zappar-cv/3.0.1-alpha.14/zappar-cv.zip)
|
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
|
+
}
|
|
@@ -134,7 +134,8 @@ export interface zappar {
|
|
|
134
134
|
world_tracker_tracks_data_enabled_set(o: zappar_world_tracker_t, tracks_data_enabled: boolean): void;
|
|
135
135
|
world_tracker_tracks_data_size(o: zappar_world_tracker_t): number;
|
|
136
136
|
world_tracker_tracks_data(o: zappar_world_tracker_t): Float32Array;
|
|
137
|
-
|
|
137
|
+
world_tracker_projections_data_enabled(o: zappar_world_tracker_t): boolean;
|
|
138
|
+
world_tracker_projections_data_enabled_set(o: zappar_world_tracker_t, projections_data_enabled: boolean): void;
|
|
138
139
|
world_tracker_projections_data_size(o: zappar_world_tracker_t): number;
|
|
139
140
|
world_tracker_projections_data(o: zappar_world_tracker_t): Float32Array;
|
|
140
141
|
}
|
package/lib/gen/zappar-client.js
CHANGED
|
@@ -802,13 +802,19 @@ export class zappar_client {
|
|
|
802
802
|
throw new Error("This object has been destroyed");
|
|
803
803
|
return s.tracks_data;
|
|
804
804
|
},
|
|
805
|
-
|
|
805
|
+
world_tracker_projections_data_enabled: (o) => {
|
|
806
|
+
let s = this._world_tracker_state_by_instance.get(o);
|
|
807
|
+
if (!s)
|
|
808
|
+
throw new Error("This object has been destroyed");
|
|
809
|
+
return s.projections_data_enabled;
|
|
810
|
+
},
|
|
811
|
+
world_tracker_projections_data_enabled_set: (o, projections_data_enabled) => {
|
|
806
812
|
let s = this._world_tracker_state_by_instance.get(o);
|
|
807
813
|
if (!s)
|
|
808
814
|
throw new Error("This object has been destroyed");
|
|
809
815
|
this.serializer.sendMessage(50, m => {
|
|
810
816
|
m.type(o);
|
|
811
|
-
m.bool(
|
|
817
|
+
m.bool(projections_data_enabled);
|
|
812
818
|
});
|
|
813
819
|
},
|
|
814
820
|
world_tracker_projections_data_size: (o) => {
|
package/lib/gen/zappar-cwrap.js
CHANGED
|
@@ -272,6 +272,9 @@ export function getRuntimeObject(mod) {
|
|
|
272
272
|
let world_tracker_tracks_data_wrapped = mod.cwrap("zappar_world_tracker_tracks_data", "number", [
|
|
273
273
|
"number"
|
|
274
274
|
]);
|
|
275
|
+
let world_tracker_projections_data_enabled_wrapped = mod.cwrap("zappar_world_tracker_projections_data_enabled", "number", [
|
|
276
|
+
"number"
|
|
277
|
+
]);
|
|
275
278
|
let world_tracker_projections_data_enabled_set_wrapped = mod.cwrap("zappar_world_tracker_projections_data_enabled_set", null, [
|
|
276
279
|
"number",
|
|
277
280
|
"number"
|
|
@@ -830,9 +833,14 @@ export function getRuntimeObject(mod) {
|
|
|
830
833
|
ret = ab;
|
|
831
834
|
return ret;
|
|
832
835
|
},
|
|
833
|
-
|
|
834
|
-
let
|
|
835
|
-
|
|
836
|
+
world_tracker_projections_data_enabled: (o) => {
|
|
837
|
+
let ret = world_tracker_projections_data_enabled_wrapped(o);
|
|
838
|
+
ret = ret === 1;
|
|
839
|
+
return ret;
|
|
840
|
+
},
|
|
841
|
+
world_tracker_projections_data_enabled_set: (o, projections_data_enabled) => {
|
|
842
|
+
let arg_projections_data_enabled = projections_data_enabled ? 1 : 0;
|
|
843
|
+
let ret = world_tracker_projections_data_enabled_set_wrapped(o, arg_projections_data_enabled);
|
|
836
844
|
return ret;
|
|
837
845
|
},
|
|
838
846
|
world_tracker_projections_data_size: (o) => {
|
|
@@ -199,7 +199,8 @@ export interface zappar_cwrap {
|
|
|
199
199
|
world_tracker_tracks_data_enabled_set(o: zappar_world_tracker_t, tracks_data_enabled: boolean): void;
|
|
200
200
|
world_tracker_tracks_data_size(o: zappar_world_tracker_t): number;
|
|
201
201
|
world_tracker_tracks_data(o: zappar_world_tracker_t): Float32Array;
|
|
202
|
-
|
|
202
|
+
world_tracker_projections_data_enabled(o: zappar_world_tracker_t): boolean;
|
|
203
|
+
world_tracker_projections_data_enabled_set(o: zappar_world_tracker_t, projections_data_enabled: boolean): void;
|
|
203
204
|
world_tracker_projections_data_size(o: zappar_world_tracker_t): number;
|
|
204
205
|
world_tracker_projections_data(o: zappar_world_tracker_t): Float32Array;
|
|
205
206
|
}
|
package/lib/gen/zappar.d.ts
CHANGED
|
@@ -222,7 +222,8 @@ export interface zappar {
|
|
|
222
222
|
world_tracker_tracks_data_enabled_set(o: zappar_world_tracker_t, tracks_data_enabled: boolean): void;
|
|
223
223
|
world_tracker_tracks_data_size(o: zappar_world_tracker_t): number;
|
|
224
224
|
world_tracker_tracks_data(o: zappar_world_tracker_t): Float32Array;
|
|
225
|
-
|
|
225
|
+
world_tracker_projections_data_enabled(o: zappar_world_tracker_t): boolean;
|
|
226
|
+
world_tracker_projections_data_enabled_set(o: zappar_world_tracker_t, projections_data_enabled: boolean): void;
|
|
226
227
|
world_tracker_projections_data_size(o: zappar_world_tracker_t): number;
|
|
227
228
|
world_tracker_projections_data(o: zappar_world_tracker_t): Float32Array;
|
|
228
229
|
}
|
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.14";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0.1-alpha.
|
|
1
|
+
export const VERSION = "3.0.1-alpha.14";
|