Vuforia-Getting Started with Vuforia for Unity Development

来源:互联网 发布:网络安全教育视频大学 编辑:程序博客网 时间:2024/06/04 19:26

  • Developing Vuforia Apps Using a Graphical Workflow            使用图形工作流程开发Vuforia应用程序
  • How To Install the Vuforia Unity Extension                               如何安装Vuforia Unity扩展
  • How To Setup a Simple Unity Project                                        如何设置简单的Unity项目


Developing Vuforia Apps Using a Graphical Workflow   

使用图形工作流程开发Vuforia应用程序

The Vuforia Unity Extension enables you to create vision apps for Android and iOS using a simple drag-and-drop authoring workflow in Unity.

Unity is a popular development engine that provides high quality rendering and animation features, along with the ability to implement custom app logic through scripting.

Vuforia provides a variety of Unity sample projects that demonstrate how to implement all of the features of the platform. You can use these projects as templates for your own apps, and customize them by adding your own digital content and target images.


Vuforia Unity Extension使您能够使用Unity中的简单拖放创作工作流为Android和iOS创建视觉应用。


Unity是一种流行的开发引擎,可提供高质量的渲染和动画功能,以及通过脚本实现自定义应用程序逻辑的能力。


Vuforia提供了各种Unity示例项目,演示如何实现平台的所有功能。 您可以使用这些项目作为自己的应用程序的模板,并通过添加自己的数字内容和目标图像进行自定义。


Getting Started    入门

The Image Targets in Unity video tutorial will show you how to author a simple Vuforia project using Image Targets in Unity.

How To Setup a Unity Project will walk you through the steps necessary for setting-up, customizing and building a simple Vuforia Unity project for both iOS and Android.

The Vuforia Play Mode for Unity video tutorial will show you how to rapidly prototype your app in Unity using the Vuforia simulator in Play Mode.

Unity中的图像目标视频教程将向您展示如何使用Unity中的图像目标创建一个简单的Vuforia项目。


如何设置Unity项目将引导您完成为iOS和Android设置,定制和构建简单的Vuforia Unity项目所需的步骤。


Vuforia Play Mode for Unity视频教程将向您展示如何使用Play Mode中的Vuforia模拟器在Unity中快速原型化您的应用程序。

Creating Targets

You will use the online Target Manager to create and manage the target images that your app can recognize and track. The Vuforia Target Manager Guide provides an introduction to working with the Target Manager to create targets and target databases.

For tips on selecting and designing target images, review the Image Targets Guide.

您将使用在线目标管理器来创建和管理应用程序可以识别和跟踪的目标图像。 “Vuforia目标管理器指南”提供了使用目标管理器创建目标和目标数据库的简介。


有关选择和设计目标图像的提示,请查看“图像目标指南”。


More Information

The Vuforia Developer Library documents all of the features, tools and services of the Vuforia Platform.

Vuforia开发人员库记录了Vuforia平台的所有功能,工具和服务。


How To Install the Vuforia Unity Extension       如何安装Vuforia Unity扩展

The Vuforia Unity Extension enables the development of vision based apps using the Unity Game Engine. Developers must obtain the Unity Editor, along with the Unity Android and/or Unity iOS mobile plugins from Unity Technologies. To use Vuforia in Unity, you'll need to import the Vuforia Unity Extension into your Unity project
Note: The Vuforia Unity Extension is compatible with both Unity Standard and Unity Pro.

Visit the Unity website for further information about Unity and how to download it.
If you already have Unity and need to migrate an existing Vuforia project to a new extension version, See: How To Migrate a Unity Project
Importing the extension

  1.  Download the Vuforia Unity Extension.
  2. Open your Unity project or create a new one.
  3. Import the Vuforia Unity Extension by either double clicking the extensions *.unitypackage file on your file system, or by selecting Assets/Import Package/Custom Package in the Editor's menu and then selecting the *.unitypackage on your file system.
  4. The extension archive will self install into your project, adding the following folders, with plugins and libraries, to your project.
Vuforia Unity Extension支持使用Unity游戏引擎开发基于视觉的应用程序。开发人员必须获得Unity编辑器,以及来自Unity Technologies的Unity Android和/或Unity iOS移动插件。要在Unity中使用Vuforia,您需要将Vuforia Unity扩展导入到Unity项目中
注意:Vuforia Unity Extension与Unity Standard和Unity Pro兼容。

