@srsergio/taptapp-ar 1.0.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.
Files changed (207) hide show
  1. package/README.md +62 -0
  2. package/dist/compiler/aframe.d.ts +1 -0
  3. package/dist/compiler/aframe.js +275 -0
  4. package/dist/compiler/compiler-base.d.ts +12 -0
  5. package/dist/compiler/compiler-base.js +165 -0
  6. package/dist/compiler/compiler.d.ts +9 -0
  7. package/dist/compiler/compiler.js +24 -0
  8. package/dist/compiler/compiler.worker.d.ts +1 -0
  9. package/dist/compiler/compiler.worker.js +28 -0
  10. package/dist/compiler/controller.d.ts +101 -0
  11. package/dist/compiler/controller.js +400 -0
  12. package/dist/compiler/controller.worker.d.ts +1 -0
  13. package/dist/compiler/controller.worker.js +61 -0
  14. package/dist/compiler/detector/crop-detector.d.ts +65 -0
  15. package/dist/compiler/detector/crop-detector.js +59 -0
  16. package/dist/compiler/detector/detector.d.ts +98 -0
  17. package/dist/compiler/detector/detector.js +1049 -0
  18. package/dist/compiler/detector/freak.d.ts +1 -0
  19. package/dist/compiler/detector/freak.js +89 -0
  20. package/dist/compiler/detector/kernels/cpu/binomialFilter.d.ts +6 -0
  21. package/dist/compiler/detector/kernels/cpu/binomialFilter.js +51 -0
  22. package/dist/compiler/detector/kernels/cpu/buildExtremas.d.ts +6 -0
  23. package/dist/compiler/detector/kernels/cpu/buildExtremas.js +89 -0
  24. package/dist/compiler/detector/kernels/cpu/computeExtremaAngles.d.ts +7 -0
  25. package/dist/compiler/detector/kernels/cpu/computeExtremaAngles.js +79 -0
  26. package/dist/compiler/detector/kernels/cpu/computeExtremaFreak.d.ts +6 -0
  27. package/dist/compiler/detector/kernels/cpu/computeExtremaFreak.js +68 -0
  28. package/dist/compiler/detector/kernels/cpu/computeFreakDescriptors.d.ts +6 -0
  29. package/dist/compiler/detector/kernels/cpu/computeFreakDescriptors.js +57 -0
  30. package/dist/compiler/detector/kernels/cpu/computeLocalization.d.ts +6 -0
  31. package/dist/compiler/detector/kernels/cpu/computeLocalization.js +54 -0
  32. package/dist/compiler/detector/kernels/cpu/computeOrientationHistograms.d.ts +6 -0
  33. package/dist/compiler/detector/kernels/cpu/computeOrientationHistograms.js +118 -0
  34. package/dist/compiler/detector/kernels/cpu/downsampleBilinear.d.ts +6 -0
  35. package/dist/compiler/detector/kernels/cpu/downsampleBilinear.js +29 -0
  36. package/dist/compiler/detector/kernels/cpu/extremaReduction.d.ts +6 -0
  37. package/dist/compiler/detector/kernels/cpu/extremaReduction.js +50 -0
  38. package/dist/compiler/detector/kernels/cpu/fakeShader.d.ts +20 -0
  39. package/dist/compiler/detector/kernels/cpu/fakeShader.js +80 -0
  40. package/dist/compiler/detector/kernels/cpu/index.d.ts +1 -0
  41. package/dist/compiler/detector/kernels/cpu/index.js +25 -0
  42. package/dist/compiler/detector/kernels/cpu/prune.d.ts +1 -0
  43. package/dist/compiler/detector/kernels/cpu/prune.js +103 -0
  44. package/dist/compiler/detector/kernels/cpu/smoothHistograms.d.ts +6 -0
  45. package/dist/compiler/detector/kernels/cpu/smoothHistograms.js +47 -0
  46. package/dist/compiler/detector/kernels/cpu/upsampleBilinear.d.ts +6 -0
  47. package/dist/compiler/detector/kernels/cpu/upsampleBilinear.js +43 -0
  48. package/dist/compiler/detector/kernels/index.d.ts +1 -0
  49. package/dist/compiler/detector/kernels/index.js +2 -0
  50. package/dist/compiler/detector/kernels/webgl/binomialFilter.d.ts +6 -0
  51. package/dist/compiler/detector/kernels/webgl/binomialFilter.js +67 -0
  52. package/dist/compiler/detector/kernels/webgl/buildExtremas.d.ts +6 -0
  53. package/dist/compiler/detector/kernels/webgl/buildExtremas.js +101 -0
  54. package/dist/compiler/detector/kernels/webgl/computeExtremaAngles.d.ts +6 -0
  55. package/dist/compiler/detector/kernels/webgl/computeExtremaAngles.js +78 -0
  56. package/dist/compiler/detector/kernels/webgl/computeExtremaFreak.d.ts +6 -0
  57. package/dist/compiler/detector/kernels/webgl/computeExtremaFreak.js +86 -0
  58. package/dist/compiler/detector/kernels/webgl/computeFreakDescriptors.d.ts +6 -0
  59. package/dist/compiler/detector/kernels/webgl/computeFreakDescriptors.js +52 -0
  60. package/dist/compiler/detector/kernels/webgl/computeLocalization.d.ts +6 -0
  61. package/dist/compiler/detector/kernels/webgl/computeLocalization.js +58 -0
  62. package/dist/compiler/detector/kernels/webgl/computeOrientationHistograms.d.ts +6 -0
  63. package/dist/compiler/detector/kernels/webgl/computeOrientationHistograms.js +116 -0
  64. package/dist/compiler/detector/kernels/webgl/downsampleBilinear.d.ts +6 -0
  65. package/dist/compiler/detector/kernels/webgl/downsampleBilinear.js +46 -0
  66. package/dist/compiler/detector/kernels/webgl/extremaReduction.d.ts +6 -0
  67. package/dist/compiler/detector/kernels/webgl/extremaReduction.js +48 -0
  68. package/dist/compiler/detector/kernels/webgl/index.d.ts +1 -0
  69. package/dist/compiler/detector/kernels/webgl/index.js +25 -0
  70. package/dist/compiler/detector/kernels/webgl/smoothHistograms.d.ts +6 -0
  71. package/dist/compiler/detector/kernels/webgl/smoothHistograms.js +49 -0
  72. package/dist/compiler/detector/kernels/webgl/upsampleBilinear.d.ts +6 -0
  73. package/dist/compiler/detector/kernels/webgl/upsampleBilinear.js +56 -0
  74. package/dist/compiler/estimation/esimate-experiment.d.ts +5 -0
  75. package/dist/compiler/estimation/esimate-experiment.js +267 -0
  76. package/dist/compiler/estimation/estimate.d.ts +5 -0
  77. package/dist/compiler/estimation/estimate.js +51 -0
  78. package/dist/compiler/estimation/estimator.d.ts +13 -0
  79. package/dist/compiler/estimation/estimator.js +30 -0
  80. package/dist/compiler/estimation/refine-estimate-experiment.d.ts +6 -0
  81. package/dist/compiler/estimation/refine-estimate-experiment.js +429 -0
  82. package/dist/compiler/estimation/refine-estimate.d.ts +6 -0
  83. package/dist/compiler/estimation/refine-estimate.js +299 -0
  84. package/dist/compiler/estimation/utils.d.ts +10 -0
  85. package/dist/compiler/estimation/utils.js +80 -0
  86. package/dist/compiler/image-list.d.ts +13 -0
  87. package/dist/compiler/image-list.js +52 -0
  88. package/dist/compiler/index.d.ts +3 -0
  89. package/dist/compiler/index.js +10 -0
  90. package/dist/compiler/input-loader.d.ts +23 -0
  91. package/dist/compiler/input-loader.js +88 -0
  92. package/dist/compiler/matching/hamming-distance.d.ts +1 -0
  93. package/dist/compiler/matching/hamming-distance.js +20 -0
  94. package/dist/compiler/matching/hierarchical-clustering.d.ts +7 -0
  95. package/dist/compiler/matching/hierarchical-clustering.js +109 -0
  96. package/dist/compiler/matching/hough.d.ts +1 -0
  97. package/dist/compiler/matching/hough.js +169 -0
  98. package/dist/compiler/matching/matcher.d.ts +28 -0
  99. package/dist/compiler/matching/matcher.js +48 -0
  100. package/dist/compiler/matching/matching.d.ts +41 -0
  101. package/dist/compiler/matching/matching.js +197 -0
  102. package/dist/compiler/matching/ransacHomography.d.ts +1 -0
  103. package/dist/compiler/matching/ransacHomography.js +136 -0
  104. package/dist/compiler/offline-compiler.d.ts +10 -0
  105. package/dist/compiler/offline-compiler.js +450 -0
  106. package/dist/compiler/tensorflow-setup.d.ts +7 -0
  107. package/dist/compiler/tensorflow-setup.js +73 -0
  108. package/dist/compiler/three.d.ts +66 -0
  109. package/dist/compiler/three.js +310 -0
  110. package/dist/compiler/tracker/extract-utils.d.ts +1 -0
  111. package/dist/compiler/tracker/extract-utils.js +29 -0
  112. package/dist/compiler/tracker/extract.d.ts +4 -0
  113. package/dist/compiler/tracker/extract.js +349 -0
  114. package/dist/compiler/tracker/tracker.d.ts +38 -0
  115. package/dist/compiler/tracker/tracker.js +327 -0
  116. package/dist/compiler/utils/cumsum.d.ts +5 -0
  117. package/dist/compiler/utils/cumsum.js +39 -0
  118. package/dist/compiler/utils/geometry.d.ts +8 -0
  119. package/dist/compiler/utils/geometry.js +101 -0
  120. package/dist/compiler/utils/homography.d.ts +1 -0
  121. package/dist/compiler/utils/homography.js +138 -0
  122. package/dist/compiler/utils/images.d.ts +24 -0
  123. package/dist/compiler/utils/images.js +99 -0
  124. package/dist/compiler/utils/randomizer.d.ts +5 -0
  125. package/dist/compiler/utils/randomizer.js +25 -0
  126. package/dist/index.d.ts +6 -0
  127. package/dist/index.js +7 -0
  128. package/dist/react/AREditor.d.ts +5 -0
  129. package/dist/react/AREditor.js +159 -0
  130. package/dist/react/ProgressDialog.d.ts +13 -0
  131. package/dist/react/ProgressDialog.js +57 -0
  132. package/dist/react/types.d.ts +22 -0
  133. package/dist/react/types.js +14 -0
  134. package/package.json +53 -0
  135. package/src/astro/ARScene.astro +59 -0
  136. package/src/astro/ARVideoTrigger.astro +73 -0
  137. package/src/astro/overlays/ErrorOverlay.astro +40 -0
  138. package/src/astro/overlays/LoadingOverlay.astro +28 -0
  139. package/src/astro/overlays/ScanningOverlay.astro +119 -0
  140. package/src/astro/scripts/ARScripts.astro +118 -0
  141. package/src/astro/styles/ARStyles.astro +147 -0
  142. package/src/compiler/aframe.js +343 -0
  143. package/src/compiler/compiler-base.js +195 -0
  144. package/src/compiler/compiler.js +25 -0
  145. package/src/compiler/compiler.worker.js +30 -0
  146. package/src/compiler/controller.js +473 -0
  147. package/src/compiler/controller.worker.js +77 -0
  148. package/src/compiler/detector/crop-detector.js +68 -0
  149. package/src/compiler/detector/detector.js +1130 -0
  150. package/src/compiler/detector/freak.js +91 -0
  151. package/src/compiler/detector/kernels/cpu/binomialFilter.js +59 -0
  152. package/src/compiler/detector/kernels/cpu/buildExtremas.js +108 -0
  153. package/src/compiler/detector/kernels/cpu/computeExtremaAngles.js +91 -0
  154. package/src/compiler/detector/kernels/cpu/computeExtremaFreak.js +92 -0
  155. package/src/compiler/detector/kernels/cpu/computeFreakDescriptors.js +68 -0
  156. package/src/compiler/detector/kernels/cpu/computeLocalization.js +71 -0
  157. package/src/compiler/detector/kernels/cpu/computeOrientationHistograms.js +141 -0
  158. package/src/compiler/detector/kernels/cpu/downsampleBilinear.js +33 -0
  159. package/src/compiler/detector/kernels/cpu/extremaReduction.js +53 -0
  160. package/src/compiler/detector/kernels/cpu/fakeShader.js +88 -0
  161. package/src/compiler/detector/kernels/cpu/index.js +26 -0
  162. package/src/compiler/detector/kernels/cpu/prune.js +114 -0
  163. package/src/compiler/detector/kernels/cpu/smoothHistograms.js +57 -0
  164. package/src/compiler/detector/kernels/cpu/upsampleBilinear.js +51 -0
  165. package/src/compiler/detector/kernels/index.js +2 -0
  166. package/src/compiler/detector/kernels/webgl/binomialFilter.js +72 -0
  167. package/src/compiler/detector/kernels/webgl/buildExtremas.js +109 -0
  168. package/src/compiler/detector/kernels/webgl/computeExtremaAngles.js +82 -0
  169. package/src/compiler/detector/kernels/webgl/computeExtremaFreak.js +105 -0
  170. package/src/compiler/detector/kernels/webgl/computeFreakDescriptors.js +56 -0
  171. package/src/compiler/detector/kernels/webgl/computeLocalization.js +70 -0
  172. package/src/compiler/detector/kernels/webgl/computeOrientationHistograms.js +129 -0
  173. package/src/compiler/detector/kernels/webgl/downsampleBilinear.js +50 -0
  174. package/src/compiler/detector/kernels/webgl/extremaReduction.js +50 -0
  175. package/src/compiler/detector/kernels/webgl/index.js +26 -0
  176. package/src/compiler/detector/kernels/webgl/smoothHistograms.js +53 -0
  177. package/src/compiler/detector/kernels/webgl/upsampleBilinear.js +62 -0
  178. package/src/compiler/estimation/esimate-experiment.js +316 -0
  179. package/src/compiler/estimation/estimate.js +67 -0
  180. package/src/compiler/estimation/estimator.js +34 -0
  181. package/src/compiler/estimation/refine-estimate-experiment.js +512 -0
  182. package/src/compiler/estimation/refine-estimate.js +365 -0
  183. package/src/compiler/estimation/utils.js +97 -0
  184. package/src/compiler/image-list.js +62 -0
  185. package/src/compiler/index.js +13 -0
  186. package/src/compiler/input-loader.js +107 -0
  187. package/src/compiler/matching/hamming-distance.js +23 -0
  188. package/src/compiler/matching/hierarchical-clustering.js +131 -0
  189. package/src/compiler/matching/hough.js +206 -0
  190. package/src/compiler/matching/matcher.js +59 -0
  191. package/src/compiler/matching/matching.js +237 -0
  192. package/src/compiler/matching/ransacHomography.js +192 -0
  193. package/src/compiler/offline-compiler.js +553 -0
  194. package/src/compiler/tensorflow-setup.js +88 -0
  195. package/src/compiler/three.js +368 -0
  196. package/src/compiler/tracker/extract-utils.js +34 -0
  197. package/src/compiler/tracker/extract.js +419 -0
  198. package/src/compiler/tracker/tracker.js +397 -0
  199. package/src/compiler/utils/cumsum.js +40 -0
  200. package/src/compiler/utils/geometry.js +114 -0
  201. package/src/compiler/utils/homography.js +150 -0
  202. package/src/compiler/utils/images.js +111 -0
  203. package/src/compiler/utils/randomizer.js +29 -0
  204. package/src/index.ts +8 -0
  205. package/src/react/AREditor.tsx +394 -0
  206. package/src/react/ProgressDialog.tsx +185 -0
  207. package/src/react/types.ts +35 -0
