Skip to content

Commit

Permalink
added onTargetUpdate event for image tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
hiukim committed Feb 8, 2023
1 parent 9c2e17e commit 7740932
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions examples/image-tracking/example3.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
console.log("target lost");
});

exampleTarget.addEventListener("targetUpdate", event => {
console.log("target position update");
});


loadingOverlay.style.display = "block";
controlOverlay.style.display = "block";
Expand Down
1 change: 1 addition & 0 deletions src/image-target/aframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ AFRAME.registerComponent('mindar-image-target', {
},

updateWorldMatrix(worldMatrix) {
this.el.emit("targetUpdate");
if (!this.el.object3D.visible && worldMatrix !== null) {
this.el.emit("targetFound");
} else if (this.el.object3D.visible && worldMatrix === null) {
Expand Down
8 changes: 6 additions & 2 deletions src/image-target/three.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class MindARThree {
const group = new Group();
group.visible = false;
group.matrixAutoUpdate = false;
const anchor = { group, targetIndex, onTargetFound: null, onTargetLost: null, css: false, visible: false };
const anchor = { group, targetIndex, onTargetFound: null, onTargetLost: null, onTargetUpdate: null, css: false, visible: false };
this.anchors.push(anchor);
this.scene.add(group);
return anchor;
Expand All @@ -68,7 +68,7 @@ export class MindARThree {
const group = new Group();
group.visible = false;
group.matrixAutoUpdate = false;
const anchor = { group, targetIndex, onTargetFound: null, onTargetLost: null, css: true, visible: false };
const anchor = { group, targetIndex, onTargetFound: null, onTargetLost: null, onTargetUpdate: null, css: true, visible: false };
this.anchors.push(anchor);
this.cssScene.add(group);
return anchor;
Expand Down Expand Up @@ -161,6 +161,10 @@ export class MindARThree {
this.anchors[i].onTargetFound();
}
}

if (this.anchors[i].onTargetUpdate) {
this.anchors[i].onTargetUpdate();
}
}
}

Expand Down

0 comments on commit 7740932

Please sign in to comment.