访问Unity网站了解有关Unity的更多信息以及如何下载。
如果您已经拥有Unity并且需要将现有的Vuforia项目迁移到新的扩展版本,请参阅:如何迁移Unity项目
导入扩展名
1、下载Vuforia Unity Extension。
2、打开你的Unity项目或创建一个新的。
3、通过双击文件系统上的扩展名* .unitypackage文件,或者在编辑器菜单中选择Assets / Import Package / Custom Package,然后在文件系统上选择* .unitypackage导入4、Vuforia Unity Extension。
4、扩展存档将自动安装到您的项目中,将以下插件和库的文件夹添加到项目中。



How To Setup a Simple Unity Project

It's easy to set-up a basic Vuforia project in Unity. Follow these steps to import the Vuforia Unity extension and to add and configure the prefabs and assets used to develop Vuforia apps in Unity.

在Unity中设置基本的Vuforia项目很容易。 按照以下步骤导入Vuforia Unity扩展,并添加和配置用于在Unity中开发Vuforia应用程序的预制和资产。

Create a project

  1. Create a new project in Unity.
  2. Download the Vuforia Unity Extension
  3. Browse to the vuforia-unity-xx-yy-zz.unitypackage you just downloaded double-click on the file.
  4. Accept the import of the package into your Unity project.
1、在Unity中创建一个新项目。
2、下载Vuforia Unity Extension
3、浏览到刚刚下载的vuforia-unity-xx-yy-zz.unitypackage双击该文件。
4、接受将包导入您的Unity项目。

Obtain a License Key       获得许可证密钥

You will need create a license key for your app in the License Manager and add this key to your project.

See:
How To Create a License Key
How To add a License Key to your Vuforia App

您将需要在许可证管理器中为您的应用程序创建许可证密钥,并将此密钥添加到您的项目中。


查看:
如何创建许可证密钥
如何在Vuforia应用程序中添加许可证密钥

Adding Targets                添加目标

Next, you need to add a Device Database to your project. You can do this in two ways:

  • Create a target on the Target Manager

OR

  • Use existing targets from other projects
  1. To use the Target Manager method, see Vuforia Target Manager to create and download a package.
  2. Double-click the downloaded package, or right-click on Unity Project for Import Package and "Custom Package.
  3. Select the downloaded package.
  4. Click Import to import the target Device Database.
接下来,您需要向您的项目添加一个设备数据库。 你可以通过两种方法来实现:


在目标管理器上创建目标
或者
         使用其他项目的现有目标
1、要使用目标管理器方法,请参阅Vuforia目标管理器来创建和下载软件包。
2、双击下载的软件包,或右键单击Unity Project for Import Package和“Custom Package”。
3、选择下载的包。
4、单击导入以导入目标设备数据库。

If you are copying the Device Database files from another project, be sure to copy any files located in the Editor/QCAR/ImageTargetTextures folder. These will be used to texture the target plane in the Unity editor.

You should now see the following folder structure inside Unity:

如果要从另一个项目复制设备数据库文件,请确保复制位于Editor / QCAR / ImageTargetTextures文件夹中的任何文件。 这些将用于在Unity编辑器中纹理目标平面。


您现在应该在Unity中看到以下文件夹结构:


Project Folders      项目文件夹

  • Editor - Contains the scripts required to interact dynamically with Target data in the Unity editor
  • 编辑器 - 包含在Unity编辑器中与Target数据动态交互所需的脚本
  • Plugins - Contains Java and native binaries that integrate the Vuforia AR SDK with the Unity Android or Unity iOS application
  • 插件 - 包含将Vuforia AR SDK与Unity Android或Unity iOS应用程序集成的Java和本机二进制文件
  • Vuforia - Contains the prefabs and scripts required to bring augmented reality to your Unity application
  • Vuforia - 包含将增强现实带到您的Unity应用程序所需的预制和脚本
  • Streaming Assets / QCAR - Contains the Device Database configuration XML and DAT files downloaded from the online Target Manager
  • 流式资源/ QCAR - 包含从在线目标管理器下载的设备数据库配置XML和DAT文件

