Skip to main content
ARShow
ARShow
 首页 » AR资讯

AR如何动态加载模型资源并且将模型资源赋予某一个ImageTarget

2016年08月24日 19:47:4113170

根据跟踪状态实现相应功能

  • TrackableBehaviour.Status.DETECTED//检测到

  • TrackableBehaviour.Status.EXTENDED_TRACKED//延伸跟踪

  • TrackableBehaviour.Status.NOT_FOUND//未找到

  • TrackableBehaviour.Status.TRACKED//跟踪中

  • TrackableBehaviour.Status.UNDEFINED//未定义的

  • TrackableBehaviour.Status.UNKNOWN//未知的

接下来是脚本

public class MyPrefabInstantiator : MonoBehaviour, ITrackableEventHandler

{

private TrackableBehaviour mTrackableBehaviour;

public Transform myModelPrefab;

// Use this for initialization

void Start ()

{

mTrackableBehaviour = GetComponent();

if (mTrackableBehaviour)

{

mTrackableBehaviour.RegisterTrackableEventHandler(this);

}

}

public void onTrackableStateChanged(

TrackableBehaviour.Status previousStatus,

TrackableBehaviour.Status newStatus)

{

if (newStatus == TrackableBehaviour.Status.DETECTED ||

newStatus == TrackableBehaviour.Status.TRACKED ||

newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)

{

onTrackingFound();

}

}

private void onTrackingFound()

{

if (myModelPrefab != null)

{

Transform myModelTrf = GameObject.Instantiate(myModelPrefab) as Transform;

myModelTrf.parent = mTrackableBehaviour.transform;

myModelTrf.localPosition = new Vector3(0f, 0f, 0f);

myModelTrf.localRotation = Quaternion.identity;

myModelTrf.localScale = new Vector3(0.0005f, 0.0005f, 0.0005f);

myModelTrf.gameObject.active = true;

}

}

}

大致上是这个样子 具体根据需求改动。

更多AR新闻就在中国AR网(http://www.chinaar.com/)


评论列表暂无评论
发表评论