@zappar/zappar-cv 3.0.1-beta.1 → 3.0.1-beta.10
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 +0 -2
- 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/drawquad.d.ts +2 -0
- package/lib/drawquad.js +99 -0
- 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/html-element-source.js +1 -1
- package/lib/mstp-camera-source.js +2 -1
- package/lib/native.js +247 -35
- 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 +3 -3
- package/lib/zappar-cv.js +1 -1
- package/lib/zappar-cv.wasm +0 -0
- package/package.json +8 -16
- package/umd/{ad30381eac4454d1944a.wasm → 067b89f3ea352f4f7279.wasm} +0 -0
- package/umd/751.zappar-cv.js +1 -1
- package/umd/867.zappar-cv.js +1 -1
- 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;
|
|
@@ -47,10 +49,27 @@ export function initialize(opts) {
|
|
|
47
49
|
});
|
|
48
50
|
const uid = getUID();
|
|
49
51
|
let hasPersistedUID = false;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
let hasSetID = false;
|
|
53
|
+
try {
|
|
54
|
+
/** @ts-ignore */
|
|
55
|
+
const cookies = Object.fromEntries(document.cookie.split('; ').map(v => v.split(/=(.*)/s).map(decodeURIComponent)));
|
|
56
|
+
if (cookies['zw-uar-project']) {
|
|
57
|
+
const parsed = JSON.parse(cookies['zw-uar-project']);
|
|
58
|
+
if (typeof parsed === 'object' && typeof parsed['id'] === 'string') {
|
|
59
|
+
c.impl.analytics_project_id_set(".wiz" + parsed['id'], uid);
|
|
60
|
+
hasSetID = true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (err) { }
|
|
65
|
+
if (!hasSetID) {
|
|
66
|
+
if (window.location.hostname.toLowerCase().indexOf(".zappar.io") > 0 || window.location.hostname.toLowerCase().indexOf(".webar.run") > 0 || window.location.hostname.toLowerCase().indexOf(".arweb.app") > 0 || window.location.hostname.toLowerCase().indexOf(".zappar-us.io") > 0 || window.location.hostname.toLowerCase().indexOf(".zappar-eu.io") > 0) {
|
|
67
|
+
let pathParts = window.location.pathname.split("/");
|
|
68
|
+
if (pathParts.length > 1 && pathParts[1].length > 0) {
|
|
69
|
+
c.impl.analytics_project_id_set(".wiz" + pathParts[1], uid);
|
|
70
|
+
hasSetID = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
54
73
|
}
|
|
55
74
|
messageManager.onIncomingMessage.bind(msg => {
|
|
56
75
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -150,7 +169,7 @@ export function initialize(opts) {
|
|
|
150
169
|
}
|
|
151
170
|
}
|
|
152
171
|
});
|
|
153
|
-
const
|
|
172
|
+
const customAnchors = new Map();
|
|
154
173
|
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
174
|
let res = applyScreenCounterRotation(undefined, raw_pose);
|
|
156
175
|
if (mirror) {
|
|
@@ -163,14 +182,6 @@ export function initialize(opts) {
|
|
|
163
182
|
}, 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
183
|
var _a;
|
|
165
184
|
(_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
185
|
}, draw_plane: (gl, projectionMatrix, cameraMatrix, targetMatrix, texture) => {
|
|
175
186
|
drawPlane(gl, projectionMatrix, cameraMatrix, targetMatrix, texture);
|
|
176
187
|
}, draw_grid: (gl, projectionMatrix, cameraMatrix, targetMatrix) => {
|
|
@@ -196,7 +207,7 @@ export function initialize(opts) {
|
|
|
196
207
|
return;
|
|
197
208
|
}
|
|
198
209
|
(_a = Pipeline.get(p)) === null || _a === void 0 ? void 0 : _a.drawImageTargetPreview(projectionMatrix, cameraMatrix, targetMatrix, indx, obj);
|
|
199
|
-
},
|
|
210
|
+
}, 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
211
|
let res = applyScreenCounterRotation(undefined, c.impl.instant_world_tracker_anchor_pose_raw(o));
|
|
201
212
|
if (mirror) {
|
|
202
213
|
let scale = mat4.create();
|
|
@@ -228,8 +239,31 @@ export function initialize(opts) {
|
|
|
228
239
|
let rawVec = vec3.create();
|
|
229
240
|
vec3.transformMat4(rawVec, [x, y, z], rotationMat);
|
|
230
241
|
c.impl.instant_world_tracker_anchor_pose_set_from_camera_offset_raw(o, rawVec[0], rawVec[1], rawVec[2], orientation);
|
|
242
|
+
}, custom_anchor_pose_raw: (o) => {
|
|
243
|
+
const entry = customAnchors.get(o);
|
|
244
|
+
if (entry === undefined) {
|
|
245
|
+
zcwarn("attempting to call custom_anchor_pose_raw on a destroyed zappar_custom_anchor_t");
|
|
246
|
+
return mat4.create();
|
|
247
|
+
}
|
|
248
|
+
if (entry.expectedPoseVersion <= client.custom_anchor_pose_version(o))
|
|
249
|
+
return c.impl.custom_anchor_pose_raw(o);
|
|
250
|
+
const world_anchor_raw = client.world_tracker_world_anchor_pose_raw(entry.wt).slice();
|
|
251
|
+
const ret = mat4.create();
|
|
252
|
+
mat4.multiply(ret, world_anchor_raw, entry.poseRelativeToWorldAnchor);
|
|
253
|
+
return ret;
|
|
254
|
+
}, custom_anchor_status: (o) => {
|
|
255
|
+
const entry = customAnchors.get(o);
|
|
256
|
+
if (entry === undefined) {
|
|
257
|
+
zcwarn("attempting to call custom_anchor_status on a destroyed zappar_custom_anchor_t");
|
|
258
|
+
return anchor_status_t.ANCHOR_STATUS_STOPPED;
|
|
259
|
+
}
|
|
260
|
+
if (entry.expectedPoseVersion === 0)
|
|
261
|
+
return anchor_status_t.ANCHOR_STATUS_STOPPED;
|
|
262
|
+
if (entry.expectedPoseVersion <= client.custom_anchor_pose_version(o))
|
|
263
|
+
return c.impl.custom_anchor_status(o);
|
|
264
|
+
return anchor_status_t.ANCHOR_STATUS_INITIALIZING;
|
|
231
265
|
}, custom_anchor_pose_camera_relative: (o, mirror) => {
|
|
232
|
-
let res = applyScreenCounterRotation(undefined,
|
|
266
|
+
let res = applyScreenCounterRotation(undefined, client.custom_anchor_pose_raw(o));
|
|
233
267
|
if (mirror) {
|
|
234
268
|
let scale = mat4.create();
|
|
235
269
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -238,7 +272,7 @@ export function initialize(opts) {
|
|
|
238
272
|
}
|
|
239
273
|
return res;
|
|
240
274
|
}, custom_anchor_pose: (o, cameraPose, mirror) => {
|
|
241
|
-
let res = applyScreenCounterRotation(undefined,
|
|
275
|
+
let res = applyScreenCounterRotation(undefined, client.custom_anchor_pose_raw(o));
|
|
242
276
|
if (mirror) {
|
|
243
277
|
let scale = mat4.create();
|
|
244
278
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -249,23 +283,193 @@ export function initialize(opts) {
|
|
|
249
283
|
return res;
|
|
250
284
|
}, custom_anchor_create: (p, wt, id) => {
|
|
251
285
|
const ret = c.impl.custom_anchor_create(p, wt, id);
|
|
252
|
-
|
|
286
|
+
customAnchors.set(ret, { id, wt, expectedPoseVersion: 0, poseRelativeToWorldAnchor: mat4.create() });
|
|
253
287
|
return ret;
|
|
254
288
|
}, custom_anchor_id: (o) => {
|
|
255
|
-
|
|
256
|
-
|
|
289
|
+
var _a;
|
|
290
|
+
let id = (_a = customAnchors.get(o)) === null || _a === void 0 ? void 0 : _a.id;
|
|
291
|
+
if (id === undefined) {
|
|
257
292
|
zcwarn("attempting to call custom_anchor_id on a destroyed zappar_custom_anchor_t");
|
|
258
293
|
return "";
|
|
259
294
|
}
|
|
260
295
|
return id;
|
|
261
296
|
}, custom_anchor_pose_set_from_camera_offset: (o, x, y, z, orientation) => {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
297
|
+
const entry = customAnchors.get(o);
|
|
298
|
+
if (entry === undefined) {
|
|
299
|
+
zcwarn("attempting to call custom_anchor_pose_set_from_camera_offset on a destroyed zappar_custom_anchor_t");
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const pose = mat4.create();
|
|
303
|
+
// camera space -> world anchor transform
|
|
304
|
+
mat4.invert(_temporaryMatrix, client.world_tracker_world_anchor_pose_camera_relative(entry.wt, false));
|
|
305
|
+
_temporaryVec3[0] = x;
|
|
306
|
+
_temporaryVec3[1] = y;
|
|
307
|
+
_temporaryVec3[2] = z;
|
|
308
|
+
switch (orientation) {
|
|
309
|
+
// UNCHANGED and PARENT easiest in camera space
|
|
310
|
+
case transform_orientation_t.PARENT:
|
|
311
|
+
// Identity rotation in camera space
|
|
312
|
+
pose[12] = _temporaryVec3[0];
|
|
313
|
+
pose[13] = _temporaryVec3[1];
|
|
314
|
+
pose[14] = _temporaryVec3[2];
|
|
315
|
+
// Convert to world pose
|
|
316
|
+
mat4.multiply(pose, _temporaryMatrix, pose);
|
|
317
|
+
break;
|
|
318
|
+
case transform_orientation_t.UNCHANGED:
|
|
319
|
+
// Take rotation form current camera_relative pose
|
|
320
|
+
mat4.copy(pose, client.custom_anchor_pose_camera_relative(o, false));
|
|
321
|
+
pose[12] = _temporaryVec3[0];
|
|
322
|
+
pose[13] = _temporaryVec3[1];
|
|
323
|
+
pose[14] = _temporaryVec3[2];
|
|
324
|
+
// Convert to world pose
|
|
325
|
+
mat4.multiply(pose, _temporaryMatrix, pose);
|
|
326
|
+
break;
|
|
327
|
+
// WORLD and Z_TOWARDS_CAMERA easiest in world space
|
|
328
|
+
case transform_orientation_t.WORLD:
|
|
329
|
+
// Transform the position into world space
|
|
330
|
+
vec3.transformMat4(_temporaryVec3, _temporaryVec3, _temporaryMatrix);
|
|
331
|
+
// Rotation bit is already identity
|
|
332
|
+
pose[12] = _temporaryVec3[0];
|
|
333
|
+
pose[13] = _temporaryVec3[1];
|
|
334
|
+
pose[14] = _temporaryVec3[2];
|
|
335
|
+
break;
|
|
336
|
+
case transform_orientation_t.Z_TOWARDS_CAMERA:
|
|
337
|
+
// Transform the position into world space
|
|
338
|
+
vec3.transformMat4(_temporaryVec3, _temporaryVec3, _temporaryMatrix);
|
|
339
|
+
// Z in pose should be aligned with the xz plane projection of target to camera vector
|
|
340
|
+
let pose_zx = _temporaryMatrix[12] - _temporaryVec3[0];
|
|
341
|
+
let pose_zz = _temporaryMatrix[14] - _temporaryVec3[2];
|
|
342
|
+
let magn2 = pose_zx * pose_zx + pose_zz * pose_zz;
|
|
343
|
+
if (magn2 > Number.EPSILON) {
|
|
344
|
+
let scale = 1.0 / (Math.sqrt(magn2));
|
|
345
|
+
pose_zx *= scale;
|
|
346
|
+
pose_zz *= scale;
|
|
347
|
+
pose[8] = pose_zx;
|
|
348
|
+
pose[10] = pose_zz;
|
|
349
|
+
// Fill in x axis by rotation matrix properties
|
|
350
|
+
pose[0] = pose_zz;
|
|
351
|
+
pose[2] = -pose_zx;
|
|
352
|
+
}
|
|
353
|
+
// Fill in the postion
|
|
354
|
+
pose[12] = _temporaryVec3[0];
|
|
355
|
+
pose[13] = _temporaryVec3[1];
|
|
356
|
+
pose[14] = _temporaryVec3[2];
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
client.custom_anchor_pose_set(o, pose);
|
|
360
|
+
}, custom_anchor_pose_set_from_anchor_offset: (o, anchor_id, x, y, z, orientation) => {
|
|
361
|
+
const entry = customAnchors.get(o);
|
|
362
|
+
if (entry === undefined) {
|
|
363
|
+
zcwarn("attempting to call custom_anchor_pose_set_from_anchor_offset on a destroyed zappar_custom_anchor_t");
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
let anchor_pose;
|
|
367
|
+
if (anchor_id === client.world_tracker_ground_anchor_id(entry.wt)) {
|
|
368
|
+
anchor_pose = client.world_tracker_ground_anchor_pose_raw(entry.wt);
|
|
369
|
+
}
|
|
370
|
+
else if (anchor_id === client.world_tracker_world_anchor_id(entry.wt)) {
|
|
371
|
+
anchor_pose = client.world_tracker_world_anchor_pose_raw(entry.wt);
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
for (let i = 0; i < client.world_tracker_plane_anchor_count(entry.wt); i++) {
|
|
375
|
+
if (anchor_id === client.world_tracker_plane_anchor_id(entry.wt, i)) {
|
|
376
|
+
anchor_pose = client.world_tracker_plane_anchor_pose_raw(entry.wt, i);
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (!anchor_pose) {
|
|
381
|
+
for (const [anchor, details] of customAnchors.entries()) {
|
|
382
|
+
if (details.id !== anchor_id)
|
|
383
|
+
continue;
|
|
384
|
+
anchor_pose = client.custom_anchor_pose_raw(anchor);
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (!anchor_pose) {
|
|
390
|
+
zcwarn("unable for find anchor with id", anchor_id);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const pose = mat4.create();
|
|
394
|
+
// camera_raw space -> world anchor transform
|
|
395
|
+
mat4.invert(_temporaryMatrix, client.world_tracker_world_anchor_pose_raw(entry.wt));
|
|
396
|
+
// Get position offset relative to camera_raw
|
|
397
|
+
_temporaryVec3[0] = x;
|
|
398
|
+
_temporaryVec3[1] = y;
|
|
399
|
+
_temporaryVec3[2] = z;
|
|
400
|
+
vec3.transformMat4(_temporaryVec3, _temporaryVec3, anchor_pose);
|
|
401
|
+
switch (orientation) {
|
|
402
|
+
// UNCHANGED and PARENT easiest in camera_raw space
|
|
403
|
+
case transform_orientation_t.PARENT:
|
|
404
|
+
mat4.copy(pose, anchor_pose);
|
|
405
|
+
pose[12] = _temporaryVec3[0];
|
|
406
|
+
pose[13] = _temporaryVec3[1];
|
|
407
|
+
pose[14] = _temporaryVec3[2];
|
|
408
|
+
// Convert to world pose
|
|
409
|
+
mat4.multiply(pose, _temporaryMatrix, pose);
|
|
410
|
+
break;
|
|
411
|
+
case transform_orientation_t.UNCHANGED:
|
|
412
|
+
mat4.copy(pose, client.custom_anchor_pose_raw(o));
|
|
413
|
+
pose[12] = _temporaryVec3[0];
|
|
414
|
+
pose[13] = _temporaryVec3[1];
|
|
415
|
+
pose[14] = _temporaryVec3[2];
|
|
416
|
+
// Convert to world pose
|
|
417
|
+
mat4.multiply(pose, _temporaryMatrix, pose);
|
|
418
|
+
break;
|
|
419
|
+
// WORLD and Z_TOWARDS_CAMERA easiest in world space
|
|
420
|
+
case transform_orientation_t.WORLD:
|
|
421
|
+
// Transform the position into world space
|
|
422
|
+
vec3.transformMat4(_temporaryVec3, _temporaryVec3, _temporaryMatrix);
|
|
423
|
+
// Rotation bit is already identity
|
|
424
|
+
pose[12] = _temporaryVec3[0];
|
|
425
|
+
pose[13] = _temporaryVec3[1];
|
|
426
|
+
pose[14] = _temporaryVec3[2];
|
|
427
|
+
break;
|
|
428
|
+
case transform_orientation_t.Z_TOWARDS_CAMERA:
|
|
429
|
+
// Transform the position into world space
|
|
430
|
+
vec3.transformMat4(_temporaryVec3, _temporaryVec3, _temporaryMatrix);
|
|
431
|
+
// Z in pose should be aligned with the xz plane projection of target to camera vector
|
|
432
|
+
let pose_zx = _temporaryMatrix[12] - _temporaryVec3[0];
|
|
433
|
+
let pose_zz = _temporaryMatrix[14] - _temporaryVec3[2];
|
|
434
|
+
let magn2 = pose_zx * pose_zx + pose_zz * pose_zz;
|
|
435
|
+
if (magn2 > Number.EPSILON) {
|
|
436
|
+
let scale = 1.0 / (Math.sqrt(magn2));
|
|
437
|
+
pose_zx *= scale;
|
|
438
|
+
pose_zz *= scale;
|
|
439
|
+
pose[8] = pose_zx;
|
|
440
|
+
pose[10] = pose_zz;
|
|
441
|
+
// Fill in x axis by rotation matrix properties
|
|
442
|
+
pose[0] = pose_zz;
|
|
443
|
+
pose[2] = -pose_zx;
|
|
444
|
+
}
|
|
445
|
+
// Fill in the postion
|
|
446
|
+
pose[12] = _temporaryVec3[0];
|
|
447
|
+
pose[13] = _temporaryVec3[1];
|
|
448
|
+
pose[14] = _temporaryVec3[2];
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
client.custom_anchor_pose_set_with_parent(o, pose, anchor_id);
|
|
452
|
+
}, custom_anchor_pose_set: (o, pose) => {
|
|
453
|
+
const entry = customAnchors.get(o);
|
|
454
|
+
if (entry === undefined) {
|
|
455
|
+
zcwarn("attempting to call custom_anchor_pose_set on a destroyed zappar_custom_anchor_t");
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
entry.expectedPoseVersion++;
|
|
459
|
+
mat4.copy(entry.poseRelativeToWorldAnchor, pose);
|
|
460
|
+
c.impl.custom_anchor_pose_set(o, pose);
|
|
461
|
+
}, custom_anchor_pose_set_with_parent: (o, pose, anchor_id) => {
|
|
462
|
+
const entry = customAnchors.get(o);
|
|
463
|
+
if (entry === undefined) {
|
|
464
|
+
zcwarn("attempting to call custom_anchor_pose_set_with_parent on a destroyed zappar_custom_anchor_t");
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
entry.expectedPoseVersion++;
|
|
468
|
+
mat4.copy(entry.poseRelativeToWorldAnchor, pose);
|
|
469
|
+
c.impl.custom_anchor_pose_set_with_parent(o, pose, anchor_id);
|
|
470
|
+
}, custom_anchor_destroy: (o) => {
|
|
471
|
+
customAnchors.delete(o);
|
|
472
|
+
c.impl.custom_anchor_destroy(o);
|
|
269
473
|
}, 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
474
|
let obj = ImageTracker.get(t);
|
|
271
475
|
if (!obj) {
|
|
@@ -591,13 +795,21 @@ export function initialize(opts) {
|
|
|
591
795
|
const ret = c.impl.world_tracker_create(pipeline);
|
|
592
796
|
pipelineByWorldTracker.set(ret, pipeline);
|
|
593
797
|
return ret;
|
|
798
|
+
}, world_tracker_reset: (wt) => {
|
|
799
|
+
for (const entry of customAnchors.values()) {
|
|
800
|
+
if (entry.wt === wt) {
|
|
801
|
+
mat4.identity(entry.poseRelativeToWorldAnchor);
|
|
802
|
+
entry.expectedPoseVersion = 0;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
c.impl.world_tracker_reset(wt);
|
|
594
806
|
}, world_tracker_points_data_matrix: (wt, screenWidth, screenHeight, mirror) => {
|
|
595
807
|
const pipeline = pipelineByWorldTracker.get(wt);
|
|
596
808
|
if (pipeline === undefined || !client)
|
|
597
809
|
return mat4.create();
|
|
598
|
-
return getPointsDataMatrix(client.
|
|
810
|
+
return getPointsDataMatrix(client.pipeline_camera_data_width(pipeline), client.pipeline_camera_data_height(pipeline), screenWidth, screenHeight, mirror);
|
|
599
811
|
}, world_tracker_plane_anchor_pose_camera_relative: (o, indx, mirror) => {
|
|
600
|
-
let res = applyScreenCounterRotation(undefined,
|
|
812
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_plane_anchor_pose_raw(o, indx));
|
|
601
813
|
if (mirror) {
|
|
602
814
|
let scale = mat4.create();
|
|
603
815
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -606,7 +818,7 @@ export function initialize(opts) {
|
|
|
606
818
|
}
|
|
607
819
|
return res;
|
|
608
820
|
}, world_tracker_plane_anchor_pose: (o, indx, cameraPose, mirror) => {
|
|
609
|
-
let res = applyScreenCounterRotation(undefined,
|
|
821
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_plane_anchor_pose_raw(o, indx));
|
|
610
822
|
if (mirror) {
|
|
611
823
|
let scale = mat4.create();
|
|
612
824
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -616,7 +828,7 @@ export function initialize(opts) {
|
|
|
616
828
|
mat4.multiply(res, cameraPose, res);
|
|
617
829
|
return res;
|
|
618
830
|
}, world_tracker_world_anchor_pose: (o, cameraPose, mirror) => {
|
|
619
|
-
let res = applyScreenCounterRotation(undefined,
|
|
831
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_world_anchor_pose_raw(o));
|
|
620
832
|
if (mirror) {
|
|
621
833
|
let scale = mat4.create();
|
|
622
834
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -626,7 +838,7 @@ export function initialize(opts) {
|
|
|
626
838
|
mat4.multiply(res, cameraPose, res);
|
|
627
839
|
return res;
|
|
628
840
|
}, world_tracker_world_anchor_pose_camera_relative: (o, mirror) => {
|
|
629
|
-
let res = applyScreenCounterRotation(undefined,
|
|
841
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_world_anchor_pose_raw(o));
|
|
630
842
|
if (mirror) {
|
|
631
843
|
let scale = mat4.create();
|
|
632
844
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -635,7 +847,7 @@ export function initialize(opts) {
|
|
|
635
847
|
}
|
|
636
848
|
return res;
|
|
637
849
|
}, world_tracker_ground_anchor_pose: (o, cameraPose, mirror) => {
|
|
638
|
-
let res = applyScreenCounterRotation(undefined,
|
|
850
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_ground_anchor_pose_raw(o));
|
|
639
851
|
if (mirror) {
|
|
640
852
|
let scale = mat4.create();
|
|
641
853
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -645,7 +857,7 @@ export function initialize(opts) {
|
|
|
645
857
|
mat4.multiply(res, cameraPose, res);
|
|
646
858
|
return res;
|
|
647
859
|
}, world_tracker_ground_anchor_pose_camera_relative: (o, mirror) => {
|
|
648
|
-
let res = applyScreenCounterRotation(undefined,
|
|
860
|
+
let res = applyScreenCounterRotation(undefined, client.world_tracker_ground_anchor_pose_raw(o));
|
|
649
861
|
if (mirror) {
|
|
650
862
|
let scale = mat4.create();
|
|
651
863
|
mat4.fromScaling(scale, [-1, 1, 1]);
|
|
@@ -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.10";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0.1-beta.
|
|
1
|
+
export const VERSION = "3.0.1-beta.10";
|
package/lib/worker-server.js
CHANGED
|
@@ -266,7 +266,7 @@ function consumeReader(mod, r, reader, p, userFacing, server, source, workerMess
|
|
|
266
266
|
mat4.fromScaling(cameraToDeviceTransform, [-1, 1, -1]);
|
|
267
267
|
else
|
|
268
268
|
mat4.identity(cameraToDeviceTransform);
|
|
269
|
-
let focalLength = 240.0 * dataWidth / 320.0;
|
|
269
|
+
let focalLength = (userFacing ? 300.0 : 240.0) * dataWidth / 320.0;
|
|
270
270
|
cameraModel[0] = focalLength;
|
|
271
271
|
cameraModel[1] = focalLength;
|
|
272
272
|
cameraModel[2] = dataWidth * 0.5;
|
|
@@ -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();
|