Closed adilsonv77 closed 1 year ago
onTargetFound is bind to specific anchor already
Ok. How can access It?
anchor.onTargetFound = () => {
}
OK... I understood your point. However, I´m working with multi targets, dinamically loaded from a database.
I have this piece of code, to adding an anchor for each target. When the target is detected, then show a button (in thruth is an hyperlink) in the page. Each target must change the value of the parameter from the hyperlink.
for (var i = 0; .....) {
...
const glb = await loadGLTF(<dinamically from a database>);
const glbScene = glb.scene;
...
const anchor = mindarThree.addAnchor(i);
anchor.someAttribute = take the value from somewhere
anchor.group.add(glbScene);
anchor.onTargetFound = () => {
buttonAR.href = buttonAR._href + "?id=" + <I wanna get someAttribute from the current anchor>
buttonAR.style.display = 'block';
}
....
} Can you see? Anchor is dinamically created in multitarget problem.
Yes, buttonAR.href = buttonAR._href + "?id=" + anchor.someAttribute
should work.
I tried now, and it gave the error message "Uncaught ReferenceError: anchor is not defined"
I changed three.js with this code
if (this.anchors[i].onTargetFound) { this.anchors[i].onTargetFound(this.anchors[i]); }
It worked for me.
That's weird. I really don't think you need to do that. But whatever works for you.
However, I would like to use your suggestion. After compile the code with my modification and use mindar-image-three.js, seems the model is shivering.
Everything is ok. I tried your suggestion.
In image-target/three.js, line 161, I identified that any information is send to onTargetFound.
With multiple-targets, I´m interesting to identifiy which target emitted this event. How can I do this? Suggestions...