瀏覽代碼

Version bump

customisations
alemart 3 年之前
父節點
當前提交
d39d38d145
共有 3 個文件被更改,包括 71 次插入57 次删除
  1. 65
    51
      dist/martins.js
  2. 3
    3
      dist/martins.min.js
  3. 3
    3
      package.json

+ 65
- 51
dist/martins.js 查看文件

1
 /*!
1
 /*!
2
- * MARTINS.js Free Edition version 0.1.0
2
+ * MARTINS.js Free Edition version 0.1.1
3
  * GPU-accelerated Augmented Reality for the web
3
  * GPU-accelerated Augmented Reality for the web
4
  * Copyright 2022 Alexandre Martins <alemartf(at)gmail.com> (https://github.com/alemart)
4
  * Copyright 2022 Alexandre Martins <alemartf(at)gmail.com> (https://github.com/alemart)
5
  * https://github.com/alemart/martins-js
5
  * https://github.com/alemart/martins-js
6
  *
6
  *
7
  * @license AGPL-3.0-only
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
 (function webpackUniversalModuleDefinition(root, factory) {
10
 (function webpackUniversalModuleDefinition(root, factory) {
11
 	if(typeof exports === 'object' && typeof module === 'object')
11
 	if(typeof exports === 'object' && typeof module === 'object')
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
      * Size of the AR screen space, in pixels
26483
      * Size of the AR screen space, in pixels
26500
      * @returns size in pixels
26484
      * @returns size in pixels
26501
      */
26485
      */
27072
  */
27056
  */
27073
 /**
27057
 /**
27074
  * A pose represents a position and an orientation in a 3D space
27058
  * A pose represents a position and an orientation in a 3D space
27059
+ * (and sometimes a scale, too...)
27075
  */
27060
  */
27076
 class Pose {
27061
 class Pose {
27077
     /**
27062
     /**
27078
      * Constructor
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
     constructor(transform) {
27066
     constructor(transform) {
27082
         this._transform = transform;
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
      * of the pose relative to the 3D space to which it belongs
27071
      * of the pose relative to the 3D space to which it belongs
27087
      */
27072
      */
27088
     get transform() {
27073
     get transform() {
27138
  * An invertible 3D transformation
27123
  * An invertible 3D transformation
27139
  */
27124
  */
27140
 class InvertibleTransform extends BaseTransform {
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
      * Constructor
27148
      * Constructor
27149
      * @param matrix a 4x4 matrix
27149
      * @param matrix a 4x4 matrix
27150
      */
27150
      */
27151
     constructor(matrix) {
27151
     constructor(matrix) {
27152
+        // WARNING: we do not check if the matrix actually encodes a standard transform!
27152
         super(matrix);
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
         // WARNING: we do not check if the matrix actually encodes a rigid transform!
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
     get inverse() {
27188
     get inverse() {
27168
         /*
27189
         /*
27232
     constructor(camera) {
27253
     constructor(camera) {
27233
         // compute the view matrix and its inverse in AR screen space
27254
         // compute the view matrix and its inverse in AR screen space
27234
         const viewMatrix = ViewerPose._computeViewMatrix(camera);
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
      * This 4x4 matrix moves 3D points from world space to viewer space. We
27261
      * This 4x4 matrix moves 3D points from world space to viewer space. We
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
  * A PerspectiveView is a View defining a symmetric frustum around the z-axis
27340
  * A PerspectiveView is a View defining a symmetric frustum around the z-axis
27326
  * (perspective projection)
27341
  * (perspective projection)
27469
         const modelMatrix = pose.transform.matrix;
27484
         const modelMatrix = pose.transform.matrix;
27470
         const viewMatrix = this._pose.viewMatrix;
27485
         const viewMatrix = this._pose.viewMatrix;
27471
         const modelViewMatrix = speedy_vision_default().Matrix(viewMatrix.times(modelMatrix));
27486
         const modelViewMatrix = speedy_vision_default().Matrix(viewMatrix.times(modelMatrix));
27472
-        const transform = RigidTransform.fromMatrix(modelViewMatrix);
27487
+        const transform = new StandardTransform(modelViewMatrix);
27473
         return new Pose(transform);
27488
         return new Pose(transform);
27474
     }
27489
     }
27475
 }
27490
 }
27513
 const NUMBER_OF_PBOS = 2;
27528
 const NUMBER_OF_PBOS = 2;
27514
 /** Frame skipping; meaningful only when using turbo */
27529
 /** Frame skipping; meaningful only when using turbo */
27515
 const TURBO_SKIP = 2;
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
  * The tracking state of the Image Tracker tracks
27532
  * The tracking state of the Image Tracker tracks
27523
  * keypoints of the image target and updates the
27533
  * keypoints of the image target and updates the
27729
             //return this._findPolyline(this._warpHomography, this.screenSize);
27739
             //return this._findPolyline(this._warpHomography, this.screenSize);
27730
         }).then(polyline => {
27740
         }).then(polyline => {
27731
             // we let the target object be at the origin of the world space
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
             // given the current state of the camera model, we get a viewer
27747
             // given the current state of the camera model, we get a viewer
27734
             // compatible with the pose of the target
27748
             // compatible with the pose of the target
27735
             const viewer = new Viewer(this._camera);
27749
             const viewer = new Viewer(this._camera);
28783
         if (false)
28797
         if (false)
28784
             {}
28798
             {}
28785
         else
28799
         else
28786
-            return "0.1.0";
28800
+            return "0.1.1";
28787
     }
28801
     }
28788
     /**
28802
     /**
28789
      * Engine edition
28803
      * Engine edition

+ 3
- 3
dist/martins.min.js
文件差異過大導致無法顯示
查看文件


+ 3
- 3
package.json 查看文件

1
 {
1
 {
2
   "name": "martins-js",
2
   "name": "martins-js",
3
-  "version": "0.1.0",
3
+  "version": "0.1.1",
4
   "description": "GPU-accelerated Augmented Reality for the web",
4
   "description": "GPU-accelerated Augmented Reality for the web",
5
   "author": "Alexandre Martins <alemartf@gmail.com> (https://github.com/alemart)",
5
   "author": "Alexandre Martins <alemartf@gmail.com> (https://github.com/alemart)",
6
   "homepage": "https://github.com/alemart/martins-js",
6
   "homepage": "https://github.com/alemart/martins-js",
17
   "main": "dist/martins.js",
17
   "main": "dist/martins.js",
18
   "scripts": {
18
   "scripts": {
19
     "start": "webpack serve --mode development --env PORT=8000",
19
     "start": "webpack serve --mode development --env PORT=8000",
20
-    "build": "npm run clean && webpack --mode development",
21
-    "build-prod": "npm run clean && webpack --mode production && webpack --mode production --env minimize=1",
20
+    "build-dev": "npm run clean && webpack --mode development",
21
+    "build": "npm run clean && webpack --mode production && webpack --mode production --env minimize=1",
22
     "clean": "rm -rf dist/*",
22
     "clean": "rm -rf dist/*",
23
     "test": "echo \"Error: no test specified\" && exit 1"
23
     "test": "echo \"Error: no test specified\" && exit 1"
24
   },
24
   },

Loading…
取消
儲存