Add AR assets and prefabs to scene                   向场景添加AR资产和预制

  1. Now that you have imported the Vuforia AR Extension for Unity, you can easily adapt your project to use augmented reality.  
     现在您已经导入了用于Unity的Vuforia AR Extension,您可以轻松地使您的项目适应使用增强现实。
  2. Open the /Vuforia/Prefabs folder  
    打开/ Vuforia / Prefabs文件夹 
  3. Delete the Main Camera in your current scene hierarchy, and drag an instance of the ARCamera prefab into your scene. The ARCamera is responsible for rendering the camera image in the background and manipulating scene objects to react to tracking data.     
     删除当前场景层次结构中的主相机,然后将ARCamera预制件的实例拖动到场景中。 ARCamera负责在后台渲染相机图像,并操纵场景对象以对跟踪数据做出反应。
  4. With the ARCamera in place and the target assets available in the StreamingAssets/QCAR folder, run the application on a supported device, and see the live video in the background.
      使用ARCamera并且StreamingAssets / QCAR文件夹中的目标资源可用,在受支持的设备上运行应用程序,并在后台查看实时视频。          
  5. Drag an instance of the ImageTarget prefab into your scene. This prefab represents a single instance of an Image Target object.  
    将ImageTarget预制件的实例拖动到场景中。此预制表示图像目标对象的单个实例。
  6. Select the ImageTarget object in your scene, and look at the Inspector. There should be an Image Target Behaviour attached, with a property named Data Set. This property contains a drop-down list of all available Data Sets for this project. When a Data Set is selected, the Image Target property drop-down is filled with a list of the targets available in that Data Set.
    在场景中选择ImageTarget对象,然后查看Inspector。应该有附加的图像目标行为,其属性名为数据集。此属性包含此项目的所有可用数据集的下拉列表。选择数据集后,“图像目标”属性下拉列表将填充该数据集中可用的目标列表。
  7. Select the Data Set and Image Target from your StreamingAssets/QCAR project. In this example, we choose "StonesAndChips". (It is automatically populated from the Device Database XML file that is downloaded from the online Target Manager). The Unity sample apps come with several Image Targets . To use them, copy them from the ImageTargets sample, or create your own at the Target Manager section of this site.                                                         从StreamingAssets / QCAR项目中选择数据集和图像目标。在这个例子中,我们选择“StonesAndChips”。 (它从从在线目标管理器下载的设备数据库XML文件自动填充)。 Unity示例应用程序附带了几个图像目标。要使用它们,请从ImageTargets示例中复制它们,或在本网站的“目标管理器”部分创建自己的样本。


NOTE: When you added the Image Target object to your scene, a gray plane object appeared. This object is a placeholder for actual Image Targets. In the inspector view of the Image Target there is a pop-up list called Image Target. From this list, you can choose any Image Target that has been defined in one of the StreamingAssets/QCAR datasets so that the Image Target object in your scene adopts the size and shape from the Image Target it represents. The object is also textured with the same image from which the Image Target was created.

注意:当您将图像目标对象添加到场景中时,会出现一个灰色平面对象。 此对象是实际图像目标的占位符。 在“图像目标”的检查器视图中,有一个名为“图像目标”的弹出列表。 从该列表中,您可以选择在其中一个StreamingAssets / QCAR数据集中定义的任何图像目标,以使场景中的图像目标对象采用其所代表的图像目标的大小和形状。 该对象也使用与其创建映像目标相同的映像进行纹理化。

Add 3D objects to scene and attach to trackables           将3D对象添加到场景并附加到跟踪

Now you can bind 3D content to your Image Target.

  1. As a test, create a simple Cube object (GameObject > 3D Object > Cube).
  2. Add the cube as a child of the ImageTarget object by selecting it in the Hierarchy list and dragging it onto the ImageTarget item.
  3. Move the cube in the scene until it is centered on the Image Target. You can also add a Directional Light to the scene (GameObject > Light > Directional Light).


现在,您可以将3D内容绑定到您的图像目标。


1.作为测试,创建一个简单的Cube对象(GameObject> 3D Object> Cube)。
2.通过在“层次结构”列表中选择它并将其拖动到ImageTarget项上,将该多维数据集作为ImageTarget对象的子项添加。
3.移动场景中的立方体,直到它位于图像目标的中心。 您还可以向场景添加方向光(GameObject> Light> Directional Light)。

TrackableEventHandler

The Default Trackable Event Handler (DefaultTrackableEventHandler) is a script component of the Image Target that causes the cube you just drew to appear or disappear automatically an automatic reaction to the appearance of the target in the video.

You can override this default behavior by revising the DefaultTrackableEventHandler script or writing your own by implementing the ITrackableEventHandler interface.

默认跟踪事件处理程序(DefaultTrackableEventHandler)是映像目标的脚本组件,导致您刚刚绘制的多维数据集自动显示或自动消失视频中对目标外观的自动反应。


您可以通过修改DefaultTrackableEventHandler脚本或通过实现ITrackableEventHandler接口编写自己的代码来覆盖此默认行为。

