ARKit and Vuforia - marker recognition

不羁岁月 提交于 2019-11-30 05:23:10

Q1: You can handle the recognition of the marker (called Image Target in Vuforia) Create a script:

public class CustomTrackableEventHandler : MonoBehaviour,
                                           ITrackableEventHandler
{
    ...

    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED ||
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            OnTrackingFound(); 
            // **** Your own logic here ****
        }
        else
        {
            OnTrackingLost();
        }
    }
}

Then you can replace the DefaultTrackableEventHandler with this this script.

Q2: I need to get the position of the marker only ones, in order to place 3D content there, after that I want to use ARKit for tracking.

You can add an empty game object to be the child of the marker (ImageTarget), and the hierarchy would be:

YourMarker(ImageTarget)
     |__EmptyPlaceHolder

When the marker is recognised, you can then programatically get its location:

var placeHolder = GameObject.Find("EmptyPlaceHolder");
if(placeHolder != null){
    Debug.Log(placeHolder.transform.position); // all the location, localPosition, quaternion etc will be available to you

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!