@zappar/zappar-cv 2.1.4 → 3.0.0-alpha.0

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.
@@ -28,6 +28,7 @@ export declare class ImageBitmapCameraSource extends Source {
28
28
  private _getUserMedia;
29
29
  private _syncCamera;
30
30
  private _hasStartedOrientation;
31
+ private _lastTimestamp;
31
32
  private _deviceMotionListener;
32
33
  private _startDeviceOrientation;
33
34
  private _startDeviceMotion;
@@ -33,23 +33,37 @@ export class ImageBitmapCameraSource extends Source {
33
33
  this._cameraToDeviceTransformUserFacing = mat4.create();
34
34
  this._cameraModel = new Float32Array([300, 300, 160, 120, 0, 0]);
35
35
  this._hasStartedOrientation = false;
36
+ this._lastTimestamp = -1;
36
37
  this._deviceMotionListener = (ev) => {
37
38
  let pipeline = Pipeline.get(this._pipeline);
38
39
  if (!pipeline)
39
40
  return;
40
41
  let timeStamp = (ev.timeStamp !== undefined && ev.timeStamp !== null) ? ev.timeStamp : performance.now();
42
+ let interval = ev.interval;
43
+ if (this._lastTimestamp > -1 && !profile.trustSensorIntervals) {
44
+ interval = Math.max(timeStamp - this._lastTimestamp, interval);
45
+ }
46
+ this._lastTimestamp = timeStamp;
47
+ interval *= profile.intervalMultiplier;
48
+ if (ev.acceleration !== null &&
49
+ ev.acceleration.x !== null &&
50
+ ev.acceleration.y !== null &&
51
+ ev.acceleration.z !== null) {
52
+ pipeline.motionAccelerometerWithoutGravitySubmitInt(timeStamp, interval, ev.acceleration.x * profile.deviceMotionMutliplier, ev.acceleration.y * profile.deviceMotionMutliplier, ev.acceleration.z * profile.deviceMotionMutliplier);
53
+ }
41
54
  if (ev.accelerationIncludingGravity !== null &&
42
55
  ev.accelerationIncludingGravity.x !== null &&
43
56
  ev.accelerationIncludingGravity.y !== null &&
44
57
  ev.accelerationIncludingGravity.z !== null) {
45
58
  pipeline.motionAccelerometerSubmit(timeStamp, ev.accelerationIncludingGravity.x * profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.y * profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.z * profile.deviceMotionMutliplier);
59
+ pipeline.motionAccelerometerWithGravitySubmitInt(timeStamp, interval, ev.accelerationIncludingGravity.x * profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.y * profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.z * profile.deviceMotionMutliplier);
46
60
  }
47
61
  if (ev.rotationRate !== null &&
48
62
  ev.rotationRate.alpha !== null &&
49
63
  ev.rotationRate.beta !== null &&
50
- ev.rotationRate.gamma !== null && !this._hasStartedOrientation) {
51
- ev.timeStamp;
52
- pipeline.motionRotationRateSubmit(timeStamp, ev.rotationRate.alpha * Math.PI / -180.0, ev.rotationRate.beta * Math.PI / -180.0, ev.rotationRate.gamma * Math.PI / -180.0);
64
+ ev.rotationRate.gamma !== null && this._hasStartedOrientation) {
65
+ pipeline.motionRotationRateSubmit(timeStamp, ev.rotationRate.alpha, ev.rotationRate.beta, ev.rotationRate.gamma);
66
+ pipeline.motionRotationRateSubmitInt(timeStamp, interval, ev.rotationRate.alpha, ev.rotationRate.beta, ev.rotationRate.gamma);
53
67
  }
54
68
  else if (!this._hasStartedOrientation) {
55
69
  this._startDeviceOrientation();
@@ -240,6 +254,7 @@ export class ImageBitmapCameraSource extends Source {
240
254
  if (ev.alpha === null || ev.beta === null || ev.gamma === null)
241
255
  return;
242
256
  pipeline.motionAttitudeSubmit(timeStamp, ev.alpha, ev.beta, ev.gamma);
257
+ pipeline.motionAttitudeSubmitInt(timeStamp, 0, ev.alpha, ev.beta, ev.gamma);
243
258
  });
244
259
  }
245
260
  _startDeviceMotion() {
package/lib/index.d.ts CHANGED
@@ -3,4 +3,4 @@ import { Additional } from "./additional";
3
3
  import { Options } from "./options";
4
4
  export declare type Zappar = zappar & Additional;
5
5
  export declare function initialize(opts?: Options): Zappar;
6
- export { zappar_image_tracker_t, zappar_instant_world_tracker_t, zappar_barcode_finder_t, zappar_face_tracker_t, zappar_face_landmark_t, barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, zappar_face_mesh_t, zappar_pipeline_t, zappar_camera_source_t, zappar_sequence_source_t, image_target_type_t } from "./gen/zappar";
6
+ export { zappar_image_tracker_t, zappar_instant_world_tracker_t, zappar_world_tracker_t, zappar_barcode_finder_t, zappar_face_tracker_t, zappar_face_landmark_t, barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, zappar_face_mesh_t, zappar_pipeline_t, zappar_camera_source_t, zappar_sequence_source_t, image_target_type_t, world_tracker_quality_t } from "./gen/zappar";
package/lib/index.js CHANGED
@@ -4,4 +4,4 @@ export function initialize(opts) {
4
4
  console.log(`Zappar CV v${VERSION}`);
5
5
  return nativeInitialize(opts);
6
6
  }
7
- export { barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, image_target_type_t } from "./gen/zappar";
7
+ export { barcode_format_t, face_landmark_name_t, instant_world_tracker_transform_orientation_t, log_level_t, image_target_type_t, world_tracker_quality_t } from "./gen/zappar";
@@ -21,6 +21,7 @@ export declare class MSTPCameraSource extends Source {
21
21
  private _getUserMedia;
22
22
  private _syncCamera;
23
23
  private _hasStartedOrientation;
24
+ private _lastTimestamp;
24
25
  private _deviceMotionListener;
25
26
  private _startDeviceOrientation;
26
27
  private _startDeviceMotion;
@@ -25,23 +25,37 @@ export class MSTPCameraSource extends Source {
25
25
  this._isUserFacing = false;
26
26
  this._cameraToScreenRotation = 0;
27
27
  this._hasStartedOrientation = false;
28
+ this._lastTimestamp = -1;
28
29
  this._deviceMotionListener = (ev) => {
29
30
  let pipeline = Pipeline.get(this._pipeline);
30
31
  if (!pipeline)
31
32
  return;
32
33
  let timeStamp = (ev.timeStamp !== undefined && ev.timeStamp !== null) ? ev.timeStamp : performance.now();
34
+ let interval = ev.interval;
35
+ if (this._lastTimestamp > -1 && !profile.trustSensorIntervals) {
36
+ interval = Math.max(timeStamp - this._lastTimestamp, interval);
37
+ }
38
+ this._lastTimestamp = timeStamp;
39
+ interval *= profile.intervalMultiplier;
40
+ if (ev.acceleration !== null &&
41
+ ev.acceleration.x !== null &&
42
+ ev.acceleration.y !== null &&
43
+ ev.acceleration.z !== null) {
44
+ pipeline.motionAccelerometerWithoutGravitySubmitInt(timeStamp, interval, ev.acceleration.x * profile.deviceMotionMutliplier, ev.acceleration.y * profile.deviceMotionMutliplier, ev.acceleration.z * profile.deviceMotionMutliplier);
45
+ }
33
46
  if (ev.accelerationIncludingGravity !== null &&
34
47
  ev.accelerationIncludingGravity.x !== null &&
35
48
  ev.accelerationIncludingGravity.y !== null &&
36
49
  ev.accelerationIncludingGravity.z !== null) {
37
50
  pipeline.motionAccelerometerSubmit(timeStamp, ev.accelerationIncludingGravity.x * profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.y * profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.z * profile.deviceMotionMutliplier);
51
+ pipeline.motionAccelerometerWithGravitySubmitInt(timeStamp, interval, ev.accelerationIncludingGravity.x * profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.y * profile.deviceMotionMutliplier, ev.accelerationIncludingGravity.z * profile.deviceMotionMutliplier);
38
52
  }
39
53
  if (ev.rotationRate !== null &&
40
54
  ev.rotationRate.alpha !== null &&
41
55
  ev.rotationRate.beta !== null &&
42
- ev.rotationRate.gamma !== null && !this._hasStartedOrientation) {
43
- ev.timeStamp;
44
- pipeline.motionRotationRateSubmit(timeStamp, ev.rotationRate.alpha * Math.PI / -180.0, ev.rotationRate.beta * Math.PI / -180.0, ev.rotationRate.gamma * Math.PI / -180.0);
56
+ ev.rotationRate.gamma !== null && this._hasStartedOrientation) {
57
+ pipeline.motionRotationRateSubmit(timeStamp, ev.rotationRate.alpha, ev.rotationRate.beta, ev.rotationRate.gamma);
58
+ pipeline.motionRotationRateSubmitInt(timeStamp, interval, ev.rotationRate.alpha, ev.rotationRate.beta, ev.rotationRate.gamma);
45
59
  }
46
60
  else if (!this._hasStartedOrientation) {
47
61
  this._startDeviceOrientation();
@@ -193,6 +207,7 @@ export class MSTPCameraSource extends Source {
193
207
  if (ev.alpha === null || ev.beta === null || ev.gamma === null)
194
208
  return;
195
209
  pipeline.motionAttitudeSubmit(timeStamp, ev.alpha, ev.beta, ev.gamma);
210
+ pipeline.motionAttitudeSubmitInt(timeStamp, 0, ev.alpha, ev.beta, ev.gamma);
196
211
  });
197
212
  }
198
213
  _startDeviceMotion() {
package/lib/native.js CHANGED
@@ -478,6 +478,63 @@ export function initialize(opts) {
478
478
  return mat4.create();
479
479
  }
480
480
  return obj.anchor_pose;
481
+ }, world_tracker_plane_pose_camera_relative: (o, indx, mirror) => {
482
+ let res = applyScreenCounterRotation(undefined, c.impl.world_tracker_plane_pose_raw(o, indx));
483
+ if (mirror) {
484
+ let scale = mat4.create();
485
+ mat4.fromScaling(scale, [-1, 1, 1]);
486
+ mat4.multiply(res, scale, res);
487
+ mat4.multiply(res, res, scale);
488
+ }
489
+ return res;
490
+ }, world_tracker_plane_pose: (o, indx, cameraPose, mirror) => {
491
+ let res = applyScreenCounterRotation(undefined, c.impl.world_tracker_plane_pose_raw(o, indx));
492
+ if (mirror) {
493
+ let scale = mat4.create();
494
+ mat4.fromScaling(scale, [-1, 1, 1]);
495
+ mat4.multiply(res, scale, res);
496
+ mat4.multiply(res, res, scale);
497
+ }
498
+ mat4.multiply(res, cameraPose, res);
499
+ return res;
500
+ }, world_tracker_world_anchor_pose: (o, cameraPose, mirror) => {
501
+ let res = applyScreenCounterRotation(undefined, c.impl.world_tracker_world_anchor_pose_raw(o));
502
+ if (mirror) {
503
+ let scale = mat4.create();
504
+ mat4.fromScaling(scale, [-1, 1, 1]);
505
+ mat4.multiply(res, scale, res);
506
+ mat4.multiply(res, res, scale);
507
+ }
508
+ mat4.multiply(res, cameraPose, res);
509
+ return res;
510
+ }, world_tracker_world_anchor_pose_camera_relative: (o, mirror) => {
511
+ let res = applyScreenCounterRotation(undefined, c.impl.world_tracker_world_anchor_pose_raw(o));
512
+ if (mirror) {
513
+ let scale = mat4.create();
514
+ mat4.fromScaling(scale, [-1, 1, 1]);
515
+ mat4.multiply(res, scale, res);
516
+ mat4.multiply(res, res, scale);
517
+ }
518
+ return res;
519
+ }, world_tracker_ground_anchor_pose: (o, cameraPose, mirror) => {
520
+ let res = applyScreenCounterRotation(undefined, c.impl.world_tracker_ground_anchor_pose_raw(o));
521
+ if (mirror) {
522
+ let scale = mat4.create();
523
+ mat4.fromScaling(scale, [-1, 1, 1]);
524
+ mat4.multiply(res, scale, res);
525
+ mat4.multiply(res, res, scale);
526
+ }
527
+ mat4.multiply(res, cameraPose, res);
528
+ return res;
529
+ }, world_tracker_ground_anchor_pose_camera_relative: (o, mirror) => {
530
+ let res = applyScreenCounterRotation(undefined, c.impl.world_tracker_ground_anchor_pose_raw(o));
531
+ if (mirror) {
532
+ let scale = mat4.create();
533
+ mat4.fromScaling(scale, [-1, 1, 1]);
534
+ mat4.multiply(res, scale, res);
535
+ mat4.multiply(res, res, scale);
536
+ }
537
+ return res;
481
538
  }, 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 => {
482
539
  setLogLevel(l);
483
540
  c.impl.log_level_set(l);
package/lib/pipeline.d.ts CHANGED
@@ -58,6 +58,10 @@ export declare class Pipeline {
58
58
  registerToken(info: CameraFrameInfo): number;
59
59
  processGL(): void;
60
60
  motionAccelerometerSubmit(timestamp: number, x: number, y: number, z: number): void;
61
+ motionAccelerometerWithoutGravitySubmitInt(timestamp: number, interval: number, x: number, y: number, z: number): void;
62
+ motionAccelerometerWithGravitySubmitInt(timestamp: number, interval: number, x: number, y: number, z: number): void;
63
+ motionRotationRateSubmitInt(timestamp: number, interval: number, x: number, y: number, z: number): void;
64
+ motionAttitudeSubmitInt(timestamp: number, interval: number, x: number, y: number, z: number): void;
61
65
  motionRotationRateSubmit(timestamp: number, x: number, y: number, z: number): void;
62
66
  motionAttitudeSubmit(timestamp: number, x: number, y: number, z: number): void;
63
67
  motionAttitudeMatrix(m: Float32Array): void;
package/lib/pipeline.js CHANGED
@@ -270,23 +270,104 @@ export class Pipeline {
270
270
  var _a;
271
271
  if (!this._sequenceRecordDeviceAttitudeMatrices)
272
272
  (_a = this._sequenceRecorder) === null || _a === void 0 ? void 0 : _a.appendAccelerometer(timestamp, x, y, z);
273
- this._client.pipeline_motion_accelerometer_submit(this._impl, timestamp, x, y, z);
273
+ const msg = {
274
+ t: 'sensorDataC2S',
275
+ sensor: 'accel',
276
+ interval: 0,
277
+ timestamp,
278
+ x, y, z,
279
+ p: this._impl
280
+ };
281
+ this._mgr.postOutgoingMessage(msg, []);
282
+ }
283
+ motionAccelerometerWithoutGravitySubmitInt(timestamp, interval, x, y, z) {
284
+ var _a;
285
+ (_a = this._sequenceRecorder) === null || _a === void 0 ? void 0 : _a.appendAccelerometerWithoutGravityInt(timestamp, interval, x, y, z);
286
+ const msg = {
287
+ t: 'sensorDataC2S',
288
+ sensor: 'accel_wo_gravity_int',
289
+ interval,
290
+ timestamp,
291
+ x, y, z,
292
+ p: this._impl
293
+ };
294
+ this._mgr.postOutgoingMessage(msg, []);
295
+ }
296
+ motionAccelerometerWithGravitySubmitInt(timestamp, interval, x, y, z) {
297
+ var _a;
298
+ (_a = this._sequenceRecorder) === null || _a === void 0 ? void 0 : _a.appendAccelerometerWithGravityInt(timestamp, interval, x, y, z);
299
+ const msg = {
300
+ t: 'sensorDataC2S',
301
+ sensor: 'accel_w_gravity_int',
302
+ interval,
303
+ timestamp,
304
+ x, y, z,
305
+ p: this._impl
306
+ };
307
+ this._mgr.postOutgoingMessage(msg, []);
308
+ }
309
+ motionRotationRateSubmitInt(timestamp, interval, x, y, z) {
310
+ var _a;
311
+ (_a = this._sequenceRecorder) === null || _a === void 0 ? void 0 : _a.appendRotationRateInt(timestamp, interval, x, y, z);
312
+ const msg = {
313
+ t: 'sensorDataC2S',
314
+ sensor: 'rotation_rate_int',
315
+ interval,
316
+ timestamp,
317
+ x, y, z,
318
+ p: this._impl
319
+ };
320
+ this._mgr.postOutgoingMessage(msg, []);
321
+ }
322
+ motionAttitudeSubmitInt(timestamp, interval, x, y, z) {
323
+ var _a;
324
+ (_a = this._sequenceRecorder) === null || _a === void 0 ? void 0 : _a.appendAttitudeInt(timestamp, interval, x, y, z);
325
+ const msg = {
326
+ t: 'sensorDataC2S',
327
+ sensor: 'attitude_int',
328
+ interval,
329
+ timestamp,
330
+ x, y, z,
331
+ p: this._impl
332
+ };
333
+ this._mgr.postOutgoingMessage(msg, []);
274
334
  }
275
335
  motionRotationRateSubmit(timestamp, x, y, z) {
276
336
  var _a;
277
337
  if (!this._sequenceRecordDeviceAttitudeMatrices)
278
338
  (_a = this._sequenceRecorder) === null || _a === void 0 ? void 0 : _a.appendRotationRate(timestamp, x, y, z);
279
- this._client.pipeline_motion_rotation_rate_submit(this._impl, timestamp, x, y, z);
339
+ const msg = {
340
+ t: 'sensorDataC2S',
341
+ sensor: 'rotation_rate',
342
+ interval: 0,
343
+ timestamp,
344
+ x, y, z,
345
+ p: this._impl
346
+ };
347
+ this._mgr.postOutgoingMessage(msg, []);
280
348
  }
281
349
  motionAttitudeSubmit(timestamp, x, y, z) {
282
350
  var _a;
283
351
  if (!this._sequenceRecordDeviceAttitudeMatrices)
284
352
  (_a = this._sequenceRecorder) === null || _a === void 0 ? void 0 : _a.appendAttitude(timestamp, x, y, z);
285
- this._client.pipeline_motion_attitude_submit(this._impl, timestamp, x, y, z);
353
+ const msg = {
354
+ t: 'sensorDataC2S',
355
+ sensor: 'attitude',
356
+ interval: 0,
357
+ timestamp,
358
+ x, y, z,
359
+ p: this._impl
360
+ };
361
+ this._mgr.postOutgoingMessage(msg, []);
286
362
  }
287
363
  motionAttitudeMatrix(m) {
288
364
  // This doesn't need to be added to the sequence since that's done on frame update instead
289
- this._client.pipeline_motion_attitude_matrix_submit(this._impl, m);
365
+ const msg = {
366
+ t: 'attitudeMatrixC2S',
367
+ p: this._impl,
368
+ m,
369
+ };
370
+ this._mgr.postOutgoingMessage(msg, []);
290
371
  }
291
372
  sendCameraStreamToWorker(source, stream, userFacing) {
292
373
  let msg = {
package/lib/profile.d.ts CHANGED
@@ -17,4 +17,6 @@ export declare let profile: {
17
17
  preferImageBitmapCamera: boolean;
18
18
  ios164CameraSelection: boolean;
19
19
  forceWindowOrientation: boolean;
20
+ intervalMultiplier: number;
21
+ trustSensorIntervals: boolean;
20
22
  };
package/lib/profile.js CHANGED
@@ -15,10 +15,12 @@ export let profile = {
15
15
  dataWidth: 320,
16
16
  dataHeight: 240,
17
17
  videoElementInDOM: false,
18
- preferMediaStreamTrackProcessorCamera: false,
18
+ preferMediaStreamTrackProcessorCamera: true,
19
19
  preferImageBitmapCamera: false,
20
20
  ios164CameraSelection: false,
21
21
  forceWindowOrientation: false,
22
+ intervalMultiplier: 1,
23
+ trustSensorIntervals: false,
22
24
  };
23
25
  if (typeof window !== "undefined") {
24
26
  window["zeeProfile"] = profile;
@@ -48,6 +50,9 @@ if (engine === "webkit" && os === "ios") {
48
50
  }
49
51
  function iDevice(version) {
50
52
  profile.forceWindowOrientation = true;
53
+ profile.preferMediaStreamTrackProcessorCamera = false;
54
+ profile.intervalMultiplier = 1000;
55
+ profile.trustSensorIntervals = true;
51
56
  let versionParts = version.split(".");
52
57
  if (versionParts.length >= 2) {
53
58
  const majorVersion = parseInt(versionParts[0]);
@@ -4,7 +4,11 @@ export declare enum SequenceRecorderPacketType {
4
4
  ACCELEROMETER = 1,
5
5
  ROTATION_RATE = 2,
6
6
  ATTITUDE = 3,
7
- ATTITUDE_MATRIX = 4
7
+ ATTITUDE_MATRIX = 4,
8
+ ACCELEROMETER_WO_GRAVITY_INT = 5,
9
+ ACCELEROMETER_W_GRAVITY_INT = 6,
10
+ ROTATION_RATE_INT = 7,
11
+ ATTITUDE_INT = 8
8
12
  }
9
13
  export declare class SequenceRecorder {
10
14
  static headerSizeBytes: number;
@@ -16,6 +20,7 @@ export declare class SequenceRecorder {
16
20
  static psbCameraModel: number;
17
21
  static cameraPacketSizeBytes: number;
18
22
  static accelerometerPacketSizeBytes: number;
23
+ static sensorWithIntervalPacketSizeBytes: number;
19
24
  static rotationRatePacketSizeBytes: number;
20
25
  static attitudePacketSizeBytes: number;
21
26
  static attitudeMatrixPacketSizeBytes: number;
@@ -36,6 +41,11 @@ export declare class SequenceRecorder {
36
41
  appendAccelerometer(t: number, x: number, y: number, z: number): void;
37
42
  appendRotationRate(t: number, x: number, y: number, z: number): void;
38
43
  appendAttitude(t: number, x: number, y: number, z: number): void;
44
+ appendAccelerometerWithoutGravityInt(t: number, int: number, x: number, y: number, z: number): void;
45
+ appendAccelerometerWithGravityInt(t: number, int: number, x: number, y: number, z: number): void;
46
+ appendRotationRateInt(t: number, int: number, x: number, y: number, z: number): void;
47
+ appendAttitudeInt(t: number, int: number, x: number, y: number, z: number): void;
48
+ private _appendSensorWithInterval;
39
49
  private _appendTimestampedVec3;
40
50
  appendAttitudeMatrix(m: Float32Array): void;
41
51
  private _growArrayBuffer;
@@ -64,11 +74,16 @@ export interface SequenceRotationRateData extends SequenceVec3Data {
64
74
  export interface SequenceAttitudeData extends SequenceVec3Data {
65
75
  type: SequenceRecorderPacketType.ATTITUDE;
66
76
  }
77
+ declare type SensorSourceType = SequenceRecorderPacketType.ACCELEROMETER_WO_GRAVITY_INT | SequenceRecorderPacketType.ACCELEROMETER_W_GRAVITY_INT | SequenceRecorderPacketType.ATTITUDE_INT | SequenceRecorderPacketType.ROTATION_RATE_INT;
78
+ export interface SequenceSensorData extends SequenceVec3Data {
79
+ type: SensorSourceType;
80
+ int: number;
81
+ }
67
82
  export interface SequenceAttitudeMatrixData {
68
83
  type: SequenceRecorderPacketType.ATTITUDE_MATRIX;
69
84
  attitude: Float32Array;
70
85
  }
71
- export declare type SequencePacketData = SequenceCameraData | SequenceAccelerometerData | SequenceRotationRateData | SequenceAttitudeData | SequenceAttitudeMatrixData;
86
+ export declare type SequencePacketData = SequenceCameraData | SequenceAccelerometerData | SequenceRotationRateData | SequenceAttitudeData | SequenceAttitudeMatrixData | SequenceSensorData;
72
87
  export declare class SequenceDecoder {
73
88
  private _data;
74
89
  dataByPacket: Map<number, SequencePacketData>;
@@ -81,3 +96,4 @@ export declare class SequenceDecoder {
81
96
  numberAttitudeMatrixPackets: number;
82
97
  constructor(_data: ArrayBuffer);
83
98
  }
99
+ export {};
@@ -6,6 +6,10 @@ export var SequenceRecorderPacketType;
6
6
  SequenceRecorderPacketType[SequenceRecorderPacketType["ROTATION_RATE"] = 2] = "ROTATION_RATE";
7
7
  SequenceRecorderPacketType[SequenceRecorderPacketType["ATTITUDE"] = 3] = "ATTITUDE";
8
8
  SequenceRecorderPacketType[SequenceRecorderPacketType["ATTITUDE_MATRIX"] = 4] = "ATTITUDE_MATRIX";
9
+ SequenceRecorderPacketType[SequenceRecorderPacketType["ACCELEROMETER_WO_GRAVITY_INT"] = 5] = "ACCELEROMETER_WO_GRAVITY_INT";
10
+ SequenceRecorderPacketType[SequenceRecorderPacketType["ACCELEROMETER_W_GRAVITY_INT"] = 6] = "ACCELEROMETER_W_GRAVITY_INT";
11
+ SequenceRecorderPacketType[SequenceRecorderPacketType["ROTATION_RATE_INT"] = 7] = "ROTATION_RATE_INT";
12
+ SequenceRecorderPacketType[SequenceRecorderPacketType["ATTITUDE_INT"] = 8] = "ATTITUDE_INT";
9
13
  })(SequenceRecorderPacketType || (SequenceRecorderPacketType = {}));
10
14
  export class SequenceRecorder {
11
15
  constructor(estimatedFrames) {
@@ -85,6 +89,38 @@ export class SequenceRecorder {
85
89
  appendAttitude(t, x, y, z) {
86
90
  this._appendTimestampedVec3(SequenceRecorderPacketType.ATTITUDE, t, x, y, z);
87
91
  }
92
+ appendAccelerometerWithoutGravityInt(t, int, x, y, z) {
93
+ this._appendSensorWithInterval(SequenceRecorderPacketType.ACCELEROMETER_WO_GRAVITY_INT, t, int, x, y, z);
94
+ }
95
+ appendAccelerometerWithGravityInt(t, int, x, y, z) {
96
+ this._appendSensorWithInterval(SequenceRecorderPacketType.ACCELEROMETER_W_GRAVITY_INT, t, int, x, y, z);
97
+ }
98
+ appendRotationRateInt(t, int, x, y, z) {
99
+ this._appendSensorWithInterval(SequenceRecorderPacketType.ROTATION_RATE_INT, t, int, x, y, z);
100
+ }
101
+ appendAttitudeInt(t, int, x, y, z) {
102
+ this._appendSensorWithInterval(SequenceRecorderPacketType.ATTITUDE_INT, t, int, x, y, z);
103
+ }
104
+ _appendSensorWithInterval(type, t, int, x, y, z) {
105
+ if (!this._started)
106
+ return;
107
+ let increment = SequenceRecorder.psbPacketType + SequenceRecorder.sensorWithIntervalPacketSizeBytes;
108
+ this._growArrayBuffer(increment);
109
+ this._dataView.setUint32(this._insertionByte, type, true);
110
+ this._insertionByte += SequenceRecorder.psbPacketType;
111
+ this._dataView.setUint32(this._insertionByte, t, true);
112
+ this._insertionByte += 4;
113
+ this._dataView.setUint32(this._insertionByte, int, true);
114
+ this._insertionByte += 4;
115
+ this._dataView.setFloat32(this._insertionByte, x, true);
116
+ this._insertionByte += 4;
117
+ this._dataView.setFloat32(this._insertionByte, y, true);
118
+ this._insertionByte += 4;
119
+ this._dataView.setFloat32(this._insertionByte, z, true);
120
+ this._insertionByte += 4;
121
+ this._numberPackets++;
122
+ this._dataView.setUint32(4, this._numberPackets, true);
123
+ }
88
124
  _appendTimestampedVec3(type, t, x, y, z) {
89
125
  if (!this._started)
90
126
  return;
@@ -145,6 +181,8 @@ SequenceRecorder.cameraPacketSizeBytes = SequenceRecorder.psbCameraFrameWidth +
145
181
  SequenceRecorder.psbFlags;
146
182
  // Accelerometer
147
183
  SequenceRecorder.accelerometerPacketSizeBytes = 4 * 4; // t, x, y, z
184
+ // Sensor with interval
185
+ SequenceRecorder.sensorWithIntervalPacketSizeBytes = 4 * 5; // t, interval, x, y, z
148
186
  // Rotation rate
149
187
  SequenceRecorder.rotationRatePacketSizeBytes = 4 * 4; // t, x, y, z
150
188
  // Attitude
@@ -272,6 +310,28 @@ export class SequenceDecoder {
272
310
  this.numberAttitudeMatrixPackets++;
273
311
  break;
274
312
  }
313
+ case SequenceRecorderPacketType.ACCELEROMETER_WO_GRAVITY_INT:
314
+ case SequenceRecorderPacketType.ACCELEROMETER_W_GRAVITY_INT:
315
+ case SequenceRecorderPacketType.ATTITUDE_INT:
316
+ case SequenceRecorderPacketType.ROTATION_RATE_INT:
317
+ {
318
+ let t = dataView.getUint32(readPoint, true);
319
+ readPoint += 4;
320
+ let int = dataView.getUint32(readPoint, true);
321
+ readPoint += 4;
322
+ let x = dataView.getFloat32(readPoint, true);
323
+ readPoint += 4;
324
+ let y = dataView.getFloat32(readPoint, true);
325
+ readPoint += 4;
326
+ let z = dataView.getFloat32(readPoint, true);
327
+ readPoint += 4;
328
+ this.dataByPacket.set(i, {
329
+ type: type,
330
+ t, int, x, y, z
331
+ });
332
+ this.numberAccelerometerPackets++;
333
+ break;
334
+ }
275
335
  }
276
336
  }
277
337
  }
@@ -157,6 +157,22 @@ export class SequenceSource extends Source {
157
157
  pipeline.motionAttitudeMatrix(packet.attitude);
158
158
  pendingMotionUpdate = true;
159
159
  break;
160
+ case SequenceRecorderPacketType.ACCELEROMETER_WO_GRAVITY_INT:
161
+ pipeline.motionAccelerometerWithoutGravitySubmitInt(packet.t, packet.int, packet.x, packet.y, packet.z);
162
+ pendingMotionUpdate = true;
163
+ break;
164
+ case SequenceRecorderPacketType.ACCELEROMETER_W_GRAVITY_INT:
165
+ pipeline.motionAccelerometerWithGravitySubmitInt(packet.t, packet.int, packet.x, packet.y, packet.z);
166
+ pendingMotionUpdate = true;
167
+ break;
168
+ case SequenceRecorderPacketType.ATTITUDE_INT:
169
+ pipeline.motionAttitudeSubmitInt(packet.t, packet.int, packet.x, packet.y, packet.z);
170
+ pendingMotionUpdate = true;
171
+ break;
172
+ case SequenceRecorderPacketType.ROTATION_RATE_INT:
173
+ pipeline.motionRotationRateSubmitInt(packet.t, packet.int, packet.x, packet.y, packet.z);
174
+ pendingMotionUpdate = true;
175
+ break;
160
176
  }
161
177
  this._packetNumber++;
162
178
  }
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "2.1.4";
1
+ export declare const VERSION = "3.0.0-alpha.0";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "2.1.4";
1
+ export const VERSION = "3.0.0-alpha.0";
@@ -35,7 +35,7 @@ export function handleImageBitmap(m, r, server, mgr) {
35
35
  if (!texture)
36
36
  return;
37
37
  if (!pixels || pixels.byteLength < profile.dataWidth * profile.dataHeight) {
38
- console.log("Generating pixel buffer", profile.dataWidth * profile.dataHeight);
38
+ // console.log("Generating pixel buffer", profile.dataWidth * profile.dataHeight);
39
39
  pixels = new ArrayBuffer(profile.dataWidth * profile.dataHeight);
40
40
  }
41
41
  imageProcessor.uploadFrame(texture, m.i, m.r, m.userFacing);
@@ -81,6 +81,44 @@ export function launchWorkerServer(wasmUrl) {
81
81
  handleImageBitmap(msgt, r, server, messageManager);
82
82
  break;
83
83
  }
84
+ case "sensorDataC2S": {
85
+ const msgt = msg;
86
+ const pipeline = server._pipeline_by_instance.get(msgt.p);
87
+ if (!pipeline)
88
+ break;
89
+ switch (msgt.sensor) {
90
+ case "accel":
91
+ r.pipeline_motion_accelerometer_submit(pipeline, msgt.timestamp, msgt.x, msgt.y, msgt.z);
92
+ break;
93
+ case "accel_w_gravity_int":
94
+ r.pipeline_motion_accelerometer_with_gravity_submit_int(pipeline, msgt.timestamp, msgt.interval, msgt.x, msgt.y, msgt.z);
95
+ break;
96
+ case "accel_wo_gravity_int":
97
+ r.pipeline_motion_accelerometer_without_gravity_submit_int(pipeline, msgt.timestamp, msgt.interval, msgt.x, msgt.y, msgt.z);
98
+ break;
99
+ case "attitude_int":
100
+ r.pipeline_motion_attitude_submit_int(pipeline, msgt.timestamp, msgt.interval, msgt.x, msgt.y, msgt.z);
101
+ break;
102
+ case "attitude":
103
+ r.pipeline_motion_attitude_submit(pipeline, msgt.timestamp, msgt.x, msgt.y, msgt.z);
104
+ break;
105
+ case "rotation_rate_int":
106
+ r.pipeline_motion_rotation_rate_submit_int(pipeline, msgt.timestamp, msgt.interval, msgt.x, msgt.y, msgt.z);
107
+ break;
108
+ case "rotation_rate":
109
+ r.pipeline_motion_rotation_rate_submit(pipeline, msgt.timestamp, msgt.x, msgt.y, msgt.z);
110
+ break;
111
+ }
112
+ break;
113
+ }
114
+ case "attitudeMatrixC2S": {
115
+ const msgt = msg;
116
+ const pipeline = server._pipeline_by_instance.get(msgt.p);
117
+ if (!pipeline)
118
+ break;
119
+ r.pipeline_motion_attitude_matrix_submit(pipeline, msgt.m);
120
+ break;
121
+ }
84
122
  }
85
123
  });
86
124
  }
@@ -88,14 +126,27 @@ export function launchWorkerServer(wasmUrl) {
88
126
  });
89
127
  }
90
128
  ;
129
+ function consumeStream(mod, r, stream, p, userFacing, server, source) {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ while (true) {
132
+ try {
133
+ const reader = yield stream.getReader();
134
+ yield consumeReader(mod, r, reader, p, userFacing, server, source);
135
+ }
136
+ catch (err) {
137
+ console.log("Consuming reader error", err);
138
+ }
139
+ yield delay(1000);
140
+ }
141
+ });
142
+ }
91
143
  let streamDataBufferPointer = 0;
92
144
  let streamDataBufferLength = 0;
93
145
  let tokenId = 1;
94
146
  const cameraToDeviceTransform = mat4.create();
95
147
  const cameraModel = new Float32Array([300, 300, 160, 120, 0, 0]);
96
- function consumeStream(mod, r, stream, p, userFacing, server, source) {
148
+ function consumeReader(mod, r, reader, p, userFacing, server, source) {
97
149
  return __awaiter(this, void 0, void 0, function* () {
98
- const reader = yield stream.getReader();
99
150
  while (true) {
100
151
  let result = yield reader.read();
101
152
  if (result.done) {
@@ -162,7 +213,12 @@ function consumeStream(mod, r, stream, p, userFacing, server, source) {
162
213
  messageManager.postOutgoingMessage(ret, [ret.d, ret.uvTransform.buffer]);
163
214
  const pipeline = server._pipeline_by_instance.get(p);
164
215
  if (pipeline) {
165
- r.pipeline_camera_frame_submit_raw_pointer(pipeline, streamDataBufferPointer, size, framePixelFormatFromFormat(frame.format), width, height, token, cameraToDeviceTransform, latestCameraToScreenRotation, cameraModel, userFacing);
216
+ try {
217
+ r.pipeline_camera_frame_submit_raw_pointer(pipeline, streamDataBufferPointer, size, framePixelFormatFromFormat(frame.format), width, height, token, cameraToDeviceTransform, latestCameraToScreenRotation, cameraModel, userFacing);
218
+ }
219
+ catch (err) {
220
+ console.log('Exception during camera processing', err);
221
+ }
166
222
  r.pipeline_frame_update(pipeline);
167
223
  server.exploreState();
168
224
  }
@@ -170,6 +226,12 @@ function consumeStream(mod, r, stream, p, userFacing, server, source) {
170
226
  }
171
227
  });
172
228
  }
229
+ function delay(ms) {
230
+ return new Promise(resolve => {
231
+ setTimeout(resolve, ms);
232
+ });
233
+ }
234
+ ;
173
235
  function framePixelFormatFromFormat(f) {
174
236
  switch (f) {
175
237
  case "I420": return frame_pixel_format_t.FRAME_PIXEL_FORMAT_I420;