Adding Dataset load to camera        将数据集加载到相机

The Vuforia SDK has the ability to use multiple active Device Databases simultaneously. To demonstrate this capability, you can borrow the StonesAndChips and Tarmac Device Databases from the ImageTargets sample and configure both to load and activate in the Datasets field of the ARCamera s Vuforia Configuration asset, which is accessible from the ARCamera's Inspector panel via the Open Vuforia Configuration button. You can also search for VuforiaConfiguration in the Project panel.This allows you to use targets from both Device Databases at the same time in your Unity scene.


Vuforia SDK可以同时使用多个活动的设备数据库。 为了演示此功能,您可以从ImageTargets示例中借用StonesAndChips和Parmac Device Databases,并将其配置为在ARCamera的Vuforia Configuration资产的“数据集”字段中进行加载和激活,ARCAMera的Vuforia Configuration资产可通过Open Vuforia Configuration从ARCamera的Inspector面板访问按钮。 您还可以在“项目”面板中搜索“VuforiaConfiguration”。这样您可以在Unity场景中同时使用设备数据库中的目标。


Deploy the application         部署应用程序

The next step is to deploy your application to a supported device.

Android deployment process

Unity provides a number of settings when building for Android devices select from the menu (File > Build Settings > Player Settings ) to see the current settings. Also, choose your platform now Android or iOS.

  1. Click Resolution and Presentation to select the required Default Orientation.
  2. Click Icon to set your application icon.
  3. Click Other Settings. Set the Minimum API Level to Android 4.1 'JellyBean' (API level 16) or higher. Set Bundle Identifier to a valid name (e.g., com.mycompany.firstARapp).
  4. Save your scene (File > Save Scene).
  5. Open the build menu (File > Build Settings ). Make sure that your scene is part of Scenes in Build. If not, do one of the following:
  • Use Add Current to add the currently active scene.
  • Drag and drop your saved AR scene from the project view into the Window.


下一步是将应用程序部署到受支持的设备。


Android部署过程


Unity在为Android设备构建时提供了许多设置,从菜单中选择(文件>构建设置>播放器设置)来查看当前设置。 此外,现在选择您的平台Android或iOS。


1.单击分辨率和演示文稿以选择所需的默认方向。
2.单击图标以设置应用程序图标。
3.单击其他设置。 将最低API级别设置为Android 4.1“JellyBean”(API级别16)或更高版本。 将包标识符设置为有效的名称(例如,com.mycompany.firstARapp)。
4.保存场景(文件>保存场景)。
5.打开构建菜单(文件>构建设置)。 确保您的场景是构建场景的一部分。 如果没有,请执行以下操作之一:
6.使用添加电流添加当前活动的场景。
7.将保存的AR场景从项目视图拖放到窗口中。

You can now build the application. Attach your Android device and then click Build And Run to initialize the deployment process.

iOS deployment process

Unity provides a number of settings when building for iOS devices (File > Build Settings > Platform > iOS icon).

  1. Before building, select the required Default Orientation. Note:The Vuforia AR Extension now supports Auto Rotation.
  2. Make sure that Target Platform is not set to armv6 (OpenGL ES 1.1). As of Vuforia version 6.2, the Unity extension supports OpenGL-ES 2 and 3.
  3. Make sure that Bundle Identifier is set to the correct value for your iOS developer profile.
  4. Now you can choose to build the application. First, save your scene (File > Save Scene).
  5. Open the build menu (File > Build Settings ).
  6. Make sure that your scene is part of Scenes in Build. If this is not the case:
    a. Use Add Current to add the currently active scene.
    OR
    b. Drag and drop your saved AR scene from the project view into the Window.
  7. Press Build And Run to initialize the deployment process.

您现在可以构建应用程序。连接您的Android设备,然后单击构建和运行以初始化部署过程。


iOS部署过程


Unity在构建iOS设备时提供了许多设置(文件>构建设置>平台> iOS图标)。


1.在构建之前,选择所需的默认方向。注意:Vuforia AR Extension现在支持自动旋转。
2.确保目标平台未设置为armv6(OpenGL ES 1.1)。从Vuforia版本6.2起,Unity扩展支持OpenGL-ES 2和3。
3.确保将Bundle Identifier设置为您的iOS开发人员配置文件的正确值。
4.现在您可以选择构建应用程序。首先,保存场景(文件>保存场景)。
5.打开构建菜单(文件>构建设置)。
6.确保您的场景是构建场景的一部分。如果不是这样的话:
          a.使用添加电流添加当前活动的场景。
           或者
          b.将保存的AR场景从项目视图拖放到窗口中。
