当前位置:网站首页>Introduction to ground plane in unity

Introduction to ground plane in unity

2022-06-21 09:30:00 have a rest

This guide will guide you step-by-step through how to Unity Create an augmented reality experience in . We suggest that Vuforia The core sample is the starting point .

Be careful :  Android,iOS and UWP Support ground aircraft . The ground plane is only associated with the platform enabler (ARKit / ARCore) Supported devices or Vuforia Engine Specially calibrated devices are compatible . of   Latest equipment coverage , see also   List of supported devices .

Unity Ground plane in

The ground level should preferably pass through Unity Vuforia Core examples to demonstrate , We recommend starting here to familiarize yourself with the concepts and components , To build your own surface inspection AR Experience . 

  1.   stay Unity in establish And open a new project . according to here Of 《 Getting started 》, Use Vuforia Engine settings  .
  2. Navigate to Unity Asset Store( stay Web Browser ) And search for Vuforia. 
  3. choice Vuforia Core Sample and add it to your assets . Make sure to use your Unity Account login . 
  4. return Unity Editor , And then from window -> Package manager Tab to open package management   device .
  5. In the drop-down menu , choice   My assets

  1. choice Vuforia Core Samples, Then press  Import. This will install Vuforia Engine And all necessary dependencies .
  2. After completion , Find and open  3 Ground level   Scenarios under the project tab   assets / Sample resources / scene
  3. To use “ Play mode ” Test the ground plane function ,   You must first print the destination . The target is located at   assets / Editor / Vuforia / ImageTargetTextures / VuforiaEmulator /.

perhaps , Open the tab   file -> Build settings ,  Then select your platform and build it into your device . 

Ground plane scene structure

In addition to using the necessary components of the ground plane , The sample scenario also provided us with other useful parts , To create an intuitive AR Experience . 

PlaneManager.cs  The logic of the hit test that controls the surface and resets . It also defines what the following phases place in the real world :Anchor_Plane and Anchor_MidAir. 

ProductPlacement.cs  and  TouchHandler.cs  Shows logic on how to enable users to interact with placed content . 

GroundPlaneUI.cs  Have a to indicate and interact with each virtual content UI.  

Create your first ground experience

In this section , We will add the ground plane function to an empty Unity In the project , And explain it when adding components . These steps will guide you through adding and testing ground planes . 

  1. open Unity and   establish   A new project .
  2. Such as this paper Add Vuforia Engine SDK  .
  3. Delete default   Main camera  , And add  ARCamera Game objects   By expanding   Game objects Menu drop-down list and select  Vuforia engine - > AR The camera .
    1. open   Of  Vuforia Engine configuration   And add   License key .
  4. In the same way as above , go to  GameObject  And add  Vuforia Engine-> Ground Plane> Ground Plane Stage.

The   Ground plane stage game object   As   Parent game object . Your content should be a child of this component . 

Please note that , There are visual signs on the ground level stage , Show that it is 100 square centimetre . These visual guides are available only in Unity Render in the editor , Used to determine the Unity The actual scale in the editor . Besides ,Ground Plane Stage Allows you to compare content to Ground Plane Position itself , This allows you to place content relative to the actual surface and scale .

We will add some content on the ground plane stage . 

  1.   Select... In the hierarchy “  Ground level stage ” GameObject, Then right-click to add  3D Object-> Capsule. Put it X,Y and Z The scale is set to 0.5.
  1. stay  GameObject  The menu , choice  Vuforia Engine-> Ground Plane> Plane Finder

    The plane finder does the following :

    • nail nchor Enter the listening behavior -  Listening for input from the user ( for example , Taps on the device screen ).
    • Plane finder behavior -  Try to find the right plane to place the content in the real world . 
    • Content positioning behavior - take   Put the content into the real world .

ad locum , You can personalize the indicator used to identify the surface , And according to the user input will “ Pattern ”  Set up   by “ Automatically ” For automatic detection or “ Interaction ” To test . You can also define the height for the desired distance between the device and the plane . 

  1. take   Ground level stage GameObject  Drag onto  “ Plane Finder GameObject”  in “ Content positioning behavior ” Components   Of “  Anchor stage ” Parameters in  . This is all that is required for the normal operation of the ground level .

