Skip to content

Commit 77f7c79

Browse files
committed
fix: image tracking issues
1 parent 3a0984d commit 77f7c79

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

android/sharedCode/src/main/cpp/arcore/VROARSessionARCore.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,18 +1126,18 @@ void VROARSessionARCore::processUpdatedAnchors(VROARFrameARCore *frameAR) {
11261126
if (imageIsTracked) {
11271127
auto it = _nativeAnchorMap.find(key);
11281128

1129-
// Old image tracking target: update it
1129+
// Old image tracking target: update tracking method and imageAnchor pose.
1130+
// Position sync for the scene node is handled by the per-frame sync loop below,
1131+
// which ensures updates happen every frame regardless of getUpdatedTrackables.
11301132
if (it != _nativeAnchorMap.end()) {
11311133
std::shared_ptr<VROARAnchorARCore> vAnchor = it->second;
11321134
std::shared_ptr<VROARImageAnchor> imageAnchor =
11331135
std::dynamic_pointer_cast<VROARImageAnchor>(
11341136
vAnchor->getTrackable());
11351137

1136-
if (vAnchor) {
1138+
if (imageAnchor) {
11371139
imageAnchor->setTrackingMethod(trackingMethod);
11381140
syncImageAnchorWithARCore(imageAnchor, image);
1139-
vAnchor->sync();
1140-
updateAnchor(vAnchor);
11411141
} else {
11421142
pwarn("Anchor processing error: expected to find an image anchor");
11431143
}
@@ -1202,6 +1202,27 @@ void VROARSessionARCore::processUpdatedAnchors(VROARFrameARCore *frameAR) {
12021202
}
12031203
}
12041204
delete (imageList);
1205+
1206+
// Per-frame position sync for all active image anchors.
1207+
//
1208+
// ARCore updates the ArAnchor pose on every ArSession_update() for anchors attached to
1209+
// trackables — regardless of whether the image appears in getUpdatedTrackables() that
1210+
// frame. By syncing here we guarantee the scene node is always at the current world-space
1211+
// pose of the image, not just on frames where ARCore happens to report the trackable as
1212+
// "updated".
1213+
for (auto& entry : _nativeAnchorMap) {
1214+
std::shared_ptr<VROARAnchorARCore> vAnchor = entry.second;
1215+
if (!vAnchor || !vAnchor->isManaged() || !vAnchor->getARNode()) {
1216+
continue;
1217+
}
1218+
std::shared_ptr<VROARImageAnchor> imageAnchor =
1219+
std::dynamic_pointer_cast<VROARImageAnchor>(vAnchor->getTrackable());
1220+
if (!imageAnchor) {
1221+
continue;
1222+
}
1223+
vAnchor->sync();
1224+
updateAnchor(vAnchor);
1225+
}
12051226
}
12061227

12071228
delete (anchorList);
-307 KB
Binary file not shown.

0 commit comments

Comments
 (0)