@zappar/zappar-cv 2.0.0-beta.5 → 2.0.0-beta.9
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/CHANGELOG.md +6 -0
- package/README.md +2 -2
- package/lib/additional.d.ts +1 -0
- package/lib/drawplane.js +1 -0
- package/lib/drawpreviewmesh.d.ts +16 -0
- package/lib/drawpreviewmesh.js +186 -0
- package/lib/gen/zappar.d.ts +12 -0
- package/lib/image-process-gl.d.ts +3 -1
- package/lib/image-process-gl.js +32 -1
- package/lib/imagetracker-previewmesh.js +18 -11
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/native.js +65 -1
- package/lib/pipeline.d.ts +3 -0
- package/lib/pipeline.js +14 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/worker-client.js +1 -1
- package/lib/worker-server.js +2 -2
- package/lib/worker.js +1 -1
- package/lib/{zcv.js → zappar-cv.js} +63 -61
- package/lib/{zcv.wasm → zappar-cv.wasm} +0 -0
- package/package.json +2 -1
- package/umd/{d623b76c14719b88c180.wasm → 1bd0122688d1b0cb8762.wasm} +0 -0
- package/umd/56.zappar-cv.js +1 -0
- package/umd/zappar-cv.js +1 -1
- package/umd/zappar-cv.worker.js +1 -1
- package/umd/752.zappar-cv.js +0 -1
package/CHANGELOG.md
CHANGED
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/2.0.0-beta.
|
|
21
|
+
<script src="https://libs.zappar.com/zappar-cv/2.0.0-beta.9/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/2.0.0-beta.
|
|
25
|
+
[https://libs.zappar.com/zappar-cv/2.0.0-beta.9/zappar-cv.zip](https://libs.zappar.com/zappar-cv/2.0.0-beta.9/zappar-cv.zip)
|
package/lib/additional.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface Additional {
|
|
|
6
6
|
pipeline_gl_context_set(pipeline: zappar_pipeline_t, gl: WebGLRenderingContext, texturePool?: WebGLTexture[]): void;
|
|
7
7
|
pipeline_gl_context_lost(pipeline: zappar_pipeline_t): void;
|
|
8
8
|
pipeline_draw_face(pipeline: zappar_pipeline_t, projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, o: zappar_face_mesh_t): void;
|
|
9
|
+
pipeline_draw_image_target_preview(pipeline: zappar_pipeline_t, projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, o: zappar_image_tracker_t, indx: number): void;
|
|
9
10
|
pipeline_draw_face_project(pipeline: zappar_pipeline_t, drawwMatrix: Float32Array, vertices: Float32Array, uvMatrix: Float32Array, uvs: Float32Array, indices: Uint16Array, texture: WebGLTexture): void;
|
|
10
11
|
draw_plane(gl: WebGLRenderingContext, projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, texture: string): void;
|
|
11
12
|
image_tracker_target_image(o: zappar_image_tracker_t, indx: number): HTMLImageElement | undefined;
|
package/lib/drawplane.js
CHANGED
|
@@ -63,6 +63,7 @@ export function drawPlane(gl, projectionMatrix, cameraMatrix, targetMatrix, text
|
|
|
63
63
|
gl.enableVertexAttribArray(shader.attr_textureCoord);
|
|
64
64
|
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
65
65
|
gl.disableVertexAttribArray(shader.attr_position);
|
|
66
|
+
gl.disableVertexAttribArray(shader.attr_textureCoord);
|
|
66
67
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
67
68
|
}
|
|
68
69
|
function generateLocalMatrix() {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ImageTracker } from "./imagetracker";
|
|
2
|
+
export declare class PreviewMeshDraw {
|
|
3
|
+
private _gl;
|
|
4
|
+
private _vbo;
|
|
5
|
+
private _uvbo;
|
|
6
|
+
private _ibo;
|
|
7
|
+
private _lastIndices;
|
|
8
|
+
private _shader;
|
|
9
|
+
constructor(_gl: WebGLRenderingContext);
|
|
10
|
+
dispose(): void;
|
|
11
|
+
private _generateIBO;
|
|
12
|
+
private _generateVBO;
|
|
13
|
+
private _generateUVBO;
|
|
14
|
+
draw(matrix: Float32Array, tracker: ImageTracker, indx: number): void;
|
|
15
|
+
private _getShader;
|
|
16
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { compileShader, linkProgram } from "./shader";
|
|
2
|
+
export class PreviewMeshDraw {
|
|
3
|
+
constructor(_gl) {
|
|
4
|
+
this._gl = _gl;
|
|
5
|
+
}
|
|
6
|
+
dispose() {
|
|
7
|
+
if (this._vbo)
|
|
8
|
+
this._gl.deleteBuffer(this._vbo);
|
|
9
|
+
if (this._uvbo)
|
|
10
|
+
this._gl.deleteBuffer(this._uvbo);
|
|
11
|
+
if (this._ibo)
|
|
12
|
+
this._gl.deleteBuffer(this._ibo);
|
|
13
|
+
if (this._shader)
|
|
14
|
+
this._gl.deleteProgram(this._shader.prog);
|
|
15
|
+
this._vbo = undefined;
|
|
16
|
+
this._uvbo = undefined;
|
|
17
|
+
this._ibo = undefined;
|
|
18
|
+
this._shader = undefined;
|
|
19
|
+
}
|
|
20
|
+
_generateIBO(indices, gl) {
|
|
21
|
+
if (this._ibo && this._lastIndices === indices)
|
|
22
|
+
return this._ibo;
|
|
23
|
+
this._lastIndices = indices;
|
|
24
|
+
if (!this._ibo)
|
|
25
|
+
this._ibo = gl.createBuffer();
|
|
26
|
+
if (!this._ibo)
|
|
27
|
+
throw new Error("Unable to create buffer object");
|
|
28
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._ibo);
|
|
29
|
+
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
|
|
30
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
31
|
+
return this._ibo;
|
|
32
|
+
}
|
|
33
|
+
_generateVBO(face, gl) {
|
|
34
|
+
if (!this._vbo)
|
|
35
|
+
this._vbo = gl.createBuffer();
|
|
36
|
+
if (!this._vbo)
|
|
37
|
+
throw new Error("Unable to create buffer object");
|
|
38
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._vbo);
|
|
39
|
+
gl.bufferData(gl.ARRAY_BUFFER, face, gl.STATIC_DRAW);
|
|
40
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
41
|
+
return this._vbo;
|
|
42
|
+
}
|
|
43
|
+
_generateUVBO(face, gl) {
|
|
44
|
+
if (!this._uvbo)
|
|
45
|
+
this._uvbo = gl.createBuffer();
|
|
46
|
+
if (!this._uvbo)
|
|
47
|
+
throw new Error("Unable to create buffer object");
|
|
48
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvbo);
|
|
49
|
+
gl.bufferData(gl.ARRAY_BUFFER, face, gl.STATIC_DRAW);
|
|
50
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
51
|
+
return this._uvbo;
|
|
52
|
+
}
|
|
53
|
+
draw(matrix, tracker, indx) {
|
|
54
|
+
var _a;
|
|
55
|
+
const o = tracker.getPreviewMesh(indx);
|
|
56
|
+
const image = (_a = tracker.getTargetInfo(indx).preview) === null || _a === void 0 ? void 0 : _a.image;
|
|
57
|
+
if (!o || !image)
|
|
58
|
+
return;
|
|
59
|
+
if (!image.complete)
|
|
60
|
+
return;
|
|
61
|
+
let gl = this._gl;
|
|
62
|
+
let shader = this._getShader(gl);
|
|
63
|
+
let v = this._generateVBO(o.vertices, gl);
|
|
64
|
+
let n = this._generateUVBO(o.uvs, gl);
|
|
65
|
+
let i = this._generateIBO(o.indices, gl);
|
|
66
|
+
gl.enable(gl.DEPTH_TEST);
|
|
67
|
+
gl.enable(gl.CULL_FACE);
|
|
68
|
+
gl.useProgram(shader.prog);
|
|
69
|
+
gl.uniformMatrix4fv(shader.unif_matrix, false, matrix);
|
|
70
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
71
|
+
gl.bindTexture(gl.TEXTURE_2D, loadTexture(gl, image));
|
|
72
|
+
gl.uniform1i(shader.unif_skinSampler, 0);
|
|
73
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, v);
|
|
74
|
+
gl.vertexAttribPointer(shader.attr_position, 3, gl.FLOAT, false, 0, 0);
|
|
75
|
+
gl.enableVertexAttribArray(shader.attr_position);
|
|
76
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, n);
|
|
77
|
+
gl.vertexAttribPointer(shader.attr_textureCoord, 2, gl.FLOAT, false, 0, 0);
|
|
78
|
+
gl.enableVertexAttribArray(shader.attr_textureCoord);
|
|
79
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, i);
|
|
80
|
+
gl.drawElements(gl.TRIANGLES, o.indices.length, gl.UNSIGNED_SHORT, 0);
|
|
81
|
+
gl.disableVertexAttribArray(shader.attr_position);
|
|
82
|
+
gl.disableVertexAttribArray(shader.attr_textureCoord);
|
|
83
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
84
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
85
|
+
}
|
|
86
|
+
_getShader(gl) {
|
|
87
|
+
if (this._shader)
|
|
88
|
+
return this._shader;
|
|
89
|
+
let prog = gl.createProgram();
|
|
90
|
+
if (!prog)
|
|
91
|
+
throw new Error("Unable to create program");
|
|
92
|
+
let vertexShader = compileShader(gl, gl.VERTEX_SHADER, vertexShaderSrc);
|
|
93
|
+
let fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSrc);
|
|
94
|
+
gl.attachShader(prog, vertexShader);
|
|
95
|
+
gl.attachShader(prog, fragmentShader);
|
|
96
|
+
linkProgram(gl, prog);
|
|
97
|
+
let unif_matrix = gl.getUniformLocation(prog, "matrix");
|
|
98
|
+
if (!unif_matrix)
|
|
99
|
+
throw new Error("Unable to get uniform location mattrix");
|
|
100
|
+
let unif_skinSampler = gl.getUniformLocation(prog, "skinSampler");
|
|
101
|
+
if (!unif_skinSampler)
|
|
102
|
+
throw new Error("Unable to get uniform location skinSampler");
|
|
103
|
+
this._shader = {
|
|
104
|
+
prog,
|
|
105
|
+
unif_matrix,
|
|
106
|
+
unif_skinSampler,
|
|
107
|
+
attr_position: gl.getAttribLocation(prog, "position"),
|
|
108
|
+
attr_textureCoord: gl.getAttribLocation(prog, "textureCoord")
|
|
109
|
+
};
|
|
110
|
+
return this._shader;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const texturesByElement = new Map();
|
|
114
|
+
function loadTexture(gl, elm) {
|
|
115
|
+
let existing = texturesByElement.get(elm);
|
|
116
|
+
if (existing)
|
|
117
|
+
return existing;
|
|
118
|
+
existing = gl.createTexture() || undefined;
|
|
119
|
+
if (!existing)
|
|
120
|
+
throw new Error("Unable to create texture");
|
|
121
|
+
texturesByElement.set(elm, existing);
|
|
122
|
+
gl.bindTexture(gl.TEXTURE_2D, existing);
|
|
123
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
124
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
125
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
126
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
127
|
+
// Because images have to be download over the internet
|
|
128
|
+
// they might take a moment until they are ready.
|
|
129
|
+
// Until then put a single pixel in the texture so we can
|
|
130
|
+
// use it immediately. When the image has finished downloading
|
|
131
|
+
// we'll update the texture with the contents of the image.
|
|
132
|
+
const level = 0;
|
|
133
|
+
const internalFormat = gl.RGBA;
|
|
134
|
+
const srcFormat = gl.RGBA;
|
|
135
|
+
const srcType = gl.UNSIGNED_BYTE;
|
|
136
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
137
|
+
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, srcFormat, srcType, elm);
|
|
138
|
+
elm.addEventListener("load", () => {
|
|
139
|
+
if (!existing)
|
|
140
|
+
return;
|
|
141
|
+
gl.bindTexture(gl.TEXTURE_2D, existing);
|
|
142
|
+
const level = 0;
|
|
143
|
+
const internalFormat = gl.RGBA;
|
|
144
|
+
const srcFormat = gl.RGBA;
|
|
145
|
+
const srcType = gl.UNSIGNED_BYTE;
|
|
146
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
147
|
+
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, srcFormat, srcType, elm);
|
|
148
|
+
});
|
|
149
|
+
return existing;
|
|
150
|
+
}
|
|
151
|
+
let vertexShaderSrc = `
|
|
152
|
+
#ifndef GL_ES
|
|
153
|
+
#define highp
|
|
154
|
+
#define mediump
|
|
155
|
+
#define lowp
|
|
156
|
+
#endif
|
|
157
|
+
|
|
158
|
+
uniform mat4 matrix;
|
|
159
|
+
attribute vec4 position;
|
|
160
|
+
attribute vec2 textureCoord;
|
|
161
|
+
|
|
162
|
+
varying highp vec2 vTextureCoord;
|
|
163
|
+
|
|
164
|
+
void main()
|
|
165
|
+
{
|
|
166
|
+
gl_Position = matrix * position;
|
|
167
|
+
vTextureCoord = textureCoord;
|
|
168
|
+
}`;
|
|
169
|
+
let fragmentShaderSrc = `
|
|
170
|
+
#define highp mediump
|
|
171
|
+
#ifdef GL_ES
|
|
172
|
+
// define default precision for float, vec, mat.
|
|
173
|
+
precision highp float;
|
|
174
|
+
#else
|
|
175
|
+
#define highp
|
|
176
|
+
#define mediump
|
|
177
|
+
#define lowp
|
|
178
|
+
#endif
|
|
179
|
+
|
|
180
|
+
varying highp vec2 vTextureCoord;
|
|
181
|
+
uniform sampler2D skinSampler;
|
|
182
|
+
|
|
183
|
+
void main()
|
|
184
|
+
{
|
|
185
|
+
gl_FragColor = texture2D(skinSampler, vTextureCoord);
|
|
186
|
+
}`;
|
package/lib/gen/zappar.d.ts
CHANGED
|
@@ -39,6 +39,10 @@ export declare type zappar_instant_world_tracker_t = number & {
|
|
|
39
39
|
export interface zappar {
|
|
40
40
|
loaded(): boolean;
|
|
41
41
|
camera_default_device_id(userFacing: boolean): string;
|
|
42
|
+
camera_count(): number;
|
|
43
|
+
camera_id(indx: number): string;
|
|
44
|
+
camera_name(indx: number): string;
|
|
45
|
+
camera_user_facing(indx: number): boolean;
|
|
42
46
|
projection_matrix_from_camera_model(model: Float32Array, renderWidth: number, renderHeight: number): Float32Array;
|
|
43
47
|
projection_matrix_from_camera_model_ext(model: Float32Array, renderWidth: number, renderHeight: number, zNear: number, zFar: number): Float32Array;
|
|
44
48
|
log_level(): log_level_t;
|
|
@@ -105,6 +109,14 @@ export interface zappar {
|
|
|
105
109
|
image_tracker_target_preview_compressed(o: zappar_image_tracker_t, indx: number): Uint8Array;
|
|
106
110
|
image_tracker_target_preview_compressed_size(o: zappar_image_tracker_t, indx: number): number;
|
|
107
111
|
image_tracker_target_preview_compressed_mimetype(o: zappar_image_tracker_t, indx: number): string;
|
|
112
|
+
image_tracker_target_preview_mesh_indices(o: zappar_image_tracker_t, indx: number): Uint16Array;
|
|
113
|
+
image_tracker_target_preview_mesh_indices_size(o: zappar_image_tracker_t, indx: number): number;
|
|
114
|
+
image_tracker_target_preview_mesh_vertices(o: zappar_image_tracker_t, indx: number): Float32Array;
|
|
115
|
+
image_tracker_target_preview_mesh_vertices_size(o: zappar_image_tracker_t, indx: number): number;
|
|
116
|
+
image_tracker_target_preview_mesh_normals(o: zappar_image_tracker_t, indx: number): Float32Array;
|
|
117
|
+
image_tracker_target_preview_mesh_normals_size(o: zappar_image_tracker_t, indx: number): number;
|
|
118
|
+
image_tracker_target_preview_mesh_uvs(o: zappar_image_tracker_t, indx: number): Float32Array;
|
|
119
|
+
image_tracker_target_preview_mesh_uvs_size(o: zappar_image_tracker_t, indx: number): number;
|
|
108
120
|
image_tracker_enabled(o: zappar_image_tracker_t): boolean;
|
|
109
121
|
image_tracker_enabled_set(o: zappar_image_tracker_t, enabled: boolean): void;
|
|
110
122
|
image_tracker_anchor_count(o: zappar_image_tracker_t): number;
|
|
@@ -23,7 +23,9 @@ export declare class ImageProcessGL {
|
|
|
23
23
|
private _vertexBuffer;
|
|
24
24
|
private _indexBuffer;
|
|
25
25
|
private _greyscaleShader;
|
|
26
|
-
|
|
26
|
+
private _isWebGL2;
|
|
27
|
+
private _instancedArraysExtension;
|
|
28
|
+
constructor(_gl: WebGL2RenderingContext | WebGLRenderingContext);
|
|
27
29
|
resetGLContext(): void;
|
|
28
30
|
destroy(): void;
|
|
29
31
|
uploadFrame(texture: WebGLTexture, img: HTMLVideoElement | HTMLImageElement | ImageBitmap, rotation: number, fc: boolean): void;
|
package/lib/image-process-gl.js
CHANGED
|
@@ -17,6 +17,11 @@ export class ImageProcessGL {
|
|
|
17
17
|
this._framebufferHeight = 0;
|
|
18
18
|
this._framebufferId = null;
|
|
19
19
|
this._renderTexture = null;
|
|
20
|
+
this._isWebGL2 = false;
|
|
21
|
+
this._isWebGL2 = _gl.getParameter(_gl.VERSION).indexOf("WebGL 2") >= 0;
|
|
22
|
+
if (!this._isWebGL2) {
|
|
23
|
+
this._instancedArraysExtension = this._gl.getExtension("ANGLE_instanced_arrays");
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
resetGLContext() {
|
|
22
27
|
this._framebufferId = null;
|
|
@@ -36,6 +41,7 @@ export class ImageProcessGL {
|
|
|
36
41
|
const reenableDepthTest = gl.isEnabled(gl.DEPTH_TEST);
|
|
37
42
|
const reenableBlend = gl.isEnabled(gl.BLEND);
|
|
38
43
|
const reenableCullFace = gl.isEnabled(gl.CULL_FACE);
|
|
44
|
+
const reenableStencilTest = gl.isEnabled(gl.STENCIL_TEST);
|
|
39
45
|
const previousActiveTexture = gl.getParameter(gl.ACTIVE_TEXTURE);
|
|
40
46
|
const previousUnpackFlip = gl.getParameter(gl.UNPACK_FLIP_Y_WEBGL);
|
|
41
47
|
const previousProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
@@ -48,6 +54,7 @@ export class ImageProcessGL {
|
|
|
48
54
|
gl.disable(gl.DEPTH_TEST);
|
|
49
55
|
gl.disable(gl.BLEND);
|
|
50
56
|
gl.disable(gl.CULL_FACE);
|
|
57
|
+
gl.disable(gl.STENCIL_TEST);
|
|
51
58
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
52
59
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
53
60
|
const level = 0;
|
|
@@ -84,8 +91,22 @@ export class ImageProcessGL {
|
|
|
84
91
|
const previousTextureAttribNormalized = gl.getVertexAttrib(shader.aTextureCoordLoc, gl.VERTEX_ATTRIB_ARRAY_NORMALIZED);
|
|
85
92
|
const previousTextureAttribStride = gl.getVertexAttrib(shader.aTextureCoordLoc, gl.VERTEX_ATTRIB_ARRAY_STRIDE);
|
|
86
93
|
const previousTextureAttribOffset = gl.getVertexAttribOffset(shader.aTextureCoordLoc, gl.VERTEX_ATTRIB_ARRAY_POINTER);
|
|
87
|
-
const previousTextureAttribEnabled = gl.getVertexAttrib(shader.aTextureCoordLoc, gl.VERTEX_ATTRIB_ARRAY_ENABLED);
|
|
88
94
|
const previousTextureAttribBufferBinding = gl.getVertexAttrib(shader.aTextureCoordLoc, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING);
|
|
95
|
+
const previousTextureAttribEnabled = gl.getVertexAttrib(shader.aTextureCoordLoc, gl.VERTEX_ATTRIB_ARRAY_ENABLED);
|
|
96
|
+
let previousVertexAttribDivisor = 0;
|
|
97
|
+
let previousTextureAttribDivisor = 0;
|
|
98
|
+
if (this._isWebGL2) {
|
|
99
|
+
previousVertexAttribDivisor = gl.getVertexAttrib(shader.aVertexPositionLoc, gl.VERTEX_ATTRIB_ARRAY_DIVISOR);
|
|
100
|
+
previousTextureAttribDivisor = gl.getVertexAttrib(shader.aTextureCoordLoc, gl.VERTEX_ATTRIB_ARRAY_DIVISOR);
|
|
101
|
+
gl.vertexAttribDivisor(shader.aVertexPositionLoc, 0);
|
|
102
|
+
gl.vertexAttribDivisor(shader.aTextureCoordLoc, 0);
|
|
103
|
+
}
|
|
104
|
+
else if (this._instancedArraysExtension) {
|
|
105
|
+
previousVertexAttribDivisor = gl.getVertexAttrib(shader.aVertexPositionLoc, this._instancedArraysExtension.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
|
|
106
|
+
previousTextureAttribDivisor = gl.getVertexAttrib(shader.aTextureCoordLoc, this._instancedArraysExtension.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
|
|
107
|
+
this._instancedArraysExtension.vertexAttribDivisorANGLE(shader.aVertexPositionLoc, 0);
|
|
108
|
+
this._instancedArraysExtension.vertexAttribDivisorANGLE(shader.aTextureCoordLoc, 0);
|
|
109
|
+
}
|
|
89
110
|
// Rendering to the greyscale conversion buffer - bind the framebuffer
|
|
90
111
|
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
91
112
|
gl.viewport(0, 0, this._framebufferWidth, this._framebufferHeight);
|
|
@@ -121,6 +142,14 @@ export class ImageProcessGL {
|
|
|
121
142
|
gl.disableVertexAttribArray(shader.aVertexPositionLoc);
|
|
122
143
|
if (!previousTextureAttribEnabled)
|
|
123
144
|
gl.disableVertexAttribArray(shader.aTextureCoordLoc);
|
|
145
|
+
if (this._isWebGL2) {
|
|
146
|
+
gl.vertexAttribDivisor(shader.aVertexPositionLoc, previousVertexAttribDivisor);
|
|
147
|
+
gl.vertexAttribDivisor(shader.aTextureCoordLoc, previousTextureAttribDivisor);
|
|
148
|
+
}
|
|
149
|
+
else if (this._instancedArraysExtension) {
|
|
150
|
+
this._instancedArraysExtension.vertexAttribDivisorANGLE(shader.aVertexPositionLoc, previousVertexAttribDivisor);
|
|
151
|
+
this._instancedArraysExtension.vertexAttribDivisorANGLE(shader.aTextureCoordLoc, previousTextureAttribDivisor);
|
|
152
|
+
}
|
|
124
153
|
gl.bindFramebuffer(gl.FRAMEBUFFER, previousBoundFramebuffer);
|
|
125
154
|
gl.useProgram(previousProgram);
|
|
126
155
|
gl.bindTexture(gl.TEXTURE_2D, previousBoundTexture);
|
|
@@ -135,6 +164,8 @@ export class ImageProcessGL {
|
|
|
135
164
|
gl.enable(gl.DEPTH_TEST);
|
|
136
165
|
if (reenableScissorTest)
|
|
137
166
|
gl.enable(gl.SCISSOR_TEST);
|
|
167
|
+
if (reenableStencilTest)
|
|
168
|
+
gl.enable(gl.STENCIL_TEST);
|
|
138
169
|
}
|
|
139
170
|
readFrame(texture, pixels) {
|
|
140
171
|
let gl = this._gl;
|
|
@@ -12,11 +12,12 @@ function planar(info) {
|
|
|
12
12
|
const aspectRatio = info.trainedWidth / info.trainedHeight;
|
|
13
13
|
if (isNaN(aspectRatio))
|
|
14
14
|
return defaultMesh();
|
|
15
|
+
const scaling = info.physicalScaleFactor > 0 ? info.physicalScaleFactor : 1;
|
|
15
16
|
const vertices = new Float32Array([
|
|
16
|
-
-1.0 * aspectRatio, -1, 0,
|
|
17
|
-
-1.0 * aspectRatio,
|
|
18
|
-
aspectRatio,
|
|
19
|
-
aspectRatio, -1, 0
|
|
17
|
+
-1.0 * aspectRatio * scaling, -1 * scaling, 0,
|
|
18
|
+
-1.0 * aspectRatio * scaling, scaling, 0,
|
|
19
|
+
aspectRatio * scaling, scaling, 0,
|
|
20
|
+
aspectRatio * scaling, -1 * scaling, 0
|
|
20
21
|
]);
|
|
21
22
|
const indices = new Uint16Array([0, 2, 1, 0, 3, 2]);
|
|
22
23
|
const uvs = new Float32Array([
|
|
@@ -42,7 +43,8 @@ function defaultMesh() {
|
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
45
|
function cylindrical(info) {
|
|
45
|
-
|
|
46
|
+
const wrap_amount = 2 * info.trainedWidth / (info.trainedHeight * info.topRadius);
|
|
47
|
+
return generalConical(info, 2, false, 0, 0, 0, vec2.create(), info.trainedWidth / info.trainedHeight, wrap_amount, info.physicalScaleFactor);
|
|
46
48
|
}
|
|
47
49
|
function conical(info) {
|
|
48
50
|
const radius_diff = info.topRadius - info.bottomRadius;
|
|
@@ -131,26 +133,31 @@ function conical(info) {
|
|
|
131
133
|
vec2.subtract(bottom_from_center, bottom_corner, rotation_center);
|
|
132
134
|
const top_2d_radius = vec2.length(top_from_center);
|
|
133
135
|
const bottom_2d_radius = vec2.length(bottom_from_center);
|
|
136
|
+
let max_angle = 2 * Math.abs(Math.atan(top_from_center[0] / top_from_center[1]));
|
|
137
|
+
if (wide)
|
|
138
|
+
max_angle = (2 * Math.PI) - max_angle;
|
|
139
|
+
let theta_3d = (top_2d_radius * max_angle) / info.topRadius;
|
|
134
140
|
let theta = Math.abs(Math.atan(top_from_center[0] / top_from_center[1]));
|
|
135
141
|
if (wide)
|
|
136
142
|
theta = Math.PI - theta;
|
|
137
|
-
return generalConical(info, height_3d, flip, theta, bottom_2d_radius, top_2d_radius, rotation_center, aspect_ratio);
|
|
143
|
+
return generalConical(info, height_3d, flip, theta, bottom_2d_radius, top_2d_radius, rotation_center, aspect_ratio, theta_3d, info.physicalScaleFactor);
|
|
138
144
|
}
|
|
139
|
-
function generalConical(info, height_3d, flip, theta, bottom_2d_radius, top_2d_radius, rotation_center, aspect_ratio) {
|
|
145
|
+
function generalConical(info, height_3d, flip, theta, bottom_2d_radius, top_2d_radius, rotation_center, aspect_ratio, wrap_amount, psf) {
|
|
140
146
|
if (isNaN(aspect_ratio))
|
|
141
147
|
aspect_ratio = 1;
|
|
142
148
|
const vertices = [];
|
|
143
149
|
const uvs = [];
|
|
144
|
-
const
|
|
150
|
+
const physical_scale = psf > 0 ? psf : 1;
|
|
151
|
+
const scale_factor = physical_scale * 2.0 / height_3d;
|
|
145
152
|
const subdivisons = 64;
|
|
146
153
|
for (let s = 0; s <= subdivisons; ++s) {
|
|
147
|
-
const angle = s * 2
|
|
154
|
+
const angle = (s * wrap_amount / subdivisons) + (((2 * Math.PI) - wrap_amount) / 2);
|
|
148
155
|
const bx = info.bottomRadius * Math.sin(angle) * scale_factor;
|
|
149
156
|
const bz = info.bottomRadius * Math.cos(angle) * scale_factor;
|
|
150
157
|
const tx = info.topRadius * Math.sin(angle) * scale_factor;
|
|
151
158
|
const tz = info.topRadius * Math.cos(angle) * scale_factor;
|
|
152
|
-
const btm = -1;
|
|
153
|
-
const top =
|
|
159
|
+
const btm = -1 * physical_scale;
|
|
160
|
+
const top = physical_scale;
|
|
154
161
|
if (flip) {
|
|
155
162
|
vertices.push(bx, btm, bz);
|
|
156
163
|
vertices.push(tx, top, tz);
|
package/lib/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import { Additional } from "./additional";
|
|
|
3
3
|
import { Options } from "./options";
|
|
4
4
|
export declare type Zappar = zappar & Additional;
|
|
5
5
|
export declare function initialize(opts?: Options): Zappar;
|
|
6
|
-
export { zappar_image_tracker_t, zappar_instant_world_tracker_t, zappar_barcode_finder_t, zappar_face_tracker_t, zappar_face_landmark_t, barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, zappar_face_mesh_t, zappar_pipeline_t, zappar_camera_source_t, zappar_sequence_source_t } from "./gen/zappar";
|
|
6
|
+
export { zappar_image_tracker_t, zappar_instant_world_tracker_t, zappar_barcode_finder_t, zappar_face_tracker_t, zappar_face_landmark_t, barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, zappar_face_mesh_t, zappar_pipeline_t, zappar_camera_source_t, zappar_sequence_source_t, image_target_type_t } from "./gen/zappar";
|
package/lib/index.js
CHANGED
|
@@ -4,4 +4,4 @@ export function initialize(opts) {
|
|
|
4
4
|
console.log(`Zappar CV v${VERSION}`);
|
|
5
5
|
return nativeInitialize(opts);
|
|
6
6
|
}
|
|
7
|
-
export { barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t } from "./gen/zappar";
|
|
7
|
+
export { barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, image_target_type_t } from "./gen/zappar";
|
package/lib/native.js
CHANGED
|
@@ -118,7 +118,7 @@ export function initialize(opts) {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
|
-
client = Object.assign(Object.assign({}, c.impl), { loaded: () => loaded, camera_default_device_id: userFacing => userFacing ? CameraSource.USER_DEFAULT_DEVICE_ID : CameraSource.DEFAULT_DEVICE_ID, camera_source_create: (p, deviceId) => createCameraSource(p, deviceId), camera_source_destroy: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.destroy(); }, camera_source_pause: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.pause(); }, camera_source_start: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.start(); }, pipeline_create: () => Pipeline.create(c.impl, messageManager), pipeline_frame_update: (p) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.frameUpdate(c); }, pipeline_camera_frame_draw_gl: (pipeline, screenWidth, screenHeight, mirror) => {
|
|
121
|
+
client = Object.assign(Object.assign({}, c.impl), { loaded: () => loaded, camera_default_device_id: userFacing => userFacing ? CameraSource.USER_DEFAULT_DEVICE_ID : CameraSource.DEFAULT_DEVICE_ID, camera_source_create: (p, deviceId) => createCameraSource(p, deviceId), camera_source_destroy: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.destroy(); }, camera_source_pause: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.pause(); }, camera_source_start: cam => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.start(); }, camera_count: () => 2, camera_id: indx => indx === 0 ? CameraSource.DEFAULT_DEVICE_ID : CameraSource.USER_DEFAULT_DEVICE_ID, camera_name: indx => indx === 0 ? "Rear-facing Camera" : "User-facing Camera", camera_user_facing: indx => indx !== 0, pipeline_create: () => Pipeline.create(c.impl, messageManager), pipeline_frame_update: (p) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.frameUpdate(c); }, pipeline_camera_frame_draw_gl: (pipeline, screenWidth, screenHeight, mirror) => {
|
|
122
122
|
var _a;
|
|
123
123
|
(_a = Pipeline.get(pipeline)) === null || _a === void 0 ? void 0 : _a.cameraFrameDrawGL(screenWidth, screenHeight, mirror);
|
|
124
124
|
}, draw_plane: (gl, projectionMatrix, cameraMatrix, targetMatrix, texture) => {
|
|
@@ -134,6 +134,14 @@ export function initialize(opts) {
|
|
|
134
134
|
}, pipeline_draw_face_project: (p, matrix, vertices, uvMatrix, uvs, indices, texture) => {
|
|
135
135
|
var _a;
|
|
136
136
|
(_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.drawFaceProject(matrix, vertices, uvMatrix, uvs, indices, texture);
|
|
137
|
+
}, pipeline_draw_image_target_preview: (p, projectionMatrix, cameraMatrix, targetMatrix, o, indx) => {
|
|
138
|
+
var _a;
|
|
139
|
+
let obj = ImageTracker.get(o);
|
|
140
|
+
if (!obj) {
|
|
141
|
+
zcwarn("image tracker not found");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
(_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.drawImageTargetPreview(projectionMatrix, cameraMatrix, targetMatrix, indx, obj);
|
|
137
145
|
}, projection_matrix_from_camera_model: projectionMatrix, projection_matrix_from_camera_model_ext: projectionMatrix, pipeline_process_gl: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.processGL(); }, pipeline_gl_context_set: (p, gl, texturePool) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.glContextSet(gl, texturePool); }, pipeline_gl_context_lost: (p) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.glContextLost(); }, pipeline_camera_frame_upload_gl: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.uploadGL(); }, pipeline_camera_frame_texture_gl: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameTexture(); }, pipeline_camera_frame_texture_matrix: (p, sw, sh, mirror) => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameTextureMatrix(sw, sh, mirror)) || mat4.create(); }, pipeline_camera_frame_user_facing: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraFrameUserFacing()) || false; }, pipeline_camera_pose_default: () => mat4.create(), pipeline_camera_pose_with_attitude: (p, mirror) => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.cameraPoseWithAttitude(mirror)) || mat4.create(); }, pipeline_camera_pose_with_origin: (p, o) => { let res = mat4.create(); mat4.invert(res, o); return res; }, pipeline_sequence_record_clear: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordClear(); }, pipeline_sequence_record_start: (p, expectedFrames) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordStart(expectedFrames); }, pipeline_sequence_record_stop: p => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordStop(); }, pipeline_sequence_record_device_attitude_matrices_set: (p, v) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordDeviceAttitudeMatrices(v); }, pipeline_sequence_record_data: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordData()) || new Uint8Array(0); }, pipeline_sequence_record_data_size: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.sequenceRecordData().byteLength) || 0; }, instant_world_tracker_anchor_pose_camera_relative: (o, mirror) => {
|
|
138
146
|
let res = applyScreenCounterRotation(undefined, c.impl.instant_world_tracker_anchor_pose_raw(o));
|
|
139
147
|
if (mirror) {
|
|
@@ -265,6 +273,62 @@ export function initialize(opts) {
|
|
|
265
273
|
}
|
|
266
274
|
mat4.multiply(res, cameraPose, res);
|
|
267
275
|
return res;
|
|
276
|
+
}, image_tracker_target_preview_mesh_indices: (o, indx) => {
|
|
277
|
+
let obj = ImageTracker.get(o);
|
|
278
|
+
if (!obj) {
|
|
279
|
+
zcwarn("attempting to call image_tracker_target_preview_mesh_indices on a destroyed zappar_image_tracker_t");
|
|
280
|
+
return new Uint16Array();
|
|
281
|
+
}
|
|
282
|
+
return obj.getPreviewMesh(indx).indices;
|
|
283
|
+
}, image_tracker_target_preview_mesh_vertices: (o, indx) => {
|
|
284
|
+
let obj = ImageTracker.get(o);
|
|
285
|
+
if (!obj) {
|
|
286
|
+
zcwarn("attempting to call image_tracker_target_preview_mesh_vertices on a destroyed zappar_image_tracker_t");
|
|
287
|
+
return new Float32Array();
|
|
288
|
+
}
|
|
289
|
+
return obj.getPreviewMesh(indx).vertices;
|
|
290
|
+
}, image_tracker_target_preview_mesh_uvs: (o, indx) => {
|
|
291
|
+
let obj = ImageTracker.get(o);
|
|
292
|
+
if (!obj) {
|
|
293
|
+
zcwarn("attempting to call image_tracker_target_preview_mesh_uvs on a destroyed zappar_image_tracker_t");
|
|
294
|
+
return new Float32Array();
|
|
295
|
+
}
|
|
296
|
+
return obj.getPreviewMesh(indx).uvs;
|
|
297
|
+
}, image_tracker_target_preview_mesh_normals: (o, indx) => {
|
|
298
|
+
let obj = ImageTracker.get(o);
|
|
299
|
+
if (!obj) {
|
|
300
|
+
zcwarn("attempting to call image_tracker_target_preview_mesh_normals on a destroyed zappar_image_tracker_t");
|
|
301
|
+
return new Float32Array();
|
|
302
|
+
}
|
|
303
|
+
return obj.getPreviewMesh(indx).normals;
|
|
304
|
+
}, image_tracker_target_preview_mesh_indices_size: (o, indx) => {
|
|
305
|
+
let obj = ImageTracker.get(o);
|
|
306
|
+
if (!obj) {
|
|
307
|
+
zcwarn("attempting to call image_tracker_target_preview_mesh_indices_size on a destroyed zappar_image_tracker_t");
|
|
308
|
+
return 0;
|
|
309
|
+
}
|
|
310
|
+
return obj.getPreviewMesh(indx).indices.length;
|
|
311
|
+
}, image_tracker_target_preview_mesh_vertices_size: (o, indx) => {
|
|
312
|
+
let obj = ImageTracker.get(o);
|
|
313
|
+
if (!obj) {
|
|
314
|
+
zcwarn("attempting to call image_tracker_target_preview_mesh_vertices_size on a destroyed zappar_image_tracker_t");
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
return obj.getPreviewMesh(indx).vertices.length;
|
|
318
|
+
}, image_tracker_target_preview_mesh_uvs_size: (o, indx) => {
|
|
319
|
+
let obj = ImageTracker.get(o);
|
|
320
|
+
if (!obj) {
|
|
321
|
+
zcwarn("attempting to call image_tracker_target_preview_mesh_uvs_size on a destroyed zappar_image_tracker_t");
|
|
322
|
+
return 0;
|
|
323
|
+
}
|
|
324
|
+
return obj.getPreviewMesh(indx).uvs.length;
|
|
325
|
+
}, image_tracker_target_preview_mesh_normals_size: (o, indx) => {
|
|
326
|
+
let obj = ImageTracker.get(o);
|
|
327
|
+
if (!obj) {
|
|
328
|
+
zcwarn("attempting to call image_tracker_target_preview_mesh_normals_size on a destroyed zappar_image_tracker_t");
|
|
329
|
+
return 0;
|
|
330
|
+
}
|
|
331
|
+
return obj.getPreviewMesh(indx).normals.length;
|
|
268
332
|
}, face_tracker_anchor_pose_camera_relative: (o, indx, mirror) => {
|
|
269
333
|
let res = applyScreenCounterRotation(undefined, c.impl.face_tracker_anchor_pose_raw(o, indx));
|
|
270
334
|
if (mirror) {
|
package/lib/pipeline.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Source, CameraFrameInfo } from "./source";
|
|
|
7
7
|
import { CameraFrameReturnS2C, ImageBitmapS2C, VideoFrameS2C } from "./workerinterface";
|
|
8
8
|
import { FaceMesh } from "./facemesh";
|
|
9
9
|
import { Event } from "./event";
|
|
10
|
+
import { ImageTracker } from "./imagetracker";
|
|
10
11
|
export declare class Pipeline {
|
|
11
12
|
private _client;
|
|
12
13
|
private _impl;
|
|
@@ -21,6 +22,7 @@ export declare class Pipeline {
|
|
|
21
22
|
cameraPixelArrays: ArrayBuffer[];
|
|
22
23
|
private _cameraDraw;
|
|
23
24
|
private _faceDraw;
|
|
25
|
+
private _imageTargetPreviewDraw;
|
|
24
26
|
private _faceProjectDraw;
|
|
25
27
|
private _sequenceRecorder;
|
|
26
28
|
private _sequenceRecordDeviceAttitudeMatrices;
|
|
@@ -44,6 +46,7 @@ export declare class Pipeline {
|
|
|
44
46
|
glContextLost(): void;
|
|
45
47
|
glContextSet(gl: WebGLRenderingContext, texturePool?: WebGLTexture[]): void;
|
|
46
48
|
drawFace(projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, o: FaceMesh): void;
|
|
49
|
+
drawImageTargetPreview(projectionMatrix: Float32Array, cameraMatrix: Float32Array, targetMatrix: Float32Array, indx: number, o: ImageTracker): void;
|
|
47
50
|
drawFaceProject(matrix: Float32Array, vertices: Float32Array, uvMatrix: Float32Array, uvs: Float32Array, indices: Uint16Array, texture: WebGLTexture): void;
|
|
48
51
|
cameraFrameTexture(): WebGLTexture | undefined;
|
|
49
52
|
cameraFrameTextureMatrix(sw: number, sh: number, mirror: boolean): Float32Array;
|
package/lib/pipeline.js
CHANGED
|
@@ -8,6 +8,7 @@ import { Event } from "./event";
|
|
|
8
8
|
import { zcerr } from "./loglevel";
|
|
9
9
|
import { SequenceRecorder } from "./sequencerecorder";
|
|
10
10
|
import { getCameraSource } from "./camera-source-map";
|
|
11
|
+
import { PreviewMeshDraw } from "./drawpreviewmesh";
|
|
11
12
|
let byId = new Map();
|
|
12
13
|
let identity = mat4.create();
|
|
13
14
|
export class Pipeline {
|
|
@@ -121,10 +122,13 @@ export class Pipeline {
|
|
|
121
122
|
this._cameraDraw.dispose();
|
|
122
123
|
if (this._faceDraw)
|
|
123
124
|
this._faceDraw.dispose();
|
|
125
|
+
if (this._imageTargetPreviewDraw)
|
|
126
|
+
this._imageTargetPreviewDraw.dispose();
|
|
124
127
|
if (this._faceProjectDraw)
|
|
125
128
|
this._faceProjectDraw.dispose();
|
|
126
129
|
delete this._cameraDraw;
|
|
127
130
|
delete this._faceDraw;
|
|
131
|
+
delete this._imageTargetPreviewDraw;
|
|
128
132
|
delete this._faceProjectDraw;
|
|
129
133
|
disposeDrawPlane();
|
|
130
134
|
this.onGLContextReset.emit();
|
|
@@ -166,6 +170,16 @@ export class Pipeline {
|
|
|
166
170
|
mat4.multiply(mat, mat, targetMatrix);
|
|
167
171
|
this._faceDraw.drawFace(mat, o);
|
|
168
172
|
}
|
|
173
|
+
drawImageTargetPreview(projectionMatrix, cameraMatrix, targetMatrix, indx, o) {
|
|
174
|
+
if (!this.glContext)
|
|
175
|
+
return;
|
|
176
|
+
if (!this._imageTargetPreviewDraw)
|
|
177
|
+
this._imageTargetPreviewDraw = new PreviewMeshDraw(this.glContext);
|
|
178
|
+
let mat = mat4.create();
|
|
179
|
+
mat4.multiply(mat, projectionMatrix, cameraMatrix);
|
|
180
|
+
mat4.multiply(mat, mat, targetMatrix);
|
|
181
|
+
this._imageTargetPreviewDraw.draw(mat, o, indx);
|
|
182
|
+
}
|
|
169
183
|
drawFaceProject(matrix, vertices, uvMatrix, uvs, indices, texture) {
|
|
170
184
|
if (!this.glContext)
|
|
171
185
|
return;
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.9";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "2.0.0-beta.
|
|
1
|
+
export const VERSION = "2.0.0-beta.9";
|
package/lib/worker-client.js
CHANGED
|
@@ -15,7 +15,7 @@ export function launchWorker(worker) {
|
|
|
15
15
|
worker = new Worker(new URL("./worker", import.meta.url), { type: 'module' });
|
|
16
16
|
worker.postMessage({
|
|
17
17
|
t: "wasm",
|
|
18
|
-
url: new URL("./
|
|
18
|
+
url: new URL("./zappar-cv.wasm", import.meta.url).toString()
|
|
19
19
|
});
|
|
20
20
|
yield waitForLoad(worker);
|
|
21
21
|
function sendOutgoing() {
|
package/lib/worker-server.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import * as ZNM from "./
|
|
10
|
+
import * as ZNM from "./zappar-cv";
|
|
11
11
|
import { getRuntimeObject } from "./gen/zappar-cwrap";
|
|
12
12
|
import { zappar_server } from "./gen/zappar-server";
|
|
13
13
|
import { MsgManager } from "./messages";
|
|
@@ -21,7 +21,7 @@ export function launchWorkerServer(wasmUrl) {
|
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
let mod = ZNM.default({
|
|
23
23
|
locateFile: (path, prefix) => {
|
|
24
|
-
if (path.endsWith("
|
|
24
|
+
if (path.endsWith("zappar-cv.wasm")) {
|
|
25
25
|
return wasmUrl;
|
|
26
26
|
}
|
|
27
27
|
return prefix + path;
|
package/lib/worker.js
CHANGED
|
@@ -8,7 +8,7 @@ messageManager.onOutgoingMessage.bind(() => {
|
|
|
8
8
|
});
|
|
9
9
|
let launchHandler = (evt) => {
|
|
10
10
|
if (evt && evt.data && evt.data.t === "wasm") {
|
|
11
|
-
let url = location.href.startsWith("blob") ? evt.data.url : new URL("./
|
|
11
|
+
let url = location.href.startsWith("blob") ? evt.data.url : new URL("./zappar-cv.wasm", import.meta.url).toString();
|
|
12
12
|
launchWorkerServer(url);
|
|
13
13
|
ctx.removeEventListener("message", launchHandler);
|
|
14
14
|
}
|