Multi-AR Tips and Tricks

Here are some tips and tricks regarding the ‘Multi-AR Examples’-asset. By publishing them here, it will be easier for me, to keep the AR-related knowledge base in one place. There are many tricky things to keep in mind in this area. And many more will come soon, because AR is a hot topic, and will become even hotter in the future.

Here is a link to the Online documentation of the Multi-AR-asset.

 

Table of Contents:

How to use the Multi-AR-package functionality in your own Unity project
How to anchor a scene object to the world
How to run the networking client-server demo
How to set the ARCore-settings on different platforms
How to run the image-anchor demo scene

 

How to use the Multi-AR-package functionality in your own Unity project

1. Copy folder ‘MultiAR’ from the Assets-folder of the package to the Assets-folder of your project. This folder contains the package scripts, AR-platform interfaces and needed resources. It includes Multi-AR demo scenes, as well. You can delete MultiAR/DemoScenes-folder to save space.
2. Copy folder ‘GoogleARCore’ from the Assets-folder of the package to the Assets-folder of your project. This folder contains Google AR-Core scripts, libraries and resources. It includes the AR-Core demo scenes, as well. You can delete the GoogleARCore/Examples-folder to save space.
3. Copy folder ‘UnityARKitPlugin’ from the Assets-folder of the package to the Assets-folder of your project. It contains Apple AR-Kit scripts, libraries and resources. It includes the AR-Kit demo scenes, as well. You can delete the UnityARKitPlugin/Examples-folder to save space.
4. Open the project in Unity editor. There shouldn’t be any errors in the console.
5. Add the MultiARController-prefab from MultiAR/CoreScripts/Prefabs-folder to the scene, if it is not yet there. You are all set now.

How to anchor a scene object to the world

Here is how to anchor a game object in the scene (called ‘obj’ in the code below) to the world point, where the user taps. This world point should belong to a detected surface.

MultiARManager arManager = MultiARManager.Instance;

if (obj && arManager && arManager.IsInitialized() && arManager.IsInputAvailable(true))
{
	MultiARInterop.InputAction action = arManager.GetInputAction();

	if (action == MultiARInterop.InputAction.Click)
	{
		MultiARInterop.TrackableHit hit;
		if(arManager.RaycastToWorld(true, out hit))
		{
			arManager.AnchorGameObjectToWorld(obj, hit);
		}
	}
}

How to run the networking client-server demo (v2.4 and later)

This example consists of two scenes in DemoScenes/NetworkDemo-folder. It uses the Google cloud anchors, to share the AR playground among the clients. The ArServerDemo-scene is a dedicated game server that stores the shared cloud anchor ID and synchronizes the clients and players. The simple multiplayer game, world anchoring and cloud anchor sharing is done in the ArClientCloudAnchorDemo-scene. Here is how to setup and run these demo scenes.

1. Build the ARServerDemo-scene for Standalone platform (Windows or MacOS-X). It is a simple dedicated game server. Its purpose is to share the cloud anchor ID among the clients, and synchronize the players.
2. You can build the ArClientCloudAnchorDemo-scene on either Android or iOS devices, because Google cloud anchors can work on both AR-Core and AR-Kit. In this regard, first you need to get your AR-Core API Key, needed for cloud anchor sharing (i.e. saving and restoring).
3. To get a cloud anchor API go to this page and look for ‘ARCore Cloud Anchor API’. One found, select and enable the API. Create a cloud project as well, if needed.
4. Then go to this page and create a new API key. Copy the newly created key to the clipboard.
5. Go back to the Unity editor. Open menu ‘Edit / Project settings / ARCore’ and paste the copied key to its ‘Android cloud services API key’ or ‘iOS cloud services API key’-setting.
6. Select the ClientController-object in Hierarchy, and look at its ArClientCloudAnchorController-component. As you can see, ‘Server host’ is set to ‘0.0.0.0’. This means the client will utilize network discovery, to find the game server automatically. If this doesn’t work, you can set ‘Server host’ to the server’s IP address (or name) instead.
7. Run the server, then build and run the client(s) on the respective mobile platform. When the first client connects to the server and AR surfaces are detected, you should tap on a detected surface to anchor the playground to the world, and then save this anchor to the cloud. The other clients will get the anchor ID from the server, and then restore the same anchor from the cloud. Hence, all clients (players) will share the same play area. After the play area is setup, you can look for other connected players, and tap the screen to shoot at them.

How to set the ARCore-settings on different platforms

As you probably know, you can see and edit the ARCore-specific settings by selecting ‘Edit / Project Settings / ARCore’. They should be set differently, depending on the target platform:

– Android: ‘ARCore required’ should be enabled. Optionally ‘Instant preview enabled’ may be enabled too, if you are utilizing the InstantPreview-tool in your development. In case you utilize cloud anchors in your project (see the previous tip), ‘Android cloud services API key’ should be set, as well.

– iOS: In case you don’t utilize cloud anchors (see the previous tip), please make sure that both ‘ARCore required’ and ‘iOS support enabled’ are disabled. In this case, in Xcode open the Unity generated .xcodeproject for the Unity project. In case you utilize the cloud anchors functionality on iOS, please enable both ‘ARCore required’ and ‘iOS support enabled’. Don’t forget to set ‘iOS cloud services API key’, as well. In this case, in Xcode open the Unity generated workspace.

– Other platforms: Make sure that all ‘ARCore required’, ‘Instant preview enabled’ and ‘iOS support enabled’ are disabled.

How to run the image-anchor demo scene (v2.5 and later)

To run the image-anchor demo scene on ARCore (Android) or ARKit (iOS) platforms, you need a bit a preparation first. HoloLens and Win-MR devices don’t support image anchoring at the moment. So, here is what to do, if you are targeting ARCore or ARKit:

1. Open the ImageAnchorDemo-scene in MultiAR/DemoScenes/ImageAnchorDemo-folder, and select the MultiARController-game object in Hierarchy.
2. Below the MultiARManager you’ll see a new component, called AnchorImageManager. Unfold the AnchorImages-list, and you will see the textures (images) that may be used later as AR anchors, along with their real widths in meters. The heights are estimated at run-time, from the specified widths and the respective aspect ratios.
3. You are free to modify the AnchorImages-list and use your own images, if you like. Keep in mind the used images need to have enough detectable feature points and must avoid repeating patterns, if possible.
4. When you are ready with the AnchorImages-list, press the ‘Create Database’-button below the list. This creates the needed platform-specific data structures for ARCore or ARKit. These data structures are created in the Assets/Resources-folder of the project.
5. Print one or more of the images (with the specified width) on sheets of paper and put them somewhere in the room.
6. Save the scene, build it for the respective AR-platform, deploy it and run it on the respective Android or iOS device.
7. With the demo scene running on your device, locate one of the printed images. You should be close enough, so that the printed image takes at least 60-70% of the camera image. You will see how the virtual coffee cups are created and anchored to the image. Here is the context of this scene.
8. Feel free to change the used models and other settings of the CoffeeMachineController-component in the scene. You may also use the script as example and use its code in your own script, according to your needs.

 

 

3 thoughts on “Multi-AR Tips and Tricks

  1. Pingback: Multi-AR Examples | RFilkov.com - Technology, Health and More

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s