|
@@ -1,11 +1,11 @@
|
1
|
1
|
/*!
|
2
|
|
- * MARTINS.js Free Edition version 0.1.0
|
|
2
|
+ * MARTINS.js Free Edition version 0.1.1
|
3
|
3
|
* GPU-accelerated Augmented Reality for the web
|
4
|
4
|
* Copyright 2022 Alexandre Martins <alemartf(at)gmail.com> (https://github.com/alemart)
|
5
|
5
|
* https://github.com/alemart/martins-js
|
6
|
6
|
*
|
7
|
7
|
* @license AGPL-3.0-only
|
8
|
|
- * Date: 2022-04-21T17:21:12.069Z
|
|
8
|
+ * Date: 2022-04-28T23:26:33.373Z
|
9
|
9
|
*/
|
10
|
10
|
(function webpackUniversalModuleDefinition(root, factory) {
|
11
|
11
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
@@ -26480,22 +26480,6 @@ class CameraModel {
|
26480
|
26480
|
]);
|
26481
|
26481
|
}
|
26482
|
26482
|
/**
|
26483
|
|
- * The inverse of denormalizer()
|
26484
|
|
- * @returns 4x4 matrix
|
26485
|
|
- */
|
26486
|
|
- denormalizerInverse() {
|
26487
|
|
- const w = this._screenSize.width / 2;
|
26488
|
|
- const h = this._screenSize.height / 2;
|
26489
|
|
- const d = Math.min(w, h);
|
26490
|
|
- const b = 1 / d;
|
26491
|
|
- return speedy_vision_default().Matrix(4, 4, [
|
26492
|
|
- b, 0, 0, 0,
|
26493
|
|
- 0, -b, 0, 0,
|
26494
|
|
- 0, 0, -b, 0,
|
26495
|
|
- -w * b, h * b, 0, 1,
|
26496
|
|
- ]);
|
26497
|
|
- }
|
26498
|
|
- /**
|
26499
|
26483
|
* Size of the AR screen space, in pixels
|
26500
|
26484
|
* @returns size in pixels
|
26501
|
26485
|
*/
|
|
@@ -27072,17 +27056,18 @@ class CameraModel {
|
27072
|
27056
|
*/
|
27073
|
27057
|
/**
|
27074
|
27058
|
* A pose represents a position and an orientation in a 3D space
|
|
27059
|
+ * (and sometimes a scale, too...)
|
27075
|
27060
|
*/
|
27076
|
27061
|
class Pose {
|
27077
|
27062
|
/**
|
27078
|
27063
|
* Constructor
|
27079
|
|
- * @param transform a rigid transform in a 3D space (e.g., world space, viewer space or other)
|
|
27064
|
+ * @param transform usually a rigid transform in a 3D space (e.g., world space, viewer space or other)
|
27080
|
27065
|
*/
|
27081
|
27066
|
constructor(transform) {
|
27082
|
27067
|
this._transform = transform;
|
27083
|
27068
|
}
|
27084
|
27069
|
/**
|
27085
|
|
- * A rigid transform describing the position and the orientation
|
|
27070
|
+ * A transform describing the position and the orientation
|
27086
|
27071
|
* of the pose relative to the 3D space to which it belongs
|
27087
|
27072
|
*/
|
27088
|
27073
|
get transform() {
|
|
@@ -27138,31 +27123,67 @@ class BaseTransform {
|
27138
|
27123
|
* An invertible 3D transformation
|
27139
|
27124
|
*/
|
27140
|
27125
|
class InvertibleTransform extends BaseTransform {
|
|
27126
|
+ /**
|
|
27127
|
+ * Constructor
|
|
27128
|
+ * @param matrix a 4x4 matrix
|
|
27129
|
+ */
|
|
27130
|
+ constructor(matrix) {
|
|
27131
|
+ // WARNING: we do not check if the matrix actually encodes an invertible transform!
|
|
27132
|
+ super(matrix);
|
|
27133
|
+ }
|
|
27134
|
+ /**
|
|
27135
|
+ * The inverse of the transform
|
|
27136
|
+ */
|
|
27137
|
+ get inverse() {
|
|
27138
|
+ const inverseMatrix = speedy_vision_default().Matrix(this._matrix.inverse());
|
|
27139
|
+ return new InvertibleTransform(inverseMatrix);
|
|
27140
|
+ }
|
27141
|
27141
|
}
|
27142
|
27142
|
/**
|
27143
|
|
- * A 3D transformation described by position and orientation
|
|
27143
|
+ * A 3D transformation described by translation, rotation and scale
|
27144
|
27144
|
*/
|
27145
|
|
-class RigidTransform extends InvertibleTransform {
|
27146
|
|
- // TODO: position and orientation attributes
|
|
27145
|
+class StandardTransform extends InvertibleTransform {
|
|
27146
|
+ // TODO: position, rotation and scale attributes
|
27147
|
27147
|
/**
|
27148
|
27148
|
* Constructor
|
27149
|
27149
|
* @param matrix a 4x4 matrix
|
27150
|
27150
|
*/
|
27151
|
27151
|
constructor(matrix) {
|
|
27152
|
+ // WARNING: we do not check if the matrix actually encodes a standard transform!
|
27152
|
27153
|
super(matrix);
|
27153
|
27154
|
}
|
27154
|
27155
|
/**
|
27155
|
|
- * Create a new rigid transform using a pre-computed transformation matrix
|
27156
|
|
- * @param matrix a 4x4 matrix encoding a rigid transform
|
27157
|
|
- * @returns a new rigid transform
|
27158
|
|
- * @internal
|
|
27156
|
+ * The inverse of the transform
|
|
27157
|
+ */
|
|
27158
|
+ get inverse() {
|
|
27159
|
+ /*
|
|
27160
|
+
|
|
27161
|
+ The inverse of a 4x4 standard transform T * R * S...
|
|
27162
|
+
|
|
27163
|
+ [ RS t ] is [ ZR' -ZR't ]
|
|
27164
|
+ [ 0' 1 ] [ 0' 1 ]
|
|
27165
|
+
|
|
27166
|
+ where S is 3x3, R is 3x3, t is 3x1, 0' is 1x3 and Z is the inverse of S
|
|
27167
|
+
|
|
27168
|
+ */
|
|
27169
|
+ return super.inverse;
|
|
27170
|
+ }
|
|
27171
|
+}
|
|
27172
|
+/**
|
|
27173
|
+ * A 3D transformation described by position and orientation
|
|
27174
|
+ */
|
|
27175
|
+class RigidTransform extends StandardTransform {
|
|
27176
|
+ // TODO: position and rotation attributes (need to decompose the matrix)
|
|
27177
|
+ /**
|
|
27178
|
+ * Constructor
|
|
27179
|
+ * @param matrix a 4x4 matrix
|
27159
|
27180
|
*/
|
27160
|
|
- static fromMatrix(matrix) {
|
|
27181
|
+ constructor(matrix) {
|
27161
|
27182
|
// WARNING: we do not check if the matrix actually encodes a rigid transform!
|
27162
|
|
- return new RigidTransform(matrix);
|
|
27183
|
+ super(matrix);
|
27163
|
27184
|
}
|
27164
|
27185
|
/**
|
27165
|
|
- * The inverse of the rigid transform
|
|
27186
|
+ * The inverse of the transform
|
27166
|
27187
|
*/
|
27167
|
27188
|
get inverse() {
|
27168
|
27189
|
/*
|
|
@@ -27232,15 +27253,9 @@ class ViewerPose extends Pose {
|
27232
|
27253
|
constructor(camera) {
|
27233
|
27254
|
// compute the view matrix and its inverse in AR screen space
|
27234
|
27255
|
const viewMatrix = ViewerPose._computeViewMatrix(camera);
|
27235
|
|
- const viewMatrixInverse = RigidTransform.fromMatrix(viewMatrix).inverse.matrix;
|
27236
|
|
- // perform a change of coordinates
|
27237
|
|
- const M = camera.denormalizer();
|
27238
|
|
- const W = camera.denormalizerInverse();
|
27239
|
|
- const myViewMatrix = speedy_vision_default().Matrix(viewMatrix.times(M));
|
27240
|
|
- const myViewMatrixInverse = speedy_vision_default().Matrix(W.times(viewMatrixInverse));
|
27241
|
|
- // create the viewer pose
|
27242
|
|
- super(RigidTransform.fromMatrix(myViewMatrixInverse));
|
27243
|
|
- this._viewMatrix = myViewMatrix;
|
|
27256
|
+ const inverseTransform = new RigidTransform(viewMatrix);
|
|
27257
|
+ super(inverseTransform.inverse);
|
|
27258
|
+ this._viewMatrix = viewMatrix;
|
27244
|
27259
|
}
|
27245
|
27260
|
/**
|
27246
|
27261
|
* This 4x4 matrix moves 3D points from world space to viewer space. We
|
|
@@ -27317,10 +27332,10 @@ class ViewerPose extends Pose {
|
27317
|
27332
|
|
27318
|
27333
|
|
27319
|
27334
|
|
27320
|
|
-/** Default distance of the near plane to the optical center of the camera */
|
27321
|
|
-const DEFAULT_NEAR = 0.1;
|
27322
|
|
-/** Default distance of the far plane to the optical center of the camera */
|
27323
|
|
-const DEFAULT_FAR = 2000;
|
|
27335
|
+/** Default distance in pixels of the near plane to the optical center of the camera */
|
|
27336
|
+const DEFAULT_NEAR = 1;
|
|
27337
|
+/** Default distance in pixels of the far plane to the optical center of the camera */
|
|
27338
|
+const DEFAULT_FAR = 20000;
|
27324
|
27339
|
/**
|
27325
|
27340
|
* A PerspectiveView is a View defining a symmetric frustum around the z-axis
|
27326
|
27341
|
* (perspective projection)
|
|
@@ -27469,7 +27484,7 @@ class Viewer {
|
27469
|
27484
|
const modelMatrix = pose.transform.matrix;
|
27470
|
27485
|
const viewMatrix = this._pose.viewMatrix;
|
27471
|
27486
|
const modelViewMatrix = speedy_vision_default().Matrix(viewMatrix.times(modelMatrix));
|
27472
|
|
- const transform = RigidTransform.fromMatrix(modelViewMatrix);
|
|
27487
|
+ const transform = new StandardTransform(modelViewMatrix);
|
27473
|
27488
|
return new Pose(transform);
|
27474
|
27489
|
}
|
27475
|
27490
|
}
|
|
@@ -27513,11 +27528,6 @@ const USE_TURBO = true;
|
27513
|
27528
|
const NUMBER_OF_PBOS = 2;
|
27514
|
27529
|
/** Frame skipping; meaningful only when using turbo */
|
27515
|
27530
|
const TURBO_SKIP = 2;
|
27516
|
|
-/** An identity transform computed lazily */
|
27517
|
|
-const identityTransform = (() => {
|
27518
|
|
- let transform = null;
|
27519
|
|
- return () => (transform = transform || RigidTransform.fromMatrix(speedy_vision_default().Matrix.Eye(4)));
|
27520
|
|
-})();
|
27521
|
27531
|
/**
|
27522
|
27532
|
* The tracking state of the Image Tracker tracks
|
27523
|
27533
|
* keypoints of the image target and updates the
|
|
@@ -27729,7 +27739,11 @@ class ImageTrackerTrackingState extends ImageTrackerState {
|
27729
|
27739
|
//return this._findPolyline(this._warpHomography, this.screenSize);
|
27730
|
27740
|
}).then(polyline => {
|
27731
|
27741
|
// we let the target object be at the origin of the world space
|
27732
|
|
- const pose = new Pose(identityTransform());
|
|
27742
|
+ // (identity transform). We also perform a change of coordinates,
|
|
27743
|
+ // so that we move out from pixel space and into normalized space
|
|
27744
|
+ const modelMatrix = this._camera.denormalizer(); // ~ "identity matrix"
|
|
27745
|
+ const transform = new StandardTransform(modelMatrix);
|
|
27746
|
+ const pose = new Pose(transform);
|
27733
|
27747
|
// given the current state of the camera model, we get a viewer
|
27734
|
27748
|
// compatible with the pose of the target
|
27735
|
27749
|
const viewer = new Viewer(this._camera);
|
|
@@ -28783,7 +28797,7 @@ class Martins {
|
28783
|
28797
|
if (false)
|
28784
|
28798
|
{}
|
28785
|
28799
|
else
|
28786
|
|
- return "0.1.0";
|
|
28800
|
+ return "0.1.1";
|
28787
|
28801
|
}
|
28788
|
28802
|
/**
|
28789
|
28803
|
* Engine edition
|