Unity3d-simple AR game

Unity3d-simple AR game

1. Image recognition and modeling

Import of Vufria module

The first is to install the Vuforia module. After the 2017 version, you can install it directly using Unity Hub. After the installation is completed, you can use it directly in the software.

1

Then add the AR camera in GameObject->Vuforia->AR Camera in the menu directory. After adding, the software will ask to import Vuforia related files, just select import.

2

After the import is successful, you can see Vuria-related modules in the file management menu below.

Create Vufria project

After successfully importing the module, you need to set the project as an AR project. Click File->Build Setting on the main menu to open the build settings.

Then click playing setting to pop up the Playing setting window on the right. Here, check Vuforia Realit in the XR Setting item.

Vuforia certificate addition

The above has set the game project as an AR project, but some image processing settings must be made below to use it. The first is to add the vuforia certificate. Click on the ARCamera just created to enter its Inspector page and open the Open Vuforia configuration under this page.

Click to enter the Inspector of VuforiaConfiguration. Click the Add License button here, and then a Vuforia official website will pop up.

After clicking on the website, you are first asked to log in to your account. If you still have an account here, you need to register one. After logging in, you will see the certificate management page below, which lists the valid certificates for the account. If there is no valid certificate, click Get Development Key to create one.

Just enter a different name on the certificate creation page to confirm. After the creation is completed, click the created certificate on the certificate management page just now, and then copy the contents of the gray box.

Then return to the Inspector page of AR Camera and paste the certificate content into the App License Key input box. The addition of the certificate is completed.

Add image database

After the certificate is added, AR Camera can perform image recognition, but now it can only recognize its built-in pictures. The next step is to add your own recognition pictures. First, on the AR Camera page, open the Databases property, click the Add Database button, and enter the Vufria image database identification website.

After opening, enter the Target Manager page. Listed here are the image databases that have been recognized by the login account. To create a new one, click the Add Database button.

On the Create Database page, enter the name of the database and select Device as the type.

After creation, enter the image database page, select Add target on this page to add the corresponding image, fill in the image type, width and name, and then the progress bar of the recognition will pop up, waiting for the upload to be successful.

After the upload is successful, the corresponding images will appear in the database, and then the corresponding database can be downloaded. Check the image to be identified in the database on the left, click Download Database on the upper right, a Download Databases dialog box will pop up, select Unity Editor as the option, and then click the download button.

After the download is completed, find the corresponding downloaded file with the suffix name, drag .unitypackageit directly into unity3d, the import window will pop up, and click the import button.

Finally, return to the Inspector page of AR Camera again. Click on Databases and you will see that there is an option to create the database just now. Check it and the Active option that appears behind it. In this way, the addition of the image recognition database is completed. The pictures in the corresponding database can be identified.

Image recognition modeling

After the database is added, image recognition and modeling can be performed. Right-click in a blank space of the object tree and select Vuforia->Image to create a Target Image.

Click ImageTarget to enter the Inspector page, and select the database and image to be recognized in Image Target Behavior.

Then model the corresponding image, add any 3D sub-object to the ImageTarget, and then run it. After running, you can see that there is a corresponding created 3D file above the image.

Virtual button game

I don’t know what virtual button game to make, so I directly used the cruiser game I wrote before, used pictures to model the cruiser game, and then added four virtual buttons to represent up, down, left, and right.

Add recognition pictures and models

In image recognition, the images that come with Vufria are directly used here, create a new ImageTarget, select VuforiaMars_Images in Databases, and select Astronaut for Image Target.

Add the map in the original game as a child object of ImageTarget.

Add virtual button

Click ImageTarget to enter the Inspector page, open the Advanced option in the Image Target Behavior option, click the Add Virtual Button button, and add a virtual button.

Set the name, size and position of the virtual button. The name must be unique.

Virtual buttons have no entities. You need to add entities and text to each button, and add corresponding 3dObject and 3dtext text to each virtual button.

The effect after adding is as follows.

Game pictures, videos, and code addresses.

Insert image description here

Video website: https://www.bilibili.com/video/av80631937/

or hw11.mov

Code address: https://github.com/ouzj5/3dgame/tree/master/hw11

Guess you like

Origin blog.csdn.net/qq_40135006/article/details/103704181