@srsergio/taptapp-ar 1.0.26 → 1.0.27
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.
- package/dist/compiler/simple-ar.d.ts +39 -22
- package/dist/compiler/simple-ar.js +23 -10
- package/package.json +1 -1
- package/src/compiler/simple-ar.js +24 -10
|
@@ -15,32 +15,49 @@
|
|
|
15
15
|
* await ar.start();
|
|
16
16
|
*/
|
|
17
17
|
export class SimpleAR {
|
|
18
|
+
/**
|
|
19
|
+
* @param {Object} options
|
|
20
|
+
* @param {HTMLElement} options.container
|
|
21
|
+
* @param {string|string[]} options.targetSrc
|
|
22
|
+
* @param {HTMLElement} options.overlay
|
|
23
|
+
* @param {number} [options.scale=1.0]
|
|
24
|
+
* @param {((data: {targetIndex: number}) => void | Promise<void>) | null} [options.onFound]
|
|
25
|
+
* @param {((data: {targetIndex: number}) => void | Promise<void>) | null} [options.onLost]
|
|
26
|
+
* @param {((data: {targetIndex: number, worldMatrix: number[]}) => void) | null} [options.onUpdate]
|
|
27
|
+
* @param {Object} [options.cameraConfig]
|
|
28
|
+
*/
|
|
18
29
|
constructor({ container, targetSrc, overlay, scale, onFound, onLost, onUpdate, cameraConfig, }: {
|
|
19
|
-
container:
|
|
20
|
-
targetSrc:
|
|
21
|
-
overlay:
|
|
30
|
+
container: HTMLElement;
|
|
31
|
+
targetSrc: string | string[];
|
|
32
|
+
overlay: HTMLElement;
|
|
22
33
|
scale?: number | undefined;
|
|
23
|
-
onFound?:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
onFound?: ((data: {
|
|
35
|
+
targetIndex: number;
|
|
36
|
+
}) => void | Promise<void>) | null | undefined;
|
|
37
|
+
onLost?: ((data: {
|
|
38
|
+
targetIndex: number;
|
|
39
|
+
}) => void | Promise<void>) | null | undefined;
|
|
40
|
+
onUpdate?: ((data: {
|
|
41
|
+
targetIndex: number;
|
|
42
|
+
worldMatrix: number[];
|
|
43
|
+
}) => void) | null | undefined;
|
|
44
|
+
cameraConfig?: Object | undefined;
|
|
31
45
|
});
|
|
32
|
-
container:
|
|
33
|
-
targetSrc:
|
|
34
|
-
overlay:
|
|
46
|
+
container: HTMLElement;
|
|
47
|
+
targetSrc: string | string[];
|
|
48
|
+
overlay: HTMLElement;
|
|
35
49
|
scaleMultiplier: number;
|
|
36
|
-
onFound:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
onFound: ((data: {
|
|
51
|
+
targetIndex: number;
|
|
52
|
+
}) => void | Promise<void>) | null;
|
|
53
|
+
onLost: ((data: {
|
|
54
|
+
targetIndex: number;
|
|
55
|
+
}) => void | Promise<void>) | null;
|
|
56
|
+
onUpdateCallback: ((data: {
|
|
57
|
+
targetIndex: number;
|
|
58
|
+
worldMatrix: number[];
|
|
59
|
+
}) => void) | null;
|
|
60
|
+
cameraConfig: Object;
|
|
44
61
|
video: HTMLVideoElement | null;
|
|
45
62
|
controller: Controller | null;
|
|
46
63
|
isTracking: boolean;
|
|
@@ -16,6 +16,17 @@ import { Controller } from "./controller.js";
|
|
|
16
16
|
* await ar.start();
|
|
17
17
|
*/
|
|
18
18
|
class SimpleAR {
|
|
19
|
+
/**
|
|
20
|
+
* @param {Object} options
|
|
21
|
+
* @param {HTMLElement} options.container
|
|
22
|
+
* @param {string|string[]} options.targetSrc
|
|
23
|
+
* @param {HTMLElement} options.overlay
|
|
24
|
+
* @param {number} [options.scale=1.0]
|
|
25
|
+
* @param {((data: {targetIndex: number}) => void | Promise<void>) | null} [options.onFound]
|
|
26
|
+
* @param {((data: {targetIndex: number}) => void | Promise<void>) | null} [options.onLost]
|
|
27
|
+
* @param {((data: {targetIndex: number, worldMatrix: number[]}) => void) | null} [options.onUpdate]
|
|
28
|
+
* @param {Object} [options.cameraConfig]
|
|
29
|
+
*/
|
|
19
30
|
constructor({ container, targetSrc, overlay, scale = 1.0, // Multiplicador de escala personalizado
|
|
20
31
|
onFound = null, onLost = null, onUpdate = null, cameraConfig = { facingMode: 'environment', width: 1280, height: 720 }, }) {
|
|
21
32
|
this.container = container;
|
|
@@ -45,6 +56,7 @@ class SimpleAR {
|
|
|
45
56
|
const targets = Array.isArray(this.targetSrc) ? this.targetSrc : [this.targetSrc];
|
|
46
57
|
const result = await this.controller.addImageTargets(targets);
|
|
47
58
|
this.markerDimensions = result.dimensions; // [ [w1, h1], [w2, h2], ... ]
|
|
59
|
+
console.log("Targets loaded. Dimensions:", this.markerDimensions);
|
|
48
60
|
this.controller.processVideo(this.video);
|
|
49
61
|
return this;
|
|
50
62
|
}
|
|
@@ -153,9 +165,6 @@ class SimpleAR {
|
|
|
153
165
|
const tz = mVT[2][0] * (markerW / 2) + mVT[2][1] * (markerH / 2) + mVT[2][3];
|
|
154
166
|
let screenX, screenY, rotation;
|
|
155
167
|
if (needsRotation) {
|
|
156
|
-
// Mapping for 90deg clockwise rotation:
|
|
157
|
-
// Buffer X (0..videoW) -> Screen Y (0..displayH)
|
|
158
|
-
// Buffer Y (0..videoH) -> Screen X (displayW..0)
|
|
159
168
|
const bufferOffsetX = (tx * f / tz);
|
|
160
169
|
const bufferOffsetY = (ty * f / tz);
|
|
161
170
|
screenX = offsetX + (displayW / 2) - (bufferOffsetY * perspectiveScale);
|
|
@@ -163,21 +172,25 @@ class SimpleAR {
|
|
|
163
172
|
rotation = Math.atan2(mVT[1][0], mVT[0][0]) - Math.PI / 2;
|
|
164
173
|
}
|
|
165
174
|
else {
|
|
166
|
-
// Normal mapping:
|
|
167
|
-
// Buffer X -> Screen X
|
|
168
|
-
// Buffer Y -> Screen Y
|
|
169
175
|
const bufferOffsetX = (tx * f / tz);
|
|
170
176
|
const bufferOffsetY = (ty * f / tz);
|
|
171
177
|
screenX = offsetX + (displayW / 2) + (bufferOffsetX * perspectiveScale);
|
|
172
178
|
screenY = offsetY + (displayH / 2) + (bufferOffsetY * perspectiveScale);
|
|
173
179
|
rotation = Math.atan2(mVT[1][0], mVT[0][0]);
|
|
174
180
|
}
|
|
175
|
-
// Final Scale calculation:
|
|
176
|
-
// f/tz converts world units to buffer pixels
|
|
177
|
-
// perspectiveScale converts buffer pixels to screen pixels
|
|
178
|
-
// matrixScale handles the target's relative orientation in 2D
|
|
179
181
|
const matrixScale = Math.sqrt(mVT[0][0] ** 2 + mVT[1][0] ** 2);
|
|
180
182
|
const finalScale = (f / tz) * perspectiveScale * matrixScale * this.scaleMultiplier;
|
|
183
|
+
// DEBUG LOGS
|
|
184
|
+
if (window.AR_DEBUG) {
|
|
185
|
+
console.log('--- AR POSITION DEBUG ---');
|
|
186
|
+
console.log('Container:', containerRect.width, 'x', containerRect.height);
|
|
187
|
+
console.log('Video:', videoW, 'x', videoH, 'needsRotation:', needsRotation);
|
|
188
|
+
console.log('PerspectiveScale (Cover):', perspectiveScale);
|
|
189
|
+
console.log('Display:', displayW, 'x', displayH, 'Offsets:', offsetX, offsetY);
|
|
190
|
+
console.log('Projection (tx, ty, tz):', tx.toFixed(2), ty.toFixed(2), tz.toFixed(2));
|
|
191
|
+
console.log('Screen Coords:', screenX.toFixed(2), screenY.toFixed(2));
|
|
192
|
+
console.log('Final Scale:', finalScale.toFixed(4), '(MatrixScale:', matrixScale.toFixed(4), ')');
|
|
193
|
+
}
|
|
181
194
|
// Apply
|
|
182
195
|
this.overlay.style.width = `${markerW}px`;
|
|
183
196
|
this.overlay.style.height = 'auto';
|
package/package.json
CHANGED
|
@@ -17,6 +17,17 @@ import { Controller } from "./controller.js";
|
|
|
17
17
|
* await ar.start();
|
|
18
18
|
*/
|
|
19
19
|
class SimpleAR {
|
|
20
|
+
/**
|
|
21
|
+
* @param {Object} options
|
|
22
|
+
* @param {HTMLElement} options.container
|
|
23
|
+
* @param {string|string[]} options.targetSrc
|
|
24
|
+
* @param {HTMLElement} options.overlay
|
|
25
|
+
* @param {number} [options.scale=1.0]
|
|
26
|
+
* @param {((data: {targetIndex: number}) => void | Promise<void>) | null} [options.onFound]
|
|
27
|
+
* @param {((data: {targetIndex: number}) => void | Promise<void>) | null} [options.onLost]
|
|
28
|
+
* @param {((data: {targetIndex: number, worldMatrix: number[]}) => void) | null} [options.onUpdate]
|
|
29
|
+
* @param {Object} [options.cameraConfig]
|
|
30
|
+
*/
|
|
20
31
|
constructor({
|
|
21
32
|
container,
|
|
22
33
|
targetSrc,
|
|
@@ -59,6 +70,7 @@ class SimpleAR {
|
|
|
59
70
|
const targets = Array.isArray(this.targetSrc) ? this.targetSrc : [this.targetSrc];
|
|
60
71
|
const result = await this.controller.addImageTargets(targets);
|
|
61
72
|
this.markerDimensions = result.dimensions; // [ [w1, h1], [w2, h2], ... ]
|
|
73
|
+
console.log("Targets loaded. Dimensions:", this.markerDimensions);
|
|
62
74
|
|
|
63
75
|
this.controller.processVideo(this.video);
|
|
64
76
|
|
|
@@ -186,9 +198,6 @@ class SimpleAR {
|
|
|
186
198
|
let screenX, screenY, rotation;
|
|
187
199
|
|
|
188
200
|
if (needsRotation) {
|
|
189
|
-
// Mapping for 90deg clockwise rotation:
|
|
190
|
-
// Buffer X (0..videoW) -> Screen Y (0..displayH)
|
|
191
|
-
// Buffer Y (0..videoH) -> Screen X (displayW..0)
|
|
192
201
|
const bufferOffsetX = (tx * f / tz);
|
|
193
202
|
const bufferOffsetY = (ty * f / tz);
|
|
194
203
|
|
|
@@ -196,9 +205,6 @@ class SimpleAR {
|
|
|
196
205
|
screenY = offsetY + (displayH / 2) + (bufferOffsetX * perspectiveScale);
|
|
197
206
|
rotation = Math.atan2(mVT[1][0], mVT[0][0]) - Math.PI / 2;
|
|
198
207
|
} else {
|
|
199
|
-
// Normal mapping:
|
|
200
|
-
// Buffer X -> Screen X
|
|
201
|
-
// Buffer Y -> Screen Y
|
|
202
208
|
const bufferOffsetX = (tx * f / tz);
|
|
203
209
|
const bufferOffsetY = (ty * f / tz);
|
|
204
210
|
|
|
@@ -207,13 +213,21 @@ class SimpleAR {
|
|
|
207
213
|
rotation = Math.atan2(mVT[1][0], mVT[0][0]);
|
|
208
214
|
}
|
|
209
215
|
|
|
210
|
-
// Final Scale calculation:
|
|
211
|
-
// f/tz converts world units to buffer pixels
|
|
212
|
-
// perspectiveScale converts buffer pixels to screen pixels
|
|
213
|
-
// matrixScale handles the target's relative orientation in 2D
|
|
214
216
|
const matrixScale = Math.sqrt(mVT[0][0] ** 2 + mVT[1][0] ** 2);
|
|
215
217
|
const finalScale = (f / tz) * perspectiveScale * matrixScale * this.scaleMultiplier;
|
|
216
218
|
|
|
219
|
+
// DEBUG LOGS
|
|
220
|
+
if (window.AR_DEBUG) {
|
|
221
|
+
console.log('--- AR POSITION DEBUG ---');
|
|
222
|
+
console.log('Container:', containerRect.width, 'x', containerRect.height);
|
|
223
|
+
console.log('Video:', videoW, 'x', videoH, 'needsRotation:', needsRotation);
|
|
224
|
+
console.log('PerspectiveScale (Cover):', perspectiveScale);
|
|
225
|
+
console.log('Display:', displayW, 'x', displayH, 'Offsets:', offsetX, offsetY);
|
|
226
|
+
console.log('Projection (tx, ty, tz):', tx.toFixed(2), ty.toFixed(2), tz.toFixed(2));
|
|
227
|
+
console.log('Screen Coords:', screenX.toFixed(2), screenY.toFixed(2));
|
|
228
|
+
console.log('Final Scale:', finalScale.toFixed(4), '(MatrixScale:', matrixScale.toFixed(4), ')');
|
|
229
|
+
}
|
|
230
|
+
|
|
217
231
|
// Apply
|
|
218
232
|
this.overlay.style.width = `${markerW}px`;
|
|
219
233
|
this.overlay.style.height = 'auto';
|