@zappar/zappar-cv 3.0.1-beta.0 → 3.0.1-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/README.md +2 -2
- package/lib/additional.d.ts +14 -3
- package/lib/cameramodel.d.ts +1 -1
- package/lib/cameramodel.js +3 -3
- package/lib/drawpointswithtype.d.ts +1 -1
- package/lib/drawpointswithtype.js +11 -13
- package/lib/gen/zappar-bridge.d.ts +5 -2
- package/lib/gen/zappar-client.js +103 -55
- package/lib/gen/zappar-cwrap.js +37 -26
- package/lib/gen/zappar-native.d.ts +5 -4
- package/lib/gen/zappar-server.js +63 -43
- package/lib/gen/zappar.d.ts +7 -4
- package/lib/native.js +226 -31
- package/lib/permission.d.ts +3 -2
- package/lib/permission.js +18 -15
- package/lib/tracing/jsontracer.d.ts +14 -0
- package/lib/tracing/jsontracer.js +37 -0
- package/lib/tracing/performancetracer.d.ts +11 -0
- package/lib/tracing/performancetracer.js +17 -0
- package/lib/tracing/sharedtracer.d.ts +2 -0
- package/lib/tracing/sharedtracer.js +8 -0
- package/lib/tracing/usertimingtracer.d.ts +10 -0
- package/lib/tracing/usertimingtracer.js +30 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/worker-server.js +2 -2
- package/lib/zappar-cv.js +1 -1
- package/lib/zappar-cv.wasm +0 -0
- package/package.json +3 -1
- package/umd/751.zappar-cv.js +1 -1
- package/umd/867.zappar-cv.js +1 -1
- package/umd/{c8e05439176ea756192a.wasm → abae5a71374067ca08fc.wasm} +0 -0
- package/umd/zappar-cv.js +1 -1
- package/umd/zappar-cv.worker.js +1 -1
package/lib/native.js
CHANGED
|
@@ -7,10 +7,10 @@ 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 { image_target_type_t } from "./gen/zappar";
|
|
10
|
+
import { transform_orientation_t, image_target_type_t, anchor_status_t } from "./gen/zappar";
|
|
11
11
|
import { zappar_client } from "./gen/zappar-client";
|
|
12
12
|
import { drawPlane } from "./drawplane";
|
|
13
|
-
import { cameraRotationForScreenOrientation,
|
|
13
|
+
import { cameraRotationForScreenOrientation, projectionMatrixFromModelAndSize } from "./cameramodel";
|
|
14
14
|
import { mat4, vec3 } from "gl-matrix";
|
|
15
15
|
import { launchCeresWorker, launchWorker, messageManager } from "./worker-client";
|
|
16
16
|
import { permissionRequestUI, permissionGrantedAll, permissionGrantedCamera, permissionGrantedMotion, permissionDeniedAny, permissionDeniedCamera, permissionDeniedMotion, permissionRequestMotion, permissionRequestCamera, permissionRequestAll, permissionDeniedUI } from "./permission";
|
|
@@ -31,6 +31,8 @@ import { getPointsDataMatrix } from "./drawpoints";
|
|
|
31
31
|
import { drawAxis } from "./drawaxis";
|
|
32
32
|
let client;
|
|
33
33
|
const pipelineByWorldTracker = new Map();
|
|
34
|
+
const _temporaryMatrix = mat4.create();
|
|
35
|
+
const _temporaryVec3 = vec3.create();
|
|
34
36
|
export function initialize(opts) {
|
|
35
37
|
if (client)
|
|
36
38
|
return client;
|
|
@@ -150,7 +152,7 @@ export function initialize(opts) {
|
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
154
|
});
|
|
153
|
-
const
|
|
155
|
+
const customAnchors = new Map();
|
|
154
156
|
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_source_profile_set: (cam, p) => { var _a; return (_a = getCameraSource(cam)) === null || _a === void 0 ? void 0 : _a.setProfile(p); }, 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, pose_from_raw: (raw_pose, mirror) => {
|
|
155
157
|
let res = applyScreenCounterRotation(undefined, raw_pose);
|
|
156
158
|
if (mirror) {
|
|
@@ -163,14 +165,6 @@ export function initialize(opts) {
|
|
|
163
165
|
}, 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) => {
|
|
164
166
|
var _a;
|
|
165
167
|
(_a = Pipeline.get(pipeline)) === null || _a === void 0 ? void 0 : _a.cameraFrameDrawGL(screenWidth, screenHeight, mirror);
|
|
166
|
-
}, pipeline_camera_frame_data_width: (pipeline) => {
|
|
167
|
-
var _a, _b;
|
|
168
|
-
const info = (_a = Pipeline.get(pipeline)) === null || _a === void 0 ? void 0 : _a.getCurrentCameraInfo();
|
|
169
|
-
return (_b = info === null || info === void 0 ? void 0 : info.dataWidth) !== null && _b !== void 0 ? _b : 0;
|
|
170
|
-
}, pipeline_camera_frame_data_height: (pipeline) => {
|
|
171
|
-
var _a, _b;
|
|
172
|
-
const info = (_a = Pipeline.get(pipeline)) === null || _a === void 0 ? void 0 : _a.getCurrentCameraInfo();
|
|
173
|
-
return (_b = info === null || info === void 0 ? void 0 : info.dataHeight) !== null && _b !== void 0 ? _b : 0;
|
|
174
168
|
}, draw_plane: (gl, projectionMatrix, cameraMatrix, targetMatrix, texture) => {
|
|
175
169
|
drawPlane(gl, projectionMatrix, cameraMatrix, targetMatrix, texture);
|
|
176
170
|
}, draw_grid: (gl, projectionMatrix, cameraMatrix, targetMatrix) => {
|
|
@@ -196,7 +190,7 @@ export function initialize(opts) {
|
|
|
196
190
|
return;
|
|
197
191
|
}
|
|
198
192
|
(_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.drawImageTargetPreview(projectionMatrix, cameraMatrix, targetMatrix, indx, obj);
|
|
199
|
-
},
|
|
193
|
+
}, projection_matrix_from_camera_model_and_size: projectionMatrixFromModelAndSize, projection_matrix_from_camera_model_and_size_ext: projectionMatrixFromModelAndSize, 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; }, pipeline_camera_frame_data_raw: p => { var _a; return ((_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.getCameraFrameDataRaw()) || Promise.reject(); }, pipeline_camera_frame_data_raw_enabled_set: (p, v) => { var _a; return (_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.setCameraFrameDataRawEnabled(v); }, instant_world_tracker_anchor_pose_camera_relative: (o, mirror) => {
|
|
200
194
|
let res = applyScreenCounterRotation(undefined, c.impl.instant_world_tracker_anchor_pose_raw(o));
|
|
201
195
|
if (mirror) {
|
|
202
196
|
let scale = mat4.create();
|
|
@@ -228,8 +222,31 @@ export function initialize(opts) {
|
|
|
228
222
|
let rawVec = vec3.create();
|
|
229
223
|
vec3.transformMat4(rawVec, [x, y, z], rotationMat);
|
|
230
224
|
c.impl.instant_world_tracker_anchor_pose_set_from_camera_offset_raw(o, rawVec[0], rawVec[1], rawVec[2], orientation);
|
|
225
|
+
}, custom_anchor_pose_raw: (o) => {
|
|
226
|
+
const entry = customAnchors.get(o);
|
|
227
|
+
if (entry === undefined) {
|
|
228
|
+
zcwarn("attempting to call custom_anchor_pose_raw on a destroyed zappar_custom_anchor_t");
|
|
229
|
+
return mat4.create();
|
|
230
|
+
}
|
|
231
|
+
if (entry.expectedPoseVersion <= client.custom_anchor_pose_version(o))
|
|
232
|
+
return c.impl.custom_anchor_pose_raw(o);
|
|
233
|
+
const world_anchor_raw = client.world_tracker_world_anchor_pose_raw(entry.wt).slice();
|
|
234
|
+
const ret = mat4.create();
|
|
235
|
+
mat4.multiply(ret, world_anchor_raw, entry.poseRelativeToWorldAnchor);
|
|
236
|
+
return ret;
|
|
237
|
+
}, custom_anchor_status: (o) => {
|
|
238
|
+
const entry = customAnchors.get(o);
|
|
239
|
+
if (entry === undefined) {
|
|
240
|
+
zcwarn("attempting to call custom_anchor_status on a destroyed zappar_custom_anchor_t");
|
|
241
|
+
return anchor_status_t.ANCHOR_STATUS_STOPPED;
|
|
242
|
+
}
|
|
243
|
+
if (entry.expectedPoseVersion === 0)
|
|
244
|
+
return anchor_status_t.ANCHOR_STATUS_STOPPED;
|
|
245
|
+
if (entry.expectedPoseVersion <= client.custom_anchor_pose_version(o))
|
|
246
|
+
return c.impl.custom_anchor_status(o);
|
|
247
|
+
return anchor_status_t.ANCHOR_STATUS_INITIALIZING;
|
|
231
248
|
}, custom_anchor_pose_camera_relative: (o, mirror) => {
|
|
232
|
-
let res = applyScreenCounterRotation(undefined,
|
|
249
|
+
let res = applyScreenCounterRotation(undefined, client.custom_anchor_pose_raw(o));
|
|
233
250
|
if (mirror) {
|
|
234
251
|
let scale = mat4.create();
|
|
235
252
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -238,7 +255,7 @@ export function initialize(opts) {
|
|
|
238
255
|
}
|
|
239
256
|
return res;
|
|
240
257
|
}, custom_anchor_pose: (o, cameraPose, mirror) => {
|
|
241
|
-
let res = applyScreenCounterRotation(undefined,
|
|
258
|
+
let res = applyScreenCounterRotation(undefined, client.custom_anchor_pose_raw(o));
|
|
242
259
|
if (mirror) {
|
|
243
260
|
let scale = mat4.create();
|
|
244
261
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -249,23 +266,193 @@ export function initialize(opts) {
|
|
|
249
266
|
return res;
|
|
250
267
|
}, custom_anchor_create: (p, wt, id) => {
|
|
251
268
|
const ret = c.impl.custom_anchor_create(p, wt, id);
|
|
252
|
-
|
|
269
|
+
customAnchors.set(ret, { id, wt, expectedPoseVersion: 0, poseRelativeToWorldAnchor: mat4.create() });
|
|
253
270
|
return ret;
|
|
254
271
|
}, custom_anchor_id: (o) => {
|
|
255
|
-
|
|
256
|
-
|
|
272
|
+
var _a;
|
|
273
|
+
let id = (_a = customAnchors.get(o)) === null || _a === void 0 ? void 0 : _a.id;
|
|
274
|
+
if (id === undefined) {
|
|
257
275
|
zcwarn("attempting to call custom_anchor_id on a destroyed zappar_custom_anchor_t");
|
|
258
276
|
return "";
|
|
259
277
|
}
|
|
260
278
|
return id;
|
|
261
279
|
}, custom_anchor_pose_set_from_camera_offset: (o, x, y, z, orientation) => {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
280
|
+
const entry = customAnchors.get(o);
|
|
281
|
+
if (entry === undefined) {
|
|
282
|
+
zcwarn("attempting to call custom_anchor_pose_set_from_camera_offset on a destroyed zappar_custom_anchor_t");
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const pose = mat4.create();
|
|
286
|
+
// camera space -> world anchor transform
|
|
287
|
+
mat4.invert(_temporaryMatrix, client.world_tracker_world_anchor_pose_camera_relative(entry.wt, false));
|
|
288
|
+
_temporaryVec3[0] = x;
|
|
289
|
+
_temporaryVec3[1] = y;
|
|
290
|
+
_temporaryVec3[2] = z;
|
|
291
|
+
switch (orientation) {
|
|
292
|
+
// UNCHANGED and PARENT easiest in camera space
|
|
293
|
+
case transform_orientation_t.PARENT:
|
|
294
|
+
// Identity rotation in camera space
|
|
295
|
+
pose[12] = _temporaryVec3[0];
|
|
296
|
+
pose[13] = _temporaryVec3[1];
|
|
297
|
+
pose[14] = _temporaryVec3[2];
|
|
298
|
+
// Convert to world pose
|
|
299
|
+
mat4.multiply(pose, _temporaryMatrix, pose);
|
|
300
|
+
break;
|
|
301
|
+
case transform_orientation_t.UNCHANGED:
|
|
302
|
+
// Take rotation form current camera_relative pose
|
|
303
|
+
mat4.copy(pose, client.custom_anchor_pose_camera_relative(o, false));
|
|
304
|
+
pose[12] = _temporaryVec3[0];
|
|
305
|
+
pose[13] = _temporaryVec3[1];
|
|
306
|
+
pose[14] = _temporaryVec3[2];
|
|
307
|
+
// Convert to world pose
|
|
308
|
+
mat4.multiply(pose, _temporaryMatrix, pose);
|
|
309
|
+
break;
|
|
310
|
+
// WORLD and Z_TOWARDS_CAMERA easiest in world space
|
|
311
|
+
case transform_orientation_t.WORLD:
|
|
312
|
+
// Transform the position into world space
|
|
313
|
+
vec3.transformMat4(_temporaryVec3, _temporaryVec3, _temporaryMatrix);
|
|
314
|
+
// Rotation bit is already identity
|
|
315
|
+
pose[12] = _temporaryVec3[0];
|
|
316
|
+
pose[13] = _temporaryVec3[1];
|
|
317
|
+
pose[14] = _temporaryVec3[2];
|
|
318
|
+
break;
|
|
319
|
+
case transform_orientation_t.Z_TOWARDS_CAMERA:
|
|
320
|
+
// Transform the position into world space
|
|
321
|
+
vec3.transformMat4(_temporaryVec3, _temporaryVec3, _temporaryMatrix);
|
|
322
|
+
// Z in pose should be aligned with the xz plane projection of target to camera vector
|
|
323
|
+
let pose_zx = _temporaryMatrix[12] - _temporaryVec3[0];
|
|
324
|
+
let pose_zz = _temporaryMatrix[14] - _temporaryVec3[2];
|
|
325
|
+
let magn2 = pose_zx * pose_zx + pose_zz * pose_zz;
|
|
326
|
+
if (magn2 > Number.EPSILON) {
|
|
327
|
+
let scale = 1.0 / (Math.sqrt(magn2));
|
|
328
|
+
pose_zx *= scale;
|
|
329
|
+
pose_zz *= scale;
|
|
330
|
+
pose[8] = pose_zx;
|
|
331
|
+
pose[10] = pose_zz;
|
|
332
|
+
// Fill in x axis by rotation matrix properties
|
|
333
|
+
pose[0] = pose_zz;
|
|
334
|
+
pose[2] = -pose_zx;
|
|
335
|
+
}
|
|
336
|
+
// Fill in the postion
|
|
337
|
+
pose[12] = _temporaryVec3[0];
|
|
338
|
+
pose[13] = _temporaryVec3[1];
|
|
339
|
+
pose[14] = _temporaryVec3[2];
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
client.custom_anchor_pose_set(o, pose);
|
|
343
|
+
}, custom_anchor_pose_set_from_anchor_offset: (o, anchor_id, x, y, z, orientation) => {
|
|
344
|
+
const entry = customAnchors.get(o);
|
|
345
|
+
if (entry === undefined) {
|
|
346
|
+
zcwarn("attempting to call custom_anchor_pose_set_from_anchor_offset on a destroyed zappar_custom_anchor_t");
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
let anchor_pose;
|
|
350
|
+
if (anchor_id === client.world_tracker_ground_anchor_id(entry.wt)) {
|
|
351
|
+
anchor_pose = client.world_tracker_ground_anchor_pose_raw(entry.wt);
|
|
352
|
+
}
|
|
353
|
+
else if (anchor_id === client.world_tracker_world_anchor_id(entry.wt)) {
|
|
354
|
+
anchor_pose = client.world_tracker_world_anchor_pose_raw(entry.wt);
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
for (let i = 0; i < client.world_tracker_plane_anchor_count(entry.wt); i++) {
|
|
358
|
+
if (anchor_id === client.world_tracker_plane_anchor_id(entry.wt, i)) {
|
|
359
|
+
anchor_pose = client.world_tracker_plane_anchor_pose_raw(entry.wt, i);
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (!anchor_pose) {
|
|
364
|
+
for (const [anchor, details] of customAnchors.entries()) {
|
|
365
|
+
if (details.id !== anchor_id)
|
|
366
|
+
continue;
|
|
367
|
+
anchor_pose = client.custom_anchor_pose_raw(anchor);
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (!anchor_pose) {
|
|
373
|
+
zcwarn("unable for find anchor with id", anchor_id);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const pose = mat4.create();
|
|
377
|
+
// camera_raw space -> world anchor transform
|
|
378
|
+
mat4.invert(_temporaryMatrix, client.world_tracker_world_anchor_pose_raw(entry.wt));
|
|
379
|
+
// Get position offset relative to camera_raw
|
|
380
|
+
_temporaryVec3[0] = x;
|
|
381
|
+
_temporaryVec3[1] = y;
|
|
382
|
+
_temporaryVec3[2] = z;
|
|
383
|
+
vec3.transformMat4(_temporaryVec3, _temporaryVec3, anchor_pose);
|
|
384
|
+
switch (orientation) {
|
|
385
|
+
// UNCHANGED and PARENT easiest in camera_raw space
|
|
386
|
+
case transform_orientation_t.PARENT:
|
|
387
|
+
mat4.copy(pose, anchor_pose);
|
|
388
|
+
pose[12] = _temporaryVec3[0];
|
|
389
|
+
pose[13] = _temporaryVec3[1];
|
|
390
|
+
pose[14] = _temporaryVec3[2];
|
|
391
|
+
// Convert to world pose
|
|
392
|
+
mat4.multiply(pose, _temporaryMatrix, pose);
|
|
393
|
+
break;
|
|
394
|
+
case transform_orientation_t.UNCHANGED:
|
|
395
|
+
mat4.copy(pose, client.custom_anchor_pose_raw(o));
|
|
396
|
+
pose[12] = _temporaryVec3[0];
|
|
397
|
+
pose[13] = _temporaryVec3[1];
|
|
398
|
+
pose[14] = _temporaryVec3[2];
|
|
399
|
+
// Convert to world pose
|
|
400
|
+
mat4.multiply(pose, _temporaryMatrix, pose);
|
|
401
|
+
break;
|
|
402
|
+
// WORLD and Z_TOWARDS_CAMERA easiest in world space
|
|
403
|
+
case transform_orientation_t.WORLD:
|
|
404
|
+
// Transform the position into world space
|
|
405
|
+
vec3.transformMat4(_temporaryVec3, _temporaryVec3, _temporaryMatrix);
|
|
406
|
+
// Rotation bit is already identity
|
|
407
|
+
pose[12] = _temporaryVec3[0];
|
|
408
|
+
pose[13] = _temporaryVec3[1];
|
|
409
|
+
pose[14] = _temporaryVec3[2];
|
|
410
|
+
break;
|
|
411
|
+
case transform_orientation_t.Z_TOWARDS_CAMERA:
|
|
412
|
+
// Transform the position into world space
|
|
413
|
+
vec3.transformMat4(_temporaryVec3, _temporaryVec3, _temporaryMatrix);
|
|
414
|
+
// Z in pose should be aligned with the xz plane projection of target to camera vector
|
|
415
|
+
let pose_zx = _temporaryMatrix[12] - _temporaryVec3[0];
|
|
416
|
+
let pose_zz = _temporaryMatrix[14] - _temporaryVec3[2];
|
|
417
|
+
let magn2 = pose_zx * pose_zx + pose_zz * pose_zz;
|
|
418
|
+
if (magn2 > Number.EPSILON) {
|
|
419
|
+
let scale = 1.0 / (Math.sqrt(magn2));
|
|
420
|
+
pose_zx *= scale;
|
|
421
|
+
pose_zz *= scale;
|
|
422
|
+
pose[8] = pose_zx;
|
|
423
|
+
pose[10] = pose_zz;
|
|
424
|
+
// Fill in x axis by rotation matrix properties
|
|
425
|
+
pose[0] = pose_zz;
|
|
426
|
+
pose[2] = -pose_zx;
|
|
427
|
+
}
|
|
428
|
+
// Fill in the postion
|
|
429
|
+
pose[12] = _temporaryVec3[0];
|
|
430
|
+
pose[13] = _temporaryVec3[1];
|
|
431
|
+
pose[14] = _temporaryVec3[2];
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
client.custom_anchor_pose_set_with_parent(o, pose, anchor_id);
|
|
435
|
+
}, custom_anchor_pose_set: (o, pose) => {
|
|
436
|
+
const entry = customAnchors.get(o);
|
|
437
|
+
if (entry === undefined) {
|
|
438
|
+
zcwarn("attempting to call custom_anchor_pose_set on a destroyed zappar_custom_anchor_t");
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
entry.expectedPoseVersion++;
|
|
442
|
+
mat4.copy(entry.poseRelativeToWorldAnchor, pose);
|
|
443
|
+
c.impl.custom_anchor_pose_set(o, pose);
|
|
444
|
+
}, custom_anchor_pose_set_with_parent: (o, pose, anchor_id) => {
|
|
445
|
+
const entry = customAnchors.get(o);
|
|
446
|
+
if (entry === undefined) {
|
|
447
|
+
zcwarn("attempting to call custom_anchor_pose_set_with_parent on a destroyed zappar_custom_anchor_t");
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
entry.expectedPoseVersion++;
|
|
451
|
+
mat4.copy(entry.poseRelativeToWorldAnchor, pose);
|
|
452
|
+
c.impl.custom_anchor_pose_set_with_parent(o, pose, anchor_id);
|
|
453
|
+
}, custom_anchor_destroy: (o) => {
|
|
454
|
+
customAnchors.delete(o);
|
|
455
|
+
c.impl.custom_anchor_destroy(o);
|
|
269
456
|
}, 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_type: (t, i) => {
|
|
270
457
|
let obj = ImageTracker.get(t);
|
|
271
458
|
if (!obj) {
|
|
@@ -591,13 +778,21 @@ export function initialize(opts) {
|
|
|
591
778
|
const ret = c.impl.world_tracker_create(pipeline);
|
|
592
779
|
pipelineByWorldTracker.set(ret, pipeline);
|
|
593
780
|
return ret;
|
|
781
|
+
}, world_tracker_reset: (wt) => {
|
|
782
|
+
for (const entry of customAnchors.values()) {
|
|
783
|
+
if (entry.wt === wt) {
|
|
784
|
+
mat4.identity(entry.poseRelativeToWorldAnchor);
|
|
785
|
+
entry.expectedPoseVersion = 0;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
c.impl.world_tracker_reset(wt);
|
|
594
789
|
}, world_tracker_points_data_matrix: (wt, screenWidth, screenHeight, mirror) => {
|
|
595
790
|
const pipeline = pipelineByWorldTracker.get(wt);
|
|
596
791
|
if (pipeline === undefined || !client)
|
|
597
792
|
return mat4.create();
|
|
598
|
-
return getPointsDataMatrix(client.
|
|
793
|
+
return getPointsDataMatrix(client.pipeline_camera_data_width(pipeline), client.pipeline_camera_data_height(pipeline), screenWidth, screenHeight, mirror);
|
|
599
794
|
}, world_tracker_plane_anchor_pose_camera_relative: (o, indx, mirror) => {
|
|
600
|
-
let res = applyScreenCounterRotation(undefined,
|
|
795
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_plane_anchor_pose_raw(o, indx));
|
|
601
796
|
if (mirror) {
|
|
602
797
|
let scale = mat4.create();
|
|
603
798
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -606,7 +801,7 @@ export function initialize(opts) {
|
|
|
606
801
|
}
|
|
607
802
|
return res;
|
|
608
803
|
}, world_tracker_plane_anchor_pose: (o, indx, cameraPose, mirror) => {
|
|
609
|
-
let res = applyScreenCounterRotation(undefined,
|
|
804
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_plane_anchor_pose_raw(o, indx));
|
|
610
805
|
if (mirror) {
|
|
611
806
|
let scale = mat4.create();
|
|
612
807
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -616,7 +811,7 @@ export function initialize(opts) {
|
|
|
616
811
|
mat4.multiply(res, cameraPose, res);
|
|
617
812
|
return res;
|
|
618
813
|
}, world_tracker_world_anchor_pose: (o, cameraPose, mirror) => {
|
|
619
|
-
let res = applyScreenCounterRotation(undefined,
|
|
814
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_world_anchor_pose_raw(o));
|
|
620
815
|
if (mirror) {
|
|
621
816
|
let scale = mat4.create();
|
|
622
817
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -626,7 +821,7 @@ export function initialize(opts) {
|
|
|
626
821
|
mat4.multiply(res, cameraPose, res);
|
|
627
822
|
return res;
|
|
628
823
|
}, world_tracker_world_anchor_pose_camera_relative: (o, mirror) => {
|
|
629
|
-
let res = applyScreenCounterRotation(undefined,
|
|
824
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_world_anchor_pose_raw(o));
|
|
630
825
|
if (mirror) {
|
|
631
826
|
let scale = mat4.create();
|
|
632
827
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -635,7 +830,7 @@ export function initialize(opts) {
|
|
|
635
830
|
}
|
|
636
831
|
return res;
|
|
637
832
|
}, world_tracker_ground_anchor_pose: (o, cameraPose, mirror) => {
|
|
638
|
-
let res = applyScreenCounterRotation(undefined,
|
|
833
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_ground_anchor_pose_raw(o));
|
|
639
834
|
if (mirror) {
|
|
640
835
|
let scale = mat4.create();
|
|
641
836
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -645,7 +840,7 @@ export function initialize(opts) {
|
|
|
645
840
|
mat4.multiply(res, cameraPose, res);
|
|
646
841
|
return res;
|
|
647
842
|
}, world_tracker_ground_anchor_pose_camera_relative: (o, mirror) => {
|
|
648
|
-
let res = applyScreenCounterRotation(undefined,
|
|
843
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_ground_anchor_pose_raw(o));
|
|
649
844
|
if (mirror) {
|
|
650
845
|
let scale = mat4.create();
|
|
651
846
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
package/lib/permission.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PermissionDeniedUIOptions, PermissionRequestUIOptions } from "./additional";
|
|
1
2
|
export declare function permissionGrantedCamera(): boolean;
|
|
2
3
|
export declare function permissionGrantedMotion(): boolean;
|
|
3
4
|
export declare function permissionDeniedCamera(): boolean;
|
|
@@ -7,5 +8,5 @@ export declare function permissionGrantedAll(): boolean;
|
|
|
7
8
|
export declare function permissionRequestAll(): Promise<void>;
|
|
8
9
|
export declare function permissionRequestCamera(): Promise<void>;
|
|
9
10
|
export declare function permissionRequestMotion(): Promise<false | undefined>;
|
|
10
|
-
export declare function permissionRequestUI(): Promise<boolean>;
|
|
11
|
-
export declare function permissionDeniedUI(): void;
|
|
11
|
+
export declare function permissionRequestUI(options?: PermissionRequestUIOptions): Promise<boolean>;
|
|
12
|
+
export declare function permissionDeniedUI(options?: PermissionDeniedUIOptions): void;
|
package/lib/permission.js
CHANGED
|
@@ -74,7 +74,8 @@ export function permissionRequestMotion() {
|
|
|
74
74
|
_permissionDeniedMotion = false;
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
export function permissionRequestUI() {
|
|
77
|
+
export function permissionRequestUI(options) {
|
|
78
|
+
var _a, _b, _c;
|
|
78
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
80
|
yield checkForCameraPermission();
|
|
80
81
|
if (permissionGrantedAll()) {
|
|
@@ -136,9 +137,9 @@ export function permissionRequestUI() {
|
|
|
136
137
|
}
|
|
137
138
|
</style>
|
|
138
139
|
<div class="zappar-inner">
|
|
139
|
-
<div class="zappar-title">${tr(STRINGS.PermissionTitle)}</div>
|
|
140
|
-
<div class="zappar-text">${tr(STRINGS.PermissionDescription)}</div>
|
|
141
|
-
<button id="zappar-permission-request-button">${tr(STRINGS.PermissionButton)}</button>
|
|
140
|
+
<div class="zappar-title">${(_a = options === null || options === void 0 ? void 0 : options.title) !== null && _a !== void 0 ? _a : tr(STRINGS.PermissionTitle)}</div>
|
|
141
|
+
<div class="zappar-text">${(_b = options === null || options === void 0 ? void 0 : options.description) !== null && _b !== void 0 ? _b : tr(STRINGS.PermissionDescription)}</div>
|
|
142
|
+
<button id="zappar-permission-request-button">${(_c = options === null || options === void 0 ? void 0 : options.button) !== null && _c !== void 0 ? _c : tr(STRINGS.PermissionButton)}</button>
|
|
142
143
|
</div>
|
|
143
144
|
`;
|
|
144
145
|
document.body.append(div);
|
|
@@ -176,17 +177,18 @@ export function permissionRequestUI() {
|
|
|
176
177
|
function nextFrame() {
|
|
177
178
|
return new Promise(resolve => requestAnimationFrame(() => resolve()));
|
|
178
179
|
}
|
|
179
|
-
export function permissionDeniedUI() {
|
|
180
|
+
export function permissionDeniedUI(options) {
|
|
180
181
|
switch (parser.getBrowser().name) {
|
|
181
182
|
case "Chrome":
|
|
182
|
-
permissionDeniedUIChrome();
|
|
183
|
+
permissionDeniedUIChrome(options);
|
|
183
184
|
break;
|
|
184
185
|
default:
|
|
185
|
-
permissionDeniedUIIOS();
|
|
186
|
+
permissionDeniedUIIOS(options);
|
|
186
187
|
break;
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
|
-
function permissionDeniedUIIOS() {
|
|
190
|
+
function permissionDeniedUIIOS(options) {
|
|
191
|
+
var _a, _b, _c, _d;
|
|
190
192
|
let div = document.createElement("div");
|
|
191
193
|
div.classList.add("zappar-permission-request");
|
|
192
194
|
div.innerHTML = `
|
|
@@ -228,16 +230,17 @@ function permissionDeniedUIIOS() {
|
|
|
228
230
|
}
|
|
229
231
|
</style>
|
|
230
232
|
<div class="zappar-inner">
|
|
231
|
-
<div class="zappar-title"
|
|
232
|
-
<div class="zappar-text"
|
|
233
|
-
<button id="zappar-permission-reload-button"
|
|
233
|
+
<div class="zappar-title">${(_a = options === null || options === void 0 ? void 0 : options.title) !== null && _a !== void 0 ? _a : 'Permission is Needed'}</div>
|
|
234
|
+
<div class="zappar-text">${(_c = (_b = options === null || options === void 0 ? void 0 : options.descriptionIOS) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.description) !== null && _c !== void 0 ? _c : "Permission to access your device's camera and motion sensors is necessary for this experience. Please reload the page to try again."}</div>
|
|
235
|
+
<button id="zappar-permission-reload-button">${(_d = options === null || options === void 0 ? void 0 : options.button) !== null && _d !== void 0 ? _d : 'Reload'}</button>
|
|
234
236
|
</div>
|
|
235
237
|
`;
|
|
236
238
|
document.body.append(div);
|
|
237
239
|
let button = div.querySelector("#zappar-permission-reload-button");
|
|
238
240
|
button === null || button === void 0 ? void 0 : button.addEventListener("click", () => window.location.reload());
|
|
239
241
|
}
|
|
240
|
-
function permissionDeniedUIChrome() {
|
|
242
|
+
function permissionDeniedUIChrome(options) {
|
|
243
|
+
var _a, _b, _c, _d;
|
|
241
244
|
let div = document.createElement("div");
|
|
242
245
|
div.classList.add("zappar-permission-request");
|
|
243
246
|
div.innerHTML = `
|
|
@@ -279,9 +282,9 @@ function permissionDeniedUIChrome() {
|
|
|
279
282
|
}
|
|
280
283
|
</style>
|
|
281
284
|
<div class="zappar-inner">
|
|
282
|
-
<div class="zappar-title"
|
|
283
|
-
<div class="zappar-text"
|
|
284
|
-
<button id="zappar-permission-reload-button"
|
|
285
|
+
<div class="zappar-title">${(_a = options === null || options === void 0 ? void 0 : options.title) !== null && _a !== void 0 ? _a : 'Permission is Needed'}</div>
|
|
286
|
+
<div class="zappar-text">${(_c = (_b = options === null || options === void 0 ? void 0 : options.descriptionChrome) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.description) !== null && _c !== void 0 ? _c : `Permission to access your device's camera and motion sensors is necessary for this experience.<br/><br/>To grant access, please tap the <svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 -960 960 960" width="16px" fill="white"><path d="M696-144q-60.48 0-102.24-41.76T552-288q0-60.48 41.76-102.24T696-432q60.48 0 102.24 41.76T840-288q0 60.48-41.76 102.24T696-144Zm.12-72Q726-216 747-237.12q21-21.12 21-51T746.88-339q-21.12-21-51-21T645-338.88q-21 21.12-21 51T645.12-237q21.12 21 51 21ZM168-252v-72h312v72H168Zm96-276q-60.48 0-102.24-41.76T120-672q0-60.48 41.76-102.24T264-816q60.48 0 102.24 41.76T408-672q0 60.48-41.76 102.24T264-528Zm.12-72Q294-600 315-621.12q21-21.12 21-51T314.88-723q-21.12-21-51-21T213-722.88q-21 21.12-21 51T213.12-621q21.12 21 51 21ZM480-636v-72h312v72H480Zm216 348ZM264-672Z"/></svg> button in the address bar of your browser, then "Permissions", and finally "Reset permissions". You can then reload the page to try again.`}</div>
|
|
287
|
+
<button id="zappar-permission-reload-button">${(_d = options === null || options === void 0 ? void 0 : options.button) !== null && _d !== void 0 ? _d : 'Reload'}</button>
|
|
285
288
|
</div>
|
|
286
289
|
`;
|
|
287
290
|
document.body.append(div);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PerformanceTracer } from "./performancetracer";
|
|
2
|
+
export declare class JSONTracer implements PerformanceTracer {
|
|
3
|
+
private stackDepth;
|
|
4
|
+
private events;
|
|
5
|
+
private static beginTemplate;
|
|
6
|
+
private static endTemplate;
|
|
7
|
+
private static namingEvents;
|
|
8
|
+
constructor();
|
|
9
|
+
clear(): void;
|
|
10
|
+
toJSON(): string;
|
|
11
|
+
postJSON(url: string): void;
|
|
12
|
+
start(name: string): void;
|
|
13
|
+
end(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class JSONTracer {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.stackDepth = 0;
|
|
4
|
+
this.events = [];
|
|
5
|
+
this.events = [...JSONTracer.namingEvents];
|
|
6
|
+
}
|
|
7
|
+
clear() {
|
|
8
|
+
this.stackDepth = 0;
|
|
9
|
+
this.events = [...JSONTracer.namingEvents];
|
|
10
|
+
}
|
|
11
|
+
toJSON() {
|
|
12
|
+
return JSON.stringify(this.events);
|
|
13
|
+
}
|
|
14
|
+
postJSON(url) {
|
|
15
|
+
fetch(url, { method: 'POST', body: this.toJSON() });
|
|
16
|
+
}
|
|
17
|
+
start(name) {
|
|
18
|
+
this.stackDepth++;
|
|
19
|
+
let beginEvent = Object.assign({ "name": name }, JSONTracer.beginTemplate);
|
|
20
|
+
this.events.push(beginEvent);
|
|
21
|
+
beginEvent.ts = Math.round(performance.now() * 1000);
|
|
22
|
+
}
|
|
23
|
+
end() {
|
|
24
|
+
let endTimestamp = Math.round(performance.now() * 1000);
|
|
25
|
+
if (this.stackDepth <= 0)
|
|
26
|
+
return;
|
|
27
|
+
this.stackDepth--;
|
|
28
|
+
let endEvent = Object.assign({ "ts": endTimestamp }, JSONTracer.endTemplate);
|
|
29
|
+
this.events.push(endEvent);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
JSONTracer.beginTemplate = { "ts": 0, "cat": "zcv", "ph": "B", "pid": 100, "tid": 100 };
|
|
33
|
+
JSONTracer.endTemplate = { "ph": "E", "pid": 100, "tid": 100 };
|
|
34
|
+
JSONTracer.namingEvents = [
|
|
35
|
+
{ "name": "process_name", "ph": "M", "pid": 100, "args": { "name": "Content Process" } },
|
|
36
|
+
{ "name": "thread_name", "ph": "M", "pid": 100, "tid": 100, "args": { "name": "UI Thread" } }
|
|
37
|
+
];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface PerformanceTracer {
|
|
2
|
+
clear: () => void;
|
|
3
|
+
start: (name: string) => void;
|
|
4
|
+
end: () => void;
|
|
5
|
+
}
|
|
6
|
+
export declare class PerformanceTracerManager implements PerformanceTracer {
|
|
7
|
+
tracers: PerformanceTracer[];
|
|
8
|
+
clear(): void;
|
|
9
|
+
start(name: string): void;
|
|
10
|
+
end(): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class PerformanceTracerManager {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.tracers = [];
|
|
4
|
+
}
|
|
5
|
+
clear() {
|
|
6
|
+
for (let t of this.tracers)
|
|
7
|
+
t.clear();
|
|
8
|
+
}
|
|
9
|
+
start(name) {
|
|
10
|
+
for (let t of this.tracers)
|
|
11
|
+
t.start(name);
|
|
12
|
+
}
|
|
13
|
+
end() {
|
|
14
|
+
for (let t of this.tracers)
|
|
15
|
+
t.end();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PerformanceTracer } from "./performancetracer";
|
|
2
|
+
export declare class UserTimingTracer implements PerformanceTracer {
|
|
3
|
+
private useFixedName;
|
|
4
|
+
private markCount;
|
|
5
|
+
private traceStack;
|
|
6
|
+
constructor(useFixedName?: boolean);
|
|
7
|
+
clear(): void;
|
|
8
|
+
start(name: string): void;
|
|
9
|
+
end(): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class UserTimingTracer {
|
|
2
|
+
constructor(useFixedName = false) {
|
|
3
|
+
this.useFixedName = useFixedName;
|
|
4
|
+
this.markCount = 0;
|
|
5
|
+
this.traceStack = [];
|
|
6
|
+
}
|
|
7
|
+
clear() {
|
|
8
|
+
this.traceStack = [];
|
|
9
|
+
}
|
|
10
|
+
start(name) {
|
|
11
|
+
const markName = name + '_' + this.markCount.toFixed(0);
|
|
12
|
+
this.markCount++;
|
|
13
|
+
const startName = markName + '_s';
|
|
14
|
+
const endName = markName + '_e';
|
|
15
|
+
this.traceStack.push([name, startName, endName]);
|
|
16
|
+
performance.mark(startName);
|
|
17
|
+
}
|
|
18
|
+
end() {
|
|
19
|
+
let last = this.traceStack.pop();
|
|
20
|
+
if (!last)
|
|
21
|
+
return;
|
|
22
|
+
performance.mark(last[2]);
|
|
23
|
+
if (this.useFixedName) {
|
|
24
|
+
performance.measure("ZTracing", { start: last[1], end: last[2], detail: { name: last[0] } });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
performance.measure(last[0], last[1], last[2]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
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.3";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0.1-beta.
|
|
1
|
+
export const VERSION = "3.0.1-beta.3";
|
package/lib/worker-server.js
CHANGED
|
@@ -322,8 +322,8 @@ function consumeReader(mod, r, reader, p, userFacing, server, source, workerMess
|
|
|
322
322
|
buffer.set(mod.HEAPU8.subarray(dataPointer, dataPointer + size));
|
|
323
323
|
buffers.ready.push({ token, data: {
|
|
324
324
|
data: buffer,
|
|
325
|
-
width: r.
|
|
326
|
-
height: r.
|
|
325
|
+
width: r.pipeline_camera_data_width(p),
|
|
326
|
+
height: r.pipeline_camera_data_height(p),
|
|
327
327
|
} });
|
|
328
328
|
}
|
|
329
329
|
server.exploreState();
|