@zappar/zappar-cv 3.0.1-beta.5 → 3.0.1-beta.8
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/drawquad.d.ts +2 -0
- package/lib/drawquad.js +99 -0
- package/lib/html-element-source.js +1 -1
- package/lib/native.js +1 -1
- 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/{5780e3e18c5b55f66214.wasm → 7fd693559466ec5f412e.wasm} +0 -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/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-beta.
|
|
21
|
+
<script src="https://libs.zappar.com/zappar-cv/3.0.1-beta.8/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-beta.
|
|
25
|
+
[https://libs.zappar.com/zappar-cv/3.0.1-beta.8/zappar-cv.zip](https://libs.zappar.com/zappar-cv/3.0.1-beta.8/zappar-cv.zip)
|
package/lib/drawquad.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { compileShader, linkProgram } from "./shader";
|
|
2
|
+
let shader;
|
|
3
|
+
let vbo;
|
|
4
|
+
export function disposeDrawQuad() {
|
|
5
|
+
shader = undefined;
|
|
6
|
+
vbo = undefined;
|
|
7
|
+
}
|
|
8
|
+
function generate(gl) {
|
|
9
|
+
if (vbo)
|
|
10
|
+
return vbo;
|
|
11
|
+
vbo = gl.createBuffer();
|
|
12
|
+
if (!vbo)
|
|
13
|
+
throw new Error("Unable to create buffer object");
|
|
14
|
+
let coords = [
|
|
15
|
+
-0.5, 0.5, 0,
|
|
16
|
+
-0.5, -0.5, 0,
|
|
17
|
+
0.5, 0.5, 0,
|
|
18
|
+
0.5, -0.5, 0
|
|
19
|
+
];
|
|
20
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
|
21
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(coords), gl.STATIC_DRAW);
|
|
22
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
23
|
+
return vbo;
|
|
24
|
+
}
|
|
25
|
+
export function drawQuad(gl, projectionMatrix, modelviewMatrix, color) {
|
|
26
|
+
let shader = getShader(gl);
|
|
27
|
+
let v = generate(gl);
|
|
28
|
+
gl.useProgram(shader.prog);
|
|
29
|
+
gl.uniformMatrix4fv(shader.unif_projection, false, projectionMatrix);
|
|
30
|
+
gl.uniformMatrix4fv(shader.unif_modelView, false, modelviewMatrix);
|
|
31
|
+
gl.uniform4fv(shader.unif_color, color);
|
|
32
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, v);
|
|
33
|
+
gl.vertexAttribPointer(shader.attr_position, 3, gl.FLOAT, false, 3 * 4, 0);
|
|
34
|
+
gl.enableVertexAttribArray(shader.attr_position);
|
|
35
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
36
|
+
gl.disableVertexAttribArray(shader.attr_position);
|
|
37
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
38
|
+
}
|
|
39
|
+
let vertexShaderSrc = `
|
|
40
|
+
#ifndef GL_ES
|
|
41
|
+
#define highp
|
|
42
|
+
#define mediump
|
|
43
|
+
#define lowp
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
uniform mat4 projMatrix;
|
|
47
|
+
uniform mat4 modelViewMatrix;
|
|
48
|
+
attribute vec4 position;
|
|
49
|
+
|
|
50
|
+
void main()
|
|
51
|
+
{
|
|
52
|
+
gl_Position = projMatrix * modelViewMatrix * position;
|
|
53
|
+
}`;
|
|
54
|
+
let fragmentShaderSrc = `
|
|
55
|
+
#define highp mediump
|
|
56
|
+
#ifdef GL_ES
|
|
57
|
+
// define default precision for float, vec, mat.
|
|
58
|
+
precision highp float;
|
|
59
|
+
#else
|
|
60
|
+
#define highp
|
|
61
|
+
#define mediump
|
|
62
|
+
#define lowp
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
uniform vec4 color;
|
|
66
|
+
|
|
67
|
+
void main()
|
|
68
|
+
{
|
|
69
|
+
gl_FragColor = color;
|
|
70
|
+
}`;
|
|
71
|
+
function getShader(gl) {
|
|
72
|
+
if (shader)
|
|
73
|
+
return shader;
|
|
74
|
+
let prog = gl.createProgram();
|
|
75
|
+
if (!prog)
|
|
76
|
+
throw new Error("Unable to create program");
|
|
77
|
+
let vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSrc);
|
|
78
|
+
let fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSrc);
|
|
79
|
+
gl.attachShader(prog, vertexShader);
|
|
80
|
+
gl.attachShader(prog, fragmentShader);
|
|
81
|
+
linkProgram(gl, prog);
|
|
82
|
+
let unif_projection = gl.getUniformLocation(prog, "projMatrix");
|
|
83
|
+
if (!unif_projection)
|
|
84
|
+
throw new Error("Unable to get uniform location projMatrix");
|
|
85
|
+
let unif_modelView = gl.getUniformLocation(prog, "modelViewMatrix");
|
|
86
|
+
if (!unif_modelView)
|
|
87
|
+
throw new Error("Unable to get uniform location modelViewMatrix");
|
|
88
|
+
let unif_color = gl.getUniformLocation(prog, "color");
|
|
89
|
+
if (!unif_color)
|
|
90
|
+
throw new Error("Unable to get uniform location color");
|
|
91
|
+
shader = {
|
|
92
|
+
prog,
|
|
93
|
+
unif_modelView,
|
|
94
|
+
unif_projection,
|
|
95
|
+
unif_color,
|
|
96
|
+
attr_position: gl.getAttribLocation(prog, "position"),
|
|
97
|
+
};
|
|
98
|
+
return shader;
|
|
99
|
+
}
|
|
@@ -159,7 +159,7 @@ export class HTMLElementSource extends Source {
|
|
|
159
159
|
}
|
|
160
160
|
let tex = this._currentVideoTexture;
|
|
161
161
|
this._currentVideoTexture = undefined;
|
|
162
|
-
let focalLength = 240.0 * dataWidth / 320.0;
|
|
162
|
+
let focalLength = (this._isUserFacing ? 300.0 : 240.0) * dataWidth / 320.0;
|
|
163
163
|
this._cameraModel[0] = focalLength;
|
|
164
164
|
this._cameraModel[1] = focalLength;
|
|
165
165
|
this._cameraModel[2] = dataWidth * 0.5;
|
package/lib/native.js
CHANGED
|
@@ -49,7 +49,7 @@ export function initialize(opts) {
|
|
|
49
49
|
});
|
|
50
50
|
const uid = getUID();
|
|
51
51
|
let hasPersistedUID = false;
|
|
52
|
-
if (window.location.hostname.toLowerCase().indexOf(".zappar.io") > 0 || window.location.hostname.toLowerCase().indexOf(".webar.run") > 0 || window.location.hostname.toLowerCase().indexOf(".arweb.app") > 0) {
|
|
52
|
+
if (window.location.hostname.toLowerCase().indexOf(".zappar.io") > 0 || window.location.hostname.toLowerCase().indexOf(".webar.run") > 0 || window.location.hostname.toLowerCase().indexOf(".arweb.app") > 0 || window.location.hostname.toLowerCase().indexOf(".zappar-us.io") > 0 || window.location.hostname.toLowerCase().indexOf(".zappar-eu.io") > 0) {
|
|
53
53
|
let pathParts = window.location.pathname.split("/");
|
|
54
54
|
if (pathParts.length > 1 && pathParts[1].length > 0)
|
|
55
55
|
c.impl.analytics_project_id_set(".wiz" + pathParts[1], uid);
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "3.0.1-beta.
|
|
1
|
+
export declare const VERSION = "3.0.1-beta.8";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0.1-beta.
|
|
1
|
+
export const VERSION = "3.0.1-beta.8";
|
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 = 240.0 * dataWidth / 320.0;
|
|
269
|
+
let focalLength = (userFacing ? 300.0 : 240.0) * dataWidth / 320.0;
|
|
270
270
|
cameraModel[0] = focalLength;
|
|
271
271
|
cameraModel[1] = focalLength;
|
|
272
272
|
cameraModel[2] = dataWidth * 0.5;
|