Unity和Vuforia - 用于3d模型的AssetsBundle和用于imagetargets的CloundReco

时间:2018-05-17 22:32:34

标签: unity3d augmented-reality vuforia assetbundle vuforia-cloud-recognition

我正在开发增强现实应用程序。我想在应用程序中放入多个图像目标和多个3D模型,将特定图像目标与特定的3D模型连接起来。为此,我想使用assetbundle将3D模型存储在服务器中,并使用cloudrecognition来存储图像目标。我在这方面遇到了一些困难。有什么更好的方法呢?我甚至无法将3D模型(在assetBundle中)连接到普通图像目标中,如何将其连接到云中的图像目标?

2 个答案:

答案 0 :(得分:1)

我使用附加到cloudreco的这个脚本:

using Vuforia;
using UnityEngine;

public class SimpleCloudHandler : MonoBehaviour, ICloudRecoEventHandler
{
    private CloudRecoBehaviour mCloudRecoBehaviour;
    private bool mIsScanning = false;
    private string mTargetMetadata = "";
    // Use this for initialization
    void Start()
    {
        // register this event handler at the cloud reco behaviour
        mCloudRecoBehaviour = GetComponent<CloudRecoBehaviour>();

        if (mCloudRecoBehaviour)
        {
            mCloudRecoBehaviour.RegisterEventHandler(this);
        }
    }

    public void OnInitialized()
    {
        Debug.Log("Cloud Reco initialized");
    }
    public void OnInitError(TargetFinder.InitState initError)
    {
        Debug.Log("Cloud Reco init error " + initError.ToString());
    }
    public void OnUpdateError(TargetFinder.UpdateState updateError)
    {
        Debug.Log("Cloud Reco update error " + updateError.ToString());
    }

    public void OnStateChanged(bool scanning)
    {
        mIsScanning = scanning;
        if (scanning)
        {
            // clear all known trackables
            var tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
            tracker.TargetFinder.ClearTrackables(false);
        }
    }
    // Here we handle a cloud target recognition event
    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
        // do something with the target metadata
        NewMethod(targetSearchResult);
        // stop the target finder (i.e. stop scanning the cloud)
        mCloudRecoBehaviour.CloudRecoEnabled = false;
    }

    private void NewMethod(TargetFinder.TargetSearchResult targetSearchResult)
    {
        mTargetMetadata = targetSearchResult.MetaData;
    }

    void OnGUI()
    {
        // Display current 'scanning' status
        GUI.Box(new Rect(100, 100, 200, 50), mIsScanning ? "Scanning" : "Not scanning");
        // Display metadata of latest detected cloud-target
        GUI.Box(new Rect(100, 200, 200, 50), "Metadata: " + mTargetMetadata);
        // If not scanning, show button
        // so that user can restart cloud scanning
        if (!mIsScanning)
        {
            if (GUI.Button(new Rect(100, 300, 200, 50), "Restart Scanning"))
            {
                // Restart TargetFinder
                mCloudRecoBehaviour.CloudRecoEnabled = true;
            }
        }
    }
}

并出现此消息: 我们获得了目标元数据:https://drive.google.com/uc?authuser=0&id=1twVZENr-J9gsw4PwLeelA1quAIgxsLUN&export=download UnityEngine.Debug:日志(对象) SimpleCloudHandler:OnNewSearchResult(TargetSearchResult)(在Assets / SimpleCloudHandler.cs:49) Vuforia.CloudRecoBehaviour:更新()

答案 1 :(得分:0)