@zappar/zappar-cv 0.4.0-beta.9 → 2.0.0-beta.3
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 +12 -0
- package/README.md +2 -2
- package/lib/additional.d.ts +3 -1
- package/lib/additional.js +1 -2
- package/lib/camera-source-map.js +16 -24
- package/lib/camera-source.js +17 -21
- package/lib/cameramodel.js +18 -23
- package/lib/compatibility.js +1 -3
- package/lib/deserializer.js +1 -5
- package/lib/direct.js +12 -16
- package/lib/drawcamera.js +26 -31
- package/lib/drawface.js +5 -9
- package/lib/drawfaceproject.js +5 -9
- package/lib/drawplane.js +6 -11
- package/lib/event.js +5 -13
- package/lib/facelandmark.d.ts +1 -2
- package/lib/facelandmark.js +11 -18
- package/lib/facelandmarkdata.js +1 -4
- package/lib/facelandmarkinterface.js +1 -2
- package/lib/facemesh.js +10 -17
- package/lib/gen/zappar-client.js +5 -24
- package/lib/gen/zappar-cwrap.js +1 -12
- package/lib/gen/zappar-native.d.ts +0 -1
- package/lib/gen/zappar-native.js +10 -13
- package/lib/gen/zappar-server.js +5 -13
- package/lib/gen/zappar.d.ts +7 -2
- package/lib/gen/zappar.js +5 -13
- package/lib/gfx.js +1 -4
- package/lib/gl-state-manager.js +1 -5
- package/lib/html-element-source.js +23 -27
- package/lib/image-process-gl.js +29 -21
- package/lib/imagebitmap-camera-source.js +30 -34
- package/lib/imagetracker.d.ts +28 -0
- package/lib/imagetracker.js +115 -0
- package/lib/index-standalone.d.ts +3 -0
- package/lib/index-standalone.js +5 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -27
- package/lib/landmarkdatagenerate.js +25 -30
- package/lib/loglevel.js +9 -16
- package/lib/messages.js +4 -8
- package/lib/mstp-camera-source.js +22 -26
- package/lib/native.d.ts +2 -1
- package/lib/native.js +194 -132
- package/lib/options.d.ts +3 -0
- package/lib/options.js +1 -0
- package/lib/permission.js +13 -27
- package/lib/pipeline.d.ts +1 -2
- package/lib/pipeline.js +34 -39
- package/lib/profile.js +40 -45
- package/lib/riff-reader.d.ts +18 -0
- package/lib/riff-reader.js +52 -0
- package/lib/sequencerecorder.js +7 -12
- package/lib/sequencesource.d.ts +2 -0
- package/lib/sequencesource.js +28 -25
- package/lib/serializer.js +1 -5
- package/lib/shader.js +2 -7
- package/lib/source.js +1 -5
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -4
- package/lib/worker-client.d.ts +1 -1
- package/lib/worker-client.js +9 -21
- package/lib/worker-imagebitmap.js +9 -13
- package/lib/worker-server.js +33 -37
- package/lib/worker.js +6 -10
- package/lib/workerinterface.js +1 -2
- package/lib/zcv.js +125 -115
- package/lib/zcv.wasm +0 -0
- package/package.json +14 -16
- package/umd/169.zappar-cv.js +1 -0
- package/umd/{482727c0e7dd40d73f5aae47f238ad61.zbin → 482727c0e7dd40d73f5a.zbin} +0 -0
- package/umd/752.zappar-cv.js +1 -0
- package/umd/{b4f46e148a3b3b5aef90717d8d60e3fc.zbin → b4f46e148a3b3b5aef90.zbin} +0 -0
- package/umd/f2c60b832388cf528a24.wasm +0 -0
- package/umd/{f7b62a3a53b5c9b3222ba8dc53cb8b11.zbin → f7b62a3a53b5c9b3222b.zbin} +0 -0
- package/umd/zappar-cv.js +1 -1
- package/umd/zappar-cv.worker.js +1 -1
- package/umd/a78f5ad0a44def457ee50c8bcd5fd27c.wasm +0 -0
package/lib/native.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,35 +7,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const gfx_1 = require("./gfx");
|
|
10
|
+
import { zappar_client } from "./gen/zappar-client";
|
|
11
|
+
import { drawPlane } from "./drawplane";
|
|
12
|
+
import { cameraRotationForScreenOrientation, projectionMatrix } from "./cameramodel";
|
|
13
|
+
import { mat4, vec3 } from "gl-matrix";
|
|
14
|
+
import { launchWorker, messageManager } from "./worker-client";
|
|
15
|
+
import { permissionRequestUI, permissionGrantedAll, permissionGrantedCamera, permissionGrantedMotion, permissionDeniedAny, permissionDeniedCamera, permissionDeniedMotion, permissionRequestMotion, permissionRequestCamera, permissionRequestAll, permissionDeniedUI } from "./permission";
|
|
16
|
+
import { createFaceMesh, destroyFaceMesh, getFaceMesh } from "./facemesh";
|
|
17
|
+
import { Pipeline, applyScreenCounterRotation } from "./pipeline";
|
|
18
|
+
import { CameraSource } from "./camera-source";
|
|
19
|
+
import { HTMLElementSource } from "./html-element-source";
|
|
20
|
+
import { createFaceLandmark, destroyFaceLandmark, getFaceLandmark } from "./facelandmark";
|
|
21
|
+
import compatibility from './compatibility';
|
|
22
|
+
import { setLogLevel, zcwarn, zcout } from "./loglevel";
|
|
23
|
+
import { SequenceSource } from "./sequencesource";
|
|
24
|
+
import { createCameraSource, getCameraSource } from "./camera-source-map";
|
|
25
|
+
import { gfx } from "./gfx";
|
|
26
|
+
import { ImageTracker } from "./imagetracker";
|
|
29
27
|
let client;
|
|
30
|
-
function initialize() {
|
|
28
|
+
export function initialize(opts) {
|
|
31
29
|
if (client)
|
|
32
30
|
return client;
|
|
33
31
|
let loaded = false;
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
launchWorker(opts === null || opts === void 0 ? void 0 : opts.worker).then(() => {
|
|
33
|
+
zcout("Fully loaded");
|
|
36
34
|
loaded = true;
|
|
37
35
|
});
|
|
38
|
-
let c = new
|
|
39
|
-
|
|
36
|
+
let c = new zappar_client(ab => {
|
|
37
|
+
messageManager.postOutgoingMessage({
|
|
40
38
|
t: "zappar",
|
|
41
39
|
d: ab
|
|
42
40
|
}, [ab]);
|
|
@@ -46,28 +44,28 @@ function initialize() {
|
|
|
46
44
|
if (pathParts.length > 1 && pathParts[1].length > 0)
|
|
47
45
|
c.impl.analytics_project_id_set(".wiz" + pathParts[1]);
|
|
48
46
|
}
|
|
49
|
-
|
|
47
|
+
messageManager.onIncomingMessage.bind(msg => {
|
|
50
48
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
51
49
|
switch (msg.t) {
|
|
52
50
|
case "zappar":
|
|
53
|
-
(_a =
|
|
51
|
+
(_a = Pipeline.get(msg.p)) === null || _a === void 0 ? void 0 : _a.pendingMessages.push(msg.d);
|
|
54
52
|
break;
|
|
55
53
|
case "buf":
|
|
56
54
|
c.serializer.bufferReturn(msg.d);
|
|
57
55
|
break;
|
|
58
56
|
case "cameraFrameRecycleS2C": {
|
|
59
57
|
let msgt = msg;
|
|
60
|
-
(_c = (_b =
|
|
58
|
+
(_c = (_b = Pipeline.get(msgt.p)) === null || _b === void 0 ? void 0 : _b.cameraTokenReturn) === null || _c === void 0 ? void 0 : _c.call(_b, msg);
|
|
61
59
|
break;
|
|
62
60
|
}
|
|
63
61
|
case "videoFrameS2C": {
|
|
64
62
|
let msgt = msg;
|
|
65
|
-
(_e = (_d =
|
|
63
|
+
(_e = (_d = Pipeline.get(msgt.p)) === null || _d === void 0 ? void 0 : _d.videoFrameFromWorker) === null || _e === void 0 ? void 0 : _e.call(_d, msgt);
|
|
66
64
|
break;
|
|
67
65
|
}
|
|
68
66
|
case "imageBitmapS2C": {
|
|
69
67
|
let msgt = msg;
|
|
70
|
-
(_g = (_f =
|
|
68
|
+
(_g = (_f = Pipeline.get(msgt.p)) === null || _f === void 0 ? void 0 : _f.imageBitmapFromWorker) === null || _g === void 0 ? void 0 : _g.call(_f, msgt);
|
|
71
69
|
break;
|
|
72
70
|
}
|
|
73
71
|
case "licerr": {
|
|
@@ -97,7 +95,7 @@ function initialize() {
|
|
|
97
95
|
}
|
|
98
96
|
case "gfx": {
|
|
99
97
|
let div = document.createElement("div");
|
|
100
|
-
div.innerHTML =
|
|
98
|
+
div.innerHTML = gfx;
|
|
101
99
|
div.style.position = "absolute";
|
|
102
100
|
div.style.bottom = "20px";
|
|
103
101
|
div.style.width = "250px";
|
|
@@ -119,40 +117,40 @@ function initialize() {
|
|
|
119
117
|
}
|
|
120
118
|
}
|
|
121
119
|
});
|
|
122
|
-
client = Object.assign(Object.assign({}, c.impl), { loaded: () => loaded, camera_default_device_id: userFacing => userFacing ?
|
|
120
|
+
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) => {
|
|
123
121
|
var _a;
|
|
124
|
-
(_a =
|
|
122
|
+
(_a = Pipeline.get(pipeline)) === null || _a === void 0 ? void 0 : _a.cameraFrameDrawGL(screenWidth, screenHeight, mirror);
|
|
125
123
|
}, draw_plane: (gl, projectionMatrix, cameraMatrix, targetMatrix, texture) => {
|
|
126
|
-
|
|
124
|
+
drawPlane(gl, projectionMatrix, cameraMatrix, targetMatrix, texture);
|
|
127
125
|
}, pipeline_draw_face: (p, projectionMatrix, cameraMatrix, targetMatrix, o) => {
|
|
128
126
|
var _a;
|
|
129
|
-
let obj =
|
|
127
|
+
let obj = getFaceMesh(o);
|
|
130
128
|
if (!obj) {
|
|
131
|
-
|
|
129
|
+
zcwarn("attempting to call draw_face on a destroyed zappar_face_mesh_t");
|
|
132
130
|
return new Uint16Array();
|
|
133
131
|
}
|
|
134
|
-
(_a =
|
|
132
|
+
(_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.drawFace(projectionMatrix, cameraMatrix, targetMatrix, obj);
|
|
135
133
|
}, pipeline_draw_face_project: (p, matrix, vertices, uvMatrix, uvs, indices, texture) => {
|
|
136
134
|
var _a;
|
|
137
|
-
(_a =
|
|
138
|
-
}, projection_matrix_from_camera_model:
|
|
139
|
-
let res =
|
|
135
|
+
(_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.drawFaceProject(matrix, vertices, uvMatrix, uvs, indices, texture);
|
|
136
|
+
}, 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) => {
|
|
137
|
+
let res = applyScreenCounterRotation(undefined, c.impl.instant_world_tracker_anchor_pose_raw(o));
|
|
140
138
|
if (mirror) {
|
|
141
|
-
let scale =
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
let scale = mat4.create();
|
|
140
|
+
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
141
|
+
mat4.multiply(res, scale, res);
|
|
142
|
+
mat4.multiply(res, res, scale);
|
|
145
143
|
}
|
|
146
144
|
return res;
|
|
147
145
|
}, instant_world_tracker_anchor_pose: (o, cameraPose, mirror) => {
|
|
148
|
-
let res =
|
|
146
|
+
let res = applyScreenCounterRotation(undefined, c.impl.instant_world_tracker_anchor_pose_raw(o));
|
|
149
147
|
if (mirror) {
|
|
150
|
-
let scale =
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
let scale = mat4.create();
|
|
149
|
+
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
150
|
+
mat4.multiply(res, scale, res);
|
|
151
|
+
mat4.multiply(res, res, scale);
|
|
154
152
|
}
|
|
155
|
-
|
|
153
|
+
mat4.multiply(res, cameraPose, res);
|
|
156
154
|
return res;
|
|
157
155
|
}, instant_world_tracker_anchor_pose_set_from_camera_offset: (o, x, y, z, orientation) => {
|
|
158
156
|
// TODO - add an _ext function if we need to support mirrored cameras with an extra param
|
|
@@ -161,197 +159,261 @@ function initialize() {
|
|
|
161
159
|
// }
|
|
162
160
|
// TODO - can we access the appropriate pipeline here to call pipeline_camera_frame_user_facing(p)?
|
|
163
161
|
let userFacing = false;
|
|
164
|
-
let rotation =
|
|
165
|
-
let rotationMat =
|
|
166
|
-
|
|
167
|
-
let rawVec =
|
|
168
|
-
|
|
162
|
+
let rotation = cameraRotationForScreenOrientation(userFacing) * Math.PI / 180.0;
|
|
163
|
+
let rotationMat = mat4.create();
|
|
164
|
+
mat4.fromRotation(rotationMat, -rotation, [0, 0, 1]);
|
|
165
|
+
let rawVec = vec3.create();
|
|
166
|
+
vec3.transformMat4(rawVec, [x, y, z], rotationMat);
|
|
169
167
|
c.impl.instant_world_tracker_anchor_pose_set_from_camera_offset_raw(o, rawVec[0], rawVec[1], rawVec[2], orientation);
|
|
168
|
+
}, image_tracker_create: pipeline => ImageTracker.create(pipeline, c.impl), image_tracker_destroy: t => { var _a; return (_a = ImageTracker.get(t)) === null || _a === void 0 ? void 0 : _a.destroy(); }, image_tracker_target_count: t => {
|
|
169
|
+
let obj = ImageTracker.get(t);
|
|
170
|
+
if (!obj) {
|
|
171
|
+
zcwarn("attempting to call image_tracker_target_count on a destroyed zappar_image_tracker_t");
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
return obj.targetCount();
|
|
175
|
+
}, image_tracker_target_load_from_memory: (t, data) => {
|
|
176
|
+
let obj = ImageTracker.get(t);
|
|
177
|
+
if (!obj) {
|
|
178
|
+
zcwarn("attempting to call image_tracker_target_load_from_memory on a destroyed zappar_image_tracker_t");
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
obj.loadFromMemory(data);
|
|
182
|
+
}, image_tracker_target_preview_compressed: (t, i) => {
|
|
183
|
+
var _a;
|
|
184
|
+
let obj = ImageTracker.get(t);
|
|
185
|
+
if (!obj) {
|
|
186
|
+
zcwarn("attempting to call image_tracker_target_preview_compressed on a destroyed zappar_image_tracker_t");
|
|
187
|
+
return new Uint8Array(0);
|
|
188
|
+
}
|
|
189
|
+
return ((_a = obj.getTargetInfo(i).preview) === null || _a === void 0 ? void 0 : _a.compressed) || new Uint8Array(0);
|
|
190
|
+
}, image_tracker_target_preview_compressed_mimetype: (t, i) => {
|
|
191
|
+
var _a;
|
|
192
|
+
let obj = ImageTracker.get(t);
|
|
193
|
+
if (!obj) {
|
|
194
|
+
zcwarn("attempting to call image_tracker_target_preview_compressed_mimetype on a destroyed zappar_image_tracker_t");
|
|
195
|
+
return "";
|
|
196
|
+
}
|
|
197
|
+
return ((_a = obj.getTargetInfo(i).preview) === null || _a === void 0 ? void 0 : _a.mimeType) || "";
|
|
198
|
+
}, image_tracker_target_preview_compressed_size: (t, i) => {
|
|
199
|
+
var _a, _b;
|
|
200
|
+
let obj = ImageTracker.get(t);
|
|
201
|
+
if (!obj) {
|
|
202
|
+
zcwarn("attempting to call image_tracker_target_preview_compressed_size on a destroyed zappar_image_tracker_t");
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
return ((_b = (_a = obj.getTargetInfo(i).preview) === null || _a === void 0 ? void 0 : _a.compressed) === null || _b === void 0 ? void 0 : _b.byteLength) || 0;
|
|
206
|
+
}, image_tracker_target_physical_scale_factor: (t, i) => {
|
|
207
|
+
let obj = ImageTracker.get(t);
|
|
208
|
+
if (!obj) {
|
|
209
|
+
zcwarn("attempting to call image_tracker_target_physical_scale_factor on a destroyed zappar_image_tracker_t");
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
return obj.getTargetInfo(i).physicalScaleFactor;
|
|
213
|
+
}, image_tracker_target_radius_top: (t, i) => {
|
|
214
|
+
let obj = ImageTracker.get(t);
|
|
215
|
+
if (!obj) {
|
|
216
|
+
zcwarn("attempting to call image_tracker_target_radius_top on a destroyed zappar_image_tracker_t");
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
return obj.getTargetInfo(i).topRadius;
|
|
220
|
+
}, image_tracker_target_radius_bottom: (t, i) => {
|
|
221
|
+
let obj = ImageTracker.get(t);
|
|
222
|
+
if (!obj) {
|
|
223
|
+
zcwarn("attempting to call image_tracker_target_radius_bottom on a destroyed zappar_image_tracker_t");
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
return obj.getTargetInfo(i).bottomRadius;
|
|
227
|
+
}, image_tracker_target_side_length: (t, i) => {
|
|
228
|
+
let obj = ImageTracker.get(t);
|
|
229
|
+
if (!obj) {
|
|
230
|
+
zcwarn("attempting to call image_tracker_target_side_length on a destroyed zappar_image_tracker_t");
|
|
231
|
+
return 0;
|
|
232
|
+
}
|
|
233
|
+
return obj.getTargetInfo(i).sideLength;
|
|
234
|
+
}, image_tracker_target_image: (t, i) => {
|
|
235
|
+
let obj = ImageTracker.get(t);
|
|
236
|
+
if (!obj) {
|
|
237
|
+
zcwarn("attempting to call image_tracker_target_image on a destroyed zappar_image_tracker_t");
|
|
238
|
+
return new Image();
|
|
239
|
+
}
|
|
240
|
+
return obj.getDecodedPreview(i);
|
|
170
241
|
}, image_tracker_anchor_pose_camera_relative: (o, indx, mirror) => {
|
|
171
|
-
let res =
|
|
242
|
+
let res = applyScreenCounterRotation(undefined, c.impl.image_tracker_anchor_pose_raw(o, indx));
|
|
172
243
|
if (mirror) {
|
|
173
|
-
let scale =
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
244
|
+
let scale = mat4.create();
|
|
245
|
+
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
246
|
+
mat4.multiply(res, scale, res);
|
|
247
|
+
mat4.multiply(res, res, scale);
|
|
177
248
|
}
|
|
178
249
|
return res;
|
|
179
250
|
}, image_tracker_anchor_pose: (o, indx, cameraPose, mirror) => {
|
|
180
|
-
let res =
|
|
251
|
+
let res = applyScreenCounterRotation(undefined, c.impl.image_tracker_anchor_pose_raw(o, indx));
|
|
181
252
|
if (mirror) {
|
|
182
|
-
let scale =
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
253
|
+
let scale = mat4.create();
|
|
254
|
+
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
255
|
+
mat4.multiply(res, scale, res);
|
|
256
|
+
mat4.multiply(res, res, scale);
|
|
186
257
|
}
|
|
187
|
-
|
|
258
|
+
mat4.multiply(res, cameraPose, res);
|
|
188
259
|
return res;
|
|
189
260
|
}, face_tracker_anchor_pose_camera_relative: (o, indx, mirror) => {
|
|
190
|
-
let res =
|
|
261
|
+
let res = applyScreenCounterRotation(undefined, c.impl.face_tracker_anchor_pose_raw(o, indx));
|
|
191
262
|
if (mirror) {
|
|
192
|
-
let scale =
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
263
|
+
let scale = mat4.create();
|
|
264
|
+
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
265
|
+
mat4.multiply(res, scale, res);
|
|
266
|
+
mat4.multiply(res, res, scale);
|
|
196
267
|
}
|
|
197
268
|
return res;
|
|
198
269
|
}, face_tracker_anchor_pose: (o, indx, cameraPose, mirror) => {
|
|
199
|
-
let res =
|
|
270
|
+
let res = applyScreenCounterRotation(undefined, c.impl.face_tracker_anchor_pose_raw(o, indx));
|
|
200
271
|
if (mirror) {
|
|
201
|
-
let scale =
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
272
|
+
let scale = mat4.create();
|
|
273
|
+
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
274
|
+
mat4.multiply(res, scale, res);
|
|
275
|
+
mat4.multiply(res, res, scale);
|
|
205
276
|
}
|
|
206
|
-
|
|
277
|
+
mat4.multiply(res, cameraPose, res);
|
|
207
278
|
return res;
|
|
208
279
|
}, face_tracker_model_load_default: (o) => __awaiter(this, void 0, void 0, function* () {
|
|
209
280
|
yield loadDefaultFaceModel(o);
|
|
210
281
|
}), face_mesh_create: () => {
|
|
211
|
-
return
|
|
282
|
+
return createFaceMesh();
|
|
212
283
|
}, face_mesh_destroy: (m) => {
|
|
213
|
-
|
|
284
|
+
destroyFaceMesh(m);
|
|
214
285
|
}, face_mesh_indices: (m) => {
|
|
215
|
-
let obj =
|
|
286
|
+
let obj = getFaceMesh(m);
|
|
216
287
|
if (!obj) {
|
|
217
|
-
|
|
288
|
+
zcwarn("attempting to call face_mesh_indices on a destroyed zappar_face_mesh_t");
|
|
218
289
|
return new Uint16Array();
|
|
219
290
|
}
|
|
220
291
|
return obj.getIndices();
|
|
221
292
|
}, face_mesh_indices_size: (m) => {
|
|
222
|
-
let obj =
|
|
293
|
+
let obj = getFaceMesh(m);
|
|
223
294
|
if (!obj) {
|
|
224
|
-
|
|
295
|
+
zcwarn("attempting to call face_mesh_indices_size on a destroyed zappar_face_mesh_t");
|
|
225
296
|
return 0;
|
|
226
297
|
}
|
|
227
298
|
return obj.getIndices().length;
|
|
228
299
|
}, face_mesh_uvs: (m) => {
|
|
229
|
-
let obj =
|
|
300
|
+
let obj = getFaceMesh(m);
|
|
230
301
|
if (!obj) {
|
|
231
|
-
|
|
302
|
+
zcwarn("attempting to call face_mesh_uvs on a destroyed zappar_face_mesh_t");
|
|
232
303
|
return new Float32Array();
|
|
233
304
|
}
|
|
234
305
|
return obj.getUVs();
|
|
235
306
|
}, face_mesh_uvs_size: (m) => {
|
|
236
|
-
let obj =
|
|
307
|
+
let obj = getFaceMesh(m);
|
|
237
308
|
if (!obj) {
|
|
238
|
-
|
|
309
|
+
zcwarn("attempting to call face_mesh_uvs_size on a destroyed zappar_face_mesh_t");
|
|
239
310
|
return 0;
|
|
240
311
|
}
|
|
241
312
|
return obj.getUVs().length;
|
|
242
313
|
}, face_mesh_vertices: (m) => {
|
|
243
|
-
let obj =
|
|
314
|
+
let obj = getFaceMesh(m);
|
|
244
315
|
if (!obj) {
|
|
245
|
-
|
|
316
|
+
zcwarn("attempting to call face_mesh_vertices on a destroyed zappar_face_mesh_t");
|
|
246
317
|
return new Float32Array();
|
|
247
318
|
}
|
|
248
319
|
return obj.getVertices();
|
|
249
320
|
}, face_mesh_vertices_size: (m) => {
|
|
250
|
-
let obj =
|
|
321
|
+
let obj = getFaceMesh(m);
|
|
251
322
|
if (!obj) {
|
|
252
|
-
|
|
323
|
+
zcwarn("attempting to call face_mesh_vertices_size on a destroyed zappar_face_mesh_t");
|
|
253
324
|
return 0;
|
|
254
325
|
}
|
|
255
326
|
return obj.getVertices().length;
|
|
256
327
|
}, face_mesh_normals: (m) => {
|
|
257
|
-
let obj =
|
|
328
|
+
let obj = getFaceMesh(m);
|
|
258
329
|
if (!obj) {
|
|
259
|
-
|
|
330
|
+
zcwarn("attempting to call face_mesh_normals on a destroyed zappar_face_mesh_t");
|
|
260
331
|
return new Float32Array();
|
|
261
332
|
}
|
|
262
333
|
return obj.getNormals();
|
|
263
334
|
}, face_mesh_normals_size: (m) => {
|
|
264
|
-
let obj =
|
|
335
|
+
let obj = getFaceMesh(m);
|
|
265
336
|
if (!obj) {
|
|
266
|
-
|
|
337
|
+
zcwarn("attempting to call face_mesh_normals_size on a destroyed zappar_face_mesh_t");
|
|
267
338
|
return 0;
|
|
268
339
|
}
|
|
269
340
|
return obj.getNormals().length;
|
|
270
341
|
}, face_mesh_load_from_memory: (m, ab, fillMouth, fillEyeL, fillEyeR, fillNeck) => {
|
|
271
|
-
let obj =
|
|
342
|
+
let obj = getFaceMesh(m);
|
|
272
343
|
if (!obj) {
|
|
273
|
-
|
|
344
|
+
zcwarn("attempting to call face_mesh_load_from_memory on a destroyed zappar_face_mesh_t");
|
|
274
345
|
return;
|
|
275
346
|
}
|
|
276
347
|
obj.loadFromMemory(ab, fillMouth, fillEyeL, fillEyeR, fillNeck);
|
|
277
348
|
}, face_mesh_update: (m, identity, expression, mirrored) => {
|
|
278
|
-
let obj =
|
|
349
|
+
let obj = getFaceMesh(m);
|
|
279
350
|
if (!obj) {
|
|
280
|
-
|
|
351
|
+
zcwarn("attempting to call face_mesh_update on a destroyed zappar_face_mesh_t");
|
|
281
352
|
return;
|
|
282
353
|
}
|
|
283
354
|
obj.update(identity, expression, mirrored);
|
|
284
355
|
}, face_mesh_load_default: (m) => __awaiter(this, void 0, void 0, function* () {
|
|
285
|
-
let obj =
|
|
356
|
+
let obj = getFaceMesh(m);
|
|
286
357
|
if (!obj) {
|
|
287
|
-
|
|
358
|
+
zcwarn("attempting to call face_mesh_load_default on a destroyed zappar_face_mesh_t");
|
|
288
359
|
return;
|
|
289
360
|
}
|
|
290
|
-
let url =
|
|
291
|
-
|
|
292
|
-
url = url.default;
|
|
293
|
-
let req = yield fetch(url);
|
|
361
|
+
let url = new URL("./face_mesh_face_model.zbin", import.meta.url);
|
|
362
|
+
let req = yield fetch(url.toString());
|
|
294
363
|
obj.loadFromMemory(yield req.arrayBuffer(), false, false, false, false);
|
|
295
364
|
}), face_mesh_load_default_face: (m, fillMouth, fillEyeL, fillEyeR) => __awaiter(this, void 0, void 0, function* () {
|
|
296
|
-
let obj =
|
|
365
|
+
let obj = getFaceMesh(m);
|
|
297
366
|
if (!obj) {
|
|
298
|
-
|
|
367
|
+
zcwarn("attempting to call face_mesh_load_default_face on a destroyed zappar_face_mesh_t");
|
|
299
368
|
return;
|
|
300
369
|
}
|
|
301
|
-
let url =
|
|
302
|
-
|
|
303
|
-
url = url.default;
|
|
304
|
-
let req = yield fetch(url);
|
|
370
|
+
let url = new URL("./face_mesh_face_model.zbin", import.meta.url);
|
|
371
|
+
let req = yield fetch(url.toString());
|
|
305
372
|
obj.loadFromMemory(yield req.arrayBuffer(), fillMouth, fillEyeL, fillEyeR, false);
|
|
306
373
|
}), face_mesh_load_default_full_head_simplified: (m, fillMouth, fillEyeL, fillEyeR, fillNeck) => __awaiter(this, void 0, void 0, function* () {
|
|
307
|
-
let obj =
|
|
374
|
+
let obj = getFaceMesh(m);
|
|
308
375
|
if (!obj) {
|
|
309
|
-
|
|
376
|
+
zcwarn("attempting to call face_mesh_load_default_full_head_simplified on a destroyed zappar_face_mesh_t");
|
|
310
377
|
return;
|
|
311
378
|
}
|
|
312
|
-
let url =
|
|
313
|
-
|
|
314
|
-
url = url.default;
|
|
315
|
-
let req = yield fetch(url);
|
|
379
|
+
let url = new URL("./face_mesh_full_head_simplified_model.zbin", import.meta.url);
|
|
380
|
+
let req = yield fetch(url.toString());
|
|
316
381
|
obj.loadFromMemory(yield req.arrayBuffer(), fillMouth, fillEyeL, fillEyeR, fillNeck);
|
|
317
382
|
}), face_mesh_loaded_version: (m) => {
|
|
318
|
-
let obj =
|
|
383
|
+
let obj = getFaceMesh(m);
|
|
319
384
|
if (!obj) {
|
|
320
|
-
|
|
385
|
+
zcwarn("attempting to call face_mesh_load_default on a destroyed zappar_face_mesh_t");
|
|
321
386
|
return -1;
|
|
322
387
|
}
|
|
323
388
|
return obj.getModelVersion();
|
|
324
389
|
}, face_landmark_create: (n) => {
|
|
325
|
-
return
|
|
390
|
+
return createFaceLandmark(n);
|
|
326
391
|
}, face_landmark_destroy: (m) => {
|
|
327
|
-
|
|
392
|
+
destroyFaceLandmark(m);
|
|
328
393
|
}, face_landmark_update: (m, identity, expression, mirrored) => {
|
|
329
|
-
let obj =
|
|
394
|
+
let obj = getFaceLandmark(m);
|
|
330
395
|
if (!obj) {
|
|
331
|
-
|
|
396
|
+
zcwarn("attempting to call face_landmark_update on a destroyed zappar_face_landmark_t");
|
|
332
397
|
return;
|
|
333
398
|
}
|
|
334
399
|
obj.update(identity, expression, mirrored);
|
|
335
400
|
}, face_landmark_anchor_pose: (m) => {
|
|
336
|
-
let obj =
|
|
401
|
+
let obj = getFaceLandmark(m);
|
|
337
402
|
if (!obj) {
|
|
338
|
-
|
|
339
|
-
return
|
|
403
|
+
zcwarn("attempting to call face_landmark_anchor_pose on a destroyed zappar_face_landmark_t");
|
|
404
|
+
return mat4.create();
|
|
340
405
|
}
|
|
341
406
|
return obj.anchor_pose;
|
|
342
|
-
}, html_element_source_create: (pipeline, elm) =>
|
|
343
|
-
|
|
407
|
+
}, html_element_source_create: (pipeline, elm) => HTMLElementSource.createVideoElementSource(pipeline, elm), html_element_source_start: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.start(); }, html_element_source_pause: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, html_element_source_destroy: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, sequence_source_create: p => SequenceSource.create(p), sequence_source_load_from_memory: (o, data) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.loadFromMemory(data); }, sequence_source_pause: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, sequence_source_start: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.start(); }, sequence_source_max_playback_fps_set: (o, fps) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.maxPlaybackFpsSet(fps); }, sequence_source_time_set: (o, t) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.setTime(t); }, sequence_source_destroy: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, permission_granted_all: permissionGrantedAll, permission_granted_camera: permissionGrantedCamera, permission_granted_motion: permissionGrantedMotion, permission_denied_any: permissionDeniedAny, permission_denied_camera: permissionDeniedCamera, permission_denied_motion: permissionDeniedMotion, permission_request_motion: permissionRequestMotion, permission_request_camera: permissionRequestCamera, permission_request_all: permissionRequestAll, permission_request_ui: permissionRequestUI, permission_request_ui_promise: permissionRequestUI, permission_denied_ui: permissionDeniedUI, browser_incompatible: compatibility.incompatible, browser_incompatible_ui: compatibility.incompatible_ui, log_level_set: l => {
|
|
408
|
+
setLogLevel(l);
|
|
344
409
|
c.impl.log_level_set(l);
|
|
345
410
|
} });
|
|
346
411
|
return client;
|
|
347
412
|
}
|
|
348
|
-
exports.initialize = initialize;
|
|
349
413
|
function loadDefaultFaceModel(o) {
|
|
350
414
|
return __awaiter(this, void 0, void 0, function* () {
|
|
351
|
-
let url =
|
|
352
|
-
|
|
353
|
-
url = url.default;
|
|
354
|
-
let data = yield fetch(url);
|
|
415
|
+
let url = new URL("./face_tracking_model.zbin", import.meta.url);
|
|
416
|
+
let data = yield fetch(url.toString());
|
|
355
417
|
let ab = yield data.arrayBuffer();
|
|
356
418
|
client === null || client === void 0 ? void 0 : client.face_tracker_model_load_from_memory(o, ab);
|
|
357
419
|
});
|
package/lib/options.d.ts
ADDED
package/lib/options.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/permission.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,10 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const ua_parser_js_1 = require("ua-parser-js");
|
|
14
|
-
let parser = new ua_parser_js_1.UAParser();
|
|
10
|
+
import { UAParser } from "ua-parser-js";
|
|
11
|
+
let parser = new UAParser();
|
|
15
12
|
let _permissionGrantedCamera = false;
|
|
16
13
|
let _permissionGrantedMotion = false;
|
|
17
14
|
let _permissionDeniedCamera = false;
|
|
@@ -32,26 +29,19 @@ function checkForCameraPermission() {
|
|
|
32
29
|
});
|
|
33
30
|
}
|
|
34
31
|
checkForCameraPermission();
|
|
35
|
-
function permissionGrantedCamera() { return _permissionGrantedCamera; }
|
|
36
|
-
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
function
|
|
42
|
-
exports.permissionDeniedMotion = permissionDeniedMotion;
|
|
43
|
-
function permissionDeniedAny() { return _permissionDeniedCamera || _permissionDeniedMotion; }
|
|
44
|
-
exports.permissionDeniedAny = permissionDeniedAny;
|
|
45
|
-
function permissionGrantedAll() { return _permissionGrantedCamera && _permissionGrantedMotion; }
|
|
46
|
-
exports.permissionGrantedAll = permissionGrantedAll;
|
|
47
|
-
function permissionRequestAll() {
|
|
32
|
+
export function permissionGrantedCamera() { return _permissionGrantedCamera; }
|
|
33
|
+
export function permissionGrantedMotion() { return _permissionGrantedMotion; }
|
|
34
|
+
export function permissionDeniedCamera() { return _permissionDeniedCamera; }
|
|
35
|
+
export function permissionDeniedMotion() { return _permissionDeniedMotion; }
|
|
36
|
+
export function permissionDeniedAny() { return _permissionDeniedCamera || _permissionDeniedMotion; }
|
|
37
|
+
export function permissionGrantedAll() { return _permissionGrantedCamera && _permissionGrantedMotion; }
|
|
38
|
+
export function permissionRequestAll() {
|
|
48
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
40
|
yield permissionRequestMotion();
|
|
50
41
|
yield permissionRequestCamera();
|
|
51
42
|
});
|
|
52
43
|
}
|
|
53
|
-
|
|
54
|
-
function permissionRequestCamera() {
|
|
44
|
+
export function permissionRequestCamera() {
|
|
55
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
46
|
try {
|
|
57
47
|
let res = yield navigator.mediaDevices.getUserMedia({
|
|
@@ -68,8 +58,7 @@ function permissionRequestCamera() {
|
|
|
68
58
|
}
|
|
69
59
|
});
|
|
70
60
|
}
|
|
71
|
-
|
|
72
|
-
function permissionRequestMotion() {
|
|
61
|
+
export function permissionRequestMotion() {
|
|
73
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
63
|
if (window.DeviceOrientationEvent && window.DeviceOrientationEvent.requestPermission) {
|
|
75
64
|
let permissionResult = yield window.DeviceOrientationEvent.requestPermission();
|
|
@@ -84,8 +73,7 @@ function permissionRequestMotion() {
|
|
|
84
73
|
_permissionDeniedMotion = false;
|
|
85
74
|
});
|
|
86
75
|
}
|
|
87
|
-
|
|
88
|
-
function permissionRequestUI() {
|
|
76
|
+
export function permissionRequestUI() {
|
|
89
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
78
|
yield checkForCameraPermission();
|
|
91
79
|
if (permissionGrantedAll()) {
|
|
@@ -158,11 +146,10 @@ function permissionRequestUI() {
|
|
|
158
146
|
});
|
|
159
147
|
});
|
|
160
148
|
}
|
|
161
|
-
exports.permissionRequestUI = permissionRequestUI;
|
|
162
149
|
function nextFrame() {
|
|
163
150
|
return new Promise(resolve => requestAnimationFrame(() => resolve()));
|
|
164
151
|
}
|
|
165
|
-
function permissionDeniedUI() {
|
|
152
|
+
export function permissionDeniedUI() {
|
|
166
153
|
switch (parser.getBrowser().name) {
|
|
167
154
|
case "Chrome":
|
|
168
155
|
permissionDeniedUIChrome();
|
|
@@ -172,7 +159,6 @@ function permissionDeniedUI() {
|
|
|
172
159
|
break;
|
|
173
160
|
}
|
|
174
161
|
}
|
|
175
|
-
exports.permissionDeniedUI = permissionDeniedUI;
|
|
176
162
|
function permissionDeniedUIIOS() {
|
|
177
163
|
let div = document.createElement("div");
|
|
178
164
|
div.classList.add("zappar-permission-request");
|