@@ -0,0 +1,368 @@
1
+ import {
2
+ Matrix4,
3
+ Vector3,
4
+ Quaternion,
5
+ Scene,
6
+ WebGLRenderer,
7
+ PerspectiveCamera,
8
+ Group,
9
+ sRGBEncoding,
10
+ } from "three";
11
+ import * as tf from "@tensorflow/tfjs";
12
+ //import { CSS3DRenderer } from '../libs/CSS3DRenderer.js';
13
+ import { CSS3DRenderer } from "three/addons/renderers/CSS3DRenderer.js";
14
+ import { Controller } from "./controller.js";
15
+ import { UI } from "../ui/ui.js";
16
+
17
+ const cssScaleDownMatrix = new Matrix4();
18
+ cssScaleDownMatrix.compose(new Vector3(), new Quaternion(), new Vector3(0.001, 0.001, 0.001));
19
+
20
+ const invisibleMatrix = new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
21
+
22
+ export class MindARThree {
23
+ constructor({
24
+ container,
25
+ imageTargetSrc,
26
+ maxTrack,
27
+ uiLoading = "yes",
28
+ uiScanning = "yes",
29
+ uiError = "yes",
30
+ filterMinCF = null,
31
+ filterBeta = null,
32
+ warmupTolerance = null,
33
+ missTolerance = null,
34
+ userDeviceId = null,
35
+ environmentDeviceId = null,
36
+ }) {
37
+ this.container = container;
38
+ this.imageTargetSrc = imageTargetSrc;
39
+ this.maxTrack = maxTrack;
40
+ this.filterMinCF = filterMinCF;
41
+ this.filterBeta = filterBeta;
42
+ this.warmupTolerance = warmupTolerance;
43
+ this.missTolerance = missTolerance;
44
+ this.ui = new UI({ uiLoading, uiScanning, uiError });
45
+ this.userDeviceId = userDeviceId;
46
+ this.environmentDeviceId = environmentDeviceId;
47
+
48
+ this.shouldFaceUser = false;
49
+
50
+ this.scene = new Scene();
51
+ this.cssScene = new Scene();
52
+ this.renderer = new WebGLRenderer({ antialias: true, alpha: true });
53
+ this.cssRenderer = new CSS3DRenderer({ antialias: true });
54
+ this.renderer.outputEncoding = sRGBEncoding;
55
+ this.renderer.setPixelRatio(window.devicePixelRatio);
56
+ this.camera = new PerspectiveCamera();
57
+ this.anchors = [];
58
+
59
+ this.renderer.domElement.style.position = "absolute";
60
+ this.cssRenderer.domElement.style.position = "absolute";
61
+ this.container.appendChild(this.renderer.domElement);
62
+ this.container.appendChild(this.cssRenderer.domElement);
63
+
64
+ window.addEventListener("resize", this.resize.bind(this));
65
+ }
66
+
67
+ async start() {
68
+ this.ui.showLoading();
69
+ await this._startVideo();
70
+ await this._startAR();
71
+ }
72
+
73
+ stop() {
74
+ this.controller.stopProcessVideo();
75
+ const tracks = this.video.srcObject.getTracks();
76
+ tracks.forEach(function (track) {
77
+ track.stop();
78
+ });
79
+ this.video.remove();
80
+ }
81
+
82
+ switchCamera() {
83
+ this.shouldFaceUser = !this.shouldFaceUser;
84
+ this.stop();
85
+ this.start();
86
+ }
87
+
88
+ addAnchor(targetIndex) {
89
+ const group = new Group();
90
+ group.visible = false;
91
+ group.matrixAutoUpdate = false;
92
+ const anchor = {
93
+ group,
94
+ targetIndex,
95
+ onTargetFound: null,
96
+ onTargetLost: null,
97
+ onTargetUpdate: null,
98
+ css: false,
99
+ visible: false,
100
+ };
101
+ this.anchors.push(anchor);
102
+ this.scene.add(group);
103
+ return anchor;
104
+ }
105
+
106
+ addCSSAnchor(targetIndex) {
107
+ const group = new Group();
108
+ group.visible = false;
109
+ group.matrixAutoUpdate = false;
110
+ const anchor = {
111
+ group,
112
+ targetIndex,
113
+ onTargetFound: null,
114
+ onTargetLost: null,
115
+ onTargetUpdate: null,
116
+ css: true,
117
+ visible: false,
118
+ };
119
+ this.anchors.push(anchor);
120
+ this.cssScene.add(group);
121
+ return anchor;
122
+ }
123
+
124
+ _startVideo() {
125
+ return new Promise((resolve, reject) => {
126
+ this.video = document.createElement("video");
127
+
128
+ this.video.setAttribute("autoplay", "");
129
+ this.video.setAttribute("muted", "");
130
+ this.video.setAttribute("playsinline", "");
131
+ this.video.style.position = "absolute";
132
+ this.video.style.top = "0px";
133
+ this.video.style.left = "0px";
134
+ this.video.style.zIndex = "-2";
135
+ this.container.appendChild(this.video);
136
+
137
+ if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
138
+ this.ui.showCompatibility();
139
+ reject();
140
+ return;
141
+ }
142
+
143
+ const constraints = {
144
+ audio: false,
145
+ video: {},
146
+ };
147
+ if (this.shouldFaceUser) {
148
+ if (this.userDeviceId) {
149
+ constraints.video.deviceId = { exact: this.userDeviceId };
150
+ } else {
151
+ constraints.video.facingMode = "user";
152
+ }
153
+ } else {
154
+ if (this.environmentDeviceId) {
155
+ constraints.video.deviceId = { exact: this.environmentDeviceId };
156
+ } else {
157
+ constraints.video.facingMode = "environment";
158
+ }
159
+ }
160
+
161
+ navigator.mediaDevices
162
+ .getUserMedia(constraints)
163
+ .then((stream) => {
164
+ this.video.addEventListener("loadedmetadata", () => {
165
+ this.video.setAttribute("width", this.video.videoWidth);
166
+ this.video.setAttribute("height", this.video.videoHeight);
167
+ resolve();
168
+ });
169
+ this.video.srcObject = stream;
170
+ })
171
+ .catch((err) => {
172
+ console.log("getUserMedia error", err);
173
+ reject();
174
+ });
175
+ });
176
+ }
177
+
178
+ _startAR() {
179
+ return new Promise(async (resolve, reject) => {
180
+ const video = this.video;
181
+ const container = this.container;
182
+
183
+ this.controller = new Controller({
184
+ inputWidth: video.videoWidth,
185
+ inputHeight: video.videoHeight,
186
+ filterMinCF: this.filterMinCF,
187
+ filterBeta: this.filterBeta,
188
+ warmupTolerance: this.warmupTolerance,
189
+ missTolerance: this.missTolerance,
190
+ maxTrack: this.maxTrack,
191
+ onUpdate: (data) => {
192
+ if (data.type === "updateMatrix") {
193
+ const { targetIndex, worldMatrix } = data;
194
+
195
+ for (let i = 0; i < this.anchors.length; i++) {
196
+ if (this.anchors[i].targetIndex === targetIndex) {
197
+ if (this.anchors[i].css) {
198
+ this.anchors[i].group.children.forEach((obj) => {
199
+ obj.element.style.visibility = worldMatrix === null ? "hidden" : "visible";
200
+ });
201
+ } else {
202
+ this.anchors[i].group.visible = worldMatrix !== null;
203
+ }
204
+
205
+ if (worldMatrix !== null) {
206
+ let m = new Matrix4();
207
+ m.elements = [...worldMatrix];
208
+ m.multiply(this.postMatrixs[targetIndex]);
209
+ if (this.anchors[i].css) {
210
+ m.multiply(cssScaleDownMatrix);
211
+ }
212
+ this.anchors[i].group.matrix = m;
213
+ } else {
214
+ this.anchors[i].group.matrix = invisibleMatrix;
215
+ }
216
+
217
+ if (this.anchors[i].visible && worldMatrix === null) {
218
+ this.anchors[i].visible = false;
219
+ if (this.anchors[i].onTargetLost) {
220
+ this.anchors[i].onTargetLost();
221
+ }
222
+ }
223
+
224
+ if (!this.anchors[i].visible && worldMatrix !== null) {
225
+ this.anchors[i].visible = true;
226
+ if (this.anchors[i].onTargetFound) {
227
+ this.anchors[i].onTargetFound();
228
+ }
229
+ }
230
+
231
+ if (this.anchors[i].onTargetUpdate) {
232
+ this.anchors[i].onTargetUpdate();
233
+ }
234
+ }
235
+ }
236
+
237
+ let isAnyVisible = this.anchors.reduce((acc, anchor) => {
238
+ return acc || anchor.visible;
239
+ }, false);
240
+ if (isAnyVisible) {
241
+ this.ui.hideScanning();
242
+ } else {
243
+ this.ui.showScanning();
244
+ }
245
+ }
246
+ },
247
+ });
248
+
249
+ this.resize();
250
+
251
+ const { dimensions: imageTargetDimensions } = await this.controller.addImageTargets(
252
+ this.imageTargetSrc,
253
+ );
254
+
255
+ this.postMatrixs = [];
256
+ for (let i = 0; i < imageTargetDimensions.length; i++) {
257
+ const position = new Vector3();
258
+ const quaternion = new Quaternion();
259
+ const scale = new Vector3();
260
+ const [markerWidth, markerHeight] = imageTargetDimensions[i];
261
+ position.x = markerWidth / 2;
262
+ position.y = markerWidth / 2 + (markerHeight - markerWidth) / 2;
263
+ scale.x = markerWidth;
264
+ scale.y = markerWidth;
265
+ scale.z = markerWidth;
266
+ const postMatrix = new Matrix4();
267
+ postMatrix.compose(position, quaternion, scale);
268
+ this.postMatrixs.push(postMatrix);
269
+ }
270
+
271
+ await this.controller.dummyRun(this.video);
272
+ this.ui.hideLoading();
273
+ this.ui.showScanning();
274
+
275
+ this.controller.processVideo(this.video);
276
+ resolve();
277
+ });
278
+ }
279
+
280
+ resize() {
281
+ const { renderer, cssRenderer, camera, container, video } = this;
282
+ if (!video) return;
283
+
284
+ this.video.setAttribute("width", this.video.videoWidth);
285
+ this.video.setAttribute("height", this.video.videoHeight);
286
+
287
+ let vw, vh; // display css width, height
288
+ const videoRatio = video.videoWidth / video.videoHeight;
289
+ const containerRatio = container.clientWidth / container.clientHeight;
290
+ if (videoRatio > containerRatio) {
291
+ vh = container.clientHeight;
292
+ vw = vh * videoRatio;
293
+ } else {
294
+ vw = container.clientWidth;
295
+ vh = vw / videoRatio;
296
+ }
297
+
298
+ const proj = this.controller.getProjectionMatrix();
299
+
300
+ // TODO: move this logic to controller
301
+ // Handle when phone is rotated, video width and height are swapped
302
+ const inputRatio = this.controller.inputWidth / this.controller.inputHeight;
303
+ let inputAdjust;
304
+ if (inputRatio > containerRatio) {
305
+ inputAdjust = this.video.width / this.controller.inputWidth;
306
+ } else {
307
+ inputAdjust = this.video.height / this.controller.inputHeight;
308
+ }
309
+ let videoDisplayHeight;
310
+ let videoDisplayWidth;
311
+ if (inputRatio > containerRatio) {
312
+ videoDisplayHeight = container.clientHeight;
313
+ videoDisplayHeight *= inputAdjust;
314
+ } else {
315
+ videoDisplayWidth = container.clientWidth;
316
+ videoDisplayHeight =
317
+ (videoDisplayWidth / this.controller.inputWidth) * this.controller.inputHeight;
318
+ videoDisplayHeight *= inputAdjust;
319
+ }
320
+ let fovAdjust = container.clientHeight / videoDisplayHeight;
321
+
322
+ // const fov = 2 * Math.atan(1 / proj[5] / vh * container.clientHeight) * 180 / Math.PI; // vertical fov
323
+ const fov = (2 * Math.atan((1 / proj[5]) * fovAdjust) * 180) / Math.PI; // vertical fov
324
+ const near = proj[14] / (proj[10] - 1.0);
325
+ const far = proj[14] / (proj[10] + 1.0);
326
+ const ratio = proj[5] / proj[0]; // (r-l) / (t-b)
327
+
328
+ camera.fov = fov;
329
+ camera.near = near;
330
+ camera.far = far;
331
+ camera.aspect = container.clientWidth / container.clientHeight;
332
+ camera.updateProjectionMatrix();
333
+
334
+ video.style.top = -(vh - container.clientHeight) / 2 + "px";
335
+ video.style.left = -(vw - container.clientWidth) / 2 + "px";
336
+ video.style.width = vw + "px";
337
+ video.style.height = vh + "px";
338
+
339
+ const canvas = renderer.domElement;
340
+ const cssCanvas = cssRenderer.domElement;
341
+
342
+ canvas.style.position = "absolute";
343
+ canvas.style.left = 0;
344
+ canvas.style.top = 0;
345
+ canvas.style.width = container.clientWidth + "px";
346
+ canvas.style.height = container.clientHeight + "px";
347
+
348
+ cssCanvas.style.position = "absolute";
349
+ cssCanvas.style.left = 0;
350
+ cssCanvas.style.top = 0;
351
+ cssCanvas.style.width = container.clientWidth + "px";
352
+ cssCanvas.style.height = container.clientHeight + "px";
353
+
354
+ renderer.setSize(container.clientWidth, container.clientHeight);
355
+ cssRenderer.setSize(container.clientWidth, container.clientHeight);
356
+ }
357
+ }
358
+
359
+ if (!window.MINDAR) {
360
+ window.MINDAR = {};
361
+ }
362
+ if (!window.MINDAR.IMAGE) {
363
+ window.MINDAR.IMAGE = {};
364
+ }
365
+
366
+ window.MINDAR.IMAGE.MindARThree = MindARThree;
367
+ //window.MINDAR.IMAGE.THREE = THREE;
368
+ window.MINDAR.IMAGE.tf = tf;
@@ -0,0 +1,34 @@
1
+ import { extract } from "./extract.js";
2
+
3
+ /**
4
+ * Extrae características de tracking de una lista de imágenes
5
+ * Procesa cada imagen para obtener puntos característicos y datos de escala
6
+ * @param {Array<Object>} imageList - Lista de imágenes a procesar
7
+ * @param {Function} doneCallback - Función de callback para reportar progreso
8
+ * @returns {Array<Object>} Conjunto de características extraídas
9
+ */
10
+ export const extractTrackingFeatures = (imageList, doneCallback) => {
11
+ const featureSets = [];
12
+
13
+ // Procesar cada imagen en la lista
14
+ for (let i = 0; i < imageList.length; i++) {
15
+ const image = imageList[i];
16
+
17
+ // Extraer puntos característicos
18
+ const points = extract(image);
19
+
20
+ // Construir conjunto de características
21
+ const featureSet = {
22
+ data: image.data,
23
+ scale: image.scale,
24
+ width: image.width,
25
+ height: image.height,
26
+ points,
27
+ };
28
+ featureSets.push(featureSet);
29
+
30
+ // Reportar progreso
31
+ doneCallback(i);
32
+ }
33
+ return featureSets;
34
+ };