【Vuforia+Unity】AR04-地面、桌面平面识别功能

 不论你是否曾有过相关经验,只要跟随本文的步骤,你就可以成功地创建你自己的AR应用。

官方教程Ground Plane in Unity | Vuforia Library

这个功能很棒,但是要求也很不友好,只能支持部分移动设备,具体清单如下:

01.Vuforia的地面识别功能仅支持的设备清单:

 Recommended Devices | Vuforia Library

IOS Devices

Device Name

Comments

iPhone SE (2nd & 3rd generation)

iPhone 8, iPhone 8 Plus

iPhone X, iPhone XR, iPhone XS, iPhone XS Max

iPhone 11, iPhone 11 Pro, iPhone 11 Pro Max

iPhone 12 mini, iPhone 12, iPhone 12 Pro, iPhone 12 Pro Max

The iPhone 12 Pro and iPhone 12 Pro Max support the Vuforia Creator App

iPhone 13 mini, iPhone 13, iPhone 13 Pro, iPhone 13 Pro Max The iPhone 13 Pro and iPhone 13 Pro Max support the Vuforia Creator App
iPhone 14, iPhone 14 Plus, iPhone 14 Pro, iPhone 14 Pro Max The iPhone 14 Pro and iPhone 14 Pro Max support the Vuforia Creator App
iPhone 15, iPhone 15 Plus, iPhone 15 Pro, iPhone 15 Pro Max

The iPhone 15 Pro and iPhone 15 Pro Max support the Vuforia Creator App

iPad Mini (5th & 6th generation)

iPad Air 3, iPad Air 4, iPad Air 5

iPad (5th through 10th generation)

iPad Pro

iPad Pro 9.7”, iPad Pro 10.5”, iPad Pro 11” (1st through 4th generation), iPad Pro 12.9” (3rd through 6th generation)

The iPad Pro 11” (through 4th generation) and iPad Pro 12.9” (3rd through 6th generation) support the Vuforia Creator App

Android Devices

Device Name
Comments

Samsung Galaxy A20e

SM-A202F, SM-A202K

Samsung Galaxy A32

SM-A325F, SM-A325M, SM-A325N

Samsung Galaxy A52s 5G

SM-A528B, SM-A528N

Samsung Galaxy S10e
SM-G970F, SM-G970X, SM-G970N, SM-G970U, SM-G970U1, SM-G970W, SM-G970XC, SM-G9708, SM-G9700

Samsung Galaxy S10/S10 5G
SM-G973F, SM-G973X, SM-G973N, SM-G973U, SM-G973U1, SM-G973W, SM-G973XC, SM-G9738, SM-G9730, SM-G977N, SM-G977B, SM-G977D, SM-G977J, SM-G977P, SM-G977T, SM-G977U

Samsung Galaxy S10+
SM-G975F, SM-G975X, SM-G975N, SM-G975XN, SM-G975U, SM-G975U1, SM-G975W, SM-G975XC, SM-G9758, SM-G9750, SM-G975XU

Samsung Galaxy S21/S21 5G

SM-G991B, SM-G991N, SM-G991U, SM-G991U1, SM-G991W, SM-G9910

Samsung Galaxy S21+

SM-G996B, SM-G996N, SM-G996U, SM-G996U1, SM-G996W, SM-G9960

Samsung Galaxy S21 Ultra

SM-G998B, SM-G998N, SM-G998U, SM-G998U1, SM-G998W, SM-G9980

Samsung Galaxy S22

SM-S901B, SM-S901E, SM-S901N, SM-S901U, SM-S901U1, SM-S901W, SM-S9010

Samsung Galaxy S22+

SM-S906B, SM-S906E, SM-S906N, SM-S906U, SM-S906U1, SM-S906W, SM-S9060

Samsung Galaxy S22 Ultra

SM-S908B, SM-S908E, SM-S908N, SM-S908U, SM-S908U1, SM-S908W, SM-S9080

Samsung Galaxy S23

SM-S9110, SM-S911B, SM-S911N, SM-S911U, SM-S911U1, SM-S911W

Samsung Galaxy S23+

SM-S9160, SM-S916B, SM-S916N, SM-S916U, SM-S916U1, SM-S916W

Samsung Galaxy S23 Ultra

SM-S9180, SM-S918B, SM-S918N, SM-S918U, SM-S918U1, SM-S918W

Samsung Galaxy Tab S5e

