@srsergio/taptapp-ar 1.0.38 → 1.0.40
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.
|
@@ -181,6 +181,8 @@ class Controller {
|
|
|
181
181
|
return { targetIndex: matchedTargetIndex, modelViewTransform };
|
|
182
182
|
}
|
|
183
183
|
async _trackAndUpdate(inputData, lastModelViewTransform, targetIndex) {
|
|
184
|
+
if (!lastModelViewTransform)
|
|
185
|
+
return null;
|
|
184
186
|
const result = this.tracker.track(inputData, lastModelViewTransform, targetIndex);
|
|
185
187
|
if (result.worldCoords.length < 6)
|
|
186
188
|
return null; // Umbral de puntos mínimos para mantener el seguimiento
|
|
@@ -243,73 +245,79 @@ class Controller {
|
|
|
243
245
|
for (let i = 0; i < this.trackingStates.length; i++) {
|
|
244
246
|
const trackingState = this.trackingStates[i];
|
|
245
247
|
if (trackingState.isTracking) {
|
|
246
|
-
|
|
247
|
-
if (result === null) {
|
|
248
|
+
if (!trackingState.currentModelViewTransform) {
|
|
248
249
|
trackingState.isTracking = false;
|
|
249
250
|
trackingState.stabilityCount = 0;
|
|
250
251
|
}
|
|
251
252
|
else {
|
|
252
|
-
trackingState.currentModelViewTransform
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (result.inliers > 35) {
|
|
257
|
-
trackingState.stabilityCount++;
|
|
258
|
-
if (trackingState.stabilityCount > 30) { // 30 frames (~1s) de estabilidad absoluta
|
|
259
|
-
this.tracker.applyLiveFeedback(i, result.octaveIndex, 0.05); // Menor alpha (5%) para ser más conservador
|
|
260
|
-
if (this.debugMode)
|
|
261
|
-
console.log(`✨ Live Reification: Target ${i} (Octave ${result.octaveIndex}) updated.`);
|
|
262
|
-
trackingState.stabilityCount = 0;
|
|
263
|
-
}
|
|
253
|
+
let result = await this._trackAndUpdate(inputData, trackingState.currentModelViewTransform, i);
|
|
254
|
+
if (result === null) {
|
|
255
|
+
trackingState.isTracking = false;
|
|
256
|
+
trackingState.stabilityCount = 0;
|
|
264
257
|
}
|
|
265
258
|
else {
|
|
266
|
-
trackingState.
|
|
259
|
+
trackingState.currentModelViewTransform = result.modelViewTransform;
|
|
260
|
+
// --- LIVE MODEL ADAPTATION LOGIC ---
|
|
261
|
+
// Si el tracking es muy sólido (muchos inliers) y estable, refinamos el modelo
|
|
262
|
+
// Requisito: > 35 inliers (muy exigente) para evitar polución por ruido
|
|
263
|
+
if (result.inliers > 35) {
|
|
264
|
+
trackingState.stabilityCount++;
|
|
265
|
+
if (trackingState.stabilityCount > 30) { // 30 frames (~1s) de estabilidad absoluta
|
|
266
|
+
this.tracker.applyLiveFeedback(i, result.octaveIndex, 0.05); // Menor alpha (5%) para ser más conservador
|
|
267
|
+
if (this.debugMode)
|
|
268
|
+
console.log(`✨ Live Reification: Target ${i} (Octave ${result.octaveIndex}) updated.`);
|
|
269
|
+
trackingState.stabilityCount = 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
trackingState.stabilityCount = Math.max(0, trackingState.stabilityCount - 1);
|
|
274
|
+
}
|
|
275
|
+
// -----------------------------------
|
|
267
276
|
}
|
|
268
|
-
// -----------------------------------
|
|
269
277
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
278
|
+
// if not showing, then show it once it reaches warmup number of frames
|
|
279
|
+
if (!trackingState.showing) {
|
|
280
|
+
if (trackingState.isTracking) {
|
|
281
|
+
trackingState.trackMiss = 0;
|
|
282
|
+
trackingState.trackCount += 1;
|
|
283
|
+
if (trackingState.trackCount > this.warmupTolerance) {
|
|
284
|
+
trackingState.showing = true;
|
|
285
|
+
trackingState.trackingMatrix = null;
|
|
286
|
+
trackingState.filter.reset();
|
|
287
|
+
}
|
|
280
288
|
}
|
|
281
289
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
290
|
+
// if showing, then count miss, and hide it when reaches tolerance
|
|
291
|
+
if (trackingState.showing) {
|
|
292
|
+
if (!trackingState.isTracking) {
|
|
293
|
+
trackingState.trackCount = 0;
|
|
294
|
+
trackingState.trackMiss += 1;
|
|
295
|
+
if (trackingState.trackMiss > this.missTolerance) {
|
|
296
|
+
trackingState.showing = false;
|
|
297
|
+
trackingState.trackingMatrix = null;
|
|
298
|
+
this.onUpdate &&
|
|
299
|
+
this.onUpdate({ type: "updateMatrix", targetIndex: i, worldMatrix: null });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
trackingState.trackMiss = 0;
|
|
293
304
|
}
|
|
294
305
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
clone = this.getRotatedZ90Matrix(clone);
|
|
306
|
+
// if showing, then call onUpdate, with world matrix
|
|
307
|
+
if (trackingState.showing && trackingState.currentModelViewTransform) {
|
|
308
|
+
const worldMatrix = this._glModelViewMatrix(trackingState.currentModelViewTransform, i);
|
|
309
|
+
trackingState.trackingMatrix = trackingState.filter.filter(Date.now(), worldMatrix);
|
|
310
|
+
let clone = [];
|
|
311
|
+
for (let j = 0; j < trackingState.trackingMatrix.length; j++) {
|
|
312
|
+
clone[j] = trackingState.trackingMatrix[j];
|
|
313
|
+
}
|
|
314
|
+
const isInputRotated = input.width === this.inputHeight && input.height === this.inputWidth;
|
|
315
|
+
if (isInputRotated) {
|
|
316
|
+
clone = this.getRotatedZ90Matrix(clone);
|
|
317
|
+
}
|
|
318
|
+
this.onUpdate &&
|
|
319
|
+
this.onUpdate({ type: "updateMatrix", targetIndex: i, worldMatrix: clone, modelViewTransform: trackingState.currentModelViewTransform });
|
|
310
320
|
}
|
|
311
|
-
this.onUpdate &&
|
|
312
|
-
this.onUpdate({ type: "updateMatrix", targetIndex: i, worldMatrix: clone, modelViewTransform: trackingState.currentModelViewTransform });
|
|
313
321
|
}
|
|
314
322
|
}
|
|
315
323
|
this.onUpdate && this.onUpdate({ type: "processDone" });
|
|
@@ -46,6 +46,8 @@ class Tracker {
|
|
|
46
46
|
}
|
|
47
47
|
track(inputData, lastModelViewTransform, targetIndex) {
|
|
48
48
|
let debugExtra = {};
|
|
49
|
+
if (!lastModelViewTransform)
|
|
50
|
+
return { worldCoords: [], screenCoords: [], octaveIndex: 0, debugExtra };
|
|
49
51
|
// Select the best octave based on current estimated distance/scale
|
|
50
52
|
// We want the octave where the marker size is closest to its projected size on screen
|
|
51
53
|
const modelViewProjectionTransform = buildModelViewProjectionTransform(this.projectionTransform, lastModelViewTransform);
|
package/package.json
CHANGED
|
@@ -226,6 +226,7 @@ class Controller {
|
|
|
226
226
|
return { targetIndex: matchedTargetIndex, modelViewTransform };
|
|
227
227
|
}
|
|
228
228
|
async _trackAndUpdate(inputData, lastModelViewTransform, targetIndex) {
|
|
229
|
+
if (!lastModelViewTransform) return null;
|
|
229
230
|
const result = this.tracker.track(
|
|
230
231
|
inputData,
|
|
231
232
|
lastModelViewTransform,
|
|
@@ -299,85 +300,89 @@ class Controller {
|
|
|
299
300
|
const trackingState = this.trackingStates[i];
|
|
300
301
|
|
|
301
302
|
if (trackingState.isTracking) {
|
|
302
|
-
|
|
303
|
-
inputData,
|
|
304
|
-
trackingState.currentModelViewTransform,
|
|
305
|
-
i,
|
|
306
|
-
);
|
|
307
|
-
if (result === null) {
|
|
303
|
+
if (!trackingState.currentModelViewTransform) {
|
|
308
304
|
trackingState.isTracking = false;
|
|
309
305
|
trackingState.stabilityCount = 0;
|
|
310
306
|
} else {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (result
|
|
317
|
-
trackingState.
|
|
318
|
-
|
|
319
|
-
this.tracker.applyLiveFeedback(i, result.octaveIndex, 0.05); // Menor alpha (5%) para ser más conservador
|
|
320
|
-
if (this.debugMode) console.log(`✨ Live Reification: Target ${i} (Octave ${result.octaveIndex}) updated.`);
|
|
321
|
-
trackingState.stabilityCount = 0;
|
|
322
|
-
}
|
|
307
|
+
let result = await this._trackAndUpdate(
|
|
308
|
+
inputData,
|
|
309
|
+
trackingState.currentModelViewTransform,
|
|
310
|
+
i,
|
|
311
|
+
);
|
|
312
|
+
if (result === null) {
|
|
313
|
+
trackingState.isTracking = false;
|
|
314
|
+
trackingState.stabilityCount = 0;
|
|
323
315
|
} else {
|
|
324
|
-
trackingState.
|
|
316
|
+
trackingState.currentModelViewTransform = result.modelViewTransform;
|
|
317
|
+
|
|
318
|
+
// --- LIVE MODEL ADAPTATION LOGIC ---
|
|
319
|
+
// Si el tracking es muy sólido (muchos inliers) y estable, refinamos el modelo
|
|
320
|
+
// Requisito: > 35 inliers (muy exigente) para evitar polución por ruido
|
|
321
|
+
if (result.inliers > 35) {
|
|
322
|
+
trackingState.stabilityCount++;
|
|
323
|
+
if (trackingState.stabilityCount > 30) { // 30 frames (~1s) de estabilidad absoluta
|
|
324
|
+
this.tracker.applyLiveFeedback(i, result.octaveIndex, 0.05); // Menor alpha (5%) para ser más conservador
|
|
325
|
+
if (this.debugMode) console.log(`✨ Live Reification: Target ${i} (Octave ${result.octaveIndex}) updated.`);
|
|
326
|
+
trackingState.stabilityCount = 0;
|
|
327
|
+
}
|
|
328
|
+
} else {
|
|
329
|
+
trackingState.stabilityCount = Math.max(0, trackingState.stabilityCount - 1);
|
|
330
|
+
}
|
|
331
|
+
// -----------------------------------
|
|
325
332
|
}
|
|
326
|
-
// -----------------------------------
|
|
327
333
|
}
|
|
328
|
-
}
|
|
329
334
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
335
|
+
// if not showing, then show it once it reaches warmup number of frames
|
|
336
|
+
if (!trackingState.showing) {
|
|
337
|
+
if (trackingState.isTracking) {
|
|
338
|
+
trackingState.trackMiss = 0;
|
|
339
|
+
trackingState.trackCount += 1;
|
|
340
|
+
if (trackingState.trackCount > this.warmupTolerance) {
|
|
341
|
+
trackingState.showing = true;
|
|
342
|
+
trackingState.trackingMatrix = null;
|
|
343
|
+
trackingState.filter.reset();
|
|
344
|
+
}
|
|
339
345
|
}
|
|
340
346
|
}
|
|
341
|
-
}
|
|
342
347
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
348
|
+
// if showing, then count miss, and hide it when reaches tolerance
|
|
349
|
+
if (trackingState.showing) {
|
|
350
|
+
if (!trackingState.isTracking) {
|
|
351
|
+
trackingState.trackCount = 0;
|
|
352
|
+
trackingState.trackMiss += 1;
|
|
353
|
+
|
|
354
|
+
if (trackingState.trackMiss > this.missTolerance) {
|
|
355
|
+
trackingState.showing = false;
|
|
356
|
+
trackingState.trackingMatrix = null;
|
|
357
|
+
this.onUpdate &&
|
|
358
|
+
this.onUpdate({ type: "updateMatrix", targetIndex: i, worldMatrix: null });
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
trackingState.trackMiss = 0;
|
|
354
362
|
}
|
|
355
|
-
} else {
|
|
356
|
-
trackingState.trackMiss = 0;
|
|
357
363
|
}
|
|
358
|
-
}
|
|
359
364
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
365
|
+
// if showing, then call onUpdate, with world matrix
|
|
366
|
+
if (trackingState.showing && trackingState.currentModelViewTransform) {
|
|
367
|
+
const worldMatrix = this._glModelViewMatrix(trackingState.currentModelViewTransform, i);
|
|
368
|
+
trackingState.trackingMatrix = trackingState.filter.filter(Date.now(), worldMatrix);
|
|
364
369
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
370
|
+
let clone = [];
|
|
371
|
+
for (let j = 0; j < trackingState.trackingMatrix.length; j++) {
|
|
372
|
+
clone[j] = trackingState.trackingMatrix[j];
|
|
373
|
+
}
|
|
369
374
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
+
const isInputRotated =
|
|
376
|
+
input.width === this.inputHeight && input.height === this.inputWidth;
|
|
377
|
+
if (isInputRotated) {
|
|
378
|
+
clone = this.getRotatedZ90Matrix(clone);
|
|
379
|
+
}
|
|
375
380
|
|
|
376
|
-
|
|
377
|
-
|
|
381
|
+
this.onUpdate &&
|
|
382
|
+
this.onUpdate({ type: "updateMatrix", targetIndex: i, worldMatrix: clone, modelViewTransform: trackingState.currentModelViewTransform });
|
|
383
|
+
}
|
|
378
384
|
}
|
|
379
385
|
}
|
|
380
|
-
|
|
381
386
|
this.onUpdate && this.onUpdate({ type: "processDone" });
|
|
382
387
|
|
|
383
388
|
// Use requestAnimationFrame if available, otherwise just wait briefly
|
|
@@ -61,6 +61,7 @@ class Tracker {
|
|
|
61
61
|
|
|
62
62
|
track(inputData, lastModelViewTransform, targetIndex) {
|
|
63
63
|
let debugExtra = {};
|
|
64
|
+
if (!lastModelViewTransform) return { worldCoords: [], screenCoords: [], octaveIndex: 0, debugExtra };
|
|
64
65
|
|
|
65
66
|
// Select the best octave based on current estimated distance/scale
|
|
66
67
|
// We want the octave where the marker size is closest to its projected size on screen
|