@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,73 @@
1
+ import * as tf from "@tensorflow/tfjs";
2
+ // Registrar backends básicos
3
+ import "@tensorflow/tfjs-backend-cpu";
4
+ import "@tensorflow/tfjs-backend-webgl";
5
+ // Registrar kernels personalizados
6
+ import "./detector/kernels/cpu/index.js";
7
+ import "./detector/kernels/webgl/index.js";
8
+ /**
9
+ * Configuración optimizada de TensorFlow para diferentes entornos
10
+ * @returns {Promise<string>} El backend activo ('webgl', 'cpu')
11
+ */
12
+ export async function setupTensorFlow() {
13
+ console.log("🔧 Iniciando configuración optimizada de TensorFlow.js...");
14
+ try {
15
+ // Optimizaciones base para todos los backends
16
+ tf.ENV.set("DEBUG", false);
17
+ tf.ENV.set("WEBGL_CPU_FORWARD", false);
18
+ tf.ENV.set("WEBGL_FORCE_F16_TEXTURES", true);
19
+ // Configuración adaptativa de memoria según el entorno
20
+ const isServerless = typeof window === "undefined";
21
+ const memoryThreshold = isServerless ? 1024 * 1024 * 4 : 1024 * 1024 * 8; // 4MB en serverless, 8MB en cliente
22
+ tf.ENV.set("CPU_HANDOFF_SIZE_THRESHOLD", memoryThreshold);
23
+ // Configuración específica para entorno serverless
24
+ if (isServerless) {
25
+ try {
26
+ await tf.setBackend("cpu");
27
+ console.log("🚀 Backend CPU optimizado para entorno serverless");
28
+ // Optimizaciones específicas para CPU en serverless
29
+ tf.ENV.set("CPU_HANDOFF_SIZE_THRESHOLD", 1024 * 1024 * 2); // 2MB
30
+ tf.ENV.set("WEBGL_DELETE_TEXTURE_THRESHOLD", 0);
31
+ // Precalentar el backend
32
+ await tf.ready();
33
+ return "cpu";
34
+ }
35
+ catch (cpuError) {
36
+ console.error("❌ Error crítico en configuración CPU:", cpuError);
37
+ throw new Error("No se pudo inicializar TensorFlow.js en modo serverless");
38
+ }
39
+ }
40
+ // Configuración optimizada para navegador (WebGL)
41
+ try {
42
+ // Optimizaciones avanzadas para WebGL
43
+ tf.ENV.set("WEBGL_PACK", true);
44
+ tf.ENV.set("WEBGL_PACK_DEPTHWISECONV", true);
45
+ tf.ENV.set("WEBGL_MAX_TEXTURE_SIZE", 4096);
46
+ tf.ENV.set("WEBGL_USE_SHAPES_UNIFORMS", true);
47
+ tf.ENV.set("WEBGL_CONV_IM2COL", true);
48
+ await tf.setBackend("webgl");
49
+ console.log("🎮 Backend WebGL activado con optimizaciones avanzadas");
50
+ // Precalentar el backend
51
+ await tf.ready();
52
+ return "webgl";
53
+ }
54
+ catch (webglError) {
55
+ console.warn(`No se pudo activar WebGL: ${webglError.message}, usando CPU como último recurso`);
56
+ }
57
+ // CPU Backend (más lento, último recurso)
58
+ await tf.setBackend("cpu");
59
+ console.log("⚠️ Backend CPU activado (rendimiento sub-óptimo)");
60
+ // Optimizaciones específicas para CPU
61
+ tf.ENV.set("CPU_HANDOFF_SIZE_THRESHOLD", 1024 * 1024 * 2); // 2MB
62
+ }
63
+ catch (error) {
64
+ console.error("Error crítico configurando backends de TensorFlow:", error);
65
+ throw new Error("No se pudo inicializar TensorFlow.js con ningún backend");
66
+ }
67
+ // Registrar kernels específicos para el backend activo
68
+ const backend = tf.getBackend();
69
+ console.log(`Backend activo: ${backend}`);
70
+ return backend;
71
+ }
72
+ // Exportamos tf para poder usarlo en otros archivos
73
+ export { tf };
@@ -0,0 +1,66 @@
1
+ export class MindARThree {
2
+ constructor({ container, imageTargetSrc, maxTrack, uiLoading, uiScanning, uiError, filterMinCF, filterBeta, warmupTolerance, missTolerance, userDeviceId, environmentDeviceId, }: {
3
+ container: any;
4
+ imageTargetSrc: any;
5
+ maxTrack: any;
6
+ uiLoading?: string | undefined;
7
+ uiScanning?: string | undefined;
8
+ uiError?: string | undefined;
9
+ filterMinCF?: null | undefined;
10
+ filterBeta?: null | undefined;
11
+ warmupTolerance?: null | undefined;
12
+ missTolerance?: null | undefined;
13
+ userDeviceId?: null | undefined;
14
+ environmentDeviceId?: null | undefined;
15
+ });
16
+ container: any;
17
+ imageTargetSrc: any;
18
+ maxTrack: any;
19
+ filterMinCF: any;
20
+ filterBeta: any;
21
+ warmupTolerance: any;
22
+ missTolerance: any;
23
+ ui: any;
24
+ userDeviceId: any;
25
+ environmentDeviceId: any;
26
+ shouldFaceUser: boolean;
27
+ scene: Scene;
28
+ cssScene: Scene;
29
+ renderer: WebGLRenderer;
30
+ cssRenderer: CSS3DRenderer;
31
+ camera: PerspectiveCamera;
32
+ anchors: any[];
33
+ start(): Promise<void>;
34
+ stop(): void;
35
+ switchCamera(): void;
36
+ addAnchor(targetIndex: any): {
37
+ group: Group<import("three").Object3DEventMap>;
38
+ targetIndex: any;
39
+ onTargetFound: null;
40
+ onTargetLost: null;
41
+ onTargetUpdate: null;
42
+ css: boolean;
43
+ visible: boolean;
44
+ };
45
+ addCSSAnchor(targetIndex: any): {
46
+ group: Group<import("three").Object3DEventMap>;
47
+ targetIndex: any;
48
+ onTargetFound: null;
49
+ onTargetLost: null;
50
+ onTargetUpdate: null;
51
+ css: boolean;
52
+ visible: boolean;
53
+ };
54
+ _startVideo(): Promise<any>;
55
+ video: HTMLVideoElement | undefined;
56
+ _startAR(): Promise<any>;
57
+ controller: Controller | undefined;
58
+ postMatrixs: any[] | undefined;
59
+ resize(): void;
60
+ }
61
+ import { Scene } from "three";
62
+ import { WebGLRenderer } from "three";
63
+ import { CSS3DRenderer } from "three/addons/renderers/CSS3DRenderer.js";
64
+ import { PerspectiveCamera } from "three";
65
+ import { Group } from "three";
66
+ import { Controller } from "./controller.js";
@@ -0,0 +1,310 @@
1
+ import { Matrix4, Vector3, Quaternion, Scene, WebGLRenderer, PerspectiveCamera, Group, sRGBEncoding, } from "three";
2
+ import * as tf from "@tensorflow/tfjs";
3
+ //import { CSS3DRenderer } from '../libs/CSS3DRenderer.js';
4
+ import { CSS3DRenderer } from "three/addons/renderers/CSS3DRenderer.js";
5
+ import { Controller } from "./controller.js";
6
+ import { UI } from "../ui/ui.js";
7
+ const cssScaleDownMatrix = new Matrix4();
8
+ cssScaleDownMatrix.compose(new Vector3(), new Quaternion(), new Vector3(0.001, 0.001, 0.001));
9
+ const invisibleMatrix = new Matrix4().set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
10
+ export class MindARThree {
11
+ constructor({ container, imageTargetSrc, maxTrack, uiLoading = "yes", uiScanning = "yes", uiError = "yes", filterMinCF = null, filterBeta = null, warmupTolerance = null, missTolerance = null, userDeviceId = null, environmentDeviceId = null, }) {
12
+ this.container = container;
13
+ this.imageTargetSrc = imageTargetSrc;
14
+ this.maxTrack = maxTrack;
15
+ this.filterMinCF = filterMinCF;
16
+ this.filterBeta = filterBeta;
17
+ this.warmupTolerance = warmupTolerance;
18
+ this.missTolerance = missTolerance;
19
+ this.ui = new UI({ uiLoading, uiScanning, uiError });
20
+ this.userDeviceId = userDeviceId;
21
+ this.environmentDeviceId = environmentDeviceId;
22
+ this.shouldFaceUser = false;
23
+ this.scene = new Scene();
24
+ this.cssScene = new Scene();
25
+ this.renderer = new WebGLRenderer({ antialias: true, alpha: true });
26
+ this.cssRenderer = new CSS3DRenderer({ antialias: true });
27
+ this.renderer.outputEncoding = sRGBEncoding;
28
+ this.renderer.setPixelRatio(window.devicePixelRatio);
29
+ this.camera = new PerspectiveCamera();
30
+ this.anchors = [];
31
+ this.renderer.domElement.style.position = "absolute";
32
+ this.cssRenderer.domElement.style.position = "absolute";
33
+ this.container.appendChild(this.renderer.domElement);
34
+ this.container.appendChild(this.cssRenderer.domElement);
35
+ window.addEventListener("resize", this.resize.bind(this));
36
+ }
37
+ async start() {
38
+ this.ui.showLoading();
39
+ await this._startVideo();
40
+ await this._startAR();
41
+ }
42
+ stop() {
43
+ this.controller.stopProcessVideo();
44
+ const tracks = this.video.srcObject.getTracks();
45
+ tracks.forEach(function (track) {
46
+ track.stop();
47
+ });
48
+ this.video.remove();
49
+ }
50
+ switchCamera() {
51
+ this.shouldFaceUser = !this.shouldFaceUser;
52
+ this.stop();
53
+ this.start();
54
+ }
55
+ addAnchor(targetIndex) {
56
+ const group = new Group();
57
+ group.visible = false;
58
+ group.matrixAutoUpdate = false;
59
+ const anchor = {
60
+ group,
61
+ targetIndex,
62
+ onTargetFound: null,
63
+ onTargetLost: null,
64
+ onTargetUpdate: null,
65
+ css: false,
66
+ visible: false,
67
+ };
68
+ this.anchors.push(anchor);
69
+ this.scene.add(group);
70
+ return anchor;
71
+ }
72
+ addCSSAnchor(targetIndex) {
73
+ const group = new Group();
74
+ group.visible = false;
75
+ group.matrixAutoUpdate = false;
76
+ const anchor = {
77
+ group,
78
+ targetIndex,
79
+ onTargetFound: null,
80
+ onTargetLost: null,
81
+ onTargetUpdate: null,
82
+ css: true,
83
+ visible: false,
84
+ };
85
+ this.anchors.push(anchor);
86
+ this.cssScene.add(group);
87
+ return anchor;
88
+ }
89
+ _startVideo() {
90
+ return new Promise((resolve, reject) => {
91
+ this.video = document.createElement("video");
92
+ this.video.setAttribute("autoplay", "");
93
+ this.video.setAttribute("muted", "");
94
+ this.video.setAttribute("playsinline", "");
95
+ this.video.style.position = "absolute";
96
+ this.video.style.top = "0px";
97
+ this.video.style.left = "0px";
98
+ this.video.style.zIndex = "-2";
99
+ this.container.appendChild(this.video);
100
+ if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
101
+ this.ui.showCompatibility();
102
+ reject();
103
+ return;
104
+ }
105
+ const constraints = {
106
+ audio: false,
107
+ video: {},
108
+ };
109
+ if (this.shouldFaceUser) {
110
+ if (this.userDeviceId) {
111
+ constraints.video.deviceId = { exact: this.userDeviceId };
112
+ }
113
+ else {
114
+ constraints.video.facingMode = "user";
115
+ }
116
+ }
117
+ else {
118
+ if (this.environmentDeviceId) {
119
+ constraints.video.deviceId = { exact: this.environmentDeviceId };
120
+ }
121
+ else {
122
+ constraints.video.facingMode = "environment";
123
+ }
124
+ }
125
+ navigator.mediaDevices
126
+ .getUserMedia(constraints)
127
+ .then((stream) => {
128
+ this.video.addEventListener("loadedmetadata", () => {
129
+ this.video.setAttribute("width", this.video.videoWidth);
130
+ this.video.setAttribute("height", this.video.videoHeight);
131
+ resolve();
132
+ });
133
+ this.video.srcObject = stream;
134
+ })
135
+ .catch((err) => {
136
+ console.log("getUserMedia error", err);
137
+ reject();
138
+ });
139
+ });
140
+ }
141
+ _startAR() {
142
+ return new Promise(async (resolve, reject) => {
143
+ const video = this.video;
144
+ const container = this.container;
145
+ this.controller = new Controller({
146
+ inputWidth: video.videoWidth,
147
+ inputHeight: video.videoHeight,
148
+ filterMinCF: this.filterMinCF,
149
+ filterBeta: this.filterBeta,
150
+ warmupTolerance: this.warmupTolerance,
151
+ missTolerance: this.missTolerance,
152
+ maxTrack: this.maxTrack,
153
+ onUpdate: (data) => {
154
+ if (data.type === "updateMatrix") {
155
+ const { targetIndex, worldMatrix } = data;
156
+ for (let i = 0; i < this.anchors.length; i++) {
157
+ if (this.anchors[i].targetIndex === targetIndex) {
158
+ if (this.anchors[i].css) {
159
+ this.anchors[i].group.children.forEach((obj) => {
160
+ obj.element.style.visibility = worldMatrix === null ? "hidden" : "visible";
161
+ });
162
+ }
163
+ else {
164
+ this.anchors[i].group.visible = worldMatrix !== null;
165
+ }
166
+ if (worldMatrix !== null) {
167
+ let m = new Matrix4();
168
+ m.elements = [...worldMatrix];
169
+ m.multiply(this.postMatrixs[targetIndex]);
170
+ if (this.anchors[i].css) {
171
+ m.multiply(cssScaleDownMatrix);
172
+ }
173
+ this.anchors[i].group.matrix = m;
174
+ }
175
+ else {
176
+ this.anchors[i].group.matrix = invisibleMatrix;
177
+ }
178
+ if (this.anchors[i].visible && worldMatrix === null) {
179
+ this.anchors[i].visible = false;
180
+ if (this.anchors[i].onTargetLost) {
181
+ this.anchors[i].onTargetLost();
182
+ }
183
+ }
184
+ if (!this.anchors[i].visible && worldMatrix !== null) {
185
+ this.anchors[i].visible = true;
186
+ if (this.anchors[i].onTargetFound) {
187
+ this.anchors[i].onTargetFound();
188
+ }
189
+ }
190
+ if (this.anchors[i].onTargetUpdate) {
191
+ this.anchors[i].onTargetUpdate();
192
+ }
193
+ }
194
+ }
195
+ let isAnyVisible = this.anchors.reduce((acc, anchor) => {
196
+ return acc || anchor.visible;
197
+ }, false);
198
+ if (isAnyVisible) {
199
+ this.ui.hideScanning();
200
+ }
201
+ else {
202
+ this.ui.showScanning();
203
+ }
204
+ }
205
+ },
206
+ });
207
+ this.resize();
208
+ const { dimensions: imageTargetDimensions } = await this.controller.addImageTargets(this.imageTargetSrc);
209
+ this.postMatrixs = [];
210
+ for (let i = 0; i < imageTargetDimensions.length; i++) {
211
+ const position = new Vector3();
212
+ const quaternion = new Quaternion();
213
+ const scale = new Vector3();
214
+ const [markerWidth, markerHeight] = imageTargetDimensions[i];
215
+ position.x = markerWidth / 2;
216
+ position.y = markerWidth / 2 + (markerHeight - markerWidth) / 2;
217
+ scale.x = markerWidth;
218
+ scale.y = markerWidth;
219
+ scale.z = markerWidth;
220
+ const postMatrix = new Matrix4();
221
+ postMatrix.compose(position, quaternion, scale);
222
+ this.postMatrixs.push(postMatrix);
223
+ }
224
+ await this.controller.dummyRun(this.video);
225
+ this.ui.hideLoading();
226
+ this.ui.showScanning();
227
+ this.controller.processVideo(this.video);
228
+ resolve();
229
+ });
230
+ }
231
+ resize() {
232
+ const { renderer, cssRenderer, camera, container, video } = this;
233
+ if (!video)
234
+ return;
235
+ this.video.setAttribute("width", this.video.videoWidth);
236
+ this.video.setAttribute("height", this.video.videoHeight);
237
+ let vw, vh; // display css width, height
238
+ const videoRatio = video.videoWidth / video.videoHeight;
239
+ const containerRatio = container.clientWidth / container.clientHeight;
240
+ if (videoRatio > containerRatio) {
241
+ vh = container.clientHeight;
242
+ vw = vh * videoRatio;
243
+ }
244
+ else {
245
+ vw = container.clientWidth;
246
+ vh = vw / videoRatio;
247
+ }
248
+ const proj = this.controller.getProjectionMatrix();
249
+ // TODO: move this logic to controller
250
+ // Handle when phone is rotated, video width and height are swapped
251
+ const inputRatio = this.controller.inputWidth / this.controller.inputHeight;
252
+ let inputAdjust;
253
+ if (inputRatio > containerRatio) {
254
+ inputAdjust = this.video.width / this.controller.inputWidth;
255
+ }
256
+ else {
257
+ inputAdjust = this.video.height / this.controller.inputHeight;
258
+ }
259
+ let videoDisplayHeight;
260
+ let videoDisplayWidth;
261
+ if (inputRatio > containerRatio) {
262
+ videoDisplayHeight = container.clientHeight;
263
+ videoDisplayHeight *= inputAdjust;
264
+ }
265
+ else {
266
+ videoDisplayWidth = container.clientWidth;
267
+ videoDisplayHeight =
268
+ (videoDisplayWidth / this.controller.inputWidth) * this.controller.inputHeight;
269
+ videoDisplayHeight *= inputAdjust;
270
+ }
271
+ let fovAdjust = container.clientHeight / videoDisplayHeight;
272
+ // const fov = 2 * Math.atan(1 / proj[5] / vh * container.clientHeight) * 180 / Math.PI; // vertical fov
273
+ const fov = (2 * Math.atan((1 / proj[5]) * fovAdjust) * 180) / Math.PI; // vertical fov
274
+ const near = proj[14] / (proj[10] - 1.0);
275
+ const far = proj[14] / (proj[10] + 1.0);
276
+ const ratio = proj[5] / proj[0]; // (r-l) / (t-b)
277
+ camera.fov = fov;
278
+ camera.near = near;
279
+ camera.far = far;
280
+ camera.aspect = container.clientWidth / container.clientHeight;
281
+ camera.updateProjectionMatrix();
282
+ video.style.top = -(vh - container.clientHeight) / 2 + "px";
283
+ video.style.left = -(vw - container.clientWidth) / 2 + "px";
284
+ video.style.width = vw + "px";
285
+ video.style.height = vh + "px";
286
+ const canvas = renderer.domElement;
287
+ const cssCanvas = cssRenderer.domElement;
288
+ canvas.style.position = "absolute";
289
+ canvas.style.left = 0;
290
+ canvas.style.top = 0;
291
+ canvas.style.width = container.clientWidth + "px";
292
+ canvas.style.height = container.clientHeight + "px";
293
+ cssCanvas.style.position = "absolute";
294
+ cssCanvas.style.left = 0;
295
+ cssCanvas.style.top = 0;
296
+ cssCanvas.style.width = container.clientWidth + "px";
297
+ cssCanvas.style.height = container.clientHeight + "px";
298
+ renderer.setSize(container.clientWidth, container.clientHeight);
299
+ cssRenderer.setSize(container.clientWidth, container.clientHeight);
300
+ }
301
+ }
302
+ if (!window.MINDAR) {
303
+ window.MINDAR = {};
304
+ }
305
+ if (!window.MINDAR.IMAGE) {
306
+ window.MINDAR.IMAGE = {};
307
+ }
308
+ window.MINDAR.IMAGE.MindARThree = MindARThree;
309
+ //window.MINDAR.IMAGE.THREE = THREE;
310
+ window.MINDAR.IMAGE.tf = tf;
@@ -0,0 +1 @@
1
+ export function extractTrackingFeatures(imageList: Array<Object>, doneCallback: Function): Array<Object>;
@@ -0,0 +1,29 @@
1
+ import { extract } from "./extract.js";
2
+ /**
3
+ * Extrae características de tracking de una lista de imágenes
4
+ * Procesa cada imagen para obtener puntos característicos y datos de escala
5
+ * @param {Array<Object>} imageList - Lista de imágenes a procesar
6
+ * @param {Function} doneCallback - Función de callback para reportar progreso
7
+ * @returns {Array<Object>} Conjunto de características extraídas
8
+ */
9
+ export const extractTrackingFeatures = (imageList, doneCallback) => {
10
+ const featureSets = [];
11
+ // Procesar cada imagen en la lista
12
+ for (let i = 0; i < imageList.length; i++) {
13
+ const image = imageList[i];
14
+ // Extraer puntos característicos
15
+ const points = extract(image);
16
+ // Construir conjunto de características
17
+ const featureSet = {
18
+ data: image.data,
19
+ scale: image.scale,
20
+ width: image.width,
21
+ height: image.height,
22
+ points,
23
+ };
24
+ featureSets.push(featureSet);
25
+ // Reportar progreso
26
+ doneCallback(i);
27
+ }
28
+ return featureSets;
29
+ };
@@ -0,0 +1,4 @@
1
+ export function extract(image: any): {
2
+ x: number;
3
+ y: number;
4
+ }[];