Unity高通AR 创建一个简单的工程(入门)


(来自官网的 https://developer.vuforia.com/resources/dev-guide/step-2-compiling-simple-project)

Create a project 如何创建一个工程

  1. After you have installed the package, create a new project in Unity.
    在Unity下创建一个新的工程
  2. Select vuforia-unity-android-ios-xx-yy-zz.unitypackage from the list of Import the following packages.
    导入vuforia-unity-android-ios-xx-yy-zz.unitypackage到新的工程中.(ps)

            OR 或者

  1. Right-click in the Project view of an open project and choose Import Package…
  2. Browse to the vuforia-unity-android-ios-xx-yy-zz.unitypackage you just installed and import it or double-click on the downloaded package. 

When creating the Unity project, avoid using spaces in the name if targeting iOS because this causes problems later when you build with Xcode. Note that by double-clicking on a package, you can selectively import parts of that package.
当创建的工程目标平台是iOS时,工程名中不要包含空格字符,因为之后工程转到Xcode中会出问题。

Note: If you do not see the Vuforia package in the list, go back to Step 1 and manually install the packages.

Next, you need to add a Device Database to your project. You can do this in two ways:
接下来,你需要给你的工程添加一个Device Database。你有两个方法做到这点:

  • Create a target on the Target Manager
    用线上的Target Manager来创建一个目标

             OR 或

  • Use existing targets from other projects
    使用其它工程中现有的目标
  1. To use the Target Manager method, see the Target Manager to create and download a package. 
    使用Target Manager的方式,来创建并下载一个package。详见Target Manager
  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.
    2--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.
如果你用从其它工程复制Device Database文件方式的话,请确保复制Editor/QCAR/ImageTargetTextures文件夹下所有的文件。

You should now see the following folder structure inside Unity:
这时,你在Unity中应该能看到如下图显示一个目录结构:

Following is a summary of the folder contents:
下面总结了文件夹的内容:

  • Editor - Contains the scripts required to interact dynamically with Target data in the Unity editor
    包含一些在unity编辑器中,与目标数据动态交互的,脚本。
  • Plugins - Contains Java and native binaries that integrate the Vuforia AR SDK with the Unity Android or Unity iOS application
    包含Java和本地二进制文件,用于整合Vuforia AR SDK与Unity Android或Unity OS应用程序。
  • Qualcomm Augmented Reality - Contains the prefabs and scripts required to bring augmented reality to your Unity application
    包含一些prefabs和一些脚本。这些被用来将增强现实到Unity应用程序上。
  • Streaming Assets - Contains the Device Database configuration XML and DAT files downloaded from the online Target Manager
    包一些从线上Target Manager中下载下来的xml和dat格式的 Device Database的配置文件

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.
  2. Expand the Qualcomm Augmented Reality folder, and expand the Prefabs folder.
    展开Qualcomm Augmented Reality文件夹,接着展开其中的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.
    删除场景中的Main Camera对象,并拖曳一个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.
    以上几步都做好了的话,就要可运行程序了,背景就个视频直播了。

Inspector view of the ARCamera 上图是一个ARCamera的检视器的视图

  1. Drag an instance of the ImageTarget prefab into your scene. This prefab represents a single instance of an Image Target object.
    拖拽一个 ImageTarget预设到你的场景中
  2. 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对象有一个Target Behaviour组件,其它有两个属性 Data Sets和Image Target。
  3. 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.

Inspector view of the ImageTarget

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 theStreamingAssets/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.

Add 3D objects to scene and attach to trackables

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

  1. As a test, create a simple Cube object (GameObject > Create Other > 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 > Create Other > 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 – one could also imagine playing a fade-out animation, showing an info screen or playing a sound for example. For a more detailed description of the ITrackableEventHandler interface, please see  'Responding to Tracking Events' in the Special Options section.

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 ARCamera’s Inspector panel. This allows you to use targets from both Device Databases at the same time in your Unity scene.

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. Note: the Vuforia AR Extension now supports Auto Rotation.
  2. Click  Icon to set your application icon.
  3. Click Other Settings.  Set the Minimum API Level to Android 2.3 'Gingerbread' (API level 9) 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.

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 supportsAuto Rotation.  
  2. Make sure that Target Platform is not set to armv6 (OpenGL ES 1.1). This version of the extension supports only OpenGL-ES 2.0. 
  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.

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 thePostProcessBuildPlayer script to avoid overwriting your changes.

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 theTHREAD_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.

Created AR scene

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/QCAR/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!

Running in the editor

The Vuforia Unity Extension supports the Play Mode feature, which provides AR application emulation through the Unity Pro Editor using a webcam. Configure this feature through the Web Cam Behaviour component of the ARCamera in the Inspector.

To use Play Mode for Vuforia in Unity Pro, simply select the attached, or built-in, 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 with non-Pro Unity versions and by set ‘Don’t use for Play Mode’ in the Web Cam Behaviour component.

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.




  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值