7.按构建和运行初始化部署过程。


When building and running apps for iOS, Unity generates an Xcode project. It launches Xcode and loads this project. The Vuforia AR Extension includes a PostProcessBuildPlayer script that performs the task of integrating the Vuforia library into the generated Xcode project. This is run automatically when you select Build from within Unity. Be aware that if you manually change the generated Xcode project, you may need to update the PostProcessBuildPlayer script to avoid overwriting your changes.

在构建和运行iOS应用程序时,Unity会生成一个Xcode项目。 它启动Xcode并加载此项目。 Vuforia AR扩展包括一个PostProcessBuildPlayer脚本,用于执行将Vuforia库集成到生成的Xcode项目中的任务。 当您从Unity中选择Build时,这将自动运行。 请注意,如果您手动更改生成的Xcode项目,则可能需要更新PostProcessBuildPlayer脚本,以避免覆盖您的更改。

The generated Xcode project includes a file called AppController.mm. There are Unity provided options in this file to tailor the performance of the app for your own purpose. The PostProcessBuildPlayer script sets the THREAD_BASED_LOOP as a default because it gives the best visible performance with the samples provided alongside the Vuforia AR Extension. Consider changing these options to whatever gives the best performance for your own application.


生成的Xcode项目包含一个名为AppController.mm的文件。 在此文件中有Unity提供的选项,以根据您自己的目的来定制应用程序的性能。 PostProcessBuildPlayer脚本将THREAD_BASED_LOOP设置为默认值,因为它提供了与Vuforia AR Extension一起提供的样本的最佳可见性能。 考虑将这些选项更改为为您自己的应用程序提供最佳性能。


Using the application        使用应用程序

You should have a printout of the appropriate Image Target in front of you. If you are working with a target from one of the sample apps, the PDFs are located at Editor/Vuforia/ForPrint/*.pdf. Otherwise, print out the image that you uploaded to the Target Manager and make sure that the aspect ratio doesn t change. When you look at the target using the device camera, you should see your cube object bound to the target. Congratulations, you have successfully augmented reality!


您应该在您面前打印出适当的图像目标。 如果您正在使用其中一个示例应用程序的目标,则PDF位于Editor / Vuforia / ForPrint / *。pdf。 否则,打印出您上传到目标管理器的图像,并确保纵横比不变。 当您使用设备相机查看目标时,您应该会看到您的多维数据集对象绑定到目标。 恭喜,您已成功增强现实!

Running in the editor           在编辑器中运行


Vuforia Unity Extension支持播放模式功能,通过使用网络摄像头的Unity编辑器提供AR应用程序仿真。 通过VuforiaConfiguration资产上的Web Cam字段配置此功能。

The Vuforia Unity Extension supports the Play Mode feature, which provides AR application emulation through the Unity Editor using a webcam. Configure this feature through the Web Cam field on the VuforiaConfiguration asset.


Vuforia Unity Extension支持播放模式功能,通过使用网络摄像头的Unity编辑器提供AR应用程序仿真。 通过Vuforia Configuration资产上的Web Cam字段配置此功能。


To use Play Mode for Vuforia in Unity select the webcam that you want to use from the Camera Device menu, and activate Play Mode using the Play button at the top of the Editor UI.

You can also use the standard Unity Play Mode by checking Disable Vuforia Play Mode in the Web Cam field.

To use standard Play Mode, adjust the transform of the ARCamera object to get your entire scene in view, and then run the application in the Unity editor. There is no live camera image or tracking in standard Play Mode; instead, all Targets are assumed to be visible. This allows you to test the non-AR components of your application, such as scripts and animations, without having to deploy to the device each time.

要在Unity中使用Vuforia的播放模式,请从“相机设备”菜单中选择要使用的网络摄像机,然后使用“编辑器”界面顶部的“播放”按钮激活播放模式。


您还可以通过在Web Cam字段中选中Disable Vuforia播放模式来使用标准Unity播放模式。


要使用标准播放模式,请调整ARCamera对象的变换以获取整个场景,然后在Unity编辑器中运行该应用程序。 标准播放模式中没有实时摄像机图像或跟踪; 相反,假定所有目标都是可见的。 这样就可以测试应用程序的非AR组件,例如脚本和动画,而无需每次部署到设备。


原网址:https://library.vuforia.com/articles/Solution/Getting-Started-with-Vuforia-for-Unity-Development.html

原创粉丝点击