SM-T720, SM-T725, SM-T725C, SM-T725N

Samsung Galaxy Tab S6 Lite

SM-P610, SM-P615

Galaxy Tab S7/S7 5G

SM-T870, SM-T875, SM-T875N, SM-T878U

Galaxy Tab S7 Plus

SM-T970, SM-T975, SM-T976B

Galaxy Tab S8/S8 5G

SM-X700, SM-X706

Galaxy Tab S8 Plus/S8 Plus 5G

SM-X800, SM-X806

Galaxy Tab S8 Ultra/S8 Ultra 5G

SM-X900, SM-X906

Google Pixel 5/5a 5G
Google Pixel 6/6a/6 Pro
Google Pixel 7/7a/7 Pro

UWP Devices

Device Name
Comments

Microsoft Surface

Surface Pro 8, Surface Pro X, Surface Pro 7, Surface Pro 6, Surface Go, Surface Go 2

Eyewear Devices

Device Name
Comments

Microsoft

HoloLens 2

All features supported except for Ground Plane. For equivalent functionality, please use SDK provided by OEM.

Area Target Capture API is not supported on this platform.

*HoloLens 1 is no longer supported by Vuforia Engine 10.9+

Magic Leap

Magic Leap 2

All features supported except for Ground Plane. For equivalent functionality, please use SDK provided by OEM.

Area Target Capture API is not supported on this platform.

*Magic Leap 1 is no longer supported by Vuforia Engine 10.10+

Vuzix

M400

Supported features: ImageTargetsCylinderTargetMulti TargetsVuMark.

Extended Tracking not supported (no Device Tracking).

RealWear

HMT-1, HMT-1Z1

Supported features: ImageTargetsCylinderTargetMulti TargetsVuMark.

Extended Tracking not supported (no Device Tracking).

02.平面识别的目的意义:

实现自动识别环境空间的平面,然后便于后续业务逻辑的实现,例如拖拽模型到地面、平面,打乒乓球等,类似pokemon GO游戏

 03.实现步骤

确保你安装了Vuforia 的SDK在Unity 中,具体请看【Vuforia+Unity】AR01实现单张多张图片识别产生对应数字内容-CSDN博客

 然后我们可以自己搭建,也可以直接基于官方示例搭建!

3.1自己搭建

01首先创建三样东西
这个类型需要三个东西:ARcamera,Ground Plane Stage,还有Plane Finder

创建一个带有Vuforia插件普通空项目,创建一个ARcamera,创建一个Ground Plane Stage,创建一个Plane Finder

02 把识别平面后要放在平面上的数字内容模型,放在Ground Plane Stage下

接下来你需要把你所想要展现的场景和物品拖到Ground Plane Stage下

最简单的地面识别已经搭建完成!需要其他功能,请在此基础上继续开发!比如触发回调,地面被识别时、物体被放置时等等!

OVER !

3.2 直接用官方案例即可

vuforia - Asset Store (unity.com)传送门

官方还赠送了一个脚本,这个脚本在Plane Finder的"Content Positioning Behaviour"脚本中被回调:

意思是,当物体被放置在平面上后调用"Product Placement"脚本中物体的旋转功能函数

 ProductPlacement 这个物体身上脚本的理解:

脚本:"Product Placement"(产品放置)和"Touch Handler"(触摸处理)。

"Product Placement"脚本有以下字段:

  • Augmentation Object(增强对象):"Chair"(椅子)和"Chair Shadow"(椅子阴影)被分配到这个字段。
  • Control Indicators(控制指示器):此处引用了"Translation Indicator"(平移指示器)和"Rotation Indicator"(旋转指示器)。
  • Augmentation Size(增强大小):这是一个滑动条,"Product Size"(产品大小)的值为0.65。

"Touch Handler"脚本有以下字段:

  • Augmentation Object(增强对象):"Chair (Transform)"(椅子(变换))被分配到这个字段。
  • Enable Pinch Scaling(启用捏合缩放):这是一个复选框,目前处于未选中状态。

总的来说,这个设置似乎是用于控制在场景中的增强现实对象(椅子)的放置和缩放(使用触摸手势)。"Translation Indicator"(平移指示器)和"Rotation Indicator"(旋转指示器)可能是用户操作对象的视觉提示。

04  相关设置和深入理解

首先是Plane Finder,这个是识别地面的主要组件,他身上有3个脚本组件

 Plane Finder三个脚本的理解(这部分可以跳过,仅供查阅)

