1、选择目标图
选择了一个与模型寒冰相关的图片
2、上传图片到官网的数据库
3、查看该图片目标的识别星级
4、下载数据到本地
浏览器会下载.unitypackge的包,包名与你创建的数据集名字一样,导入unity即可。
5.在unity中选择自己的数据
6.控制模型的生成
创建脚本AR,附加在imagTagert,移除自身的,继承接口 ITrackableEventHandler
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class AR : MonoBehaviour, ITrackableEventHandler
{
protected TrackableBehaviour mTrackableBehaviour; //声明可识别行为脚本
public GameObject AIXIPrefab;//模型预制
private GameObject aixi; //生成的模型
protected virtual void Start()
{
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
if (mTrackableBehaviour)
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}
protected virtual void OnDestroy()
{
if (mTrackableBehaviour)
mTrackableBehaviour.UnregisterTrackableEventHandler(this);
}
/// <summary>
/// 状态的改变
/// </summary>
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
OnTrackingFound();
}
else if (previousStatus == TrackableBehaviour.Status.TRACKED &&
newStatus == TrackableBehaviour.Status.NOT_FOUND)
{
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
OnTrackingLost();
}
else
{
OnTrackingLost();
}
}
/// <summary>
/// 识别到物体
/// </summary>
protected virtual void OnTrackingFound()
{
aixi = GameObject.Instantiate(AIXIPrefab);
aixi.transform.position = this.transform.position;
aixi.transform.SetParent(this.transform);
}
/// <summary>
/// 丢失物体
/// </summary>
protected virtual void OnTrackingLost()
{
if (aixi != null)
{
Destroy(aixi);
}
}
}
主要接口方法:
OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)