Build and test on the device

  1. We will deploy to this device to test our ground plane experience . 

Make sure to use “ Ground level   Supported devices ” Devices in the list . see also   here ,  To get the settings “  Build settings ”  and “  Player settings ”  as well as    Put the application Build and run To   Description of the equipment . If the device is not available , See below “ Ground plane simulator ” part .

  1. Start the application , Look around your environment . Please note that , Lines should appear and be projected onto the plane . 

Find the right surface , Click on the screen . You should see that the capsule is placed on the plane pointed by the marking line . Tap again to add other Capsules . 

By default ,  Every time When positioning ,“  Content positioning behavior ” Will copy the stage and content . Instead, move the stage on each user's click ,   You can uncheck “ Content positioning behavior ” Of “  Repeat the stage ”.

Ground level simulator

If supported devices are not supported , It's in Unity Of “ Play mode ” Next Runtime , You can use Vuforia Engine Simulate the ground  . This allows developers to test their... Without having to deploy to a device “ Ground plane ” Experience . 

  1. To simulate the ground plane , Please navigate to “ project ” window , Then go to   assets \ Vuforia \ database \ ForPrint \ Emulator \  Then open the   Simulator ground plane .pdf  The file is not scaled A4 Print template on size paper .

  1. Connect a standard webcam to your computer , And then in Unity Press “ Play ” Button . Point your webcam at “ Ground plane formwork ”.
  1. You should see that the capsule is relative to “ Ground level ” The template appears . without , Please make sure   stay Vuforia To configure (Cmd + Shift + V or Ctrl + Shift + V) Lieutenant general “  Play mode ” Set correctly to WEBCAM  

Place floating content in your environment

The workflow for placing floating content is very similar to the workflow for placing content on an aircraft . This section will focus on the main differences between floating content and basic content .

  1. Instead of creating   Ground level stage , Not as good as establish   Air stage . from  GameObject  The menu , choice  Vuforia Engine-> Mid Air> Mid Air Stage.
  2. stay   Mid air stage game object   As   Parent game object  , The content is treated as a child . 

Please note that , There are visual signs on the aerial stage , Indicates that it is 100 square centimetre . These visual guides are available only in Unity Render in the editor , Used to determine the Unity The actual scale in the editor .

  1. Add your content as a child of the air stage . In this example , We added a model of an unmanned aircraft in the air stage .

  1. Use a real scale on the mid air stage to correctly position and scale the content relative to the stage ( apart 50cm).

  1. stay  GameObject  The menu , choice  Vuforia Engine> Mid Air> Mid Air Positioner. The behavior of the aerial locator is related to “ Plane Finder ” The behavior toward ground level is very similar .

The aerial stage performs the following operations :

  • Anchor input listener behavior - Listen   Input from users ( for example , Click... On the device screen ).
  • Air locator behavior -  Try to find the right plane to put content on . 

Here you can configure the distance between the indicator and the camera . You can also customize the indicators . 

  • Content positioning behavior - take   Put the content into the real world .
  1. take   Air stage GameObject  Drag onto  “ Content positioning behavior ”  Component's “  Anchor stage ” Parameter  .

  1. Now? , Build or test scenarios using standard webcams . You will see a green translucent sphere in the middle of the screen . The green sphere indicates where to place the content when you click .
 

Advanced settings

The ground plane example demonstrates only one way to build application logic and create immersive and interactive AR The way to experience . The components used to enable the ground plane are only used for common use cases , It can be easily configured to build your own application logic . 

To customize , You can write your own logic , To position the content on an empty anchor when the hit test results return to the appropriate surface . Replace... With a custom script  ContentPositioningBehaviour , The script uses  PositionalDeviceTracker API Create an empty anchor . then , Give Way  MidAirPositionerBehaviour  and  PlaneFinderBehaviour  Call custom script .

Change how hit tests are passed to, for example, user input . Integrate your own UI System , And invoke the event by pressing the button . In short , call  MidAirPositionerBehaviour  and  PlaneFinderBehaviour  event , It is usually called by  AnchorInputListener

原网站

版权声明
本文为[have a rest]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210919062638.html