Anchor Input Listener Behaviour(脚本)

用来返回摄像机射线射击到的平面,被用来确定用户触摸或点击检测到的平面上的点

Plane Finder Behaviour(脚本):

此组件负责在实际环境中寻找平面。其模式被设置为"AUTOMATIC",这意味着它将无需用户交互地持续尝试寻找平面。"Plane indicator"属性是一个自定义的可视元素,用于显示检测到平面的位置。此外,这个组件处理两种hit测试:

Interactive Hit Test:它接受来自"ContentPositioningBehaviour"的代理函数"PositionContentAtPlaneAnchor",可能被用来在用户与其交互时,将内容放置在平面上的特定点。

Automatic Hit Test:它接受来自"ProductPlacement"的代理函数"OnAutomaticHitTest",这可能被用来无需用户交互就能自动在检测到的平面上放置产品或物体。

"Content Positioning Behaviour"脚本组件

脚本是Vuforia引擎中的一个组件,主要负责在增强现实(AR)环境中定位和放置内容。这个脚本通常与"Plane Finder"组件一起使用,以在实际的环境平面(如桌面或地面)上定位和放置虚拟对象。

主要特性包括:

  1. 定位和放置:当用户选择一个位置(通常是通过触摸屏幕来选择),该脚本会在那个位置创建一个锚点,并将相关的虚拟内容放置在那里。这个过程通常被称为"hit testing"。

  2. 转换:一旦虚拟内容被放置,用户可以通过手势来移动和旋转它。

  3. 锚点:为了保持虚拟内容的稳定性,该脚本使用了所谓的"锚点"。锚点是AR系统用来确保虚拟内容保持在正确位置的一种工具,即使设备的相机移动或旋转。这个锚点自动添加,当我们创建了Ground Plane Stage

总的来说,"Content Positioning Behaviour"脚本在AR应用中起着非常重要的作用,它使得虚拟内容能够以一种直观和稳定的方式放置和交互在真实世界中。

在这个脚本下面有个高级选项,里面是当平面被识别后,数字内容被用户放在平面上后就会触发

"on Content Placed(Gameobject)" 是一个事件,这个事件将在内容(即GameObject)被放置在场景中时触发。你可以在这个事件中添加方法,当事件触发时,这些方法会被自动执行。

举个例子,如果你创建了一个AR应用,并且用户可以在实际环境中放置虚拟物体,那么当用户放置这些虚拟物体时,“on Content Placed(Gameobject)" 就会被触发。在这个事件里,你可能会加入一些自定义的行为或者效果,比如播放一个声音或动画,来告诉用户虚拟物体已经成功被放置。

你可以通过点击 "+" 按钮来添加自定义的方法,也可以通过 "-" 按钮来删除已经添加的方法。这个事件的功能十分灵活,你可以根据你自己的需求来定制。

其他相关博客

关于自己创建Vuforia地面识别Demo不如原生样例(GroundPlane Sample)识别的好的解决办法_vuforia平面识别ground plane-CSDN博客

关于Vuforia插件(3D物体识别和地面识别)的一些测试记录_unity vuforia object-CSDN博客

Vuforia的各种Target的简单介绍(包括地面识别)_ar中的target是什么-CSDN博客

相关推荐

  1. ubuntu 24.04 向日葵桌面版安装

    2024-02-22 06:08:01       18 阅读
  2. Android:身份证识别功能实现

    2024-02-22 06:08:01       14 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-22 06:08:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-22 06:08:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-22 06:08:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-22 06:08:01       18 阅读

热门阅读

  1. Android Debug Bridge (ADB) v1.0.31

    2024-02-22 06:08:01       27 阅读
  2. 【0261】pg内核 raw parsetree 深入分析(一)

    2024-02-22 06:08:01       29 阅读
  3. python opencv比较图片相似度

    2024-02-22 06:08:01       25 阅读
  4. Opencv(C++)学习 ARM上引用opencv报相关头文件找不到

    2024-02-22 06:08:01       24 阅读
  5. 多模态大型语言模型综述

    2024-02-22 06:08:01       27 阅读
  6. 如何理解三大微分中值定理

    2024-02-22 06:08:01       32 阅读
  7. 使用 Nginx 将 HTTP 重定向到 HTTPS

    2024-02-22 06:08:01       26 阅读