ARFoundation之路_很全面的

Posted haneya

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ARFoundation之路_很全面的相关的知识,希望对你有一定的参考价值。

ARFoundation之路-概述

ARFoundation之路-架构及术语

ARFoundation之路-图像跟踪

ARFoundation之路-光照估计

ARFoundation之路-点云与参考点

ARFoundation之路-平面管理

ARFoundation之路-平面管理之二

ARFoundation之路-ARSession & ARSessionOrigin

ARFoundation之路-Raycasting

ARFoundation之路-环境配置(ios)之一

ARFoundation之路-环境配置(iOS)之二

ARFoundation之路-环境配置(android)

ARFoundation之路-可跟踪对象

ARFoundation之路-视频播放

ARFoundation之路-AR子系统

ARFoundation之路-Environment Probe之一

ARFoundation之路-Environment Probe之二

ARFoundation之路-AR阴影生成之一

ARFoundation之路-AR阴影生成之二

ARFoundation之路-AR阴影生成之三

ARFoundation之路-AR阴影生成之四

ARFoundation之路-3D物体识别之一

ARFoundation之路-3D物体识别之二

ARFoundation之路-3D物体识别之三

ARFoundation之路-人脸检测增强之一

ARFoundation之路-人脸检测增强之二

ARFoundation之路-人脸检测增强之三

ARFoundation之路-人脸检测增强之四
————————————————
版权声明:本文为CSDN博主「习惯冬天的静谧」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_35080168/article/details/103156542

Unity ARFoundation 图像跟踪预制位置

【中文标题】Unity ARFoundation 图像跟踪预制位置【英文标题】:Unity ARFoundation image tracking prefab location 【发布时间】:2019-11-23 23:55:12 【问题描述】:

我正在尝试扫描标记并将 3D 对象放在该标记上。到目前为止,这是有效的,但我似乎无法在脚本(arFoundation 脚本)中找到一个位置,当找到 referenceImage 时放置预制件。获取 referenceImage 位置也很有用,因此我可以自己在该位置实例化对象。

任何帮助将不胜感激

我正在使用:

ARFoundation 2.2.0 preview
ARCore 2.1.0 preview
ARKit 2.2.0 preview
Unity 2019.1.8f1



//TrackedImageInfoManager.cs SCRIPT
public void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)

    /*ARTrackedImage trackedImage = null;//SOME CODE FROM FORUMS, could this be better than below uncommented code?

    for (int i = 0; i < eventArgs.added.Count; i++)
    
        trackedImage = eventArgs.added[i];
        // instantiate AR object, set trackedImage.transform
        // use a Dictionary, the key could be the trackedImage, or the name of the reference image -> trackedImage.referenceImage.name
        // the value of the Dictionary is the AR object you instantiate.
    

    for (int i = 0; i < eventArgs.updated.Count; i++)
    
        trackedImage = eventArgs.updated[i];
        if (trackedImage.trackingState == TrackingState.Tracking)
        //if (trackedImage.trackingState != TrackingState.None)
        
            // set AR object to active, use Dictionary to get AR object based on trackedImage
            // you can also include TrackingState.Limited by checking for None
        
        else
        
            // set active to false
        
    

    for (int i = 0; i < eventArgs.removed.Count; i++)
    
        // destroy AR object, or set active to false. Use Dictionary.
    */ 
    //END HERE

    //WORKING CODE STARTS HERE
    foreach ( var trackedImage in eventArgs.added)
    
        trackedImage.transform.localScale = new Vector3(0.1f , 0.1f , 0.1f);//when object is instaniated, this handles it scale
        //trackedImage.transform.localPosition
        UpdateInfo(trackedImage);
    

    foreach( var trackedImage in eventArgs.updated)
    
        UpdateInfo(trackedImage);
    



我需要找到一种方法来处理实例化的预制件,或者只是获取将实例化的位置(在 referenceImage 上)并自己实例化它。

【问题讨论】:

【参考方案1】:
 if (trackedImage.trackingState == TrackingState.Tracking)
            
// do something

这行代码可以跟踪更新问题。

【讨论】:

【参考方案2】:

默认 Prefeb 在 ARTrackedImageManager 中设置为 trackedImagePrefab , 如果您想在每个新图像轨道上实例化自己的预制件,您可以像这样更改代码

void UpdateInfo(ARTrackedImage trackedImage)


  if (trackedImage.trackingState != TrackingState.Tracking)
    

     if(trackedImage.referenceImage.name == "ABC")
        Instantiate(prefab1, transform.position, transform.rotation);
      
     else if(trackedImage.referenceImage.name == "XYZ")
        Instantiate(prefab2, transform.position, transform.rotation);
      

    else
    // Destroy object if you dont want to keep
   

希望这段代码对你有所帮助。

【讨论】:

以上是关于ARFoundation之路_很全面的的主要内容,如果未能解决你的问题,请参考以下文章

[ARFoundation]unity ARfoundation+ARcore

[ARFoundation]unity ARfoundation+ARcore

计算幻术之路:被定义之前的增强现实

ARFoundation入门到精通 - 1.1 ARFoundation 简介

ARFoundation+Unity中遇到的问题

ARFoundation+Unity中遇到的问题